]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/theme.cpp
90cbf6ddf6a7ad0352cb8a69d224dd8182b534c3
[vlc] / modules / gui / skins2 / src / theme.cpp
1 /*****************************************************************************
2  * theme.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #include "theme.hpp"
26
27
28 Theme::~Theme()
29 {
30     saveConfig();
31
32     // Be sure things are destroyed in the right order (XXX check)
33     m_vouts.clear();
34     m_layouts.clear();
35     m_controls.clear();
36     m_windows.clear();
37     m_bitmaps.clear();
38     m_fonts.clear();
39     m_commands.clear();
40     m_vars.clear();
41     m_curves.clear();
42 }
43
44
45 void Theme::loadConfig()
46 {
47     msg_Dbg( getIntf(), "Loading theme configuration");
48
49     // Get config from vlcrc file
50     char *save = config_GetPsz( getIntf(), "skins2-config" );
51     if( save == NULL )
52         return;
53
54     // Initialization
55     map<string, GenericWindowPtr>::const_iterator it;
56     int i = 0;
57     int x, y, v, scan;
58
59     // Get config for each window
60     for( it = m_windows.begin(); it != m_windows.end(); it++ )
61     {
62         GenericWindow *pWin = (*it).second.get();
63         // Get config
64         scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &v );
65
66         // If config has the correct number of arguments
67         if( scan > 2 )
68         {
69             pWin->move( x, y );
70             if( v ) pWin->show();
71         }
72
73         // Next window
74         i++;
75     }
76 }
77
78
79 void Theme::saveConfig()
80 {
81     msg_Dbg( getIntf(), "Saving theme configuration");
82
83     // Initialize char where config is stored
84     char *save  = new char[400];
85     map<string, GenericWindowPtr>::const_iterator it;
86     int i = 0;
87     int x, y;
88
89     // Save config of every window
90     for( it = m_windows.begin(); it != m_windows.end(); it++ )
91     {
92         GenericWindow *pWin = (*it).second.get();
93         // Print config
94         x = pWin->getLeft();
95         y = pWin->getTop();
96         sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
97             pWin->getVisibleVar().get() );
98         i++;
99     }
100
101     // Save config to file
102     config_PutPsz( getIntf(), "skins2-config", save );
103     config_SaveConfigFile( getIntf(), "skins2" );
104
105     // Free memory
106     delete[] save;
107 }
108
109
110 // Useful macro
111 #define FIND_OBJECT( mapData, mapName ) \
112     map<string, mapData>::const_iterator it; \
113     it = mapName.find( id ); \
114     if( it == mapName.end() ) \
115     { \
116         return NULL; \
117     } \
118     return (*it).second.get();
119
120 GenericBitmap *Theme::getBitmapById( const string &id )
121 {
122     FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
123 }
124
125 GenericFont *Theme::getFontById( const string &id )
126 {
127     FIND_OBJECT( GenericFontPtr, m_fonts );
128 }
129
130 GenericWindow *Theme::getWindowById( const string &id )
131 {
132     FIND_OBJECT( GenericWindowPtr, m_windows );
133 }
134
135 GenericLayout *Theme::getLayoutById( const string &id )
136 {
137     FIND_OBJECT( GenericLayoutPtr, m_layouts );
138 }
139
140 CtrlGeneric *Theme::getControlById( const string &id )
141 {
142     FIND_OBJECT( CtrlGenericPtr, m_controls );
143 }
144
145
146