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
;
101 irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons
*self
)
103 /* TODO: Add initialization code here */
107 gtk_box_set_spacing(GTK_BOX(self
), 1);
110 self
->scroll_buttons
= gtk_scrolled_window_new(NULL
, NULL
);
111 self
->store_buttons
= gtk_list_store_new(N_COLUMNS
, G_TYPE_POINTER
,
112 G_TYPE_STRING
, GDK_TYPE_PIXBUF
,
114 self
->view_buttons
= gtk_tree_view_new();
115 gtk_box_pack_start_defaults(GTK_BOX(self
), self
->scroll_buttons
);
120 gtk_tree_view_set_model(GTK_TREE_VIEW(self
->view_buttons
),
121 GTK_TREE_MODEL(self
->store_buttons
));
122 g_object_unref(self
->store_buttons
);
124 /* Create pixbuf column. */
125 self
->renderer_buttons
= gtk_cell_renderer_pixbuf_new();
126 self
->column_buttons
= gtk_tree_view_column_new_with_attributes(
127 "Unpressed ", self
->renderer_buttons
,
128 "pixbuf", UNPIXBUF_COL
, NULL
);
129 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_buttons
),
130 self
->column_buttons
);
132 self
->renderer_buttons
= gtk_cell_renderer_pixbuf_new();
133 self
->column_buttons
= gtk_tree_view_column_new_with_attributes(
135 self
->renderer_buttons
,
136 "pixbuf", PIXBUF_COL
, NULL
);
137 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_buttons
),
138 self
->column_buttons
);
140 /* Create text column. */
141 self
->renderer_buttons
= gtk_cell_renderer_text_new();
142 self
->column_buttons
= gtk_tree_view_column_new_with_attributes(
144 self
->renderer_buttons
,
145 "text", TEXT_COL
, NULL
);
146 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_buttons
),
147 self
->column_buttons
);
148 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self
->view_buttons
),
153 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self
->scroll_buttons
),
154 GTK_POLICY_AUTOMATIC
,
155 GTK_POLICY_AUTOMATIC
);
156 gtk_container_add(GTK_CONTAINER(self
->scroll_buttons
),
158 self
->tree_selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(
159 self
->view_buttons
));
160 gtk_tree_selection_set_mode(self
->tree_selection
, GTK_SELECTION_SINGLE
);
163 /* Signal handlers. */
164 g_signal_connect(G_OBJECT(self
->tree_selection
),
166 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
200 static void _image_selection_changed(GtkTreeSelection
* selection
,
201 IrrecoThemeCreatorButtons
*self
)
204 GtkTreeModel
*model
= NULL
;
205 GtkTreePath
*path
= NULL
;
206 gint
*path_indices
= NULL
;
209 /* Get currect selection, if set. */
210 selection
= gtk_tree_view_get_selection(
211 GTK_TREE_VIEW(self
->view_buttons
));
212 if (gtk_tree_selection_get_selected(self
->tree_selection
,
214 path
= gtk_tree_model_get_path(model
, &iter
);
215 path_indices
= gtk_tree_path_get_indices(path
);
216 self
->sel_index
= path_indices
[0];
217 gtk_tree_path_free(path
);
219 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
,
220 DATA_COL
, &self
->current_button
,
223 self
->current_button
= NULL
;
231 irreco_theme_creator_buttons_get_iter(IrrecoThemeCreatorButtons
*self
,
232 gint index
, GtkTreeIter
* iter
)
239 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(
240 self
->view_buttons
));
241 path
= gtk_tree_path_new_from_indices(index
, -1);
242 rvalue
= gtk_tree_model_get_iter(model
, iter
, path
);
243 gtk_tree_path_free(path
);
244 IRRECO_RETURN_INT(rvalue
);
248 irreco_theme_creator_buttons_set_selection(IrrecoThemeCreatorButtons
254 if (irreco_theme_creator_buttons_get_iter(self
, index
, &iter
)) {
255 gtk_tree_selection_select_iter(self
->tree_selection
, &iter
);
256 IRRECO_RETURN_BOOL(TRUE
);
258 IRRECO_RETURN_BOOL(FALSE
);
260 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
261 /* Public Functions */
262 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
265 * @name Public Functions
270 * Set parent window for popup dialogs.
273 irreco_theme_creator_buttons_set_parent_window(IrrecoThemeCreatorButtons
*self
,
277 self
->parent_window
= parent
;
282 irreco_theme_creator_buttons_refresh(IrrecoThemeCreatorButtons
*self
)
285 GdkPixbuf
*unpixbuf
= NULL
;
286 GdkPixbuf
*pixbuf
= NULL
;
287 GError
*error
= NULL
;
288 IrrecoData
*irreco_data
= NULL
;
289 IrrecoThemeManager
*manager
= NULL
;
294 gtk_list_store_clear(self
->store_buttons
);
295 irreco_data
= self
->irreco_data
;
296 manager
= irreco_data
->theme_manager
;
301 IRRECO_STRING_TABLE_FOREACH_DATA(theme
->buttons
,
302 IrrecoThemeButton
*, button
)
304 irreco_theme_button_print(button
);
305 unpixbuf
= gdk_pixbuf_new_from_file_at_scale(
306 button
->image_up
->str
,
307 IRRECO_BUTTON_PREVIEW_WIDHT
,
308 IRRECO_BUTTON_PREVIEW_HEIGHT
,
309 GDK_INTERP_NEAREST
, &error
);
312 if (irreco_gerror_check_print(&error
)) {
316 pixbuf
= gdk_pixbuf_new_from_file_at_scale(
317 button
->image_down
->str
,
318 IRRECO_BUTTON_PREVIEW_WIDHT
,
319 IRRECO_BUTTON_PREVIEW_HEIGHT
,
320 GDK_INTERP_NEAREST
, &error
);
321 if (irreco_gerror_check_print(&error
)) {
325 gtk_list_store_append(self
->store_buttons
, &iter
);
327 gtk_list_store_set(self
->store_buttons
, &iter
,
329 UNPIXBUF_COL
, unpixbuf
,
332 button
->name
->str
, -1);
333 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(
334 self
->view_buttons
));
335 IRRECO_STRING_TABLE_FOREACH_END
338 if (unpixbuf
!= NULL
) g_object_unref(G_OBJECT(unpixbuf
));
339 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
345 *irreco_theme_creator_buttons_get_selected_button(IrrecoThemeCreatorButtons
349 IRRECO_RETURN_PTR(self
->current_button
);
353 irreco_theme_creator_buttons_remove_selected(IrrecoThemeCreatorButtons
*self
)
359 _image_selection_changed(self
->tree_selection
, self
);
360 if ((index
= self
->sel_index
) == -1
361 || irreco_theme_creator_buttons_get_iter(self
, index
, &iter
) == FALSE
) {
362 IRRECO_RETURN_BOOL(FALSE
);
364 irreco_theme_creator_buttons_set_selection(self
, index
- 1)
365 || irreco_theme_creator_buttons_set_selection(self
, index
+ 1);
367 gtk_list_store_remove(self
->store_buttons
, &iter
);
368 IRRECO_RETURN_BOOL(TRUE
);