]> git.sesse.net Git - vlc/commitdiff
* all: save the theme configuration at exit (theme path and
authorCyril Deguet <asmax@videolan.org>
Sun, 25 Jan 2004 23:04:06 +0000 (23:04 +0000)
committerCyril Deguet <asmax@videolan.org>
Sun, 25 Jan 2004 23:04:06 +0000 (23:04 +0000)
  position/visibilty of the windows)
* parser/xmlparser.cpp: fixed a segfault when the file cannot be opened

modules/gui/skins2/parser/xmlparser.cpp
modules/gui/skins2/src/skin_main.cpp
modules/gui/skins2/src/theme.cpp
modules/gui/skins2/src/theme.hpp
modules/gui/skins2/src/theme_loader.cpp

index 694cdb1f9f98cf4d74765f4a3921f225e5deda52..5eaadfe6d4c65ea251f15e836b45db24b2ebff08 100644 (file)
@@ -2,7 +2,7 @@
  * xmlparser.cpp
  *****************************************************************************
  * Copyright (C) 2004 VideoLAN
- * $Id: xmlparser.cpp,v 1.3 2004/01/25 11:44:19 asmax Exp $
+ * $Id: xmlparser.cpp,v 1.4 2004/01/25 23:04:01 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *
@@ -31,6 +31,7 @@ XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
     {
         msg_Err( getIntf(), "Failed to open %s for parsing",
                  rFileName.c_str() );
+        return;
     }
 
     // Activate DTD validation
@@ -55,7 +56,7 @@ bool XMLParser::parse()
 {
     if( !m_pReader )
     {
-        return -1;
+        return false;
     }
 
     m_errors = false;
@@ -69,7 +70,7 @@ bool XMLParser::parse()
         {
             // Error
             case -1:
-                return -1;
+                return false;
                 break;
 
             // Begin element
@@ -79,7 +80,7 @@ bool XMLParser::parse()
                 const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
                 if( !eltName )
                 {
-                    return -1;
+                    return false;
                 }
                 // Read the attributes
                 AttrList_t attributes;
@@ -89,7 +90,7 @@ bool XMLParser::parse()
                     const xmlChar *value = xmlTextReaderConstValue( m_pReader );
                     if( !name || !value )
                     {
-                        return -1;
+                        return false;
                     }
                     attributes[(const char*)name] = (const char*)value;
                 }
@@ -103,7 +104,7 @@ bool XMLParser::parse()
                 const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
                 if( !eltName )
                 {
-                    return -1;
+                    return false;
                 }
                 handleEndElement( (const char*)eltName );
                 break;
index 8c460c726cad16d28ce4db35bae48b0af2a01dd4..b56c77507562c9dec3f7519e92f473ec6b60d873 100644 (file)
@@ -2,7 +2,7 @@
  * skin_main.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: skin_main.cpp,v 1.4 2004/01/25 17:20:19 kuehne Exp $
+ * $Id: skin_main.cpp,v 1.5 2004/01/25 23:04:06 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
  *****************************************************************************/
 
 #include <stdlib.h>
-#include "generic_window.hpp"
 #include "dialogs.hpp"
 #include "os_factory.hpp"
 #include "os_loop.hpp"
-#include "window_manager.hpp"
 #include "var_manager.hpp"
 #include "vlcproc.hpp"
-#include "theme.hpp"
 #include "theme_loader.hpp"
+#include "theme.hpp"
 #include "../parser/interpreter.hpp"
 #include "../commands/async_queue.hpp"
+#include "../commands/cmd_quit.hpp"
 
 
 //---------------------------------------------------------------------------
@@ -167,7 +166,7 @@ static void Run( intf_thread_t *p_intf )
 {
     // Load a theme
     ThemeLoader *pLoader = new ThemeLoader( p_intf );
-    char *skin_last = config_GetPsz( p_intf, "skin_last2" );
+    char *skin_last = config_GetPsz( p_intf, "skin_last" );
 
     if( skin_last == NULL || !pLoader->load( skin_last ) )
     {
@@ -186,7 +185,18 @@ static void Run( intf_thread_t *p_intf )
         {
             // Last chance: the user can select a new theme file (blocking call)
             Dialogs *pDialogs = Dialogs::instance( p_intf );
-            pDialogs->showChangeSkin();
+            if( pDialogs )
+            {
+                pDialogs->showChangeSkin();
+            }
+            else
+            {
+                // No dialogs provider, just quit...
+                CmdQuit *pCmd = new CmdQuit( p_intf );
+                AsyncQueue *pQueue = AsyncQueue::instance( p_intf );
+                pQueue->push( CmdGenericPtr( pCmd ) );
+                msg_Err( p_intf, "Cannot show the \"open skin\" dialog: exiting...");
+            }
         }
     }
     delete pLoader;
@@ -198,6 +208,8 @@ static void Run( intf_thread_t *p_intf )
 
     // Get the instance of OSLoop
     OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop();
+
+    // Enter the main event loop
     loop->run();
 
     // Delete the theme
@@ -213,10 +225,13 @@ static void Run( intf_thread_t *p_intf )
 //---------------------------------------------------------------------------
 #define DEFAULT_SKIN        N_("Last skin used")
 #define DEFAULT_SKIN_LONG   N_("Select the path to the last skin used.")
+#define SKIN_CONFIG         N_("Config of last used skin")
+#define SKIN_CONFIG_LONG    N_("Config of last used skin.")
 
 vlc_module_begin();
-// XXX
-    add_string( "skin_last2", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
+    add_string( "skin_last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG,
+                VLC_TRUE );
+    add_string( "skin_config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG,
                 VLC_TRUE );
     set_description( _("Skinnable Interface") );
     set_capability( "interface", 30 );
index d12e55022b336efc181c951e32eb320e5cb0caaf..777633e1e8b0e3f5b9d15bfd201dffbd636cbd72 100755 (executable)
@@ -2,7 +2,7 @@
  * theme.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: theme.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
+ * $Id: theme.cpp,v 1.2 2004/01/25 23:04:06 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -27,6 +27,8 @@
 
 Theme::~Theme()
 {
+    saveConfig();
+
     // Be sure things are destroyed in the right order (XXX check)
     m_layouts.clear();
     m_controls.clear();
@@ -38,6 +40,71 @@ Theme::~Theme()
 }
 
 
+void Theme::loadConfig()
+{
+    msg_Dbg( getIntf(), "Loading theme configuration");
+
+    // Get config from vlcrc file
+    char *save = config_GetPsz( getIntf(), "skin_config" );
+    if( save == NULL )
+        return;
+
+    // Initialization
+    map<string, GenericWindowPtr>::const_iterator it;
+    int i = 0;
+    int x, y, v, scan;
+
+    // Get config for each window
+    for( it = m_windows.begin(); it != m_windows.end(); it++ )
+    {
+        GenericWindow *pWin = (*it).second.get();
+        // Get config
+        scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &v );
+
+        // If config has the correct number of arguments
+        if( scan > 2 )
+        {
+            pWin->move( x, y );
+            if( v ) pWin->show();
+        }
+
+        // Next window
+        i++;
+    }
+}
+
+
+void Theme::saveConfig()
+{
+    msg_Dbg( getIntf(), "Saving theme configuration");
+
+    // Initialize char where config is stored
+    char *save  = new char[400];
+    map<string, GenericWindowPtr>::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();
+        // Print config
+        x = pWin->getLeft();
+        y = pWin->getTop();
+        sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
+            pWin->getVisibleVar().get() );
+        i++;
+    }
+
+    // Save config to file
+    config_PutPsz( getIntf(), "skin_config", save );
+    config_SaveConfigFile( getIntf(), "skins" );
+
+    // Free memory
+    delete[] save;
+}
+
+
 // Useful macro
 #define FIND_OBJECT( mapData, mapName ) \
     map<string, mapData>::const_iterator it; \
