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_HEIGHT / 5)
44 #define IRRECO_BUTTON_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 5)
54 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
56 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
57 static void _image_selection_changed(GtkTreeSelection
* selection
,
58 IrrecoThemeCreatorButtons
*self
);
61 irreco_theme_creator_buttons_get_iter(IrrecoThemeCreatorButtons
*self
,
62 gint index
, GtkTreeIter
* iter
);
64 irreco_theme_creator_buttons_set_selection(IrrecoThemeCreatorButtons
66 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
67 /* Construction & Destruction */
68 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
71 * @name Construction & Destruction
75 G_DEFINE_TYPE (IrrecoThemeCreatorButtons
, irreco_theme_creator_buttons
,
76 IRRECO_TYPE_INTERNAL_WIDGET
)
79 irreco_theme_creator_buttons_finalize (GObject
*object
)
81 /* TODO: Add deinitalization code here */
84 irreco_theme_creator_buttons_parent_class
)->finalize (object
);
89 irreco_theme_creator_buttons_class_init (IrrecoThemeCreatorButtonsClass
*klass
)
91 GObjectClass
*object_class
;
94 object_class
= G_OBJECT_CLASS (klass
);
95 object_class
->finalize
= irreco_theme_creator_buttons_finalize
;
100 irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons
*self
)
102 /* TODO: Add initialization code here */
106 gtk_box_set_spacing(GTK_BOX(self
), 1);
109 self
->scroll_buttons
= gtk_scrolled_window_new(NULL
, NULL
);
110 self
->store_buttons
= gtk_list_store_new(N_COLUMNS
, G_TYPE_POINTER
,
111 G_TYPE_STRING
, GDK_TYPE_PIXBUF
,
113 self
->view_buttons
= gtk_tree_view_new();
114 gtk_box_pack_start_defaults(GTK_BOX(self
), self
->scroll_buttons
);
119 gtk_tree_view_set_model(GTK_TREE_VIEW(self
->view_buttons
),
120 GTK_TREE_MODEL(self
->store_buttons
));
121 g_object_unref(self
->store_buttons
);
123 /* Create pixbuf column. */
124 self
->renderer_buttons
= gtk_cell_renderer_pixbuf_new();
125 self
->column_buttons
= gtk_tree_view_column_new_with_attributes(
126 "Unpressed ", self
->renderer_buttons
,
127 "pixbuf", UNPIXBUF_COL
, NULL
);
128 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_buttons
),
129 self
->column_buttons
);
131 self
->renderer_buttons
= gtk_cell_renderer_pixbuf_new();
132 self
->column_buttons
= gtk_tree_view_column_new_with_attributes(
134 self
->renderer_buttons
,
135 "pixbuf", PIXBUF_COL
, NULL
);
136 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_buttons
),
137 self
->column_buttons
);
139 /* Create text column. */
140 self
->renderer_buttons
= gtk_cell_renderer_text_new();
141 self
->column_buttons
= gtk_tree_view_column_new_with_attributes(
143 self
->renderer_buttons
,
144 "text", TEXT_COL
, NULL
);
145 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_buttons
),
146 self
->column_buttons
);
147 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self
->view_buttons
),
152 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self
->scroll_buttons
),
153 GTK_POLICY_AUTOMATIC
,
154 GTK_POLICY_AUTOMATIC
);
155 gtk_container_add(GTK_CONTAINER(self
->scroll_buttons
),
157 self
->tree_selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(
158 self
->view_buttons
));
159 gtk_tree_selection_set_mode(self
->tree_selection
, GTK_SELECTION_SINGLE
);
162 /* Signal handlers. */
163 g_signal_connect(G_OBJECT(self
->tree_selection
),
165 G_CALLBACK(_image_selection_changed
),
171 GtkWidget
* irreco_theme_creator_buttons_new(GtkWindow
*parent
,
172 IrrecoData
*irreco_data
,
173 IrrecoTheme
* irreco_theme
)
175 IrrecoThemeCreatorButtons
*self
;
178 self
= g_object_new(IRRECO_TYPE_THEME_CREATOR_BUTTONS
,
179 "irreco-data", irreco_data
,
182 irreco_theme_creator_buttons_set_parent_window(self
, parent
);
183 self
->parent_window
= GTK_WINDOW(parent
);
184 self
->irreco_data
= irreco_data
;
185 self
->theme
= irreco_theme
;
186 irreco_theme_creator_buttons_refresh(self
);
187 IRRECO_RETURN_PTR(GTK_WIDGET(self
));
191 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
192 /* Private Functions */
193 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
196 * @name Private Functions
199 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
200 /* Public Functions */
201 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
204 * @name Public Functions
209 * Set parent window for popup dialogs.
212 irreco_theme_creator_buttons_set_parent_window(IrrecoThemeCreatorButtons
*self
,
216 self
->parent_window
= parent
;
221 irreco_theme_creator_buttons_refresh(IrrecoThemeCreatorButtons
*self
)
224 GdkPixbuf
*unpixbuf
= NULL
;
225 GdkPixbuf
*pixbuf
= NULL
;
226 GError
*error
= NULL
;
227 IrrecoData
*irreco_data
= NULL
;
228 IrrecoThemeManager
*manager
= NULL
;
230 gint theme_button_count
;
231 const gchar
*image_name
;
236 gtk_list_store_clear(self
->store_buttons
);
237 irreco_data
= self
->irreco_data
;
238 manager
= irreco_data
->theme_manager
;
242 theme_button_count
= irreco_string_table_lenght(theme
->buttons
);
244 if (theme_button_count
> 0) {
245 while(theme_button_count
> 0) {
247 IrrecoThemeButton
*button_image
;
249 irreco_string_table_index(theme
->buttons
, i
,
253 /*unpixbuf = gdk_pixbuf_new_from_file(
254 button_image->image_up->str,
257 unpixbuf
= gdk_pixbuf_new_from_file_at_scale(
258 button_image
->image_up
->str
,
259 IRRECO_BUTTON_PREVIEW_WIDHT
,
260 IRRECO_BUTTON_PREVIEW_HEIGHT
,
261 GDK_INTERP_NEAREST
, &error
);
264 if (irreco_gerror_check_print(&error
)) {
267 /*pixbuf = gdk_pixbuf_new_from_file(
268 button_image->image_down->str,
270 pixbuf
= gdk_pixbuf_new_from_file_at_scale(
271 button_image
->image_down
->str
,
272 IRRECO_BUTTON_PREVIEW_WIDHT
,
273 IRRECO_BUTTON_PREVIEW_HEIGHT
,
274 GDK_INTERP_NEAREST
, &error
);
275 if (irreco_gerror_check_print(&error
)) {
279 gtk_list_store_append(self
->store_buttons
, &iter
);
281 gtk_list_store_set(self
->store_buttons
, &iter
,
282 DATA_COL
, button_image
,
283 UNPIXBUF_COL
, unpixbuf
,
286 button_image
->name
->str
, -1);
288 theme_button_count
-=1;
296 if (unpixbuf
!= NULL
) g_object_unref(G_OBJECT(unpixbuf
));
297 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
303 static void _image_selection_changed(GtkTreeSelection
* selection
,
304 IrrecoThemeCreatorButtons
*self
)
307 GtkTreeModel
*model
= NULL
;
310 /* Get currect selection, if set. */
311 selection
= gtk_tree_view_get_selection(
312 GTK_TREE_VIEW(self
->view_buttons
));
313 if (gtk_tree_selection_get_selected(self
->tree_selection
,
315 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
,
316 DATA_COL
, &self
->current_button
,
325 *irreco_theme_creator_buttons_get_selected_button(IrrecoThemeCreatorButtons
329 IRRECO_RETURN_PTR(self
->current_button
);
334 irreco_theme_creator_buttons_remove_selected(IrrecoThemeCreatorButtons
*self
)
341 if ((index
= self
->sel_index
) == -1
342 || irreco_theme_creator_buttons_get_iter(self
, index
, &iter
) == FALSE
) {
343 IRRECO_RETURN_BOOL(FALSE
);
346 irreco_theme_creator_buttons_set_selection(self
, index
- 1)
347 || irreco_theme_creator_buttons_set_selection(self
, index
+ 1);
349 gtk_list_store_remove(self
->store_buttons
, &iter
);
350 IRRECO_RETURN_BOOL(TRUE
);
354 irreco_theme_creator_buttons_get_iter(IrrecoThemeCreatorButtons
*self
,
355 gint index
, GtkTreeIter
* iter
)
362 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(
363 self
->view_buttons
));
364 path
= gtk_tree_path_new_from_indices(index
, -1);
365 rvalue
= gtk_tree_model_get_iter(model
, iter
, path
);
366 gtk_tree_path_free(path
);
367 IRRECO_RETURN_INT(rvalue
);
372 irreco_theme_creator_buttons_set_selection(IrrecoThemeCreatorButtons
378 if (irreco_theme_creator_buttons_get_iter(self
, index
, &iter
)) {
379 gtk_tree_selection_select_iter(self
->tree_selection
, &iter
);
380 IRRECO_RETURN_BOOL(TRUE
);
382 IRRECO_RETURN_BOOL(FALSE
);