[vlc-commits] commit: skins2: rework theme loader (Erwan Tulou )

git at videolan.org git at videolan.org
Sat Jul 31 18:07:00 CEST 2010


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Jul 31 16:14:43 2010 +0200| [b0ad9149cedf0c94932ed8c9ae034e63accbed41] | committer: Erwan Tulou 

skins2: rework theme loader

This patch does the following:
   - fix skins that could not be saved, because their ids contained the space
     character. Names are now enclosed between "" to preserve those spaces.
   - show windows only when the init and check work is done. This avoids
     fleeting windows that sometimes occur (usually visible on Linux)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b0ad9149cedf0c94932ed8c9ae034e63accbed41
---

 modules/gui/skins2/src/theme.cpp        |  134 ++++++++++++++++++++++---------
 modules/gui/skins2/src/theme.hpp        |   15 ++++
 modules/gui/skins2/src/theme_loader.cpp |   25 ++-----
 3 files changed, 117 insertions(+), 57 deletions(-)

diff --git a/modules/gui/skins2/src/theme.cpp b/modules/gui/skins2/src/theme.cpp
index b7df897..f233f79 100644
--- a/modules/gui/skins2/src/theme.cpp
+++ b/modules/gui/skins2/src/theme.cpp
@@ -45,20 +45,67 @@ void Theme::loadConfig()
 {
     msg_Dbg( getIntf(), "loading theme configuration");
 
+    if( readConfig() == VLC_SUCCESS )
+    {
+        applyConfig();
+    }
+    else
+    {
+        getWindowManager().showAll( true );
+    }
+}
+
+
+void Theme::applyConfig()
+{
+    msg_Dbg( getIntf(), "Apply saved configuration");
+
+    list<save_t>::const_iterator it;
+    for( it = m_saved.begin(); it!= m_saved.end(); ++it )
+    {
+        TopWindow *pWin = (*it).win;
+        GenericLayout *pLayout = (*it).layout;
+        int x = (*it).x;
+        int y = (*it).y;
+        int width = (*it).width;
+        int height = (*it).height;
+
+        // Restore the layout
+        m_windowManager.setActiveLayout( *pWin, *pLayout );
+        if( pLayout->getWidth() != width ||
+            pLayout->getHeight() != height )
+        {
+            m_windowManager.startResize( *pLayout, WindowManager::kResizeSE );
+            m_windowManager.resize( *pLayout, width, height );
+            m_windowManager.stopResize();
+        }
+        // Move the window (which incidentally takes care of the anchoring)
+        m_windowManager.startMove( *pWin );
+        m_windowManager.move( *pWin, x, y );
+        m_windowManager.stopMove();
+    }
+
+    for( it = m_saved.begin(); it != m_saved.end(); ++it )
+    {
+       if( (*it).visible )
+            m_windowManager.show( *((*it).win) );
+    }
+}
+
+
+int Theme::readConfig()
+{
+    msg_Dbg( getIntf(), "reading theme configuration");
+
     // Get config from vlcrc file
     char *save = config_GetPsz( getIntf(), "skins2-config" );
-    if( !save ) return;
-
-    // Is there an existing config?
-    if( !strcmp( save, "" ) )
+    if( !save || !*save )
     {
-        // Show the windows as indicated by the XML file
-        m_windowManager.showAll( true );
         free( save );
-        return;
+        return VLC_EGENERIC;
     }
 
-    istringstream inStream(save);
+    istringstream inStream( save );
     free( save );
 
     char sep;
@@ -67,10 +114,29 @@ void Theme::loadConfig()
     bool somethingVisible = false;
     while( !inStream.eof() )
     {
+        stringbuf buf, buf2;
+
+        inStream >> sep;
+        if( sep != '[' )
+            goto invalid;
+
+        inStream >> sep;
+        if( sep != '"' )
+            goto invalid;
+        inStream.get( buf, '"' );
+        winId = buf.str();
+        inStream >> sep;
+
+        inStream >> sep;
+        if( sep != '"' )
+            goto invalid;
+        inStream.get( buf2, '"' );
+        layId = buf2.str();
         inStream >> sep;
-        if( sep != '[' ) goto invalid;
-        inStream >> winId >> layId >> x >> y >> width >> height >> visible >> sep >> ws;
-        if( sep != ']' ) goto invalid;
+
+        inStream >> x >> y >> width >> height >> visible >> sep >> ws;
+        if( sep != ']' )
+            goto invalid;
 
         // Try to find the window and the layout
         map<string, TopWindowPtr>::const_iterator itWin;
@@ -78,42 +144,32 @@ void Theme::loadConfig()
         itWin = m_windows.find( winId );
         itLay = m_layouts.find( layId );
         if( itWin == m_windows.end() || itLay == m_layouts.end() )
-        {
             goto invalid;
-        }
-        TopWindow *pWin = itWin->second.get();
-        GenericLayout *pLayout = itLay->second.get();
 
-        // Restore the layout
-        m_windowManager.setActiveLayout( *pWin, *pLayout );
-        if( pLayout->getWidth() != width ||
-            pLayout->getHeight() != height )
-        {
-            m_windowManager.startResize( *pLayout, WindowManager::kResizeSE );
-            m_windowManager.resize( *pLayout, width, height );
-            m_windowManager.stopResize();
-        }
-        // Move the window (which incidentally takes care of the anchoring)
-        m_windowManager.startMove( *pWin );
-        m_windowManager.move( *pWin, x, y );
-        m_windowManager.stopMove();
+        save_t save;
+        save.win = itWin->second.get();
+        save.layout = itLay->second.get();
+        save.x = x;
+        save.y = y;
+        save.width = width;
+        save.height = height;
+        save.visible = visible;
+
+        m_saved.push_back( save );
+
         if( visible )
-        {
             somethingVisible = true;
-            m_windowManager.show( *pWin );
-        }
     }
 
     if( !somethingVisible )
-    {
         goto invalid;
-    }
-    return;
+
+    return VLC_SUCCESS;
 
 invalid:
-    msg_Warn( getIntf(), "invalid config: %s", inStream.str().c_str() );
-    // Restore the visibility defined in the theme
-    m_windowManager.showAll( true );
+    msg_Dbg( getIntf(), "invalid config: %s", inStream.str().c_str() );
+    m_saved.clear();
+    return VLC_EGENERIC;
 }
 
 
