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