1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains implementation of the graph view object
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.
28 #include "graph_view.h"
30 #include "world_tree.h"
34 struct list_head siblings
;
36 graph_canvas_handle graph_canvas
;
37 graph_proxy_handle graph
;
38 GtkWidget
* canvas_widget
;
39 ladish_app_supervisor_proxy_handle app_supervisor
;
42 struct list_head g_views
;
44 GtkScrolledWindow
* g_main_scrolledwin
;
45 static struct graph_view
* g_current_view
;
46 GtkWidget
* g_view_label
;
48 const char * g_view_lavel_text
=
49 "If you've started ladish for the first time, you should:\n\n"
50 " 1. Create a new studio (in the menu, Studio -> New Studio)\n"
51 " 2. Configure JACK (in the menu, Tools -> Configure JACK)\n"
52 " 3. Start the studio (in the menu, Studio -> Start Studio)\n"
53 " 4. Start apps (in the menu, Application -> Run)\n"
54 " 5. Connect their ports by click & drag on canvas\n"
55 " 6. Save the studio (in the menu, Studio -> Save Studio)\n";
59 g_main_scrolledwin
= GTK_SCROLLED_WINDOW(get_glade_widget("main_scrolledwin"));
60 INIT_LIST_HEAD(&g_views
);
62 g_view_label
= gtk_label_new(g_view_lavel_text
);
63 g_object_ref(g_view_label
);
64 gtk_widget_show(g_view_label
);
66 g_current_view
= NULL
;
67 gtk_scrolled_window_add_with_viewport(g_main_scrolledwin
, g_view_label
);
70 static void app_added(void * context
, uint64_t id
, const char * name
, bool running
, bool terminal
, uint8_t level
)
72 //log_info("app added. id=%"PRIu64", name='%s', %srunning, %s, level %u", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level);
73 world_tree_add_app(context
, id
, name
, running
, terminal
, level
);
76 static void app_state_changed(void * context
, uint64_t id
, const char * name
, bool running
, bool terminal
, uint8_t level
)
78 //log_info("app state changed. id=%"PRIu64", name='%s', %srunning, %s, level %u", id, name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level);
79 world_tree_app_state_changed(context
, id
, name
, running
, terminal
, level
);
82 static void app_removed(void * context
, uint64_t id
)
84 //log_info("app removed. id=%"PRIu64, id);
85 world_tree_remove_app(context
, id
);
93 bool graph_dict_supported
,
94 bool app_supervisor_supported
,
96 graph_view_handle
* handle_ptr
)
98 struct graph_view
* view_ptr
;
100 view_ptr
= malloc(sizeof(struct graph_view
));
101 if (view_ptr
== NULL
)
103 log_error("malloc() failed for struct graph_view");
107 view_ptr
->name
= strdup(name
);
108 if (view_ptr
->name
== NULL
)
110 log_error("strdup() failed for \"%s\"", name
);
114 view_ptr
->app_supervisor
= NULL
;
116 if (!graph_proxy_create(service
, object
, graph_dict_supported
, &view_ptr
->graph
))
121 if (!graph_canvas_create(1600 * 2, 1200 * 2, &view_ptr
->graph_canvas
))
126 if (!graph_canvas_attach(view_ptr
->graph_canvas
, view_ptr
->graph
))
128 goto destroy_graph_canvas
;
131 view_ptr
->canvas_widget
= canvas_get_widget(graph_canvas_get_canvas(view_ptr
->graph_canvas
));
133 list_add_tail(&view_ptr
->siblings
, &g_views
);
135 gtk_widget_show(view_ptr
->canvas_widget
);
137 world_tree_add((graph_view_handle
)view_ptr
, force_activate
);
139 if (app_supervisor_supported
)
141 if (!ladish_app_supervisor_proxy_create(service
, object
, view_ptr
, app_added
, app_state_changed
, app_removed
, &view_ptr
->app_supervisor
))
143 goto detach_graph_canvas
;
147 if (!graph_proxy_activate(view_ptr
->graph
))
149 goto free_app_supervisor
;
152 *handle_ptr
= (graph_view_handle
)view_ptr
;
157 if (view_ptr
->app_supervisor
!= NULL
)
159 ladish_app_supervisor_proxy_destroy(view_ptr
->app_supervisor
);
162 graph_canvas_detach(view_ptr
->graph_canvas
);
163 destroy_graph_canvas
:
164 graph_canvas_destroy(view_ptr
->graph_canvas
);
166 graph_proxy_destroy(view_ptr
->graph
);
168 free(view_ptr
->name
);
175 static void attach_canvas(struct graph_view
* view_ptr
)
179 child
= gtk_bin_get_child(GTK_BIN(g_main_scrolledwin
));
181 if (child
== view_ptr
->canvas_widget
)
188 gtk_container_remove(GTK_CONTAINER(g_main_scrolledwin
), child
);
191 g_current_view
= view_ptr
;
192 gtk_container_add(GTK_CONTAINER(g_main_scrolledwin
), view_ptr
->canvas_widget
);
194 //_main_scrolledwin->property_hadjustment().get_value()->set_step_increment(10);
195 //_main_scrolledwin->property_vadjustment().get_value()->set_step_increment(10);
198 static void detach_canvas(struct graph_view
* view_ptr
)
202 child
= gtk_bin_get_child(GTK_BIN(g_main_scrolledwin
));
203 if (child
== view_ptr
->canvas_widget
)
205 gtk_container_remove(GTK_CONTAINER(g_main_scrolledwin
), view_ptr
->canvas_widget
);
206 g_current_view
= NULL
;
207 gtk_widget_show(g_view_label
);
208 gtk_scrolled_window_add_with_viewport(g_main_scrolledwin
, g_view_label
);
212 #define view_ptr ((struct graph_view *)view)
214 void destroy_view(graph_view_handle view
)
216 list_del(&view_ptr
->siblings
);
217 if (!list_empty(&g_views
))
219 world_tree_activate((graph_view_handle
)list_entry(g_views
.next
, struct graph_view
, siblings
));
223 set_main_window_title(NULL
);
226 detach_canvas(view_ptr
);
228 world_tree_remove(view
);
230 graph_canvas_detach(view_ptr
->graph_canvas
);
231 graph_canvas_destroy(view_ptr
->graph_canvas
);
232 graph_proxy_destroy(view_ptr
->graph
);
234 if (view_ptr
->app_supervisor
!= NULL
)
236 ladish_app_supervisor_proxy_destroy(view_ptr
->app_supervisor
);
239 free(view_ptr
->name
);
243 void activate_view(graph_view_handle view
)
245 attach_canvas(view_ptr
);
246 set_main_window_title(view
);
249 const char * get_view_name(graph_view_handle view
)
251 return view_ptr
->name
;
254 bool set_view_name(graph_view_handle view
, const char * cname
)
258 name
= strdup(cname
);
261 log_error("strdup() failed for \"%s\"", name
);
265 free(view_ptr
->name
);
266 view_ptr
->name
= name
;
268 world_tree_name_changed(view
);
270 if (g_current_view
== view_ptr
)
272 set_main_window_title(view
);
278 canvas_handle
get_current_canvas()
280 if (g_current_view
== NULL
)
285 return graph_canvas_get_canvas(g_current_view
->graph_canvas
);
288 bool app_run_custom(graph_view_handle view
, const char * command
, const char * name
, bool run_in_terminal
, uint8_t level
)
290 return ladish_app_supervisor_proxy_run_custom(view_ptr
->app_supervisor
, command
, name
, run_in_terminal
, level
);
293 ladish_app_supervisor_proxy_handle
graph_view_get_app_supervisor(graph_view_handle view
)
295 return view_ptr
->app_supervisor
;