]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/epg.cpp
Qt/EPG: Remove the update button. Improve the window layout.
[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
31 #include <QVBoxLayout>
32 #include <QSplitter>
33 #include <QLabel>
34 #include <QGroupBox>
35 #include <QPushButton>
36 #include <QTextEdit>
37
38 #include "qt4.hpp"
39 #include "input_manager.hpp"
40
41 EpgDialog::EpgDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
42 {
43     setWindowTitle( qtr( "Program Guide" ) );
44
45     QVBoxLayout *layout = new QVBoxLayout( this );
46     layout->setMargin( 0 );
47     epg = new EPGWidget( this );
48
49     QGroupBox *descBox = new QGroupBox( qtr( "Description" ), this );
50
51     QVBoxLayout *boxLayout = new QVBoxLayout( descBox );
52
53     description = new QTextEdit( this );
54     description->setReadOnly( true );
55     description->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel );
56     description->setAutoFillBackground( true );
57     description->setAlignment( Qt::AlignLeft | Qt::AlignTop );
58     description->setFixedHeight( 100 );
59
60     QPalette palette;
61     palette.setBrush(QPalette::Active, QPalette::Window, palette.brush( QPalette::Base ) );
62     description->setPalette( palette );
63
64     title = new QLabel( qtr( "Title" ), this );
65     title->setWordWrap( true );
66
67     boxLayout->addWidget( title );
68     boxLayout->addWidget( description );
69
70     layout->addWidget( epg, 10 );
71     layout->addWidget( descBox );
72
73     CONNECT( epg, itemSelectionChanged( EPGEvent *), this, showEvent( EPGEvent *) );
74     CONNECT( THEMIM->getIM(), epgChanged(), this, updateInfos() );
75
76 #if 0
77     QPushButton *update = new QPushButton( qtr( "Update" ) ); // Temporary to test
78     boxLayout->addWidget( update, 0, Qt::AlignRight );
79     BUTTONACT( update, updateInfos() );
80 #endif
81
82     QPushButton *close = new QPushButton( qtr( "&Close" ) );
83     boxLayout->addWidget( close, 0, Qt::AlignRight );
84     BUTTONACT( close, close() );
85
86     updateInfos();
87     readSettings( "EPGDialog", QSize( 650, 450 ) );
88 }
89
90 EpgDialog::~EpgDialog()
91 {
92     writeSettings( "EPGDialog" );
93 }
94
95 void EpgDialog::showEvent( EPGEvent *event )
96 {
97     if( !event ) return;
98
99     QString titleDescription, textDescription;
100     if( event->description.isEmpty() )
101         textDescription = event->shortDescription;
102     else
103     {
104         textDescription = event->description;
105         if( !event->shortDescription.isEmpty() )
106             titleDescription = " - " + event->shortDescription;
107     }
108
109     QDateTime end = event->start.addSecs( event->duration );
110     title->setText( event->start.toString( "hh:mm" ) + " - "
111                     + end.toString( "hh:mm" ) + " : "
112                     + event->name + titleDescription );
113
114     description->setText( textDescription );
115 }
116
117 void EpgDialog::updateInfos()
118 {
119     if( !THEMIM->getInput() ) return;
120
121     msg_Dbg( p_intf, "Found %i EPG items", input_GetItem( THEMIM->getInput())->i_epg);
122     epg->updateEPG( input_GetItem( THEMIM->getInput())->pp_epg, input_GetItem( THEMIM->getInput())->i_epg );
123
124 }