]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Qt4 - File renaming for consistency.
[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 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
35                         vlc_value_t oldval, vlc_value_t newval, void *param );
36 MediaInfoDialog *MediaInfoDialog::instance = NULL;
37
38 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
39                                   bool _stats ) :
40                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
41                                   stats( _stats )
42 {
43     i_runs = 0;
44     p_input = NULL;
45     b_need_update = true;
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     /* FIXME GNOME/KDE ? */
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, editMeta() );
89
90     CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
91
92     /* Create the main Update function with a time (150ms) */
93     if( mainInput ) {
94         ON_TIMEOUT( update() );
95         var_AddCallback( THEPL, "item-change", ItemChanged, this );
96     }
97 }
98
99 MediaInfoDialog::~MediaInfoDialog()
100 {
101     if( mainInput ) {
102         var_DelCallback( THEPL, "item-change", ItemChanged, this );
103     }
104     writeSettings( "mediainfo" );
105 }
106
107 void MediaInfoDialog::showTab( int i_tab = 0 )
108 {
109     this->show();
110     IT->setCurrentIndex( i_tab );
111 }
112
113 void MediaInfoDialog::editMeta()
114 {
115     saveMetaButton->show();
116 }
117
118 void MediaInfoDialog::saveMeta()
119 {
120     MP->saveMeta();
121     saveMetaButton->hide();
122 }
123
124 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
125         vlc_value_t oldval, vlc_value_t newval, void *param )
126 {
127     MediaInfoDialog *p_d = (MediaInfoDialog *)param;
128     p_d->b_need_update = VLC_TRUE;
129     return VLC_SUCCESS;
130 }
131
132 void MediaInfoDialog::setInput( input_item_t *p_input )
133 {
134     clear();
135     update( p_input, true, true );
136     /* if info is from current input, don't set default to edit, if user opens
137      * some other item, se default to edit, so it won't be updated to current item metas
138      *
139      * This really doesn't seem as clean solution as it could be
140      */
141     input_thread_t *p_current =
142                      MainInputManager::getInstance( p_intf )->getInput();
143     MP->setEditMode( ( !p_current || p_current->b_dead || input_GetItem( p_current ) != p_input ) ?
144                             true: false );
145 }
146
147 void MediaInfoDialog::update()
148 {
149     /* Timer runs at 150 ms, dont' update more than 2 times per second */
150     i_runs++;
151     if( i_runs % 4 != 0 ) return;
152
153     /* Get Input and clear if non-existant */
154     input_thread_t *p_input =
155                      MainInputManager::getInstance( p_intf )->getInput();
156     if( !p_input || p_input->b_dead )
157     {
158         clear();
159         return;
160     }
161
162     vlc_object_yield( p_input );
163
164     update( input_GetItem(p_input), b_need_update, b_need_update );
165     b_need_update = false;
166
167     vlc_object_release( p_input );
168 }
169
170 void MediaInfoDialog::update( input_item_t *p_item,
171                                                  bool update_info,
172                                                  bool update_meta )
173 {
174     MP->setInput( p_item );
175     if( update_info )
176         IP->update( p_item );
177     if( update_meta )
178     {
179         MP->update( p_item );
180         EMP->update( p_item );
181     }
182     if( stats )
183         ISP->update( p_item );
184 }
185
186 void MediaInfoDialog::clear()
187 {
188     IP->clear();
189     MP->clear();
190     EMP->clear();
191     if( stats ) ISP->clear();
192 }
193
194 void MediaInfoDialog::close()
195 {
196     this->toggleVisible();
197
198     if( mainInput == false ) {
199         deleteLater();
200     }
201     MP->setEditMode( false );
202 }
203
204 void MediaInfoDialog::updateButtons( int i_tab )
205 {
206     if( MP->isInEditMode() && i_tab == 0 )
207         saveMetaButton->show();
208     else
209         saveMetaButton->hide();
210 }