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"
23 * @addtogroup IrrecoBackendSelectDlg
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().
34 * Source file of @ref IrrecoBackendSelectDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /* Construction & Destruction */
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 * @name Construction & Destruction
47 G_DEFINE_TYPE(IrrecoBackendSelectDlg
, irreco_backend_select_dlg
,
50 static void irreco_backend_select_dlg_finalize(GObject
*object
)
52 G_OBJECT_CLASS(irreco_backend_select_dlg_parent_class
)->
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
)
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
,
79 self
->listbox
= irreco_listbox_text_new_with_autosize(360, 500,
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
));
88 GtkWidget
*irreco_backend_select_dlg_new(IrrecoData
*irreco_data
,
91 IrrecoBackendSelectDlg
*self
;
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
);
104 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
105 /* Private Functions */
106 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
109 * @name Private Functions
114 * Generate the listbox.
117 irreco_backend_select_dlg_populate_listbox(IrrecoBackendSelectDlg
* self
)
120 IRRECO_BACKEND_MANAGER_FOREACH_LIB(
121 self
->irreco_data
->irreco_backend_manager
, lib
)
122 IRRECO_DEBUG("Adding backend lib \"%s\" to list.\n",
124 irreco_listbox_text_append(IRRECO_LISTBOX_TEXT(self
->listbox
),
126 IRRECO_STRING_TABLE_FOREACH_END
134 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
136 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
139 * @name Public Functions
144 void irreco_backend_select_dlg_set_irreco_data(IrrecoBackendSelectDlg
*self
,
145 IrrecoData
*irreco_data
)
148 self
->irreco_data
= irreco_data
;
149 irreco_backend_select_dlg_populate_listbox(self
);
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
,
161 IrrecoBackendLib
** backend_lib
)
165 gpointer sel_user_data
;
166 IrrecoBackendSelectDlg
*self
;
169 self
= IRRECO_BACKEND_SELECT_DLG(irreco_backend_select_dlg_new(
170 irreco_data
, parent
));
173 switch (gtk_dialog_run(GTK_DIALOG(self
))) {
174 case GTK_RESPONSE_CANCEL
:
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) {
185 (IrrecoBackendLib
*) sel_user_data
;
188 irreco_info_dlg(GTK_WINDOW(self
),
189 _("Select backend type "
190 "before clicking OK."));
194 } while (rvalue
== -1);
196 gtk_widget_destroy(GTK_WIDGET(self
));
197 IRRECO_RETURN_BOOL(rvalue
);