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
;
200 if (irreco_theme
!=NULL
) {
201 irreco_theme_creator_backgrounds_refresh(self
);
203 /*if (irreco_string_table_lenght(irreco_theme->buttons) != 0) {
204 irreco_theme_creator_backgrounds_image_append_with_size(self);
207 IRRECO_RETURN_PTR(GTK_WIDGET(self
));
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
213 /* Private Functions */
214 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
217 * @name Private Functions
222 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
223 /* Public Functions */
224 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
227 * @name Public Functions
232 * Set parent window for popup dialogs.
235 irreco_theme_creator_backgrounds_set_parent_window(
236 IrrecoThemeCreatorBackgrounds
*self
,
240 self
->parent_window
= parent
;
245 * Append row to the listbox with resized image.
250 irreco_theme_creator_backgrounds_refresh(
251 IrrecoThemeCreatorBackgrounds
*self
)
254 GdkPixbuf
*pixbuf
= NULL
;
255 GError
*error
= NULL
;
256 IrrecoData
*irreco_data
= NULL
;
257 IrrecoThemeManager
*manager
= NULL
;
260 const gchar
*image_name
;
266 gtk_list_store_clear(self
->store_backgrounds
);
268 irreco_data
= self
->irreco_data
;
269 manager
= irreco_data
->theme_manager
;
272 theme_bg_count
= irreco_string_table_lenght(theme
->backgrounds
);
274 if (theme_bg_count
> 0) {
275 while(theme_bg_count
> 0) {
276 IrrecoThemeBg
*background_image
;
278 irreco_string_table_index(theme
->backgrounds
, i
,
282 irreco_theme_bg_print(background_image
);
284 pixbuf
= gdk_pixbuf_new_from_file_at_scale(
285 background_image
->image_path
->str
,
286 IRRECO_BACKGROUNDS_PREVIEW_WIDHT
,
287 IRRECO_BACKGROUNDS_PREVIEW_HEIGHT
,
288 GDK_INTERP_NEAREST
, &error
);
289 if (irreco_gerror_check_print(&error
)) {
293 gtk_list_store_append(self
->store_backgrounds
,
296 gtk_list_store_set(self
->store_backgrounds
,
298 background_image
, PIXBUF_COL
,
299 pixbuf
, TEXT_COL
, image_name
,
302 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(
303 self
->view_backgrounds
));
313 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
319 void _backgrounds_row_activated_event(GtkTreeView
*tree_view
,
321 GtkTreeViewColumn
*column
,
322 IrrecoThemeCreatorBackgrounds
*self
)
329 *Get information on the background picture
332 static void _image_selection_changed(GtkTreeSelection
* selection
,
333 IrrecoThemeCreatorBackgrounds
*self
)
336 GtkTreeModel
*model
= NULL
;
338 GtkTreePath
*path
= NULL
;
339 gint
*path_indices
= NULL
;
342 /* Get currect selection, if set. */
343 selection
= gtk_tree_view_get_selection(
344 GTK_TREE_VIEW(self
->view_backgrounds
));
345 if (gtk_tree_selection_get_selected(self
->tree_selection
,
348 path
= gtk_tree_model_get_path(model
, &iter
);
349 path_indices
= gtk_tree_path_get_indices(path
);
350 self
->sel_index
= path_indices
[0];
352 gtk_tree_model_get(GTK_TREE_MODEL(model
), &iter
,
353 DATA_COL
, &self
->current_bg
,
362 irreco_theme_creator_backgrounds_get_selected_bg(
363 IrrecoThemeCreatorBackgrounds
*self
)
367 IRRECO_RETURN_PTR(self
->current_bg
);
371 irreco_theme_creator_backgrounds_remove_selected(IrrecoThemeCreatorBackgrounds
*self
)
377 if ((index
= self
->sel_index
) == -1
378 || irreco_theme_creator_backgrounds_get_iter(self
, index
, &iter
) == FALSE
) {
379 IRRECO_RETURN_BOOL(FALSE
);
382 irreco_theme_creator_backgrounds_set_selection(self
, index
- 1)
383 || irreco_theme_creator_backgrounds_set_selection(self
, index
+ 1);
385 gtk_list_store_remove(self
->store_backgrounds
, &iter
);
387 irreco_string_table_remove((self
->theme
)->backgrounds
,
388 self
->current_bg
->image_name
->str
);
389 irreco_theme_update_keyfile(self
->theme
);
391 IRRECO_RETURN_BOOL(TRUE
);
395 irreco_theme_creator_backgrounds_get_iter(IrrecoThemeCreatorBackgrounds
*self
,
396 gint index
, GtkTreeIter
* iter
)
403 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(
404 self
->view_backgrounds
));
405 path
= gtk_tree_path_new_from_indices(index
, -1);
406 rvalue
= gtk_tree_model_get_iter(model
, iter
, path
);
407 gtk_tree_path_free(path
);
408 IRRECO_RETURN_INT(rvalue
);
412 irreco_theme_creator_backgrounds_set_selection(IrrecoThemeCreatorBackgrounds
418 if (irreco_theme_creator_backgrounds_get_iter(self
, index
, &iter
)) {
419 gtk_tree_selection_select_iter(self
->tree_selection
, &iter
);
420 IRRECO_RETURN_BOOL(TRUE
);
422 IRRECO_RETURN_BOOL(FALSE
);