]> git.sesse.net Git - vlc/commitdiff
Qt/EPG: Remove channels when they don't have any item.
authorAdrien Maglo <magsoft@videolan.org>
Wed, 4 Aug 2010 09:07:22 +0000 (11:07 +0200)
committerAdrien Maglo <magsoft@videolan.org>
Wed, 4 Aug 2010 09:07:52 +0000 (11:07 +0200)
modules/gui/qt4/components/epg/EPGItem.cpp
modules/gui/qt4/components/epg/EPGItem.hpp
modules/gui/qt4/components/epg/EPGView.cpp

index d634175f3859ccf669bd9ef85a6f572c77ed2b9b..2e4df4b4690410a3b2db9a42c2bcce321ebf8aaa 100644 (file)
@@ -112,7 +112,12 @@ int EPGItem::duration() const
     return m_duration;
 }
 
-void EPGItem::setChannel( int channelNb )
+int EPGItem::getChannelNb() const
+{
+    return m_channelNb;
+}
+
+void EPGItem::setChannelNb( int channelNb )
 {
     //qDebug() << "Channel" << channelNb;
     m_channelNb = channelNb;
index 04f9909ef37e7560179a0c096e097bb4a588fbee..057ff39201df635c0b37838c68b7c5316f44cc30 100644 (file)
@@ -44,8 +44,9 @@ public:
     const QDateTime& start() const;
 
     int duration() const;
+    int getChannelNb() const;
 
-    void setChannel( int channelNb );
+    void setChannelNb( int channelNb );
     void setStart( const QDateTime& start );
     void setDuration( int duration );
     void setName( const QString& name );
index cb6690c7a24b1e04fa4130f24072dc820d4bf830..5701c3cdf860fbea9ea57daba53299a09088d25d 100644 (file)
@@ -92,7 +92,7 @@ void EPGView::addEvent( EPGEvent* event )
         m_channels.append( event->channelName );
 
     EPGItem* item = new EPGItem( this );
-    item->setChannel( m_channels.indexOf( event->channelName ) );
+    item->setChannelNb( m_channels.indexOf( event->channelName ) );
     item->setStart( event->start );
     item->setDuration( event->duration );
     item->setName( event->name );
@@ -107,9 +107,45 @@ void EPGView::addEvent( EPGEvent* event )
 
 void EPGView::delEvent( EPGEvent* event )
 {
-    if( event->item != NULL )
-        scene()->removeItem( event->item );
+    if( event->item == NULL )
+        return;
+
+    int channelNb = event->item->getChannelNb();
+
+    // Remove the item.
+    scene()->removeItem( event->item );
     event->item = NULL;
+
+    // Look if the channel is still used by other events.
+    QList<QGraphicsItem*> itemList = items();
+    bool b_used = false;
+    for( int i = 0; i < itemList.count(); ++i )
+    {
+        EPGItem* item = qgraphicsitem_cast<EPGItem*>( itemList.at( i ) );
+        if ( !item )
+            continue;
+        if( item->getChannelNb() == channelNb )
+        {
+            b_used = true;
+            break;
+        }
+    }
+
+    // If the channel is no more used, then we remove it from the list
+    // and decrease the channel number of the concerned items.
+    if( !b_used )
+    {
+        m_channels.removeAt( channelNb );
+        for( int i = 0; i < itemList.count(); ++i )
+        {
+            EPGItem* item = qgraphicsitem_cast<EPGItem*>( itemList.at( i ) );
+            if ( !item )
+                continue;
+            int itemChannelNb = item->getChannelNb();
+            if( itemChannelNb > channelNb )
+                item->setChannelNb( itemChannelNb - 1 );
+        }
+    }
 }
 
 void EPGView::updateDuration()