Merge branch 'stable' into 'main'
[ladish.git] / gui / control.c
blobc1a735a30efb020dddfb09c1a48678f742b28e26
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*
3 * LADI Session Handler (ladish)
5 * Copyright (C) 2010,2012 Nedko Arnaudov <nedko@arnaudov.name>
7 **************************************************************************
8 * This file contains code related to the ladishd control 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.
27 #include "internal.h"
28 #include "studio.h"
29 #include "../proxies/control_proxy.h"
30 #include "../proxies/studio_proxy.h"
31 #include "world_tree.h"
32 #include "ask_dialog.h"
34 static guint g_ladishd_poll_source_tag;
36 static gboolean poll_ladishd(gpointer UNUSED(data))
38 control_proxy_ping();
39 return TRUE;
42 void control_proxy_on_daemon_appeared(void)
44 if (get_studio_state() == STUDIO_STATE_NA || get_studio_state() == STUDIO_STATE_SICK)
46 log_info("ladishd appeared");
47 g_source_remove(g_ladishd_poll_source_tag);
50 set_studio_state(STUDIO_STATE_UNLOADED);
51 studio_state_changed(NULL);
54 void control_proxy_on_daemon_disappeared(bool clean_exit)
56 log_info("ladishd disappeared");
58 if (!clean_exit)
60 error_message_box("ladish daemon crashed");
61 set_studio_state(STUDIO_STATE_SICK);
63 else
65 set_studio_state(STUDIO_STATE_NA);
68 studio_state_changed(NULL);
70 if (studio_loaded())
72 destroy_studio_view();
75 world_tree_destroy_room_views();
77 g_ladishd_poll_source_tag = g_timeout_add(500, poll_ladishd, NULL);
80 void control_proxy_on_studio_appeared(bool initial)
82 char * name;
83 bool started;
85 set_studio_state(STUDIO_STATE_STOPPED);
87 if (initial)
89 if (!studio_proxy_is_started(&started))
91 log_error("intially, studio is present but is_started() check failed.");
92 return;
95 if (started)
97 set_studio_state(STUDIO_STATE_STARTED);
101 if (studio_state_changed(&name))
103 if (studio_loaded())
105 log_error("studio appear signal received but studio already exists");
107 else
109 create_studio_view(name);
112 free(name);
116 void control_proxy_on_studio_disappeared(void)
118 set_studio_state(STUDIO_STATE_UNLOADED);
119 studio_state_changed(NULL);
121 if (!studio_loaded())
123 log_error("studio disappear signal received but studio does not exists");
124 return;
127 destroy_studio_view();
130 void menu_request_ladishd_exit(void)
132 log_info("ladishd exit request");
134 if (!control_proxy_exit())
136 error_message_box(_("ladishd exit command failed, please inspect logs."));
140 void menu_request_new_studio(void)
142 char * new_name;
144 log_info("new studio request");
146 if (name_dialog(_("New studio"), _("Studio name"), "", &new_name))
148 if (!control_proxy_new_studio(new_name))
150 error_message_box(_("Creation of new studio failed, please inspect logs."));
153 free(new_name);
157 void on_load_studio(const char * studio_name)
159 log_info("Load studio \"%s\"", studio_name);
161 if (!control_proxy_load_studio(studio_name))
163 error_message_box(_("Studio load failed, please inspect logs."));
167 void on_delete_studio(const char * studio_name)
169 bool result;
171 if (!ask_dialog(&result, _("<b><big>Confirm studio delete</big></b>"), _("Studio \"%s\" will be deleted. Are you sure?"), studio_name) || !result)
173 return;
176 log_info("Delete studio \"%s\"", studio_name);
178 if (!control_proxy_delete_studio(studio_name))
180 error_message_box(_("Studio delete failed, please inspect logs."));