]> git.sesse.net Git - vlc/commitdiff
QT/EPG: Fix EPGItem management.
authorAdrien Maglo <magsoft@videolan.org>
Fri, 18 Jun 2010 20:14:53 +0000 (22:14 +0200)
committerAdrien Maglo <magsoft@videolan.org>
Fri, 18 Jun 2010 20:15:03 +0000 (22:15 +0200)
Synchronize correctly with the EPG structures provided by the core.
Remove EPGItems from the EPGView when they are not anymore stored.

modules/gui/qt4/components/epg/EPGEvent.hpp
modules/gui/qt4/components/epg/EPGView.cpp
modules/gui/qt4/components/epg/EPGView.hpp
modules/gui/qt4/components/epg/EPGWidget.cpp

index 1296f7b68cb8111b5d2ae39bdf68e157b9974bb9..c246abe232ac33656fddcdb4ea72c6ac2362fd3f 100644 (file)
 #define EPGEVENT_H
 
 class QString;
+class EPGItem;
 #include <QDateTime>
 
 class EPGEvent
 {
 public:
     EPGEvent( const QString& eventName )
-        : current( false ), updated( true )
+        : current( false ), updated( true ), item( NULL )
     {
         name = eventName;
     }
 
+    bool operator==( const EPGEvent & other ) const
+    {
+        return start == other.start
+               && duration == other.duration
+               && name == other.name
+               && description == other.description
+               && shortDescription == other.shortDescription
+               && channelName == other.channelName
+               && current == other.current;
+    }
+
     QDateTime   start;
     int         duration;
     QString     name;
@@ -44,6 +56,8 @@ public:
     QString     channelName;
     bool        current;
     bool        updated;
+
+    EPGItem     *item;
 };
 
 #endif // EPGEVENT_H
index 432228a9f7dcb812014aff5b8a7dc184d870da0d..d1d95348de8b0ebdc769d0092468d9a16d692a01 100644 (file)
@@ -88,17 +88,16 @@ void EPGView::addEvent( EPGEvent* event )
     item->setShortDescription( event->shortDescription );
     item->setCurrent( event->current );
 
-    scene()->addItem( item );
-}
+    event->item = item;
 
-void EPGView::updateEvent( EPGEvent* event )
-{
-    //qDebug() << "Update event: " << event->name;
+    scene()->addItem( item );
 }
 
 void EPGView::delEvent( EPGEvent* event )
 {
-    //qDebug() << "Del event: " << event->name;
+    if( event->item != NULL )
+        scene()->removeItem( event->item );
+    event->item = NULL;
 }
 
 void EPGView::updateDuration()
index 8cad5bdf860d5dca1452700a2d2e169b53870b65..3cad7a553c6aa803224b9b1a77507565e9d30110 100644 (file)
@@ -45,7 +45,6 @@ public:
     const QDateTime& startTime();
 
     void            addEvent( EPGEvent* event );
-    void            updateEvent( EPGEvent* event );
     void            delEvent( EPGEvent* event );
     void            updateDuration();
 
index 59b52290eeb90148a628cd36782738e7a683b9b4..508c117fb2f21987bf45c7d71d32c24a54946198 100644 (file)
@@ -80,52 +80,42 @@ void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
 
         for ( int j = 0; j < p_epg->i_event; ++j )
         {
-            EPGEvent *item = NULL;
             vlc_epg_event_t *p_event = p_epg->pp_event[j];
             QString eventName = qfu( p_event->psz_name );
             QDateTime eventStart = QDateTime::fromTime_t( p_event->i_start );
 
             QList<EPGEvent*> events = m_events.values( channelName );
 
+            EPGEvent *item = new EPGEvent( eventName );
+            item->description = qfu( p_event->psz_description );
+            item->shortDescription = qfu( p_event->psz_short_description );
+            item->start = eventStart;
+            item->duration = p_event->i_duration;
+            item->channelName = channelName;
+            item->current = ( p_epg->p_current == p_event ) ? true : false;
+
+            bool alreadyIn = false;
+
             for ( int k = 0; k < events.count(); ++k )
             {
-                if ( events.at( k )->name == eventName &&
-                     events.at( k )->channelName == channelName &&
-                     events.at( k )->start == eventStart )
+                if ( *events.at( k ) == *item )
                 {
-                    /* Update the event. */
-                    item = events.at( k );
-                    item->updated = true;
-                    item->description = qfu( p_event->psz_description );
-                    item->shortDescription = qfu( p_event->psz_short_description );
-                    item->start = eventStart;
-                    item->duration = p_event->i_duration;
-                    item->current = ( p_epg->p_current == p_event ) ? true : false;
-
-                    if ( item->start < m_epgView->startTime() )
-                        m_epgView->setStartTime( item->start );
-
-                    m_epgView->updateEvent( item );
+                    alreadyIn = true;
+                    events.at( k )->updated = true;
                     break;
                 }
             }
 
-            if ( !item )
+            if ( !alreadyIn )
             {
-                item = new EPGEvent( eventName );
-                item->description = qfu( p_event->psz_description );
-                item->shortDescription = qfu( p_event->psz_short_description );
-                item->start = eventStart;
-                item->duration = p_event->i_duration;
-                item->channelName = channelName;
-                item->current = ( p_epg->p_current == p_event ) ? true : false;
                 m_events.insert( channelName, item );
-
                 if ( item->start < m_epgView->startTime() )
                     m_epgView->setStartTime( item->start );
 
                 m_epgView->addEvent( item );
             }
+            else
+                delete item;
         }
     }