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_hardkey_dlg.h"
21 #include "irreco_listbox_image.h"
22 #include "irreco_cmd_chain_editor.h"
25 * @addtogroup IrrecoHardkeyDlg
28 * Allows user attach commands to hardkeys.
35 * Source file of @ref IrrecoHardkeyDlg.
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
52 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
54 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
57 irreco_hardkey_dlg_button_sel_changed(GtkTreeSelection
*treeselection
,
58 IrrecoHardkeyDlg
*self
);
59 static void irreco_hardkey_dlg_responce_signal(IrrecoHardkeyDlg
*self
,
64 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
65 /* Construction & Destruction */
66 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
69 * @name Construction & Destruction
73 G_DEFINE_TYPE(IrrecoHardkeyDlg
, irreco_hardkey_dlg
, IRRECO_TYPE_INTERNAL_DLG
)
75 static void irreco_hardkey_dlg_constructed(GObject
*object
)
77 IrrecoHardkeyDlg
*self
;
78 IrrecoData
*irreco_data
;
79 GtkWidget
*keylist_frame
;
80 GtkWidget
*editor_frame
;
84 G_OBJECT_CLASS(irreco_hardkey_dlg_parent_class
)->constructed(object
);
85 self
= IRRECO_HARDKEY_DLG(object
);
86 irreco_data
= irreco_internal_dlg_get_irreco_data(
87 IRRECO_INTERNAL_DLG(self
));
89 /* Construct dialog. */
90 gtk_window_set_title(GTK_WINDOW(self
), _("Hardware keys"));
91 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
92 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
93 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
94 gtk_dialog_add_buttons(GTK_DIALOG(self
),
95 /* _("Cancel"), GTK_RESPONSE_NO,*/
96 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
99 /* Create new Hardkey map. */
100 self
->new_hardkey_map
= irreco_hardkey_map_new(
101 irreco_data
->cmd_chain_manager
);
103 /* Check that hardkey maps are set. */
104 g_assert(self
->new_hardkey_map
);
105 g_assert(self
->old_hardkey_map
);
107 /* Create widgets. */
108 hbox
= gtk_hbox_new(0, 8);
109 keylist_frame
= gtk_frame_new(NULL
);
110 gtk_frame_set_label_widget(GTK_FRAME(keylist_frame
),
111 irreco_gtk_label_bold(_("Key"),
113 editor_frame
= gtk_frame_new(NULL
);
114 gtk_frame_set_label_widget(GTK_FRAME(editor_frame
),
115 irreco_gtk_label_bold(_("Command chain"),
117 self
->keylist
= irreco_listbox_image_new_with_autosize(0, 300, 100, 220);
118 self
->editor
= irreco_cmd_chain_editor_new(
119 irreco_data
, GTK_WINDOW(self
));
120 irreco_cmd_chain_editor_set_edit_mode(
121 IRRECO_CMD_CHAIN_EDITOR(self
->editor
), IRRECO_DIRECT_EDITING
);
122 irreco_cmd_chain_editor_set_autosize(
123 IRRECO_CMD_CHAIN_EDITOR(self
->editor
), 0, 350, 100, 220);
126 gtk_container_add(GTK_CONTAINER(keylist_frame
),
127 irreco_gtk_pad(self
->keylist
, 4, 1, 1, 1));
128 gtk_container_add(GTK_CONTAINER(editor_frame
),
129 irreco_gtk_pad(self
->editor
, 4, 1, 1, 1));
130 gtk_container_add(GTK_CONTAINER(hbox
), keylist_frame
);
131 gtk_container_add(GTK_CONTAINER(hbox
), editor_frame
);
132 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self
)->vbox
),
133 irreco_gtk_pad(hbox
, 8, 8, 8, 8));
136 /*irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
137 "Up", (void *) IRRECO_HARDKEY_UP,
138 IRRECO_ICON_HARDKEY_DIR "/up.png");
139 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
140 "Down", (void *) IRRECO_HARDKEY_DOWN,
141 IRRECO_ICON_HARDKEY_DIR "/down.png");
142 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
143 "Left", (void *) IRRECO_HARDKEY_LEFT,
144 IRRECO_ICON_HARDKEY_DIR "/left.png");
145 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
146 "Right", (void *) IRRECO_HARDKEY_RIGHT,
147 IRRECO_ICON_HARDKEY_DIR "/right.png");
148 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
149 "Select", (void *) IRRECO_HARDKEY_SELECT,
150 IRRECO_ICON_HARDKEY_DIR "/select.png");
151 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
152 "Back", (void *) IRRECO_HARDKEY_BACK,
153 IRRECO_ICON_HARDKEY_DIR "/back.png");
154 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
155 "Menu", (void *) IRRECO_HARDKEY_MENU,
156 IRRECO_ICON_HARDKEY_DIR "/menu.png");
157 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
158 "Home", (void *) IRRECO_HARDKEY_HOME,
159 IRRECO_ICON_HARDKEY_DIR "/home.png");
161 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self->keylist),
162 "Fullscreen", (void *) IRRECO_HARDKEY_FULLSCREEN,
163 IRRECO_ICON_HARDKEY_DIR "/fullscreen.png");*/
164 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self
->keylist
),
165 "Plus", (void *) IRRECO_HARDKEY_PLUS
,
166 IRRECO_ICON_HARDKEY_DIR
"/plus.png");
167 irreco_listbox_image_append(IRRECO_LISTBOX_IMAGE(self
->keylist
),
168 "Minus", (void *) IRRECO_HARDKEY_MINUS
,
169 IRRECO_ICON_HARDKEY_DIR
"/minus.png");
171 /* Signal handlers. */
172 g_signal_connect(G_OBJECT(
173 IRRECO_LISTBOX(self
->keylist
)->tree_selection
),
175 G_CALLBACK(irreco_hardkey_dlg_button_sel_changed
),
177 g_signal_connect(G_OBJECT(self
), "response",
178 G_CALLBACK(irreco_hardkey_dlg_responce_signal
),
181 /* This should trigger the signal handler and set fill the editor. */
182 irreco_listbox_set_selection(IRRECO_LISTBOX(self
->keylist
), 0);
184 gtk_widget_show_all(GTK_WIDGET(self
));
188 static void irreco_hardkey_dlg_finalize(GObject
*object
)
190 IrrecoHardkeyDlg
*self
= NULL
;
193 G_OBJECT_CLASS(irreco_hardkey_dlg_parent_class
)->finalize (object
);
194 self
= IRRECO_HARDKEY_DLG(object
);
195 irreco_hardkey_map_free(self
->new_hardkey_map
);
200 irreco_hardkey_dlg_set_property(GObject
*object
, guint prop_id
,
201 const GValue
*value
, GParamSpec
*pspec
)
203 IrrecoHardkeyDlg
*self
= NULL
;
204 g_return_if_fail (IRRECO_IS_HARDKEY_DLG (object
));
208 case PROP_OLD_HARDKEY_MAP
:
209 self
= IRRECO_HARDKEY_DLG(object
);
210 self
->old_hardkey_map
=
211 (IrrecoHardkeyMap
*) g_value_get_pointer(value
);
214 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
219 static void irreco_hardkey_dlg_class_init(IrrecoHardkeyDlgClass
*klass
)
221 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
223 object_class
->finalize
= irreco_hardkey_dlg_finalize
;
224 object_class
->constructed
= irreco_hardkey_dlg_constructed
;
225 object_class
->set_property
= irreco_hardkey_dlg_set_property
;
227 g_object_class_install_property(
229 PROP_OLD_HARDKEY_MAP
,
230 g_param_spec_pointer(
234 G_PARAM_CONSTRUCT_ONLY
|
238 static void irreco_hardkey_dlg_init(IrrecoHardkeyDlg
*self
)
242 GtkWidget
* irreco_hardkey_dlg_new(GtkWindow
*parent
,
243 IrrecoData
*irreco_data
,
244 IrrecoHardkeyMap
*hardkey_map
)
246 IrrecoHardkeyDlg
*self
;
249 self
= g_object_new(IRRECO_TYPE_HARDKEY_DLG
,
250 "irreco-data", irreco_data
,
251 "old-hardkey-map", hardkey_map
,
254 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
255 IRRECO_RETURN_PTR(self
);
262 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
263 /* Private Functions */
264 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
267 * @name Private Functions
271 static void irreco_hardkey_dlg_apply_changes_foreach(IrrecoHardkeyMap
*map
,
273 IrrecoCmdChainId chain_id
,
274 IrrecoCmdChain
*new_chain
,
277 IrrecoCmdChain
*old_chain
= NULL
;
278 IrrecoHardkeyDlg
*self
= IRRECO_HARDKEY_DLG(user_data
);
281 irreco_hardkey_map_assosiate_chain(
282 self
->old_hardkey_map
, keyval
);
283 old_chain
= irreco_hardkey_map_get_cmd_chain(
284 self
->old_hardkey_map
, keyval
);
285 irreco_cmd_chain_copy(new_chain
, old_chain
);
293 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
294 /* Public Functions */
295 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
298 * @name Public Functions
302 void irreco_hardkey_dlg_set_hardkey_map(IrrecoHardkeyDlg
*self
,
303 IrrecoHardkeyMap
*hardkey_map
)
306 self
->old_hardkey_map
= hardkey_map
;
311 void irreco_hardkey_dlg_apply_changes(IrrecoHardkeyDlg
*self
)
314 irreco_hardkey_map_chain_foreach(self
->new_hardkey_map
,
315 irreco_hardkey_dlg_apply_changes_foreach
,
324 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
325 /* Events and Callbacks */
326 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
329 * @name Events and Callbacks
334 irreco_hardkey_dlg_button_sel_changed(GtkTreeSelection
*treeselection
,
335 IrrecoHardkeyDlg
*self
)
340 gpointer sel_user_data
;
341 IrrecoCmdChain
*old_chain
= NULL
;
342 IrrecoCmdChain
*new_chain
= NULL
;
345 irreco_listbox_get_selection(IRRECO_LISTBOX(self
->keylist
),
346 &sel_index
, NULL
, &sel_user_data
);
348 if (sel_index
== -1) IRRECO_RETURN
;
350 g_assert(self
->new_hardkey_map
);
351 g_assert(self
->old_hardkey_map
);
353 keyval
= (guint
) sel_user_data
;
354 hardkey_str
= irreco_hardkey_to_str(keyval
);
355 IRRECO_PRINTF("Editing hardkey \"%s\".\n", hardkey_str
);
358 if (irreco_hardkey_map_cmd_chain_exists(self
->new_hardkey_map
, keyval
)
360 IRRECO_PRINTF("Creating a copy of command chain.\n");
361 irreco_hardkey_map_assosiate_chain(
362 self
->new_hardkey_map
, keyval
);
363 IRRECO_DEBUG("Creating new chain.\n");
364 new_chain
= irreco_hardkey_map_get_cmd_chain(
365 self
->new_hardkey_map
, keyval
);
366 IRRECO_DEBUG("Getting old chain.\n");
367 old_chain
= irreco_hardkey_map_get_cmd_chain(
368 self
->old_hardkey_map
, keyval
);
369 if (old_chain
!= NULL
&& new_chain
!= NULL
) {
370 irreco_cmd_chain_copy(old_chain
, new_chain
);
372 irreco_cmd_chain_editor_set_chain(
373 IRRECO_CMD_CHAIN_EDITOR(
378 IRRECO_PRINTF("Using old copy of command chain.\n");
379 new_chain
= irreco_hardkey_map_get_cmd_chain(
380 self
->new_hardkey_map
, keyval
);
381 irreco_cmd_chain_editor_set_chain(
382 IRRECO_CMD_CHAIN_EDITOR(self
->editor
), new_chain
);
388 static void irreco_hardkey_dlg_responce_signal(IrrecoHardkeyDlg
*self
,
392 if (response
== GTK_RESPONSE_OK
) {
393 irreco_hardkey_dlg_apply_changes(self
);