1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 #include "top_window.hpp"
32 // Be sure things are destroyed in the right order (XXX check)
44 void Theme::loadConfig()
46 msg_Dbg( getIntf(), "loading theme configuration");
48 // Get config from vlcrc file
49 char *save = config_GetPsz( getIntf(), "skins2-config" );
52 // Is there an existing config?
53 if( !strcmp( save, "" ) )
55 // Show the windows as indicated by the XML file
56 m_windowManager.showAll( true );
60 istringstream inStream(save);
65 int x, y, width, height, visible;
66 bool somethingVisible = false;
67 while( !inStream.eof() )
70 if( sep != '[' ) goto invalid;
71 inStream >> winId >> layId >> x >> y >> width >> height >> visible >> sep >> ws;
72 if( sep != ']' ) goto invalid;
74 // Try to find the window and the layout
75 map<string, TopWindowPtr>::const_iterator itWin;
76 map<string, GenericLayoutPtr>::const_iterator itLay;
77 itWin = m_windows.find( winId );
78 itLay = m_layouts.find( layId );
79 if( itWin == m_windows.end() || itLay == m_layouts.end() )
83 TopWindow *pWin = itWin->second.get();
84 GenericLayout *pLayout = itLay->second.get();
87 m_windowManager.setActiveLayout( *pWin, *pLayout );
88 if( pLayout->getWidth() != width ||
89 pLayout->getHeight() != height )
91 m_windowManager.startResize( *pLayout, WindowManager::kResizeSE );
92 m_windowManager.resize( *pLayout, width, height );
93 m_windowManager.stopResize();
95 // Move the window (which incidentally takes care of the anchoring)
96 m_windowManager.startMove( *pWin );
97 m_windowManager.move( *pWin, x, y );
98 m_windowManager.stopMove();
101 somethingVisible = true;
102 m_windowManager.show( *pWin );
106 if( !somethingVisible )
113 msg_Warn( getIntf(), "invalid config: %s", inStream.str().c_str() );
114 // Restore the visibility defined in the theme
115 m_windowManager.showAll( true );
119 void Theme::saveConfig()
121 msg_Dbg( getIntf(), "saving theme configuration");
123 map<string, TopWindowPtr>::const_iterator itWin;
124 map<string, GenericLayoutPtr>::const_iterator itLay;
125 ostringstream outStream;
126 for( itWin = m_windows.begin(); itWin != m_windows.end(); itWin++ )
128 TopWindow *pWin = itWin->second.get();
130 // Find the layout id for this window
132 const GenericLayout *pLayout = &pWin->getActiveLayout();
133 for( itLay = m_layouts.begin(); itLay != m_layouts.end(); itLay++ )
135 if( itLay->second.get() == pLayout )
137 layoutId = itLay->first;
141 outStream << '[' << itWin->first << ' ' << layoutId << ' '
142 << pWin->getLeft() << ' ' << pWin->getTop() << ' '
143 << pLayout->getWidth() << ' ' << pLayout->getHeight() << ' '
144 << (pWin->getVisibleVar().get() ? 1 : 0) << ']';
147 // Save config to file
148 config_PutPsz( getIntf(), "skins2-config", outStream.str().c_str() );
152 // Takes an ID of the form "id1;id2;id3", and returns the object
153 // corresponding to the first valid ID. If no ID is valid, it returns NULL.
154 // XXX The string handling here probably could be improved.
155 template<class T> typename T::pointer
156 Theme::IDmap<T>::find_first_object( const string &id ) const
158 string rightPart = id;
159 string::size_type pos;
162 pos = rightPart.find( ";" );
163 string leftPart = rightPart.substr( 0, pos );
165 typename T::pointer p = find_object( leftPart );
168 if( pos != string::npos )
170 rightPart = rightPart.substr( pos, rightPart.size() );
172 rightPart.substr( rightPart.find_first_not_of( " \t;" ),
176 while( pos != string::npos );
180 GenericBitmap *Theme::getBitmapById( const string &id ) const
182 return m_bitmaps.find_first_object( id );
185 GenericFont *Theme::getFontById( const string &id ) const
187 return m_fonts.find_first_object( id );