ladishd: fix hidden connection save. Fix for #151
[ladish.git] / gui / dialogs.c
bloba178ba0c486ab3ea2316401ef3cf57ce27636837
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file implements dialogs that are not implemented in dedicated files
9 **************************************************************************
11 * LADI Session Handler is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * LADI Session Handler is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
23 * or write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "graph_view.h"
28 #include "gtk_builder.h"
30 static GtkWidget * g_name_dialog;
31 GtkWidget * g_app_dialog = NULL;
33 void run_custom_command_dialog(void)
35 graph_view_handle view;
36 guint result;
37 GtkEntry * command_entry = GTK_ENTRY(get_gtk_builder_widget("app_command_entry"));
38 GtkEntry * name_entry = GTK_ENTRY(get_gtk_builder_widget("app_name_entry"));
39 GtkToggleButton * terminal_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_terminal_check_button"));
40 GtkToggleButton * level0_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level0"));
41 GtkToggleButton * level1_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level1"));
42 GtkToggleButton * level2_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level2"));
43 GtkToggleButton * level3_button = GTK_TOGGLE_BUTTON(get_gtk_builder_widget("app_level3"));
44 uint8_t level;
46 view = get_current_view();
48 gtk_entry_set_text(name_entry, "");
49 gtk_entry_set_text(command_entry, "");
50 gtk_toggle_button_set_active(terminal_button, FALSE);
52 gtk_widget_set_sensitive(GTK_WIDGET(command_entry), TRUE);
53 gtk_widget_set_sensitive(GTK_WIDGET(terminal_button), TRUE);
54 gtk_widget_set_sensitive(GTK_WIDGET(level0_button), TRUE);
55 gtk_widget_set_sensitive(GTK_WIDGET(level1_button), TRUE);
57 gtk_window_set_focus(GTK_WINDOW(g_app_dialog), GTK_WIDGET(command_entry));
58 gtk_window_set_title(GTK_WINDOW(g_app_dialog), _("New application"));
60 gtk_widget_show(g_app_dialog);
62 result = gtk_dialog_run(GTK_DIALOG(g_app_dialog));
63 if (result == 2)
65 if (gtk_toggle_button_get_active(level0_button))
67 level = 0;
69 else if (gtk_toggle_button_get_active(level1_button))
71 level = 1;
73 else if (gtk_toggle_button_get_active(level2_button))
75 level = 2;
77 else if (gtk_toggle_button_get_active(level3_button))
79 level = 3;
81 else
83 log_error("unknown level");
84 ASSERT_NO_PASS;
85 level = 0;
88 log_info("'%s':'%s' %s level %"PRIu8, gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button) ? "terminal" : "shell", level);
89 if (!app_run_custom(
90 view,
91 gtk_entry_get_text(command_entry),
92 gtk_entry_get_text(name_entry),
93 gtk_toggle_button_get_active(terminal_button),
94 level))
96 error_message_box(_("Execution failed. I know you want to know more for the reson but currently you can only check the log file."));
100 gtk_widget_hide(g_app_dialog);
103 bool name_dialog(const char * title, const char * object, const char * old_name, char ** new_name)
105 guint result;
106 bool ok;
107 GtkEntry * entry = GTK_ENTRY(get_gtk_builder_widget("name_entry"));
109 gtk_window_set_title(GTK_WINDOW(g_app_dialog), title);
111 gtk_widget_show(g_name_dialog);
113 gtk_label_set_text(GTK_LABEL(get_gtk_builder_widget("name_label")), object);
114 gtk_entry_set_text(entry, old_name);
115 gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
117 result = gtk_dialog_run(GTK_DIALOG(g_name_dialog));
118 ok = result == 2;
119 if (ok)
121 *new_name = strdup(gtk_entry_get_text(entry));
122 if (*new_name == NULL)
124 log_error("strdup failed for new name (name_dialog)");
125 ok = false;
129 gtk_widget_hide(g_name_dialog);
131 return ok;
134 void error_message_box(const char * failed_operation)
136 GtkWidget * dialog;
137 dialog = get_gtk_builder_widget("error_dialog");
138 gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), _("<b><big>Error</big></b>"));
139 gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), "%s", failed_operation);
140 gtk_widget_show(dialog);
141 gtk_dialog_run(GTK_DIALOG(dialog));
142 gtk_widget_hide(dialog);
145 void menu_request_start_app(void)
147 run_custom_command_dialog();
150 void init_dialogs(void)
152 g_name_dialog = get_gtk_builder_widget("name_dialog");
153 g_app_dialog = get_gtk_builder_widget("app_dialog");