2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_style_browser_dlg.h"
21 #include "irreco_scrolled_window.h"
22 #include <hildon/hildon-banner.h>
25 * @typedef IrrecoStyleBrowser
27 * Dialog which displays a list of button styles to the user, so the user
31 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
33 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
35 irreco_style_browser_dlg_loading_loop(IrrecoStyleBrowserDlgLoading
*loading
);
36 static void irreco_style_browser_dlg_button_click(IrrecoButton
*irreco_button
,
37 IrrecoStyleBrowserDlg
*self
);
38 static gboolean
irreco_style_browser_dlg_map_event(IrrecoStyleBrowserDlg
*self
,
42 irreco_style_browser_dlg_configure_event(IrrecoStyleBrowserDlg *self,
43 GdkEventConfigure *event,
44 gpointer user_data);*/
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 /* Construction & Destruction */
50 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
52 G_DEFINE_TYPE(IrrecoStyleBrowserDlg
, irreco_style_browser_dlg
, IRRECO_TYPE_DLG
)
54 static void irreco_style_browser_dlg_finalize(GObject
*object
)
57 G_OBJECT_CLASS(irreco_style_browser_dlg_parent_class
)->finalize(object
);
58 g_hash_table_destroy(IRRECO_STYLE_BROWSER_DLG(object
)->layout_array
);
62 static void irreco_style_browser_dlg_class_init(IrrecoStyleBrowserDlgClass
*klass
)
64 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
65 object_class
->finalize
= irreco_style_browser_dlg_finalize
;
68 static void irreco_style_browser_dlg_init(IrrecoStyleBrowserDlg
*self
)
73 /* Create array for irreco layouts. */
74 self
->layout_array
= g_hash_table_new_full(
75 g_direct_hash
, g_direct_equal
, NULL
,
76 G_DESTROYNOTIFY(irreco_button_layout_destroy
));
78 /* Construct dialog. */
79 gtk_window_set_title(GTK_WINDOW(self
), _("Style Browser"));
80 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
81 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
82 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
83 gtk_dialog_add_buttons(GTK_DIALOG(self
),
84 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
,
88 scrolled
= irreco_scrolled_window_new_with_autoresize(300, 700,
90 self
->vbox
= gtk_vbox_new(FALSE
, 10);
92 /* Add widgets to dialog. */
93 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self
)->vbox
), scrolled
);
94 irreco_scrolled_window_add(IRRECO_SCROLLED_WINDOW(scrolled
),
97 /* Signal handlers. */
98 g_signal_connect(G_OBJECT(self
), "map-event",
99 G_CALLBACK(irreco_style_browser_dlg_map_event
), NULL
);
100 /*g_signal_connect(G_OBJECT(self), "configure-event",
101 G_CALLBACK(irreco_style_browser_dlg_configure_event),
104 /* Show dialog, hopefully on the left-top corner of the screen. */
105 gtk_widget_show_all(GTK_WIDGET(self
));
106 gtk_window_move(GTK_WINDOW(self
), 80, 60);
110 GtkWidget
* irreco_style_browser_dlg_new(IrrecoData
*irreco_data
,
113 IrrecoStyleBrowserDlg
*self
;
116 self
= g_object_new(IRRECO_TYPE_STYLE_BROWSER_DLG
, NULL
);
117 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
118 irreco_style_browser_dlg_set_irreco_data(self
, irreco_data
);
119 IRRECO_RETURN_PTR(self
);
124 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
125 /* Private Functions */
126 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
128 static void irreco_style_browser_dlg_add_style(IrrecoStyleBrowserDlg
*self
,
129 IrrecoButtonStyle
*style
)
134 IrrecoButtonLayout
*layout
;
137 /* Create widgets. */
139 label
= gtk_label_new(_("Normal button"));
141 label
= gtk_label_new(style
->name
);
143 hbox
= gtk_hbox_new(FALSE
, 10);
144 fixed
= gtk_fixed_new();
146 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
147 gtk_box_pack_start(GTK_BOX(hbox
), fixed
, 0, 0, 0);
148 gtk_box_pack_end_defaults(GTK_BOX(hbox
), label
);
149 gtk_container_add(GTK_CONTAINER(self
->vbox
), hbox
);
150 gtk_widget_show_all(hbox
);
152 /* Create layout and setup callbacks. */
153 layout
= irreco_button_layout_create(fixed
, NULL
);
154 g_hash_table_insert(self
->layout_array
, layout
, layout
);
155 irreco_button_layout_set_press_callback(layout
, irreco_button_down
);
156 irreco_button_layout_set_release_callback(
157 layout
, irreco_style_browser_dlg_button_click
);
158 irreco_button_layout_set_callback_data(layout
, self
);
161 irreco_button_create(layout
, 0, 0, _("Select"), style
, NULL
);
162 irreco_button_layout_create_widgets(layout
);
167 static void irreco_style_browser_dlg_loading_start(IrrecoStyleBrowserDlg
*self
)
171 if (self
->loading
== NULL
) {
172 self
->loading
= g_slice_new0(IrrecoStyleBrowserDlgLoading
);
173 self
->loading
->self
= self
;
174 self
->loading
->len
= irreco_string_table_lenght(
175 self
->irreco_data
->button_style_array
);
176 self
->loading
->banner
= hildon_banner_show_progress(
177 GTK_WIDGET(self
), NULL
, "Loading");
178 hildon_banner_set_fraction(HILDON_BANNER(self
->loading
->banner
),
179 (float) 1 / (float) self
->loading
->len
);
180 g_hash_table_remove_all(self
->layout_array
);
182 /* Add GtkButton layout. */
183 irreco_style_browser_dlg_add_style(self
, NULL
);
184 g_idle_add(G_SOURCEFUNC(irreco_style_browser_dlg_loading_loop
),
190 static void irreco_style_browser_dlg_loading_cancel(IrrecoStyleBrowserDlg
*self
)
193 if (self
->loading
!= NULL
) self
->loading
->self
= NULL
;
198 irreco_style_browser_dlg_loading_loop(IrrecoStyleBrowserDlgLoading
*loading
)
204 /* Use has closed the dialog before the loading has been completed.
205 When we hit this, Gtk has already destroyed the dialog, so all we
206 need to do is to realease the loading strucure.*/
207 if (loading
->self
== NULL
) {
208 IRRECO_DEBUG("Cancelling style loading.\n");
209 g_slice_free(IrrecoStyleBrowserDlgLoading
, loading
);
210 IRRECO_RETURN_BOOL(FALSE
);
212 } else if (irreco_string_table_index(
213 loading
->self
->irreco_data
->button_style_array
,
214 loading
->pos
, &key
, &style
)) {
215 IRRECO_DEBUG("Loading style \"%s\".\n", key
);
216 irreco_style_browser_dlg_add_style(loading
->self
,
217 (IrrecoButtonStyle
*) style
);
218 loading
->pos
= loading
->pos
+ 1;
219 hildon_banner_set_fraction(HILDON_BANNER(loading
->banner
),
220 (float) 1 / (float) loading
->len
221 * (float) loading
->pos
);
222 IRRECO_RETURN_BOOL(TRUE
);
225 IRRECO_DEBUG("Loading complete. Cleaning up.\n");
226 gtk_widget_destroy(loading
->banner
);
227 loading
->self
->loading
= NULL
;
228 loading
->banner
= NULL
;
230 g_slice_free(IrrecoStyleBrowserDlgLoading
, loading
);
231 IRRECO_RETURN_BOOL(FALSE
);
237 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
239 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
241 void irreco_style_browser_dlg_set_irreco_data(IrrecoStyleBrowserDlg
*self
,
242 IrrecoData
*irreco_data
)
245 self
->irreco_data
= irreco_data
;
249 gboolean
irreco_show_style_browser_dlg(IrrecoData
*irreco_data
,
251 IrrecoButtonStyle
**style
)
254 IrrecoStyleBrowserDlg
*self
;
257 self
= IRRECO_STYLE_BROWSER_DLG(irreco_style_browser_dlg_new(
258 irreco_data
, parent
));
259 response
= gtk_dialog_run(GTK_DIALOG(self
));
260 irreco_style_browser_dlg_loading_cancel(self
);
262 if (response
== 1) *style
= self
->style
;
263 gtk_widget_destroy(GTK_WIDGET(self
));
265 if (response
== 1) IRRECO_RETURN_BOOL(TRUE
);
266 IRRECO_RETURN_BOOL(FALSE
);
271 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
272 /* Events and Callbacks */
273 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
275 static void irreco_style_browser_dlg_button_click(IrrecoButton
*irreco_button
,
276 IrrecoStyleBrowserDlg
*self
)
279 self
->style
= irreco_button
->style
;
280 gtk_dialog_response(GTK_DIALOG(self
), 1);
284 static gboolean
irreco_style_browser_dlg_map_event(IrrecoStyleBrowserDlg
*self
,
289 irreco_style_browser_dlg_loading_start(self
);
290 IRRECO_RETURN_BOOL(FALSE
);
295 irreco_style_browser_dlg_configure_event(IrrecoStyleBrowserDlg *self,
296 GdkEventConfigure *event,
300 IRRECO_PRINTF("Dialog position x%i y%i\n", event->x, event->y);
301 IRRECO_RETURN_BOOL(FALSE);