root/gui/control.c @ e405d25fc134cb60726160476ebf2af982684849

Revision e405d25fc134cb60726160476ebf2af982684849, 4.1 KB (checked in by Nedko Arnaudov <nedko@…>, 3 years ago)

gladish: make dynmenu code reusable

  • Property mode set to 100644
Line 
1/* -*- Mode: C ; c-basic-offset: 2 -*- */
2/*
3 * LADI Session Handler (ladish)
4 *
5 * Copyright (C) 2010 Nedko Arnaudov <nedko@arnaudov.name>
6 *
7 **************************************************************************
8 * This file contains code related to the ladishd control object
9 **************************************************************************
10 *
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.
15 *
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.
20 *
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.
25 */
26
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"
33
34static guint g_ladishd_poll_source_tag;
35
36static gboolean poll_ladishd(gpointer data)
37{
38  control_proxy_ping();
39  return TRUE;
40}
41
42void control_proxy_on_daemon_appeared(void)
43{
44  if (get_studio_state() == STUDIO_STATE_NA || get_studio_state() == STUDIO_STATE_SICK)
45  {
46    log_info("ladishd appeared");
47    g_source_remove(g_ladishd_poll_source_tag);
48  }
49
50  set_studio_state(STUDIO_STATE_UNLOADED);
51  studio_state_changed(NULL);
52}
53
54void control_proxy_on_daemon_disappeared(bool clean_exit)
55{
56  log_info("ladishd disappeared");
57
58  if (!clean_exit)
59  {
60    error_message_box("ladish daemon crashed");
61    set_studio_state(STUDIO_STATE_SICK);
62  }
63  else
64  {
65    set_studio_state(STUDIO_STATE_NA);
66  }
67
68  studio_state_changed(NULL);
69
70  if (studio_loaded())
71  {
72    destroy_studio_view();
73  }
74
75  world_tree_destroy_room_views();
76
77  g_ladishd_poll_source_tag = g_timeout_add(500, poll_ladishd, NULL);
78}
79
80void control_proxy_on_studio_appeared(bool initial)
81{
82  char * name;
83  bool started;
84
85  set_studio_state(STUDIO_STATE_STOPPED);
86
87  if (initial)
88  {
89    if (!studio_proxy_is_started(&started))
90    {
91      log_error("intially, studio is present but is_started() check failed.");
92      return;
93    }
94
95    if (started)
96    {
97      set_studio_state(STUDIO_STATE_STARTED);
98    }
99  }
100
101  if (studio_state_changed(&name))
102  {
103    if (studio_loaded())
104    {
105      log_error("studio appear signal received but studio already exists");
106    }
107    else
108    {
109      create_studio_view(name);
110    }
111
112    free(name);
113  }
114}
115
116void control_proxy_on_studio_disappeared(void)
117{
118  set_studio_state(STUDIO_STATE_UNLOADED);
119  studio_state_changed(NULL);
120
121  if (!studio_loaded())
122  {
123    log_error("studio disappear signal received but studio does not exists");
124    return;
125  }
126
127  destroy_studio_view();
128}
129
130void menu_request_daemon_exit(void)
131{
132  log_info("Daemon exit request");
133
134  if (!control_proxy_exit())
135  {
136    error_message_box("Daemon exit command failed, please inspect logs.");
137  }
138}
139
140void menu_request_new_studio(void)
141{
142  char * new_name;
143
144  log_info("new studio request");
145
146  if (name_dialog("New studio", "Studio name", "", &new_name))
147  {
148    if (!control_proxy_new_studio(new_name))
149    {
150      error_message_box("Creation of new studio failed, please inspect logs.");
151    }
152
153    free(new_name);
154  }
155}
156
157void on_load_studio(const char * studio_name)
158{
159  log_info("Load studio \"%s\"", studio_name);
160
161  if (!control_proxy_load_studio(studio_name))
162  {
163    error_message_box("Studio load failed, please inspect logs.");
164  }
165}
166
167void on_delete_studio(const char * studio_name)
168{
169  bool result;
170
171  if (!ask_dialog(&result, "<b><big>Confirm studio delete</big></b>", "Studio \"%s\" will be deleted. Are you sure?", studio_name) || !result)
172  {
173    return;
174  }
175
176  log_info("Delete studio \"%s\"", studio_name);
177
178  if (!control_proxy_delete_studio(studio_name))
179  {
180    error_message_box("Studio delete failed, please inspect logs.");
181  }
182}
Note: See TracBrowser for help on using the browser.