clean code
[irreco.git] / irreco / src / core / irreco_theme_creator_buttons.c
blobf0eed4c145ed3bd3f184a81a39227e59695d9c7f
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * irreco - Ir Remote Control
4 * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com)
5 *
6 * irreco_theme_creator_buttons.c is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * irreco_theme_creator_buttons.c is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "irreco_theme_creator_buttons.h"
21 #include "irreco_theme_creator_dlg.h"
22 #include "irreco_background_creator_dlg.h"
23 #include "irreco_button_creator_dlg.h"
25 /**
26 * @addtogroup IrrecoThemeCreatorBackgrounds
27 * @ingroup Irreco
29 * User interface for IrrecoThemeCreatorDlgBackgrounds.
31 * @{
34 /**
35 * @file
36 * Source file of @ref IrrecoThemeCreatorBackgrounds.
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /* Datatypes */
41 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 #define IRRECO_BUTTON_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 3)
44 #define IRRECO_BUTTON_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 3)
46 enum
48 DATA_COL,
49 TEXT_COL,
50 PIXBUF_COL,
51 PIXBUF_COL,
52 N_COLUMNS
54 /** Loader states. */
55 enum
57 LOADER_STATE_INIT,
58 LOADER_STATE_LOOP,
59 LOADER_STATE_END,
60 LOADER_STATE_CLEANUP
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
64 /* Prototypes. */
65 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
67 void irreco_theme_creator_buttons_image_append(IrrecoThemeCreatorButtons *self);
73 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
74 /* Construction & Destruction */
75 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
77 /**
78 * @name Construction & Destruction
79 * @{
85 G_DEFINE_TYPE (IrrecoThemeCreatorButtons, irreco_theme_creator_buttons,
86 IRRECO_TYPE_INTERNAL_WIDGET)
88 static void
89 irreco_theme_creator_buttons_finalize (GObject *object)
91 /* TODO: Add deinitalization code here */
92 IRRECO_ENTER
93 G_OBJECT_CLASS (
94 irreco_theme_creator_buttons_parent_class)->finalize (object);
95 IRRECO_RETURN
98 static void
99 irreco_theme_creator_buttons_class_init (IrrecoThemeCreatorButtonsClass *klass)
101 GObjectClass *object_class;
102 IRRECO_ENTER
104 object_class = G_OBJECT_CLASS (klass);
105 object_class->finalize = irreco_theme_creator_buttons_finalize;
106 IRRECO_RETURN
109 static void
110 irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons *self)
112 /* TODO: Add initialization code here */
114 IRRECO_ENTER
116 gtk_box_set_spacing(GTK_BOX(self), 1);
118 /*BUTTONS*/
119 self->scroll_buttons = gtk_scrolled_window_new(NULL, NULL);
120 self->store_buttons = gtk_list_store_new(N_COLUMNS, G_TYPE_POINTER,
121 G_TYPE_STRING, GDK_TYPE_PIXBUF,
122 GDK_TYPE_PIXBUF);
123 self->view_buttons = gtk_tree_view_new();
124 gtk_box_pack_start_defaults(GTK_BOX(self), self->scroll_buttons);
127 /*BUTTONS COLUMNS*/
129 gtk_tree_view_set_model(GTK_TREE_VIEW(self->view_buttons),
130 GTK_TREE_MODEL(self->store_buttons));
131 g_object_unref(self->store_buttons);
133 /* Create pixbuf column. */
134 self->renderer_buttons = gtk_cell_renderer_pixbuf_new();
135 self->column_buttons = gtk_tree_view_column_new_with_attributes(
136 "Unpressed ", self->renderer_buttons,
137 "pixbuf", PIXBUF_COL, NULL);
138 gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons),
139 self->column_buttons);
141 self->renderer_buttons = gtk_cell_renderer_pixbuf_new();
142 self->column_buttons = gtk_tree_view_column_new_with_attributes(
143 "Pressed ",
144 self->renderer_buttons,
145 "pixbuf", PIXBUF_COL, NULL);
146 gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons),
147 self->column_buttons);
149 /* Create text column. */
150 self->renderer_buttons = gtk_cell_renderer_text_new();
151 self->column_buttons = gtk_tree_view_column_new_with_attributes(
152 "Name ",
153 self->renderer_buttons,
154 "text", TEXT_COL, NULL);
155 gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons),
156 self->column_buttons);
157 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self->view_buttons),
158 TRUE);
161 /* Scroll_buttons*/
163 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scroll_buttons),
164 GTK_POLICY_AUTOMATIC,
165 GTK_POLICY_AUTOMATIC);
166 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
167 self->scroll_buttons),
168 self->view_buttons);
169 self->tree_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(
170 self->view_buttons));
171 gtk_tree_selection_set_mode(self->tree_selection, GTK_SELECTION_SINGLE);
173 IRRECO_RETURN
177 GtkWidget* irreco_theme_creator_buttons_new(GtkWindow *parent,
178 IrrecoData *irreco_data,
179 IrrecoTheme * irreco_theme)
181 IrrecoThemeCreatorButtons *self;
182 IRRECO_ENTER
184 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_BUTTONS,
185 "irreco-data", irreco_data,
186 NULL);
188 irreco_theme_creator_buttons_set_parent_window(self, parent);
189 self->parent_window = GTK_WINDOW(parent);
190 self->irreco_data = irreco_data;
191 self->theme = irreco_theme;
192 if (irreco_theme !=NULL) {
193 irreco_theme_creator_buttons_image_append(self);
195 IRRECO_RETURN_PTR(GTK_WIDGET(self));
198 /** @} */
202 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
203 /* Private Functions */
204 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
207 * @name Private Functions
208 * @{
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
213 /* Public Functions */
214 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
217 * @name Public Functions
218 * @{
222 * Set parent window for popup dialogs.
224 void
225 irreco_theme_creator_buttons_set_parent_window(IrrecoThemeCreatorButtons *self,
226 GtkWindow *parent)
228 IRRECO_ENTER
229 self->parent_window = parent;
230 IRRECO_RETURN
233 void irreco_theme_creator_buttons_image_append(IrrecoThemeCreatorButtons *self)
236 GdkPixbuf *unpixbuf = NULL;
237 GdkPixbuf *pixbuf = NULL;
238 GError *error = NULL;
239 IrrecoData *irreco_data = NULL;
240 IrrecoThemeManager *manager = NULL;
241 gint i=0;
243 IRRECO_ENTER
245 irreco_data = self->irreco_data;
246 manager = irreco_data->theme_manager;
248 switch (self->loader_state) {
249 case LOADER_STATE_INIT: {
250 GtkTreeIter iter;
251 /*irreco_theme_creator_backgrounds_set_banner(self, _("Loading ..."), 0.5);*/
252 self->loader_state = LOADER_STATE_LOOP;
253 self->loader_iter = gtk_tree_iter_copy(&iter);
256 case LOADER_STATE_LOOP: {
257 gint theme_button_count;
258 /*gfloat banner;*/
259 const gchar *image_name;
260 IrrecoTheme *theme;
261 GtkTreeIter iter;
263 irreco_string_table_get(manager->themes,
264 self->theme->name->str,
265 (gpointer *) &theme);
267 theme_button_count = irreco_string_table_lenght(theme->buttons);
269 if (theme_button_count > 0) {
270 while(theme_button_count > 0) {
272 IrrecoThemeButton *button_image;
274 irreco_string_table_index(theme->buttons, i,
275 &image_name,
276 (gpointer *)
277 &button_image);
280 unpixbuf = gdk_pixbuf_new_from_file(
281 button_image->image_up->str,
282 &error);
283 if (irreco_gerror_check_print(&error)) {
284 IRRECO_RETURN
286 pixbuf = gdk_pixbuf_new_from_file(
287 button_image->image_down->str,
288 &error);
289 if (irreco_gerror_check_print(&error)) {
290 IRRECO_RETURN
293 gtk_list_store_append(self->store_buttons, &iter);
295 gtk_list_store_set(self->store_buttons, &iter,
296 DATA_COL, button_image,
297 PIXBUF_COL, unpixbuf,
298 PIXBUF_COL, pixbuf,
299 TEXT_COL, image_name, -1);
301 theme_button_count -=1;
302 i++;
305 } else {
309 /*irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
310 1.0);*/
311 self->loader_state = LOADER_STATE_END;
312 IRRECO_RETURN
315 case LOADER_STATE_END:
316 if (self->loader_iter != NULL) {
317 gtk_tree_iter_free(self->loader_iter);
320 if (unpixbuf != NULL) g_object_unref(G_OBJECT(unpixbuf));
321 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf));
322 /*irreco_theme_manager_dlg_hide_banner(self);
323 irreco_theme_manager_dlg_loader_stop(self);*/
327 IRRECO_RETURN