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 <QGridLayout>
36 ChannelsWidget::ChannelsWidget( QWidget *parent ) : QWidget( parent )
38 setContentsMargins( 0, 0, 0, 0 );
39 setMaximumWidth( 50 );
40 setFocusPolicy( Qt::ClickFocus );
43 EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
45 QGridLayout* layout = new QGridLayout( this );
47 m_rulerWidget = new EPGRuler( this );
48 m_channelsWidget = new ChannelsWidget( this );
49 m_epgView = new EPGView( this );
51 m_channelsWidget->setMinimumWidth( 40 );
53 m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
56 layout->addWidget( m_rulerWidget, 0, 1 );
57 layout->addWidget( m_channelsWidget, 1, 0 );
58 layout->addWidget( m_epgView, 1, 1 );
59 layout->setSpacing( 0 );
62 connect( m_epgView, SIGNAL( startTimeChanged(QDateTime) ),
63 m_rulerWidget, SLOT( setStartTime(QDateTime) ) );
64 connect( m_epgView, SIGNAL( durationChanged(int) ),
65 m_rulerWidget, SLOT( setDuration(int) ) );
66 connect( m_epgView->horizontalScrollBar(), SIGNAL( valueChanged(int) ),
67 m_rulerWidget, SLOT( setOffset(int) ) );
68 connect( m_epgView, SIGNAL( eventFocusedChanged(EPGEvent*)),
69 this, SIGNAL(itemSelectionChanged(EPGEvent*)) );
72 void EPGWidget::setZoom( int level )
74 double scale = (double)level / 20;
75 m_epgView->setScale( scale );
76 m_rulerWidget->setScale( scale );
79 void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
81 m_epgView->setStartTime( QDateTime::currentDateTime() );
82 for ( int i = 0; i < i_epg; ++i )
84 vlc_epg_t *p_epg = pp_epg[i];
85 QString channelName = qfu( p_epg->psz_name );
87 for ( int j = 0; j < p_epg->i_event; ++j )
89 EPGEvent *item = NULL;
90 vlc_epg_event_t *p_event = p_epg->pp_event[j];
91 QString eventName = qfu( p_event->psz_name );
93 QList<EPGEvent*> events = m_events.values( channelName );
95 for ( int k = 0; k < events.count(); ++k )
97 if ( events.at( k )->name == eventName &&
98 events.at( k )->channelName == channelName )
100 item = events.at( k );
101 item->updated = true;
102 item->description = qfu( p_event->psz_description );
103 item->shortDescription = qfu( p_event->psz_short_description );
104 item->start = QDateTime::fromTime_t( p_event->i_start );
105 item->duration = p_event->i_duration;
106 item->current = ( p_epg->p_current == p_event ) ? true : false;
108 if ( item->start < m_epgView->startTime() )
109 m_epgView->setStartTime( item->start );
111 m_epgView->updateEvent( item );
118 item = new EPGEvent( eventName );
119 item->description = qfu( p_event->psz_description );
120 item->shortDescription = qfu( p_event->psz_short_description );
121 item->start = QDateTime::fromTime_t( p_event->i_start );
122 item->duration = p_event->i_duration;
123 item->channelName = channelName;
124 item->current = ( p_epg->p_current == p_event ) ? true : false;
125 m_events.insert( channelName, item );
127 if ( item->start < m_epgView->startTime() )
128 m_epgView->setStartTime( item->start );
130 m_epgView->addEvent( item );
136 QMap<QString, EPGEvent*>::iterator i = m_events.begin();
137 while ( i != m_events.end() )
139 EPGEvent* item = i.value();
140 if ( !item->updated )
142 m_epgView->delEvent( item );
144 i = m_events.erase( i );
147 item->updated = false;
152 // Update the global duration
153 m_epgView->updateDuration();