gui: dialog for starting programs now starts them through ladishd

This commit is contained in:
Nedko Arnaudov 2009-12-03 01:49:08 +02:00
parent 94c197fe33
commit 67a1dd5013
6 changed files with 182 additions and 3 deletions

101
gui/app_supervisor_proxy.c Normal file
View File

@ -0,0 +1,101 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* 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 <http://www.gnu.org/licenses/>
* 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

View File

@ -0,0 +1,38 @@
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* LADI Session Handler (ladish)
*
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
*
**************************************************************************
* 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
* 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 <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED
#define APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED
#include "common.h"
typedef struct ladish_app_supervisor_proxy_tag { int unused; } * ladish_app_supervisor_proxy_handle;
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);
#endif /* #ifndef APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED */

View File

@ -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);
}

View File

@ -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);

View File

@ -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;

View File

@ -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))