1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "theme_repository.hpp"
25 #include "os_factory.hpp"
26 #include "../commands/async_queue.hpp"
27 #include "../commands/cmd_dialogs.hpp"
30 #elif defined( WIN32 ) && !defined( UNDER_CE )
38 const char *ThemeRepository::kOpenDialog = "{openSkin}";
41 ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf )
43 if( pIntf->p_sys->p_repository == NULL )
45 pIntf->p_sys->p_repository = new ThemeRepository( pIntf );
48 return pIntf->p_sys->p_repository;
52 void ThemeRepository::destroy( intf_thread_t *pIntf )
54 if( pIntf->p_sys->p_repository )
56 delete pIntf->p_sys->p_repository;
57 pIntf->p_sys->p_repository = NULL;
62 ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
64 vlc_value_t val, text;
66 // Create a variable to add items in wxwindows popup menu
67 var_Create( pIntf, "intf-skins", VLC_VAR_STRING |
68 VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND );
69 text.psz_string = _("Select skin");
70 var_Change( pIntf, "intf-skins", VLC_VAR_SETTEXT, &text, NULL );
72 // Scan vlt files in the resource path
73 OSFactory *pOsFactory = OSFactory::instance( pIntf );
74 list<string> resPath = pOsFactory->getResourcePath();
75 list<string>::const_iterator it;
76 for( it = resPath.begin(); it != resPath.end(); it++ )
78 parseDirectory( *it );
81 // Add an entry for the "open skin" dialog
82 val.psz_string = (char*)kOpenDialog;
83 text.psz_string = _("Open skin...");
84 var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
88 var_AddCallback( pIntf, "intf-skins", changeSkin, this );
92 ThemeRepository::~ThemeRepository()
94 var_Destroy( getIntf(), "intf-skins" );
98 void ThemeRepository::parseDirectory( const string &rDir_locale )
102 vlc_value_t val, text;
104 const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
107 // FIXME: parseDirectory should be invoked with UTF-8 input instead!!
108 string rDir = sFromLocale( rDir_locale );
109 pDir = utf8_opendir( rDir.c_str() );
114 msg_Dbg( getIntf(), "cannot open directory %s", rDir.c_str() );
118 // While we still have entries in the directory
119 while( ( pszDirContent = utf8_readdir( pDir ) ) != NULL )
121 string name = pszDirContent;
123 if( name.size() > 4 )
125 extension = name.substr( name.size() - 4, 4 );
127 if( extension == ".vlt" || extension == ".wsz" )
129 string path = rDir + sep + name;
130 msg_Dbg( getIntf(), "found skin %s", path.c_str() );
132 // Add the theme in the popup menu
133 string shortname = name.substr( 0, name.size() - 4 );
134 val.psz_string = new char[path.size() + 1];
135 text.psz_string = new char[shortname.size() + 1];
136 strcpy( val.psz_string, path.c_str() );
137 strcpy( text.psz_string, shortname.c_str() );
138 var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
140 delete[] val.psz_string;
141 delete[] text.psz_string;
144 free( pszDirContent );
152 int ThemeRepository::changeSkin( vlc_object_t *pIntf, char const *pCmd,
153 vlc_value_t oldval, vlc_value_t newval,
156 ThemeRepository *pThis = (ThemeRepository*)(pData);
158 // Special menu entry for the open skin dialog
159 if( !strcmp( newval.psz_string, kOpenDialog ) )
161 CmdDlgChangeSkin cmd( pThis->getIntf() );
166 // Try to load the new skin
167 CmdChangeSkin *pCmd = new CmdChangeSkin( pThis->getIntf(),
169 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
170 pQueue->push( CmdGenericPtr( pCmd ) );