]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/theme.cpp
skins2: rework theme loader
[vlc] / modules / gui / skins2 / src / theme.cpp
index 7eec553609854b214c30742c51c0563e8cd317bb..f233f79597abf2458053623c2a4f8e9ae93a947f 100644 (file)
@@ -45,19 +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 );
-        return;
+        free( save );
+        return VLC_EGENERIC;
     }
 
-    istringstream inStream(save);
+    istringstream inStream( save );
     free( save );
 
     char sep;
@@ -66,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;
@@ -77,52 +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 )
-        {
-            // XXX FIXME XXX: big kludge
-            // As resizing a hidden window causes some trouble (at least on
-            // Windows), first show the window off screen, resize it, and
-            // hide it again.
-            // This has to be investigated more deeply!
-            m_windowManager.startMove( *pWin );
-            m_windowManager.move( *pWin, -width - pLayout->getWidth(), 0);
-            m_windowManager.stopMove();
-            m_windowManager.show( *pWin );
-            m_windowManager.startResize( *pLayout, WindowManager::kResizeSE );
-            m_windowManager.resize( *pLayout, width, height );
-            m_windowManager.stopResize();
-            m_windowManager.hide( *pWin );
-        }
-        // 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;
 }
 
 
@@ -148,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) << ']';