[vlc-commits] commit: skins2: improve list of skins (Erwan Tulou )
git at videolan.org
git at videolan.org
Wed Mar 10 17:12:01 CET 2010
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Tue Mar 9 18:57:41 2010 +0100| [79944bcee0ee49d490081a16e683a02bf29a318f] | committer: Erwan Tulou
skins2: improve list of skins
- make it case insensitive and sorted alphabetically
- fix a few regressions about config_Get vs. var_Inherit
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=79944bcee0ee49d490081a16e683a02bf29a318f
---
modules/gui/skins2/src/skin_main.cpp | 2 +-
modules/gui/skins2/src/theme_loader.cpp | 2 +-
modules/gui/skins2/src/theme_repository.cpp | 44 +++++++++++++++++++--------
3 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp
index f019c1f..c51ac49 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -256,7 +256,7 @@ static void *Run( void * p_obj )
}
// Load a theme
- skin_last = var_InheritString( p_intf, "skins2-last" );
+ skin_last = config_GetPsz( p_intf, "skins2-last" );
pLoader = new ThemeLoader( p_intf );
if( !skin_last || !pLoader->load( skin_last ) )
diff --git a/modules/gui/skins2/src/theme_loader.cpp b/modules/gui/skins2/src/theme_loader.cpp
index f06e77c..0d9cfd5 100644
--- a/modules/gui/skins2/src/theme_loader.cpp
+++ b/modules/gui/skins2/src/theme_loader.cpp
@@ -98,7 +98,7 @@ bool ThemeLoader::load( const string &fileName )
}
// Check if the skin to load is in the config file, to load its config
- char *skin_last = var_InheritString( getIntf(), "skins2-last" );
+ char *skin_last = config_GetPsz( getIntf(), "skins2-last" );
if( skin_last != NULL && fileName == (string)skin_last )
{
// Restore the theme configuration
diff --git a/modules/gui/skins2/src/theme_repository.cpp b/modules/gui/skins2/src/theme_repository.cpp
index df8d8d1..1dc83b1 100644
--- a/modules/gui/skins2/src/theme_repository.cpp
+++ b/modules/gui/skins2/src/theme_repository.cpp
@@ -34,6 +34,7 @@
# include <dirent.h>
#endif
+#include <fstream>
ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf )
@@ -77,29 +78,34 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
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;
+ string name = itmap->first;
+ string path = itmap->second;
val.psz_string = (char*) path.c_str();
text.psz_string = (char*) name.c_str();
var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
&text );
- if( name == "default" )
+ if( name == "Default" )
itdefault = itmap;
}
// retrieve last skins stored or skins requested by user
char* psz_current = var_InheritString( getIntf(), "skins2-last" );
string current = string( psz_current ? psz_current : "" );
+ free( 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() );
- }
+ // check if skins exists and is readable
+ bool b_readable = !ifstream( current.c_str() ).fail();
- free( psz_current );
+ msg_Dbg( getIntf(), "requested skins %s is %s accessible",
+ current.c_str(), b_readable ? "" : "NOT" );
+
+ // set the default skins if given skins not accessible
+ if( !b_readable )
+ current = itdefault->second;
+
+ // save this valid skins for reuse
+ config_PutPsz( getIntf(), "skins2-last", current.c_str() );
// Update repository
updateRepository();
@@ -164,7 +170,11 @@ void ThemeRepository::parseDirectory( const string &rDir_locale )
{
string path = rDir + sep + name;
string shortname = name.substr( 0, name.size() - 4 );
- m_skinsMap[path] = shortname;
+ for( int i = 0; i < shortname.size(); i++ )
+ shortname[i] = ( i == 0 ) ?
+ toupper( shortname[i] ) :
+ tolower( shortname[i] );
+ m_skinsMap[shortname] = path;
msg_Dbg( getIntf(), "found skin %s", path.c_str() );
}
@@ -206,7 +216,7 @@ void ThemeRepository::updateRepository()
vlc_value_t val, text;
// retrieve the current skin
- char* psz_current = var_InheritString( getIntf(), "skins2-last" );
+ char* psz_current = config_GetPsz( getIntf(), "skins2-last" );
if( !psz_current )
return;
@@ -215,10 +225,18 @@ void ThemeRepository::updateRepository()
// add this new skins if not yet present in repository
string current( psz_current );
- if( m_skinsMap.find( current ) == m_skinsMap.end() )
+ map<string,string>::const_iterator it;
+ for( it = m_skinsMap.begin(); it != m_skinsMap.end(); it++ )
+ {
+ if( it->second == current )
+ break;
+ }
+ if( it == m_skinsMap.end() )
{
var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
&text );
+ string name = psz_current;
+ m_skinsMap[name] = name;
}
// mark this current skins as 'checked' in list
More information about the vlc-commits
mailing list