2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
4 * Sami Mäki (kasmra@xob.kapsi.fi)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "irreco_theme_manager.h"
24 * @addtogroup IrrecoThemeManager
27 * Contains information of themes.
32 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
34 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
36 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData
* dir_data
);
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /* Construction & Destruction */
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 * @name Construction & Destruction
47 IrrecoThemeManager
*irreco_theme_manager_new(IrrecoData
* irreco_data
)
49 IrrecoThemeManager
*self
;
52 self
= g_slice_new0(IrrecoThemeManager
);
54 self
->irreco_data
= irreco_data
;
56 self
->themes
= irreco_string_table_new(
57 (GDestroyNotify
)irreco_theme_free
, NULL
);
59 irreco_theme_manager_read_themes_from_dir(self
, IRRECO_THEME_DIR
);
60 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc1/irreco");
61 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc2/irreco");
63 IRRECO_RETURN_PTR(self
);
66 void irreco_theme_manager_free(IrrecoThemeManager
*self
)
70 g_assert(self
!= NULL
);
72 irreco_string_table_free(self
->themes
);
75 g_slice_free(IrrecoThemeManager
, self
);
83 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
84 /* Private Functions */
85 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
88 * @name Private Functions
92 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData
* dir_data
)
94 IrrecoTheme
*theme
= NULL
;
95 IrrecoThemeManager
*self
= (IrrecoThemeManager
*) dir_data
->user_data_1
;
98 IrrecoKeyFile
*keyfile
= NULL
;
101 conf
= g_string_new(dir_data
->filepath
);
103 g_string_append_printf(conf
, "/theme.conf");
104 keyfile
= irreco_keyfile_create(dir_data
->filepath
,
107 if (keyfile
== NULL
) goto end
;
109 /* Required fields. */
110 if (!irreco_keyfile_get_str(keyfile
, "name", &name
)) {
111 IRRECO_PRINTF("Could not read theme \"%s\"\n",
116 if (irreco_string_table_get(self
->themes
, name
, (gpointer
*) &theme
)) {
117 irreco_theme_read(theme
, dir_data
->filepath
);
119 theme
= irreco_theme_new_from_dir(dir_data
->filepath
);
120 irreco_string_table_add(self
->themes
, theme
->name
->str
, theme
);
123 g_string_free(conf
, TRUE
);
124 if (keyfile
!= NULL
) irreco_keyfile_destroy(keyfile
);
125 if (name
!= NULL
) g_free(name
);
133 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
134 /* Public Functions */
135 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
138 * @name Public Functions
142 void irreco_theme_manager_print(IrrecoThemeManager
*self
)
147 irreco_string_table_print(self
->themes
);
151 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
)
152 IRRECO_PRINTF("Theme: %s \n", theme
->name
->str
);
153 irreco_theme_print(theme
);
154 IRRECO_STRING_TABLE_FOREACH_END
160 IrrecoStringTable
*irreco_theme_manager_get_themes(IrrecoThemeManager
*self
)
164 IRRECO_RETURN_PTR(self
->themes
);
167 IrrecoStringTable
*irreco_theme_manager_get_buttons(IrrecoThemeManager
*self
,
168 const gchar
*theme_name
)
170 IrrecoStringTable
*buttons
= NULL
;
171 IrrecoTheme
*theme
= NULL
;
174 IRRECO_PRINTF("theme_name: %s\n", theme_name
);
175 if (irreco_string_table_get(self
->themes
, theme_name
,
176 (gpointer
*) &theme
)) {
177 buttons
= theme
->buttons
;
180 IRRECO_RETURN_PTR(buttons
);
183 IrrecoStringTable
*irreco_theme_manager_get_backgrounds(IrrecoThemeManager
*self
,
184 const gchar
*theme_name
)
186 IrrecoStringTable
*backgrounds
= NULL
;
187 IrrecoTheme
*theme
= NULL
;
190 if (irreco_string_table_get(self
->themes
, theme_name
,
191 (gpointer
*)&theme
)) {
192 backgrounds
= theme
->backgrounds
;
195 IRRECO_RETURN_PTR(backgrounds
);
198 void irreco_theme_manager_read_themes_from_dir(IrrecoThemeManager
*self
,
201 IrrecoDirForeachData themes
;
204 IRRECO_DEBUG("THEME_DIR = %s\n", dir
);
205 themes
.directory
= dir
;
207 themes
.filesuffix
= "";
208 themes
.user_data_1
= self
;
210 irreco_dir_foreach(&themes
, irreco_theme_manager_read_file_foreach
);
212 irreco_string_table_sort_abc(self
->themes
);
216 gboolean
irreco_theme_manager_get_button_style(IrrecoThemeManager
*self
,
217 const gchar
*style_name
,
218 IrrecoThemeButton
**style
)
220 IrrecoThemeButton
*button
= NULL
;
221 gboolean rvalue
= FALSE
;
223 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, void *, theme
) {
224 IrrecoStringTable
* buttons
= irreco_theme_get_buttons(theme
);
226 if (irreco_string_table_get(buttons
, style_name
,
227 (gpointer
*) &button
)) {
232 IRRECO_STRING_TABLE_FOREACH_END
233 IRRECO_RETURN_BOOL(rvalue
);
236 gboolean
irreco_theme_manager_does_deb_exist(IrrecoThemeManager
*self
)
238 gboolean rvalue
= FALSE
;
240 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
241 if (g_utf8_collate(theme
->source
->str
, "deb") == 0 ||
242 g_utf8_collate(theme
->source
->str
, "DEB") == 0) {
246 IRRECO_STRING_TABLE_FOREACH_END
247 IRRECO_RETURN_BOOL(rvalue
);
250 gboolean
irreco_theme_manager_does_web_exist(IrrecoThemeManager
*self
)
252 gboolean rvalue
= FALSE
;
254 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
255 if (g_utf8_collate(theme
->source
->str
, "web") == 0 ||
256 g_utf8_collate(theme
->source
->str
, "WEB") == 0) {
260 IRRECO_STRING_TABLE_FOREACH_END
261 IRRECO_RETURN_BOOL(rvalue
);
264 gboolean
irreco_theme_manager_does_user_exist(IrrecoThemeManager
*self
)
266 gboolean rvalue
= FALSE
;
268 IRRECO_STRING_TABLE_FOREACH_DATA(self
->themes
, IrrecoTheme
*, theme
) {
269 if (g_utf8_collate(theme
->source
->str
, "user") == 0 ||
270 g_utf8_collate(theme
->source
->str
, "USER") == 0) {
274 IRRECO_STRING_TABLE_FOREACH_END
275 IRRECO_RETURN_BOOL(rvalue
);
278 gboolean
irreco_theme_manager_remove_theme(IrrecoThemeManager
*self
,
279 const gchar
*theme_name
)
281 IrrecoTheme
*rmtheme
;
283 gboolean rvalue
= FALSE
;
284 IrrecoStringTable
*table
;
288 if (irreco_string_table_get(self
->themes
, theme_name
,
289 (gpointer
*) &rmtheme
)) {
290 /* Remove styles from layouts */
291 table
= self
->irreco_data
->irreco_layout_array
;
292 IRRECO_STRING_TABLE_FOREACH(table
, key
,
293 IrrecoButtonLayout
*, layout
)
294 IRRECO_PTR_ARRAY_FORWARDS(layout
->button_array
,
295 IrrecoButton
*, button
)
296 if (button
->style
!= NULL
&&
297 g_str_equal(button
->style
->theme_name
->str
,
299 button
->type
= IRRECO_BTYPE_GTK_BUTTON
;
300 irreco_button_set_style(button
, NULL
);
301 irreco_button_create_widget(button
);
304 IRRECO_PTR_ARRAY_FORWARDS_END
305 IRRECO_STRING_TABLE_FOREACH_END
308 irreco_config_save_layouts(self
->irreco_data
);
310 /* Build remove command */
311 rm_cmd
= g_strconcat("rm -r ", rmtheme
->path
->str
, NULL
);
313 /* Remove theme directory and its contents from device */
318 /* And from the string table */
319 irreco_string_table_remove(self
->themes
, theme_name
);
324 IRRECO_RETURN_BOOL(rvalue
);
327 void irreco_theme_manager_update_theme_manager(IrrecoThemeManager
*self
)
331 irreco_theme_manager_read_themes_from_dir(self
, IRRECO_THEME_DIR
);
332 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc1/irreco");
333 irreco_theme_manager_read_themes_from_dir(self
, "/media/mmc2/irreco");
335 /* Check if some theme is deleted */
336 IRRECO_STRING_TABLE_FOREACH(self
->themes
, key
, IrrecoTheme
*,
338 if(!irreco_is_dir(theme
->path
->str
)) {
339 irreco_string_table_remove(self
->themes
, key
);
341 IRRECO_STRING_TABLE_FOREACH_END
348 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
349 /* Events and Callbacks */
350 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/