[vlc-devel] commit: skins2: improve the way skins are listed (Erwan Tulou )
git version control
git at videolan.org
Tue Jan 5 22:32:31 CET 2010
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Jan 2 23:05:53 2010 +0100| [836c694fa15e36de06251aea4433e7803a507590] | committer: Erwan Tulou
skins2: improve the way skins are listed
This patch fixes the following :
- skins are now sorted alphabetically (Linux issue only)
- the current skins is checked in list (instead of the first skins in list)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=836c694fa15e36de06251aea4433e7803a507590
---
modules/gui/skins2/src/skin_main.cpp | 41 +++---------------
modules/gui/skins2/src/theme_repository.cpp | 61 +++++++++++++++++++++++----
modules/gui/skins2/src/theme_repository.hpp | 4 ++
3 files changed, 62 insertions(+), 44 deletions(-)
diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp
index a69ac75..5c9e6e4 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -268,42 +268,13 @@ static void *Run( void * p_obj )
skin_last = config_GetPsz( p_intf, "skins2-last" );
pLoader = new ThemeLoader( p_intf );
- if( !skin_last || !*skin_last || !pLoader->load( skin_last ) )
+ if( !skin_last || !pLoader->load( skin_last ) )
{
- // Get the resource path and try to load the default skin
- OSFactory *pOSFactory = OSFactory::instance( p_intf );
- const list<string> &resPath = pOSFactory->getResourcePath();
- const string &sep = pOSFactory->getDirSeparator();
-
- list<string>::const_iterator it;
- for( it = resPath.begin(); it != resPath.end(); it++ )
- {
- string path = (*it) + sep + "default.vlt";
- if( pLoader->load( path ) )
- {
- // Theme loaded successfully
- break;
- }
- }
- if( it == resPath.end() )
- {
- // Last chance: the user can select a new theme file
- if( Dialogs::instance( p_intf ) )
- {
- CmdDlgChangeSkin *pCmd = new CmdDlgChangeSkin( p_intf );
- AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
- pQueue->push( CmdGenericPtr( pCmd ) );
- }
- else
- {
- // No dialogs provider, just quit...
- CmdQuit *pCmd = new CmdQuit( p_intf );
- AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
- pQueue->push( CmdGenericPtr( pCmd ) );
- msg_Err( p_intf,
- "cannot show the \"open skin\" dialog: exiting...");
- }
- }
+ // No skins (not even the default one). let's quit
+ CmdQuit *pCmd = new CmdQuit( p_intf );
+ AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
+ pQueue->push( CmdGenericPtr( pCmd ) );
+ msg_Err( p_intf, "no skins found : exiting");
}
delete pLoader;
diff --git a/modules/gui/skins2/src/theme_repository.cpp b/modules/gui/skins2/src/theme_repository.cpp
index 643209f..019ebe1 100644
--- a/modules/gui/skins2/src/theme_repository.cpp
+++ b/modules/gui/skins2/src/theme_repository.cpp
@@ -73,6 +73,55 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
parseDirectory( *it );
}
+ // retrieve skins for skins directories and locate default skins
+ map<string,string>::const_iterator itmap, itdefault;
+ for( itmap = m_skinsMap.begin(); itmap != m_skinsMap.end(); itmap++ )
+ {
+ string path = itmap->first;
+ string name = itmap->second;
+ val.psz_string = strdup( path.c_str() );
+ text.psz_string = strdup( name.c_str() );
+ var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
+ &text );
+ free( val.psz_string );
+ free( text.psz_string );
+
+ if( name == "default" )
+ itdefault = itmap;
+ }
+
+ // retrieve the current skin
+ char* psz_current = config_GetPsz( getIntf(), "skins2-last" );
+ string current = string( psz_current ? psz_current : "" );
+
+ // set the default skins if no skins provided
+ if( current.size() == 0 )
+ {
+ current = itdefault->first;
+ config_PutPsz( getIntf(), "skins2-last", current.c_str() );
+ }
+
+ // add an extra item if needed and set the current skins to 'checked'
+ itmap = m_skinsMap.find( current );
+ if( itmap == m_skinsMap.end() )
+ {
+ val.psz_string = strdup( current.c_str() );
+ text.psz_string = strdup( current.c_str() );
+ var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
+ &text );
+ var_Change( getIntf(), "intf-skins", VLC_VAR_SETVALUE, &val, NULL );
+ free( val.psz_string );
+ free( text.psz_string );
+ }
+ else
+ {
+ val.psz_string = strdup( current.c_str() );
+ var_Change( getIntf(), "intf-skins", VLC_VAR_SETVALUE, &val, NULL );
+ free( val.psz_string );
+ }
+ free( psz_current );
+ m_skinsMap.clear();
+
// Set the callback
var_AddCallback( pIntf, "intf-skins", changeSkin, this );
@@ -131,16 +180,10 @@ void ThemeRepository::parseDirectory( const string &rDir_locale )
if( extension == ".vlt" || extension == ".wsz" )
{
string path = rDir + sep + name;
- msg_Dbg( getIntf(), "found skin %s", path.c_str() );
-
- // Add the theme in the popup menu
string shortname = name.substr( 0, name.size() - 4 );
- val.psz_string = strdup( path.c_str() );
- text.psz_string = strdup( shortname.c_str() );
- var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
- &text );
- free( val.psz_string );
- free( text.psz_string );
+ m_skinsMap[path] = shortname;
+
+ msg_Dbg( getIntf(), "found skin %s", path.c_str() );
}
free( pszDirContent );
diff --git a/modules/gui/skins2/src/theme_repository.hpp b/modules/gui/skins2/src/theme_repository.hpp
index bacc0e0..109ed24 100644
--- a/modules/gui/skins2/src/theme_repository.hpp
+++ b/modules/gui/skins2/src/theme_repository.hpp
@@ -25,6 +25,7 @@
#define THEME_REPOSITORY_HPP
#include "skin_common.hpp"
+#include <map>
/// Singleton object handling the list of available themes
@@ -51,6 +52,9 @@ private:
static int changeSkin( vlc_object_t *pThis, char const *pVariable,
vlc_value_t oldval, vlc_value_t newval,
void *pData );
+
+ /// list of skins available
+ map<string,string> m_skinsMap;
};
More information about the vlc-devel
mailing list