1 /*****************************************************************************
2 * mediainfo.cpp : Information about an item
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 ******************************************************************************/
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"
33 #include <QGridLayout>
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;
41 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
43 QVLCFrame( _p_intf ), mainInput(_mainInput),
50 setWindowTitle( qtr( "Media information" ) );
53 /* TabWidgets and Tabs creation */
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" ) );
63 ISP = new InputStatsPanel( IT, p_intf );
64 IT->addTab( ISP, qtr( "&Stats" ) );
67 QGridLayout *layout = new QGridLayout( this );
69 /* FIXME GNOME/KDE ? */
70 saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
71 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
72 closeButton->setDefault( true );
74 uriLine = new QLineEdit;
75 QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
77 layout->addWidget( IT, 0, 0, 1, 8 );
78 layout->addWidget( uriLabel, 1, 0, 1, 1 );
79 layout->addWidget( uriLine, 1, 1, 1, 7 );
80 layout->addWidget( saveMetaButton, 2, 6 );
81 layout->addWidget( closeButton, 2, 7 );
83 BUTTONACT( closeButton, close() );
85 /* The tabs buttons are shown in the main dialog for space and cosmetics */
86 CONNECT( saveMetaButton, clicked(), MP, saveMeta() );
88 /* Let the MetaData Panel update the URI */
89 CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
91 CONNECT( IT, currentChanged ( int ), this, updateButtons( int ) );
94 /* Create the main Update function with a time (150ms) */
96 ON_TIMEOUT( update() );
97 var_AddCallback( THEPL, "item-change", ItemChanged, this );
101 MediaInfoDialog::~MediaInfoDialog()
104 var_DelCallback( THEPL, "item-change", ItemChanged, this );
106 writeSettings( "mediainfo" );
109 void MediaInfoDialog::showTab( int i_tab = 0 )
112 IT->setCurrentIndex( i_tab );
115 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
116 vlc_value_t oldval, vlc_value_t newval, void *param )
118 MediaInfoDialog *p_d = (MediaInfoDialog *)param;
119 p_d->need_update = VLC_TRUE;
123 void MediaInfoDialog::setInput( input_item_t *p_input )
126 vlc_mutex_lock( &p_input->lock );
127 update( p_input, true, true );
128 vlc_mutex_unlock( &p_input->lock );
131 void MediaInfoDialog::update()
133 /* Timer runs at 150 ms, dont' update more than 2 times per second */
135 if( i_runs % 4 != 0 ) return;
137 /* Get Input and clear if non-existant */
138 input_thread_t *p_input =
139 MainInputManager::getInstance( p_intf )->getInput();
140 if( !p_input || p_input->b_dead )
146 vlc_object_yield( p_input );
147 vlc_mutex_lock( &input_GetItem(p_input)->lock );
149 update( input_GetItem(p_input), need_update, need_update );
152 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
153 vlc_object_release( p_input );
156 void MediaInfoDialog::update( input_item_t *p_item, bool update_info,
159 MP->p_input = p_item;
161 IP->update( p_item );
164 MP->update( p_item );
165 EMP->update( p_item );
168 ISP->update( p_item );
171 void MediaInfoDialog::clear()
176 if( stats ) ISP->clear();
179 void MediaInfoDialog::close()
181 this->toggleVisible();
183 if( mainInput == false ) {
188 void MediaInfoDialog::updateButtons( int i_tab )
190 msg_Dbg( p_intf, "Coin Coin, Tab number: %i", i_tab );
192 if( i_tab == 0 ) saveMetaButton->show();
193 else saveMetaButton->hide();