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 <QStackedWidget>
31 #include <QVBoxLayout>
34 #include <QStringList>
36 #include "input_manager.hpp"
37 #include <vlc_common.h>
46 EPGWidget::EPGWidget( QWidget *parent ) : QWidget( parent )
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 );
53 m_channelsWidget->setMinimumWidth( 100 );
55 m_epgView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
58 rootWidget = new QStackedWidget( this );
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 );
69 QLabel *noepgLabel = new QLabel( qtr("No EPG Data Available"), this );
70 noepgLabel->setAlignment( Qt::AlignCenter );
71 rootWidget->insertWidget( NOEPG_WIDGET, noepgLabel );
73 rootWidget->setCurrentIndex( 1 );
74 layout = new QGridLayout( this );
75 layout->addWidget( rootWidget );
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) );
92 void EPGWidget::reset()
95 m_epgView->updateDuration();
96 m_epgView->updateStartTime();
99 void EPGWidget::setZoom( int level )
101 double scale = (double)level / 20;
102 m_epgView->setScale( scale );
103 m_rulerWidget->setScale( scale );
106 void EPGWidget::updateEPG( input_item_t *p_input_item )
108 if( !p_input_item ) return;
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;
115 m_epgView->cleanup(); /* expire items and flags */
116 /* Fixme: input could have dissapeared */
117 vlc_mutex_lock( & p_input_item->lock );
119 for ( int i = 0; i < p_input_item->i_epg; ++i )
121 vlc_epg_t *p_epg = p_input_item->pp_epg[i];
123 /* Read current epg events from libvlc and try to insert them */
124 for ( int j = 0; j < p_epg->i_event; ++j )
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 ) );
131 vlc_mutex_unlock( & p_input_item->lock );
133 /* toggle our widget view */
134 rootWidget->setCurrentIndex(
135 m_epgView->hasValidData() ? EPGVIEW_WIDGET : NOEPG_WIDGET );
137 // Update the global duration and start time.
138 m_epgView->updateDuration();
139 m_epgView->updateStartTime();