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"
23 * @addtogroup IrrecoCmdChainSetupDlg
26 * Dialog for setting some properties of command chains.
33 * Source file of @ref IrrecoCmdChainSetupDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 void irreco_cmd_chain_setup_dlg_responce_signal(IrrecoCmdChainSetupDlg
*self
,
43 void irreco_cmd_chain_setup_dlg_progress_toggled(GtkToggleButton
*togglebutton
,
44 IrrecoCmdChainSetupDlg
*self
);
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 /* Construction & Destruction */
50 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
53 * @name Construction & Destruction
57 G_DEFINE_TYPE(IrrecoCmdChainSetupDlg
, irreco_cmd_chain_setup_dlg
,
61 static void irreco_cmd_chain_setup_dlg_finalize(GObject *object)
63 G_OBJECT_CLASS(irreco_cmd_chain_setup_dlg_parent_class)
68 irreco_cmd_chain_setup_dlg_class_init(IrrecoCmdChainSetupDlgClass *klass)
70 GObjectClass *object_class;
73 object_class = G_OBJECT_CLASS(klass);
74 object_class->finalize = irreco_cmd_chain_setup_dlg_finalize;
80 irreco_cmd_chain_setup_dlg_class_init(IrrecoCmdChainSetupDlgClass
*klass
)
86 static void irreco_cmd_chain_setup_dlg_init(IrrecoCmdChainSetupDlg
*self
)
91 GtkWidget *label_repeat;
92 GtkWidget *radio_repeat;
93 GtkWidget *radio_norepeat;
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
,
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);
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),
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),
153 hbox = gtk_hbox_new(0, 8);
154 gtk_box_pack_start(GTK_BOX(vbox),
155 irreco_gtk_pad(hbox, 0, 0, 16, 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);
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
));
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
),
190 g_signal_connect(G_OBJECT(self
->progbar_check
), "toggled",
191 G_CALLBACK(irreco_cmd_chain_setup_dlg_progress_toggled
),
197 GtkWidget
* irreco_cmd_chain_setup_dlg_new(GtkWindow
*parent
,
198 IrrecoCmdChain
*cmd_chain
)
200 IrrecoCmdChainSetupDlg
*self
;
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
);
213 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
214 /* Private Functions */
215 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
218 * @name Private Functions
222 /* Add functions here. */
228 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
229 /* Public Functions */
230 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
233 * @name Public Functions
237 void irreco_cmd_chain_setup_dlg_set_chain(IrrecoCmdChainSetupDlg
*self
,
238 IrrecoCmdChain
*cmd_chain
)
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
);
253 * This is a terrible way to set the selected item.
254 * Replace text combo box with proper model / view structure.
256 for (i
= 0; i
< 17; i
++) {
257 gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combo_box
), i
);
258 irreco_gstring_set_and_free(combo
,
259 gtk_combo_box_get_active_text(
260 GTK_COMBO_BOX(self
->combo_box
)));
261 if (strcmp(combo
->str
, rate
->str
) == 0) {
267 g_string_free(combo
, FALSE
);
268 g_string_free(rate
, FALSE
);
269 if (i
> 0) gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combo_box
), 0);
271 /* Set progress checkbox. */
272 gtk_toggle_button_set_active(
273 GTK_TOGGLE_BUTTON(self
->progbar_check
),
274 irreco_cmd_chain_get_show_progress(self
->cmd_chain
));
283 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
284 /* Events and Callbacks */
285 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
288 * @name Events and Callbacks
292 void irreco_cmd_chain_setup_dlg_responce_signal(IrrecoCmdChainSetupDlg
*self
,
296 if (response
== GTK_RESPONSE_OK
) {
301 IRRECO_PRINTF("GTK_RESPONSE_OK\n");
303 text
= gtk_combo_box_get_active_text(
304 GTK_COMBO_BOX(self
->combo_box
));
305 sscanf(text
, "%f", &rate_f
);
308 rate_l
= IRRECO_SECONDS_TO_USEC(rate_f
);
309 irreco_cmd_chain_set_execution_rate(self
->cmd_chain
, rate_l
);
314 void irreco_cmd_chain_setup_dlg_progress_toggled(GtkToggleButton
*togglebutton
,
315 IrrecoCmdChainSetupDlg
*self
)
318 irreco_cmd_chain_set_show_progress(
319 self
->cmd_chain
, gtk_toggle_button_get_active(togglebutton
));