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_backgrounds.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_backgrounds.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_backgrounds.h"
21 #include "irreco_theme_creator_dlg.h"
22 #include "irreco_listbox.h"
25 * @addtogroup IrrecoThemeCreatorBackgrounds
28 * User interface for IrrecoThemeCreatorDlgBackgrounds.
35 * Source file of @ref IrrecoThemeCreatorBackgrounds.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 #define IRRECO_BACKGROUNDS_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 4.5)
43 #define IRRECO_BACKGROUNDS_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 4.5)
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
65 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 static void _image_selection_changed(GtkTreeSelection
* selection
,
67 IrrecoThemeCreatorBackgrounds
*self
);
70 _get_selection(IrrecoThemeCreatorBackgrounds
*self
, gint
*index
, gchar
**label
,
73 irreco_theme_creator_backgrounds_get_iter(IrrecoThemeCreatorBackgrounds
*self
,
74 gint index
, GtkTreeIter
* iter
);
76 irreco_theme_creator_backgrounds_set_selection(IrrecoThemeCreatorBackgrounds
80 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
81 /* Construction & Destruction */
82 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
85 * @name Construction & Destruction
89 G_DEFINE_TYPE (IrrecoThemeCreatorBackgrounds
, irreco_theme_creator_backgrounds
,
90 IRRECO_TYPE_INTERNAL_WIDGET
)
94 irreco_theme_creator_backgrounds_finalize (GObject
*object
)
96 /* TODO: Add deinitalization code here */
99 irreco_theme_creator_backgrounds_parent_class
)->finalize
106 irreco_theme_creator_backgrounds_class_init(
107 IrrecoThemeCreatorBackgroundsClass
*klass
)
109 GObjectClass
*object_class
;
112 object_class
= G_OBJECT_CLASS (klass
);
113 object_class
->finalize
= irreco_theme_creator_backgrounds_finalize
;
118 irreco_theme_creator_backgrounds_init (IrrecoThemeCreatorBackgrounds
*self
)
120 /* TODO: Add initialization code here */
122 /*Backgrounds widgets*/
126 gtk_box_set_spacing(GTK_BOX(self
), 1);
130 self
->scroll_backgrounds
= gtk_scrolled_window_new(NULL
, NULL
);
131 self
->store_backgrounds
= gtk_list_store_new(N_COLUMNS
, G_TYPE_POINTER
,
134 self
->view_backgrounds
= gtk_tree_view_new();
136 gtk_box_pack_start_defaults(GTK_BOX(self
), self
->scroll_backgrounds
);
138 /*BACKGROUNDS COLUMNS*/
139 gtk_tree_view_set_model(GTK_TREE_VIEW(self
->view_backgrounds
),
140 GTK_TREE_MODEL(self
->store_backgrounds
));
141 g_object_unref(self
->store_backgrounds
);
143 /* Create pixbuf column. */
144 self
->renderer_backgrounds
= gtk_cell_renderer_pixbuf_new();
145 self
->column_backgrounds
= gtk_tree_view_column_new_with_attributes(
147 self
->renderer_backgrounds
,
148 "pixbuf", PIXBUF_COL
, NULL
);
149 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_backgrounds
),
150 self
->column_backgrounds
);
152 /* Create text column. */
153 self
->renderer_backgrounds
= gtk_cell_renderer_text_new();
154 self
->column_backgrounds
= gtk_tree_view_column_new_with_attributes(
156 self
->renderer_backgrounds
,
157 "text", TEXT_COL
, NULL
);
158 gtk_tree_view_append_column(GTK_TREE_VIEW(self
->view_backgrounds
),
159 self
->column_backgrounds
);
160 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(self
->view_backgrounds
),
164 /* Scroll_backgrounds*/
166 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
167 self
->scroll_backgrounds
),
168 GTK_POLICY_AUTOMATIC
,
169 GTK_POLICY_AUTOMATIC
);
170 gtk_container_add(GTK_CONTAINER(self
->scroll_backgrounds
),
171 self
->view_backgrounds
);
173 self
->tree_selection
= gtk_tree_view_get_selection(
174 GTK_TREE_VIEW(self
->view_backgrounds
));
175 gtk_tree_selection_set_mode(self
->tree_selection
,
176 GTK_SELECTION_SINGLE
);
178 /* Signal handlers. */
179 g_signal_connect(G_OBJECT(self
->tree_selection
),
181 G_CALLBACK(_image_selection_changed
),
187 irreco_theme_creator_backgrounds_new(GtkWindow
*parent
, IrrecoData
*irreco_data
,
188 IrrecoTheme
* irreco_theme
)
190 IrrecoThemeCreatorBackgrounds
*self
;
193 self
= g_object_new(IRRECO_TYPE_THEME_CREATOR_BACKGROUNDS
,
194 "irreco-data", irreco_data
, NULL
);
196 irreco_theme_creator_backgrounds_set_parent_window(self
, parent
);
197 self
->parent_window
= GTK_WINDOW(parent
);
198 self
->irreco_data
= irreco_data
;
199 self
->theme
= irreco_theme
;
201 irreco_theme_creator_backgrounds_refresh(self
);
203 IRRECO_RETURN_PTR(GTK_WIDGET(self
));
208 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
209 /* Private Functions */
210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
213 * @name Private Functions
219 *Get information on the background picture
222 static void _image_selection_changed(GtkTreeSelection
* selection
,
223 IrrecoThemeCreatorBackgrounds
*self
)
226 GtkTreeModel
*model
= NULL
;
227 GtkTreePath
*path
= NULL
;
228 gint
*path_indices
= NULL
;
231 /* Get currect selection, if set. */
232 selection
= gtk_tree_view_get_selection(
233 GTK_TREE_VIEW(self
->view_backgrounds
));
234 if (gtk_tree_selection_get_selected(self
->tree_selection
,
237 path
= gtk_tree_model_get_path(model
, &iter
);
238 path_indices
= gtk_tree_path_get_indices(path
);
239 self
->sel_index
= path_indices
[0];
240 gtk_tree_path_free(path
);
242 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
,
243 DATA_COL
, &self
->current_bg
,
246 self
->current_bg
= NULL
;
253 irreco_theme_creator_backgrounds_get_iter(IrrecoThemeCreatorBackgrounds
*self
,
254 gint index
, GtkTreeIter
* iter
)
261 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(
262 self
->view_backgrounds
));
263 path
= gtk_tree_path_new_from_indices(index
, -1);
264 rvalue
= gtk_tree_model_get_iter(model
, iter
, path
);
265 gtk_tree_path_free(path
);
266 IRRECO_RETURN_INT(rvalue
);
270 irreco_theme_creator_backgrounds_set_selection(IrrecoThemeCreatorBackgrounds
276 if (irreco_theme_creator_backgrounds_get_iter(self
, index
, &iter
)) {
277 gtk_tree_selection_select_iter(self
->tree_selection
, &iter
);
278 IRRECO_RETURN_BOOL(TRUE
);
280 IRRECO_RETURN_BOOL(FALSE
);
284 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
285 /* Public Functions */
286 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
289 * @name Public Functions
294 * Set parent window for popup dialogs.
297 irreco_theme_creator_backgrounds_set_parent_window(
298 IrrecoThemeCreatorBackgrounds
*self
,
302 self
->parent_window
= parent
;
307 * Append row to the listbox with resized image.
312 irreco_theme_creator_backgrounds_refresh(IrrecoThemeCreatorBackgrounds
*self
)
315 GdkPixbuf
*pixbuf
= NULL
;
316 GError
*error
= NULL
;
317 IrrecoData
*irreco_data
= NULL
;
318 IrrecoThemeManager
*manager
= NULL
;
321 const gchar
*image_name
;
326 gtk_list_store_clear(self
->store_backgrounds
);
327 irreco_data
= self
->irreco_data
;
328 manager
= irreco_data
->theme_manager
;
331 IRRECO_DEBUG("Pointer: %p \n", (void*) theme
);
332 IRRECO_DEBUG("Pointer: %p \n", (void*) self
->theme
);
333 IRRECO_DEBUG("Pointer: %p \n", (void*) theme
->backgrounds
);
335 theme_bg_count
= irreco_string_table_lenght(theme
->backgrounds
);
336 if (theme_bg_count
> 0) {
337 while(theme_bg_count
> 0) {
338 IrrecoThemeBg
*background_image
;
340 irreco_string_table_index(theme
->backgrounds
, i
,
345 irreco_theme_bg_print(background_image
);
346 pixbuf
= gdk_pixbuf_new_from_file_at_scale(
347 background_image
->image_path
->str
,
348 IRRECO_BACKGROUNDS_PREVIEW_WIDHT
,
349 IRRECO_BACKGROUNDS_PREVIEW_HEIGHT
,
350 GDK_INTERP_NEAREST
, &error
);
352 if (irreco_gerror_check_print(&error
)) {
355 gtk_list_store_append(self
->store_backgrounds
,
357 gtk_list_store_set(self
->store_backgrounds
,
359 background_image
, PIXBUF_COL
,
361 background_image
->image_name
->str
,
364 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(
365 self
->view_backgrounds
));
375 /*if (image_name != NULL) g_free(image_name);*/
376 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
382 void _backgrounds_row_activated_event(GtkTreeView
*tree_view
,
384 GtkTreeViewColumn
*column
,
385 IrrecoThemeCreatorBackgrounds
*self
)
392 irreco_theme_creator_backgrounds_get_selected_bg(
393 IrrecoThemeCreatorBackgrounds
*self
)
397 IRRECO_RETURN_PTR(self
->current_bg
);
401 irreco_theme_creator_backgrounds_remove_selected(IrrecoThemeCreatorBackgrounds
*self
)
407 if ((index
= self
->sel_index
) == -1
408 || irreco_theme_creator_backgrounds_get_iter(self
, index
, &iter
) == FALSE
) {
409 IRRECO_RETURN_BOOL(FALSE
);
412 irreco_theme_creator_backgrounds_set_selection(self
, index
- 1)
413 || irreco_theme_creator_backgrounds_set_selection(self
, index
+ 1);
415 gtk_list_store_remove(self
->store_backgrounds
, &iter
);
416 IRRECO_RETURN_BOOL(TRUE
);