Commit 753a7d15 authored by Adrien Maglo's avatar Adrien Maglo

QT/EPG: Fix EPGItem management.

Synchronize correctly with the EPG structures provided by the core.
Remove EPGItems from the EPGView when they are not anymore stored.
parent c57d47db
...@@ -25,17 +25,29 @@ ...@@ -25,17 +25,29 @@
#define EPGEVENT_H #define EPGEVENT_H
class QString; class QString;
class EPGItem;
#include <QDateTime> #include <QDateTime>
class EPGEvent class EPGEvent
{ {
public: public:
EPGEvent( const QString& eventName ) EPGEvent( const QString& eventName )
: current( false ), updated( true ) : current( false ), updated( true ), item( NULL )
{ {
name = eventName; 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; QDateTime start;
int duration; int duration;
QString name; QString name;
...@@ -44,6 +56,8 @@ public: ...@@ -44,6 +56,8 @@ public:
QString channelName; QString channelName;
bool current; bool current;
bool updated; bool updated;
EPGItem *item;
}; };
#endif // EPGEVENT_H #endif // EPGEVENT_H
...@@ -88,17 +88,16 @@ void EPGView::addEvent( EPGEvent* event ) ...@@ -88,17 +88,16 @@ void EPGView::addEvent( EPGEvent* event )
item->setShortDescription( event->shortDescription ); item->setShortDescription( event->shortDescription );
item->setCurrent( event->current ); item->setCurrent( event->current );
scene()->addItem( item ); event->item = item;
}
void EPGView::updateEvent( EPGEvent* event ) scene()->addItem( item );
{
//qDebug() << "Update event: " << event->name;
} }
void EPGView::delEvent( EPGEvent* event ) void EPGView::delEvent( EPGEvent* event )
{ {
//qDebug() << "Del event: " << event->name; if( event->item != NULL )
scene()->removeItem( event->item );
event->item = NULL;
} }
void EPGView::updateDuration() void EPGView::updateDuration()
......
...@@ -45,7 +45,6 @@ public: ...@@ -45,7 +45,6 @@ public:
const QDateTime& startTime(); const QDateTime& startTime();
void addEvent( EPGEvent* event ); void addEvent( EPGEvent* event );
void updateEvent( EPGEvent* event );
void delEvent( EPGEvent* event ); void delEvent( EPGEvent* event );
void updateDuration(); void updateDuration();
......
...@@ -80,52 +80,42 @@ void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg ) ...@@ -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 ) for ( int j = 0; j < p_epg->i_event; ++j )
{ {
EPGEvent *item = NULL;
vlc_epg_event_t *p_event = p_epg->pp_event[j]; vlc_epg_event_t *p_event = p_epg->pp_event[j];
QString eventName = qfu( p_event->psz_name ); QString eventName = qfu( p_event->psz_name );
QDateTime eventStart = QDateTime::fromTime_t( p_event->i_start ); QDateTime eventStart = QDateTime::fromTime_t( p_event->i_start );
QList<EPGEvent*> events = m_events.values( channelName ); 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 ) for ( int k = 0; k < events.count(); ++k )
{ {
if ( events.at( k )->name == eventName && if ( *events.at( k ) == *item )
events.at( k )->channelName == channelName &&
events.at( k )->start == eventStart )
{ {
/* Update the event. */ alreadyIn = true;
item = events.at( k ); events.at( k )->updated = true;
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 );
break; 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 ); m_events.insert( channelName, item );
if ( item->start < m_epgView->startTime() ) if ( item->start < m_epgView->startTime() )
m_epgView->setStartTime( item->start ); m_epgView->setStartTime( item->start );
m_epgView->addEvent( item ); m_epgView->addEvent( item );
} }
else
delete item;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment