Commit 2f1aa52f authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: don't throw previous EPG data on channel/input switch

parent 887ad85c
...@@ -48,6 +48,12 @@ public: ...@@ -48,6 +48,12 @@ public:
&& current == other.current; && current == other.current;
} }
bool ends_before( const QDateTime & ref ) const
{
QDateTime start_ = start;
return start_.addSecs( duration ) < ref;
}
QDateTime start; QDateTime start;
int duration; int duration;
QString name; QString name;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QDebug> #include <QDebug>
#include <QLabel> #include <QLabel>
#include <QStringList>
#include "qt4.hpp" #include "qt4.hpp"
EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent ) EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
...@@ -72,20 +73,32 @@ void EPGWidget::setZoom( int level ) ...@@ -72,20 +73,32 @@ void EPGWidget::setZoom( int level )
void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg ) void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
{ {
QStringList channelsList;
EPGEvent* item;
/* FIXME: dvb time might be from the next timezone */
QDateTime timeReference = QDateTime::currentDateTime();
/* flag all entries as non updated */
foreach( const QString &str, m_events.uniqueKeys() )
foreach( item, m_events.values( str ) )
item->updated = false;
for ( int i = 0; i < i_epg; ++i ) for ( int i = 0; i < i_epg; ++i )
{ {
vlc_epg_t *p_epg = pp_epg[i]; vlc_epg_t *p_epg = pp_epg[i];
QString channelName = qfu( p_epg->psz_name ); QString channelName = qfu( p_epg->psz_name );
channelsList.append( channelName );
/* Read current epg events from libvlc and try to insert them */
for ( int j = 0; j < p_epg->i_event; ++j ) for ( int j = 0; j < p_epg->i_event; ++j )
{ {
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 );
/* ensure we display ongoing item */
if ( eventStart < timeReference ) timeReference = eventStart;
QList<EPGEvent*> events = m_events.values( channelName ); QList<EPGEvent*> events = m_events.values( channelName );
EPGEvent *item = new EPGEvent( eventName ); item = new EPGEvent( eventName );
item->description = qfu( p_event->psz_description ); item->description = qfu( p_event->psz_description );
item->shortDescription = qfu( p_event->psz_short_description ); item->shortDescription = qfu( p_event->psz_short_description );
item->start = eventStart; item->start = eventStart;
...@@ -110,27 +123,34 @@ void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg ) ...@@ -110,27 +123,34 @@ void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
m_events.insert( channelName, item ); m_events.insert( channelName, item );
m_epgView->addEvent( item ); m_epgView->addEvent( item );
} }
else else /* the new item is unused */
delete item; delete item;
} }
} }
// Remove old items /* Remove old (not in current epg list) items for current tuned channels */
/* and try to keep previously tuned in channels data */
QMultiMap<QString, EPGEvent*>::iterator i = m_events.begin(); QMultiMap<QString, EPGEvent*>::iterator i = m_events.begin();
while ( i != m_events.end() ) while ( i != m_events.end() )
{ {
EPGEvent* item = i.value(); item = i.value();
if ( !item->updated ) if ( channelsList.contains( item->channelName ) && !item->updated )
{ {
m_epgView->delEvent( item ); m_epgView->delEvent( item );
delete item; delete item;
--i; i = m_events.erase( i );
m_events.erase( i + 1 );
} }
else else
item->updated = false; {/* If it's known but not in current libvlc data, try to expire it */
if ( item->ends_before( timeReference ) )
++i; {
m_epgView->delEvent( item );
delete item;
i = m_events.erase( i );
}
else
++i;
}
} }
// Update the global duration and start time. // Update the global duration and start time.
......
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