Clean code
[irreco.git] / irreco / src / core / irreco_backend_select_dlg.c
blob850e447925776724759b5d63b1f43a29bc49542b
1 /*
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_backend_select_dlg.h"
22 /**
23 * @addtogroup IrrecoBackendSelectDlg
24 * @ingroup Irreco
26 * Shows a list of Backends to the user and ask the user to select one. This
27 * dialog should be used trough irreco_show_backend_select_dlg().
29 * @{
32 /**
33 * @file
34 * Source file of @ref IrrecoBackendSelectDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /* Construction & Destruction */
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 /**
43 * @name Construction & Destruction
44 * @{
47 G_DEFINE_TYPE(IrrecoBackendSelectDlg, irreco_backend_select_dlg,
48 IRRECO_TYPE_DLG)
50 static void irreco_backend_select_dlg_finalize(GObject *object)
52 G_OBJECT_CLASS(irreco_backend_select_dlg_parent_class)->
53 finalize(object);
56 static void
57 irreco_backend_select_dlg_class_init(IrrecoBackendSelectDlgClass *klass)
59 GObjectClass *object_class = G_OBJECT_CLASS(klass);
60 object_class->finalize = irreco_backend_select_dlg_finalize;
63 static void irreco_backend_select_dlg_init(IrrecoBackendSelectDlg *self)
65 IRRECO_ENTER
67 /* Construct dialog. */
68 gtk_window_set_title(GTK_WINDOW(self),
69 _("What do you want to control?"));
70 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
71 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
72 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
73 gtk_dialog_add_buttons(GTK_DIALOG(self),
74 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
75 GTK_STOCK_OK, GTK_RESPONSE_OK,
76 NULL);
78 /* Create listbox. */
79 self->listbox = irreco_listbox_text_new_with_autosize(360, 500,
80 100, 250);
81 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox),
82 irreco_gtk_align(GTK_WIDGET(self->listbox),
83 0, 0, 1, 1, 8, 8, 8, 8));
84 gtk_widget_show_all(GTK_WIDGET(self));
85 IRRECO_RETURN
88 GtkWidget *irreco_backend_select_dlg_new(IrrecoData *irreco_data,
89 GtkWindow *parent)
91 IrrecoBackendSelectDlg *self;
92 IRRECO_ENTER
94 self = g_object_new(IRRECO_TYPE_BACKEND_SELECT_DLG, NULL);
95 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
96 irreco_backend_select_dlg_set_irreco_data(self, irreco_data);
97 IRRECO_RETURN_PTR(self);
100 /** @} */
104 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
105 /* Private Functions */
106 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
109 * @name Private Functions
110 * @{
114 * Generate the listbox.
116 static void
117 irreco_backend_select_dlg_populate_listbox(IrrecoBackendSelectDlg * self)
119 IRRECO_ENTER
120 IRRECO_BACKEND_MANAGER_FOREACH_LIB(
121 self->irreco_data->irreco_backend_manager, lib)
122 IRRECO_DEBUG("Adding backend lib \"%s\" to list.\n",
123 lib->filename);
124 irreco_listbox_text_append(IRRECO_LISTBOX_TEXT(self->listbox),
125 lib->name, lib);
126 IRRECO_STRING_TABLE_FOREACH_END
127 IRRECO_RETURN
130 /** @} */
134 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
135 /* Functions */
136 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
139 * @name Public Functions
140 * @{
144 void irreco_backend_select_dlg_set_irreco_data(IrrecoBackendSelectDlg *self,
145 IrrecoData *irreco_data)
147 IRRECO_ENTER
148 self->irreco_data = irreco_data;
149 irreco_backend_select_dlg_populate_listbox(self);
150 IRRECO_RETURN
155 * Show a list of backend and allow user to select one.
157 * Returns: TRUE if backend_lib is set, FALSE otherwise.
159 gboolean irreco_show_backend_select_dlg(IrrecoData *irreco_data,
160 GtkWindow *parent,
161 IrrecoBackendLib ** backend_lib)
163 gint rvalue = -1;
164 gint sel_index;
165 gpointer sel_user_data;
166 IrrecoBackendSelectDlg *self;
167 IRRECO_ENTER
169 self = IRRECO_BACKEND_SELECT_DLG(irreco_backend_select_dlg_new(
170 irreco_data, parent));
172 do {
173 switch (gtk_dialog_run(GTK_DIALOG(self))) {
174 case GTK_RESPONSE_CANCEL:
175 rvalue = FALSE;
176 break;
178 case GTK_RESPONSE_OK:
179 irreco_listbox_get_selection(
180 IRRECO_LISTBOX(self->listbox),
181 &sel_index, NULL, &sel_user_data);
183 if (sel_index >= 0) {
184 *backend_lib =
185 (IrrecoBackendLib *) sel_user_data;
186 rvalue = TRUE;
187 } else {
188 irreco_info_dlg(GTK_WINDOW(self),
189 _("Select backend type "
190 "before clicking OK."));
192 break;
194 } while (rvalue == -1);
196 gtk_widget_destroy(GTK_WIDGET(self));
197 IRRECO_RETURN_BOOL(rvalue);
200 /** @} */
201 /** @} */