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 "components/infopanels.hpp"
27 #include "input_manager.hpp"
28 #include "dialogs_provider.hpp"
31 #include <QGridLayout>
35 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
36 vlc_value_t oldval, vlc_value_t newval, void *param );
37 MediaInfoDialog *MediaInfoDialog::instance = NULL;
39 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
41 QVLCFrame( _p_intf ), mainInput(_mainInput),
48 setWindowTitle( qtr( "Media information" ) );
51 /* TabWidgets and Tabs creation */
53 MP = new MetaPanel( IT, p_intf );
54 IT->addTab( MP, qtr( "&General" ) );
55 EMP = new ExtraMetaPanel( IT, p_intf );
56 IT->addTab( EMP, qtr( "&Extra Metadata" ) );
57 IP = new InfoPanel( IT, p_intf );
58 IT->addTab( IP, qtr( "&Codec Details" ) );
61 ISP = new InputStatsPanel( IT, p_intf );
62 IT->addTab( ISP, qtr( "&Stats" ) );
65 QGridLayout *layout = new QGridLayout( this );
67 /* FIXME GNOME/KDE ? */
68 saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
69 saveMetaButton->hide();
70 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
71 closeButton->setDefault( true );
73 uriLine = new QLineEdit;
74 QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
76 layout->addWidget( IT, 0, 0, 1, 8 );
77 layout->addWidget( uriLabel, 1, 0, 1, 1 );
78 layout->addWidget( uriLine, 1, 1, 1, 7 );
79 layout->addWidget( saveMetaButton, 2, 6 );
80 layout->addWidget( closeButton, 2, 7 );
82 BUTTONACT( closeButton, close() );
84 /* The tabs buttons are shown in the main dialog for space and cosmetics */
85 CONNECT( saveMetaButton, clicked(), this, saveMeta() );
87 /* Let the MetaData Panel update the URI */
88 CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
89 CONNECT( MP, editing(), this, editMeta() );
91 CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
93 /* Create the main Update function with a time (150ms) */
95 ON_TIMEOUT( update() );
96 var_AddCallback( THEPL, "item-change", ItemChanged, this );
100 MediaInfoDialog::~MediaInfoDialog()
103 var_DelCallback( THEPL, "item-change", ItemChanged, this );
105 writeSettings( "mediainfo" );
108 void MediaInfoDialog::showTab( int i_tab = 0 )
111 IT->setCurrentIndex( i_tab );
114 void MediaInfoDialog::editMeta()
116 saveMetaButton->show();
119 void MediaInfoDialog::saveMeta()
122 saveMetaButton->hide();
125 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
126 vlc_value_t oldval, vlc_value_t newval, void *param )
128 MediaInfoDialog *p_d = (MediaInfoDialog *)param;
129 p_d->b_need_update = VLC_TRUE;
133 void MediaInfoDialog::setInput( input_item_t *p_input )
136 update( p_input, true, true );
137 /* if info is from current input, don't set default to edit, if user opens
138 * some other item, se default to edit, so it won't be updated to current item metas
140 * This really doesn't seem as clean solution as it could be
142 input_thread_t *p_current =
143 MainInputManager::getInstance( p_intf )->getInput();
144 MP->setEditMode( ( !p_current || p_current->b_dead || input_GetItem( p_current ) != p_input ) ?
148 void MediaInfoDialog::update()
150 /* Timer runs at 150 ms, dont' update more than 2 times per second */
152 if( i_runs % 4 != 0 ) return;
154 /* Get Input and clear if non-existant */
155 input_thread_t *p_input =
156 MainInputManager::getInstance( p_intf )->getInput();
157 if( !p_input || p_input->b_dead )
163 vlc_object_yield( p_input );
165 update( input_GetItem(p_input), b_need_update, b_need_update );
166 b_need_update = false;
168 vlc_object_release( p_input );
171 void MediaInfoDialog::update( input_item_t *p_item,
175 MP->setInput( p_item );
177 IP->update( p_item );
180 MP->update( p_item );
181 EMP->update( p_item );
184 ISP->update( p_item );
187 void MediaInfoDialog::clear()
192 if( stats ) ISP->clear();
195 void MediaInfoDialog::close()
197 this->toggleVisible();
199 if( mainInput == false ) {
202 MP->setEditMode( false );
205 void MediaInfoDialog::updateButtons( int i_tab )
207 if( MP->isInEditMode() && i_tab == 0 )
208 saveMetaButton->show();
210 saveMetaButton->hide();