/// Callback called when a new skin is chosen void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg ) { intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg; if( pArg->i_results ) { if( pArg->psz_results[0] ) { // Create a change skin command CmdChangeSkin *pCmd = new CmdChangeSkin( pIntf, sFromLocale( pArg->psz_results[0] ) ); // Push the command in the asynchronous command queue AsyncQueue *pQueue = AsyncQueue::instance( pIntf ); pQueue->push( CmdGenericPtr( pCmd ) ); } } else if( !pIntf->p_sys->p_theme ) { // If no theme is already loaded, it's time to quit! CmdQuit *pCmd = new CmdQuit( pIntf ); AsyncQueue *pQueue = AsyncQueue::instance( pIntf ); pQueue->push( CmdGenericPtr( pCmd ) ); } }
// FIXME: could become a skins2 OS factory function or a vlc core function std::string ThemeLoader::getTmpDir( ) { #if defined( _WIN32 ) wchar_t *tmpdir = _wtempnam( NULL, L"vlt" ); if( tmpdir == NULL ) return ""; char* utf8 = FromWide( tmpdir ); free( tmpdir ); std::string tempPath( utf8 ? utf8 : "" ); free( utf8 ); return tempPath; #elif defined( __OS2__ ) char *tmpdir = tempnam( NULL, "vlt" ); if( tmpdir == NULL ) return ""; std::string tempPath( sFromLocale( tmpdir )); free( tmpdir ); return tempPath; #else char templ[] = "/tmp/vltXXXXXX"; char *tmpdir = mkdtemp( templ ); return std::string( tmpdir ? tmpdir : ""); #endif }
void ThemeRepository::parseDirectory( const string &rDir_locale ) { DIR *pDir; char *pszDirContent; vlc_value_t val, text; // Path separator const string &sep = OSFactory::instance( getIntf() )->getDirSeparator(); // Open the dir // FIXME: parseDirectory should be invoked with UTF-8 input instead!! string rDir = sFromLocale( rDir_locale ); pDir = utf8_opendir( rDir.c_str() ); if( pDir == NULL ) { // An error occurred msg_Dbg( getIntf(), "cannot open directory %s", rDir.c_str() ); return; } // While we still have entries in the directory while( ( pszDirContent = utf8_readdir( pDir ) ) != NULL ) { string name = pszDirContent; string extension; if( name.size() > 4 ) { extension = name.substr( name.size() - 4, 4 ); } 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 ); } free( pszDirContent ); } closedir( pDir ); }
void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg ) { intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg; if( pArg->i_results && pArg->psz_results[0] ) { // Create a Playlist Load command CmdPlaylistLoad *pCmd = new CmdPlaylistLoad( pIntf, sFromLocale( pArg->psz_results[0] ) ); // Push the command in the asynchronous command queue AsyncQueue *pQueue = AsyncQueue::instance( pIntf ); pQueue->push( CmdGenericPtr( pCmd ) ); } }
void ThemeRepository::parseDirectory( const string &rDir_locale ) { DIR *pDir; char *pszDirContent; // Path separator const string &sep = OSFactory::instance( getIntf() )->getDirSeparator(); // Open the dir // FIXME: parseDirectory should be invoked with UTF-8 input instead!! string rDir = sFromLocale( rDir_locale ); pDir = vlc_opendir( rDir.c_str() ); if( pDir == NULL ) { // An error occurred msg_Dbg( getIntf(), "cannot open directory %s", rDir.c_str() ); return; } // While we still have entries in the directory while( ( pszDirContent = vlc_readdir( pDir ) ) != NULL ) { string name = pszDirContent; string extension; if( name.size() > 4 ) { extension = name.substr( name.size() - 4, 4 ); } if( extension == ".vlt" || extension == ".wsz" ) { string path = rDir + sep + name; string shortname = name.substr( 0, name.size() - 4 ); for( string::size_type 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() ); } free( pszDirContent ); } closedir( pDir ); }
bool ThemeLoader::extract( const string &fileName ) { bool result = true; char *tmpdir = tempnam( NULL, "vlt" ); string tempPath = sFromLocale( tmpdir ); free( tmpdir ); // Extract the file in a temporary directory if( ! extractTarGz( fileName, tempPath ) && ! extractZip( fileName, tempPath ) ) { deleteTempFiles( tempPath ); return false; } string path; string xmlFile; OSFactory *pOsFactory = OSFactory::instance( getIntf() ); // Find the XML file in the theme if( findFile( tempPath, DEFAULT_XML_FILE, xmlFile ) ) { path = getFilePath( xmlFile ); } else { // No XML file, check if it is a winamp2 skin string mainBmp; if( findFile( tempPath, "main.bmp", mainBmp ) ) { msg_Dbg( getIntf(), "trying to load a winamp2 skin" ); path = getFilePath( mainBmp ); // Look for winamp2.xml in the resource path list<string> resPath = pOsFactory->getResourcePath(); list<string>::const_iterator it; for( it = resPath.begin(); it != resPath.end(); it++ ) { if( findFile( *it, WINAMP2_XML_FILE, xmlFile ) ) break; } } } if( !xmlFile.empty() ) { // Parse the XML file if (! parse( path, xmlFile ) ) { msg_Err( getIntf(), "error while parsing %s", xmlFile.c_str() ); result = false; } } else { msg_Err( getIntf(), "no XML found in theme %s", fileName.c_str() ); result = false; } // Clean-up deleteTempFiles( tempPath ); return result; }
bool ThemeLoader::findFile( const string &rootDir, const string &rFileName, string &themeFilePath ) { // Path separator const string &sep = OSFactory::instance( getIntf() )->getDirSeparator(); DIR *pCurrDir; struct dirent *pDirContent; // Open the dir pCurrDir = opendir( rootDir.c_str() ); if( pCurrDir == NULL ) { // An error occurred msg_Dbg( getIntf(), "cannot open directory %s", rootDir.c_str() ); return false; } // Get the first directory entry pDirContent = (dirent*)readdir( pCurrDir ); // While we still have entries in the directory while( pDirContent != NULL ) { string newURI = rootDir + sep + pDirContent->d_name; // Skip . and .. if( string( pDirContent->d_name ) != "." && string( pDirContent->d_name ) != ".." ) { #if defined( S_ISDIR ) struct stat stat_data; stat( newURI.c_str(), &stat_data ); if( S_ISDIR(stat_data.st_mode) ) #elif defined( DT_DIR ) if( pDirContent->d_type & DT_DIR ) #else if( 0 ) #endif { // Can we find the file in this subdirectory? if( findFile( newURI, rFileName, themeFilePath ) ) { closedir( pCurrDir ); return true; } } else { // Found the theme file? if( rFileName == string( pDirContent->d_name ) ) { themeFilePath = sFromLocale( newURI ); closedir( pCurrDir ); return true; } } } pDirContent = (dirent*)readdir( pCurrDir ); } closedir( pCurrDir ); return false; }