Commit b0ad9149 authored by Erwan Tulou's avatar Erwan Tulou

skins2: rework theme loader

This patch does the following:
   - fix skins that could not be saved, because their ids contained the space
     character. Names are now enclosed between "" to preserve those spaces.
   - show windows only when the init and check work is done. This avoids
     fleeting windows that sometimes occur (usually visible on Linux)
parent 78b09e7b
......@@ -45,20 +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 );
free( save );
return;
return VLC_EGENERIC;
}
istringstream inStream(save);
istringstream inStream( save );
free( save );
char sep;
......@@ -67,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;
......@@ -78,42 +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 )
{
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();
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;
}
......@@ -139,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) << ']';
......
......@@ -54,7 +54,9 @@ public:
virtual ~Theme();
void loadConfig();
int readConfig();
void saveConfig();
void applyConfig();
GenericBitmap *getBitmapById( const string &id ) const;
GenericFont *getFontById( const string &id ) const;
......@@ -82,6 +84,17 @@ private:
}
typename T::pointer find_first_object(const string &id) const;
};
struct save_t {
TopWindow* win;
GenericLayout* layout;
int x;
int y;
int width;
int height;
int visible;
};
/// Store the bitmaps by ID
IDmap<GenericBitmapPtr> m_bitmaps;
/// Store the fonts by ID
......@@ -102,6 +115,8 @@ private:
list<BezierPtr> m_curves;
/// Store the variables
list<VariablePtr> m_vars;
/// List saved windows/layouts
list<save_t> m_saved;
WindowManager m_windowManager;
};
......
......@@ -93,26 +93,13 @@ bool ThemeLoader::load( const string &fileName )
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(), "skins2-last" );
if( skin_last != NULL && fileName == (string)skin_last )
{
// Restore the theme configuration
getIntf()->p_sys->p_theme->loadConfig();
// Used to anchor the windows at the beginning
pNewTheme->getWindowManager().stopMove();
}
else
{
config_PutPsz( getIntf(), "skins2-last", fileName.c_str() );
// Show the windows
pNewTheme->getWindowManager().showAll( true );
}
free( skin_last );
// Restore the theme configuration
getIntf()->p_sys->p_theme->loadConfig();
// Retain new loaded skins in config
config_PutPsz( getIntf(), "skins2-last", fileName.c_str() );
return true;
}
......
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