Commit 836c694f authored by Erwan Tulou's avatar 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)
parent bca9025a
......@@ -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;
......
......@@ -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 );
......
......@@ -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;
};
......
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