]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/theme.cpp
Remove bogus executable permissions
[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     // Be sure things are destroyed in the right order (XXX check)
31     m_layouts.clear();
32     m_controls.clear();
33     m_windows.clear();
34     m_bitmaps.clear();
35     m_fonts.clear();
36     m_commands.clear();
37     m_vars.clear();
38     m_curves.clear();
39 }
40
41
42 void Theme::loadConfig()
43 {
44     msg_Dbg( getIntf(), "Loading theme configuration");
45
46     // Get config from vlcrc file
47     char *save = config_GetPsz( getIntf(), "skins2-config" );
48     if( !save ) return;
49
50     // Is there an existing config?
51     if( !strcmp( save, "" ) )
52     {
53         // Show the windows
54         m_windowManager.showAll();
55         return;
56     }
57
58     // Initialization
59     map<string, TopWindowPtr>::const_iterator it;
60     int i = 0;
61     int x, y, visible, scan;
62
63     // Get config for each window
64     for( it = m_windows.begin(); it != m_windows.end(); it++ )
65     {
66         TopWindow *pWin = (*it).second.get();
67         // Get config
68         scan = sscanf( &save[i * 13], "(%4d,%4d,%1d)", &x, &y, &visible );
69
70         // If config has the correct number of arguments
71         if( scan > 2 )
72         {
73             m_windowManager.startMove( *pWin );
74             m_windowManager.move( *pWin, x, y );
75             m_windowManager.stopMove();
76             if( visible )
77             {
78                 m_windowManager.show( *pWin );
79             }
80         }
81
82         // Next window
83         i++;
84     }
85     free( save );
86 }
87
88
89 void Theme::saveConfig()
90 {
91     msg_Dbg( getIntf(), "Saving theme configuration");
92
93     // Initialize char where config is stored
94     char *save  = new char[400];
95     map<string, TopWindowPtr>::const_iterator it;
96     int i = 0;
97     int x, y;
98
99     // Save config of every window
100     for( it = m_windows.begin(); it != m_windows.end(); it++ )
101     {
102         TopWindow *pWin = (*it).second.get();
103         // Print config
104         x = pWin->getLeft();
105         y = pWin->getTop();
106         sprintf( &save[i * 13], "(%4d,%4d,%1d)", x, y,
107             pWin->getVisibleVar().get() );
108         i++;
109     }
110
111     // Save config to file
112     config_PutPsz( getIntf(), "skins2-config", save );
113     config_SaveConfigFile( getIntf(), "skins2" );
114
115     // Free memory
116     delete[] save;
117 }
118
119
120 // Useful macro
121 #define FIND_OBJECT( mapData, mapName ) \
122     map<string, mapData>::const_iterator it; \
123     it = mapName.find( id ); \
124     if( it == mapName.end() ) \
125     { \
126         return NULL; \
127     } \
128     return (*it).second.get();
129
130 GenericBitmap *Theme::getBitmapById( const string &id )
131 {
132     FIND_OBJECT( GenericBitmapPtr, m_bitmaps );
133 }
134
135 GenericFont *Theme::getFontById( const string &id )
136 {
137     FIND_OBJECT( GenericFontPtr, m_fonts );
138 }
139
140 TopWindow *Theme::getWindowById( const string &id )
141 {
142     FIND_OBJECT( TopWindowPtr, m_windows );
143 }
144
145 GenericLayout *Theme::getLayoutById( const string &id )
146 {
147     FIND_OBJECT( GenericLayoutPtr, m_layouts );
148 }
149
150 CtrlGeneric *Theme::getControlById( const string &id )
151 {
152     FIND_OBJECT( CtrlGenericPtr, m_controls );
153 }
154
155
156