@@ -139,7 +195,9 @@ void Theme::saveConfig()
             }
         }
 
-        outStream << '[' << itWin->first << ' ' << layoutId << ' '
+        outStream << '['
+            << '"' << itWin->first << '"' << ' '
+            << '"' << layoutId << '"' << ' '
             << pWin->getLeft() << ' ' << pWin->getTop() << ' '
             << pLayout->getWidth() << ' ' << pLayout->getHeight() << ' '
             << (pWin->getVisibleVar().get() ? 1 : 0) << ']';
diff --git a/modules/gui/skins2/src/theme.hpp b/modules/gui/skins2/src/theme.hpp
index 67eb601..35af05b 100644
--- a/modules/gui/skins2/src/theme.hpp
+++ b/modules/gui/skins2/src/theme.hpp
@@ -54,7 +54,9 @@ public:
     virtual ~Theme();
 
     void loadConfig();
+    int readConfig();
     void saveConfig();
+    void applyConfig();
 
     GenericBitmap *getBitmapById( const string &id ) const;
     GenericFont *getFontById( const string &id ) const;
@@ -82,6 +84,17 @@ private:
         }
         typename T::pointer find_first_object(const string &id) const;
     };
+
+    struct save_t {
+        TopWindow* win;
+        GenericLayout* layout;
+        int x;
+        int y;
+        int width;
+        int height;
+        int visible;
+    };
+
     /// Store the bitmaps by ID
     IDmap<GenericBitmapPtr> m_bitmaps;
     /// Store the fonts by ID
@@ -102,6 +115,8 @@ private:
     list<BezierPtr> m_curves;
     /// Store the variables
     list<VariablePtr> m_vars;
+    /// List saved windows/layouts
+    list<save_t> m_saved;
 
     WindowManager m_windowManager;
 };
diff --git a/modules/gui/skins2/src/theme_loader.cpp b/modules/gui/skins2/src/theme_loader.cpp
index d9ae6a4..d1f76f2 100644
--- a/modules/gui/skins2/src/theme_loader.cpp
+++ b/modules/gui/skins2/src/theme_loader.cpp
@@ -93,26 +93,13 @@ bool ThemeLoader::load( const string &fileName )
 
     Theme *pNewTheme = getIntf()->p_sys->p_theme;
     if( !pNewTheme )
-    {
         return false;
-    }
 
-    // Check if the skin to load is in the config file, to load its config
-    char *skin_last = config_GetPsz( getIntf(), "skins2-last" );
-    if( skin_last != NULL && fileName == (string)skin_last )
-    {
-        // Restore the theme configuration
-        getIntf()->p_sys->p_theme->loadConfig();
-        // Used to anchor the windows at the beginning
-        pNewTheme->getWindowManager().stopMove();
-    }
-    else
-    {
-        config_PutPsz( getIntf(), "skins2-last", fileName.c_str() );
-        // Show the windows
-        pNewTheme->getWindowManager().showAll( true );
-    }
-    free( skin_last );
+    // Restore the theme configuration
+    getIntf()->p_sys->p_theme->loadConfig();
+
+    // Retain new loaded skins in config
+    config_PutPsz( getIntf(), "skins2-last", fileName.c_str() );
 
     return true;
 }



More information about the vlc-commits mailing list