2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
4 * Sami Mäki (kasmra@xob.kapsi.fi)
5 * Pekka Gehör (pegu6@msn.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "irreco_theme_manager.h"
25 * @addtogroup IrrecoThemeManager
28 * Contains information of themes.
33 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
35 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData
* dir_data
);
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /* Construction & Destruction */
41 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 * @name Construction & Destruction
48 IrrecoThemeManager
*irreco_theme_manager_new(IrrecoData
* irreco_data
)
50 IrrecoThemeManager
*self
;
53 self
= g_slice_new0(IrrecoThemeManager
);
55 self
->irreco_data
= irreco_data
;
57 self
->themes
= irreco_string_table_new(
58 (GDestroyNotify
)irreco_theme_free
, NULL
);
60 irreco_theme_manager_read_themes_from_dir(self
, IRRECO_THEME_DIR
);
61 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc1/irreco");
62 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc2/irreco");
64 IRRECO_RETURN_PTR(self
);
67 void irreco_theme_manager_free(IrrecoThemeManager
*self
)
71 g_assert(self
!= NULL
);
73 irreco_string_table_free(self
->themes
);
76 g_slice_free(IrrecoThemeManager
, self
);
84 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
85 /* Private Functions */
86 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
89 * @name Private Functions
93 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData
* dir_data
)
95 IrrecoTheme
*theme
= NULL
;
96 IrrecoThemeManager
*self
= (IrrecoThemeManager
*) dir_data
->user_data_1
;
99 theme
= irreco_theme_new_from_dir(dir_data
->filepath
);
101 if (irreco_string_table_exists(self
->themes
, theme
->name
->str
)) {
102 IRRECO_ERROR("Error: Theme %s has already been read. "
103 "You cannot have two themes with the same name.\n",
105 irreco_theme_free(theme
);
107 irreco_string_table_add(self
->themes
, theme
->name
->str
, theme
);
115 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
116 /* Public Functions */
117 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
120 * @name Public Functions
124 void irreco_theme_manager_print(IrrecoThemeManager
*self
)
129 irreco_string_table_print(self
->themes
);
133 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
)
134 IRRECO_PRINTF("Theme: %s \n", theme
->name
->str
);
135 irreco_theme_print(theme
);
136 IRRECO_STRING_TABLE_FOREACH_END
142 IrrecoStringTable
*irreco_theme_manager_get_themes(IrrecoThemeManager
*self
)
146 IRRECO_RETURN_PTR(self
->themes
);
149 IrrecoStringTable
*irreco_theme_manager_get_buttons(IrrecoThemeManager
*self
,
150 const gchar
*theme_name
)
152 IrrecoStringTable
*buttons
= NULL
;
153 IrrecoTheme
*theme
= NULL
;
156 IRRECO_PRINTF("theme_name: %s\n", theme_name
);
157 if (irreco_string_table_get(self
->themes
, theme_name
,
158 (gpointer
*) &theme
)) {
159 buttons
= theme
->buttons
;
162 IRRECO_RETURN_PTR(buttons
);
165 IrrecoStringTable
*irreco_theme_manager_get_backgrounds(IrrecoThemeManager
*self
,
166 const gchar
*theme_name
)
168 IrrecoStringTable
*backgrounds
= NULL
;
169 IrrecoTheme
*theme
= NULL
;
172 if (irreco_string_table_get(self
->themes
, theme_name
,
173 (gpointer
*)&theme
)) {
174 backgrounds
= theme
->backgrounds
;
177 IRRECO_RETURN_PTR(backgrounds
);
180 void irreco_theme_manager_read_themes_from_dir(IrrecoThemeManager
*self
,
183 IrrecoDirForeachData themes
;
186 IRRECO_DEBUG("THEME_DIR = %s\n", dir
);
187 themes
.directory
= dir
;
189 themes
.filesuffix
= "";
190 themes
.user_data_1
= self
;
192 irreco_dir_foreach(&themes
, irreco_theme_manager_read_file_foreach
);
194 irreco_string_table_sort_abc(self
->themes
);
198 gboolean
irreco_theme_manager_get_button_style(IrrecoThemeManager
*self
,
199 const gchar
*style_name
,
200 IrrecoThemeButton
**style
)
202 IrrecoThemeButton
*button
= NULL
;
203 gboolean rvalue
= FALSE
;
205 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
) {
206 IrrecoStringTable
* buttons
= irreco_theme_get_buttons(theme
);
208 if (irreco_string_table_get(buttons
, style_name
,
209 (gpointer
*) &button
)) {
214 IRRECO_STRING_TABLE_FOREACH_END
215 IRRECO_RETURN_BOOL(rvalue
);
218 gboolean
irreco_theme_manager_does_deb_exist(IrrecoThemeManager
*self
)
220 gboolean rvalue
= FALSE
;
222 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
223 if (g_utf8_collate(theme
->source
->str
, "deb") == 0 ||
224 g_utf8_collate(theme
->source
->str
, "DEB") == 0) {
228 IRRECO_STRING_TABLE_FOREACH_END
229 IRRECO_RETURN_BOOL(rvalue
);
232 gboolean
irreco_theme_manager_does_web_exist(IrrecoThemeManager
*self
)
234 gboolean rvalue
= FALSE
;
236 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
237 if (g_utf8_collate(theme
->source
->str
, "web") == 0 ||
238 g_utf8_collate(theme
->source
->str
, "WEB") == 0) {
242 IRRECO_STRING_TABLE_FOREACH_END
243 IRRECO_RETURN_BOOL(rvalue
);
246 gboolean
irreco_theme_manager_does_user_exist(IrrecoThemeManager
*self
)
248 gboolean rvalue
= FALSE
;
250 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
251 if (g_utf8_collate(theme
->source
->str
, "user") == 0 ||
252 g_utf8_collate(theme
->source
->str
, "USER") == 0) {
256 IRRECO_STRING_TABLE_FOREACH_END
257 IRRECO_RETURN_BOOL(rvalue
);
260 gboolean
irreco_theme_manager_remove_theme(IrrecoThemeManager
*self
,
261 const gchar
*theme_name
)
263 IrrecoTheme
*rmtheme
;
265 gboolean rvalue
= FALSE
;
266 IrrecoStringTable
*table
;
270 if (irreco_string_table_get(self
->themes
, theme_name
,
271 (gpointer
*) &rmtheme
)) {
272 /* Remove styles from layouts */
273 table
= self
->irreco_data
->irreco_layout_array
;
274 IRRECO_STRING_TABLE_FOREACH(table
, key
,
275 IrrecoButtonLayout
*, layout
)
276 IRRECO_PTR_ARRAY_FORWARDS(layout
->button_array
,
277 IrrecoButton
*, button
)
278 if (button
->style
!= NULL
&&
279 g_str_equal(button
->style
->theme_name
->str
,
281 button
->type
= IRRECO_BTYPE_GTK_BUTTON
;
282 irreco_button_set_style(button
, NULL
);
283 irreco_button_create_widget(button
);
286 IRRECO_PTR_ARRAY_FORWARDS_END
287 IRRECO_STRING_TABLE_FOREACH_END
290 irreco_config_save_layouts(self
->irreco_data
);
292 /* Build remove command */
293 rm_cmd
= g_strconcat("rm -r ", rmtheme
->path
->str
, NULL
);
295 /* Remove theme directory and its contents from device */
300 /* And from the string table */
301 irreco_string_table_remove(self
->themes
, theme_name
);
306 IRRECO_RETURN_BOOL(rvalue
);
309 void irreco_theme_manager_update_theme_manager(IrrecoThemeManager
*self
)
313 irreco_theme_manager_read_themes_from_dir(self
, IRRECO_THEME_DIR
);
314 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc1/irreco");
315 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc2/irreco");
317 /* Check if some theme is deleted */
318 IRRECO_STRING_TABLE_FOREACH(self
->themes
, key
, IrrecoTheme
*,
320 if(!irreco_is_dir(theme
->path
->str
)) {
321 irreco_string_table_remove(self
->themes
, key
);
323 IRRECO_STRING_TABLE_FOREACH_END
330 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
331 /* Events and Callbacks */
332 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/