X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fdialogs%2Fmediainfo.cpp;h=63e31bf567ee9d6bdcc695acdbf37519113cbe51;hb=8c7c961f4c4dec07fa749d8a600cd1cda75e22ed;hp=c6bc6b662a124056a109fdbebb0bd4b92592c164;hpb=346d8b8d7e98236450c9dffa00cd1be26dc369d2;p=vlc diff --git a/modules/gui/qt4/dialogs/mediainfo.cpp b/modules/gui/qt4/dialogs/mediainfo.cpp index c6bc6b662a..63e31bf567 100644 --- a/modules/gui/qt4/dialogs/mediainfo.cpp +++ b/modules/gui/qt4/dialogs/mediainfo.cpp @@ -25,30 +25,32 @@ #include "dialogs/mediainfo.hpp" #include "input_manager.hpp" #include "dialogs_provider.hpp" -#include "util/qvlcframe.hpp" -#include "components/infopanels.hpp" -#include "qt4.hpp" #include #include #include #include -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, +/* 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, + bool _mainInput, bool _stats ) : QVLCFrame( _p_intf ), mainInput(_mainInput), stats( _stats ) { + p_item = _p_item; + b_cleaned = true; i_runs = 0; - p_input = NULL; - b_need_update = true; setWindowTitle( qtr( "Media information" ) ); - resize( 600 , 300 ); + resize( 600 , 480 ); /* TabWidgets and Tabs creation */ IT = new QTabWidget; @@ -61,12 +63,12 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput, if( stats ) { ISP = new InputStatsPanel( IT, p_intf ); - IT->addTab( ISP, qtr( "&Stats" ) ); + IT->addTab( ISP, qtr( "&Statistics" ) ); } QGridLayout *layout = new QGridLayout( this ); - /* FIXME GNOME/KDE ? */ + /* No need to use a QDialogButtonBox here */ saveMetaButton = new QPushButton( qtr( "&Save Metadata" ) ); saveMetaButton->hide(); QPushButton *closeButton = new QPushButton( qtr( "&Close" ) ); @@ -88,32 +90,40 @@ MediaInfoDialog::MediaInfoDialog( intf_thread_t *_p_intf, bool _mainInput, /* Let the MetaData Panel update the URI */ CONNECT( MP, uriSet( QString ), uriLine, setText( QString ) ); - CONNECT( MP, editing( bool ), this, editMeta( bool ) ); + CONNECT( MP, editing(), this, showMetaSaveButton() ); CONNECT( IT, currentChanged( int ), this, updateButtons( int ) ); - /* Create the main Update function with a time (150ms) */ - if( mainInput ) { - ON_TIMEOUT( update() ); - var_AddCallback( THEPL, "item-change", ItemChanged, this ); + /* If using the General Mode */ + if( !p_item ) + { + msg_Dbg( p_intf, "Using a general windows" ); + CONNECT( THEMIM, inputChanged( input_thread_t * ), + this, update( input_thread_t * ) ); + + p_item = input_GetItem( THEMIM->getInput() ); } + + /* Call update by hand, so info is shown from current item too */ + if( p_item ) + update( p_item, true, true ); + + if( stats ) + ON_TIMEOUT( updateOnTimeOut() ); } MediaInfoDialog::~MediaInfoDialog() { - if( mainInput ) { - var_DelCallback( THEPL, "item-change", ItemChanged, this ); - } writeSettings( "mediainfo" ); } void MediaInfoDialog::showTab( int i_tab = 0 ) { - this->show(); IT->setCurrentIndex( i_tab ); + show(); } -void MediaInfoDialog::editMeta() +void MediaInfoDialog::showMetaSaveButton() { saveMetaButton->show(); } @@ -124,57 +134,48 @@ void MediaInfoDialog::saveMeta() saveMetaButton->hide(); } -static int ItemChanged( vlc_object_t *p_this, const char *psz_var, - vlc_value_t oldval, vlc_value_t newval, void *param ) -{ - MediaInfoDialog *p_d = (MediaInfoDialog *)param; - p_d->b_need_update = VLC_TRUE; - return VLC_SUCCESS; -} - -void MediaInfoDialog::setInput( input_item_t *p_input ) +/* Function called on inputChanged-update*/ +void MediaInfoDialog::update( input_thread_t *p_input ) { - clear(); - update( p_input, true, true ); - /* if info is from current input, don't set default to edit, if user opens - * some other item, se default to edit, so it won't be updated to current item metas - * - * This really doesn't seem as clean solution as it could be - */ - input_thread_t *p_current = - MainInputManager::getInstance( p_intf )->getInput(); - MP->setEditMode( ( !p_current || p_current->b_dead ) ? - true: false ); -} - -void MediaInfoDialog::update() -{ - /* Timer runs at 150 ms, dont' update more than 2 times per second */ - i_runs++; - if( i_runs % 4 != 0 ) return; - - /* Get Input and clear if non-existant */ - input_thread_t *p_input = - MainInputManager::getInstance( p_intf )->getInput(); if( !p_input || p_input->b_dead ) { - clear(); + if( !b_cleaned ) + { + clear(); + b_cleaned = true; + } return; } + /* Launch the update in all the panels */ vlc_object_yield( p_input ); - update( input_GetItem(p_input), b_need_update, b_need_update ); - b_need_update = false; + update( input_GetItem(p_input), true, true); vlc_object_release( p_input ); } -void MediaInfoDialog::update( input_item_t *p_item, - bool update_info, - bool update_meta ) +void MediaInfoDialog::updateOnTimeOut() +{ + /* Timer runs at 150 ms, dont' update more than 2 times per second */ + i_runs++; + if( i_runs % 4 != 0 ) return; + + /* Get Input and clear if non-existant */ + input_thread_t *p_input = THEMIM->getInput(); + + if( p_input && !p_input->b_dead ) + { + vlc_object_yield( p_input ); + update( input_GetItem(p_input), false, false); + vlc_object_release( p_input ); + } +} + +void MediaInfoDialog::update( input_item_t *p_item, + bool update_info, + bool update_meta ) { - MP->setInput( p_item ); if( update_info ) IP->update( p_item ); if( update_meta ) @@ -192,16 +193,22 @@ void MediaInfoDialog::clear() MP->clear(); EMP->clear(); if( stats ) ISP->clear(); + b_cleaned = true; } void MediaInfoDialog::close() { this->toggleVisible(); + /* if dialog is closed, revert editing if not saved */ + if( MP->isInEditMode() ) + { + MP->setEditMode( false ); + updateButtons( 0 ); + } if( mainInput == false ) { deleteLater(); } - MP->setEditMode( false ); } void MediaInfoDialog::updateButtons( int i_tab )