Commit 79944bce authored by Erwan Tulou's avatar Erwan Tulou

skins2: improve list of skins

- make it case insensitive and sorted alphabetically
- fix a few regressions about config_Get vs. var_Inherit
parent a18b31a4
...@@ -256,7 +256,7 @@ static void *Run( void * p_obj ) ...@@ -256,7 +256,7 @@ static void *Run( void * p_obj )
} }
// Load a theme // Load a theme
skin_last = var_InheritString( p_intf, "skins2-last" ); skin_last = config_GetPsz( p_intf, "skins2-last" );
pLoader = new ThemeLoader( p_intf ); pLoader = new ThemeLoader( p_intf );
if( !skin_last || !pLoader->load( skin_last ) ) if( !skin_last || !pLoader->load( skin_last ) )
......
...@@ -98,7 +98,7 @@ bool ThemeLoader::load( const string &fileName ) ...@@ -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 // 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 ) if( skin_last != NULL && fileName == (string)skin_last )
{ {
// Restore the theme configuration // Restore the theme configuration
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
# include <dirent.h> # include <dirent.h>
#endif #endif
#include <fstream>
ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf ) ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf )
...@@ -77,29 +78,34 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf ) ...@@ -77,29 +78,34 @@ ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
map<string,string>::const_iterator itmap, itdefault; map<string,string>::const_iterator itmap, itdefault;
for( itmap = m_skinsMap.begin(); itmap != m_skinsMap.end(); itmap++ ) for( itmap = m_skinsMap.begin(); itmap != m_skinsMap.end(); itmap++ )
{ {
string path = itmap->first; string name = itmap->first;
string name = itmap->second; string path = itmap->second;
val.psz_string = (char*) path.c_str(); val.psz_string = (char*) path.c_str();
text.psz_string = (char*) name.c_str(); text.psz_string = (char*) name.c_str();
var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val, var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
&text ); &text );
if( name == "default" ) if( name == "Default" )
itdefault = itmap; itdefault = itmap;
} }
// retrieve last skins stored or skins requested by user // retrieve last skins stored or skins requested by user
char* psz_current = var_InheritString( getIntf(), "skins2-last" ); char* psz_current = var_InheritString( getIntf(), "skins2-last" );
string current = string( psz_current ? psz_current : "" ); string current = string( psz_current ? psz_current : "" );
free( psz_current );
// set the default skins if no skins provided // check if skins exists and is readable
if( current.size() == 0 ) bool b_readable = !ifstream( current.c_str() ).fail();
{
current = itdefault->first;
config_PutPsz( getIntf(), "skins2-last", current.c_str() );
}
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 // Update repository
updateRepository(); updateRepository();
...@@ -164,7 +170,11 @@ void ThemeRepository::parseDirectory( const string &rDir_locale ) ...@@ -164,7 +170,11 @@ void ThemeRepository::parseDirectory( const string &rDir_locale )
{ {
string path = rDir + sep + name; string path = rDir + sep + name;
string shortname = name.substr( 0, name.size() - 4 ); 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() ); msg_Dbg( getIntf(), "found skin %s", path.c_str() );
} }
...@@ -206,7 +216,7 @@ void ThemeRepository::updateRepository() ...@@ -206,7 +216,7 @@ void ThemeRepository::updateRepository()
vlc_value_t val, text; vlc_value_t val, text;
// retrieve the current skin // retrieve the current skin
char* psz_current = var_InheritString( getIntf(), "skins2-last" ); char* psz_current = config_GetPsz( getIntf(), "skins2-last" );
if( !psz_current ) if( !psz_current )
return; return;
...@@ -215,10 +225,18 @@ void ThemeRepository::updateRepository() ...@@ -215,10 +225,18 @@ void ThemeRepository::updateRepository()
// add this new skins if not yet present in repository // add this new skins if not yet present in repository
string current( psz_current ); 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, var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
&text ); &text );
string name = psz_current;
m_skinsMap[name] = name;
} }
// mark this current skins as 'checked' in list // mark this current skins as 'checked' in list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment