/*****************************************************************************
* mediainfo.cpp : Information about an item
****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2008 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
******************************************************************************/
-#include <QTabWidget>
-#include <QGridLayout>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#include "dialogs/mediainfo.hpp"
#include "input_manager.hpp"
-#include "dialogs_provider.hpp"
-#include "util/qvlcframe.hpp"
-#include "components/infopanels.hpp"
-#include "qt4.hpp"
+#include <QTabWidget>
+#include <QGridLayout>
+#include <QLineEdit>
+#include <QLabel>
-static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *param );
MediaInfoDialog *MediaInfoDialog::instance = NULL;
-MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput ) :
- QVLCFrame( _p_intf ), mainInput(_mainInput)
+/* This Dialog has two main modes:
+ - General Mode that shows the current Played item, and the stats
+ - Single mode that shows the info on ONE SINGLE Item on the playlist
+ Please be Careful of not breaking one the modes behaviour... */
+
+MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf,
+ input_item_t *p_item ) :
+ QVLCFrame( _p_intf )
{
- i_runs = 0;
- p_input = NULL;
+ isMainInputInfo = ( p_item == NULL );
+
+ setWindowTitle( qtr( "Media Information" ) );
+
+ /* TabWidgets and Tabs creation */
+ infoTabW = new QTabWidget;
+
+ MP = new MetaPanel( infoTabW, p_intf );
+ infoTabW->addTab( MP, qtr( "&General" ) );
+ EMP = new ExtraMetaPanel( infoTabW, p_intf );
+ infoTabW->addTab( EMP, qtr( "&Extra Metadata" ) );
+ IP = new InfoPanel( infoTabW, p_intf );
+ infoTabW->addTab( IP, qtr( "&Codec Details" ) );
+ if( isMainInputInfo )
+ {
+ ISP = new InputStatsPanel( infoTabW, p_intf );
+ infoTabW->addTab( ISP, qtr( "&Statistics" ) );
+ }
- setWindowTitle( qtr( "Media information" ) );
+ QGridLayout *layout = new QGridLayout( this );
- QGridLayout *layout = new QGridLayout(this);
- IT = new InfoTab( this, p_intf, true ) ;
- QPushButton *closeButton = new QPushButton(qtr("&Close"));
+ /* No need to use a QDialogButtonBox here */
+ saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) );
+ saveMetaButton->hide();
+ QPushButton *closeButton = new QPushButton( qtr( "&Close" ) );
+ closeButton->setDefault( true );
- layout->addWidget(IT,0,0,1,3);
- layout->addWidget(closeButton,1,2);
+ QLabel *uriLabel = new QLabel( qtr( "Location:" ) );
+ QLineEdit *uriLine = new QLineEdit;
+
+ layout->addWidget( infoTabW, 0, 0, 1, 8 );
+ layout->addWidget( uriLabel, 1, 0, 1, 1 );
+ layout->addWidget( uriLine, 1, 1, 1, 7 );
+ layout->addWidget( saveMetaButton, 2, 6 );
+ layout->addWidget( closeButton, 2, 7 );
BUTTONACT( closeButton, close() );
- if( mainInput ) {
- ON_TIMEOUT( update() );
- var_AddCallback( THEPL, "item-change", ItemChanged, this );
+ /* The tabs buttons are shown in the main dialog for space and cosmetics */
+ BUTTONACT( saveMetaButton, saveMeta() );
+
+ /* Let the MetaData Panel update the URI */
+ CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) );
+ CONNECT( MP, editing(), saveMetaButton, show() );
+
+ /* Display the buttonBar according to the Tab selected */
+ CONNECT( infoTabW, currentChanged( int ), this, updateButtons( int ) );
+
+ /* If using the General Mode */
+ if( isMainInputInfo )
+ {
+ msg_Dbg( p_intf, "Using a general info windows" );
+ /**
+ * Connects on the various signals of input_Manager
+ * For the currently playing element
+ **/
+ CONNECT( THEMIM->getIM(), infoChanged( input_item_t* ),
+ IP, update( input_item_t* ) );
+ CONNECT( THEMIM->getIM(), metaChanged( input_item_t* ),
+ MP, update( input_item_t* ) );
+ CONNECT( THEMIM->getIM(), metaChanged( input_item_t* ),
+ EMP, update( input_item_t* ) );
+ CONNECT( THEMIM->getIM(), statisticsUpdated( input_item_t* ),
+ ISP, update( input_item_t* ) );
+
+ if( THEMIM->getInput() )
+ p_item = input_GetItem( THEMIM->getInput() );
}
- readSettings( "mediainfo" , QSize( 500, 450 ) );
+ else
+ msg_Dbg( p_intf, "Using an item specific info windows" );
+
+ /* Call update at start, so info is filled up at begginning */
+ if( p_item )
+ updateAllTabs( p_item );
+
+ readSettings( "Mediainfo", QSize( 600 , 480 ) );
}
MediaInfoDialog::~MediaInfoDialog()
{
- if( mainInput ) {
- var_DelCallback( THEPL, "item-change", ItemChanged, this );
- }
- writeSettings( "mediainfo" );
+ writeSettings( "Mediainfo" );
}
-static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *param )
+void MediaInfoDialog::showTab( int i_tab = 0 )
{
- MediaInfoDialog *p_d = (MediaInfoDialog *)param;
- p_d->need_update = VLC_TRUE;
- return VLC_SUCCESS;
+ infoTabW->setCurrentIndex( i_tab );
+ show();
}
-void MediaInfoDialog::setInput(input_item_t *p_input)
+void MediaInfoDialog::saveMeta()
{
- IT->clear();
- vlc_mutex_lock( &p_input->lock );
- IT->update( p_input, true, true );
- vlc_mutex_unlock( &p_input->lock );
+ MP->saveMeta();
+ saveMetaButton->hide();
}
-void MediaInfoDialog::update()
+void MediaInfoDialog::updateAllTabs( input_item_t *p_item )
{
- // Timer runs at 150 ms, dont' update more than 2 times per second
- i_runs++;
- if( i_runs % 3 != 0 ) return;
-
- input_thread_t *p_input =
- MainInputManager::getInstance( p_intf )->getInput();
- if( !p_input || p_input->b_dead )
- {
- IT->clear();
- return;
- }
+ IP->update( p_item );
+ MP->update( p_item );
+ EMP->update( p_item );
- vlc_object_yield( p_input );
- vlc_mutex_lock( &input_GetItem(p_input)->lock );
+ if( isMainInputInfo ) ISP->update( p_item );
+}
- IT->update( input_GetItem(p_input), need_update, need_update );
- need_update = false;
+void MediaInfoDialog::clearAllTabs()
+{
+ IP->clear();
+ MP->clear();
+ EMP->clear();
- vlc_mutex_unlock( &input_GetItem(p_input)->lock );
- vlc_object_release( p_input );
+ if( isMainInputInfo ) ISP->clear();
}
void MediaInfoDialog::close()
{
- this->toggleVisible();
+ hide();
- if( mainInput == false ) {
- deleteLater();
+ /* if dialog is closed, revert editing if not saved */
+ if( MP->isInEditMode() )
+ {
+ MP->setEditMode( false );
+ updateButtons( 0 );
}
+
+ if( !isMainInputInfo )
+ deleteLater();
}
+
+void MediaInfoDialog::updateButtons( int i_tab )
+{
+ if( MP->isInEditMode() && i_tab == 0 )
+ saveMetaButton->show();
+ else
+ saveMetaButton->hide();
+}
+