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 );
40 m_channelsWidget = new EPGChannels( this, m_epgView );
42 m_channelsWidget->setMinimumWidth( 100 );
44 m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
47 QGridLayout* layout = new QGridLayout( this );
48 layout->addWidget( m_rulerWidget, 0, 1 );
49 layout->addWidget( m_channelsWidget, 1, 0 );
50 layout->addWidget( m_epgView, 1, 1 );
51 layout->setSpacing( 0 );
54 connect( m_epgView, SIGNAL( startTimeChanged(QDateTime) ),
55 m_rulerWidget, SLOT( setStartTime(QDateTime) ) );
56 connect( m_epgView, SIGNAL( durationChanged(int) ),
57 m_rulerWidget, SLOT( setDuration(int) ) );
58 connect( m_epgView->horizontalScrollBar(), SIGNAL( valueChanged(int) ),
59 m_rulerWidget, SLOT( setOffset(int) ) );
60 connect( m_epgView->verticalScrollBar(), SIGNAL( valueChanged(int) ),
61 m_channelsWidget, SLOT( setOffset(int) ) );
62 connect( m_epgView, SIGNAL( eventFocusedChanged(EPGEvent*)),
63 this, SIGNAL(itemSelectionChanged(EPGEvent*)) );
66 void EPGWidget::setZoom( int level )
68 double scale = (double)level / 20;
69 m_epgView->setScale( scale );
70 m_rulerWidget->setScale( scale );
73 void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
75 for ( int i = 0; i < i_epg; ++i )
77 vlc_epg_t *p_epg = pp_epg[i];
78 QString channelName = qfu( p_epg->psz_name );
80 for ( int j = 0; j < p_epg->i_event; ++j )
82 vlc_epg_event_t *p_event = p_epg->pp_event[j];
83 QString eventName = qfu( p_event->psz_name );
84 QDateTime eventStart = QDateTime::fromTime_t( p_event->i_start );
86 QList<EPGEvent*> events = m_events.values( channelName );
88 EPGEvent *item = new EPGEvent( eventName );
89 item->description = qfu( p_event->psz_description );
90 item->shortDescription = qfu( p_event->psz_short_description );
91 item->start = eventStart;
92 item->duration = p_event->i_duration;
93 item->channelName = channelName;
94 item->current = ( p_epg->p_current == p_event ) ? true : false;
96 bool alreadyIn = false;
98 for ( int k = 0; k < events.count(); ++k )
100 if ( *events.at( k ) == *item )
103 events.at( k )->updated = true;
110 m_events.insert( channelName, item );
111 m_epgView->addEvent( item );
119 QMap<QString, EPGEvent*>::iterator i = m_events.begin();
120 while ( i != m_events.end() )
122 EPGEvent* item = i.value();
123 if ( !item->updated )
125 m_epgView->delEvent( item );
127 i = m_events.erase( i );
130 item->updated = false;
135 // Update the global duration and start time.
136 m_epgView->updateDuration();
137 m_epgView->updateStartTime();