]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/mediainfo.cpp
Qt4 - Move the Write MetaData button outside of the component part because it is...
[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
49     setWindowTitle( qtr( "Media information" ) );
50     resize( 700 , 450 );
51
52     /* TabWidgets and Tabs creation */
53     IT = new QTabWidget;
54     MP = new MetaPanel( IT, p_intf );
55     IT->addTab( MP, qtr( "&General" ) );
56     EMP = new ExtraMetaPanel( IT, p_intf );
57     IT->addTab( EMP, qtr( "&Extra Metadata" ) );
58     IP = new InfoPanel( IT, p_intf );
59     IT->addTab( IP, qtr( "&Codec Details" ) );
60     if( stats )
61     {
62         ISP = new InputStatsPanel( IT, p_intf );
63         IT->addTab( ISP, qtr( "&Stats" ) );
64     }
65
66     QGridLayout *layout = new QGridLayout( this );
67
68     /* FIXME GNOME/KDE ? */
69     saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
70     QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
71     closeButton->setDefault( true );
72
73     uriLine = new QLineEdit;
74     QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
75
76     layout->addWidget( IT, 0, 0, 1, 7 );
77     layout->addWidget( closeButton, 2, 6 );
78     layout->addWidget( saveMetaButton, 2, 5 );
79     layout->addWidget( uriLabel, 1, 0, 1, 1 );
80     layout->addWidget( uriLine, 1, 1, 1, 6 );
81
82     BUTTONACT( closeButton, close() );
83
84     /* The tabs buttons are shown in the main dialog for space and cosmetics */
85     CONNECT( saveMetaButton, clicked(), MP, saveMeta() );
86
87     /* Let the MetaData Panel update the URI */
88     CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
89
90     CONNECT( IT, currentChanged ( int ), this, updateButtons( int ) );
91
92
93     /* Create the main Update function with a time (150ms) */
94     if( mainInput ) {
95         ON_TIMEOUT( update() );
96         var_AddCallback( THEPL, "item-change", ItemChanged, this );
97     }
98 }
99
100 MediaInfoDialog::~MediaInfoDialog()
101 {
102     if( mainInput ) {
103         var_DelCallback( THEPL, "item-change", ItemChanged, this );
104     }
105     writeSettings( "mediainfo" );
106 }
107
108 void MediaInfoDialog::showTab( int i_tab = 0 )
109 {
110     this->show();
111     IT->setCurrentIndex( i_tab );
112 }
113
114 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
115         vlc_value_t oldval, vlc_value_t newval, void *param )
116 {
117     MediaInfoDialog *p_d = (MediaInfoDialog *)param;
118     p_d->need_update = VLC_TRUE;
119     return VLC_SUCCESS;
120 }
121
122 void MediaInfoDialog::setInput( input_item_t *p_input )
123 {
124     clear();
125     vlc_mutex_lock( &p_input->lock );
126     update( p_input, true, true );
127     vlc_mutex_unlock( &p_input->lock );
128 }
129
130 void MediaInfoDialog::update()
131 {
132     /* Timer runs at 150 ms, dont' update more than 2 times per second */
133     if( i_runs % 4 != 0 ) return;
134     i_runs++;
135
136     /* Get Input and clear if non-existant */
137     input_thread_t *p_input =
138                      MainInputManager::getInstance( p_intf )->getInput();
139     if( !p_input || p_input->b_dead )
140     {
141         clear();
142         return;
143     }
144
145     vlc_object_yield( p_input );
146     vlc_mutex_lock( &input_GetItem(p_input)->lock );
147
148     update( input_GetItem(p_input), need_update, need_update );
149     need_update = false;
150
151     vlc_mutex_unlock( &input_GetItem(p_input)->lock );
152     vlc_object_release( p_input );
153 }
154
155 void MediaInfoDialog::update( input_item_t *p_item, bool update_info,
156                                                     bool update_meta )
157 {
158     MP->p_input = p_item;
159     if( update_info )
160         IP->update( p_item );
161     if( update_meta )
162     {
163         MP->update( p_item );
164         EMP->update( p_item );
165     }
166     if( stats )
167         ISP->update( p_item );
168 }
169
170 void MediaInfoDialog::clear()
171 {
172     IP->clear();
173     MP->clear();
174     EMP->clear();
175     if( stats ) ISP->clear();
176 }
177
178 void MediaInfoDialog::close()
179 {
180     this->toggleVisible();
181
182     if( mainInput == false ) {
183         deleteLater();
184     }
185 }
186
187 void MediaInfoDialog::updateButtons( int i_tab )
188 {
189     msg_Dbg( p_intf, "Coin Coin, Tab number: %i", i_tab );
190
191     if( i_tab == 0 ) saveMetaButton->show();
192     else saveMetaButton->hide();
193 }