Commit 9d191f1d authored by Cyril Deguet's avatar Cyril Deguet

* src/os_factory.hpp: added a method OSFactory::getResourceDir()

   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
parent 064e918c
...@@ -714,16 +714,21 @@ GenericFont *Builder::getFont( const string &fontId ) ...@@ -714,16 +714,21 @@ GenericFont *Builder::getFont( const string &fontId )
GenericFont *pFont = m_pTheme->getFontById(fontId); GenericFont *pFont = m_pTheme->getFontById(fontId);
if( !pFont && fontId == "defaultfont" ) if( !pFont && fontId == "defaultfont" )
{ {
#ifdef WIN32_SKINS // Get the resource path and try to load the default font
string defaultFont = (string)getIntf()->p_libvlc->psz_vlcpath + OSFactory *pOSFactory = OSFactory::instance( getIntf() );
"\\skins2\\fonts\\FreeSans.ttf"; const list<string> &resPath = pOSFactory->getResourcePath();
#else const string &sep = pOSFactory->getDirSeparator();
string defaultFont = (string)DATA_PATH + "/skins2/fonts/FreeSans.ttf";
#endif list<string>::const_iterator it;
pFont = new FT2Font( getIntf(), defaultFont, 12 ); for( it = resPath.begin(); it != resPath.end(); it++ )
{
string path = (*it) + sep + "fonts" + sep + "FreeSans.ttf";
pFont = new FT2Font( getIntf(), path, 12 );
if( pFont->init() ) if( pFont->init() )
{ {
// Font loaded successfully
m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont ); m_pTheme->m_fonts["defaultfont"] = GenericFontPtr( pFont );
break;
} }
else else
{ {
...@@ -731,6 +736,11 @@ GenericFont *Builder::getFont( const string &fontId ) ...@@ -731,6 +736,11 @@ GenericFont *Builder::getFont( const string &fontId )
pFont = NULL; pFont = NULL;
} }
} }
if( !pFont )
{
msg_Err( getIntf(), "Failed to open the default font" );
}
}
return pFont; return pFont;
} }
......
...@@ -68,9 +68,13 @@ bool FT2Font::init() ...@@ -68,9 +68,13 @@ bool FT2Font::init()
// Open the font // Open the font
FILE *file = fopen( m_name.c_str(), "rb" ); 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; return false;
} }
// Get the file size // Get the file size
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "skin_common.hpp" #include "skin_common.hpp"
#include "../utils/position.hpp" #include "../utils/position.hpp"
#include <string> #include <string>
#include <list>
class GenericWindow; class GenericWindow;
class OSBitmap; class OSBitmap;
...@@ -83,7 +84,10 @@ class OSFactory: public SkinObject ...@@ -83,7 +84,10 @@ class OSFactory: public SkinObject
virtual OSTooltip *createOSTooltip() = 0; virtual OSTooltip *createOSTooltip() = 0;
/// Get the directory separator /// 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 /// Get the screen size
virtual int getScreenWidth() const = 0; virtual int getScreenWidth() const = 0;
......
...@@ -165,20 +165,24 @@ static void Run( intf_thread_t *p_intf ) ...@@ -165,20 +165,24 @@ static void Run( intf_thread_t *p_intf )
if( skin_last == NULL || !pLoader->load( skin_last ) ) if( skin_last == NULL || !pLoader->load( skin_last ) )
{ {
// Too bad, it failed. Let's try with the default theme // Get the resource path and try to load the default skin
#ifdef WIN32_SKINS OSFactory *pOSFactory = OSFactory::instance( p_intf );
string default_dir = (string)p_intf->p_libvlc->psz_vlcpath + const list<string> &resPath = pOSFactory->getResourcePath();
"\\skins2\\default\\theme.xml"; const string &sep = pOSFactory->getDirSeparator();
if( !pLoader->load( default_dir ) )
#else list<string>::const_iterator it;
string user_skin = (string)p_intf->p_vlc->psz_homedir + for( it = resPath.begin(); it != resPath.end(); it++ )
"/" + CONFIG_DIR + "/skins2/default/theme.xml"; {
string path = (*it) + sep + "default" + sep + "theme.xml";
string default_skin = (string)DATA_PATH + "/skins2/default/theme.xml"; if( pLoader->load( path ) )
if( !pLoader->load( user_skin ) && !pLoader->load( default_skin ) ) {
#endif // 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 ); Dialogs *pDialogs = Dialogs::instance( p_intf );
if( pDialogs ) if( pDialogs )
{ {
......
...@@ -80,7 +80,7 @@ LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) ...@@ -80,7 +80,7 @@ LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
Win32Factory::Win32Factory( intf_thread_t *pIntf ): Win32Factory::Win32Factory( intf_thread_t *pIntf ):
OSFactory( pIntf ), TransparentBlt( NULL ), AlphaBlend( NULL ), OSFactory( pIntf ), TransparentBlt( NULL ), AlphaBlend( NULL ),
SetLayeredWindowAttributes( NULL ) SetLayeredWindowAttributes( NULL ), m_dirSep( "\\" )
{ {
// see init() // see init()
} }
...@@ -177,6 +177,10 @@ bool Win32Factory::init() ...@@ -177,6 +177,10 @@ bool Win32Factory::init()
msg_Dbg( getIntf(), "Couldn't find SetLayeredWindowAttributes()" ); 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 // All went well
return true; return true;
} }
......
...@@ -65,7 +65,11 @@ class Win32Factory: public OSFactory ...@@ -65,7 +65,11 @@ class Win32Factory: public OSFactory
virtual OSTooltip *createOSTooltip(); virtual OSTooltip *createOSTooltip();
/// Get the directory separator /// 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 /// Get the screen size
virtual int getScreenWidth() const; virtual int getScreenWidth() const;
...@@ -108,6 +112,10 @@ class Win32Factory: public OSFactory ...@@ -108,6 +112,10 @@ class Win32Factory: public OSFactory
HINSTANCE m_hMsimg32; HINSTANCE m_hMsimg32;
/// Handle on user32.dll (for SetLayeredWindowAttributes) /// Handle on user32.dll (for SetLayeredWindowAttributes)
HINSTANCE m_hUser32; HINSTANCE m_hUser32;
/// Directory separator
const string m_dirSep;
/// Resource path
list<string> m_resourcePath;
}; };
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ), X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
m_pDisplay( NULL ), m_pTimerLoop( NULL ) m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
{ {
// see init() // see init()
} }
...@@ -69,6 +69,11 @@ bool X11Factory::init() ...@@ -69,6 +69,11 @@ bool X11Factory::init()
m_pTimerLoop = new X11TimerLoop( getIntf(), m_pTimerLoop = new X11TimerLoop( getIntf(),
ConnectionNumber( pDisplay ) ); 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; return true;
} }
...@@ -111,12 +116,6 @@ OSTooltip *X11Factory::createOSTooltip() ...@@ -111,12 +116,6 @@ OSTooltip *X11Factory::createOSTooltip()
} }
const string X11Factory::getDirSeparator() const
{
return "/";
}
int X11Factory::getScreenWidth() const int X11Factory::getScreenWidth() const
{ {
Display *pDisplay = m_pDisplay->getDisplay(); Display *pDisplay = m_pDisplay->getDisplay();
......
...@@ -71,7 +71,11 @@ class X11Factory: public OSFactory ...@@ -71,7 +71,11 @@ class X11Factory: public OSFactory
virtual OSTooltip *createOSTooltip(); virtual OSTooltip *createOSTooltip();
/// Get the directory separator /// 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 /// Get the screen size
virtual int getScreenWidth() const; virtual int getScreenWidth() const;
...@@ -97,6 +101,10 @@ class X11Factory: public OSFactory ...@@ -97,6 +101,10 @@ class X11Factory: public OSFactory
X11Display *m_pDisplay; X11Display *m_pDisplay;
/// Timer loop /// Timer loop
X11TimerLoop *m_pTimerLoop; X11TimerLoop *m_pTimerLoop;
/// Directory separator
const string m_dirSep;
/// Resource path
list<string> m_resourcePath;
}; };
#endif #endif
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