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