ladishd: fix hidden connection save. Fix for #151
[ladish.git] / gui / room.c
bloba4ccfc221fa6b67aa1c7a16cf3352df75593fc7c
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 room 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 "create_room_dialog.h"
28 #include "load_project_dialog.h"
29 #include "save_project_dialog.h"
30 #include "../proxies/studio_proxy.h"
31 #include "../proxies/room_proxy.h"
32 #include "graph_view.h"
33 #include "menu.h"
34 #include "world_tree.h"
36 void menu_request_create_room(void)
38 char * name;
39 char * template;
41 log_info("create room request");
43 if (create_room_dialog_run(&name, &template))
45 log_info("Creating new room '%s' from template '%s'", name, template);
47 if (!studio_proxy_create_room(name, template))
49 error_message_box(_("Room creation failed, please inspect logs."));
52 free(name);
53 free(template);
57 void menu_request_destroy_room(void)
59 const char * room;
61 room = get_current_view_room_name();
62 if (room == NULL)
64 ASSERT_NO_PASS;
65 return;
68 log_info("destroy room '%s' request", room);
70 if (!studio_proxy_delete_room(room))
72 error_message_box(_("Room deletion failed, please inspect logs."));
76 void menu_request_load_project(void)
78 ladish_run_load_project_dialog(graph_view_get_room(get_current_view()));
81 void menu_request_unload_project(void)
83 if (!ladish_room_proxy_unload_project(graph_view_get_room(get_current_view())))
85 log_error("ladish_room_proxy_unload_project() failed");
89 void menu_request_save_project(void)
91 bool new_project;
92 const char * project_dir;
93 const char * project_name;
95 ladish_room_proxy_get_project_properties(graph_view_get_room(get_current_view()), &project_dir, &project_name, NULL, NULL);
97 new_project = strlen(project_dir) == 0;
99 if (new_project)
101 menu_request_save_as_project();
102 return;
105 if (!ladish_room_proxy_save_project(graph_view_get_room(get_current_view()), "", ""))
107 log_error("ladish_room_proxy_unload_project() failed");
111 void menu_request_save_as_project(void)
113 ladish_run_save_project_dialog(graph_view_get_room(get_current_view()));
116 static void room_appeared(const char * opath, const char * name, const char * template)
118 graph_view_handle graph_view;
120 log_info("room \"%s\" appeared (%s). template is \"%s\"", name, opath, template);
122 if (!create_view(name, SERVICE_NAME, opath, true, true, false, &graph_view))
124 log_error("create_view() failed for room \"%s\"", name);
128 static void room_disappeared(const char * opath, const char * name, const char * template)
130 graph_view_handle graph_view;
132 log_info("room \"%s\" disappeared (%s). template is \"%s\"", name, opath, template);
134 graph_view = world_tree_find_by_opath(opath);
135 if (graph_view == NULL)
137 log_error("Unknown room disappeared");
138 return;
141 destroy_view(graph_view);
144 static void room_changed(const char * opath, const char * name, const char * template)
146 log_info("%s changed. name is \"%s\". template is \"%s\"", opath, name, template);
149 void set_room_callbacks(void)
151 studio_proxy_set_room_callbacks(room_appeared, room_disappeared, room_changed);