Commit 4d447b06 authored by Cyril Deguet's avatar Cyril Deguet

* winamp2.xml: generic theme file for winamp2 skins. Still a

 lot of things to do but it works !
* theme_loader.cpp: when a theme contains no XML file, assume
 we are trying to load a winamp skin, and use winamp2.xml
* vlcproc.cpp: repaired text variables ($N was broken)
parent 1ada3176
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*****************************************************************************/ *****************************************************************************/
#include "skin_parser.hpp" #include "skin_parser.hpp"
#include "../src/os_factory.hpp"
#include <math.h> #include <math.h>
SkinParser::SkinParser( intf_thread_t *pIntf, const string &rFileName, SkinParser::SkinParser( intf_thread_t *pIntf, const string &rFileName,
...@@ -497,7 +498,8 @@ int SkinParser::convertColor( const char *transcolor ) const ...@@ -497,7 +498,8 @@ int SkinParser::convertColor( const char *transcolor ) const
string SkinParser::convertFileName( const char *fileName ) const string SkinParser::convertFileName( const char *fileName ) const
{ {
return m_path + string( fileName ); OSFactory *pFactory = OSFactory::instance( getIntf() );
return m_path + pFactory->getDirSeparator() + string( fileName );
} }
......
...@@ -67,6 +67,7 @@ int makedir( const char *newdir ); ...@@ -67,6 +67,7 @@ int makedir( const char *newdir );
#endif #endif
#define DEFAULT_XML_FILE "theme.xml" #define DEFAULT_XML_FILE "theme.xml"
#define WINAMP2_XML_FILE "winamp2.xml"
#define ZIP_BUFFER_SIZE 4096 #define ZIP_BUFFER_SIZE 4096
...@@ -74,11 +75,12 @@ bool ThemeLoader::load( const string &fileName ) ...@@ -74,11 +75,12 @@ bool ThemeLoader::load( const string &fileName )
{ {
// First, we try to un-targz the file, and if it fails we hope it's a XML // First, we try to un-targz the file, and if it fails we hope it's a XML
// file... // file...
string path = getFilePath( fileName );
#if defined( HAVE_ZLIB_H ) #if defined( HAVE_ZLIB_H )
if( ! extract( fileName ) && ! parse( fileName ) ) if( ! extract( fileName ) && ! parse( path, fileName ) )
return false; return false;
#else #else
if( ! parse( fileName ) ) if( ! parse( path, fileName ) )
return false; return false;
#endif #endif
...@@ -203,22 +205,10 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir ) ...@@ -203,22 +205,10 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir )
// Get the path of the file // Get the path of the file
string fullPath = rootDir + "/" + filenameInZip; string fullPath = rootDir + "/" + filenameInZip;
string::size_type pos = fullPath.rfind( '/' ); string basePath = getFilePath( fullPath );
string basePath;
if( pos != string::npos )
{
if( pos < fullPath.size() - 1)
{
basePath = fullPath.substr( 0, pos );
}
else
{
basePath = fullPath;
}
}
// Extract the file if is not a directory // Extract the file if is not a directory
if( pos != fullPath.size() - 1 ) if( basePath != fullPath )
{ {
if( unzOpenCurrentFile( file ) ) if( unzOpenCurrentFile( file ) )
{ {
...@@ -273,6 +263,7 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir ) ...@@ -273,6 +263,7 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir )
bool ThemeLoader::extract( const string &fileName ) bool ThemeLoader::extract( const string &fileName )
{ {
bool result = true;
char *tmpdir = tempnam( NULL, "vlt" ); char *tmpdir = tempnam( NULL, "vlt" );
string tempPath = tmpdir; string tempPath = tmpdir;
free( tmpdir ); free( tmpdir );
...@@ -282,19 +273,47 @@ bool ThemeLoader::extract( const string &fileName ) ...@@ -282,19 +273,47 @@ bool ThemeLoader::extract( const string &fileName )
! extractZip( fileName, tempPath ) ) ! extractZip( fileName, tempPath ) )
return false; return false;
// Find the XML file and parse it string path;
string xmlFile; string xmlFile;
if( ! findThemeFile( tempPath, xmlFile ) || ! parse( xmlFile ) ) OSFactory *pOsFactory = OSFactory::instance( getIntf() );
// Find the XML file in the theme
if( findFile( tempPath, DEFAULT_XML_FILE, xmlFile ) )
{ {
msg_Err( getIntf(), "%s doesn't contain a " DEFAULT_XML_FILE " file", path = getFilePath( xmlFile );
fileName.c_str() ); }
deleteTempFiles( tempPath ); else
return false; {
// No XML file, assume it is a winamp2 skin
path = tempPath;
// 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 // Clean-up
deleteTempFiles( tempPath ); deleteTempFiles( tempPath );
return true; return result;
} }
...@@ -305,24 +324,11 @@ void ThemeLoader::deleteTempFiles( const string &path ) ...@@ -305,24 +324,11 @@ void ThemeLoader::deleteTempFiles( const string &path )
#endif // HAVE_ZLIB_H #endif // HAVE_ZLIB_H
bool ThemeLoader::parse( const string &xmlFile ) bool ThemeLoader::parse( const string &path, const string &xmlFile )
{ {
// File loaded // File loaded
msg_Dbg( getIntf(), "Using skin file: %s", xmlFile.c_str() ); msg_Dbg( getIntf(), "Using skin file: %s", xmlFile.c_str() );
// Extract the path of the XML file
string path;
const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
string::size_type p = xmlFile.rfind( sep, xmlFile.size() );
if( p != string::npos )
{
path = xmlFile.substr( 0, p + 1 );
}
else
{
path = "";
}
// Start the parser // Start the parser
SkinParser parser( getIntf(), xmlFile, path ); SkinParser parser( getIntf(), xmlFile, path );
if( ! parser.parse() ) if( ! parser.parse() )
...@@ -339,7 +345,30 @@ bool ThemeLoader::parse( const string &xmlFile ) ...@@ -339,7 +345,30 @@ bool ThemeLoader::parse( const string &xmlFile )
} }
bool ThemeLoader::findThemeFile( const string &rootDir, string &themeFilePath ) string ThemeLoader::getFilePath( const string &rFullPath )
{
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
const string &sep = pOsFactory->getDirSeparator();
// Find the last separator ('/' or '\')
string::size_type p = rFullPath.rfind( sep, rFullPath.size() );
string basePath;
if( p != string::npos )
{
if( p < rFullPath.size() - 1)
{
basePath = rFullPath.substr( 0, p );
}
else
{
basePath = rFullPath;
}
}
return basePath;
}
bool ThemeLoader::findFile( const string &rootDir, const string &rFileName,
string &themeFilePath )
{ {
// Path separator // Path separator
const string &sep = OSFactory::instance( getIntf() )->getDirSeparator(); const string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
...@@ -379,8 +408,8 @@ bool ThemeLoader::findThemeFile( const string &rootDir, string &themeFilePath ) ...@@ -379,8 +408,8 @@ bool ThemeLoader::findThemeFile( const string &rootDir, string &themeFilePath )
if( 0 ) if( 0 )
#endif #endif
{ {
// Can we find the theme file in this subdirectory? // Can we find the file in this subdirectory?
if( findThemeFile( newURI, themeFilePath ) ) if( findFile( newURI, rFileName, themeFilePath ) )
{ {
closedir( pCurrDir ); closedir( pCurrDir );
return true; return true;
...@@ -389,8 +418,7 @@ bool ThemeLoader::findThemeFile( const string &rootDir, string &themeFilePath ) ...@@ -389,8 +418,7 @@ bool ThemeLoader::findThemeFile( const string &rootDir, string &themeFilePath )
else else
{ {
// Found the theme file? // Found the theme file?
if( string( DEFAULT_XML_FILE ) == if( rFileName == string( pDirContent->d_name ) )
string( pDirContent->d_name ) )
{ {
themeFilePath = newURI; themeFilePath = newURI;
closedir( pCurrDir ); closedir( pCurrDir );
......
...@@ -58,13 +58,17 @@ class ThemeLoader: public SkinObject ...@@ -58,13 +58,17 @@ class ThemeLoader: public SkinObject
#endif #endif
/// Parse the XML file given as a parameter and build the skin /// Parse the XML file given as a parameter and build the skin
bool parse( const string &xmlFile ); bool parse( const string &path, const string &xmlFile );
/// Recursively look for the XML file from rootDir. /// Recursively look for the XML file from rootDir.
/// The first corresponding file found will be chosen and themeFilePath /// The first corresponding file found will be chosen and themeFilePath
/// will be updated accordingly. /// will be updated accordingly.
/// The method returns true if a theme file was found, false otherwise /// The method returns true if a theme file was found, false otherwise
bool findThemeFile( const string &rootDir, string &themeFilePath ); bool findFile( const string &rootDir, const string &rFileName,
string &themeFilePath );
/// Get the base path of a file
string getFilePath( const string &rFullPath );
}; };
#endif #endif
...@@ -403,7 +403,7 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable, ...@@ -403,7 +403,7 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
// Push the command in the asynchronous command queue // Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
pQueue->push( CmdGenericPtr( pCmd ) ); pQueue->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmdTree ) ); pQueue->push( CmdGenericPtr( pCmdTree ), false );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -479,8 +479,8 @@ void VlcProc::updateStreamName( playlist_t *p_playlist ) ...@@ -479,8 +479,8 @@ void VlcProc::updateStreamName( playlist_t *p_playlist )
CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI ); CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI );
// Push the commands in the asynchronous command queue // Push the commands in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( getIntf() ); AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
pQueue->push( CmdGenericPtr( pCmd1 ) ); pQueue->push( CmdGenericPtr( pCmd1 ), false );
pQueue->push( CmdGenericPtr( pCmd2 ) ); pQueue->push( CmdGenericPtr( pCmd2 ), false );
} }
} }
......
...@@ -80,6 +80,7 @@ DIST_skins2 = \ ...@@ -80,6 +80,7 @@ DIST_skins2 = \
skins2/fonts/FreeSans.ttf \ skins2/fonts/FreeSans.ttf \
skins2/skin.dtd \ skins2/skin.dtd \
skins2/skin.catalog \ skins2/skin.catalog \
skins2/winamp2.xml \
$(NULL) $(NULL)
DIST_http = \ DIST_http = \
......
<!DOCTYPE Theme PUBLIC "-//VideoLAN//DTD VLC Skins V2.0//EN" "skins.dtd">
<Theme version="2.0" magnet="9" alpha="255">
<ThemeInfo name="Winamp2" author="Cyril Deguet"/>
<Bitmap id="main" file="main.bmp" alphacolor="#FF0000" />
<Bitmap id="cbuttons" file="cbuttons.bmp" alphacolor="#FF0000">
<SubBitmap id="previous_up" x="0" y="0" width="23" height="18" />
<SubBitmap id="previous_down" x="0" y="18" width="23" height="18" />
<SubBitmap id="play_up" x="23" y="0" width="23" height="18" />
<SubBitmap id="play_down" x="23" y="18" width="23" height="18" />
<SubBitmap id="pause_up" x="46" y="0" width="23" height="18" />
<SubBitmap id="pause_down" x="46" y="18" width="23" height="18" />
<SubBitmap id="stop_up" x="69" y="0" width="23" height="18" />
<SubBitmap id="stop_down" x="69" y="18" width="23" height="18" />
<SubBitmap id="next_up" x="92" y="0" width="22" height="18" />
<SubBitmap id="next_down" x="92" y="18" width="22" height="18" />
<SubBitmap id="eject_up" x="114" y="0" width="22" height="16" />
<SubBitmap id="eject_down" x="114" y="16" width="22" height="16" />
</Bitmap>
<Bitmap id="titlebar" file="titlebar.bmp" alphacolor="#FF0000" >
<SubBitmap id="quit_up" x="18" y="0" width="9" height="9" />
<SubBitmap id="quit_down" x="18" y="9" width="9" height="9" />
</Bitmap>
<BitmapFont id="digits_font" file="nums_ex.bmp" type="digits"/>
<BitmapFont id="text_font" file="text.bmp" type="text"/>
<Window id="mainWindow" x="400" y="50">
<Layout id="bigLayout" width="275" height="116">
<Group x="0" y="0">
<Image x="0" y="0" image="main" action="move" />
<Text font="digits_font" x="30" y="26" width="75" text="$T"/>
<Text font="text_font" x="111" y="27" width="155" text="$N"/>
<Button x="263" y="3" up="quit_up" down="quit_down" over="quit_up" action="vlc.quit()" tooltiptext="Quit" />
<Button x="16" y="88" up="previous_up" down="previous_down" action="playlist.previous()" tooltiptext="Previous" />
<Button x="39" y="88" up="play_up" down="play_down" action="vlc.play()" tooltiptext="Play" />
<Button x="62" y="88" up="pause_up" down="pause_down" action="vlc.pause()" tooltiptext="Pause" />
<Button x="85" y="88" up="stop_up" down="stop_down" action="vlc.stop()" tooltiptext="Stop" />
<Button x="108" y="88" up="next_up" down="next_down" action="playlist.next()" tooltiptext="Next" />
<Button x="136" y="88" up="eject_up" down="eject_down" action="dialogs.fileSimple()" tooltiptext="Open" />
</Group>
</Layout>
</Window>
</Theme>
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