]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/theme.cpp
Uniformize source files encoding
[vlc] / modules / gui / skins2 / src / theme.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 6c9ff04..a0ac0b4
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * theme.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: theme.cpp,v 1.3 2004/02/08 11:23:17 gbazin Exp $
+ * Copyright (C) 2003 the VideoLAN team
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "theme.hpp"
@@ -27,8 +27,6 @@
 
 Theme::~Theme()
 {
-    saveConfig();
-
     // Be sure things are destroyed in the right order (XXX check)
     m_layouts.clear();
     m_controls.clear();
@@ -37,6 +35,7 @@ Theme::~Theme()
     m_fonts.clear();
     m_commands.clear();
     m_vars.clear();
+    m_curves.clear();
 }
 
 
@@ -46,31 +45,44 @@ void Theme::loadConfig()
 
     // Get config from vlcrc file
     char *save = config_GetPsz( getIntf(), "skins2-config" );
-    if( save == NULL )
+    if( !save ) return;
+
+    // Is there an existing config?
+    if( !strcmp( save, "" ) )
+    {
+        // Show the windows
+        m_windowManager.showAll( true );
         return;
+    }
 
     // Initialization
-    map<string, GenericWindowPtr>::const_iterator it;
+    map<string, TopWindowPtr>::const_iterator it;
     int i = 0;
-    int x, y, v, scan;
+    int x, y, visible, scan;
 
     // Get config for each window
     for( it = m_windows.begin(); it != m_windows.end(); it++ )
     {
-        GenericWindow *pWin = (*it).second.get();
+        TopWindow *pWin = (*it).second.get();
         // Get config
-        scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &v );
+        scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &visible );
 
         // If config has the correct number of arguments
         if( scan > 2 )
         {
-            pWin->move( x, y );
-            if( v ) pWin->show();
+            m_windowManager.startMove( *pWin );
+            m_windowManager.move( *pWin, x, y );
+            m_windowManager.stopMove();
+            if( visible )
+            {
+                m_windowManager.show( *pWin );
+            }
         }
 
         // Next window
         i++;
     }
+    free( save );
 }
 
 
@@ -80,14 +92,14 @@ void Theme::saveConfig()
 
     // Initialize char where config is stored
     char *save  = new char[400];
-    map<string, GenericWindowPtr>::const_iterator it;
+    map<string, TopWindowPtr>::const_iterator it;
     int i = 0;
     int x, y;
 
     // Save config of every window
     for( it = m_windows.begin(); it != m_windows.end(); it++ )
     {
-        GenericWindow *pWin = (*it).second.get();
+        TopWindow *pWin = (*it).second.get();
         // Print config
         x = pWin->getLeft();
         y = pWin->getTop();
@@ -98,7 +110,6 @@ void Theme::saveConfig()
 
     // Save config to file
     config_PutPsz( getIntf(), "skins2-config", save );
-    config_SaveConfigFile( getIntf(), "skins2" );
 
     // Free memory
     delete[] save;
@@ -115,19 +126,52 @@ void Theme::saveConfig()
     } \
     return (*it).second.get();
 
+// This macro takes an ID of the form "id1;id2;id3", and returns the object
+// corresponding to the first valid ID. If no ID is valid, it returns NULL.
+// XXX: should we use a template method instead?
+#define FIND_FIRST_OBJECT( mapDataPtr, mapName ) \
+    string rightPart = id; \
+    string::size_type pos; \
+    do \
+    { \
+        pos = rightPart.find( ";" ); \
+        string leftPart = rightPart.substr( 0, pos ); \
+        map<string, mapDataPtr>::const_iterator it = mapName.find( leftPart ); \
+        if( it != mapName.end() ) \
+        { \
+            return (*it).second.get(); \
+            break; \
+        } \
+ \
+        if( pos != string::npos ) \
+        { \
+            rightPart = rightPart.substr( pos, rightPart.size() ); \
+            rightPart = \
+                rightPart.substr( rightPart.find_first_not_of( " \t;" ), \
+                                  rightPart.size() ); \
+        } \
+    } \
+    while( pos != string::npos ); \
+    return NULL;
+
 GenericBitmap *Theme::getBitmapById( const string &id )
 {
-    FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
+    FIND_FIRST_OBJECT( GenericBitmapPtr, m_bitmaps );
 }
 
 GenericFont *Theme::getFontById( const string &id )
 {
-    FIND_OBJECT( GenericFontPtr, m_fonts );
+    FIND_FIRST_OBJECT( GenericFontPtr, m_fonts );
+}
+
+Popup *Theme::getPopupById( const string &id )
+{
+    FIND_OBJECT( PopupPtr, m_popups );
 }
 
-GenericWindow *Theme::getWindowById( const string &id )
+TopWindow *Theme::getWindowById( const string &id )
 {
-    FIND_OBJECT( GenericWindowPtr, m_windows );
+    FIND_OBJECT( TopWindowPtr, m_windows );
 }
 
 GenericLayout *Theme::getLayoutById( const string &id )