1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * irreco - Ir Remote Control
4 * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com)
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"
26 * @addtogroup IrrecoThemeCreatorBackgrounds
29 * User interface for IrrecoThemeCreatorDlgBackgrounds.
36 * Source file of @ref IrrecoThemeCreatorBackgrounds.
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 #define IRRECO_BUTTON_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 3)
44 #define IRRECO_BUTTON_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 3)
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
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 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
79 * @name Construction & Destruction
86 G_DEFINE_TYPE (IrrecoThemeCreatorButtons
, irreco_theme_creator_buttons
,
87 IRRECO_TYPE_INTERNAL_WIDGET
)
90 irreco_theme_creator_buttons_finalize (GObject
*object
)
92 /* TODO: Add deinitalization code here */
95 irreco_theme_creator_buttons_parent_class
)->finalize (object
);
100 irreco_theme_creator_buttons_class_init (IrrecoThemeCreatorButtonsClass
*klass
)
102 GObjectClass
*object_class
;
105 object_class
= G_OBJECT_CLASS (klass
);
106 object_class
->finalize
= irreco_theme_creator_buttons_finalize
;
111 irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons
*self
)
113 /* TODO: Add initialization code here */
117 gtk_box_set_spacing(GTK_BOX(self
), 1);
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
,
124 self
->view_buttons
= gtk_tree_view_new();
125 gtk_box_pack_start_defaults(GTK_BOX(self
), self
->scroll_buttons
);
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(
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(
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
),
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
),
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
),
177 G_CALLBACK(_image_selection_changed
),
185 GtkWidget
* irreco_theme_creator_buttons_new(GtkWindow
*parent
,
186 IrrecoData
*irreco_data
,
187 IrrecoTheme
* irreco_theme
)
189 IrrecoThemeCreatorButtons
*self
;
192 self
= g_object_new(IRRECO_TYPE_THEME_CREATOR_BUTTONS
,
193 "irreco-data", irreco_data
,
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
));
210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
211 /* Private Functions */
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
215 * @name Private Functions
220 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
221 /* Public Functions */
222 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
225 * @name Public Functions
230 * Set parent window for popup dialogs.
233 irreco_theme_creator_buttons_set_parent_window(IrrecoThemeCreatorButtons
*self
,
237 self
->parent_window
= parent
;
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
;
253 irreco_data
= self
->irreco_data
;
254 manager
= irreco_data
->theme_manager
;
256 switch (self
->loader_state
) {
257 case LOADER_STATE_INIT
: {
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
;
267 const gchar
*image_name
;
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
,
288 unpixbuf
= gdk_pixbuf_new_from_file(
289 button_image
->image_up
->str
,
291 if (irreco_gerror_check_print(&error
)) {
294 pixbuf
= gdk_pixbuf_new_from_file(
295 button_image
->image_down
->str
,
297 if (irreco_gerror_check_print(&error
)) {
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
,
307 TEXT_COL
, image_name
, -1);
309 theme_button_count
-=1;
317 /*irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
319 self
->loader_state
= LOADER_STATE_END
;
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);*/
339 static void _image_selection_changed(GtkTreeSelection
* selection
,
340 IrrecoThemeCreatorButtons
*self
)
343 GtkTreeModel
*model
= NULL
;
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
,
351 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
,
352 DATA_COL
, &self
->current_button
,
363 *irreco_theme_creator_buttons_get_selected_button(IrrecoThemeCreatorButtons
371 IRRECO_RETURN_PTR(GTK_WIDGET(self
->current_button
));