{
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;
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;
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;
}
}
}
- outStream << '[' << itWin->first << ' ' << layoutId << ' '
+ outStream << '['
+ << '"' << itWin->first << '"' << ' '
+ << '"' << layoutId << '"' << ' '
<< pWin->getLeft() << ' ' << pWin->getTop() << ' '
<< pLayout->getWidth() << ' ' << pLayout->getHeight() << ' '
<< (pWin->getVisibleVar().get() ? 1 : 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(), "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;
}