Irreco for N900 (Maemo 5) update. Push for 0.8.* changes.
[irreco.git] / irreco / src / core / irreco_style_browser_dlg.c
blob54a517719a910f93ad4ef76751938b55c741b453
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi),
4 * Harri Vattulainen (t5vaha01@students.oamk.fi)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "irreco_style_browser_dlg.h"
22 #include "irreco_scrolled_window.h"
23 #include <hildon/hildon-banner.h>
25 /**
26 * @addtogroup IrrecoStyleBrowserDlg
27 * @ingroup Irreco
29 * Dialog which displays a list of button styles to the user, so the user
30 * can select one.
32 * @{
35 /**
36 * @file
37 * Source file of @ref IrrecoStyleBrowserDlg.
41 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 /* Prototypes */
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 void irreco_style_browser_dlg_set_button_widget(IrrecoStyleBrowserDlg *self);
45 void irreco_style_browser_dlg_theme_image_selection_changed(
46 GtkTreeSelection * selection,
47 IrrecoStyleBrowserDlg * self);
49 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
50 /* Construction & Destruction */
51 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
53 /**
54 * @name Construction & Destruction
55 * @{
59 G_DEFINE_TYPE(IrrecoStyleBrowserDlg, irreco_style_browser_dlg, IRRECO_TYPE_DLG)
61 static void irreco_style_browser_dlg_finalize(GObject *object)
63 IRRECO_ENTER
64 G_OBJECT_CLASS(irreco_style_browser_dlg_parent_class)->finalize(object);
65 IRRECO_RETURN
68 static void irreco_style_browser_dlg_class_init(IrrecoStyleBrowserDlgClass *klass)
70 GObjectClass *object_class = G_OBJECT_CLASS(klass);
71 object_class->finalize = irreco_style_browser_dlg_finalize;
74 static void irreco_style_browser_dlg_init(IrrecoStyleBrowserDlg *self)
76 IRRECO_ENTER
78 self->style = NULL;
80 /* Construct dialog. */
81 gtk_window_set_title(GTK_WINDOW(self), _("Style Browser"));
82 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
83 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
84 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
86 /* Show dialog, hopefully on the left-top corner of the screen. */
87 gtk_widget_show_all(GTK_WIDGET(self));
88 gtk_window_move(GTK_WINDOW(self), 80, 60);
89 IRRECO_RETURN
92 GtkWidget* irreco_style_browser_dlg_new(IrrecoData *irreco_data,
93 GtkWindow *parent)
95 IrrecoStyleBrowserDlg *self;
96 IRRECO_ENTER
97 self = g_object_new(IRRECO_TYPE_STYLE_BROWSER_DLG, NULL);
98 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
99 irreco_style_browser_dlg_set_irreco_data(self, irreco_data);
100 irreco_style_browser_dlg_set_button_widget(self);
101 IRRECO_RETURN_PTR(self);
104 /** @} */
108 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
109 /* Private Functions */
110 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
113 * @name Private Functions
114 * @{
117 static void irreco_style_browser_dlg_loading_cancel(IrrecoStyleBrowserDlg *self)
119 IRRECO_ENTER
120 if (self->loading != NULL) self->loading->self = NULL;
121 IRRECO_RETURN
124 /** @} */
128 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
129 /* Functions */
130 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
133 * @name Public Functions
134 * @{
137 void irreco_style_browser_dlg_set_irreco_data(IrrecoStyleBrowserDlg *self,
138 IrrecoData *irreco_data)
140 IRRECO_ENTER
141 self->irreco_data = irreco_data;
142 IRRECO_RETURN
145 void irreco_style_browser_dlg_set_button_widget(IrrecoStyleBrowserDlg *self)
147 IRRECO_ENTER
149 self->button_widget = irreco_button_browser_widget_new(self->irreco_data);
150 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
151 GTK_WIDGET(self->button_widget));
153 /* Signal handler */
154 g_signal_connect(G_OBJECT(IRRECO_LISTBOX(
155 self->button_widget->images)->tree_selection),
156 "changed",
157 G_CALLBACK(irreco_style_browser_dlg_theme_image_selection_changed),
158 self);
160 gtk_widget_show_all(GTK_WIDGET(self));
162 IRRECO_RETURN
165 gboolean irreco_show_style_browser_dlg(IrrecoData *irreco_data,
166 GtkWindow *parent,
167 IrrecoThemeButton **style)
169 gint response;
170 IrrecoStyleBrowserDlg *self;
171 IRRECO_ENTER
173 self = IRRECO_STYLE_BROWSER_DLG(irreco_style_browser_dlg_new(
174 irreco_data, parent));
175 response = gtk_dialog_run(GTK_DIALOG(self));
176 irreco_style_browser_dlg_loading_cancel(self);
178 if (response == 1) *style = self->style;
179 gtk_widget_destroy(GTK_WIDGET(self));
181 if (response == 1) IRRECO_RETURN_BOOL(TRUE);
182 IRRECO_RETURN_BOOL(FALSE);
185 /** @} */
189 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
190 /* Events and Callbacks */
191 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
194 * @name Events and Callbacks
195 * @{
198 void irreco_style_browser_dlg_theme_image_selection_changed(
199 GtkTreeSelection * selection,
200 IrrecoStyleBrowserDlg * self)
202 IrrecoThemeButton *button = self->button_widget->current_image;
203 IRRECO_ENTER
205 if (button != NULL) {
206 self->style = button;
207 gtk_dialog_response(GTK_DIALOG(self), 1);
209 IRRECO_RETURN
212 /** @} */
213 /** @} */