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
, "/home/user/MyDocs/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 IrrecoTheme
*old_theme
= NULL
;
97 IrrecoThemeManager
*self
= (IrrecoThemeManager
*) dir_data
->user_data_1
;
100 if (irreco_is_dir(dir_data
->filepath
)) {
101 theme
= irreco_theme_new_from_dir(dir_data
->filepath
);
103 if (irreco_string_table_exists(self
->themes
, theme
->name
->str
)) {
104 IRRECO_ERROR("Error: Theme %s has already been read. "
105 "You cannot have two themes with the same name.\n",
108 irreco_string_table_get(self
->themes
, theme
->name
->str
,
109 (gpointer
*) &old_theme
);
110 irreco_theme_read(old_theme
, dir_data
->filepath
);
111 irreco_theme_free(theme
);
114 irreco_string_table_add(self
->themes
, theme
->name
->str
, theme
);
117 IRRECO_DEBUG("DIR: %s \n", dir_data
->filepath
);
125 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
126 /* Public Functions */
127 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
130 * @name Public Functions
134 void irreco_theme_manager_print(IrrecoThemeManager
*self
)
139 irreco_string_table_print(self
->themes
);
143 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
)
144 IRRECO_PRINTF("Theme: %s \n", theme
->name
->str
);
145 irreco_theme_print(theme
);
146 IRRECO_STRING_TABLE_FOREACH_END
152 IrrecoStringTable
*irreco_theme_manager_get_themes(IrrecoThemeManager
*self
)
156 IRRECO_RETURN_PTR(self
->themes
);
159 IrrecoStringTable
*irreco_theme_manager_get_buttons(IrrecoThemeManager
*self
,
160 const gchar
*theme_name
)
162 IrrecoStringTable
*buttons
= NULL
;
163 IrrecoTheme
*theme
= NULL
;
166 IRRECO_DEBUG("theme_name: %s\n", theme_name
);
167 if (irreco_string_table_get(self
->themes
, theme_name
,
168 (gpointer
*) &theme
)) {
169 buttons
= theme
->buttons
;
172 IRRECO_RETURN_PTR(buttons
);
175 IrrecoStringTable
*irreco_theme_manager_get_backgrounds(IrrecoThemeManager
*self
,
176 const gchar
*theme_name
)
178 IrrecoStringTable
*backgrounds
= NULL
;
179 IrrecoTheme
*theme
= NULL
;
182 if (irreco_string_table_get(self
->themes
, theme_name
,
183 (gpointer
*)&theme
)) {
184 backgrounds
= theme
->backgrounds
;
187 IRRECO_RETURN_PTR(backgrounds
);
190 void irreco_theme_manager_read_themes_from_dir(IrrecoThemeManager
*self
,
193 IrrecoDirForeachData themes
;
196 IRRECO_DEBUG("THEME_DIR = %s\n", dir
);
197 themes
.directory
= dir
;
199 themes
.filesuffix
= "";
200 themes
.user_data_1
= self
;
202 irreco_dir_foreach(&themes
, irreco_theme_manager_read_file_foreach
);
204 irreco_string_table_sort_abc(self
->themes
);
208 gboolean
irreco_theme_manager_get_button_style(IrrecoThemeManager
*self
,
209 const gchar
*style_name
,
210 IrrecoThemeButton
**style
)
212 IrrecoThemeButton
*button
= NULL
;
213 gboolean rvalue
= FALSE
;
215 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
) {
216 IrrecoStringTable
* buttons
= irreco_theme_get_buttons(theme
);
218 if (irreco_string_table_get(buttons
, style_name
,
219 (gpointer
*) &button
)) {
224 IRRECO_STRING_TABLE_FOREACH_END
225 IRRECO_RETURN_BOOL(rvalue
);
228 gboolean
irreco_theme_manager_does_deb_exist(IrrecoThemeManager
*self
)
230 gboolean rvalue
= FALSE
;
232 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
233 if (g_utf8_collate(theme
->source
->str
, "deb") == 0 ||
234 g_utf8_collate(theme
->source
->str
, "DEB") == 0) {
238 IRRECO_STRING_TABLE_FOREACH_END
239 IRRECO_RETURN_BOOL(rvalue
);
242 gboolean
irreco_theme_manager_does_web_exist(IrrecoThemeManager
*self
)
244 gboolean rvalue
= FALSE
;
246 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
247 if (g_utf8_collate(theme
->source
->str
, "web") == 0 ||
248 g_utf8_collate(theme
->source
->str
, "WEB") == 0) {
252 IRRECO_STRING_TABLE_FOREACH_END
253 IRRECO_RETURN_BOOL(rvalue
);
256 gboolean
irreco_theme_manager_does_user_exist(IrrecoThemeManager
*self
)
258 gboolean rvalue
= FALSE
;
260 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
261 if (g_utf8_collate(theme
->source
->str
, "user") == 0 ||
262 g_utf8_collate(theme
->source
->str
, "USER") == 0) {
266 IRRECO_STRING_TABLE_FOREACH_END
267 IRRECO_RETURN_BOOL(rvalue
);
270 gboolean
irreco_theme_manager_remove_theme(IrrecoThemeManager
*self
,
271 const gchar
*theme_name
)
273 IrrecoTheme
*rmtheme
;
275 gboolean rvalue
= FALSE
;
276 IrrecoStringTable
*table
;
280 if (irreco_string_table_get(self
->themes
, theme_name
,
281 (gpointer
*) &rmtheme
)) {
282 /* Remove styles from layouts */
283 table
= self
->irreco_data
->irreco_layout_array
;
284 IRRECO_STRING_TABLE_FOREACH(table
, key
,
285 IrrecoButtonLayout
*, layout
)
286 IRRECO_PTR_ARRAY_FORWARDS(layout
->button_array
,
287 IrrecoButton
*, button
)
288 if (button
->style
!= NULL
&&
289 g_str_equal(button
->style
->theme_name
->str
,
291 button
->type
= IRRECO_BTYPE_GTK_BUTTON
;
292 irreco_button_set_style(button
, NULL
);
293 irreco_button_create_widget(button
);
296 IRRECO_PTR_ARRAY_FORWARDS_END
297 IRRECO_STRING_TABLE_FOREACH_END
300 irreco_config_save_layouts(self
->irreco_data
);
302 /* Build remove command */
303 rm_cmd
= g_strconcat("rm -r ", rmtheme
->path
->str
, NULL
);
305 /* Remove theme directory and its contents from device */
310 /* And from the string table */
311 irreco_string_table_remove(self
->themes
, theme_name
);
316 IRRECO_RETURN_BOOL(rvalue
);
319 void irreco_theme_manager_update_theme_manager(IrrecoThemeManager
*self
)
323 irreco_theme_manager_read_themes_from_dir(self
, IRRECO_THEME_DIR
);
324 irreco_theme_manager_read_themes_from_dir(self
, "/home/user/MyDocs/irreco");
325 /* irreco_theme_manager_read_themes_from_dir(self, "/media/mmc2/irreco");*/
327 /* Check if some theme is deleted */
328 IRRECO_STRING_TABLE_FOREACH(self
->themes
, key
, IrrecoTheme
*,
330 if(!irreco_is_dir(theme
->path
->str
)) {
331 irreco_string_table_remove(self
->themes
, key
);
333 IRRECO_STRING_TABLE_FOREACH_END
340 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
341 /* Events and Callbacks */
342 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/