Added README.
[irreco.git] / irreco / src / core / irreco_window_user.c
blob13b44c46f9aabd4dfaec372f8770af78bcea154f
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_window_user.h"
21 #include "irreco_button.h"
22 #include "irreco_window_edit.h"
23 #include "irreco_input_dlg.h"
24 #include "irreco_config.h"
25 #include "irreco_webdb_upload_dlg.h"
26 #include </usr/include/hildon-1/hildon/hildon-button.h>
27 #include "irreco_select_remote_dlg.h"
29 /**
30 * @addtogroup IrrecoWindowUser
31 * @ingroup Irreco
33 * User interface for using button layouts.
35 * @{
38 /**
39 * @file
40 * Source file of @ref IrrecoWindowUser.
44 void irreco_window_user_draw_background(IrrecoWindowUser * user_window);
45 void irreco_window_user_main_menu_create(IrrecoWindowUser * user_window);
46 void irreco_window_user_main_menu_download(GtkMenuItem * menuitem,
47 IrrecoWindowUser * user_window);
48 void irreco_window_user_new_remote(GtkMenuItem * menuitem, IrrecoWindowUser * user_window);
49 void irreco_window_user_edit_remote(GtkMenuItem * menuitem, IrrecoWindowUser * user_window);
50 void irreco_window_user_main_menu_rename(GtkMenuItem * menuitem,
51 IrrecoWindowUser * user_window);
52 void irreco_window_user_main_menu_upload(GtkMenuItem * menuitem,
53 IrrecoWindowUser * user_window);
54 void irreco_window_user_delete_remote(GtkMenuItem * menuitem,
55 IrrecoWindowUser * user_window);
56 void irreco_window_user_show_remote(GtkButton *button, IrrecoWindowUser * user_window);
57 void irreco_window_user_menu_about(GtkMenuItem * menuitem, IrrecoWindowUser * user_window);
58 void irreco_window_user_button_release(IrrecoButton * irreco_button,
59 IrrecoWindowUser * user_window);
60 void irreco_window_user_execute_start(IrrecoWindowUser * user_window,
61 IrrecoCmdChain * cmd_chain,
62 IrrecoButton * irreco_button);
63 void irreco_window_user_execute_finish(IrrecoCmdChain * cmd_chain,
64 IrrecoWindowUser * user_window);
65 gboolean irreco_window_user_key_press(GtkWidget * widget, GdkEventKey * event,
66 IrrecoWindowUser * user_window);
67 gboolean irreco_window_user_window_state_event(GtkWidget *widget,
68 GdkEventWindowState *event,
69 IrrecoWindowUser *user_window);
72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
73 /* Public api. */
74 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
76 /**
77 * @name Public api
78 * @{
81 /**
82 * Crate and display IrrecoWindowUser.
84 * @param irreco_layout IrrecoButtonLayout to display. If NULL, attempts to
85 * display first layout from
86 * irreco_data->irreco_layout_array.
88 IrrecoWindowUser *irreco_window_user_create(IrrecoWindowManager * manager)
90 IrrecoData *irreco_data = manager->irreco_data;
91 IrrecoWindowUser *user_window;
92 IRRECO_ENTER
94 user_window = g_slice_new0(IrrecoWindowUser);
95 user_window->manager = manager;
96 user_window->irreco_data = irreco_data;
97 user_window->window = irreco_window_create();
99 irreco_window_user_main_menu_create(user_window);
100 /* irreco_window_user_create_show_remote_menu(user_window);*/
102 g_signal_connect(G_OBJECT(user_window->window),
103 "key-press-event",
104 G_CALLBACK(irreco_window_user_key_press),
105 user_window);
106 g_signal_connect(G_OBJECT(user_window->window),
107 "window-state-event",
108 G_CALLBACK(irreco_window_user_window_state_event),
109 user_window);
110 IRRECO_RETURN_PTR(user_window);
113 void irreco_window_user_destroy(IrrecoWindowUser * user_window)
115 IRRECO_ENTER
116 if (user_window->irreco_layout != NULL) {
117 irreco_button_layout_reset(user_window->irreco_layout);
118 IRRECO_DEBUG_LINE
120 irreco_window_destroy(user_window->window);
121 g_slice_free(IrrecoWindowUser, user_window);
122 IRRECO_RETURN
126 * Set and display layout, or, if NULL is given, unset layout.
128 void irreco_window_user_set_layout(IrrecoWindowUser * user_window,
129 IrrecoButtonLayout * layout)
131 IRRECO_ENTER
133 if (user_window->irreco_layout != NULL) {
134 IRRECO_DEBUG_LINE
135 irreco_button_layout_reset(user_window->irreco_layout);
138 IRRECO_DEBUG_LINE
140 if (irreco_string_table_is_empty(
141 user_window->irreco_data->irreco_layout_array)) {
142 gtk_widget_set_sensitive(
143 GTK_WIDGET(user_window->menu_show_remote), FALSE);
144 } else {
145 gtk_widget_set_sensitive(
146 GTK_WIDGET(user_window->menu_show_remote), TRUE);
149 if (layout == NULL) {
150 IRRECO_PRINTF("Layout unset.\n");
151 user_window->irreco_layout = NULL;
153 /* Disable menu entries. */
154 gtk_widget_set_sensitive(
155 GTK_WIDGET(user_window->menu_edit_remote), FALSE);
156 gtk_widget_set_sensitive(
157 GTK_WIDGET(user_window->menu_rename_remote), FALSE);
158 gtk_widget_set_sensitive(
159 GTK_WIDGET(user_window->menu_upload_remote), FALSE);
160 gtk_widget_set_sensitive(
161 GTK_WIDGET(user_window->menu_delete_remote), FALSE);
162 IRRECO_RETURN
164 } else {
165 /* Enable menu entries. */
166 gtk_widget_set_sensitive(
167 GTK_WIDGET(user_window->menu_edit_remote), TRUE);
168 gtk_widget_set_sensitive(
169 GTK_WIDGET(user_window->menu_rename_remote), TRUE);
170 gtk_widget_set_sensitive(
171 GTK_WIDGET(user_window->menu_upload_remote), TRUE);
172 gtk_widget_set_sensitive(
173 GTK_WIDGET(user_window->menu_delete_remote), TRUE);
177 IRRECO_PRINTF("Displaying layout \"%s\".\n",
178 irreco_button_layout_get_name(layout));
179 irreco_button_layout_reset(layout);
180 IRRECO_DEBUG_LINE
181 user_window->irreco_layout = layout;
182 IRRECO_DEBUG_LINE
183 irreco_button_layout_set_container(layout, user_window->window->layout);
184 IRRECO_DEBUG_LINE
185 irreco_button_layout_create_widgets(layout);
186 irreco_button_layout_set_press_callback(layout, irreco_button_down);
187 irreco_button_layout_set_release_callback(
188 layout, irreco_window_user_button_release);
189 irreco_button_layout_set_callback_data(layout, user_window);
190 irreco_window_user_draw_background(user_window);
191 IRRECO_RETURN
194 void irreco_window_user_draw_background(IrrecoWindowUser * user_window)
196 const gchar *image;
197 const GdkColor *color;
198 IRRECO_ENTER
199 irreco_button_layout_get_bg(user_window->irreco_layout, &image, &color);
200 irreco_window_set_background_image(user_window->window, color,
201 image, NULL);
202 IRRECO_RETURN
206 /** @} */
210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
211 /* Callback. */
212 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
215 * @name Callback
216 * @{
220 * Button release callback handler.
222 void irreco_window_user_button_release(IrrecoButton * irreco_button,
223 IrrecoWindowUser * user_window)
225 IRRECO_ENTER
226 irreco_window_user_execute_start(
227 user_window,
228 irreco_button_get_cmd_chain(irreco_button),
229 irreco_button);
231 IRRECO_RETURN
234 void irreco_window_user_execute_start(IrrecoWindowUser * user_window,
235 IrrecoCmdChain * cmd_chain,
236 IrrecoButton * irreco_button)
238 IRRECO_ENTER
239 if (irreco_cmd_chain_execute(cmd_chain, user_window->irreco_data,
240 G_FUNC(irreco_window_user_execute_finish),
241 user_window)) {
242 user_window->execution_button = irreco_button;
243 user_window->executing_cmd_chain = TRUE;
244 gtk_widget_set_sensitive(user_window->menu, FALSE);
245 gtk_widget_set_sensitive(user_window->window->scrolled_window,
246 FALSE);
248 } else if (irreco_button != NULL) {
249 irreco_button_up(irreco_button);
251 IRRECO_RETURN
254 void irreco_window_user_execute_finish(IrrecoCmdChain * cmd_chain,
255 IrrecoWindowUser * user_window)
257 IRRECO_ENTER
259 gtk_widget_set_sensitive(user_window->menu, TRUE);
260 gtk_widget_set_sensitive(user_window->window->scrolled_window, TRUE);
261 if (user_window->execution_button != NULL) {
262 irreco_button_up(user_window->execution_button);
265 user_window->executing_cmd_chain = FALSE;
266 user_window->execution_button = NULL;
268 IRRECO_RETURN
271 /** @} */
275 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
276 /* Menu. */
277 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
280 * @name Menu
281 * @{
284 void irreco_window_user_main_menu_create(IrrecoWindowUser * user_window)
286 IRRECO_ENTER
288 /* Build menu. */
289 user_window->menu = GTK_WIDGET( hildon_app_menu_new() );
290 user_window->menu_new_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "New remote");
291 user_window->menu_download_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "Download remote");
292 user_window->menu_edit_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "Edit remote");
293 user_window->menu_rename_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "Rename remote");
294 user_window->menu_upload_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "Upload remote");
295 user_window->menu_delete_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "Delete remote");
296 user_window->menu_show_remote = hildon_button_new_with_text(2 | 4, 0, NULL, "Select remote");
297 user_window->menu_about = hildon_button_new_with_text(2 | 4, 0, NULL, "About Irreco");
299 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
300 GTK_BUTTON(user_window->menu_new_remote));
301 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
302 GTK_BUTTON(user_window->menu_download_remote));
303 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
304 GTK_BUTTON(user_window->menu_edit_remote));
305 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
306 GTK_BUTTON(user_window->menu_upload_remote));
307 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
308 GTK_BUTTON(user_window->menu_rename_remote));
309 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
310 GTK_BUTTON(user_window->menu_show_remote));
311 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
312 GTK_BUTTON(user_window->menu_delete_remote));
313 hildon_app_menu_append(HILDON_APP_MENU(user_window->menu),
314 GTK_BUTTON(user_window->menu_about));
316 /* Show menu. */
317 hildon_window_set_app_menu(HILDON_WINDOW(user_window->window),
318 HILDON_APP_MENU(user_window->menu));
319 gtk_widget_show_all(user_window->menu);
321 /* Connect signals. */
322 g_signal_connect(G_OBJECT(user_window->menu_new_remote),
323 "clicked",
324 G_CALLBACK(irreco_window_user_new_remote),
325 user_window);
326 g_signal_connect(G_OBJECT(user_window->menu_download_remote),
327 "clicked",
328 G_CALLBACK(irreco_window_user_main_menu_download),
329 user_window);
330 g_signal_connect(G_OBJECT(user_window->menu_edit_remote),
331 "clicked",
332 G_CALLBACK(irreco_window_user_edit_remote),
333 user_window);
334 g_signal_connect(G_OBJECT(user_window->menu_rename_remote),
335 "clicked",
336 G_CALLBACK(irreco_window_user_main_menu_rename),
337 user_window);
338 g_signal_connect(G_OBJECT(user_window->menu_upload_remote),
339 "clicked",
340 G_CALLBACK(irreco_window_user_main_menu_upload),
341 user_window);
342 g_signal_connect(G_OBJECT(user_window->menu_delete_remote),
343 "clicked",
344 G_CALLBACK(irreco_window_user_delete_remote),
345 user_window);
346 g_signal_connect(G_OBJECT(user_window->menu_show_remote),
347 "clicked",
348 G_CALLBACK(irreco_window_user_show_remote),
349 user_window);
350 g_signal_connect(G_OBJECT(user_window->menu_about),
351 "clicked",
352 G_CALLBACK(irreco_window_user_menu_about),
353 user_window);
354 IRRECO_RETURN
357 /** @} */
359 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
360 /* Main menu callback functions. */
361 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
364 * @name Main menu callback functions
365 * @{
369 * Create dialog window and ask the user for remote name. If user gives the
370 * remote name and clicks create, a new IrrecoButtonLayout and edit user interface
371 * will be created.
373 void irreco_window_user_new_remote(GtkMenuItem * menuitem, IrrecoWindowUser * user_window)
375 IrrecoData *irreco_data = user_window->irreco_data;
376 GtkWindow *parent = irreco_window_get_gtk_window(user_window->window);
377 IRRECO_ENTER
378 if (irreco_window_user_create_new_remote(irreco_data, parent)) {
379 irreco_window_manager_show(irreco_data->window_manager,
380 IRRECO_WINDOW_EDIT);
383 IRRECO_RETURN
386 void irreco_window_user_main_menu_download(GtkMenuItem * menuitem,
387 IrrecoWindowUser * user_window)
389 IRRECO_ENTER
391 irreco_show_remote_download_dlg(user_window->irreco_data,
392 irreco_window_get_gtk_window(
393 user_window->window));
395 IRRECO_RETURN
398 void irreco_window_user_edit_remote(GtkMenuItem * menuitem, IrrecoWindowUser * user_window)
400 IrrecoData *irreco_data = user_window->irreco_data;
401 IRRECO_ENTER
403 if (irreco_string_table_is_empty(irreco_data->irreco_layout_array)) {
404 irreco_info_dlg(irreco_window_get_gtk_window(user_window->window),
405 _(IRRECO_NO_REMOTE_HELP));
406 } else {
407 irreco_window_manager_set_layout(user_window->manager,
408 user_window->irreco_layout);
409 irreco_window_manager_show(user_window->manager,
410 IRRECO_WINDOW_EDIT);
413 IRRECO_RETURN
416 void irreco_window_user_main_menu_rename(GtkMenuItem * menuitem,
417 IrrecoWindowUser * user_window)
419 IrrecoInputDlg *input;
420 IRRECO_ENTER
422 IRRECO_PRINTF("%p\n", (void *) user_window);
424 /* Create input dialog. */
425 input = IRRECO_INPUT_DLG(irreco_input_dlg_new(
426 irreco_window_get_gtk_window(
427 user_window->window), _("Rename remote")));
428 irreco_input_dlg_set_label(input, _("Name"));
429 irreco_input_dlg_set_entry(input, irreco_button_layout_get_name(
430 user_window->irreco_layout));
432 /* Loop until cancel or successfull rename. */
433 do {
434 if (irreco_show_input_dlg(input) == FALSE) break;
435 if (irreco_string_table_change_key(
436 user_window->irreco_data->irreco_layout_array,
437 irreco_button_layout_get_name(
438 user_window->irreco_layout),
439 irreco_input_dlg_get_entry(input)) == TRUE) break;
440 irreco_error_dlg(GTK_WINDOW(input),
441 _(IRRECO_LAYOUT_NAME_COLLISION));
442 } while (TRUE);
444 irreco_config_save_layouts(user_window->irreco_data);
445 /* irreco_window_user_create_show_remote_menu(user_window);*/
446 gtk_widget_destroy(GTK_WIDGET(input));
447 IRRECO_RETURN
450 void irreco_window_user_main_menu_upload(GtkMenuItem * menuitem,
451 IrrecoWindowUser * user_window)
453 IRRECO_ENTER
455 irreco_show_remote_upload_dlg(user_window->irreco_data,
456 irreco_window_get_gtk_window(
457 user_window->window));
459 IRRECO_RETURN
462 void irreco_window_user_delete_remote(GtkMenuItem * menuitem,
463 IrrecoWindowUser * user_window)
465 guint index;
466 IrrecoButtonLayout *irreco_layout = NULL;
467 IrrecoData * irreco_data = user_window->irreco_data;
468 IRRECO_ENTER
470 /* Do we have anything to destroy? */
471 if (user_window->irreco_layout == NULL) {
472 irreco_info_dlg(irreco_window_get_gtk_window(
473 user_window->window),
474 _(IRRECO_NO_REMOTE_HELP));
476 /* If we can get the index of the current layout, and user agrees,
477 then destroy the layout. */
478 } else if(
479 irreco_string_table_get_index(irreco_data->irreco_layout_array,
480 user_window->irreco_layout, &index) &&
481 irreco_yes_no_dlg(irreco_window_get_gtk_window(user_window->window),
482 _("Delete remote?"))) {
484 IrrecoButtonLayout * layout = user_window->irreco_layout;
485 IRRECO_PRINTF("Destroying layout: \"%s\" from index %u\n",
486 irreco_button_layout_get_name(layout), index);
488 irreco_window_manager_set_layout(user_window->manager, NULL);
489 irreco_string_table_remove_by_data(
490 irreco_data->irreco_layout_array, layout);
491 irreco_config_save_layouts(irreco_data);
493 if (index > 0) index--;
494 IRRECO_PRINTF("Displaying layout from index %u\n", index);
495 irreco_string_table_index(irreco_data->irreco_layout_array,
496 index, NULL,
497 (gpointer *) &irreco_layout);
498 irreco_window_manager_set_layout(user_window->manager,
499 irreco_layout);
502 IRRECO_RETURN
506 * Pop up a info message if the user has not created any remotes.
509 void irreco_window_user_show_remote(GtkButton *button,
510 IrrecoWindowUser *user_window)
512 IRRECO_ENTER
514 if (irreco_string_table_is_empty(
515 user_window->irreco_data->irreco_layout_array)) {
516 irreco_info_dlg(irreco_window_get_gtk_window(
517 user_window->window),
518 _(IRRECO_NO_REMOTE_HELP));
519 } else {
520 irreco_show_select_remote_dlg(user_window);
523 IRRECO_RETURN
526 void irreco_window_user_menu_about(GtkMenuItem * menuitem,
527 IrrecoWindowUser * user_window)
529 GError *error = NULL;
530 GdkPixbuf *icon = NULL;
531 GString *license = NULL;
532 const gchar *authors[] = { "Arto Karppinen <arto.karppinen@iki.fi>\n"
533 "Joni Kokko <t5kojo01@students.oamk.fi>\n"
534 "Harri Vattulainen <t5vaha01@students.oamk.fi>\n"
535 "Sami Mäki <kasmra@xob.kapsi.fi>\n"
536 "Sampo Savola <samposav@paju.oulu.fi>\n"
537 "Sami Parttimaa <t5pasa02@students.oamk.fi>\n"
538 "Pekka Gehör <pegu6@msn.com>\n",
539 NULL };
540 IRRECO_ENTER
542 license = g_string_new(NULL);
543 g_string_append(license,
544 "This program is free software; you can redistribute it and/or "
545 "modify it under the terms of the GNU General Public License "
546 "as published by the Free Software Foundation; either version 2 "
547 "of the License, or (at your option) any later version. "
548 "\n");
549 g_string_append(license,
550 "This program is distributed in the hope that it will be useful, "
551 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
552 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
553 "GNU General Public License for more details. "
554 "\n");
555 g_string_append(license,
556 "You should have received a copy of the GNU General Public "
557 "License along with this program; if not, write to the Free "
558 "Software Foundation, Inc., 51 Franklin Street, Fifth Floor, "
559 "Boston, MA 02110-1301, USA.");
561 IRRECO_PRINTF("Loading icon: \"%s\".\n", IRRECO_ICON);
562 icon = gdk_pixbuf_new_from_file(IRRECO_ICON, &error);
563 if (error != NULL) g_error_free(error);
565 gtk_show_about_dialog(
566 irreco_window_manager_get_gtk_window(user_window->manager),
567 "authors", authors,
568 "license", license->str,
569 "logo", icon,
570 "version", VERSION,
571 "website", "http://irreco.garage.maemo.org",
572 "wrap-license", TRUE,
573 NULL);
574 g_string_free(license, TRUE);
575 IRRECO_RETURN
578 gboolean irreco_window_user_key_press(GtkWidget * widget, GdkEventKey * event,
579 IrrecoWindowUser * user_window)
581 IrrecoCmdChain *chain;
582 IRRECO_ENTER
584 if (user_window->irreco_layout != NULL) {
585 if (event->keyval == IRRECO_HARDKEY_MENU ||
586 event->keyval == IRRECO_HARDKEY_HOME ) {
587 gchar *hardkey = irreco_hardkey_to_str(event->keyval);
588 IRRECO_PRINTF("Ignoring keyval \"%s\"\n", hardkey);
589 g_free(hardkey);
590 } else {
591 chain = irreco_hardkey_map_get_cmd_chain(
592 user_window->irreco_layout->hardkey_map,
593 event->keyval);
594 if (chain != NULL) {
595 irreco_window_user_execute_start(
596 user_window, chain, NULL);
600 IRRECO_RETURN_BOOL(FALSE);
603 gboolean irreco_window_user_window_state_event(GtkWidget *widget,
604 GdkEventWindowState *event,
605 IrrecoWindowUser *user_window)
607 IRRECO_ENTER
609 /* Syncronize menu option state with window fullscreen state. */
610 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
611 g_signal_handler_block(user_window->menu_fullscreen,
612 user_window->menu_fullscreen_handler);
614 if (event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN) {
615 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
616 user_window->menu_fullscreen), TRUE);
617 } else {
618 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
619 user_window->menu_fullscreen), FALSE);
622 g_signal_handler_unblock(user_window->menu_fullscreen,
623 user_window->menu_fullscreen_handler);
626 IRRECO_RETURN_BOOL(FALSE);
629 /** @} */
633 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
634 /* Functions */
635 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
638 * @name Public Functions
639 * @{
643 * Create dialog window and ask the user for remote name. If user gives the
644 * remote name and clicks create, a new IrrecoButtonLayout and edit user interface
645 * will be created.
647 gboolean irreco_window_user_create_new_remote(IrrecoData *irreco_data,
648 GtkWindow *parent)
650 gboolean loop = TRUE;
651 IrrecoInputDlg *input_dlg;
652 gboolean remote_created = FALSE;
653 IRRECO_ENTER
655 /* Create input dialog. */
656 input_dlg = IRRECO_INPUT_DLG(irreco_input_dlg_new(parent,
657 _("New remote")));
658 irreco_input_dlg_set_label(input_dlg, _("Name"));
660 /* Loop until we get a name, or user cancels. */
661 while (loop == TRUE && irreco_show_input_dlg(input_dlg)) {
662 const gchar *name = irreco_input_dlg_get_entry(input_dlg);
664 /* Does it exist already? */
665 if (irreco_string_table_exists(irreco_data->irreco_layout_array,
666 name)) {
667 irreco_error_dlg(GTK_WINDOW(input_dlg),
668 _(IRRECO_LAYOUT_NAME_COLLISION));
670 /* Create new layout. */
671 } else {
672 IrrecoButtonLayout *layout;
673 IrrecoCmdChain *chain;
674 IrrecoCmd *command;
676 /* Create button layout. */
677 layout = irreco_button_layout_create(
678 NULL, irreco_data->cmd_chain_manager);
679 irreco_button_layout_set_name(layout, name);
680 irreco_string_table_add(
681 irreco_data->irreco_layout_array,
682 irreco_button_layout_get_name(layout),
683 layout);
684 irreco_string_table_sort_abc(
685 irreco_data->irreco_layout_array);
687 /* Attach fullscreen command to fullscreen button. */
688 irreco_hardkey_map_assosiate_chain(
689 layout->hardkey_map, IRRECO_HARDKEY_FULLSCREEN);
690 chain = irreco_hardkey_map_get_cmd_chain(
691 layout->hardkey_map, IRRECO_HARDKEY_FULLSCREEN);
692 command = irreco_cmd_create();
693 irreco_cmd_set_builtin(
694 command, IRRECO_COMMAND_FULLSCREEN_TOGGLE);
695 irreco_cmd_chain_append(chain, command);
697 /* Attach next remote command to plus button. */
698 irreco_hardkey_map_assosiate_chain(
699 layout->hardkey_map, IRRECO_HARDKEY_PLUS);
700 chain = irreco_hardkey_map_get_cmd_chain(
701 layout->hardkey_map, IRRECO_HARDKEY_PLUS);
702 command = irreco_cmd_create();
703 irreco_cmd_set_builtin(
704 command, IRRECO_COMMAND_NEXT_REMOTE);
705 irreco_cmd_chain_append(chain, command);
707 /* Attach previous remote command to minus button. */
708 irreco_hardkey_map_assosiate_chain(
709 layout->hardkey_map, IRRECO_HARDKEY_MINUS);
710 chain = irreco_hardkey_map_get_cmd_chain(
711 layout->hardkey_map, IRRECO_HARDKEY_MINUS);
712 command = irreco_cmd_create();
713 irreco_cmd_set_builtin(
714 command, IRRECO_COMMAND_PREVIOUS_REMOTE);
715 irreco_cmd_chain_append(chain, command);
717 /* Set layout. */
718 irreco_window_manager_set_layout(
719 irreco_data->window_manager, layout);
720 loop = FALSE;
721 remote_created = TRUE;
725 gtk_widget_destroy(GTK_WIDGET(input_dlg));
726 IRRECO_RETURN_BOOL(remote_created);
729 /** @} */
730 /** @} */