]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/epg/EPGWidget.cpp
epg: remove the external channels widget
[vlc] / modules / gui / qt4 / components / epg / EPGWidget.cpp
1 /*****************************************************************************
2  * EPGWidget.h : EPGWidget
3  ****************************************************************************
4  * Copyright © 2009-2010 VideoLAN
5  * $Id$
6  *
7  * Authors: Ludovic Fauvet <etix@l0cal.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include "EPGWidget.hpp"
29
30 #include <QVBoxLayout>
31 #include <QScrollBar>
32 #include <QDebug>
33 #include <QLabel>
34 #include "qt4.hpp"
35
36 EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
37 {
38     m_rulerWidget = new EPGRuler( this );
39     m_epgView = new EPGView( this );
40
41     m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
42     setZoom( 1 );
43
44     QVBoxLayout* layout = new QVBoxLayout( this );
45     layout->addWidget( m_rulerWidget );
46     layout->addWidget( m_epgView );
47     layout->setSpacing( 0 );
48     setLayout( layout );
49
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*)) );
58 }
59
60 void EPGWidget::setZoom( int level )
61 {
62     double scale = (double)level / 20;
63     m_epgView->setScale( scale );
64     m_rulerWidget->setScale( scale );
65 }
66
67 void EPGWidget::updateEPG( vlc_epg_t **pp_epg, int i_epg )
68 {
69     m_epgView->setStartTime( QDateTime::currentDateTime() );
70     for ( int i = 0; i < i_epg; ++i )
71     {
72         vlc_epg_t *p_epg = pp_epg[i];
73         QString channelName = qfu( p_epg->psz_name );
74
75         for ( int j = 0; j < p_epg->i_event; ++j )
76         {
77             EPGEvent *item = NULL;
78             vlc_epg_event_t *p_event = p_epg->pp_event[j];
79             QString eventName = qfu( p_event->psz_name );
80
81             QList<EPGEvent*> events = m_events.values( channelName );
82
83             for ( int k = 0; k < events.count(); ++k )
84             {
85                 if ( events.at( k )->name == eventName &&
86                      events.at( k )->channelName == channelName )
87                 {
88                     item = events.at( k );
89                     item->updated = true;
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;
95
96                     if ( item->start < m_epgView->startTime() )
97                         m_epgView->setStartTime( item->start );
98
99                     m_epgView->updateEvent( item );
100                     break;
101                 }
102             }
103
104             if ( !item )
105             {
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 );
114
115                 if ( item->start < m_epgView->startTime() )
116                     m_epgView->setStartTime( item->start );
117
118                 m_epgView->addEvent( item );
119             }
120         }
121     }
122
123     // Remove old items
124     QMap<QString, EPGEvent*>::iterator i = m_events.begin();
125     while ( i != m_events.end() )
126     {
127         EPGEvent* item = i.value();
128         if ( !item->updated )
129         {
130             m_epgView->delEvent( item );
131             delete item;
132             i = m_events.erase( i );
133         }
134         else
135             item->updated = false;
136
137         ++i;
138     }
139
140     // Update the global duration
141     m_epgView->updateDuration();
142 }
143