]> git.sesse.net Git - vlc/commitdiff
* src/os_factory.hpp: added a method OSFactory::getResourceDir()
authorCyril Deguet <asmax@videolan.org>
Mon, 12 Apr 2004 14:25:15 +0000 (14:25 +0000)
committerCyril Deguet <asmax@videolan.org>
Mon, 12 Apr 2004 14:25:15 +0000 (14:25 +0000)
   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

modules/gui/skins2/parser/builder.cpp
modules/gui/skins2/src/ft2_font.cpp
modules/gui/skins2/src/os_factory.hpp
modules/gui/skins2/src/skin_main.cpp
modules/gui/skins2/win32/win32_factory.cpp
modules/gui/skins2/win32/win32_factory.hpp
modules/gui/skins2/x11/x11_factory.cpp
modules/gui/skins2/x11/x11_factory.hpp

index d2b08d0f92e46930b934d044a22a702031f6d69c..adfc3c74b1796284a63735022d633f888ed9f240 100755 (executable)
@@ -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;
index fa3eae2871aa369a39af40724f8096a887459225..f4cddf27d5ab2b3e7e1323632078d86b459ad8b3 100644 (file)
@@ -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
index bd78d23f011723ad4f473e8748a7fb8e9efdab06..2009339aa0ea5bbe99922dced79484cd1e9b0ad4 100644 (file)
@@ -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;
index f1f73748a806221a2182f4bcf38253f030a0373e..bfdca687f855219acb04127d42872282cddd3209 100644 (file)
@@ -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 )
             {
index 956499efe0495bddafa83d5618c9b67ca1133a41..f8db23d45851023461b78680a1a2a4febbb5b0f7 100644 (file)
@@ -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;
 }
index c5b11c6ef278f33b4c2e6dc84ff751079e68a1cd..5213aeaa37f1f2e9697569c71a0f5a98ec2c993f 100644 (file)
@@ -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;
 };
 
 
index e4a7b6c589d13c567900492886ee8ba355bef95a..b37347181cc2a1140e6ff7c09d7d854c2788591d 100644 (file)
@@ -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();
index 41805fbe0bdb1deb4c75c33d0f6f54fb0ec26830..c3f351d60c8632260c8ec28bc02dd8c5a07fe6e8 100644 (file)
@@ -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