@@ -48,7 +115,6 @@ Theme::~Theme()
     } \
     return (*it).second.get();
 
-
 GenericBitmap *Theme::getBitmapById( const string &id )
 {
     FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
@@ -74,3 +140,5 @@ CtrlGeneric *Theme::getControlById( const string &id )
     FIND_OBJECT( CtrlGenericPtr, m_controls );
 }
 
+
+
index ebb11f088bde808137ed15ed71f3fb3b3a5aa2c5..22f47e0dff4432eb4c64ec3373b12310f9b7a8fc 100755 (executable)
@@ -2,7 +2,7 @@
  * theme.hpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: theme.hpp,v 1.1 2004/01/03 23:31:34 asmax Exp $
+ * $Id: theme.hpp,v 1.2 2004/01/25 23:04:06 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -46,6 +46,9 @@ class Theme: public SkinObject
             m_windowManager( getIntf() ) {}
         virtual ~Theme();
 
+        void loadConfig();
+        void saveConfig();
+
         GenericBitmap *getBitmapById( const string &id );
         GenericFont *getFontById( const string &id );
         GenericWindow *getWindowById( const string &id );
index a74c02cae0cd02160eba78713a89b8e11415bb94..3b02a037035b2379ecca3ceddbd0c9d54de2d708 100755 (executable)
@@ -2,7 +2,7 @@
  * theme_loader.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: theme_loader.cpp,v 1.7 2004/01/25 11:44:19 asmax Exp $
+ * $Id: theme_loader.cpp,v 1.8 2004/01/25 23:04:06 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -66,24 +66,24 @@ bool ThemeLoader::load( const string &fileName )
         return false;
 #endif
 
-#if 0
+    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(), "skin_last" );
     if( skin_last != NULL && fileName == (string)skin_last )
     {
-        getIntf()->p_sys->p_theme->LoadConfig();
+        // Used to anchor the windows at the beginning
+        pNewTheme->getWindowManager().stopMove();
+        // Restore the theme configuration
+        getIntf()->p_sys->p_theme->loadConfig();
     }
     else
     {
         config_PutPsz( getIntf(), "skin_last", fileName.c_str() );
-        config_SaveConfigFile( getIntf(), "skins" );
-    }
-#endif
-    Theme *pNewTheme = getIntf()->p_sys->p_theme;
-    if( pNewTheme )
-    {
-        // Used to anchor the windows at the beginning
-        pNewTheme->getWindowManager().stopMove();
         // Show the windows
         pNewTheme->getWindowManager().showAll();
     }