clean code and changed version nro.
[irreco.git] / irreco / src / core / irreco_select_instance_dlg.c
blobbb67698c5c215931da683852c21062b3829fd983
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
4 * & 2008 Joni Kokko (t5kojo01@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_backend_device.h"
22 #include "irreco_select_instance_dlg.h"
24 /**
25 * @addtogroup IrrecoSelectInstanceDlg
26 * @ingroup Irreco
28 * Dialog for creating backend devices.
30 * @{
33 /**
34 * @file
35 * Source file of @ref IrrecoSelectInstanceDlg.
38 G_DEFINE_TYPE (IrrecoSelectInstanceDlg, \
39 irreco_select_instance_dlg, \
40 IRRECO_TYPE_DLG)
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /* Prototypes */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 /* Construction & Destruction */
50 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
52 /**
53 * @name Construction & Destruction
54 * @{
57 static void
58 irreco_select_instance_dlg_dispose (GObject *object)
60 if (G_OBJECT_CLASS (irreco_select_instance_dlg_parent_class)->dispose)
61 G_OBJECT_CLASS (irreco_select_instance_dlg_parent_class)->dispose (object);
64 static void
65 irreco_select_instance_dlg_finalize (GObject *object)
67 if (G_OBJECT_CLASS (irreco_select_instance_dlg_parent_class)->finalize)
68 G_OBJECT_CLASS (irreco_select_instance_dlg_parent_class)->finalize (object);
71 static void
72 irreco_select_instance_dlg_class_init (IrrecoSelectInstanceDlgClass *klass)
74 GObjectClass *object_class = G_OBJECT_CLASS (klass);
77 object_class->dispose = irreco_select_instance_dlg_dispose;
78 object_class->finalize = irreco_select_instance_dlg_finalize;
81 static void
82 irreco_select_instance_dlg_init (IrrecoSelectInstanceDlg *self)
84 GtkWidget *padding;
85 IRRECO_ENTER
87 /* Construct dialog. */
88 gtk_window_set_title(GTK_WINDOW(self), _("Select device controller"));
89 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
90 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
91 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
92 gtk_dialog_add_buttons(GTK_DIALOG(self),
93 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
94 GTK_STOCK_OK, GTK_RESPONSE_OK,
95 NULL);
97 /* Add widgets. */
98 self->vbox = gtk_vbox_new(FALSE, 0);
99 self->listbox = IRRECO_LISTBOX(
100 irreco_listbox_text_new_with_autosize(300, 600,
101 100, 250));
103 gtk_container_add(GTK_CONTAINER(self->vbox), GTK_WIDGET(self->listbox));
104 padding = irreco_gtk_pad(self->vbox, 8, 8, 8, 8);
105 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox), padding);
107 IRRECO_RETURN
110 GtkWidget * irreco_select_instance_dlg_new (GtkWindow *parent)
112 IrrecoSelectInstanceDlg *self;
113 IRRECO_ENTER
115 self = g_object_new(IRRECO_TYPE_SELECT_INSTANCE_DLG, NULL);
116 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
118 IRRECO_RETURN_PTR(self);
121 /** @} */
125 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
126 /* Private Functions */
127 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
129 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
130 /* Functions */
131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
134 * @name Public Functions
135 * @{
138 gboolean irreco_show_select_instance_dlg(IrrecoData *irreco_data,
139 GtkWindow *parent,
140 const char *lib_name,
141 IrrecoBackendInstance ** sel_instance)
143 IrrecoSelectInstanceDlg *select_instance_dlg = NULL;
144 const gchar *name_desc = NULL;
145 gboolean rvalue = -1;
146 IRRECO_ENTER
148 select_instance_dlg = IRRECO_SELECT_INSTANCE_DLG(
149 irreco_select_instance_dlg_new (parent));
151 IRRECO_BACKEND_MANAGER_FOREACH_INSTANCE(
152 irreco_data->irreco_backend_manager, instance)
154 name_desc = irreco_backend_instance_get_name_and_description(
155 instance);
156 irreco_backend_instance_get_name_and_description(instance);
157 IRRECO_DEBUG("Adding backend instance \"%s\" to list.\n",
158 name_desc);
160 if (lib_name == NULL) {
161 irreco_listbox_text_append(IRRECO_LISTBOX_TEXT(
162 select_instance_dlg->listbox),
163 name_desc,
164 instance);
166 else if (g_utf8_collate(instance->lib->name, lib_name) == 0) {
167 irreco_listbox_text_append(IRRECO_LISTBOX_TEXT(
168 select_instance_dlg->listbox),
169 name_desc,
170 instance);
172 IRRECO_BACKEND_MANAGER_FOREACH_END
174 gtk_widget_show_all(GTK_WIDGET(select_instance_dlg));
176 while (rvalue == -1) {
177 switch (gtk_dialog_run(GTK_DIALOG(select_instance_dlg))) {
178 case GTK_RESPONSE_CANCEL:
179 rvalue = FALSE;
180 break;
182 case GTK_RESPONSE_OK: {
183 gint sel_index;
184 gpointer sel_user_data;
185 IrrecoBackendInstance *instance;
187 irreco_listbox_get_selection(
188 IRRECO_LISTBOX(select_instance_dlg->listbox),
189 &sel_index, NULL,
190 &sel_user_data);
191 instance = (IrrecoBackendInstance *) sel_user_data;
193 if (sel_index < 0) {
194 irreco_info_dlg(GTK_WINDOW(select_instance_dlg),
195 _("Select device controller "
196 "before clicking OK."));
197 break;
200 if (!instance->lib->api->flags &
201 IRRECO_BACKEND_EDITABLE_DEVICES) {
202 irreco_info_dlg(GTK_WINDOW(select_instance_dlg),
203 _("Selected instace does "
204 "not support editing of "
205 "devices"));
206 break;
209 *sel_instance = instance;
210 rvalue = TRUE;
211 } break;
215 gtk_widget_destroy(GTK_WIDGET(select_instance_dlg));
216 IRRECO_RETURN_BOOL(rvalue);
219 /** @} */
223 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
224 /* Events and Callbacks */
225 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
227 /** @} */