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
);
73 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
74 /* Construction & Destruction */
75 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
78 * @name Construction & Destruction
85 G_DEFINE_TYPE (IrrecoThemeCreatorButtons
, irreco_theme_creator_buttons
,
86 IRRECO_TYPE_INTERNAL_WIDGET
)
89 irreco_theme_creator_buttons_finalize (GObject
*object
)
91 /* TODO: Add deinitalization code here */
94 irreco_theme_creator_buttons_parent_class
)->finalize (object
);
99 irreco_theme_creator_buttons_class_init (IrrecoThemeCreatorButtonsClass
*klass
)
101 GObjectClass
*object_class
;
104 object_class
= G_OBJECT_CLASS (klass
);
105 object_class
->finalize
= irreco_theme_creator_buttons_finalize
;
110 irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons
*self
)
112 /* TODO: Add initialization code here */
116 gtk_box_set_spacing(GTK_BOX(self
), 1);
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
,
123 self
->view_buttons
= gtk_tree_view_new();
124 gtk_box_pack_start_defaults(GTK_BOX(self
), self
->scroll_buttons
);
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(
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(
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
),
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
),
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
);
177 GtkWidget
* irreco_theme_creator_buttons_new(GtkWindow
*parent
,
178 IrrecoData
*irreco_data
,
179 IrrecoTheme
* irreco_theme
)
181 IrrecoThemeCreatorButtons
*self
;
184 self
= g_object_new(IRRECO_TYPE_THEME_CREATOR_BUTTONS
,
185 "irreco-data", irreco_data
,
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
));
202 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
203 /* Private Functions */
204 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
207 * @name Private Functions
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
213 /* Public Functions */
214 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
217 * @name Public Functions
222 * Set parent window for popup dialogs.
225 irreco_theme_creator_buttons_set_parent_window(IrrecoThemeCreatorButtons
*self
,
229 self
->parent_window
= parent
;
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
;
245 irreco_data
= self
->irreco_data
;
246 manager
= irreco_data
->theme_manager
;
248 switch (self
->loader_state
) {
249 case LOADER_STATE_INIT
: {
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
;
259 const gchar
*image_name
;
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
,
280 unpixbuf
= gdk_pixbuf_new_from_file(
281 button_image
->image_up
->str
,
283 if (irreco_gerror_check_print(&error
)) {
286 pixbuf
= gdk_pixbuf_new_from_file(
287 button_image
->image_down
->str
,
289 if (irreco_gerror_check_print(&error
)) {
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
,
299 TEXT_COL
, image_name
, -1);
301 theme_button_count
-=1;
309 /*irreco_theme_manager_dlg_set_banner(self, _("Loading ..."),
311 self
->loader_state
= LOADER_STATE_END
;
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);*/