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 saveMetaButton->hide();
72 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
73 closeButton->setDefault( true );
75 uriLine = new QLineEdit;
76 QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
78 layout->addWidget( IT, 0, 0, 1, 8 );
79 layout->addWidget( uriLabel, 1, 0, 1, 1 );
80 layout->addWidget( uriLine, 1, 1, 1, 7 );
81 layout->addWidget( saveMetaButton, 2, 6 );
82 layout->addWidget( closeButton, 2, 7 );
84 BUTTONACT( closeButton, close() );
86 /* The tabs buttons are shown in the main dialog for space and cosmetics */
87 CONNECT( saveMetaButton, clicked(), this, saveMeta() );
89 /* Let the MetaData Panel update the URI */
90 CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
91 CONNECT( MP, editing(), this, editMeta() );
93 CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
95 /* Create the main Update function with a time (150ms) */
97 ON_TIMEOUT( update() );
98 var_AddCallback( THEPL, "item-change", ItemChanged, this );
102 MediaInfoDialog::~MediaInfoDialog()
105 var_DelCallback( THEPL, "item-change", ItemChanged, this );
107 writeSettings( "mediainfo" );
110 void MediaInfoDialog::showTab( int i_tab = 0 )
113 IT->setCurrentIndex( i_tab );
116 void MediaInfoDialog::editMeta()
118 saveMetaButton->show();
121 void MediaInfoDialog::saveMeta()
124 saveMetaButton->hide();
127 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
128 vlc_value_t oldval, vlc_value_t newval, void *param )
130 MediaInfoDialog *p_d = (MediaInfoDialog *)param;
131 p_d->b_need_update = VLC_TRUE;
135 void MediaInfoDialog::setInput( input_item_t *p_input )
138 update( p_input, true, true );
139 /* if info is from current input, don't set default to edit, if user opens
140 * some other item, se default to edit, so it won't be updated to current item metas
142 * This really doesn't seem as clean solution as it could be
144 input_thread_t *p_current =
145 MainInputManager::getInstance( p_intf )->getInput();
146 MP->setEditMode( ( !p_current || p_current->b_dead ) ?
150 void MediaInfoDialog::update()
152 /* Timer runs at 150 ms, dont' update more than 2 times per second */
154 if( i_runs % 4 != 0 ) return;
156 /* Get Input and clear if non-existant */
157 input_thread_t *p_input =
158 MainInputManager::getInstance( p_intf )->getInput();
159 if( !p_input || p_input->b_dead )
165 vlc_object_yield( p_input );
167 update( input_GetItem(p_input), b_need_update, b_need_update );
168 b_need_update = false;
170 vlc_object_release( p_input );
173 void MediaInfoDialog::update( input_item_t *p_item,
177 MP->setInput( p_item );
179 IP->update( p_item );
182 MP->update( p_item );
183 EMP->update( p_item );
186 ISP->update( p_item );
189 void MediaInfoDialog::clear()
194 if( stats ) ISP->clear();
197 void MediaInfoDialog::close()
199 this->toggleVisible();
201 if( mainInput == false ) {
204 MP->setEditMode( false );
207 void MediaInfoDialog::updateButtons( int i_tab )
209 if( MP->isInEditMode() && i_tab == 0 )
210 saveMetaButton->show();
212 saveMetaButton->hide();