root/gui/graph_view.c @ 67a1dd501331bba8bcb39ddb141685879f82c944

Revision 67a1dd501331bba8bcb39ddb141685879f82c944, 6.0 KB (checked in by Nedko Arnaudov <nedko@…>, 4 years ago)

gui: dialog for starting programs now starts them through ladishd

  • Property mode set to 100644
Line 
1/* -*- Mode: C ; c-basic-offset: 2 -*- */
2/*
3 * LADI Session Handler (ladish)
4 *
5 * Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
6 *
7 **************************************************************************
8 * This file contains implementation of the graph view 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 "common.h"
28#include "graph_view.h"
29#include "glade.h"
30#include "world_tree.h"
31#include "app_supervisor_proxy.h"
32
33struct graph_view
34{
35  struct list_head siblings;
36  char * name;
37  graph_canvas_handle graph_canvas;
38  graph_proxy_handle graph;
39  GtkWidget * canvas_widget;
40  ladish_app_supervisor_proxy_handle app_supervisor;
41};
42
43struct list_head g_views;
44
45GtkScrolledWindow * g_main_scrolledwin;
46static struct graph_view * g_current_view;
47
48void view_init(void)
49{
50  g_main_scrolledwin = GTK_SCROLLED_WINDOW(get_glade_widget("main_scrolledwin"));
51  INIT_LIST_HEAD(&g_views);
52  g_current_view = NULL;
53}
54
55bool
56create_view(
57  const char * name,
58  const char * service,
59  const char * object,
60  bool graph_dict_supported,
61  bool app_supervisor_supported,
62  bool force_activate,
63  graph_view_handle * handle_ptr)
64{
65  struct graph_view * view_ptr;
66
67  view_ptr = malloc(sizeof(struct graph_view));
68  if (view_ptr == NULL)
69  {
70    log_error("malloc() failed for struct graph_view");
71    goto fail;
72  }
73
74  view_ptr->name = strdup(name);
75  if (view_ptr->name == NULL)
76  {
77    log_error("strdup() failed for \"%s\"", name);
78    goto free_view;
79  }
80
81  if (app_supervisor_supported)
82  {
83    if (!ladish_app_supervisor_proxy_create(service, object, &view_ptr->app_supervisor))
84    {
85      goto free_name;
86    }
87  }
88  else
89  {
90    view_ptr->app_supervisor = NULL;
91  }
92
93  if (!graph_proxy_create(service, object, graph_dict_supported, &view_ptr->graph))
94  {
95    goto free_app_supervisor;
96  }
97
98  if (!graph_canvas_create(1600 * 2, 1200 * 2, &view_ptr->graph_canvas))
99  {
100    goto destroy_graph;
101  }
102
103  if (!graph_canvas_attach(view_ptr->graph_canvas, view_ptr->graph))
104  {
105    goto destroy_graph_canvas;
106  }
107
108  if (!graph_proxy_activate(view_ptr->graph))
109  {
110    goto detach_graph_canvas;
111  }
112
113  view_ptr->canvas_widget = canvas_get_widget(graph_canvas_get_canvas(view_ptr->graph_canvas));
114
115  list_add_tail(&view_ptr->siblings, &g_views);
116
117  gtk_widget_show(view_ptr->canvas_widget);
118
119  world_tree_add((graph_view_handle)view_ptr, force_activate);
120
121  *handle_ptr = (graph_view_handle)view_ptr;
122
123  return true;
124
125detach_graph_canvas:
126  graph_canvas_detach(view_ptr->graph_canvas);
127destroy_graph_canvas:
128  graph_canvas_destroy(view_ptr->graph_canvas);
129destroy_graph:
130  graph_proxy_destroy(view_ptr->graph);
131free_app_supervisor:
132  if (view_ptr->app_supervisor != NULL)
133  {
134    ladish_app_supervisor_proxy_destroy(view_ptr->app_supervisor);
135  }
136free_name:
137  free(view_ptr->name);
138free_view:
139  free(view_ptr);
140fail:
141  return false;
142}
143
144static void attach_canvas(struct graph_view * view_ptr)
145{
146  GtkWidget * child;
147
148  child = gtk_bin_get_child(GTK_BIN(g_main_scrolledwin));
149
150  if (child == view_ptr->canvas_widget)
151  {
152    return;
153  }
154
155  if (child != NULL)
156  {
157    gtk_container_remove(GTK_CONTAINER(g_main_scrolledwin), child);
158  }
159
160  g_current_view = view_ptr;
161  gtk_container_add(GTK_CONTAINER(g_main_scrolledwin), view_ptr->canvas_widget);
162
163  //_main_scrolledwin->property_hadjustment().get_value()->set_step_increment(10);
164  //_main_scrolledwin->property_vadjustment().get_value()->set_step_increment(10);
165}
166
167static void detach_canvas(struct graph_view * view_ptr)
168{
169  GtkWidget * child;
170
171  child = gtk_bin_get_child(GTK_BIN(g_main_scrolledwin));
172  if (child == view_ptr->canvas_widget)
173  {
174    gtk_container_remove(GTK_CONTAINER(g_main_scrolledwin), view_ptr->canvas_widget);
175    g_current_view = NULL;
176  }
177}
178
179#define view_ptr ((struct graph_view *)view)
180
181void destroy_view(graph_view_handle view)
182{
183  list_del(&view_ptr->siblings);
184  if (!list_empty(&g_views))
185  {
186    world_tree_activate((graph_view_handle)list_entry(g_views.next, struct graph_view, siblings));
187  }
188  else
189  {
190    set_main_window_title(NULL);
191  }
192
193  detach_canvas(view_ptr);
194
195  world_tree_remove(view);
196
197  graph_canvas_detach(view_ptr->graph_canvas);
198  graph_canvas_destroy(view_ptr->graph_canvas);
199  graph_proxy_destroy(view_ptr->graph);
200
201  if (view_ptr->app_supervisor != NULL)
202  {
203    ladish_app_supervisor_proxy_destroy(view_ptr->app_supervisor);
204  }
205
206  free(view_ptr->name);
207  free(view_ptr);
208}
209
210void activate_view(graph_view_handle view)
211{
212  attach_canvas(view_ptr);
213  set_main_window_title(view);
214}
215
216const char * get_view_name(graph_view_handle view)
217{
218  return view_ptr->name;
219}
220
221bool set_view_name(graph_view_handle view, const char * cname)
222{
223  char * name;
224
225  name = strdup(cname);
226  if (name == NULL)
227  {
228    log_error("strdup() failed for \"%s\"", name);
229    return false;
230  }
231
232  free(view_ptr->name);
233  view_ptr->name = name;
234
235  world_tree_name_changed(view);
236
237  if (g_current_view == view_ptr)
238  {
239    set_main_window_title(view);
240  }
241
242  return true;
243}
244
245canvas_handle get_current_canvas()
246{
247  if (g_current_view == NULL)
248  {
249    return NULL;
250  }
251
252  return graph_canvas_get_canvas(g_current_view->graph_canvas);
253}
254
255bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal)
256{
257  return ladish_app_supervisor_proxy_run_custom(view_ptr->app_supervisor, command, name, run_in_terminal);
258}
Note: See TracBrowser for help on using the browser.