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,21 +714,31 @@ GenericFont *Builder::getFont( const string &fontId )
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;
......
......@@ -68,9 +68,13 @@ bool FT2Font::init()
// 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
......
......@@ -28,6 +28,7 @@
#include "skin_common.hpp"
#include "../utils/position.hpp"
#include <string>
#include <list>
class GenericWindow;
class OSBitmap;
......@@ -83,7 +84,10 @@ class OSFactory: public SkinObject
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;
......
......@@ -165,20 +165,24 @@ static void Run( intf_thread_t *p_intf )
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 )
{
......
......@@ -80,7 +80,7 @@ LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
Win32Factory::Win32Factory( intf_thread_t *pIntf ):
OSFactory( pIntf ), TransparentBlt( NULL ), AlphaBlend( NULL ),
SetLayeredWindowAttributes( NULL )
SetLayeredWindowAttributes( NULL ), m_dirSep( "\\" )
{
// see init()
}
......@@ -177,6 +177,10 @@ bool Win32Factory::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;
}
......
......@@ -65,7 +65,11 @@ class Win32Factory: public OSFactory
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;
......@@ -108,6 +112,10 @@ class Win32Factory: public OSFactory
HINSTANCE m_hMsimg32;
/// Handle on user32.dll (for SetLayeredWindowAttributes)
HINSTANCE m_hUser32;
/// Directory separator
const string m_dirSep;
/// Resource path
list<string> m_resourcePath;
};
......
......@@ -39,7 +39,7 @@
X11Factory::X11Factory( intf_thread_t *pIntf ): OSFactory( pIntf ),
m_pDisplay( NULL ), m_pTimerLoop( NULL )
m_pDisplay( NULL ), m_pTimerLoop( NULL ), m_dirSep( "/" )
{
// see init()
}
......@@ -69,6 +69,11 @@ bool X11Factory::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;
}
......@@ -111,12 +116,6 @@ OSTooltip *X11Factory::createOSTooltip()
}
const string X11Factory::getDirSeparator() const
{
return "/";
}
int X11Factory::getScreenWidth() const
{
Display *pDisplay = m_pDisplay->getDisplay();
......
......@@ -71,7 +71,11 @@ class X11Factory: public OSFactory
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;
......@@ -97,6 +101,10 @@ class X11Factory: public OSFactory
X11Display *m_pDisplay;
/// Timer loop
X11TimerLoop *m_pTimerLoop;
/// Directory separator
const string m_dirSep;
/// Resource path
list<string> m_resourcePath;
};
#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