]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/epg.cpp
Qt: add a bunch of virtual for destructors
[vlc] / modules / gui / qt4 / dialogs / epg.cpp
1 /*****************************************************************************
2  * epg.cpp : Epg Viewer dialog
3  ****************************************************************************
4  * Copyright © 2010 VideoLAN and AUTHORS
5  *
6  * Authors:    Jean-Baptiste Kempf <jb@videolan.org>
7  *
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.
12  *
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.
17  *
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  *****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include "dialogs/epg.hpp"
28
29 #include "components/epg/EPGWidget.hpp"
30 #include <vlc_playlist.h>
31
32 #include <QVBoxLayout>
33 #include <QSplitter>
34 #include <QLabel>
35 #include <QGroupBox>
36 #include <QPushButton>
37 #include <QTextEdit>
38 #include <QDialogButtonBox>
39 #include <QTimer>
40
41 #include "qt4.hpp"
42 #include "input_manager.hpp"
43
44 EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
45 {
46     setWindowTitle( qtr( "Program Guide" ) );
47
48     QVBoxLayout *layout = new QVBoxLayout( this );
49     layout->setMargin( 0 );
50     epg = new EPGWidget( this );
51
52     QGroupBox *descBox = new QGroupBox( qtr( "Description" ), this );
53
54     QVBoxLayout *boxLayout = new QVBoxLayout( descBox );
55
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 );
62
63     QPalette palette;
64     palette.setBrush(QPalette::Active, QPalette::Window, palette.brush( QPalette::Base ) );
65     description->setPalette( palette );
66
67     title = new QLabel( qtr( "Title" ), this );
68     title->setWordWrap( true );
69
70     boxLayout->addWidget( title );
71     boxLayout->addWidget( description );
72
73     layout->addWidget( epg, 10 );
74     layout->addWidget( descBox );
75
76     CONNECT( epg, itemSelectionChanged( EPGItem *), this, displayEvent( EPGItem *) );
77     CONNECT( THEMIM->getIM(), epgChanged(), this, updateInfos() );
78     CONNECT( THEMIM, inputChanged( input_thread_t * ), this, updateInfos() );
79
80     QDialogButtonBox *buttonsBox = new QDialogButtonBox( this );
81
82 #if 0
83     QPushButton *update = new QPushButton( qtr( "Update" ) ); // Temporary to test
84     buttonsBox->addButton( update, QDialogButtonBox::ActionRole );
85     BUTTONACT( update, updateInfos() );
86 #endif
87
88     buttonsBox->addButton( new QPushButton( qtr( "&Close" ) ),
89                            QDialogButtonBox::RejectRole );
90     boxLayout->addWidget( buttonsBox );
91     CONNECT( buttonsBox, rejected(), this, close() );
92
93     timer = new QTimer( this );
94     timer->setSingleShot( true );
95     timer->setInterval( 1000 * 60 );
96     CONNECT( timer, timeout(), this, updateInfos() );
97
98     updateInfos();
99     restoreWidgetPosition( "EPGDialog", QSize( 650, 450 ) );
100 }
101
102 EpgDialog::~EpgDialog()
103 {
104     saveWidgetPosition( "EPGDialog" );
105 }
106
107 void EpgDialog::displayEvent( EPGItem *epgItem )
108 {
109     if( !epgItem ) return;
110
111     QDateTime end = epgItem->start().addSecs( epgItem->duration() );
112     title->setText( QString("%1 - %2 : %3%4")
113                    .arg( epgItem->start().toString( "hh:mm" ) )
114                    .arg( end.toString( "hh:mm" ) )
115                    .arg( epgItem->name() )
116                    .arg( epgItem->rating() ?
117                              qtr(" (%1+ rated)").arg( epgItem->rating() ) :
118                              QString() )
119                    );
120     description->setText( epgItem->description() );
121 }
122
123 void EpgDialog::updateInfos()
124 {
125     timer->stop();
126     input_item_t *p_input_item = NULL;
127     playlist_t *p_playlist = THEPL;
128     input_thread_t *p_input_thread = playlist_CurrentInput( p_playlist ); /* w/hold */
129     if( p_input_thread )
130     {
131         PL_LOCK; /* as input_GetItem still unfixed */
132         p_input_item = input_GetItem( p_input_thread );
133         if ( p_input_item ) vlc_gc_incref( p_input_item );
134         PL_UNLOCK;
135         vlc_object_release( p_input_thread );
136         if ( p_input_item )
137         {
138             epg->updateEPG( p_input_item );
139             vlc_gc_decref( p_input_item );
140             if ( isVisible() ) timer->start();
141         }
142     }
143 }