Commit 164278c3 authored by Cyril Deguet's avatar Cyril Deguet

* 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
parent 4ee258df
......@@ -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;
......
......@@ -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 Teulire <ipkiss@via.ecp.fr>
......@@ -23,17 +23,16 @@
*****************************************************************************/
#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 );
......
......@@ -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 Teulire <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 );
}
......@@ -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 );
......
......@@ -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 Teulire <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();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment