1 /*****************************************************************************
2 * EPGWidget.h : EPGWidget
3 ****************************************************************************
4 * Copyright © 2009-2010 VideoLAN
7 * Authors: Ludovic Fauvet <etix@l0cal.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "EPGWidget.hpp"
30 #include <QVBoxLayout>
36 EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
38 m_rulerWidget = new EPGRuler( this );
39 m_epgView = new EPGView( this );
41 m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
44 QVBoxLayout* layout = new QVBoxLayout( this );
45 layout->addWidget( m_rulerWidget );
46 layout->addWidget( m_epgView );
47 layout->setSpacing( 0 );
50 connect( m_epgView, SIGNAL( startTimeChanged(QDateTime) ),
51 m_rulerWidget, SLOT( setStartTime(QDateTime) ) );
52 connect( m_epgView, SIGNAL( durationChanged(int) ),
53 m_rulerWidget, SLOT( setDuration(int) ) );
54 connect( m_epgView->horizontalScrollBar(), SIGNAL( valueChanged(int) ),
55 m_rulerWidget, SLOT( setOffset(int) ) );
56 connect( m_epgView, SIGNAL( eventFocusedChanged(EPGEvent*)),
57 this, SIGNAL(itemSelectionChanged(EPGEvent*)) );
60 void EPGWidget::setZoom( int level )
62 double scale = (double)level / 20;
63 m_epgView->setScale( scale );
64 m_rulerWidget->setScale( scale );
67 void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
69 m_epgView->setStartTime( QDateTime::currentDateTime() );
70 for ( int i = 0; i < i_epg; ++i )
72 vlc_epg_t *p_epg = pp_epg[i];
73 QString channelName = qfu( p_epg->psz_name );
75 for ( int j = 0; j < p_epg->i_event; ++j )
77 EPGEvent *item = NULL;
78 vlc_epg_event_t *p_event = p_epg->pp_event[j];
79 QString eventName = qfu( p_event->psz_name );
81 QList<EPGEvent*> events = m_events.values( channelName );
83 for ( int k = 0; k < events.count(); ++k )
85 if ( events.at( k )->name == eventName &&
86 events.at( k )->channelName == channelName )
88 item = events.at( k );
90 item->description = qfu( p_event->psz_description );
91 item->shortDescription = qfu( p_event->psz_short_description );
92 item->start = QDateTime::fromTime_t( p_event->i_start );
93 item->duration = p_event->i_duration;
94 item->current = ( p_epg->p_current == p_event ) ? true : false;
96 if ( item->start < m_epgView->startTime() )
97 m_epgView->setStartTime( item->start );
99 m_epgView->updateEvent( item );
106 item = new EPGEvent( eventName );
107 item->description = qfu( p_event->psz_description );
108 item->shortDescription = qfu( p_event->psz_short_description );
109 item->start = QDateTime::fromTime_t( p_event->i_start );
110 item->duration = p_event->i_duration;
111 item->channelName = channelName;
112 item->current = ( p_epg->p_current == p_event ) ? true : false;
113 m_events.insert( channelName, item );
115 if ( item->start < m_epgView->startTime() )
116 m_epgView->setStartTime( item->start );
118 m_epgView->addEvent( item );
124 QMap<QString, EPGEvent*>::iterator i = m_events.begin();
125 while ( i != m_events.end() )
127 EPGEvent* item = i.value();
128 if ( !item->updated )
130 m_epgView->delEvent( item );
132 i = m_events.erase( i );
135 item->updated = false;
140 // Update the global duration
141 m_epgView->updateDuration();