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>
28 * @addtogroup IrrecoButtonBrowserDlg
31 * Allow user to select one button from one theme.
38 * Source file of @ref IrrecoButtonBrowserDlg.
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 #define IRRECO_BUTTON_BROWSER_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
48 #define IRRECO_BUTTON_BROWSER_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
52 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
54 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
57 _irreco_button_browser_dlg_set_banner(IrrecoButtonBrowserDlg
*self
,
61 _irreco_button_browser_dlg_hide_banner(IrrecoButtonBrowserDlg
*self
);
62 static gboolean
_irreco_button_browser_dlg_loader_images(
63 IrrecoButtonBrowserDlg
*self
);
64 static void irreco_button_browser_dlg_image_selection_changed(
65 GtkTreeSelection
* selection
,
66 IrrecoButtonBrowserDlg
*self
);
67 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
68 /* Construction & Destruction */
69 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
72 * @name Construction & Destruction
76 G_DEFINE_TYPE(IrrecoButtonBrowserDlg
, irreco_button_browser_dlg
,
77 IRRECO_TYPE_INTERNAL_DLG
)
79 static void irreco_button_browser_dlg_constructed(GObject
*object
)
81 IrrecoButtonBrowserDlg
*self
;
85 G_OBJECT_CLASS(irreco_button_browser_dlg_parent_class
)->constructed(
87 self
= IRRECO_BUTTON_BROWSER_DLG(object
);
89 self
->current_image
= NULL
;
91 /* Construct dialog. */
92 gtk_window_set_title(GTK_WINDOW(self
), _("Select preview button"));
93 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
94 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
95 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
97 /* Create list for images */
98 self
->images
= IRRECO_LISTBOX_IMAGE(
99 irreco_listbox_image_new_with_autosize(200, 450, 180, 180));
100 irreco_listbox_set_select_new_rows(IRRECO_LISTBOX(self
->images
), FALSE
);
101 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self
)->vbox
),
102 GTK_WIDGET(self
->images
));
104 g_signal_connect(G_OBJECT(IRRECO_LISTBOX(self
->images
)->tree_selection
),
106 G_CALLBACK(irreco_button_browser_dlg_image_selection_changed
),
109 gtk_widget_show_all(GTK_WIDGET(self
));
114 static void irreco_button_browser_dlg_init(IrrecoButtonBrowserDlg
*self
)
120 static void irreco_button_browser_dlg_finalize(GObject
*object
)
122 IrrecoButtonBrowserDlg
*self
;
126 self
= IRRECO_BUTTON_BROWSER_DLG(object
);
127 G_OBJECT_CLASS(irreco_button_browser_dlg_parent_class
)->finalize(object
);
133 irreco_button_browser_dlg_class_init(IrrecoButtonBrowserDlgClass
*klass
)
135 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
136 object_class
->finalize
= irreco_button_browser_dlg_finalize
;
137 object_class
->constructed
= irreco_button_browser_dlg_constructed
;
140 GtkWidget
*irreco_button_browser_dlg_new(IrrecoData
*irreco_data
,
141 GtkWindow
*parent_window
)
143 IrrecoButtonBrowserDlg
*self
;
147 self
= g_object_new(IRRECO_TYPE_BUTTON_BROWSER_DLG
,
148 "irreco-data", irreco_data
,
150 irreco_dlg_set_parent(IRRECO_DLG(self
), parent_window
);
152 IRRECO_RETURN_PTR(self
);
159 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
160 /* Private Functions */
161 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
163 * @name Private Functions
168 * Show hildon progressbar banner.
170 * This function will create a new banner if one has not been created yet,
171 * if banner already exists, it's properties will be changed.
173 * @param text Text to show.
174 * @param fraction Value of progress.
177 _irreco_button_browser_dlg_set_banner(IrrecoButtonBrowserDlg
*self
,
183 if (self
->banner
== NULL
) {
184 self
->banner
= hildon_banner_show_progress(
185 GTK_WIDGET(self
), NULL
, "");
188 hildon_banner_set_text(HILDON_BANNER(self
->banner
), text
);
189 hildon_banner_set_fraction(HILDON_BANNER(self
->banner
), fraction
);
195 * Destroy banner, if it exists.
198 _irreco_button_browser_dlg_hide_banner(IrrecoButtonBrowserDlg
*self
)
203 gtk_widget_destroy(self
->banner
);
211 * Background-image loader.
213 * This loader will create a list of background-images from the
214 * given theme and update the TreeView accordingly.
216 static gboolean
_irreco_button_browser_dlg_loader_images(
217 IrrecoButtonBrowserDlg
*self
)
219 gint theme_button_count
;
225 theme_button_count
= irreco_string_table_lenght(self
->theme
->buttons
);
227 if (theme_button_count
> 0) {
228 if(self
->loader_index
== 0) {
229 _irreco_button_browser_dlg_set_banner(self
,
238 if(self
->loader_index
< theme_button_count
){
239 IrrecoThemeButton
*button_image
;
240 const gchar
*image_name
;
242 irreco_string_table_index(self
->theme
->buttons
,
245 (gpointer
*) &button_image
);
246 /* add button to list */
247 irreco_listbox_image_append(self
->images
,
248 button_image
->name
->str
,
250 button_image
->image_up
->str
);
251 /* get and set banner fraction */
252 banner
= (gfloat
) self
->loader_index
/
253 (gfloat
) theme_button_count
;
254 _irreco_button_browser_dlg_set_banner(self
,
257 /* get next button, next time */
258 self
->loader_index
++;
261 if(self
->loader_index
== theme_button_count
) {
262 _irreco_button_browser_dlg_hide_banner(self
);
266 IRRECO_RETURN_BOOL(rvalue
);
273 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
274 /* Public Functions */
275 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
278 * Show dialog, and ask user for input.
281 IrrecoThemeButton
*irreco_button_browser_dlg_run(GtkWindow
*parent_window
,
282 IrrecoData
*irreco_data
,
283 IrrecoTheme
* irreco_theme
)
285 IrrecoButtonBrowserDlg
*self
;
287 gboolean loop
= TRUE
;
288 IrrecoThemeButton
*rvalue
= NULL
;
292 self
= (IrrecoButtonBrowserDlg
*)irreco_button_browser_dlg_new(
296 self
->theme
= irreco_theme
;
298 /* init and start loading buttons */
299 self
->loader_index
= 0;
300 irreco_listbox_clear(IRRECO_LISTBOX(self
->images
));
301 g_idle_add((GSourceFunc
)_irreco_button_browser_dlg_loader_images
, self
);
304 response
= gtk_dialog_run(GTK_DIALOG(self
));
307 case GTK_RESPONSE_DELETE_EVENT
:
308 IRRECO_DEBUG("GTK_RESPONSE_DELETE_EVENT\n");
313 case GTK_RESPONSE_ACCEPT
:
314 IRRECO_DEBUG("GTK_RESPONSE_ACCEPT\n");
315 /*rvalue = g_strdup(self->current_image->name->str);*/
316 rvalue
= self
->current_image
;
321 IRRECO_DEBUG("Something went horribly wrong\n");
326 gtk_widget_destroy(GTK_WIDGET(self
));
328 IRRECO_RETURN_PTR(rvalue
);
335 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
336 /* Events and Callbacks */
337 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
340 * @name Events and Callbacks
345 * Respond to image selection change.
347 * This function will store selected button to self->current_image
349 static void irreco_button_browser_dlg_image_selection_changed(
350 GtkTreeSelection
*selection
,
351 IrrecoButtonBrowserDlg
*self
)
354 gchar
*sel_label
= NULL
;
355 IrrecoThemeButton
*button
= NULL
;
359 if (irreco_listbox_get_selection(IRRECO_LISTBOX(self
->images
),
360 &sel_index
, &sel_label
, (gpointer
*)&button
)) {
361 self
->current_image
= button
;
363 self
->current_image
= NULL
;
367 gtk_dialog_response(GTK_DIALOG(self
), GTK_RESPONSE_ACCEPT
);