2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_theme_manager.h"
23 * @addtogroup IrrecoThemeManager
25 * Contains information of themes.
30 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
32 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
34 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData
* dir_data
);
36 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /* Construction & Destruction */
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 * @name Construction & Destruction
45 IrrecoThemeManager
*irreco_theme_manager_new(IrrecoData
* irreco_data
)
47 IrrecoThemeManager
*self
;
50 self
= g_slice_new0(IrrecoThemeManager
);
52 self
->themes
= irreco_string_table_new(
53 (GDestroyNotify
)irreco_theme_free
, NULL
);
57 IrrecoDirForeachData bg_styles
;
59 IRRECO_DEBUG("IRRECO_THEME_DIR = %s\n", IRRECO_THEME_DIR
);
60 bg_styles
.directory
= IRRECO_THEME_DIR
;
62 bg_styles
.filesuffix
= "";
63 bg_styles
.user_data_1
= irreco_data
;
64 bg_styles
.user_data_2
= self
;
66 irreco_dir_foreach(&bg_styles
,
67 irreco_theme_manager_read_file_foreach
);
69 irreco_string_table_sort_abc(self
->themes
);
72 /* Attempt to add the style to the style array. */
76 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
) {
77 IrrecoStringTable
* buttons
= irreco_theme_get_buttons(theme
);
78 IRRECO_STRING_TABLE_FOREACH_DATA(buttons
, IrrecoThemeButton
*,
80 IrrecoButtonStyle
*style
;
81 style
= irreco_button_style_create(irreco_data
,
83 button
->image_up
->str
,
84 button
->image_down
->str
,
88 if (!irreco_string_table_add(irreco_data
->button_style_array
,
89 style
->name
, style
)) {
90 IRRECO_ERROR("Dublicate style name \"%s\"\n",
92 irreco_button_style_destroy(style
);
96 IRRECO_STRING_TABLE_FOREACH_END
98 IRRECO_STRING_TABLE_FOREACH_END
102 IRRECO_RETURN_PTR(self
);
105 void irreco_theme_manager_free(IrrecoThemeManager
*self
)
109 g_assert(self
!= NULL
);
111 irreco_string_table_free(self
->themes
);
114 g_slice_free(IrrecoThemeManager
, self
);
122 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
123 /* Private Functions */
124 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
127 * @name Private Functions
131 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData
* dir_data
)
133 IrrecoData
*irreco_data
= (IrrecoData
*) dir_data
->user_data_1
;
134 IrrecoThemeManager
*self
= (IrrecoThemeManager
*) dir_data
->user_data_2
;
138 theme
= irreco_theme_new(irreco_data
, dir_data
->filename
,
141 irreco_string_table_add(self
->themes
, dir_data
->filename
, theme
);
143 irreco_theme_print(theme
);
150 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
151 /* Public Functions */
152 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
155 * @name Public Functions
159 void irreco_theme_manager_print(IrrecoThemeManager
*self
)
164 irreco_string_table_print(self
->themes
);
168 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
)
169 IRRECO_PRINTF("Theme: %s \n", theme
->name
->str
);
170 irreco_theme_print(theme
);
171 IRRECO_STRING_TABLE_FOREACH_END
177 IrrecoStringTable
*irreco_theme_manager_get_themes(IrrecoThemeManager
*self
)
181 IRRECO_RETURN_PTR(self
->themes
);
184 IrrecoStringTable
*irreco_theme_manager_get_buttons(IrrecoThemeManager
*self
,
185 const gchar
*theme_name
)
187 IrrecoStringTable
*buttons
= NULL
;
188 IrrecoTheme
*theme
= NULL
;
191 IRRECO_PRINTF("theme_name: %s\n", theme_name
);
192 if (irreco_string_table_get(self
->themes
, theme_name
,
193 (gpointer
*) &theme
)) {
194 buttons
= theme
->buttons
;
197 IRRECO_RETURN_PTR(buttons
);
200 IrrecoStringTable
*irreco_theme_manager_get_backgrounds(IrrecoThemeManager
*self
,
201 const gchar
*theme_name
)
203 IrrecoStringTable
*backgrounds
= NULL
;
204 IrrecoTheme
*theme
= NULL
;
207 if (irreco_string_table_get(self
->themes
, theme_name
,
208 (gpointer
*)&theme
)) {
209 backgrounds
= theme
->backgrounds
;
212 IRRECO_RETURN_PTR(backgrounds
);
217 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
218 /* Events and Callbacks */
219 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/