ladishd: fix introspection data for AppSupervisor.IsAppRunning
[ladish.git] / gui / menu.c
blobb2138fa38821a1d8deb35e06a2105233808d2806
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 contains menu related code
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 "internal.h"
28 #include "menu.h"
29 #include "gtk_builder.h"
30 #include "studio.h"
32 static GtkWidget * g_menu_item_new_studio;
33 static GtkWidget * g_menu_item_start_studio;
34 static GtkWidget * g_menu_item_stop_studio;
35 static GtkWidget * g_menu_item_save_studio;
36 static GtkWidget * g_menu_item_save_as_studio;
37 static GtkWidget * g_menu_item_unload_studio;
38 static GtkWidget * g_menu_item_rename_studio;
39 static GtkWidget * g_menu_item_create_room;
40 static GtkWidget * g_menu_item_destroy_room;
41 static GtkWidget * g_menu_item_load_project;
42 static GtkWidget * g_menu_item_unload_project;
43 static GtkWidget * g_menu_item_save_project;
44 static GtkWidget * g_menu_item_save_as_project;
45 static GtkWidget * g_menu_item_daemon_exit;
46 static GtkWidget * g_menu_item_jack_configure;
47 static GtkCheckMenuItem * g_menu_item_jack_latency_32;
48 static GtkCheckMenuItem * g_menu_item_jack_latency_64;
49 static GtkCheckMenuItem * g_menu_item_jack_latency_128;
50 static GtkCheckMenuItem * g_menu_item_jack_latency_256;
51 static GtkCheckMenuItem * g_menu_item_jack_latency_512;
52 static GtkCheckMenuItem * g_menu_item_jack_latency_1024;
53 static GtkCheckMenuItem * g_menu_item_jack_latency_2048;
54 static GtkCheckMenuItem * g_menu_item_jack_latency_4096;
55 static GtkCheckMenuItem * g_menu_item_jack_latency_8192;
56 static GtkWidget * g_menu_item_view_toolbar;
57 static GtkWidget * g_menu_item_view_raw_jack;
58 static GtkWidget * g_menu_item_start_app;
60 static bool g_latency_changing;
62 typedef void (* menu_request_toggle_func)(bool visible);
64 static void toggled(GtkCheckMenuItem * checkmenuitem, gpointer user_data)
66 ((menu_request_toggle_func)user_data)(gtk_check_menu_item_get_active(checkmenuitem));
69 static void buffer_size_change_request(GtkCheckMenuItem * item_ptr, gpointer user_data)
71 if (g_latency_changing)
72 { /* skip activations because of gtk_check_menu_item_set_active() called from menu_set_jack_latency() */
73 return;
76 if (!item_ptr->active)
77 { /* skip radio button deactivations, we are interested only in activations */
78 return;
81 menu_request_jack_latency_change((uint32_t)(guintptr)user_data);
84 void menu_init(void)
86 g_menu_item_new_studio = get_gtk_builder_widget("menu_item_new_studio");
87 g_menu_item_start_app = get_gtk_builder_widget("menu_item_start_app");
88 g_menu_item_start_studio = get_gtk_builder_widget("menu_item_start_studio");
89 g_menu_item_stop_studio = get_gtk_builder_widget("menu_item_stop_studio");
90 g_menu_item_save_studio = get_gtk_builder_widget("menu_item_save_studio");
91 g_menu_item_save_as_studio = get_gtk_builder_widget("menu_item_save_as_studio");
92 g_menu_item_unload_studio = get_gtk_builder_widget("menu_item_unload_studio");
93 g_menu_item_rename_studio = get_gtk_builder_widget("menu_item_rename_studio");
94 g_menu_item_create_room = get_gtk_builder_widget("menu_item_create_room");
95 g_menu_item_destroy_room = get_gtk_builder_widget("menu_item_destroy_room");
96 g_menu_item_load_project = get_gtk_builder_widget("menu_item_load_project");
97 g_menu_item_unload_project = get_gtk_builder_widget("menu_item_unload_project");
98 g_menu_item_save_project = get_gtk_builder_widget("menu_item_save_project");
99 g_menu_item_save_as_project = get_gtk_builder_widget("menu_item_save_as_project");
100 g_menu_item_daemon_exit = get_gtk_builder_widget("menu_item_daemon_exit");
101 g_menu_item_jack_configure = get_gtk_builder_widget("menu_item_jack_configure");
102 g_menu_item_view_toolbar = get_gtk_builder_widget("menu_item_view_toolbar");
103 g_menu_item_view_raw_jack = get_gtk_builder_widget("menu_item_view_raw_jack");
105 g_menu_item_jack_latency_32 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_32"));
106 g_menu_item_jack_latency_64 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_64"));
107 g_menu_item_jack_latency_128 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_128"));
108 g_menu_item_jack_latency_256 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_256"));
109 g_menu_item_jack_latency_512 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_512"));
110 g_menu_item_jack_latency_1024 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_1024"));
111 g_menu_item_jack_latency_2048 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_2048"));
112 g_menu_item_jack_latency_4096 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_4096"));
113 g_menu_item_jack_latency_8192 = GTK_CHECK_MENU_ITEM(get_gtk_builder_widget("menu_item_jack_latency_8192"));
115 g_signal_connect(G_OBJECT(g_menu_item_view_toolbar), "toggled", G_CALLBACK(toggled), menu_request_toggle_toolbar);
116 g_signal_connect(G_OBJECT(g_menu_item_view_raw_jack), "toggled", G_CALLBACK(toggled), menu_request_toggle_raw_jack);
118 g_signal_connect(G_OBJECT(g_menu_item_new_studio), "activate", G_CALLBACK(menu_request_new_studio), NULL);
119 g_signal_connect(G_OBJECT(g_menu_item_start_studio), "activate", G_CALLBACK(menu_request_start_studio), NULL);
120 g_signal_connect(G_OBJECT(g_menu_item_stop_studio), "activate", G_CALLBACK(menu_request_stop_studio), NULL);
121 g_signal_connect(G_OBJECT(g_menu_item_unload_studio), "activate", G_CALLBACK(menu_request_unload_studio), NULL);
122 g_signal_connect(G_OBJECT(g_menu_item_save_studio), "activate", G_CALLBACK(menu_request_save_studio), NULL);
123 g_signal_connect(G_OBJECT(g_menu_item_save_as_studio), "activate", G_CALLBACK(menu_request_save_as_studio), NULL);
124 g_signal_connect(G_OBJECT(g_menu_item_rename_studio), "activate", G_CALLBACK(menu_request_rename_studio), NULL);
125 g_signal_connect(G_OBJECT(g_menu_item_daemon_exit), "activate", G_CALLBACK(menu_request_daemon_exit), NULL);
126 g_signal_connect(G_OBJECT(g_menu_item_jack_configure), "activate", G_CALLBACK(menu_request_jack_configure), NULL);
127 g_signal_connect(G_OBJECT(g_menu_item_start_app), "activate", G_CALLBACK(menu_request_start_app), NULL);
128 g_signal_connect(G_OBJECT(g_menu_item_create_room), "activate", G_CALLBACK(menu_request_create_room), NULL);
129 g_signal_connect(G_OBJECT(g_menu_item_destroy_room), "activate", G_CALLBACK(menu_request_destroy_room), NULL);
130 g_signal_connect(G_OBJECT(g_menu_item_load_project), "activate", G_CALLBACK(menu_request_load_project), NULL);
131 g_signal_connect(G_OBJECT(g_menu_item_unload_project), "activate", G_CALLBACK(menu_request_unload_project), NULL);
132 g_signal_connect(G_OBJECT(g_menu_item_save_project), "activate", G_CALLBACK(menu_request_save_project), NULL);
133 g_signal_connect(G_OBJECT(g_menu_item_save_as_project), "activate", G_CALLBACK(menu_request_save_as_project), NULL);
135 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_32), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)32);
136 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_64), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)64);
137 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_128), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)128);
138 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_256), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)256);
139 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_512), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)512);
140 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_1024), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)1024);
141 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_2048), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)2048);
142 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_4096), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)4096);
143 g_signal_connect(G_OBJECT(g_menu_item_jack_latency_8192), "toggled", G_CALLBACK(buffer_size_change_request), (gpointer)8192);
146 void menu_studio_state_changed(unsigned int studio_state)
148 gtk_widget_set_sensitive(g_menu_item_start_studio, studio_state == STUDIO_STATE_STOPPED);
149 gtk_widget_set_sensitive(g_menu_item_stop_studio, studio_state == STUDIO_STATE_STARTED);
150 gtk_widget_set_sensitive(g_menu_item_save_studio, studio_state == STUDIO_STATE_STARTED);
151 gtk_widget_set_sensitive(g_menu_item_save_as_studio, studio_state == STUDIO_STATE_STARTED);
152 gtk_widget_set_sensitive(g_menu_item_unload_studio, studio_state != STUDIO_STATE_UNLOADED);
153 gtk_widget_set_sensitive(g_menu_item_rename_studio, studio_state == STUDIO_STATE_STOPPED || studio_state == STUDIO_STATE_STARTED);
154 gtk_widget_set_sensitive(g_menu_item_start_app, studio_state == STUDIO_STATE_STOPPED || studio_state == STUDIO_STATE_STARTED);
155 gtk_widget_set_sensitive(g_menu_item_create_room, studio_state == STUDIO_STATE_STOPPED || studio_state == STUDIO_STATE_STARTED);
158 void menu_set_jack_latency_items_sensivity(bool sensitive)
160 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_32), sensitive);
161 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_64), sensitive);
162 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_128), sensitive);
163 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_256), sensitive);
164 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_512), sensitive);
165 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_1024), sensitive);
166 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_2048), sensitive);
167 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_4096), sensitive);
168 gtk_widget_set_sensitive(GTK_WIDGET(g_menu_item_jack_latency_8192), sensitive);
171 bool menu_set_jack_latency(uint32_t buffer_size, bool force)
173 GtkCheckMenuItem * item_ptr;
175 switch (buffer_size)
177 case 32:
178 item_ptr = g_menu_item_jack_latency_32;
179 break;
180 case 64:
181 item_ptr = g_menu_item_jack_latency_64;
182 break;
183 case 128:
184 item_ptr = g_menu_item_jack_latency_128;
185 break;
186 case 256:
187 item_ptr = g_menu_item_jack_latency_256;
188 break;
189 case 512:
190 item_ptr = g_menu_item_jack_latency_512;
191 break;
192 case 1024:
193 item_ptr = g_menu_item_jack_latency_1024;
194 break;
195 case 2048:
196 item_ptr = g_menu_item_jack_latency_2048;
197 break;
198 case 4096:
199 item_ptr = g_menu_item_jack_latency_4096;
200 break;
201 case 8192:
202 item_ptr = g_menu_item_jack_latency_8192;
203 break;
204 default:
205 //log_error("unknown jack buffer size %"PRIu32, buffer_size);
206 return false;
209 if (force || !item_ptr->active)
211 log_info("menu_set_jack_latency() detects change");
212 g_latency_changing = true; /* latency has changed externally, don't tell jack to change it again */
213 gtk_check_menu_item_set_active(item_ptr, TRUE);
214 g_latency_changing = false;
217 return true;
220 void menu_view_activated(bool room)
222 gtk_widget_set_sensitive(g_menu_item_destroy_room, room);
223 gtk_widget_set_sensitive(g_menu_item_load_project, room);
224 gtk_widget_set_sensitive(g_menu_item_unload_project, room);
225 gtk_widget_set_sensitive(g_menu_item_save_project, room);
226 gtk_widget_set_sensitive(g_menu_item_save_as_project, room);
229 static void on_popup_menu_action_start_app(GtkWidget * menuitem, gpointer userdata)
231 menu_request_start_app();
234 static void on_popup_menu_action_create_room(GtkWidget * menuitem, gpointer userdata)
236 menu_request_create_room();
239 static void on_popup_menu_action_destroy_room(GtkWidget * menuitem, gpointer userdata)
241 menu_request_destroy_room();
244 static void on_popup_menu_action_load_project(GtkWidget * menuitem, gpointer userdata)
246 menu_request_load_project();
249 static void on_popup_menu_action_unload_project(GtkWidget * menuitem, gpointer userdata)
251 menu_request_unload_project();
254 static void on_popup_menu_action_save_project(GtkWidget * menuitem, gpointer userdata)
256 menu_request_save_project();
259 static void on_popup_menu_action_save_project_as(GtkWidget * menuitem, gpointer userdata)
261 menu_request_save_as_project();
264 void fill_view_popup_menu(GtkMenu * menu, graph_view_handle view)
266 GtkWidget * menuitem;
268 log_info("filling view menu...");
270 if (graph_view_get_app_supervisor(view) != NULL)
272 menuitem = gtk_menu_item_new_with_label("Run...");
273 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_start_app, NULL);
274 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
277 if (is_room_view(view))
279 menuitem = gtk_menu_item_new_with_label("Load Project...");
280 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_load_project, NULL);
281 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
283 menuitem = gtk_menu_item_new_with_label("Unload Project");
284 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_unload_project, NULL);
285 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
287 menuitem = gtk_menu_item_new_with_label("Save Project...");
288 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_save_project, NULL);
289 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
291 menuitem = gtk_menu_item_new_with_label("Save Project As...");
292 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_save_project_as, NULL);
293 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
295 menuitem = gtk_separator_menu_item_new(); /* separator */
296 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
298 menuitem = gtk_menu_item_new_with_label("Destroy Room");
299 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_destroy_room, NULL);
300 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
302 else
304 menuitem = gtk_menu_item_new_with_label("Create Room...");
305 g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_create_room, NULL);
306 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);