]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/theme.cpp
* src/interface/interface.c: added skins2 to the interface menu.
[vlc] / modules / gui / skins2 / src / theme.cpp
1 /*****************************************************************************
2  * theme.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: theme.cpp,v 1.3 2004/02/08 11:23:17 gbazin Exp $
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_layouts.clear();
34     m_controls.clear();
35     m_windows.clear();
36     m_bitmaps.clear();
37     m_fonts.clear();
38     m_commands.clear();
39     m_vars.clear();
40 }
41
42
43 void Theme::loadConfig()
44 {
45     msg_Dbg( getIntf(), "Loading theme configuration");
46
47     // Get config from vlcrc file
48     char *save = config_GetPsz( getIntf(), "skins2-config" );
49     if( save == NULL )
50         return;
51
52     // Initialization
53     map<string, GenericWindowPtr>::const_iterator it;
54     int i = 0;
55     int x, y, v, scan;
56
57     // Get config for each window
58     for( it = m_windows.begin(); it != m_windows.end(); it++ )
59     {
60         GenericWindow *pWin = (*it).second.get();
61         // Get config
62         scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &v );
63
64         // If config has the correct number of arguments
65         if( scan > 2 )
66         {
67             pWin->move( x, y );
68             if( v ) pWin->show();
69         }
70
71         // Next window
72         i++;
73     }
74 }
75
76
77 void Theme::saveConfig()
78 {
79     msg_Dbg( getIntf(), "Saving theme configuration");
80
81     // Initialize char where config is stored
82     char *save  = new char[400];
83     map<string, GenericWindowPtr>::const_iterator it;
84     int i = 0;
85     int x, y;
86
87     // Save config of every window
88     for( it = m_windows.begin(); it != m_windows.end(); it++ )
89     {
90         GenericWindow *pWin = (*it).second.get();
91         // Print config
92         x = pWin->getLeft();
93         y = pWin->getTop();
94         sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
95             pWin->getVisibleVar().get() );
96         i++;
97     }
98
99     // Save config to file
100     config_PutPsz( getIntf(), "skins2-config", save );
101     config_SaveConfigFile( getIntf(), "skins2" );
102
103     // Free memory
104     delete[] save;
105 }
106
107
108 // Useful macro
109 #define FIND_OBJECT( mapData, mapName ) \
110     map<string, mapData>::const_iterator it; \
111     it = mapName.find( id ); \
112     if( it == mapName.end() ) \
113     { \
114         return NULL; \
115     } \
116     return (*it).second.get();
117
118 GenericBitmap *Theme::getBitmapById( const string &id )
119 {
120     FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
121 }
122
123 GenericFont *Theme::getFontById( const string &id )
124 {
125     FIND_OBJECT( GenericFontPtr, m_fonts );
126 }
127
128 GenericWindow *Theme::getWindowById( const string &id )
129 {
130     FIND_OBJECT( GenericWindowPtr, m_windows );
131 }
132
133 GenericLayout *Theme::getLayoutById( const string &id )
134 {
135     FIND_OBJECT( GenericLayoutPtr, m_layouts );
136 }
137
138 CtrlGeneric *Theme::getControlById( const string &id )
139 {
140     FIND_OBJECT( CtrlGenericPtr, m_controls );
141 }
142
143
144