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"
30 #include <QGridLayout>
34 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
35 vlc_value_t oldval, vlc_value_t newval, void *param );
36 MediaInfoDialog *MediaInfoDialog::instance = NULL;
38 MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput,
40 QVLCFrame( _p_intf ), mainInput(_mainInput),
47 setWindowTitle( qtr( "Media information" ) );
50 /* TabWidgets and Tabs creation */
52 MP = new MetaPanel( IT, p_intf );
53 IT->addTab( MP, qtr( "&General" ) );
54 EMP = new ExtraMetaPanel( IT, p_intf );
55 IT->addTab( EMP, qtr( "&Extra Metadata" ) );
56 IP = new InfoPanel( IT, p_intf );
57 IT->addTab( IP, qtr( "&Codec Details" ) );
60 ISP = new InputStatsPanel( IT, p_intf );
61 IT->addTab( ISP, qtr( "&Statistics" ) );
64 QGridLayout *layout = new QGridLayout( this );
66 /* FIXME GNOME/KDE ? */
67 saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
68 saveMetaButton->hide();
69 QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
70 closeButton->setDefault( true );
72 uriLine = new QLineEdit;
73 QLabel *uriLabel = new QLabel( qtr( "Location :" ) );
75 layout->addWidget( IT, 0, 0, 1, 8 );
76 layout->addWidget( uriLabel, 1, 0, 1, 1 );
77 layout->addWidget( uriLine, 1, 1, 1, 7 );
78 layout->addWidget( saveMetaButton, 2, 6 );
79 layout->addWidget( closeButton, 2, 7 );
81 BUTTONACT( closeButton, close() );
83 /* The tabs buttons are shown in the main dialog for space and cosmetics */
84 CONNECT( saveMetaButton, clicked(), this, saveMeta() );
86 /* Let the MetaData Panel update the URI */
87 CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
88 CONNECT( MP, editing(), this, editMeta() );
90 CONNECT( IT, currentChanged( int ), this, updateButtons( int ) );
92 /* Create the main Update function with a time (150ms) */
94 ON_TIMEOUT( update() );
95 var_AddCallback( THEPL, "item-change", ItemChanged, this );
99 MediaInfoDialog::~MediaInfoDialog()
102 var_DelCallback( THEPL, "item-change", ItemChanged, this );
104 writeSettings( "mediainfo" );
107 void MediaInfoDialog::showTab( int i_tab = 0 )
110 IT->setCurrentIndex( i_tab );
113 void MediaInfoDialog::editMeta()
115 saveMetaButton->show();
118 void MediaInfoDialog::saveMeta()
121 saveMetaButton->hide();
124 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
125 vlc_value_t oldval, vlc_value_t newval, void *param )
127 MediaInfoDialog *p_d = (MediaInfoDialog *)param;
128 p_d->b_need_update = VLC_TRUE;
132 void MediaInfoDialog::setInput( input_item_t *p_input )
135 update( p_input, true, true );
136 /* if info is from current input, don't set default to edit, if user opens
137 * some other item, se default to edit, so it won't be updated to current item metas
139 * This really doesn't seem as clean solution as it could be
141 input_thread_t *p_current =
142 MainInputManager::getInstance( p_intf )->getInput();
143 MP->setEditMode( ( !p_current || p_current->b_dead || input_GetItem( p_current ) != p_input ) ?
147 void MediaInfoDialog::update()
149 /* Timer runs at 150 ms, dont' update more than 2 times per second */
151 if( i_runs % 4 != 0 ) return;
153 /* Get Input and clear if non-existant */
154 input_thread_t *p_input =
155 MainInputManager::getInstance( p_intf )->getInput();
156 if( !p_input || p_input->b_dead )
162 vlc_object_yield( p_input );
164 update( input_GetItem(p_input), b_need_update, b_need_update );
165 b_need_update = false;
167 vlc_object_release( p_input );
170 void MediaInfoDialog::update( input_item_t *p_item,
174 MP->setInput( p_item );
176 IP->update( p_item );
179 MP->update( p_item );
180 EMP->update( p_item );
183 ISP->update( p_item );
186 void MediaInfoDialog::clear()
191 if( stats ) ISP->clear();
194 void MediaInfoDialog::close()
196 this->toggleVisible();
198 if( mainInput == false ) {
201 MP->setEditMode( false );
204 void MediaInfoDialog::updateButtons( int i_tab )
206 if( MP->isInEditMode() && i_tab == 0 )
207 saveMetaButton->show();
209 saveMetaButton->hide();