]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Qt4 - We DO need pulling for the stats in MediaInfo Dialog... Revert part of 23590.
[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
25 #include "dialogs/mediainfo.hpp"
26 #include "input_manager.hpp"
27 #include "dialogs_provider.hpp"
28
29 #include <QTabWidget>
30 #include <QGridLayout>
31 #include <QLineEdit>
32 #include <QLabel>
33
34 MediaInfoDialog *MediaInfoDialog::instance = NULL;
35
36 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
37                                   input_item_t *_p_item,
38                                   bool _mainInput,
39                                   bool _stats ) :
40                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
41                                   stats( _stats )
42 {
43     p_item = _p_item;
44     b_cleaned = true;
45     i_runs = 0;
46
47     setWindowTitle( qtr( "Media information" ) );
48     resize( 600 , 480 );
49
50     /* TabWidgets and Tabs creation */
51     IT = new QTabWidget;
52     MP = new MetaPanel( IT, p_intf );
53     IT->addTab( MP, qtr( "&General" ) );
54     EMP = new ExtraMetaPanel( IT, p_intf );
55     IT->addTab( EMP, qtr( "&Extra Metadata" ) );
56     IP = new InfoPanel( IT, p_intf );
57     IT->addTab( IP, qtr( "&Codec Details" ) );
58     if( stats )
59     {
60         ISP = new InputStatsPanel( IT, p_intf );
61         IT->addTab( ISP, qtr( "&Statistics" ) );
62     }
63
64     QGridLayout *layout = new QGridLayout( this );
65
66     /* No need to use a QDialogButtonBox here */
67     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
68     saveMetaButton->hide();
69     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
70     closeButton->setDefault( true );
71
72     uriLine = new QLineEdit;
73     QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
74
75     layout->addWidget( IT, 0, 0, 1, 8 );
76     layout->addWidget( uriLabel, 1, 0, 1, 1 );
77     layout->addWidget( uriLine, 1, 1, 1, 7 );
78     layout->addWidget( saveMetaButton, 2, 6 );
79     layout->addWidget( closeButton, 2, 7 );
80
81     BUTTONACT( closeButton, close() );
82
83     /* The tabs buttons are shown in the main dialog for space and cosmetics */
84     CONNECT( saveMetaButton, clicked(), this, saveMeta() );
85
86     /* Let the MetaData Panel update the URI */
87     CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
88     CONNECT( MP, editing(), this, showMetaSaveButton() );
89
90     CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
91
92     CONNECT( THEMIM, inputChanged( input_thread_t * ), this, update( input_thread_t * ) );
93
94     /* Call update by hand, so info is shown from current item too */
95     if( THEMIM->getInput() )
96         update( input_GetItem(THEMIM->getInput() ), true, true );
97     if( stats )
98         ON_TIMEOUT( updateOnTimeOut() );
99 }
100
101 MediaInfoDialog::~MediaInfoDialog()
102 {
103     writeSettings( "mediainfo" );
104 }
105
106 void MediaInfoDialog::showTab( int i_tab = 0 )
107 {
108     IT->setCurrentIndex( i_tab );
109     show();
110 }
111
112 void MediaInfoDialog::showMetaSaveButton()
113 {
114     saveMetaButton->show();
115 }
116
117 void MediaInfoDialog::saveMeta()
118 {
119     MP->saveMeta();
120     saveMetaButton->hide();
121 }
122
123 /* Function called on inputChanged-update*/
124 void MediaInfoDialog::update( input_thread_t *p_input )
125 {
126     if( !p_input || p_input->b_dead )
127     {
128         if( !b_cleaned )
129         {
130             clear();
131             b_cleaned = true;
132         }
133         return;
134     }
135
136     /* Launch the update in all the panels */
137     vlc_object_yield( p_input );
138
139     update( input_GetItem(p_input), true, true);
140
141     vlc_object_release( p_input );
142 }
143
144 void MediaInfoDialog::updateOnTimeOut() 
145 {
146     /* Timer runs at 150 ms, dont' update more than 2 times per second */ 
147     i_runs++; 
148     if( i_runs % 4 != 0 ) return; 
149
150     /* Get Input and clear if non-existant */ 
151     input_thread_t *p_input = THEMIM->getInput(); 
152
153     if( p_input && !p_input->b_dead )
154     {
155         vlc_object_yield( p_input );
156         update( input_GetItem(p_input), false, false);
157         vlc_object_release( p_input );
158     }
159 }
160
161 void MediaInfoDialog::update( input_item_t *p_item,
162                               bool update_info,
163                               bool update_meta )
164 {
165     if( update_info )
166         IP->update( p_item );
167     if( update_meta )
168     {
169         MP->update( p_item );
170         EMP->update( p_item );
171     }
172     if( stats )
173         ISP->update( p_item );
174 }
175
176 void MediaInfoDialog::clear()
177 {
178     IP->clear();
179     MP->clear();
180     EMP->clear();
181     if( stats ) ISP->clear();
182     b_cleaned = true;
183 }
184
185 void MediaInfoDialog::close()
186 {
187     this->toggleVisible();
188
189     /* if dialog is closed, revert editing if not saved */
190     if( MP->isInEditMode() )
191     {
192         MP->setEditMode( false );
193         updateButtons( 0 );
194     }
195     if( mainInput == false ) {
196         deleteLater();
197     }
198 }
199
200 void MediaInfoDialog::updateButtons( int i_tab )
201 {
202     if( MP->isInEditMode() && i_tab == 0 )
203         saveMetaButton->show();
204     else
205         saveMetaButton->hide();
206 }