Changeset 164278c36c18a1b5bc26cbdd4df929f80627b320

Show
Ignore:
Timestamp:
26/01/04 00:04:06 (5 years ago)
Author:
Cyril Deguet <asmax@videolan.org>
git-committer:
Cyril Deguet <asmax@videolan.org> 1075071846 +0000
git-parent:

[4ee258dfef789140ce63a6140e5e9b544848e5a9]

git-author:
Cyril Deguet <asmax@videolan.org> 1075071846 +0000
Message:

* all: save the theme configuration at exit (theme path and

position/visibilty of the windows)

* parser/xmlparser.cpp: fixed a segfault when the file cannot be opened

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/gui/skins2/parser/xmlparser.cpp

    r1628f2f r164278c  
    33 ***************************************************************************** 
    44 * Copyright (C) 2004 VideoLAN 
    5  * $Id: xmlparser.cpp,v 1.3 2004/01/25 11:44:19 asmax Exp $ 
     5 * $Id: xmlparser.cpp,v 1.4 2004/01/25 23:04:01 asmax Exp $ 
    66 * 
    77 * Authors: Cyril Deguet     <asmax@via.ecp.fr> 
     
    3232        msg_Err( getIntf(), "Failed to open %s for parsing", 
    3333                 rFileName.c_str() ); 
     34        return; 
    3435    } 
    3536 
     
    5657    if( !m_pReader ) 
    5758    { 
    58         return -1
     59        return false
    5960    } 
    6061 
     
    7071            // Error 
    7172            case -1: 
    72                 return -1
     73                return false
    7374                break; 
    7475 
     
    8081                if( !eltName ) 
    8182                { 
    82                     return -1
     83                    return false
    8384                } 
    8485                // Read the attributes 
     
    9091                    if( !name || !value ) 
    9192                    { 
    92                         return -1
     93                        return false
    9394                    } 
    9495                    attributes[(const char*)name] = (const char*)value; 
     
    104105                if( !eltName ) 
    105106                { 
    106                     return -1
     107                    return false
    107108                } 
    108109                handleEndElement( (const char*)eltName ); 
  • modules/gui/skins2/src/skin_main.cpp

    r82a6766 r164278c  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003 VideoLAN 
    5  * $Id: skin_main.cpp,v 1.4 2004/01/25 17:20:19 kuehne Exp $ 
     5 * $Id: skin_main.cpp,v 1.5 2004/01/25 23:04:06 asmax Exp $ 
    66 * 
    77 * Authors: Cyril Deguet     <asmax@via.ecp.fr> 
     
    2424 
    2525#include <stdlib.h> 
    26 #include "generic_window.hpp" 
    2726#include "dialogs.hpp" 
    2827#include "os_factory.hpp" 
    2928#include "os_loop.hpp" 
    30 #include "window_manager.hpp" 
    3129#include "var_manager.hpp" 
    3230#include "vlcproc.hpp" 
     31#include "theme_loader.hpp" 
    3332#include "theme.hpp" 
    34 #include "theme_loader.hpp" 
    3533#include "../parser/interpreter.hpp" 
    3634#include "../commands/async_queue.hpp" 
     35#include "../commands/cmd_quit.hpp" 
    3736 
    3837 
     
    168167    // Load a theme 
    169168    ThemeLoader *pLoader = new ThemeLoader( p_intf ); 
    170     char *skin_last = config_GetPsz( p_intf, "skin_last2" ); 
     169    char *skin_last = config_GetPsz( p_intf, "skin_last" ); 
    171170 
    172171    if( skin_last == NULL || !pLoader->load( skin_last ) ) 
     
    187186            // Last chance: the user can select a new theme file (blocking call) 
    188187            Dialogs *pDialogs = Dialogs::instance( p_intf ); 
    189             pDialogs->showChangeSkin(); 
     188            if( pDialogs ) 
     189            { 
     190                pDialogs->showChangeSkin(); 
     191            } 
     192            else 
     193            { 
     194                // No dialogs provider, just quit... 
     195                CmdQuit *pCmd = new CmdQuit( p_intf ); 
     196                AsyncQueue *pQueue = AsyncQueue::instance( p_intf ); 
     197                pQueue->push( CmdGenericPtr( pCmd ) ); 
     198                msg_Err( p_intf, "Cannot show the \"open skin\" dialog: exiting..."); 
     199            } 
    190200        } 
    191201    } 
     
    199209    // Get the instance of OSLoop 
    200210    OSLoop *loop = OSFactory::instance( p_intf )->getOSLoop(); 
     211 
     212    // Enter the main event loop 
    201213    loop->run(); 
    202214 
     
    214226#define DEFAULT_SKIN        N_("Last skin used") 
    215227#define DEFAULT_SKIN_LONG   N_("Select the path to the last skin used.") 
     228#define SKIN_CONFIG         N_("Config of last used skin") 
     229#define SKIN_CONFIG_LONG    N_("Config of last used skin.") 
    216230 
    217231vlc_module_begin(); 
    218 // XXX 
    219     add_string( "skin_last2", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG, 
     232    add_string( "skin_last", "", NULL, DEFAULT_SKIN, DEFAULT_SKIN_LONG, 
     233                VLC_TRUE ); 
     234    add_string( "skin_config", "", NULL, SKIN_CONFIG, SKIN_CONFIG_LONG, 
    220235                VLC_TRUE ); 
    221236    set_description( _("Skinnable Interface") ); 
  • modules/gui/skins2/src/theme.cpp

    rb7dc5e8 r164278c  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003 VideoLAN 
    5  * $Id: theme.cpp,v 1.1 2004/01/03 23:31:34 asmax Exp $ 
     5 * $Id: theme.cpp,v 1.2 2004/01/25 23:04:06 asmax Exp $ 
    66 * 
    77 * Authors: Cyril Deguet     <asmax@via.ecp.fr> 
     
    2828Theme::~Theme() 
    2929{ 
     30    saveConfig(); 
     31 
    3032    // Be sure things are destroyed in the right order (XXX check) 
    3133    m_layouts.clear(); 
     
    3638    m_commands.clear(); 
    3739    m_vars.clear(); 
     40} 
     41 
     42 
     43void Theme::loadConfig() 
     44{ 
     45    msg_Dbg( getIntf(), "Loading theme configuration"); 
     46 
     47    // Get config from vlcrc file 
     48    char *save = config_GetPsz( getIntf(), "skin_config" ); 
     49    if( save == NULL ) 
     50        return; 
     51 
     52    // Initialization 
     53    map<string, GenericWindowPtr>::const_iterator it; 
     54    int i = 0; 
     55    int x, y, v, scan; 
     56 
     57    // Get config for each window 
     58    for( it = m_windows.begin(); it != m_windows.end(); it++ ) 
     59    { 
     60        GenericWindow *pWin = (*it).second.get(); 
     61        // Get config 
     62        scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &v ); 
     63 
     64        // If config has the correct number of arguments 
     65        if( scan > 2 ) 
     66        { 
     67            pWin->move( x, y ); 
     68            if( v ) pWin->show(); 
     69        } 
     70 
     71        // Next window 
     72        i++; 
     73    } 
     74} 
     75 
     76 
     77void Theme::saveConfig() 
     78{ 
     79    msg_Dbg( getIntf(), "Saving theme configuration"); 
     80 
     81    // Initialize char where config is stored 
     82    char *save  = new char[400]; 
     83    map<string, GenericWindowPtr>::const_iterator it; 
     84    int i = 0; 
     85    int x, y; 
     86 
     87    // Save config of every window 
     88    for( it = m_windows.begin(); it != m_windows.end(); it++ ) 
     89    { 
     90        GenericWindow *pWin = (*it).second.get(); 
     91        // Print config 
     92        x = pWin->getLeft(); 
     93        y = pWin->getTop(); 
     94        sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y, 
     95            pWin->getVisibleVar().get() ); 
     96        i++; 
     97    } 
     98 
     99    // Save config to file 
     100    config_PutPsz( getIntf(), "skin_config", save ); 
     101    config_SaveConfigFile( getIntf(), "skins" ); 
     102 
     103    // Free memory 
     104    delete[] save; 
    38105} 
    39106 
     
    48115    } \ 
    49116    return (*it).second.get(); 
    50  
    51117 
    52118GenericBitmap *Theme::getBitmapById( const string &id ) 
     
    75141} 
    76142 
     143 
     144 
  • modules/gui/skins2/src/theme.hpp

    rb7dc5e8 r164278c  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003 VideoLAN 
    5  * $Id: theme.hpp,v 1.1 2004/01/03 23:31:34 asmax Exp $ 
     5 * $Id: theme.hpp,v 1.2 2004/01/25 23:04:06 asmax Exp $ 
    66 * 
    77 * Authors: Cyril Deguet     <asmax@via.ecp.fr> 
     
    4747        virtual ~Theme(); 
    4848 
     49        void loadConfig(); 
     50        void saveConfig(); 
     51 
    4952        GenericBitmap *getBitmapById( const string &id ); 
    5053        GenericFont *getFontById( const string &id ); 
  • modules/gui/skins2/src/theme_loader.cpp

    r1628f2f r164278c  
    33 ***************************************************************************** 
    44 * Copyright (C) 2003 VideoLAN 
    5  * $Id: theme_loader.cpp,v 1.7 2004/01/25 11:44:19 asmax Exp $ 
     5 * $Id: theme_loader.cpp,v 1.8 2004/01/25 23:04:06 asmax Exp $ 
    66 * 
    77 * Authors: Cyril Deguet     <asmax@via.ecp.fr> 
     
    6767#endif 
    6868 
    69 #if 0 
     69    Theme *pNewTheme = getIntf()->p_sys->p_theme; 
     70    if( !pNewTheme ) 
     71    { 
     72        return false; 
     73    } 
     74 
    7075    // Check if the skin to load is in the config file, to load its config 
    7176    char *skin_last = config_GetPsz( getIntf(), "skin_last" ); 
    7277    if( skin_last != NULL && fileName == (string)skin_last ) 
    7378    { 
    74         getIntf()->p_sys->p_theme->LoadConfig(); 
    75     } 
    76     else 
    77     { 
    78         config_PutPsz( getIntf(), "skin_last", fileName.c_str() ); 
    79         config_SaveConfigFile( getIntf(), "skins" ); 
    80     } 
    81 #endif 
    82     Theme *pNewTheme = getIntf()->p_sys->p_theme; 
    83     if( pNewTheme ) 
    84     { 
    8579        // Used to anchor the windows at the beginning 
    8680        pNewTheme->getWindowManager().stopMove(); 
     81        // Restore the theme configuration 
     82        getIntf()->p_sys->p_theme->loadConfig(); 
     83    } 
     84    else 
     85    { 
     86        config_PutPsz( getIntf(), "skin_last", fileName.c_str() ); 
    8787        // Show the windows 
    8888        pNewTheme->getWindowManager().showAll();