Added button image data transmission from
[irreco.git] / irreco / src / core / irreco_cmd_chain_setup_dlg.c
bloba47398e1ad063a559d67fb10344daa037809cfa8
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_cmd_chain_setup_dlg.h"
22 /**
23 * @addtogroup IrrecoCmdChainSetupDlg
24 * @ingroup Irreco
26 * Dialog for setting some properties of command chains.
28 * @{
31 /**
32 * @file
33 * Source file of @ref IrrecoCmdChainSetupDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /* Prototypes */
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 void irreco_cmd_chain_setup_dlg_responce_signal(IrrecoCmdChainSetupDlg *self,
42 gint response);
43 void irreco_cmd_chain_setup_dlg_progress_toggled(GtkToggleButton *togglebutton,
44 IrrecoCmdChainSetupDlg *self);
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 /* Construction & Destruction */
50 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
52 /**
53 * @name Construction & Destruction
54 * @{
57 G_DEFINE_TYPE(IrrecoCmdChainSetupDlg, irreco_cmd_chain_setup_dlg,
58 IRRECO_TYPE_DLG)
61 static void irreco_cmd_chain_setup_dlg_finalize(GObject *object)
63 G_OBJECT_CLASS(irreco_cmd_chain_setup_dlg_parent_class)
64 ->finalize(object);
67 static void
68 irreco_cmd_chain_setup_dlg_class_init(IrrecoCmdChainSetupDlgClass *klass)
70 GObjectClass *object_class;
71 IRRECO_ENTER
73 object_class = G_OBJECT_CLASS(klass);
74 object_class->finalize = irreco_cmd_chain_setup_dlg_finalize;
75 IRRECO_RETURN
79 static void
80 irreco_cmd_chain_setup_dlg_class_init(IrrecoCmdChainSetupDlgClass *klass)
82 IRRECO_ENTER
83 IRRECO_RETURN
86 static void irreco_cmd_chain_setup_dlg_init(IrrecoCmdChainSetupDlg *self)
88 GtkWidget *vbox;
89 GtkWidget *hbox;
91 GtkWidget *label_repeat;
92 GtkWidget *radio_repeat;
93 GtkWidget *radio_norepeat;
95 IRRECO_ENTER
97 /* Construct dialog. */
98 gtk_window_set_title(GTK_WINDOW(self), _("Command chain properties"));
99 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
100 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
101 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
102 gtk_dialog_add_buttons(GTK_DIALOG(self),
103 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
104 GTK_STOCK_OK, GTK_RESPONSE_OK,
105 NULL);
107 /* Create widgets. */
108 vbox = gtk_vbox_new(0, 8);
110 radio_repeat = gtk_radio_button_new_with_label(NULL, _("Yes"));
111 radio_norepeat = gtk_radio_button_new_with_label_from_widget(
112 GTK_RADIO_BUTTON(radio_repeat), _("No"));
113 label_repeat = gtk_label_new(_("Should the command chain be "
114 "automatically repeated if user "
115 "keeps the button presseed."));
116 gtk_label_set_line_wrap(GTK_LABEL(label_repeat), TRUE);
117 gtk_misc_set_alignment(GTK_MISC(label_repeat), 0, 0.5);
119 self->combo_box = gtk_combo_box_new_text();
121 /* Add rate selection setting. */
122 gtk_box_pack_start(GTK_BOX(vbox),
123 irreco_gtk_label_bold(_("Command execution rate"),
124 0, 0.5, 0, 0, 0, 0), 0, 0, 0);
125 hbox = gtk_hbox_new(0, 8);
126 gtk_box_pack_start(GTK_BOX(vbox), hbox, 0, 0, 0);
127 gtk_box_pack_start(GTK_BOX(hbox),
128 irreco_gtk_label(_("Execute one command every"),
129 0, 0.5, 0, 0, 16, 0), 0, 0, 0);
130 gtk_box_pack_start(GTK_BOX(hbox), self->combo_box, 0, 0, 0);
131 gtk_box_pack_start(GTK_BOX(hbox),
132 irreco_gtk_label(_("seconds."),
133 0, 0.5, 0, 0, 5, 0), 0, 0, 0);
135 /* Add options. */
136 gtk_box_pack_start(GTK_BOX(vbox),
137 irreco_gtk_label_bold(_("Options"),
138 0, 0.5, 8, 0, 0, 0), 0, 0, 0);
139 self->progbar_check = gtk_check_button_new_with_label(
140 _("Show progressbar while executing several commands."));
141 gtk_box_pack_start(GTK_BOX(vbox),
142 irreco_gtk_pad(self->progbar_check, 0, 0, 16, 0),
143 0, 0, 0);
146 /* Add repeat setting. *
147 gtk_box_pack_start(GTK_BOX(vbox),
148 irreco_gtk_label_bold(_("Command chain repeating"),
149 0, 0.5, 16, 0, 0, 0), 0, 0, 0);
150 gtk_box_pack_start(GTK_BOX(vbox),
151 irreco_gtk_pad(label_repeat, 0, 0, 16, 0),
152 1, 1, 1);
153 hbox = gtk_hbox_new(0, 8);
154 gtk_box_pack_start(GTK_BOX(vbox),
155 irreco_gtk_pad(hbox, 0, 0, 16, 0),
156 0, 0, 0);
157 gtk_box_pack_start(GTK_BOX(hbox), radio_repeat, 0, 0, 0);
158 gtk_box_pack_start(GTK_BOX(hbox), radio_norepeat, 0, 0, 0);
161 /* Setup dialgo. */
162 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox),
163 irreco_gtk_pad(vbox, 8, 8, 8, 8));
164 gtk_widget_show_all(GTK_WIDGET(self));
166 /* Fill combobox. */
167 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.0");
168 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.1");
169 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.2");
170 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.3");
171 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.4");
172 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.6");
173 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "0.8");
174 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "1.0");
175 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "1.2");
176 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "1.4");
177 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "1.6");
178 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "1.8");
179 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "2.0");
180 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "2.5");
181 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "3.0");
182 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "5.0");
183 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "7.0");
184 gtk_combo_box_append_text(GTK_COMBO_BOX(self->combo_box), "10.0");
186 /* Connect signals. */
187 g_signal_connect(G_OBJECT(self), "response",
188 G_CALLBACK(irreco_cmd_chain_setup_dlg_responce_signal),
189 NULL);
190 g_signal_connect(G_OBJECT(self->progbar_check), "toggled",
191 G_CALLBACK(irreco_cmd_chain_setup_dlg_progress_toggled),
192 self);
194 IRRECO_RETURN
197 GtkWidget* irreco_cmd_chain_setup_dlg_new(GtkWindow *parent,
198 IrrecoCmdChain *cmd_chain)
200 IrrecoCmdChainSetupDlg *self;
201 IRRECO_ENTER
203 self = g_object_new(IRRECO_TYPE_CMD_CHAIN_SETUP_DLG, NULL);
204 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
205 irreco_cmd_chain_setup_dlg_set_chain(self, cmd_chain);
206 IRRECO_RETURN_PTR(self);
209 /** @} */
213 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
214 /* Private Functions */
215 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
218 * @name Private Functions
219 * @{
222 /* Add functions here. */
224 /** @} */
228 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
229 /* Public Functions */
230 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
233 * @name Public Functions
234 * @{
237 void irreco_cmd_chain_setup_dlg_set_chain(IrrecoCmdChainSetupDlg *self,
238 IrrecoCmdChain *cmd_chain)
240 gint i;
241 GString* rate;
242 GString* combo;
243 IRRECO_ENTER
245 self->cmd_chain = cmd_chain;
247 combo = g_string_new(NULL);
248 rate = g_string_new(NULL);
249 g_string_printf(rate, "%.1f", ((gfloat) self->cmd_chain->execution_rate)
250 / IRRECO_SECOND_IN_USEC);
252 /* This is a terrible way to set the selected item.
253 TODO: Replace text combo box with proper model / view structure. */
254 for (i = 0; i < 17; i++) {
255 gtk_combo_box_set_active(GTK_COMBO_BOX(self->combo_box), i);
256 irreco_gstring_set_and_free(combo,
257 gtk_combo_box_get_active_text(
258 GTK_COMBO_BOX(self->combo_box)));
259 if (strcmp(combo->str, rate->str) == 0) {
260 i = -1;
261 break;
265 g_string_free(combo, FALSE);
266 g_string_free(rate, FALSE);
267 if (i > 0) gtk_combo_box_set_active(GTK_COMBO_BOX(self->combo_box), 0);
269 /* Set progress checkbox. */
270 gtk_toggle_button_set_active(
271 GTK_TOGGLE_BUTTON(self->progbar_check),
272 irreco_cmd_chain_get_show_progress(self->cmd_chain));
274 IRRECO_RETURN
277 /** @} */
281 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
282 /* Events and Callbacks */
283 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
286 * @name Events and Callbacks
287 * @{
290 void irreco_cmd_chain_setup_dlg_responce_signal(IrrecoCmdChainSetupDlg *self,
291 gint response)
293 IRRECO_ENTER
294 if (response == GTK_RESPONSE_OK) {
295 gchar *text;
296 gfloat rate_f;
297 glong rate_l;
299 IRRECO_PRINTF("GTK_RESPONSE_OK\n");
301 text = gtk_combo_box_get_active_text(
302 GTK_COMBO_BOX(self->combo_box));
303 sscanf(text, "%f", &rate_f);
304 g_free(text);
306 rate_l = IRRECO_SECONDS_TO_USEC(rate_f);
307 irreco_cmd_chain_set_execution_rate(self->cmd_chain, rate_l);
309 IRRECO_RETURN
312 void irreco_cmd_chain_setup_dlg_progress_toggled(GtkToggleButton *togglebutton,
313 IrrecoCmdChainSetupDlg *self)
315 IRRECO_ENTER
316 irreco_cmd_chain_set_show_progress(
317 self->cmd_chain, gtk_toggle_button_get_active(togglebutton));
318 IRRECO_RETURN
321 /** @} */
323 /** @} */