1 /*****************************************************************************
2 * Epg.cpp : Epg Viewer dialog
3 ****************************************************************************
4 * Copyright © 2010 VideoLAN and AUTHORS
6 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
27 #include "dialogs/epg.hpp"
29 #include "components/epg/EPGWidget.hpp"
30 #include <vlc_playlist.h>
32 #include <QVBoxLayout>
36 #include <QPushButton>
38 #include <QDialogButtonBox>
42 #include "input_manager.hpp"
44 EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
46 setWindowTitle( qtr( "Program Guide" ) );
48 QVBoxLayout *layout = new QVBoxLayout( this );
49 layout->setMargin( 0 );
50 epg = new EPGWidget( this );
52 QGroupBox *descBox = new QGroupBox( qtr( "Description" ), this );
54 QVBoxLayout *boxLayout = new QVBoxLayout( descBox );
56 description = new QTextEdit( this );
57 description->setReadOnly( true );
58 description->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );
59 description->setAutoFillBackground( true );
60 description->setAlignment( Qt::AlignLeft | Qt::AlignTop );
61 description->setFixedHeight( 100 );
64 palette.setBrush(QPalette::Active, QPalette::Window, palette.brush( QPalette::Base ) );
65 description->setPalette( palette );
67 title = new QLabel( qtr( "Title" ), this );
68 title->setWordWrap( true );
70 boxLayout->addWidget( title );
71 boxLayout->addWidget( description );
73 layout->addWidget( epg, 10 );
74 layout->addWidget( descBox );
76 CONNECT( epg, itemSelectionChanged( EPGItem *), this, showEvent( EPGItem *) );
77 CONNECT( THEMIM->getIM(), epgChanged(), this, updateInfos() );
78 CONNECT( THEMIM, inputChanged( input_thread_t * ), this, updateInfos() );
80 QDialogButtonBox *buttonsBox = new QDialogButtonBox( this );
83 QPushButton *update = new QPushButton( qtr( "Update" ) ); // Temporary to test
84 buttonsBox->addButton( update, QDialogButtonBox::ActionRole );
85 BUTTONACT( update, updateInfos() );
88 buttonsBox->addButton( new QPushButton( qtr( "&Close" ) ),
89 QDialogButtonBox::RejectRole );
90 boxLayout->addWidget( buttonsBox );
91 CONNECT( buttonsBox, rejected(), this, close() );
93 timer = new QTimer( this );
94 timer->setSingleShot( true );
95 timer->setInterval( 1000 * 60 );
96 CONNECT( timer, timeout(), this, updateInfos() );
99 readSettings( "EPGDialog", QSize( 650, 450 ) );
102 EpgDialog::~EpgDialog()
104 writeSettings( "EPGDialog" );
107 void EpgDialog::showEvent( EPGItem *epgItem )
109 if( !epgItem ) return;
111 QDateTime end = epgItem->start().addSecs( epgItem->duration() );
112 title->setText( QString("%1 - %2 : %3")
113 .arg( epgItem->start().toString( "hh:mm" ) )
114 .arg( end.toString( "hh:mm" ) )
115 .arg( epgItem->name() )
117 description->setText( epgItem->description() );
120 void EpgDialog::updateInfos()
123 input_item_t *p_input_item = NULL;
124 playlist_t *p_playlist = THEPL;
125 input_thread_t *p_input_thread = playlist_CurrentInput( p_playlist ); /* w/hold */
128 PL_LOCK; /* as input_GetItem still unfixed */
129 p_input_item = input_GetItem( p_input_thread );
130 if ( p_input_item ) vlc_gc_incref( p_input_item );
132 vlc_object_release( p_input_thread );
135 epg->updateEPG( p_input_item );
136 vlc_gc_decref( p_input_item );
137 if ( isVisible() ) timer->start();