From 1ec9641c187d5a686d210e4a37758601856ff8c4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Kempf Date: Mon, 20 Oct 2008 12:15:27 +0200 Subject: [PATCH] [Qt] Various cleaning. --- modules/gui/qt4/dialogs_provider.cpp | 153 ++++++++++++++------------- modules/gui/qt4/dialogs_provider.hpp | 23 ++-- modules/gui/qt4/input_manager.cpp | 81 ++++++-------- modules/gui/qt4/input_manager.hpp | 17 +-- modules/gui/qt4/main_interface.cpp | 2 +- modules/gui/qt4/qt4.hpp | 2 +- 6 files changed, 140 insertions(+), 138 deletions(-) diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp index bbebc769ab..19ebedfc5c 100644 --- a/modules/gui/qt4/dialogs_provider.cpp +++ b/modules/gui/qt4/dialogs_provider.cpp @@ -21,21 +21,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ + #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include -#include -#include -#include - #include +#include + #include "qt4.hpp" #include "dialogs_provider.hpp" #include "main_interface.hpp" #include "menus.hpp" -#include #include "input_manager.hpp" #include "recents.hpp" @@ -53,6 +50,12 @@ #include "dialogs/gototime.hpp" #include "dialogs/podcast_configuration.hpp" +#include +#include +#include +#include + + DialogsProvider* DialogsProvider::instance = NULL; DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) : @@ -60,6 +63,7 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) : { b_isDying = false; + /* Various signal mappers for the menus */ menusMapper = new QSignalMapper(); CONNECT( menusMapper, mapped(QObject *), this, menuAction( QObject *) ); @@ -101,7 +105,7 @@ void DialogsProvider::quit() void DialogsProvider::customEvent( QEvent *event ) { - if( event->type() == DialogEvent_Type ) + if( event->type() == (int)DialogEvent_Type ) { DialogEvent *de = static_cast(event); switch( de->i_dialog ) @@ -148,7 +152,7 @@ void DialogsProvider::customEvent( QEvent *event ) QVLCMenu::MiscPopupMenu( p_intf ); break; case INTF_DIALOG_WIZARD: case INTF_DIALOG_STREAMWIZARD: - openThenStreamingDialogs(); break; + openAndStreamingDialogs(); break; #ifdef UPDATE_CHECK case INTF_DIALOG_UPDATEVLC: updateDialog(); break; @@ -233,20 +237,7 @@ void DialogsProvider::podcastConfigureDialog() PodcastConfigDialog::getInstance( p_intf )->toggleVisible(); } - -/**************************************************************************** - * All the open/add stuff - * Open Dialog first - Simple Open then - ****************************************************************************/ - -void DialogsProvider::openDialog( int i_tab ) -{ - OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab ); -} -void DialogsProvider::openDialog() -{ - openDialog( OPEN_FILE_TAB ); -} +/* Generic open file */ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg ) { if( p_arg == NULL ) @@ -309,7 +300,19 @@ void DialogsProvider::openFileGenericDialog( intf_dialog_args_t *p_arg ) free( p_arg->psz_extensions ); free( p_arg ); } +/**************************************************************************** + * All the open/add stuff + * Open Dialog first - Simple Open then + ****************************************************************************/ +void DialogsProvider::openDialog( int i_tab ) +{ + OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf )->showTab( i_tab ); +} +void DialogsProvider::openDialog() +{ + openDialog( OPEN_FILE_TAB ); +} void DialogsProvider::openFileDialog() { openDialog( OPEN_FILE_TAB ); @@ -330,8 +333,8 @@ void DialogsProvider::openCaptureDialog() /* Same as the open one, but force the enqueue */ void DialogsProvider::PLAppendDialog() { - OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_ENQUEUE) - ->showTab( OPEN_FILE_TAB ); + OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, + OPEN_AND_ENQUEUE )->showTab( OPEN_FILE_TAB ); } void DialogsProvider::MLAppendDialog() @@ -511,7 +514,6 @@ void DialogsProvider::saveAPlaylist() delete qfd; } - /**************************************************************************** * Sout emulation ****************************************************************************/ @@ -536,20 +538,49 @@ void DialogsProvider::streamingDialog( QWidget *parent, QString mrl, } } -void DialogsProvider::openThenStreamingDialogs() +void DialogsProvider::openAndStreamingDialogs() { OpenDialog::getInstance( p_intf->p_sys->p_mi, p_intf, false, OPEN_AND_STREAM ) ->showTab( OPEN_FILE_TAB ); } -void DialogsProvider::openThenTranscodingDialogs() +void DialogsProvider::openAndTranscodingDialogs() { OpenDialog::getInstance( p_intf->p_sys->p_mi , p_intf, false, OPEN_AND_SAVE ) ->showTab( OPEN_FILE_TAB ); } +void DialogsProvider::loadSubtitlesFile() +{ + input_thread_t *p_input = THEMIM->getInput(); + if( !p_input ) return; + + input_item_t *p_item = input_GetItem( p_input ); + if( !p_item ) return; + + char *path = input_item_GetURI( p_item ); + if( !path ) path = strdup( "" ); + + char *sep = strrchr( path, DIR_SEP_CHAR ); + if( sep ) *sep = '\0'; + + QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ), + EXT_FILTER_SUBTITLE, + path ); + free( path ); + QString qsFile; + foreach( qsFile, qsl ) + { + if( !input_AddSubtitles( p_input, qtu( toNativeSeparators( qsFile ) ), + true ) ) + msg_Warn( p_intf, "unable to load subtitles from '%s'", + qtu( qsFile ) ); + } +} + + /**************************************************************************** - * Menus / Interaction + * Menus ****************************************************************************/ void DialogsProvider::menuAction( QObject *data ) @@ -559,20 +590,37 @@ void DialogsProvider::menuAction( QObject *data ) void DialogsProvider::menuUpdateAction( QObject *data ) { - MenuFunc * f = qobject_cast(data); - f->doFunc( p_intf ); + MenuFunc *func = qobject_cast(data); + assert( func ); + func->doFunc( p_intf ); } void DialogsProvider::SDMenuAction( QString data ) { - char *psz_sd = strdup( qtu( data ) ); + char *psz_sd = qtu( data ); if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) ) playlist_ServicesDiscoveryAdd( THEPL, psz_sd ); else playlist_ServicesDiscoveryRemove( THEPL, psz_sd ); - free( psz_sd ); } +/** + * Play the MRL contained in the Recently played menu. + **/ +void DialogsProvider::playMRL( const QString &mrl ) +{ + input_item_t *p_input = input_item_New( p_intf, + qtu( mrl ), NULL ); + playlist_AddInput( THEPL, p_input, PLAYLIST_GO, + PLAYLIST_END, true, pl_Unlocked ); + vlc_gc_decref( p_input ); + + RecentsMRL::getInstance( p_intf )->addRecent( mrl ); +} + +/************************************* + * Interactions + *************************************/ void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg ) { InteractionDialog *qdialog; @@ -618,44 +666,3 @@ void DialogsProvider::doInteraction( intf_dialog_args_t *p_arg ) } } -void DialogsProvider::loadSubtitlesFile() -{ - input_thread_t *p_input = THEMIM->getInput(); - if( !p_input ) - return; - input_item_t *p_item = input_GetItem( p_input ); - if( !p_item ) - return; - char *path = input_item_GetURI( p_item ); - if( !path ) - path = strdup( "" ); - char *sep = strrchr( path, DIR_SEP_CHAR ); - if( sep ) - *sep = '\0'; - QStringList qsl = showSimpleOpen( qtr( "Open subtitles..." ), - EXT_FILTER_SUBTITLE, - path ); - free( path ); - QString qsFile; - foreach( qsFile, qsl ) - { - if( !input_AddSubtitles( p_input, qtu( toNativeSeparators( qsFile ) ), - true ) ) - msg_Warn( p_intf, "unable to load subtitles from '%s'", - qtu( qsFile ) ); - } -} - -/** - * Play the MRL contained in the Recently played menu. - **/ -void DialogsProvider::playMRL( const QString &mrl ) -{ - input_item_t *p_input = input_item_New( p_intf, - qtu( mrl ), NULL ); - playlist_AddInput( THEPL, p_input, PLAYLIST_GO, - PLAYLIST_END, true, pl_Unlocked ); - vlc_gc_decref( p_input ); - - RecentsMRL::getInstance( p_intf )->addRecent( mrl ); -} diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp index ff96d5ca3b..225fe6b80c 100644 --- a/modules/gui/qt4/dialogs_provider.hpp +++ b/modules/gui/qt4/dialogs_provider.hpp @@ -37,9 +37,6 @@ #include "dialogs/interaction.hpp" #include "dialogs/open.hpp" -#include -#include - #define ADD_FILTER_MEDIA( string ) \ string += qtr( "Media Files" ); \ string += " ( "; \ @@ -125,14 +122,13 @@ private: DialogsProvider( intf_thread_t *); intf_thread_t *p_intf; static DialogsProvider *instance; - void addFromSimple( bool, bool ); bool b_isDying; + void openDialog( int ); + void addFromSimple( bool, bool ); + public slots: void doInteraction( intf_dialog_args_t * ); - void menuAction( QObject *); - void menuUpdateAction( QObject * ); - void SDMenuAction( QString ); void playMRL( const QString & ); void playlistDialog(); @@ -153,13 +149,13 @@ public slots: void gotoTimeDialog(); void podcastConfigureDialog(); + void openFileGenericDialog( intf_dialog_args_t * ); + void simpleOpenDialog(); void simplePLAppendDialog(); void simpleMLAppendDialog(); void openDialog(); - void openDialog( int ); - void openFileGenericDialog( intf_dialog_args_t * ); void openDiscDialog(); void openFileDialog(); void openNetDialog(); @@ -167,14 +163,15 @@ public slots: void PLAppendDialog(); void MLAppendDialog(); + void PLOpenDir(); void PLAppendDir(); void MLAppendDir(); void streamingDialog( QWidget *parent, QString mrl = "", bool b_stream = true ); - void openThenStreamingDialogs(); - void openThenTranscodingDialogs(); + void openAndStreamingDialogs(); + void openAndTranscodingDialogs(); void openAPlaylist(); void saveAPlaylist(); @@ -182,6 +179,10 @@ public slots: void loadSubtitlesFile(); void quit(); +private slots: + void menuAction( QObject *); + void menuUpdateAction( QObject * ); + void SDMenuAction( QString ); }; #endif diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp index c64b0f0302..9f65f79247 100644 --- a/modules/gui/qt4/input_manager.cpp +++ b/modules/gui/qt4/input_manager.cpp @@ -66,7 +66,7 @@ InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) : QObject( parent ), p_intf( _p_intf ) { i_old_playing_status = END_S; - old_name = ""; + oldName = ""; artUrl = ""; p_input = NULL; i_rate = 0; @@ -95,7 +95,6 @@ void InputManager::setInput( input_thread_t *_p_input ) emit statusChanged( PLAYING_S ); UpdateMeta(); UpdateArt(); - UpdateSPU(); UpdateTeletext(); UpdateNavigation(); UpdateVout(); @@ -120,7 +119,7 @@ void InputManager::delInput() delCallbacks(); i_old_playing_status = END_S; i_input_id = 0; - old_name = ""; + oldName = ""; artUrl = ""; b_video = false; timeA = 0; @@ -133,7 +132,6 @@ void InputManager::delInput() emit voutChanged( false ); vlc_object_release( p_input ); p_input = NULL; - UpdateSPU(); UpdateTeletext(); } } @@ -187,21 +185,21 @@ void InputManager::delCallbacks() /* Convert the event from the callbacks in actions */ void InputManager::customEvent( QEvent *event ) { - int type = event->type(); + int i_type = event->type(); IMEvent *ple = static_cast(event); - if ( type != PositionUpdate_Type && - type != ItemChanged_Type && - type != ItemRateChanged_Type && - type != ItemTitleChanged_Type && - type != ItemSpuChanged_Type && - type != ItemTeletextChanged_Type && - type != ItemStateChanged_Type && - type != StatisticsUpdate_Type && - type != InterfaceVoutUpdate_Type ) + if ( i_type != PositionUpdate_Type && + i_type != ItemChanged_Type && + i_type != ItemRateChanged_Type && + i_type != ItemTitleChanged_Type && + i_type != ItemSpuChanged_Type && + i_type != ItemTeletextChanged_Type && + i_type != ItemStateChanged_Type && + i_type != StatisticsUpdate_Type && + i_type != InterfaceVoutUpdate_Type ) return; - if( type == ItemStateChanged_Type ) + if( i_type == ItemStateChanged_Type ) { UpdateNavigation(); UpdateTeletext(); @@ -209,23 +207,23 @@ void InputManager::customEvent( QEvent *event ) if( !hasInput() ) return; - if( ( type != PositionUpdate_Type && - type != ItemRateChanged_Type && - type != ItemSpuChanged_Type && - type != ItemTeletextChanged_Type && - type != ItemStateChanged_Type && - type != StatisticsUpdate_Type && - type != InterfaceVoutUpdate_Type + if( ( i_type != PositionUpdate_Type && + i_type != ItemRateChanged_Type && + i_type != ItemSpuChanged_Type && + i_type != ItemTeletextChanged_Type && + i_type != ItemStateChanged_Type && + i_type != StatisticsUpdate_Type && + i_type != InterfaceVoutUpdate_Type ) && ( i_input_id != ple->i_id ) ) return; - if( type != PositionUpdate_Type && - type != StatisticsUpdate_Type ) - msg_Dbg( p_intf, "New Event: type %i", type ); + if( i_type != PositionUpdate_Type && + i_type != StatisticsUpdate_Type ) + msg_Dbg( p_intf, "New Event: type %i", i_type ); /* Actions */ - switch( type ) + switch( i_type ) { case PositionUpdate_Type: UpdatePosition(); @@ -259,6 +257,8 @@ void InputManager::customEvent( QEvent *event ) case InterfaceVoutUpdate_Type: UpdateVout(); break; + default: + msg_Warn( p_intf, "This shouldn't happen: %i", i_type ); } } @@ -289,6 +289,7 @@ void InputManager::UpdateNavigation() if( val.i_int > 0 ) { emit titleChanged( true ); + /* p_input != NULL since val.i_int != 0 */ val.i_int = 0; var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL ); emit chapterChanged( (val.i_int > 0) ); @@ -365,10 +366,10 @@ void InputManager::UpdateMeta() free( psz_name ); } - if( old_name != text ) + if( oldName != text ) { emit nameChanged( text ); - old_name=text; + oldName=text; } } @@ -402,7 +403,8 @@ void InputManager::UpdateVout() { bool b_old_video = b_video; - vlc_object_t *p_vout = (vlc_object_t*)vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD ); + vlc_object_t *p_vout = (vlc_object_t*)vlc_object_find( p_input, + VLC_OBJECT_VOUT, FIND_CHILD ); b_video = p_vout != NULL; if( p_vout ) vlc_object_release( p_vout ); @@ -637,7 +639,6 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf ) p_input = NULL; im = new InputManager( this, p_intf ); -// var_AddCallback( THEPL, "item-change", PLItemChanged, this ); var_AddCallback( THEPL, "item-change", ItemChanged, im ); var_AddCallback( THEPL, "playlist-current", PLItemChanged, this ); var_AddCallback( THEPL, "activity", PLItemChanged, this ); @@ -669,7 +670,6 @@ MainInputManager::~MainInputManager() var_DelCallback( THEPL, "activity", PLItemChanged, this ); var_DelCallback( THEPL, "item-change", ItemChanged, im ); -// var_DelCallback( THEPL, "item-change", PLItemChanged, this ); var_DelCallback( THEPL, "playlist-current", PLItemChanged, this ); } @@ -688,7 +688,7 @@ void MainInputManager::customEvent( QEvent *event ) } /* Should be PLItemChanged Event */ - if( VLC_OBJECT_INTF == p_intf->i_object_type ) /* FIXME: don't use object type */ + if( !p_intf->p_sys->b_isDialogProvider ) { vlc_mutex_lock( &p_intf->change_lock ); if( p_input && ( p_input->b_dead || !vlc_object_alive (p_input) ) ) @@ -751,18 +751,6 @@ void MainInputManager::togglePlayPause() getIM()->togglePlayPause(); } -bool MainInputManager::teletextState() -{ - if( getIM()->hasInput() ) - { - const int i_teletext_es = var_GetInteger( getInput(), "teletext-es" ); - const int i_spu_es = var_GetInteger( getInput(), "spu-es" ); - - return i_teletext_es >= 0 && i_teletext_es == i_spu_es; - } - return false; -} - /* Static callbacks */ /* IM */ @@ -771,11 +759,12 @@ static int InterfaceChanged( vlc_object_t *p_this, const char *psz_var, { /* FIXME remove that static variable */ static int counter = 0; + InputManager *im = (InputManager*)param; counter = ++counter % 4; - if(!counter) - return VLC_SUCCESS; + if(!counter) return VLC_SUCCESS; + IMEvent *event = new IMEvent( PositionUpdate_Type, 0 ); QApplication::postEvent( im, static_cast(event) ); return VLC_SUCCESS; diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp index 9cda65c9a7..8e728cbc19 100644 --- a/modules/gui/qt4/input_manager.hpp +++ b/modules/gui/qt4/input_manager.hpp @@ -56,11 +56,13 @@ enum { class IMEvent : public QEvent { -public: +friend class InputManager; + public: IMEvent( int type, int id ) : QEvent( (QEvent::Type)(type) ) { i_id = id ; } ; virtual ~IMEvent() {}; +private: int i_id; }; @@ -79,22 +81,24 @@ public: bool hasAudio(); bool hasVideo() { return hasInput() && b_video; } - QString getName() { return old_name; } + QString getName() { return oldName; } private: intf_thread_t *p_intf; input_thread_t *p_input; int i_input_id; int i_old_playing_status; - QString old_name; + QString oldName; QString artUrl; int i_rate; bool b_video; mtime_t timeA, timeB; void customEvent( QEvent * ); + void addCallbacks(); void delCallbacks(); + void UpdateRate(); void UpdateMeta(); void UpdateStatus(); @@ -176,19 +180,20 @@ public: private: MainInputManager( intf_thread_t * ); + static MainInputManager *instance; + void customEvent( QEvent * ); InputManager *im; input_thread_t *p_input; - intf_thread_t *p_intf; - static MainInputManager *instance; + public slots: - bool teletextState(); void togglePlayPause(); void stop(); void next(); void prev(); + signals: void inputChanged( input_thread_t * ); void volumeChanged(); diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp index 0fa8eb2d9d..8782c41e52 100644 --- a/modules/gui/qt4/main_interface.cpp +++ b/modules/gui/qt4/main_interface.cpp @@ -1085,7 +1085,7 @@ void MainInterface::customEvent( QEvent *event ) } #endif /*else */ - if ( event->type() == SetVideoOnTopEvent_Type ) + if ( event->type() == (int)SetVideoOnTopEvent_Type ) { SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event; if( p_event->OnTop() ) diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp index 7b75944f66..e7b07f1546 100755 --- a/modules/gui/qt4/qt4.hpp +++ b/modules/gui/qt4/qt4.hpp @@ -64,8 +64,8 @@ class VideoWidget; class QSettings; -#if defined(Q_WS_WIN) #include +#if defined(Q_WS_WIN) class WinQtApp : public QApplication {