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"
28 * @addtogroup IrrecoWindowUser
31 * User interface for using button layouts.
38 * Source file of @ref IrrecoWindowUser.
42 void irreco_window_user_draw_background(IrrecoWindowUser
* user_window
);
43 void irreco_window_user_main_menu_create(IrrecoWindowUser
* user_window
);
44 void irreco_window_user_create_show_remote_menu(IrrecoWindowUser
* user_window
);
45 void irreco_window_user_create_show_remote_menu_foreach(IrrecoButtonLayout
* layout
,
47 void irreco_window_user_new_remote(GtkMenuItem
* menuitem
, IrrecoWindowUser
* user_window
);
48 void irreco_window_user_edit_remote(GtkMenuItem
* menuitem
, IrrecoWindowUser
* user_window
);
49 void irreco_window_user_main_menu_rename(GtkMenuItem
* menuitem
,
50 IrrecoWindowUser
* user_window
);
51 void irreco_window_user_delete_remote(GtkMenuItem
* menuitem
,
52 IrrecoWindowUser
* user_window
);
53 void irreco_window_user_show_remote(GtkMenuItem
* menuitem
, IrrecoWindowUser
* user_window
);
54 void irreco_window_user_menu_about(GtkMenuItem
* menuitem
, IrrecoWindowUser
* user_window
);
55 void irreco_window_user_show_remote_menu(GtkMenuItem
* menuitem
, IrrecoButtonLayout
* layout
);
56 void irreco_window_user_button_release(IrrecoButton
* irreco_button
,
57 IrrecoWindowUser
* user_window
);
58 void irreco_window_user_execute_start(IrrecoWindowUser
* user_window
,
59 IrrecoCmdChain
* cmd_chain
,
60 IrrecoButton
* irreco_button
);
61 void irreco_window_user_execute_finish(IrrecoCmdChain
* cmd_chain
,
62 IrrecoWindowUser
* user_window
);
63 void irreco_window_user_fullscreen_toggled(GtkCheckMenuItem
* checkmenuitem
,
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
);
73 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
75 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
83 * Crate and display IrrecoWindowUser.
85 * @param irreco_layout IrrecoButtonLayout to display. If NULL, attempts to
86 * display first layout from
87 * irreco_data->irreco_layout_array.
89 IrrecoWindowUser
*irreco_window_user_create(IrrecoWindowManager
* manager
)
91 IrrecoData
*irreco_data
= manager
->irreco_data
;
92 IrrecoWindowUser
*user_window
;
95 user_window
= g_slice_new0(IrrecoWindowUser
);
96 user_window
->manager
= manager
;
97 user_window
->irreco_data
= irreco_data
;
98 user_window
->window
= irreco_window_create();
100 irreco_window_user_main_menu_create(user_window
);
101 irreco_window_user_create_show_remote_menu(user_window
);
103 g_signal_connect(G_OBJECT(user_window
->window
),
105 G_CALLBACK(irreco_window_user_key_press
),
107 g_signal_connect(G_OBJECT(user_window
->window
),
108 "window-state-event",
109 G_CALLBACK(irreco_window_user_window_state_event
),
111 IRRECO_RETURN_PTR(user_window
);
114 void irreco_window_user_destroy(IrrecoWindowUser
* user_window
)
117 if (user_window
->irreco_layout
!= NULL
) {
118 irreco_button_layout_reset(user_window
->irreco_layout
);
121 irreco_window_destroy(user_window
->window
);
122 g_slice_free(IrrecoWindowUser
, user_window
);
127 * Set and display layout, or, if NULL is given, unset layout.
129 void irreco_window_user_set_layout(IrrecoWindowUser
* user_window
,
130 IrrecoButtonLayout
* layout
)
134 if (user_window
->irreco_layout
!= NULL
) {
136 irreco_button_layout_reset(user_window
->irreco_layout
);
141 if (irreco_string_table_is_empty(
142 user_window
->irreco_data
->irreco_layout_array
)) {
143 gtk_widget_set_sensitive(
144 GTK_WIDGET(user_window
->menu_show_remote
), FALSE
);
146 gtk_widget_set_sensitive(
147 GTK_WIDGET(user_window
->menu_show_remote
), TRUE
);
150 if (layout
== NULL
) {
151 IRRECO_PRINTF("Layout unset.\n");
152 user_window
->irreco_layout
= NULL
;
154 /* Disable menu entries. */
155 gtk_widget_set_sensitive(
156 GTK_WIDGET(user_window
->menu_edit_remote
), FALSE
);
157 gtk_widget_set_sensitive(
158 GTK_WIDGET(user_window
->menu_rename_remote
), FALSE
);
159 gtk_widget_set_sensitive(
160 GTK_WIDGET(user_window
->menu_delete_remote
), FALSE
);
164 /* Enable menu entries. */
165 gtk_widget_set_sensitive(
166 GTK_WIDGET(user_window
->menu_edit_remote
), TRUE
);
167 gtk_widget_set_sensitive(
168 GTK_WIDGET(user_window
->menu_rename_remote
), TRUE
);
169 gtk_widget_set_sensitive(
170 GTK_WIDGET(user_window
->menu_delete_remote
), TRUE
);
174 IRRECO_PRINTF("Displaying layout \"%s\".\n",
175 irreco_button_layout_get_name(layout
));
176 irreco_button_layout_reset(layout
);
178 user_window
->irreco_layout
= layout
;
180 irreco_button_layout_set_container(layout
, user_window
->window
->layout
);
182 irreco_button_layout_create_widgets(layout
);
183 irreco_button_layout_set_press_callback(layout
, irreco_button_down
);
184 irreco_button_layout_set_release_callback(
185 layout
, irreco_window_user_button_release
);
186 irreco_button_layout_set_callback_data(layout
, user_window
);
187 irreco_window_user_draw_background(user_window
);
188 irreco_window_user_create_show_remote_menu(user_window
);
192 void irreco_window_user_draw_background(IrrecoWindowUser
* user_window
)
195 const GdkColor
*color
;
197 irreco_button_layout_get_bg(user_window
->irreco_layout
, &image
, &color
);
198 irreco_window_set_background_image(user_window
->window
, color
,
208 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
210 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
218 * Button release callback handler.
220 void irreco_window_user_button_release(IrrecoButton
* irreco_button
,
221 IrrecoWindowUser
* user_window
)
224 irreco_window_user_execute_start(
226 irreco_button_get_cmd_chain(irreco_button
),
232 void irreco_window_user_execute_start(IrrecoWindowUser
* user_window
,
233 IrrecoCmdChain
* cmd_chain
,
234 IrrecoButton
* irreco_button
)
237 if (irreco_cmd_chain_execute(cmd_chain
, user_window
->irreco_data
,
238 G_FUNC(irreco_window_user_execute_finish
),
240 user_window
->execution_button
= irreco_button
;
241 user_window
->executing_cmd_chain
= TRUE
;
242 gtk_widget_set_sensitive(user_window
->menu
, FALSE
);
243 gtk_widget_set_sensitive(user_window
->window
->scrolled_window
,
246 } else if (irreco_button
!= NULL
) {
247 irreco_button_up(irreco_button
);
252 void irreco_window_user_execute_finish(IrrecoCmdChain
* cmd_chain
,
253 IrrecoWindowUser
* user_window
)
257 gtk_widget_set_sensitive(user_window
->menu
, TRUE
);
258 gtk_widget_set_sensitive(user_window
->window
->scrolled_window
, TRUE
);
259 if (user_window
->execution_button
!= NULL
) {
260 irreco_button_up(user_window
->execution_button
);
263 user_window
->executing_cmd_chain
= FALSE
;
264 user_window
->execution_button
= NULL
;
273 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
275 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
282 void irreco_window_user_main_menu_create(IrrecoWindowUser
* user_window
)
287 user_window
->menu
= gtk_menu_new();
288 user_window
->menu_new_remote
=
289 gtk_menu_item_new_with_label(_("New remote"));
290 user_window
->menu_edit_remote
=
291 gtk_menu_item_new_with_label(_("Edit remote"));
292 user_window
->menu_rename_remote
=
293 gtk_menu_item_new_with_label(_("Rename remote"));
294 user_window
->menu_delete_remote
=
295 gtk_menu_item_new_with_label(_("Delete remote"));
296 user_window
->menu_show_remote
=
297 gtk_menu_item_new_with_label(_("Show remote"));
298 user_window
->menu_fullscreen
=
299 gtk_check_menu_item_new_with_mnemonic(_("Fullscreen"));
300 user_window
->menu_about
=
301 gtk_menu_item_new_with_label(_("About"));
303 gtk_menu_append(user_window
->menu
, user_window
->menu_new_remote
);
304 gtk_menu_append(user_window
->menu
, user_window
->menu_edit_remote
);
305 gtk_menu_append(user_window
->menu
, user_window
->menu_rename_remote
);
306 gtk_menu_append(user_window
->menu
, user_window
->menu_delete_remote
);
307 gtk_menu_append(user_window
->menu
, gtk_separator_menu_item_new());
308 gtk_menu_append(user_window
->menu
, user_window
->menu_show_remote
);
309 gtk_menu_append(user_window
->menu
, user_window
->menu_fullscreen
);
310 gtk_menu_append(user_window
->menu
, gtk_separator_menu_item_new());
311 gtk_menu_append(user_window
->menu
, user_window
->menu_about
);
314 hildon_window_set_menu(HILDON_WINDOW(user_window
->window
),
315 GTK_MENU(user_window
->menu
));
316 gtk_menu_item_set_submenu(GTK_MENU_ITEM(user_window
->menu_show_remote
),
318 gtk_widget_show_all(user_window
->menu
);
320 /* Connect signals. */
321 g_signal_connect(G_OBJECT(user_window
->menu_new_remote
),
323 G_CALLBACK(irreco_window_user_new_remote
),
325 g_signal_connect(G_OBJECT(user_window
->menu_edit_remote
),
327 G_CALLBACK(irreco_window_user_edit_remote
),
329 g_signal_connect(G_OBJECT(user_window
->menu_rename_remote
), "activate",
330 G_CALLBACK(irreco_window_user_main_menu_rename
),
332 g_signal_connect(G_OBJECT(user_window
->menu_delete_remote
),
334 G_CALLBACK(irreco_window_user_delete_remote
),
336 g_signal_connect(G_OBJECT(user_window
->menu_show_remote
),
338 G_CALLBACK(irreco_window_user_show_remote
),
340 user_window
->menu_fullscreen_handler
= g_signal_connect(
341 G_OBJECT(user_window
->menu_fullscreen
),
343 G_CALLBACK(irreco_window_user_fullscreen_toggled
),
345 g_signal_connect(G_OBJECT(user_window
->menu_about
),
347 G_CALLBACK(irreco_window_user_menu_about
),
353 * Generates buttons submenu just in time.
355 void irreco_window_user_create_show_remote_menu(IrrecoWindowUser
* user_window
)
357 GtkWidget
*menu
= NULL
;
358 IrrecoStringTable
*table
= NULL
;
359 GCallback callback
= G_CALLBACK(irreco_window_user_show_remote_menu
);
360 GSList
*group
= NULL
;
361 GtkWidget
* item
= NULL
;
364 g_assert(user_window
!= NULL
);
366 /* Generate ratio button menu. */
367 menu
= gtk_menu_new();
368 table
= user_window
->irreco_data
->irreco_layout_array
;
369 IRRECO_STRING_TABLE_FOREACH(table
, key
, IrrecoButtonLayout
*, layout
)
371 /* Create menuitem. */
372 item
= gtk_radio_menu_item_new_with_label(
373 group
, irreco_button_layout_get_name(layout
));
374 group
= gtk_radio_menu_item_get_group(
375 GTK_RADIO_MENU_ITEM(item
));
376 gtk_menu_append(menu
, item
);
378 /* Attach user window pointer to object. */
379 g_object_set_data(G_OBJECT(item
), "IrrecoWindowUser",
382 /* Check currently active layout. */
383 if (layout
== user_window
->irreco_layout
) {
384 gtk_check_menu_item_set_active(
385 GTK_CHECK_MENU_ITEM(item
), TRUE
);
387 g_signal_connect(G_OBJECT(item
), "activate", callback
, layout
);
388 IRRECO_STRING_TABLE_FOREACH_END
390 gtk_menu_item_set_submenu(GTK_MENU_ITEM(user_window
->menu_show_remote
),
392 gtk_widget_show_all(menu
);
401 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
402 /* Main menu callback functions. */
403 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
406 * @name Main menu callback functions
411 * Create dialog window and ask the user for remote name. If user gives the
412 * remote name and clicks create, a new IrrecoButtonLayout and edit user interface
415 void irreco_window_user_new_remote(GtkMenuItem
* menuitem
, IrrecoWindowUser
* user_window
)
417 IrrecoData
*irreco_data
= user_window
->irreco_data
;
418 GtkWindow
*parent
= irreco_window_get_gtk_window(user_window
->window
);
420 if (irreco_window_user_create_new_remote(irreco_data
, parent
)) {
421 irreco_window_manager_show(irreco_data
->window_manager
,
428 void irreco_window_user_edit_remote(GtkMenuItem
* menuitem
, IrrecoWindowUser
* user_window
)
430 IrrecoData
*irreco_data
= user_window
->irreco_data
;
433 if (irreco_string_table_is_empty(irreco_data
->irreco_layout_array
)) {
434 irreco_info_dlg(irreco_window_get_gtk_window(user_window
->window
),
435 _(IRRECO_NO_REMOTE_HELP
));
437 irreco_window_manager_set_layout(user_window
->manager
,
438 user_window
->irreco_layout
);
439 irreco_window_manager_show(user_window
->manager
,
446 void irreco_window_user_main_menu_rename(GtkMenuItem
* menuitem
,
447 IrrecoWindowUser
* user_window
)
449 IrrecoInputDlg
*input
;
452 IRRECO_PRINTF("%p\n", (void *) user_window
);
454 /* Create input dialog. */
455 input
= IRRECO_INPUT_DLG(irreco_input_dlg_new(
456 irreco_window_get_gtk_window(
457 user_window
->window
), _("Rename remote")));
458 irreco_input_dlg_set_label(input
, _("Name"));
459 irreco_input_dlg_set_ok_button_text(input
, _("Rename"));
460 irreco_input_dlg_set_entry(input
, irreco_button_layout_get_name(
461 user_window
->irreco_layout
));
463 /* Loop until cancel or successfull rename. */
465 if (irreco_show_input_dlg(input
) == FALSE
) break;
466 if (irreco_string_table_change_key(
467 user_window
->irreco_data
->irreco_layout_array
,
468 irreco_button_layout_get_name(
469 user_window
->irreco_layout
),
470 irreco_input_dlg_get_entry(input
)) == TRUE
) break;
471 irreco_error_dlg(GTK_WINDOW(input
),
472 _(IRRECO_LAYOUT_NAME_COLLISION
));
475 irreco_config_save_layouts(user_window
->irreco_data
);
476 irreco_window_user_create_show_remote_menu(user_window
);
477 gtk_widget_destroy(GTK_WIDGET(input
));
481 void irreco_window_user_delete_remote(GtkMenuItem
* menuitem
,
482 IrrecoWindowUser
* user_window
)
485 IrrecoButtonLayout
*irreco_layout
= NULL
;
486 IrrecoData
* irreco_data
= user_window
->irreco_data
;
489 /* Do we have anything to destroy? */
490 if (user_window
->irreco_layout
== NULL
) {
491 irreco_info_dlg(irreco_window_get_gtk_window(
492 user_window
->window
),
493 _(IRRECO_NO_REMOTE_HELP
));
495 /* If we can get the index of the current layout, and user agrees,
496 then destroy the layout. */
498 irreco_string_table_get_index(irreco_data
->irreco_layout_array
,
499 user_window
->irreco_layout
, &index
) &&
500 irreco_yes_no_dlg(irreco_window_get_gtk_window(user_window
->window
),
501 _("Delete remote?"))) {
503 IrrecoButtonLayout
* layout
= user_window
->irreco_layout
;
504 IRRECO_PRINTF("Destroying layout: \"%s\" from index %u\n",
505 irreco_button_layout_get_name(layout
), index
);
507 irreco_window_manager_set_layout(user_window
->manager
, NULL
);
508 irreco_string_table_remove_by_data(
509 irreco_data
->irreco_layout_array
, layout
);
510 irreco_config_save_layouts(irreco_data
);
512 if (index
> 0) index
--;
513 IRRECO_PRINTF("Displaying layout from index %u\n", index
);
514 irreco_string_table_index(irreco_data
->irreco_layout_array
,
516 (gpointer
*) &irreco_layout
);
517 irreco_window_user_set_layout(user_window
, irreco_layout
);
524 * Pop up a info message if the user has not created any remotes.
526 void irreco_window_user_show_remote(GtkMenuItem
* menuitem
,
527 IrrecoWindowUser
* user_window
)
532 if (irreco_string_table_is_empty(
533 user_window->irreco_data->irreco_layout_array)) {
534 irreco_info_dlg(irreco_window_get_gtk_window(
535 user_window->window),
536 _(IRRECO_NO_REMOTE_HELP));
538 irreco_window_user_create_show_remote_menu(user_window);
545 void irreco_window_user_show_remote_menu(GtkMenuItem
* menuitem
,
546 IrrecoButtonLayout
* layout
)
548 IrrecoWindowUser
*user_window
;
551 if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem
))) {
552 user_window
= (IrrecoWindowUser
*) g_object_get_data(
553 G_OBJECT(menuitem
), "IrrecoWindowUser");
554 g_assert(user_window
!= NULL
);
555 irreco_window_manager_set_layout(user_window
->manager
, layout
);
561 void irreco_window_user_fullscreen_toggled(GtkCheckMenuItem
* checkmenuitem
,
562 IrrecoWindowUser
* user_window
)
565 irreco_window_toggle_fullscreen(user_window
->window
);
569 void irreco_window_user_menu_about(GtkMenuItem
* menuitem
,
570 IrrecoWindowUser
* user_window
)
572 GError
*error
= NULL
;
573 GdkPixbuf
*icon
= NULL
;
574 GString
*license
= NULL
;
575 const gchar
*authors
[] = { "Arto Karppinen <arto.karppinen@iki.fi>\n"
576 "Joni Kokko <t5kojo01@students.oamk.fi>\n"
577 "Harri Vattulainen <t5vaha01@students.oamk.fi>\n"
578 "Sami Mäki <kasmra@xob.kapsi.fi>\n"
579 "Sampo Savola <samposav@paju.oulu.fi>\n"
580 "Sami Parttimaa <t5pasa02@students.oamk.fi>\n"
581 "Pekka Gehör <pegu6@msn.com>\n",
585 license
= g_string_new(NULL
);
586 g_string_append(license
,
587 "This program is free software; you can redistribute it and/or "
588 "modify it under the terms of the GNU General Public License "
589 "as published by the Free Software Foundation; either version 2 "
590 "of the License, or (at your option) any later version. "
592 g_string_append(license
,
593 "This program is distributed in the hope that it will be useful, "
594 "but WITHOUT ANY WARRANTY; without even the implied warranty of "
595 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
596 "GNU General Public License for more details. "
598 g_string_append(license
,
599 "You should have received a copy of the GNU General Public "
600 "License along with this program; if not, write to the Free "
601 "Software Foundation, Inc., 51 Franklin Street, Fifth Floor, "
602 "Boston, MA 02110-1301, USA.");
604 IRRECO_PRINTF("Loading icon: \"%s\".\n", IRRECO_ICON
);
605 icon
= gdk_pixbuf_new_from_file(IRRECO_ICON
, &error
);
606 if (error
!= NULL
) g_error_free(error
);
608 gtk_show_about_dialog(
609 irreco_window_manager_get_gtk_window(user_window
->manager
),
611 "license", license
->str
,
614 "website", "http://irreco.garage.maemo.org",
615 "wrap-license", TRUE
,
617 g_string_free(license
, TRUE
);
621 gboolean
irreco_window_user_key_press(GtkWidget
* widget
, GdkEventKey
* event
,
622 IrrecoWindowUser
* user_window
)
624 IrrecoCmdChain
*chain
;
627 if (user_window
->irreco_layout
!= NULL
) {
628 if (event
->keyval
== IRRECO_HARDKEY_MENU
||
629 event
->keyval
== IRRECO_HARDKEY_HOME
) {
630 gchar
*hardkey
= irreco_hardkey_to_str(event
->keyval
);
631 IRRECO_PRINTF("Ignoring keyval \"%s\"\n", hardkey
);
634 chain
= irreco_hardkey_map_get_cmd_chain(
635 user_window
->irreco_layout
->hardkey_map
,
638 irreco_window_user_execute_start(
639 user_window
, chain
, NULL
);
643 IRRECO_RETURN_BOOL(FALSE
);
646 gboolean
irreco_window_user_window_state_event(GtkWidget
*widget
,
647 GdkEventWindowState
*event
,
648 IrrecoWindowUser
*user_window
)
652 /* Syncronize menu option state with window fullscreen state. */
653 if (event
->changed_mask
& GDK_WINDOW_STATE_FULLSCREEN
) {
654 g_signal_handler_block(user_window
->menu_fullscreen
,
655 user_window
->menu_fullscreen_handler
);
657 if (event
->new_window_state
& GDK_WINDOW_STATE_FULLSCREEN
) {
658 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
659 user_window
->menu_fullscreen
), TRUE
);
661 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
662 user_window
->menu_fullscreen
), FALSE
);
665 g_signal_handler_unblock(user_window
->menu_fullscreen
,
666 user_window
->menu_fullscreen_handler
);
669 IRRECO_RETURN_BOOL(FALSE
);
676 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
678 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
681 * @name Public Functions
686 * Create dialog window and ask the user for remote name. If user gives the
687 * remote name and clicks create, a new IrrecoButtonLayout and edit user interface
690 gboolean
irreco_window_user_create_new_remote(IrrecoData
*irreco_data
,
693 gboolean loop
= TRUE
;
694 IrrecoInputDlg
*input_dlg
;
695 gboolean remote_created
= FALSE
;
698 /* Create input dialog. */
699 input_dlg
= IRRECO_INPUT_DLG(irreco_input_dlg_new(parent
,
701 irreco_input_dlg_set_label(input_dlg
, _("Name"));
702 irreco_input_dlg_set_ok_button_text(input_dlg
, _("Create"));
704 /* Loop until we get a name, or user cancels. */
705 while (loop
== TRUE
&& irreco_show_input_dlg(input_dlg
)) {
706 const gchar
*name
= irreco_input_dlg_get_entry(input_dlg
);
708 /* Does it exist already? */
709 if (irreco_string_table_exists(irreco_data
->irreco_layout_array
,
711 irreco_error_dlg(GTK_WINDOW(input_dlg
),
712 _(IRRECO_LAYOUT_NAME_COLLISION
));
714 /* Create new layout. */
716 IrrecoButtonLayout
*layout
;
717 IrrecoCmdChain
*chain
;
720 /* Create button layout. */
721 layout
= irreco_button_layout_create(
722 NULL
, irreco_data
->cmd_chain_manager
);
723 irreco_button_layout_set_name(layout
, name
);
724 irreco_string_table_add(
725 irreco_data
->irreco_layout_array
,
726 irreco_button_layout_get_name(layout
),
728 irreco_string_table_sort_abc(
729 irreco_data
->irreco_layout_array
);
731 /* Attach fullscreen command to fullscreen button. */
732 irreco_hardkey_map_assosiate_chain(
733 layout
->hardkey_map
, IRRECO_HARDKEY_FULLSCREEN
);
734 chain
= irreco_hardkey_map_get_cmd_chain(
735 layout
->hardkey_map
, IRRECO_HARDKEY_FULLSCREEN
);
736 command
= irreco_cmd_create();
737 irreco_cmd_set_builtin(
738 command
, IRRECO_COMMAND_FULLSCREEN_TOGGLE
);
739 irreco_cmd_chain_append(chain
, command
);
741 /* Attach next remote command to plus button. */
742 irreco_hardkey_map_assosiate_chain(
743 layout
->hardkey_map
, IRRECO_HARDKEY_PLUS
);
744 chain
= irreco_hardkey_map_get_cmd_chain(
745 layout
->hardkey_map
, IRRECO_HARDKEY_PLUS
);
746 command
= irreco_cmd_create();
747 irreco_cmd_set_builtin(
748 command
, IRRECO_COMMAND_NEXT_REMOTE
);
749 irreco_cmd_chain_append(chain
, command
);
751 /* Attach previous remote command to minus button. */
752 irreco_hardkey_map_assosiate_chain(
753 layout
->hardkey_map
, IRRECO_HARDKEY_MINUS
);
754 chain
= irreco_hardkey_map_get_cmd_chain(
755 layout
->hardkey_map
, IRRECO_HARDKEY_MINUS
);
756 command
= irreco_cmd_create();
757 irreco_cmd_set_builtin(
758 command
, IRRECO_COMMAND_PREVIOUS_REMOTE
);
759 irreco_cmd_chain_append(chain
, command
);
762 irreco_window_manager_set_layout(
763 irreco_data
->window_manager
, layout
);
765 remote_created
= TRUE
;
769 gtk_widget_destroy(GTK_WIDGET(input_dlg
));
770 IRRECO_RETURN_BOOL(remote_created
);