]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Use Header capitalisation for dialogs titles.
[vlc] / modules / gui / qt4 / dialogs / mediainfo.cpp
1 /*****************************************************************************
2  * mediainfo.cpp : Information about an item
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  ******************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "dialogs/mediainfo.hpp"
29 #include "input_manager.hpp"
30 #include "dialogs_provider.hpp"
31
32 #include <QTabWidget>
33 #include <QGridLayout>
34 #include <QLineEdit>
35 #include <QLabel>
36
37 MediaInfoDialog *MediaInfoDialog::instance = NULL;
38
39 /* This Dialog has two main modes:
40     - General Mode that shows the current Played item, and the stats
41     - Single mode that shows the info on ONE SINGLE Item on the playlist
42    Please be Careful of not breaking one the modes behaviour... */
43
44 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
45                                   input_item_t *_p_item,
46                                   bool _mainInput,
47                                   bool _stats ) :
48                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
49                                   stats( _stats )
50 {
51     p_item = _p_item;
52     b_cleaned = true;
53     i_runs = 0;
54
55     setWindowTitle( qtr( "Media Information" ) );
56     resize( 600 , 480 );
57
58     /* TabWidgets and Tabs creation */
59     IT = new QTabWidget;
60     MP = new MetaPanel( IT, p_intf );
61     IT->addTab( MP, qtr( "&General" ) );
62     EMP = new ExtraMetaPanel( IT, p_intf );
63     IT->addTab( EMP, qtr( "&Extra Metadata" ) );
64     IP = new InfoPanel( IT, p_intf );
65     IT->addTab( IP, qtr( "&Codec Details" ) );
66     if( stats )
67     {
68         ISP = new InputStatsPanel( IT, p_intf );
69         IT->addTab( ISP, qtr( "&Statistics" ) );
70     }
71
72     QGridLayout *layout = new QGridLayout( this );
73
74     /* No need to use a QDialogButtonBox here */
75     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
76     saveMetaButton->hide();
77     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
78     closeButton->setDefault( true );
79
80     uriLine = new QLineEdit;
81     QLabel *uriLabel = new QLabel( qtr( "Location:" ) );
82
83     layout->addWidget( IT, 0, 0, 1, 8 );
84     layout->addWidget( uriLabel, 1, 0, 1, 1 );
85     layout->addWidget( uriLine, 1, 1, 1, 7 );
86     layout->addWidget( saveMetaButton, 2, 6 );
87     layout->addWidget( closeButton, 2, 7 );
88
89     BUTTONACT( closeButton, close() );
90
91     /* The tabs buttons are shown in the main dialog for space and cosmetics */
92     CONNECT( saveMetaButton, clicked(), this, saveMeta() );
93
94     /* Let the MetaData Panel update the URI */
95     CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
96     CONNECT( MP, editing(), this, showMetaSaveButton() );
97
98     CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
99
100     /* If using the General Mode */
101     if( !p_item )
102     {
103         msg_Dbg( p_intf, "Using a general windows" );
104         CONNECT( THEMIM, inputChanged( input_thread_t * ),
105                  this, update( input_thread_t * ) );
106
107         if( THEMIM->getInput() )
108             p_item = input_GetItem( THEMIM->getInput() );
109     }
110
111     /* Call update by hand, so info is shown from current item too */
112     if( p_item )
113         update( p_item, true, true );
114
115     if( stats )
116         ON_TIMEOUT( updateOnTimeOut() );
117 }
118
119 MediaInfoDialog::~MediaInfoDialog()
120 {
121     writeSettings( "mediainfo" );
122 }
123
124 void MediaInfoDialog::showTab( int i_tab = 0 )
125 {
126     IT->setCurrentIndex( i_tab );
127     show();
128 }
129
130 void MediaInfoDialog::showMetaSaveButton()
131 {
132     saveMetaButton->show();
133 }
134
135 void MediaInfoDialog::saveMeta()
136 {
137     MP->saveMeta();
138     saveMetaButton->hide();
139 }
140
141 /* Function called on inputChanged-update*/
142 void MediaInfoDialog::update( input_thread_t *p_input )
143 {
144     if( !p_input || p_input->b_dead )
145     {
146         if( !b_cleaned )
147         {
148             clear();
149             b_cleaned = true;
150         }
151         return;
152     }
153
154     /* Launch the update in all the panels */
155     vlc_object_yield( p_input );
156
157     update( input_GetItem(p_input), true, true);
158
159     vlc_object_release( p_input );
160 }
161
162 void MediaInfoDialog::updateOnTimeOut()
163 {
164     /* Timer runs at 150 ms, dont' update more than 2 times per second */
165     i_runs++;
166     if( i_runs % 4 != 0 ) return;
167
168     /* Get Input and clear if non-existant */
169     input_thread_t *p_input = THEMIM->getInput();
170
171     if( p_input && !p_input->b_dead )
172     {
173         vlc_object_yield( p_input );
174         update( input_GetItem(p_input), false, false);
175         vlc_object_release( p_input );
176     }
177 }
178
179 void MediaInfoDialog::update( input_item_t *p_item,
180                               bool update_info,
181                               bool update_meta )
182 {
183     if( update_info )
184         IP->update( p_item );
185     if( update_meta )
186     {
187         MP->update( p_item );
188         EMP->update( p_item );
189     }
190     if( stats )
191         ISP->update( p_item );
192 }
193
194 void MediaInfoDialog::clear()
195 {
196     IP->clear();
197     MP->clear();
198     EMP->clear();
199     if( stats ) ISP->clear();
200     b_cleaned = true;
201 }
202
203 void MediaInfoDialog::close()
204 {
205     toggleVisible();
206
207     /* if dialog is closed, revert editing if not saved */
208     if( MP->isInEditMode() )
209     {
210         MP->setEditMode( false );
211         updateButtons( 0 );
212     }
213     if( mainInput == false ) {
214         deleteLater();
215     }
216 }
217
218 void MediaInfoDialog::updateButtons( int i_tab )
219 {
220     if( MP->isInEditMode() && i_tab == 0 )
221         saveMetaButton->show();
222     else
223         saveMetaButton->hide();
224 }