From 67a1dd501331bba8bcb39ddb141685879f82c944 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Thu, 3 Dec 2009 01:49:08 +0200 Subject: [PATCH] gui: dialog for starting programs now starts them through ladishd --- gui/app_supervisor_proxy.c | 101 +++++++++++++++++++++++++++ gui/{graph_view.h => app_supervisor_proxy.h} | 34 +++------ gui/graph_view.c | 33 ++++++++- gui/graph_view.h | 3 + gui/main.c | 9 ++- wscript | 1 + 6 files changed, 153 insertions(+), 28 deletions(-) create mode 100644 gui/app_supervisor_proxy.c copy gui/{graph_view.h => app_supervisor_proxy.h} (53%) diff --git a/gui/app_supervisor_proxy.c b/gui/app_supervisor_proxy.c new file mode 100644 index 00000000..44f717c7 --- /dev/null +++ b/gui/app_supervisor_proxy.c @@ -0,0 +1,101 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2009 Nedko Arnaudov + * + ************************************************************************** + * This file contains implementation of code that interfaces + * app supervisor object through D-Bus + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "app_supervisor_proxy.h" +#include "../dbus/helpers.h" +#include "../dbus_constants.h" + +struct ladish_app_supervisor_proxy +{ + char * service; + char * object; + uint64_t version; +}; + +bool ladish_app_supervisor_proxy_create(const char * service, const char * object, ladish_app_supervisor_proxy_handle * handle_ptr) +{ + struct ladish_app_supervisor_proxy * proxy_ptr; + + proxy_ptr = malloc(sizeof(struct ladish_app_supervisor_proxy)); + if (proxy_ptr == NULL) + { + log_error("malloc() failed to allocate struct proxy"); + goto fail; + } + + proxy_ptr->service = strdup(service); + if (proxy_ptr->service == NULL) + { + log_error("strdup() failed too duplicate service name '%s'", service); + goto free_proxy; + } + + proxy_ptr->object = strdup(object); + if (proxy_ptr->object == NULL) + { + log_error("strdup() failed too duplicate object name '%s'", object); + goto free_service; + } + + proxy_ptr->version = 0; + + *handle_ptr = (ladish_app_supervisor_proxy_handle)proxy_ptr; + + return true; + +free_service: + free(proxy_ptr->service); + +free_proxy: + free(proxy_ptr); + +fail: + return false; +} + +#define proxy_ptr ((struct ladish_app_supervisor_proxy *)proxy) + +void ladish_app_supervisor_proxy_destroy(ladish_app_supervisor_proxy_handle proxy) +{ + free(proxy_ptr->object); + free(proxy_ptr->service); + free(proxy_ptr); +} + +bool ladish_app_supervisor_proxy_run_custom(ladish_app_supervisor_proxy_handle proxy, const char * command, const char * name, bool run_in_terminal) +{ + dbus_bool_t terminal; + if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_APP_SUPERVISOR, "RunCustom", "bss", &terminal, &command, &name, "")) + { + log_error("RunCustom() failed."); + return false; + } + + return true; +} + +#undef proxy_ptr diff --git a/gui/graph_view.h b/gui/app_supervisor_proxy.h similarity index 53% copy from gui/graph_view.h copy to gui/app_supervisor_proxy.h index 3415d1b7..7045b634 100644 --- a/gui/graph_view.h +++ b/gui/app_supervisor_proxy.h @@ -5,7 +5,7 @@ * Copyright (C) 2009 Nedko Arnaudov * ************************************************************************** - * This file contains interface of the graph view object + * This file contains interface to app supervisor object that is backed through D-Bus ************************************************************************** * * LADI Session Handler is free software; you can redistribute it and/or modify @@ -24,31 +24,15 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef GRAPH_VIEW_H__05B5CE46_5239_43F1_9F31_79F13EBF0DFA__INCLUDED -#define GRAPH_VIEW_H__05B5CE46_5239_43F1_9F31_79F13EBF0DFA__INCLUDED +#ifndef APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED +#define APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED -#include "graph_canvas.h" +#include "common.h" -typedef struct graph_view_tag { int unused; } * graph_view_handle; +typedef struct ladish_app_supervisor_proxy_tag { int unused; } * ladish_app_supervisor_proxy_handle; -void view_init(void); +bool ladish_app_supervisor_proxy_create(const char * service, const char * object, ladish_app_supervisor_proxy_handle * proxy_ptr); +void ladish_app_supervisor_proxy_destroy(ladish_app_supervisor_proxy_handle proxy); +bool ladish_app_supervisor_proxy_run_custom(ladish_app_supervisor_proxy_handle proxy, const char * command, const char * name, bool run_in_terminal); -bool -create_view( - const char * name, - const char * service, - const char * object, - bool graph_dict_supported, - bool force_activate, - graph_view_handle * handle_ptr); - -void destroy_view(graph_view_handle view); -void activate_view(graph_view_handle view); -const char * get_view_name(graph_view_handle view); -bool set_view_name(graph_view_handle view, const char * name); -canvas_handle get_current_canvas(); - -/* not very good place for this prototype, because it is not implemented in graph_view.c */ -void set_main_window_title(graph_view_handle view); - -#endif /* #ifndef GRAPH_VIEW_H__05B5CE46_5239_43F1_9F31_79F13EBF0DFA__INCLUDED */ +#endif /* #ifndef APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED */ diff --git a/gui/graph_view.c b/gui/graph_view.c index 5a3cb8ee..c87561fb 100644 --- a/gui/graph_view.c +++ b/gui/graph_view.c @@ -28,6 +28,7 @@ #include "graph_view.h" #include "glade.h" #include "world_tree.h" +#include "app_supervisor_proxy.h" struct graph_view { @@ -36,6 +37,7 @@ struct graph_view graph_canvas_handle graph_canvas; graph_proxy_handle graph; GtkWidget * canvas_widget; + ladish_app_supervisor_proxy_handle app_supervisor; }; struct list_head g_views; @@ -56,6 +58,7 @@ create_view( const char * service, const char * object, bool graph_dict_supported, + bool app_supervisor_supported, bool force_activate, graph_view_handle * handle_ptr) { @@ -75,9 +78,21 @@ create_view( goto free_view; } + if (app_supervisor_supported) + { + if (!ladish_app_supervisor_proxy_create(service, object, &view_ptr->app_supervisor)) + { + goto free_name; + } + } + else + { + view_ptr->app_supervisor = NULL; + } + if (!graph_proxy_create(service, object, graph_dict_supported, &view_ptr->graph)) { - goto free_name; + goto free_app_supervisor; } if (!graph_canvas_create(1600 * 2, 1200 * 2, &view_ptr->graph_canvas)) @@ -113,6 +128,11 @@ destroy_graph_canvas: graph_canvas_destroy(view_ptr->graph_canvas); destroy_graph: graph_proxy_destroy(view_ptr->graph); +free_app_supervisor: + if (view_ptr->app_supervisor != NULL) + { + ladish_app_supervisor_proxy_destroy(view_ptr->app_supervisor); + } free_name: free(view_ptr->name); free_view: @@ -177,6 +197,12 @@ void destroy_view(graph_view_handle view) graph_canvas_detach(view_ptr->graph_canvas); graph_canvas_destroy(view_ptr->graph_canvas); graph_proxy_destroy(view_ptr->graph); + + if (view_ptr->app_supervisor != NULL) + { + ladish_app_supervisor_proxy_destroy(view_ptr->app_supervisor); + } + free(view_ptr->name); free(view_ptr); } @@ -225,3 +251,8 @@ canvas_handle get_current_canvas() return graph_canvas_get_canvas(g_current_view->graph_canvas); } + +bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal) +{ + return ladish_app_supervisor_proxy_run_custom(view_ptr->app_supervisor, command, name, run_in_terminal); +} diff --git a/gui/graph_view.h b/gui/graph_view.h index 3415d1b7..3b613ee2 100644 --- a/gui/graph_view.h +++ b/gui/graph_view.h @@ -39,6 +39,7 @@ create_view( const char * service, const char * object, bool graph_dict_supported, + bool app_supervisor_supported, bool force_activate, graph_view_handle * handle_ptr); @@ -48,6 +49,8 @@ const char * get_view_name(graph_view_handle view); bool set_view_name(graph_view_handle view, const char * name); canvas_handle get_current_canvas(); +bool app_run_custom(graph_view_handle view, const char * command, const char * name, bool run_in_terminal); + /* not very good place for this prototype, because it is not implemented in graph_view.c */ void set_main_window_title(graph_view_handle view); diff --git a/gui/main.c b/gui/main.c index 9f6401fd..c0d19467 100644 --- a/gui/main.c +++ b/gui/main.c @@ -41,6 +41,7 @@ #include "../catdup.h" #include "../studio_proxy.h" #include "ask_dialog.h" +#include "app_supervisor_proxy.h" GtkWidget * g_main_win; @@ -246,6 +247,10 @@ void run_custom_command_dialog(void) if (result == 2) { log_info("'%s':'%s' %s", gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button) ? "terminal" : "shell"); + if (!app_run_custom(g_studio_view, gtk_entry_get_text(command_entry), gtk_entry_get_text(name_entry), gtk_toggle_button_get_active(terminal_button))) + { + error_message_box("Execution failed. I know you want to know more for the reson but currently you can only check the log file."); + } } gtk_widget_hide(g_app_dialog); @@ -490,7 +495,7 @@ void control_proxy_on_studio_appeared(void) goto free_name; } - if (!create_view(name, SERVICE_NAME, STUDIO_OBJECT_PATH, true, false, &g_studio_view)) + if (!create_view(name, SERVICE_NAME, STUDIO_OBJECT_PATH, true, true, false, &g_studio_view)) { log_error("create_view() failed for studio"); goto free_name; @@ -578,7 +583,7 @@ void jack_appeared(void) log_info("JACK appeared"); #if defined(SHOW_RAW_JACK) - if (!create_view("Raw JACK", JACKDBUS_SERVICE_NAME, JACKDBUS_OBJECT_PATH, false, true, &g_jack_view)) + if (!create_view("Raw JACK", JACKDBUS_SERVICE_NAME, JACKDBUS_OBJECT_PATH, false, false, true, &g_jack_view)) { log_error("create_view() failed for jack"); return; diff --git a/wscript b/wscript index 67f32082..5ded2f0c 100644 --- a/wscript +++ b/wscript @@ -296,6 +296,7 @@ def build(bld): 'graph_canvas.c', 'glade.c', 'control_proxy.c', + 'app_supervisor_proxy.c', 'ask_dialog.c', ]: gladish.source.append(os.path.join("gui", source)) -- 2.11.4.GIT