]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/epg/EPGWidget.cpp
qt4: toggleAdvanced simplifications
[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 <QStackedWidget>
31 #include <QVBoxLayout>
32 #include <QScrollBar>
33 #include <QLabel>
34 #include <QStringList>
35 #include "qt4.hpp"
36 #include "input_manager.hpp"
37 #include <vlc_common.h>
38 #include <vlc_epg.h>
39
40 enum
41 {
42     EPGVIEW_WIDGET = 0,
43     NOEPG_WIDGET = 1
44 };
45
46 EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
47 {
48     b_input_type_known = false;
49     m_rulerWidget = new EPGRuler( this );
50     m_epgView = new EPGView( this );
51     m_channelsWidget = new EPGChannels( this, m_epgView );
52
53     m_channelsWidget->setMinimumWidth( 100 );
54
55     m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
56     setZoom( 1 );
57
58     rootWidget = new QStackedWidget( this );
59
60     QWidget *containerWidget = new QWidget( this );
61     QGridLayout* layout = new QGridLayout( this );
62     layout->addWidget( m_rulerWidget, 0, 1 );
63     layout->addWidget( m_channelsWidget, 1, 0 );
64     layout->addWidget( m_epgView, 1, 1 );
65     layout->setSpacing( 0 );
66     containerWidget->setLayout( layout );
67     rootWidget->insertWidget( EPGVIEW_WIDGET, containerWidget );
68
69     QLabel *noepgLabel = new QLabel( qtr("No EPG Data Available"), this );
70     noepgLabel->setAlignment( Qt::AlignCenter );
71     rootWidget->insertWidget( NOEPG_WIDGET, noepgLabel );
72
73     rootWidget->setCurrentIndex( 1 );
74     layout = new QGridLayout( this );
75     layout->addWidget( rootWidget );
76     setLayout( layout );
77
78     CONNECT( m_epgView, startTimeChanged(QDateTime),
79              m_rulerWidget, setStartTime(QDateTime) );
80     CONNECT( m_epgView, durationChanged(int),
81              m_rulerWidget, setDuration(int) );
82     CONNECT( m_epgView->horizontalScrollBar(), valueChanged(int),
83              m_rulerWidget, setOffset(int) );
84     CONNECT( m_epgView->verticalScrollBar(), valueChanged(int),
85              m_channelsWidget, setOffset(int) );
86     connect( m_epgView, SIGNAL( itemFocused(EPGItem*)),
87              this, SIGNAL(itemSelectionChanged(EPGItem*)) );
88     CONNECT( m_epgView, channelAdded(QString), m_channelsWidget, addChannel(QString) );
89     CONNECT( m_epgView, channelRemoved(QString), m_channelsWidget, removeChannel(QString) );
90 }
91
92 void EPGWidget::reset()
93 {
94     m_epgView->reset();
95     m_epgView->updateDuration();
96     m_epgView->updateStartTime();
97 }
98
99 void EPGWidget::setZoom( int level )
100 {
101     double scale = (double)level / 20;
102     m_epgView->setScale( scale );
103     m_rulerWidget->setScale( scale );
104 }
105
106 void EPGWidget::updateEPG( input_item_t *p_input_item )
107 {
108     if( !p_input_item ) return;
109
110     /* flush our EPG data if input type has changed */
111     if ( b_input_type_known && p_input_item->i_type != i_event_source_type ) m_epgView->reset();
112     i_event_source_type = p_input_item->i_type;
113     b_input_type_known = true;
114
115     m_epgView->cleanup(); /* expire items and flags */
116     /* Fixme: input could have dissapeared */
117     vlc_mutex_lock(  & p_input_item->lock );
118
119     for ( int i = 0; i < p_input_item->i_epg; ++i )
120     {
121         vlc_epg_t *p_epg = p_input_item->pp_epg[i];
122
123         /* Read current epg events from libvlc and try to insert them */
124         for ( int j = 0; j < p_epg->i_event; ++j )
125         {
126             vlc_epg_event_t *p_event = p_epg->pp_event[j];
127             m_epgView->addEPGEvent( p_event, qfu( p_epg->psz_name ),
128                                     ( p_epg->p_current == p_event ) );
129         }
130     }
131     vlc_mutex_unlock( & p_input_item->lock );
132
133     /* toggle our widget view */
134     rootWidget->setCurrentIndex(
135             m_epgView->hasValidData() ? EPGVIEW_WIDGET : NOEPG_WIDGET );
136
137     // Update the global duration and start time.
138     m_epgView->updateDuration();
139     m_epgView->updateStartTime();
140 }
141