00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "theme_repository.hpp"
00025 #include "os_factory.hpp"
00026 #include "../commands/async_queue.hpp"
00027 #include "../commands/cmd_dialogs.hpp"
00028 #ifdef HAVE_UNISTD_H
00029 # include <unistd.h>
00030 #elif defined( WIN32 ) && !defined( UNDER_CE )
00031 # include <direct.h>
00032 #endif
00033 #ifdef HAVE_DIRENT_H
00034 # include <dirent.h>
00035 #endif
00036
00037
00038 const char *ThemeRepository::kOpenDialog = "{openSkin}";
00039
00040
00041 ThemeRepository *ThemeRepository::instance( intf_thread_t *pIntf )
00042 {
00043 if( pIntf->p_sys->p_repository == NULL )
00044 {
00045 pIntf->p_sys->p_repository = new ThemeRepository( pIntf );
00046 }
00047
00048 return pIntf->p_sys->p_repository;
00049 }
00050
00051
00052 void ThemeRepository::destroy( intf_thread_t *pIntf )
00053 {
00054 if( pIntf->p_sys->p_repository )
00055 {
00056 delete pIntf->p_sys->p_repository;
00057 pIntf->p_sys->p_repository = NULL;
00058 }
00059 }
00060
00061
00062 ThemeRepository::ThemeRepository( intf_thread_t *pIntf ): SkinObject( pIntf )
00063 {
00064 vlc_value_t val, text;
00065
00066
00067 var_Create( pIntf, "intf-skins", VLC_VAR_STRING |
00068 VLC_VAR_HASCHOICE | VLC_VAR_ISCOMMAND );
00069 text.psz_string = _("Select skin");
00070 var_Change( pIntf, "intf-skins", VLC_VAR_SETTEXT, &text, NULL );
00071
00072
00073 OSFactory *pOsFactory = OSFactory::instance( pIntf );
00074 list<string> resPath = pOsFactory->getResourcePath();
00075 list<string>::const_iterator it;
00076 for( it = resPath.begin(); it != resPath.end(); it++ )
00077 {
00078 parseDirectory( *it );
00079 }
00080
00081
00082 val.psz_string = (char*)kOpenDialog;
00083 text.psz_string = _("Open skin...");
00084 var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
00085 &text );
00086
00087
00088 var_AddCallback( pIntf, "intf-skins", changeSkin, this );
00089 }
00090
00091
00092 ThemeRepository::~ThemeRepository()
00093 {
00094 var_Destroy( getIntf(), "intf-skins" );
00095 }
00096
00097
00098 void ThemeRepository::parseDirectory( const string &rDir )
00099 {
00100 DIR *pDir;
00101 struct dirent *pDirContent;
00102 vlc_value_t val, text;
00103
00104 const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
00105
00106
00107 pDir = opendir( rDir.c_str() );
00108
00109 if( pDir == NULL )
00110 {
00111
00112 msg_Dbg( getIntf(), "Cannot open directory %s", rDir.c_str() );
00113 return;
00114 }
00115
00116
00117 pDirContent = (dirent*)readdir( pDir );
00118
00119
00120 while( pDirContent != NULL )
00121 {
00122 string name = pDirContent->d_name;
00123 if( name.size() > 4 && name.substr( name.size() - 4, 4 ) == ".vlt" )
00124 {
00125 string path = rDir + sep + name;
00126 msg_Dbg( getIntf(), "found skin %s", path.c_str() );
00127
00128
00129 string shortname = name.substr( 0, name.size() - 4 );
00130 val.psz_string = new char[path.size() + 1];
00131 text.psz_string = new char[shortname.size() + 1];
00132 strcpy( val.psz_string, path.c_str() );
00133 strcpy( text.psz_string, shortname.c_str() );
00134 var_Change( getIntf(), "intf-skins", VLC_VAR_ADDCHOICE, &val,
00135 &text );
00136 delete[] val.psz_string;
00137 delete[] text.psz_string;
00138 }
00139
00140 pDirContent = (dirent*)readdir( pDir );
00141 }
00142
00143 closedir( pDir );
00144 }
00145
00146
00147
00148 int ThemeRepository::changeSkin( vlc_object_t *pIntf, char const *pCmd,
00149 vlc_value_t oldval, vlc_value_t newval,
00150 void *pData )
00151 {
00152 ThemeRepository *pThis = (ThemeRepository*)(pData);
00153
00154
00155 if( !strcmp( newval.psz_string, kOpenDialog ) )
00156 {
00157 CmdDlgChangeSkin cmd( pThis->getIntf() );
00158 cmd.execute();
00159 }
00160 else
00161 {
00162
00163 CmdChangeSkin *pCmd = new CmdChangeSkin( pThis->getIntf(),
00164 newval.psz_string );
00165 AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
00166 pQueue->remove( "change skin" );
00167 pQueue->push( CmdGenericPtr( pCmd ) );
00168 }
00169
00170 return VLC_SUCCESS;
00171 }
00172