]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
af65871d1b89cef7163c30ff41f2f28e5bdc0882
[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 #include "util/qvlcframe.hpp"
29 #include "components/infopanels.hpp"
30 #include "qt4.hpp"
31
32 #include <QTabWidget>
33 #include <QGridLayout>
34 #include <QLineEdit>
35 #include <QLabel>
36
37 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
38                         vlc_value_t oldval, vlc_value_t newval, void *param );
39 MediaInfoDialog *MediaInfoDialog::instance = NULL;
40
41 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
42                                   bool _stats ) :
43                                   QVLCFrame( _p_intf ), mainInput(_mainInput),
44                                   stats( _stats )
45 {
46     i_runs = 0;
47     p_input = NULL;
48     need_update = true;
49
50     setWindowTitle( qtr( "Media information" ) );
51     resize( 700 , 450 );
52
53     /* TabWidgets and Tabs creation */
54     IT = new QTabWidget;
55     MP = new MetaPanel( IT, p_intf );
56     IT->addTab( MP, qtr( "&General" ) );
57     EMP = new ExtraMetaPanel( IT, p_intf );
58     IT->addTab( EMP, qtr( "&Extra Metadata" ) );
59     IP = new InfoPanel( IT, p_intf );
60     IT->addTab( IP, qtr( "&Codec Details" ) );
61     if( stats )
62     {
63         ISP = new InputStatsPanel( IT, p_intf );
64         IT->addTab( ISP, qtr( "&Stats" ) );
65     }
66
67     QGridLayout *layout = new QGridLayout( this );
68
69     /* FIXME GNOME/KDE ? */
70     editMetaButton = new QPushButton( qtr( "&Edit Metadata" ) );
71     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
72     saveMetaButton->hide();
73     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
74     closeButton->setDefault( true );
75
76     uriLine = new QLineEdit;
77     QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
78
79     layout->addWidget( IT, 0, 0, 1, 8 );
80     layout->addWidget( uriLabel, 1, 0, 1, 1 );
81     layout->addWidget( uriLine, 1, 1, 1, 7 );
82     layout->addWidget( saveMetaButton, 2, 6 );
83     layout->addWidget( editMetaButton, 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     CONNECT( editMetaButton, clicked(), this, editMeta() );
91
92     /* Let the MetaData Panel update the URI */
93     CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
94
95     CONNECT( IT, currentChanged ( int ), this, updateButtons( int ) );
96
97
98     /* Create the main Update function with a time (150ms) */
99     if( mainInput ) {
100         ON_TIMEOUT( update() );
101         var_AddCallback( THEPL, "item-change", ItemChanged, this );
102     }
103 }
104
105 MediaInfoDialog::~MediaInfoDialog()
106 {
107     if( mainInput ) {
108         var_DelCallback( THEPL, "item-change", ItemChanged, this );
109     }
110     writeSettings( "mediainfo" );
111 }
112
113 void MediaInfoDialog::showTab( int i_tab = 0 )
114 {
115     this->show();
116     IT->setCurrentIndex( i_tab );
117 }
118
119 void MediaInfoDialog::editMeta()
120 {
121     in_edit = true;
122     editMetaButton->hide();
123     saveMetaButton->show();
124     MP->editMeta();
125 }
126
127 void MediaInfoDialog::saveMeta()
128 {
129     MP->saveMeta();
130     editMetaButton->show();
131     saveMetaButton->hide();
132     in_edit = false;
133 }
134
135 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
136         vlc_value_t oldval, vlc_value_t newval, void *param )
137 {
138     MediaInfoDialog *p_d = (MediaInfoDialog *)param;
139     p_d->need_update = VLC_TRUE;
140     return VLC_SUCCESS;
141 }
142
143 void MediaInfoDialog::setInput( input_item_t *p_input )
144 {
145     clear();
146     update( p_input, true, true );
147 }
148
149 void MediaInfoDialog::update()
150 {
151     /* Timer runs at 150 ms, dont' update more than 2 times per second */
152     i_runs++;
153     if( i_runs % 4 != 0 ) return;
154
155     /* Get Input and clear if non-existant */
156     input_thread_t *p_input =
157                      MainInputManager::getInstance( p_intf )->getInput();
158     if( !p_input || p_input->b_dead )
159     {
160         clear();
161         return;
162     }
163
164     vlc_object_yield( p_input );
165
166     update( input_GetItem(p_input), need_update, need_update );
167     need_update = false;
168
169     vlc_object_release( p_input );
170 }
171
172 void MediaInfoDialog::update( input_item_t *p_item, bool update_info,
173                                                     bool update_meta )
174 {
175     if( in_edit ) return;
176     MP->p_input = p_item;
177     if( update_info )
178         IP->update( p_item );
179     if( update_meta )
180     {
181         MP->update( p_item );
182         EMP->update( p_item );
183     }
184     if( stats )
185         ISP->update( p_item );
186 }
187
188 void MediaInfoDialog::clear()
189 {
190     IP->clear();
191     MP->clear();
192     EMP->clear();
193     if( stats ) ISP->clear();
194 }
195
196 void MediaInfoDialog::close()
197 {
198     in_edit = false;
199     this->toggleVisible();
200
201     if( mainInput == false ) {
202         deleteLater();
203     }
204 }
205
206 void MediaInfoDialog::updateButtons( int i_tab )
207 {
208     msg_Dbg( p_intf, "Coin Coin, Tab number: %i", i_tab );
209
210     if( i_tab == 0 ) saveMetaButton->show();
211     else saveMetaButton->hide();
212 }