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() ...@@ -45,20 +45,67 @@ void Theme::loadConfig()
{ {
msg_Dbg( getIntf(), "loading theme configuration"); 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 // Get config from vlcrc file
char *save = config_GetPsz( getIntf(), "skins2-config" ); char *save = config_GetPsz( getIntf(), "skins2-config" );
if( !save ) return; if( !save || !*save )
// Is there an existing config?
if( !strcmp( save, "" ) )
{ {
// Show the windows as indicated by the XML file
m_windowManager.showAll( true );
free( save ); free( save );
return; return VLC_EGENERIC;
} }
istringstream inStream(save); istringstream inStream( save );
free( save ); free( save );
char sep; char sep;
...@@ -67,10 +114,29 @@ void Theme::loadConfig() ...@@ -67,10 +114,29 @@ void Theme::loadConfig()
bool somethingVisible = false; bool somethingVisible = false;
while( !inStream.eof() ) 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; inStream >> sep;
if( sep != '[' ) goto invalid;
inStream >> winId >> layId >> x >> y >> width >> height >> visible >> sep >> ws; inStream >> x >> y >> width >> height >> visible >> sep >> ws;
if( sep != ']' ) goto invalid; if( sep != ']' )
goto invalid;
// Try to find the window and the layout // Try to find the window and the layout
map<string, TopWindowPtr>::const_iterator itWin; map<string, TopWindowPtr>::const_iterator itWin;
...@@ -78,42 +144,32 @@ void Theme::loadConfig() ...@@ -78,42 +144,32 @@ void Theme::loadConfig()
itWin = m_windows.find( winId ); itWin = m_windows.find( winId );
itLay = m_layouts.find( layId ); itLay = m_layouts.find( layId );
if( itWin == m_windows.end() || itLay == m_layouts.end() ) if( itWin == m_windows.end() || itLay == m_layouts.end() )
{
goto invalid; goto invalid;
}
TopWindow *pWin = itWin->second.get();
GenericLayout *pLayout = itLay->second.get();
// Restore the layout save_t save;
m_windowManager.setActiveLayout( *pWin, *pLayout ); save.win = itWin->second.get();
if( pLayout->getWidth() != width || save.layout = itLay->second.get();
pLayout->getHeight() != height ) save.x = x;
{ save.y = y;
m_windowManager.startResize( *pLayout, WindowManager::kResizeSE ); save.width = width;
m_windowManager.resize( *pLayout, width, height ); save.height = height;
m_windowManager.stopResize(); save.visible = visible;
}
// Move the window (which incidentally takes care of the anchoring) m_saved.push_back( save );
m_windowManager.startMove( *pWin );
m_windowManager.move( *pWin, x, y );
m_windowManager.stopMove();
if( visible ) if( visible )
{
somethingVisible = true; somethingVisible = true;
m_windowManager.show( *pWin );
}
} }
if( !somethingVisible ) if( !somethingVisible )
{
goto invalid; goto invalid;
}
return; return VLC_SUCCESS;
invalid: invalid:
msg_Warn( getIntf(), "invalid config: %s", inStream.str().c_str() ); msg_Dbg( getIntf(), "invalid config: %s", inStream.str().c_str() );
// Restore the visibility defined in the theme m_saved.clear();
m_windowManager.showAll( true ); return VLC_EGENERIC;
} }
...@@ -139,7 +195,9 @@ void Theme::saveConfig() ...@@ -139,7 +195,9 @@ void Theme::saveConfig()
} }
} }
outStream << '[' << itWin->first << ' ' << layoutId << ' ' outStream << '['
<< '"' << itWin->first << '"' << ' '
<< '"' << layoutId << '"' << ' '
<< pWin->getLeft() << ' ' << pWin->getTop() << ' ' << pWin->getLeft() << ' ' << pWin->getTop() << ' '
<< pLayout->getWidth() << ' ' << pLayout->getHeight() << ' ' << pLayout->getWidth() << ' ' << pLayout->getHeight() << ' '
<< (pWin->getVisibleVar().get() ? 1 : 0) << ']'; << (pWin->getVisibleVar().get() ? 1 : 0) << ']';
......
...@@ -54,7 +54,9 @@ public: ...@@ -54,7 +54,9 @@ public:
virtual ~Theme(); virtual ~Theme();
void loadConfig(); void loadConfig();
int readConfig();
void saveConfig(); void saveConfig();
void applyConfig();
GenericBitmap *getBitmapById( const string &id ) const; GenericBitmap *getBitmapById( const string &id ) const;
GenericFont *getFontById( const string &id ) const; GenericFont *getFontById( const string &id ) const;
...@@ -82,6 +84,17 @@ private: ...@@ -82,6 +84,17 @@ private:
} }
typename T::pointer find_first_object(const string &id) const; 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 /// Store the bitmaps by ID
IDmap<GenericBitmapPtr> m_bitmaps; IDmap<GenericBitmapPtr> m_bitmaps;
/// Store the fonts by ID /// Store the fonts by ID
...@@ -102,6 +115,8 @@ private: ...@@ -102,6 +115,8 @@ private:
list<BezierPtr> m_curves; list<BezierPtr> m_curves;
/// Store the variables /// Store the variables
list<VariablePtr> m_vars; list<VariablePtr> m_vars;
/// List saved windows/layouts
list<save_t> m_saved;
WindowManager m_windowManager; WindowManager m_windowManager;
}; };
......
...@@ -93,26 +93,13 @@ bool ThemeLoader::load( const string &fileName ) ...@@ -93,26 +93,13 @@ bool ThemeLoader::load( const string &fileName )
Theme *pNewTheme = getIntf()->p_sys->p_theme; Theme *pNewTheme = getIntf()->p_sys->p_theme;
if( !pNewTheme ) if( !pNewTheme )
{
return false; return false;
}
// Check if the skin to load is in the config file, to load its config // Restore the theme configuration
char *skin_last = config_GetPsz( getIntf(), "skins2-last" ); getIntf()->p_sys->p_theme->loadConfig();
if( skin_last != NULL && fileName == (string)skin_last )
{ // Retain new loaded skins in config
// Restore the theme configuration config_PutPsz( getIntf(), "skins2-last", fileName.c_str() );
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 );
return true; 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