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 if( readConfig() == VLC_SUCCESS )
54 getWindowManager().showAll( true );
59 void Theme::applyConfig()
61 msg_Dbg( getIntf(), "Apply saved configuration");
63 list<save_t>::const_iterator it;
64 for( it = m_saved.begin(); it!= m_saved.end(); ++it )
66 TopWindow *pWin = (*it).win;
67 GenericLayout *pLayout = (*it).layout;
70 int width = (*it).width;
71 int height = (*it).height;
74 m_windowManager.setActiveLayout( *pWin, *pLayout );
75 if( pLayout->getWidth() != width ||
76 pLayout->getHeight() != height )
78 m_windowManager.startResize( *pLayout, WindowManager::kResizeSE );
79 m_windowManager.resize( *pLayout, width, height );
80 m_windowManager.stopResize();
82 // Move the window (which incidentally takes care of the anchoring)
83 m_windowManager.startMove( *pWin );
84 m_windowManager.move( *pWin, x, y );
85 m_windowManager.stopMove();
88 for( it = m_saved.begin(); it != m_saved.end(); ++it )
91 m_windowManager.show( *((*it).win) );
96 int Theme::readConfig()
98 msg_Dbg( getIntf(), "reading theme configuration");
100 // Get config from vlcrc file
101 char *save = config_GetPsz( getIntf(), "skins2-config" );
102 if( !save || !*save )
108 istringstream inStream( save );
113 int x, y, width, height, visible;
114 bool somethingVisible = false;
115 while( !inStream.eof() )
126 inStream.get( buf, '"' );
133 inStream.get( buf2, '"' );
137 inStream >> x >> y >> width >> height >> visible >> sep >> ws;
141 // Try to find the window and the layout
142 map<string, TopWindowPtr>::const_iterator itWin;
143 map<string, GenericLayoutPtr>::const_iterator itLay;
144 itWin = m_windows.find( winId );
145 itLay = m_layouts.find( layId );
146 if( itWin == m_windows.end() || itLay == m_layouts.end() )
150 save.win = itWin->second.get();
151 save.layout = itLay->second.get();
155 save.height = height;
156 save.visible = visible;
158 m_saved.push_back( save );
161 somethingVisible = true;
164 if( !somethingVisible )
170 msg_Dbg( getIntf(), "invalid config: %s", inStream.str().c_str() );
176 void Theme::saveConfig()
178 msg_Dbg( getIntf(), "saving theme configuration");
180 map<string, TopWindowPtr>::const_iterator itWin;
181 map<string, GenericLayoutPtr>::const_iterator itLay;
182 ostringstream outStream;
183 for( itWin = m_windows.begin(); itWin != m_windows.end(); itWin++ )
185 TopWindow *pWin = itWin->second.get();
187 // Find the layout id for this window
189 const GenericLayout *pLayout = &pWin->getActiveLayout();
190 for( itLay = m_layouts.begin(); itLay != m_layouts.end(); itLay++ )
192 if( itLay->second.get() == pLayout )
194 layoutId = itLay->first;
199 << '"' << itWin->first << '"' << ' '
200 << '"' << layoutId << '"' << ' '
201 << pWin->getLeft() << ' ' << pWin->getTop() << ' '
202 << pLayout->getWidth() << ' ' << pLayout->getHeight() << ' '
203 << (pWin->getVisibleVar().get() ? 1 : 0) << ']';
206 // Save config to file
207 config_PutPsz( getIntf(), "skins2-config", outStream.str().c_str() );
211 // Takes an ID of the form "id1;id2;id3", and returns the object
212 // corresponding to the first valid ID. If no ID is valid, it returns NULL.
213 // XXX The string handling here probably could be improved.
214 template<class T> typename T::pointer
215 Theme::IDmap<T>::find_first_object( const string &id ) const
217 string rightPart = id;
218 string::size_type pos;
221 pos = rightPart.find( ";" );
222 string leftPart = rightPart.substr( 0, pos );
224 typename T::pointer p = find_object( leftPart );
227 if( pos != string::npos )
229 rightPart = rightPart.substr( pos, rightPart.size() );
231 rightPart.substr( rightPart.find_first_not_of( " \t;" ),
235 while( pos != string::npos );
239 GenericBitmap *Theme::getBitmapById( const string &id ) const
241 return m_bitmaps.find_first_object( id );
244 GenericFont *Theme::getFontById( const string &id ) const
246 return m_fonts.find_first_object( id );