[vlc-commits] commit: Qt/EPG: Remove channels when they don't have any item. ( Adrien Maglo )

git at videolan.org git at videolan.org
Wed Aug 4 11:37:11 CEST 2010


vlc | branch: master | Adrien Maglo <magsoft at videolan.org> | Wed Aug  4 11:07:22 2010 +0200| [4b897bbb5eca8beac7fa2a092a94513b985f83b3] | committer: Adrien Maglo 

Qt/EPG: Remove channels when they don't have any item.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4b897bbb5eca8beac7fa2a092a94513b985f83b3
---

 modules/gui/qt4/components/epg/EPGItem.cpp |    7 ++++-
 modules/gui/qt4/components/epg/EPGItem.hpp |    3 +-
 modules/gui/qt4/components/epg/EPGView.cpp |   42 ++++++++++++++++++++++++++--
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt4/components/epg/EPGItem.cpp b/modules/gui/qt4/components/epg/EPGItem.cpp
index d634175..2e4df4b 100644
--- a/modules/gui/qt4/components/epg/EPGItem.cpp
+++ b/modules/gui/qt4/components/epg/EPGItem.cpp
@@ -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;
diff --git a/modules/gui/qt4/components/epg/EPGItem.hpp b/modules/gui/qt4/components/epg/EPGItem.hpp
index 04f9909..057ff39 100644
--- a/modules/gui/qt4/components/epg/EPGItem.hpp
+++ b/modules/gui/qt4/components/epg/EPGItem.hpp
@@ -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 );
diff --git a/modules/gui/qt4/components/epg/EPGView.cpp b/modules/gui/qt4/components/epg/EPGView.cpp
index cb6690c..5701c3c 100644
--- a/modules/gui/qt4/components/epg/EPGView.cpp
+++ b/modules/gui/qt4/components/epg/EPGView.cpp
@@ -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()



More information about the vlc-commits mailing list