From 495602e13542b7b3ed6646c9768e25d4bf66a2ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Mon, 22 Oct 2007 02:01:55 +0000 Subject: [PATCH] configuration: add config_AddIntf() config_RemoveIntf() and config_ExistIntf() to handle extra interfaces in the preferences make use of it for last.fm simple preferences (ref #1262) by the way the duplication of "control" with "extraintf" is very boring --- include/vlc_configuration.h | 134 ++++++++++++++++++ .../gui/qt4/components/simple_preferences.cpp | 30 ++-- 2 files changed, 149 insertions(+), 15 deletions(-) diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h index dc52c37939..01181615ce 100644 --- a/include/vlc_configuration.h +++ b/include/vlc_configuration.h @@ -445,6 +445,140 @@ static inline config_chain_t *config_chain_find( config_chain_t *p_cfg, const ch return p_cfg; } +static void config_AddIntf( vlc_object_t *p_this, const char *psz_intf ) +{ + assert( psz_intf ); + + char *psz_config, *psz_parser; + size_t i_len = strlen( psz_intf ); + + psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" ); + while( psz_parser ) + { + if( !strncmp( psz_intf, psz_parser, i_len ) ) + { + free( psz_config ); + return; + } + psz_parser = strchr( psz_parser, ':' ); + if( psz_parser ) psz_parser++; /* skip the ':' */ + } + free( psz_config ); + + psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" ); + while( psz_parser ) + { + if( !strncmp( psz_intf, psz_parser, i_len ) ) + { + free( psz_config ); + return; + } + psz_parser = strchr( psz_parser, ':' ); + if( psz_parser ) psz_parser++; /* skip the ':' */ + } + + /* interface not found in the config, let's add it */ + if( psz_config && strlen( psz_config ) > 0 ) + { + char *psz_newconfig; + if( asprintf( &psz_newconfig, "%s:%s", psz_config, psz_intf ) != -1 ) + { + config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig ); + free( psz_newconfig ); + } + } + else + config_PutPsz( p_this->p_libvlc, "extraintf", psz_intf ); + + free( psz_config ); +} + +static void config_RemoveIntf( vlc_object_t *p_this, const char *psz_intf ) +{ + assert( psz_intf ); + + char *psz_config, *psz_parser; + size_t i_len = strlen( psz_intf ); + + psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" ); + while( psz_parser ) + { + if( !strncmp( psz_intf, psz_parser, i_len ) ) + { + char *psz_newconfig; + char *psz_end = psz_parser + i_len; + if( *psz_end == ':' ) psz_end++; + *psz_parser = '\0'; + if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 ) + { + config_PutPsz( p_this->p_libvlc, "extraintf", psz_newconfig ); + free( psz_newconfig ); + } + break; + } + psz_parser = strchr( psz_parser, ':' ); + if( psz_parser ) psz_parser++; /* skip the ':' */ + } + free( psz_config ); + + psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" ); + while( psz_parser ) + { + if( !strncmp( psz_intf, psz_parser, i_len ) ) + { + char *psz_newconfig; + char *psz_end = psz_parser + i_len; + if( *psz_end == ':' ) psz_end++; + *psz_parser = '\0'; + if( asprintf( &psz_newconfig, "%s%s", psz_config, psz_end ) != -1 ) + { + config_PutPsz( p_this->p_libvlc, "control", psz_newconfig ); + free( psz_newconfig ); + } + break; + } + psz_parser = strchr( psz_parser, ':' ); + if( psz_parser ) psz_parser++; /* skip the ':' */ + } + free( psz_config ); +} + +static vlc_bool_t config_ExistIntf( vlc_object_t *p_this, const char *psz_intf ) +{ + assert( psz_intf ); + + char *psz_config, *psz_parser; + size_t i_len = strlen( psz_intf ); + + psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "extraintf" ); + while( psz_parser ) + { + if( !strncmp( psz_parser, psz_intf, i_len ) ) + { + free( psz_config ); + return VLC_TRUE; + } + psz_parser = strchr( psz_parser, ':' ); + if( psz_parser ) psz_parser++; /* skip the ':' */ + } + free( psz_config ); + + psz_config = psz_parser = config_GetPsz( p_this->p_libvlc, "control" ); + while( psz_parser ) + { + if( !strncmp( psz_parser, psz_intf, i_len ) ) + { + free( psz_config ); + return VLC_TRUE; + } + psz_parser = strchr( psz_parser, ':' ); + if( psz_parser ) psz_parser++; /* skip the ':' */ + } + free( psz_config ); + + return VLC_FALSE; +} + static inline char *config_chain_find_value( config_chain_t *p_cfg, const char *psz_name ) { while( p_cfg && strcmp( p_cfg->psz_name, psz_name ) ) diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp index 61814a3c41..1c2e7b8c44 100644 --- a/modules/gui/qt4/components/simple_preferences.cpp +++ b/modules/gui/qt4/components/simple_preferences.cpp @@ -34,6 +34,7 @@ #include "ui/sprefs_interface.h" #include +#include #include #include @@ -246,21 +247,22 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, volNormalizer ); CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation); -#if 0 - if( control_Exists( VLC_OBJECT( p_intf ), "audioscrobbler" ) ) + + CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label, + lastfm_user_edit ); + CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label, + lastfm_pass_edit ); + ui.lastfm_user_edit->hide(); + ui.lastfm_user_label->hide(); + ui.lastfm_pass_edit->hide(); + ui.lastfm_pass_label->hide(); + + if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) ) ui.lastfm->setCheckState( Qt::Checked ); else ui.lastfm->setCheckState( Qt::Unchecked ); CONNECT( ui.lastfm, stateChanged( int ), this , lastfm_Changed( int ) ); -#endif - CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label, - lastfm_user_edit ); - CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label, - lastfm_pass_edit ); - ui.lastfm_user_edit->hide(); - ui.lastfm_user_label->hide(); - ui.lastfm_pass_edit->hide(); - ui.lastfm_pass_label->hide(); + END_SPREFS_CAT; /* Input and Codecs Panel Implementation */ @@ -391,10 +393,8 @@ void SPrefsPanel::clean() void SPrefsPanel::lastfm_Changed( int i_state ) { -#if 0 if( i_state == Qt::Checked ) - control_Add( VLC_OBJECT( p_intf ), "audioscrobbler" ); + config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ); else if( i_state == Qt::Unchecked ) - control_Remove( VLC_OBJECT( p_intf ), "audioscrobbler" ); -#endif + config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ); } -- 2.39.2