to get a list of possible resource directories for skins2.
On linux the path is "~/.vlc/skins2:VLC_INSTALL_DIR/share/skins2"
and on win32 it is "VLC_PATH\skins2'
* src/skin_main.cpp: use the getResourceDir() method instead of #ifdef
* parser/builder.cpp: the default font is looked up in the resource dir,
so you can put fonts in ~/.vlc/skins2/fonts and avoid a make install
GenericFont *pFont = m_pTheme->getFontById(fontId);
if( !pFont && fontId == "defaultfont" )
{
-#ifdef WIN32_SKINS
- string defaultFont = (string)getIntf()->p_libvlc->psz_vlcpath +
- "\\skins2\\fonts\\FreeSans.ttf";
-#else
- string defaultFont = (string)DATA_PATH + "/skins2/fonts/FreeSans.ttf";
-#endif
- pFont = new FT2Font( getIntf(), defaultFont, 12 );
- if( pFont->init() )
+ // Get the resource path and try to load the default font
+ OSFactory *pOSFactory = OSFactory::instance( getIntf() );
+ const list<string> &resPath = pOSFactory->getResourcePath();
+ const string &sep = pOSFactory->getDirSeparator();
+
+ list<string>::const_iterator it;
+ for( it = resPath.begin(); it != resPath.end(); it++ )
{
- m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
+ string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
+ pFont = new FT2Font( getIntf(), path, 12 );
+ if( pFont->init() )
+ {
+ // Font loaded successfully
+ m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
+ break;
+ }
+ else
+ {
+ delete pFont;
+ pFont = NULL;
+ }
}
- else
+ if( !pFont )
{
- delete pFont;
- pFont = NULL;
+ msg_Err( getIntf(), "Failed to open the default font" );
}
}
return pFont;
// Open the font
FILE *file = fopen( m_name.c_str(), "rb" );
- if( !file )
+ if( file )
{
- msg_Err( getIntf(), "Unable to open the font %s", m_name.c_str() );
+ msg_Dbg( getIntf(), "Loading font %s", m_name.c_str() );
+ }
+ else
+ {
+ msg_Dbg( getIntf(), "Unable to open the font %s", m_name.c_str() );
return false;
}
// Get the file size
#include "skin_common.hpp"
#include "../utils/position.hpp"
#include <string>
+#include <list>
class GenericWindow;
class OSBitmap;
virtual OSTooltip *createOSTooltip() = 0;
/// Get the directory separator
- virtual const string getDirSeparator() const = 0;
+ virtual const string &getDirSeparator() const = 0;
+
+ /// Get the resource path
+ virtual const list<string> &getResourcePath() const = 0;
/// Get the screen size
virtual int getScreenWidth() const = 0;
if( skin_last == NULL || !pLoader->load( skin_last ) )
{
- // Too bad, it failed. Let's try with the default theme
-#ifdef WIN32_SKINS
- string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
- "\\skins2\\default\\theme.xml";
- if( !pLoader->load( default_dir ) )
-#else
- string user_skin = (string)p_intf->p_vlc->psz_homedir +
- "/" + CONFIG_DIR + "/skins2/default/theme.xml";
-
- string default_skin = (string)DATA_PATH + "/skins2/default/theme.xml";
- if( !pLoader->load( user_skin ) && !pLoader->load( default_skin ) )
-#endif
+ // 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" + sep + "theme.xml";
+ if( pLoader->load( path ) )
+ {
+ // Theme loaded successfully
+ break;
+ }
+ }
+ if( it == resPath.end() )
{
- // Last chance: the user can select a new theme file (blocking call)
+ // Last chance: the user can select a new theme file
Dialogs *pDialogs = Dialogs::instance( p_intf );
if( pDialogs )
{
Win32Factory::Win32Factory( intf_thread_t *pIntf ):
OSFactory( pIntf ), TransparentBlt( NULL ), AlphaBlend( NULL ),
- SetLayeredWindowAttributes( NULL )
+ SetLayeredWindowAttributes( NULL ), m_dirSep( "\\" )
{
// see init()
}
msg_Dbg( getIntf(), "Couldn't find SetLayeredWindowAttributes()" );
}
+ // Initialize the resource path
+ m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
+ "\\skins2" );
+
// All went well
return true;
}
virtual OSTooltip *createOSTooltip();
/// Get the directory separator
- virtual const string getDirSeparator() const;
+ virtual const string &getDirSeparator() const { return m_dirSep; }
+
+ /// Get the resource path
+ virtual const list<string> &getResourcePath() const
+ { return m_resourcePath; }
/// Get the screen size
virtual int getScreenWidth() const;
HINSTANCE m_hMsimg32;
/// Handle on user32.dll (for SetLayeredWindowAttributes)
HINSTANCE m_hUser32;
+ /// Directory separator
+ const string m_dirSep;
+ /// Resource path
+ list<string> m_resourcePath;
};
X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
- m_pDisplay( NULL ), m_pTimerLoop( NULL )
+ m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
{
// see init()
}
m_pTimerLoop = new X11TimerLoop( getIntf(),
ConnectionNumber( pDisplay ) );
+ // Initialize the resource path
+ m_resourcePath.push_back( (string)getIntf()->p_vlc->psz_homedir +
+ m_dirSep + CONFIG_DIR + "/skins2" );
+ m_resourcePath.push_back( (string)DATA_PATH + "/skins2" );
+
return true;
}
}
-const string X11Factory::getDirSeparator() const
-{
- return "/";
-}
-
-
int X11Factory::getScreenWidth() const
{
Display *pDisplay = m_pDisplay->getDisplay();
virtual OSTooltip *createOSTooltip();
/// Get the directory separator
- virtual const string getDirSeparator() const;
+ virtual const string &getDirSeparator() const { return m_dirSep; }
+
+ /// Get the resource path
+ virtual const list<string> &getResourcePath() const
+ { return m_resourcePath; }
/// Get the screen size
virtual int getScreenWidth() const;
X11Display *m_pDisplay;
/// Timer loop
X11TimerLoop *m_pTimerLoop;
+ /// Directory separator
+ const string m_dirSep;
+ /// Resource path
+ list<string> m_resourcePath;
};
#endif