2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
4 * 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * 2008 Harri Vattulainen (t5vaha01@students.oamk.fi)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "irreco_button_browser_dlg.h"
23 #include <hildon/hildon-banner.h>
24 #include "irreco_webdb_client.h"
29 * @addtogroup IrrecoButtonBrowserDlg
32 * Allow user to select one button from one theme.
39 * Source file of @ref IrrecoButtonBrowserDlg.
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 #define IRRECO_BUTTON_BROWSER_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
49 #define IRRECO_BUTTON_BROWSER_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
53 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
55 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
58 _irreco_button_browser_dlg_set_banner(IrrecoButtonBrowserDlg
*self
,
62 _irreco_button_browser_dlg_hide_banner(IrrecoButtonBrowserDlg
*self
);
63 static gboolean
_irreco_button_browser_dlg_loader_images(
64 IrrecoButtonBrowserDlg
*self
);
65 static void irreco_button_browser_dlg_image_selection_changed(
66 GtkTreeSelection
* selection
,
67 IrrecoButtonBrowserDlg
*self
);
68 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
69 /* Construction & Destruction */
70 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
73 * @name Construction & Destruction
77 G_DEFINE_TYPE(IrrecoButtonBrowserDlg
, irreco_button_browser_dlg
,
78 IRRECO_TYPE_INTERNAL_DLG
)
80 static void irreco_button_browser_dlg_constructed(GObject
*object
)
82 IrrecoButtonBrowserDlg
*self
;
86 G_OBJECT_CLASS(irreco_button_browser_dlg_parent_class
)->constructed(
88 self
= IRRECO_BUTTON_BROWSER_DLG(object
);
90 self
->current_image
= NULL
;
92 /* Construct dialog. */
93 gtk_window_set_title(GTK_WINDOW(self
), _("Select preview button"));
94 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
95 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
96 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
97 gtk_dialog_add_buttons(GTK_DIALOG(self
),
98 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
101 /* Create list for images */
102 self
->images
= IRRECO_LISTBOX_IMAGE(
103 irreco_listbox_image_new_with_autosize(200, 450, 180, 180));
104 irreco_listbox_set_select_new_rows(IRRECO_LISTBOX(self
->images
), FALSE
);
105 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self
)->vbox
),
106 GTK_WIDGET(self
->images
));
108 g_signal_connect(G_OBJECT(IRRECO_LISTBOX(self
->images
)->tree_selection
),
110 G_CALLBACK(irreco_button_browser_dlg_image_selection_changed
),
113 gtk_widget_show_all(GTK_WIDGET(self
));
118 static void irreco_button_browser_dlg_init(IrrecoButtonBrowserDlg
*self
)
124 static void irreco_button_browser_dlg_finalize(GObject
*object
)
126 IrrecoButtonBrowserDlg
*self
;
130 self
= IRRECO_BUTTON_BROWSER_DLG(object
);
131 G_OBJECT_CLASS(irreco_button_browser_dlg_parent_class
)->finalize(object
);
137 irreco_button_browser_dlg_class_init(IrrecoButtonBrowserDlgClass
*klass
)
139 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
140 object_class
->finalize
= irreco_button_browser_dlg_finalize
;
141 object_class
->constructed
= irreco_button_browser_dlg_constructed
;
144 GtkWidget
*irreco_button_browser_dlg_new(IrrecoData
*irreco_data
,
145 GtkWindow
*parent_window
)
147 IrrecoButtonBrowserDlg
*self
;
151 self
= g_object_new(IRRECO_TYPE_BUTTON_BROWSER_DLG
,
152 "irreco-data", irreco_data
,
154 irreco_dlg_set_parent(IRRECO_DLG(self
), parent_window
);
156 IRRECO_RETURN_PTR(self
);
163 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
164 /* Private Functions */
165 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
167 * @name Private Functions
172 * Show hildon progressbar banner.
174 * This function will create a new banner if one has not been created yet,
175 * if banner already exists, it's properties will be changed.
177 * @param text Text to show.
178 * @param fraction Value of progress.
181 _irreco_button_browser_dlg_set_banner(IrrecoButtonBrowserDlg
*self
,
187 if (self
->banner
== NULL
) {
188 self
->banner
= hildon_banner_show_progress(
189 GTK_WIDGET(self
), NULL
, "");
192 hildon_banner_set_text(HILDON_BANNER(self
->banner
), text
);
193 hildon_banner_set_fraction(HILDON_BANNER(self
->banner
), fraction
);
199 * Destroy banner, if it exists.
202 _irreco_button_browser_dlg_hide_banner(IrrecoButtonBrowserDlg
*self
)
207 gtk_widget_destroy(self
->banner
);
215 * Background-image loader.
217 * This loader will create a list of background-images from the
218 * given theme and update the TreeView accordingly.
220 static gboolean
_irreco_button_browser_dlg_loader_images(
221 IrrecoButtonBrowserDlg
*self
)
223 gint theme_button_count
;
229 theme_button_count
= irreco_string_table_lenght(self
->theme
->buttons
);
231 if (theme_button_count
> 0) {
232 if(self
->loader_index
== 0) {
233 _irreco_button_browser_dlg_set_banner(self
,
242 if(self
->loader_index
< theme_button_count
){
243 IrrecoThemeButton
*button_image
;
244 const gchar
*image_name
;
246 irreco_string_table_index(self
->theme
->buttons
,
249 (gpointer
*) &button_image
);
250 /* add button to list */
251 irreco_listbox_image_append(self
->images
,
252 button_image
->name
->str
,
254 button_image
->image_up
->str
);
255 /* get and set banner fraction */
256 banner
= (gfloat
) self
->loader_index
/
257 (gfloat
) theme_button_count
;
258 _irreco_button_browser_dlg_set_banner(self
,
261 /* get next button, next time */
262 self
->loader_index
++;
265 if(self
->loader_index
== theme_button_count
) {
266 _irreco_button_browser_dlg_hide_banner(self
);
270 IRRECO_RETURN_BOOL(rvalue
);
277 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
278 /* Public Functions */
279 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
282 * Show dialog, and ask user for input.
285 IrrecoThemeButton
*irreco_button_browser_dlg_run(GtkWindow
*parent_window
,
286 IrrecoData
*irreco_data
,
287 IrrecoTheme
* irreco_theme
)
289 IrrecoButtonBrowserDlg
*self
;
291 gboolean loop
= TRUE
;
292 IrrecoThemeButton
*rvalue
= NULL
;
296 self
= (IrrecoButtonBrowserDlg
*)irreco_button_browser_dlg_new(
300 self
->theme
= irreco_theme
;
302 /* init and start loading buttons */
303 self
->loader_index
= 0;
304 irreco_listbox_clear(IRRECO_LISTBOX(self
->images
));
305 g_idle_add((GSourceFunc
)_irreco_button_browser_dlg_loader_images
, self
);
308 response
= gtk_dialog_run(GTK_DIALOG(self
));
312 case GTK_RESPONSE_CANCEL
:
313 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
318 case GTK_RESPONSE_ACCEPT
:
319 IRRECO_DEBUG("GTK_RESPONSE_ACCEPT\n");
320 /*rvalue = g_strdup(self->current_image->name->str);*/
321 rvalue
= self
->current_image
;
326 IRRECO_DEBUG("Something went horribly wrong\n");
331 gtk_widget_destroy(GTK_WIDGET(self
));
333 IRRECO_RETURN_PTR(rvalue
);
340 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
341 /* Events and Callbacks */
342 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
345 * @name Events and Callbacks
350 * Respond to image selection change.
352 * This function will store selected button to self->current_image
354 static void irreco_button_browser_dlg_image_selection_changed(
355 GtkTreeSelection
*selection
,
356 IrrecoButtonBrowserDlg
*self
)
359 gchar
*sel_label
= NULL
;
360 IrrecoThemeButton
*button
= NULL
;
364 if (irreco_listbox_get_selection(IRRECO_LISTBOX(self
->images
),
365 &sel_index
, &sel_label
, (gpointer
*)&button
)) {
366 self
->current_image
= button
;
368 self
->current_image
= NULL
;
372 gtk_dialog_response(GTK_DIALOG(self
), GTK_RESPONSE_ACCEPT
);