Added button image data transmission from
[irreco.git] / irreco / src / core / irreco_theme_creator_buttons.c
blobb5770620498929a3f1afdb0b203c28cf07607a6f
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 UNPIXBUF_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);
69 static void _image_selection_changed(GtkTreeSelection * selection,
70 IrrecoThemeCreatorButtons *self);
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
75 /* Construction & Destruction */
76 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
78 /**
79 * @name Construction & Destruction
80 * @{
86 G_DEFINE_TYPE (IrrecoThemeCreatorButtons, irreco_theme_creator_buttons,
87 IRRECO_TYPE_INTERNAL_WIDGET)
89 static void
90 irreco_theme_creator_buttons_finalize (GObject *object)
92 /* TODO: Add deinitalization code here */
93 IRRECO_ENTER
94 G_OBJECT_CLASS (
95 irreco_theme_creator_buttons_parent_class)->finalize (object);
96 IRRECO_RETURN
99 static void
100 irreco_theme_creator_buttons_class_init (IrrecoThemeCreatorButtonsClass *klass)
102 GObjectClass *object_class;
103 IRRECO_ENTER
105 object_class = G_OBJECT_CLASS (klass);
106 object_class->finalize = irreco_theme_creator_buttons_finalize;
107 IRRECO_RETURN
110 static void
111 irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons *self)
113 /* TODO: Add initialization code here */
115 IRRECO_ENTER
117 gtk_box_set_spacing(GTK_BOX(self), 1);
119 /*BUTTONS*/
120 self->scroll_buttons = gtk_scrolled_window_new(NULL, NULL);
121 self->store_buttons = gtk_list_store_new(N_COLUMNS, G_TYPE_POINTER,
122 G_TYPE_STRING, GDK_TYPE_PIXBUF,
123 GDK_TYPE_PIXBUF);
124 self->view_buttons = gtk_tree_view_new();
125 gtk_box_pack_start_defaults(GTK_BOX(self), self->scroll_buttons);
128 /*BUTTONS COLUMNS*/
130 gtk_tree_view_set_model(GTK_TREE_VIEW(self->view_buttons),
131 GTK_TREE_MODEL(self->store_buttons));
132 g_object_unref(self->store_buttons);
134 /* Create pixbuf column. */
135 self->renderer_buttons = gtk_cell_renderer_pixbuf_new();
136 self->column_buttons = gtk_tree_view_column_new_with_attributes(
137 "Unpressed ", self->renderer_buttons,
138 "pixbuf", UNPIXBUF_COL, NULL);
139 gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons),
140 self->column_buttons);
142 self->renderer_buttons = gtk_cell_renderer_pixbuf_new();
143 self->column_buttons = gtk_tree_view_column_new_with_attributes(
144 "Pressed ",
145 self->renderer_buttons,
146 "pixbuf", PIXBUF_COL, NULL);
147 gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons),
148 self->column_buttons);
150 /* Create text column. */
151 self->renderer_buttons = gtk_cell_renderer_text_new();
152 self->column_buttons = gtk_tree_view_column_new_with_attributes(
153 "Name ",
154 self->renderer_buttons,
155 "text", TEXT_COL, NULL);
156 gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons),
157 self->column_buttons);
158 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self->view_buttons),
159 TRUE);
162 /* Scroll_buttons*/
164 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->scroll_buttons),
165 GTK_POLICY_AUTOMATIC,
166 GTK_POLICY_AUTOMATIC);
167 gtk_container_add(GTK_CONTAINER(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);
174 /* Signal handlers. */
175 g_signal_connect(G_OBJECT(self->tree_selection),
176 "changed",
177 G_CALLBACK(_image_selection_changed),
178 self);
181 IRRECO_RETURN
185 GtkWidget* irreco_theme_creator_buttons_new(GtkWindow *parent,
186 IrrecoData *irreco_data,
187 IrrecoTheme * irreco_theme)
189 IrrecoThemeCreatorButtons *self;
190 IRRECO_ENTER
192 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_BUTTONS,
193 "irreco-data", irreco_data,
194 NULL);
196 irreco_theme_creator_buttons_set_parent_window(self, parent);
197 self->parent_window = GTK_WINDOW(parent);
198 self->irreco_data = irreco_data;
199 self->theme = irreco_theme;
200 if (irreco_theme !=NULL) {
201 irreco_theme_creator_buttons_image_append(self);
203 IRRECO_RETURN_PTR(GTK_WIDGET(self));
206 /** @} */
210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
211 /* Private Functions */
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
215 * @name Private Functions
216 * @{
220 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
221 /* Public Functions */
222 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
225 * @name Public Functions
226 * @{
230 * Set parent window for popup dialogs.
232 void
233 irreco_theme_creator_buttons_set_parent_window(IrrecoThemeCreatorButtons *self,
234 GtkWindow *parent)
236 IRRECO_ENTER
237 self->parent_window = parent;
238 IRRECO_RETURN
241 void irreco_theme_creator_buttons_image_append(IrrecoThemeCreatorButtons *self)
244 GdkPixbuf *unpixbuf = NULL;
245 GdkPixbuf *pixbuf = NULL;
246 GError *error = NULL;
247 IrrecoData *irreco_data = NULL;
248 IrrecoThemeManager *manager = NULL;
249 gint i=0;
251 IRRECO_ENTER
253 irreco_data = self->irreco_data;
254 manager = irreco_data->theme_manager;
256 switch (self->loader_state) {
257 case LOADER_STATE_INIT: {
258 GtkTreeIter iter;
259 /*irreco_theme_creator_backgrounds_set_banner(self, _("Loading ..."), 0.5);*/
260 self->loader_state = LOADER_STATE_LOOP;
261 self->loader_iter = gtk_tree_iter_copy(&iter);
264 case LOADER_STATE_LOOP: {
265 gint theme_button_count;
266 /*gfloat banner;*/
267 const gchar *image_name;
268 IrrecoTheme *theme;
269 GtkTreeIter iter;
271 irreco_string_table_get(manager->themes,
272 self->theme->name->str,
273 (gpointer *) &theme);
275 theme_button_count = irreco_string_table_lenght(theme->buttons);
277 if (theme_button_count > 0) {
278 while(theme_button_count > 0) {
280 IrrecoThemeButton *button_image;
282 irreco_string_table_index(theme->buttons, i,
283 &image_name,
284 (gpointer *)
285 &button_image);
288 unpixbuf = gdk_pixbuf_new_from_file(
289 button_image->image_up->str,
290 &error);
291 if (irreco_gerror_check_print(&error)) {
292 IRRECO_RETURN
294 pixbuf = gdk_pixbuf_new_from_file(
295 button_image->image_down->str,
296 &error);
297 if (irreco_gerror_check_print(&error)) {
298 IRRECO_RETURN
301 gtk_list_store_append(self->store_buttons, &iter);
303 gtk_list_store_set(self->store_buttons, &iter,
304 DATA_COL, button_image,
305 UNPIXBUF_COL, unpixbuf,
306 PIXBUF_COL, pixbuf,
307 TEXT_COL, image_name, -1);
309 theme_button_count -=1;
310 i++;
313 } else {
317 /*irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
318 1.0);*/
319 self->loader_state = LOADER_STATE_END;
320 IRRECO_RETURN
323 case LOADER_STATE_END:
324 if (self->loader_iter != NULL) {
325 gtk_tree_iter_free(self->loader_iter);
328 if (unpixbuf != NULL) g_object_unref(G_OBJECT(unpixbuf));
329 if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf));
330 /*irreco_theme_manager_dlg_hide_banner(self);
331 irreco_theme_manager_dlg_loader_stop(self);*/
335 IRRECO_RETURN
339 static void _image_selection_changed(GtkTreeSelection * selection,
340 IrrecoThemeCreatorButtons *self)
342 GtkTreeIter iter;
343 GtkTreeModel *model = NULL;
344 IRRECO_ENTER
346 /* Get currect selection, if set. */
347 selection = gtk_tree_view_get_selection(
348 GTK_TREE_VIEW(self->view_buttons));
349 if (gtk_tree_selection_get_selected(self->tree_selection,
350 &model, &iter)) {
351 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
352 DATA_COL, &self->current_button,
353 -1);
356 IRRECO_RETURN
362 IrrecoThemeButton
363 *irreco_theme_creator_buttons_get_selected_button(IrrecoThemeCreatorButtons
364 *self)
367 IRRECO_ENTER
371 IRRECO_RETURN_PTR(GTK_WIDGET(self->current_button));