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"
25 * @addtogroup IrrecoSelectInstanceDlg
28 * Dialog for creating backend devices.
35 * Source file of @ref IrrecoSelectInstanceDlg.
38 G_DEFINE_TYPE (IrrecoSelectInstanceDlg
, \
39 irreco_select_instance_dlg
, \
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 /* Construction & Destruction */
50 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
53 * @name Construction & Destruction
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
);
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
);
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
;
82 irreco_select_instance_dlg_init (IrrecoSelectInstanceDlg
*self
)
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
,
98 self
->vbox
= gtk_vbox_new(FALSE
, 0);
99 self
->listbox
= IRRECO_LISTBOX(
100 irreco_listbox_text_new_with_autosize(300, 600,
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
);
110 GtkWidget
* irreco_select_instance_dlg_new (GtkWindow
*parent
)
112 IrrecoSelectInstanceDlg
*self
;
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
);
125 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
126 /* Private Functions */
127 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
129 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
131 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
134 * @name Public Functions
138 gboolean
irreco_show_select_instance_dlg(IrrecoData
*irreco_data
,
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;
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(
156 irreco_backend_instance_get_name_and_description(instance
);
157 IRRECO_DEBUG("Adding backend instance \"%s\" to list.\n",
160 if (lib_name
== NULL
) {
161 irreco_listbox_text_append(IRRECO_LISTBOX_TEXT(
162 select_instance_dlg
->listbox
),
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
),
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
:
182 case GTK_RESPONSE_OK
: {
184 gpointer sel_user_data
;
185 IrrecoBackendInstance
*instance
;
187 irreco_listbox_get_selection(
188 IRRECO_LISTBOX(select_instance_dlg
->listbox
),
191 instance
= (IrrecoBackendInstance
*) sel_user_data
;
194 irreco_info_dlg(GTK_WINDOW(select_instance_dlg
),
195 _("Select device controller "
196 "before clicking OK."));
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 "
209 *sel_instance
= instance
;
215 gtk_widget_destroy(GTK_WIDGET(select_instance_dlg
));
216 IRRECO_RETURN_BOOL(rvalue
);
223 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
224 /* Events and Callbacks */
225 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/