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