Some documenting thingies.
[irreco.git] / irreco / trunk / src / core / irreco_theme_manager.c
blobff0f5e930ff09179754f98f45d530fc151b4277a
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
4 *
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.
9 *
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"
22 /**
23 * @addtogroup IrrecoThemeManager
25 * Contains information of themes.
27 * @{
30 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
31 /* Prototypes */
32 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
34 void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData * dir_data);
36 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /* Construction & Destruction */
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /**
41 * @name Construction & Destruction
42 * @{
45 IrrecoThemeManager *irreco_theme_manager_new(IrrecoData * irreco_data)
47 IrrecoThemeManager *self;
48 IRRECO_ENTER
50 self = g_slice_new0(IrrecoThemeManager);
52 self->themes = irreco_string_table_new(
53 (GDestroyNotify)irreco_theme_free, NULL);
55 /*Get themes*/
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. */
73 #if 1
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 *,
79 button) {
80 IrrecoButtonStyle *style;
81 style = irreco_button_style_create(irreco_data,
82 button->name->str,
83 button->image_up->str,
84 button->image_down->str,
85 button->allow_text,
86 FALSE);
88 if (!irreco_string_table_add(irreco_data->button_style_array,
89 style->name, style)) {
90 IRRECO_ERROR("Dublicate style name \"%s\"\n",
91 style->name);
92 irreco_button_style_destroy(style);
96 IRRECO_STRING_TABLE_FOREACH_END
98 IRRECO_STRING_TABLE_FOREACH_END
100 #endif
102 IRRECO_RETURN_PTR(self);
105 void irreco_theme_manager_free(IrrecoThemeManager *self)
107 IRRECO_ENTER
109 g_assert(self != NULL);
111 irreco_string_table_free(self->themes);
112 self->themes = NULL;
114 g_slice_free(IrrecoThemeManager, self);
115 self = NULL;
117 IRRECO_RETURN
120 /** @} */
122 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
123 /* Private Functions */
124 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
127 * @name Private Functions
128 * @{
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;
135 IrrecoTheme *theme;
136 IRRECO_ENTER
138 theme = irreco_theme_new(irreco_data, dir_data->filename,
139 dir_data->filepath);
141 irreco_string_table_add(self->themes, dir_data->filename, theme);
143 irreco_theme_print(theme);
145 IRRECO_RETURN
148 /** @} */
150 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
151 /* Public Functions */
152 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
155 * @name Public Functions
156 * @{
159 void irreco_theme_manager_print(IrrecoThemeManager *self)
161 IRRECO_ENTER
163 #if 1
164 irreco_string_table_print(self->themes);
165 #endif
167 #if 0
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
172 #endif
174 IRRECO_RETURN
177 IrrecoStringTable *irreco_theme_manager_get_themes(IrrecoThemeManager *self)
179 IRRECO_ENTER
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;
189 IRRECO_ENTER
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;
205 IRRECO_ENTER
207 if (irreco_string_table_get(self->themes, theme_name,
208 (gpointer*)&theme)) {
209 backgrounds = theme->backgrounds;
212 IRRECO_RETURN_PTR(backgrounds);
215 /** @} */
217 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
218 /* Events and Callbacks */
219 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
221 /** @} */