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 );
61 istringstream
inStream(save
);
66 int x
, y
, width
, height
, visible
;
67 bool somethingVisible
= false;
68 while( !inStream
.eof() )
71 if( sep
!= '[' ) goto invalid
;
72 inStream
>> winId
>> layId
>> x
>> y
>> width
>> height
>> visible
>> sep
>> ws
;
73 if( sep
!= ']' ) goto invalid
;
75 // Try to find the window and the layout
76 map
<string
, TopWindowPtr
>::const_iterator itWin
;
77 map
<string
, GenericLayoutPtr
>::const_iterator itLay
;
78 itWin
= m_windows
.find( winId
);
79 itLay
= m_layouts
.find( layId
);
80 if( itWin
== m_windows
.end() || itLay
== m_layouts
.end() )
84 TopWindow
*pWin
= itWin
->second
.get();
85 GenericLayout
*pLayout
= itLay
->second
.get();
88 m_windowManager
.setActiveLayout( *pWin
, *pLayout
);
89 if( pLayout
->getWidth() != width
||
90 pLayout
->getHeight() != height
)
92 m_windowManager
.startResize( *pLayout
, WindowManager::kResizeSE
);
93 m_windowManager
.resize( *pLayout
, width
, height
);
94 m_windowManager
.stopResize();
96 // Move the window (which incidentally takes care of the anchoring)
97 m_windowManager
.startMove( *pWin
);
98 m_windowManager
.move( *pWin
, x
, y
);
99 m_windowManager
.stopMove();
102 somethingVisible
= true;
103 m_windowManager
.show( *pWin
);
107 if( !somethingVisible
)
114 msg_Warn( getIntf(), "invalid config: %s", inStream
.str().c_str() );
115 // Restore the visibility defined in the theme
116 m_windowManager
.showAll( true );
120 void Theme::saveConfig()
122 msg_Dbg( getIntf(), "saving theme configuration");
124 map
<string
, TopWindowPtr
>::const_iterator itWin
;
125 map
<string
, GenericLayoutPtr
>::const_iterator itLay
;
126 ostringstream outStream
;
127 for( itWin
= m_windows
.begin(); itWin
!= m_windows
.end(); itWin
++ )
129 TopWindow
*pWin
= itWin
->second
.get();
131 // Find the layout id for this window
133 const GenericLayout
*pLayout
= &pWin
->getActiveLayout();
134 for( itLay
= m_layouts
.begin(); itLay
!= m_layouts
.end(); itLay
++ )
136 if( itLay
->second
.get() == pLayout
)
138 layoutId
= itLay
->first
;
142 outStream
<< '[' << itWin
->first
<< ' ' << layoutId
<< ' '
143 << pWin
->getLeft() << ' ' << pWin
->getTop() << ' '
144 << pLayout
->getWidth() << ' ' << pLayout
->getHeight() << ' '
145 << (pWin
->getVisibleVar().get() ? 1 : 0) << ']';
148 // Save config to file
149 config_PutPsz( getIntf(), "skins2-config", outStream
.str().c_str() );
153 // Takes an ID of the form "id1;id2;id3", and returns the object
154 // corresponding to the first valid ID. If no ID is valid, it returns NULL.
155 // XXX The string handling here probably could be improved.
156 template<class T
> typename
T::pointer
157 Theme::IDmap
<T
>::find_first_object( const string
&id
) const
159 string rightPart
= id
;
160 string::size_type pos
;
163 pos
= rightPart
.find( ";" );
164 string leftPart
= rightPart
.substr( 0, pos
);
166 typename
T::pointer p
= find_object( leftPart
);
169 if( pos
!= string::npos
)
171 rightPart
= rightPart
.substr( pos
, rightPart
.size() );
173 rightPart
.substr( rightPart
.find_first_not_of( " \t;" ),
177 while( pos
!= string::npos
);
181 GenericBitmap
*Theme::getBitmapById( const string
&id
) const
183 return m_bitmaps
.find_first_object( id
);
186 GenericFont
*Theme::getFontById( const string
&id
) const
188 return m_fonts
.find_first_object( id
);