app properties dialog. Fixes #21
This commit is contained in:
parent
01ee09b09d
commit
d7e58c7efd
|
@ -742,10 +742,161 @@ static void kill_app(struct dbus_method_call * call_ptr)
|
|||
|
||||
static void get_app_properties(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
uint64_t id;
|
||||
struct ladish_app * app_ptr;
|
||||
dbus_bool_t running;
|
||||
dbus_bool_t terminal;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
call_ptr->message,
|
||||
&g_dbus_error,
|
||||
DBUS_TYPE_UINT64, &id,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
|
||||
dbus_error_free(&g_dbus_error);
|
||||
return;
|
||||
}
|
||||
|
||||
app_ptr = ladish_app_supervisor_find_app_by_id(supervisor_ptr, id);
|
||||
if (app_ptr == NULL)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "App with ID %"PRIu64" not found", id);
|
||||
return;
|
||||
}
|
||||
|
||||
running = app_ptr->pid != 0;
|
||||
terminal = app_ptr->terminal;
|
||||
|
||||
call_ptr->reply = dbus_message_new_method_return(call_ptr->message);
|
||||
if (call_ptr->reply == NULL)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!dbus_message_append_args(
|
||||
call_ptr->reply,
|
||||
DBUS_TYPE_STRING, &app_ptr->name,
|
||||
DBUS_TYPE_STRING, &app_ptr->commandline,
|
||||
DBUS_TYPE_BOOLEAN, &running,
|
||||
DBUS_TYPE_BOOLEAN, &terminal,
|
||||
DBUS_TYPE_BYTE, &app_ptr->level,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
goto fail_unref;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
fail_unref:
|
||||
dbus_message_unref(call_ptr->reply);
|
||||
call_ptr->reply = NULL;
|
||||
|
||||
fail:
|
||||
log_error("Ran out of memory trying to construct method return");
|
||||
}
|
||||
|
||||
static void set_app_properties(struct dbus_method_call * call_ptr)
|
||||
{
|
||||
uint64_t id;
|
||||
dbus_bool_t terminal;
|
||||
const char * name;
|
||||
const char * commandline;
|
||||
uint8_t level;
|
||||
struct ladish_app * app_ptr;
|
||||
char * name_buffer;
|
||||
char * commandline_buffer;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
call_ptr->message,
|
||||
&g_dbus_error,
|
||||
DBUS_TYPE_UINT64, &id,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_STRING, &commandline,
|
||||
DBUS_TYPE_BOOLEAN, &terminal,
|
||||
DBUS_TYPE_BYTE, &level,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message);
|
||||
dbus_error_free(&g_dbus_error);
|
||||
return;
|
||||
}
|
||||
|
||||
app_ptr = ladish_app_supervisor_find_app_by_id(supervisor_ptr, id);
|
||||
if (app_ptr == NULL)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "App with ID %"PRIu64" not found", id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (app_ptr->pid != 0 && strcmp(commandline, app_ptr->commandline) != 0)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "Cannot change commandline when app is running. '%s' -> '%s'", app_ptr->commandline, commandline);
|
||||
return;
|
||||
}
|
||||
|
||||
if (app_ptr->pid != 0 && ((app_ptr->terminal && !terminal) || (!app_ptr->terminal && terminal)))
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "Cannot change whether to run in terminal when app is running");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app_ptr->pid != 0 && app_ptr->level != level)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "Cannot change app level when app is running");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(commandline, app_ptr->commandline) != 0)
|
||||
{
|
||||
commandline_buffer = strdup(commandline);
|
||||
if (commandline_buffer == NULL)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup() failed for app commandline");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
commandline_buffer = NULL;
|
||||
}
|
||||
|
||||
if (strcmp(name, app_ptr->name) != 0)
|
||||
{
|
||||
name_buffer = strdup(name);
|
||||
if (name_buffer == NULL)
|
||||
{
|
||||
lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "strdup() failed for app nam");
|
||||
if (commandline_buffer != NULL)
|
||||
{
|
||||
free(commandline_buffer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name_buffer = NULL;
|
||||
}
|
||||
|
||||
if (name_buffer != NULL)
|
||||
{
|
||||
free(app_ptr->name);
|
||||
app_ptr->name = name_buffer;
|
||||
}
|
||||
|
||||
if (commandline_buffer != NULL)
|
||||
{
|
||||
free(app_ptr->commandline);
|
||||
app_ptr->commandline = commandline_buffer;
|
||||
}
|
||||
|
||||
app_ptr->level = level;
|
||||
app_ptr->terminal = terminal;
|
||||
|
||||
emit_app_state_changed(supervisor_ptr, app_ptr);
|
||||
|
||||
method_return_new_void(call_ptr);
|
||||
}
|
||||
|
||||
static void remove_app(struct dbus_method_call * call_ptr)
|
||||
|
@ -847,6 +998,7 @@ METHOD_ARGS_BEGIN(GetAppProperties, "Get properties of an application")
|
|||
METHOD_ARG_DESCRIBE_IN("id", DBUS_TYPE_UINT64_AS_STRING, "id of app")
|
||||
METHOD_ARG_DESCRIBE_OUT("name", DBUS_TYPE_STRING_AS_STRING, "")
|
||||
METHOD_ARG_DESCRIBE_OUT("commandline", DBUS_TYPE_STRING_AS_STRING, "Commandline")
|
||||
METHOD_ARG_DESCRIBE_OUT("running", DBUS_TYPE_BOOLEAN_AS_STRING, "")
|
||||
METHOD_ARG_DESCRIBE_OUT("terminal", DBUS_TYPE_BOOLEAN_AS_STRING, "Whether to run in terminal")
|
||||
METHOD_ARG_DESCRIBE_OUT("level", DBUS_TYPE_BYTE_AS_STRING, "Level")
|
||||
METHOD_ARGS_END
|
||||
|
|
|
@ -31,4 +31,7 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
void error_message_box(const char * failed_operation);
|
||||
extern GtkWidget * g_app_dialog;
|
||||
|
||||
#endif /* #ifndef COMMON_H__15E63B7A_8350_4ABD_B04C_592158354949__INCLUDED */
|
||||
|
|
|
@ -1038,7 +1038,6 @@ along with LADI Session Handler; if not, write to the Free Software Foundation,
|
|||
</widget>
|
||||
<widget class="GtkDialog" id="app_dialog">
|
||||
<property name="border_width">5</property>
|
||||
<property name="title" translatable="yes">Run custom command</property>
|
||||
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
|
||||
<property name="default_width">400</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
|
||||
|
|
|
@ -251,7 +251,7 @@ void run_custom_command_dialog(void)
|
|||
GtkEntry * command_entry = GTK_ENTRY(get_glade_widget("app_command_entry"));
|
||||
GtkEntry * name_entry = GTK_ENTRY(get_glade_widget("app_name_entry"));
|
||||
GtkToggleButton * terminal_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_terminal_check_button"));
|
||||
/* GtkToggleButton * level0_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level0")); */
|
||||
GtkToggleButton * level0_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level0"));
|
||||
/* GtkToggleButton * level1_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level1")); */
|
||||
/* GtkToggleButton * level2_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level2")); */
|
||||
/* GtkToggleButton * level3_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level3")); */
|
||||
|
@ -260,6 +260,13 @@ void run_custom_command_dialog(void)
|
|||
gtk_entry_set_text(command_entry, "");
|
||||
gtk_toggle_button_set_active(terminal_button, FALSE);
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(command_entry), TRUE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(terminal_button), TRUE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(level0_button), TRUE);
|
||||
|
||||
gtk_window_set_focus(GTK_WINDOW(g_app_dialog), GTK_WIDGET(command_entry));
|
||||
gtk_window_set_title(GTK_WINDOW(g_app_dialog), "New application");
|
||||
|
||||
gtk_widget_show(g_app_dialog);
|
||||
|
||||
result = gtk_dialog_run(GTK_DIALOG(g_app_dialog));
|
||||
|
|
|
@ -197,6 +197,69 @@ void on_popup_menu_action_app_remove(GtkWidget * menuitem, gpointer userdata)
|
|||
ladish_app_supervisor_proxy_remove_app(proxy, id);
|
||||
}
|
||||
|
||||
void on_popup_menu_action_app_properties(GtkWidget * menuitem, gpointer userdata)
|
||||
{
|
||||
uint64_t id;
|
||||
ladish_app_supervisor_proxy_handle proxy;
|
||||
graph_view_handle view;
|
||||
char * name;
|
||||
char * command;
|
||||
bool running;
|
||||
bool terminal;
|
||||
uint8_t level;
|
||||
guint result;
|
||||
GtkEntry * command_entry = GTK_ENTRY(get_glade_widget("app_command_entry"));
|
||||
GtkEntry * name_entry = GTK_ENTRY(get_glade_widget("app_name_entry"));
|
||||
GtkToggleButton * terminal_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_terminal_check_button"));
|
||||
GtkToggleButton * level0_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level0"));
|
||||
/* GtkToggleButton * level1_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level1")); */
|
||||
/* GtkToggleButton * level2_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level2")); */
|
||||
/* GtkToggleButton * level3_button = GTK_TOGGLE_BUTTON(get_glade_widget("app_level3")); */
|
||||
|
||||
if (!get_selected_app_id(&view, &id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
log_info("app %"PRIu64" properties", id);
|
||||
|
||||
proxy = graph_view_get_app_supervisor(view);
|
||||
|
||||
if (!ladish_app_supervisor_get_app_properties(proxy, id, &name, &command, &running, &terminal, &level))
|
||||
{
|
||||
error_message_box("Cannot get app properties");
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_entry_set_text(name_entry, name);
|
||||
gtk_entry_set_text(command_entry, command);
|
||||
gtk_toggle_button_set_active(terminal_button, terminal);
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(command_entry), !running);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(terminal_button), !running);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(level0_button), !running);
|
||||
|
||||
free(name);
|
||||
free(command);
|
||||
|
||||
gtk_window_set_focus(GTK_WINDOW(g_app_dialog), running ? GTK_WIDGET(name_entry) : GTK_WIDGET(command_entry));
|
||||
gtk_window_set_title(GTK_WINDOW(g_app_dialog), "App properties");
|
||||
|
||||
gtk_widget_show(g_app_dialog);
|
||||
|
||||
result = gtk_dialog_run(GTK_DIALOG(g_app_dialog));
|
||||
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 (!ladish_app_supervisor_set_app_properties(proxy, id, gtk_entry_get_text(name_entry), gtk_entry_get_text(command_entry), gtk_toggle_button_get_active(terminal_button), level))
|
||||
{
|
||||
error_message_box("Cannot set app properties.");
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_hide(g_app_dialog);
|
||||
}
|
||||
|
||||
void popup_menu(GtkWidget * treeview, GdkEventButton * event)
|
||||
{
|
||||
GtkTreeSelection * selection;
|
||||
|
@ -257,6 +320,10 @@ void popup_menu(GtkWidget * treeview, GdkEventButton * event)
|
|||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||
}
|
||||
|
||||
menuitem = gtk_menu_item_new_with_label("Properties");
|
||||
g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_app_properties, NULL);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
|
||||
|
||||
gtk_widget_show_all(menu);
|
||||
|
||||
/* Note: event can be NULL here when called from view_onPopupMenu;
|
||||
|
|
|
@ -345,4 +345,104 @@ bool ladish_app_supervisor_proxy_remove_app(ladish_app_supervisor_proxy_handle p
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ladish_app_supervisor_get_app_properties(
|
||||
ladish_app_supervisor_proxy_handle proxy,
|
||||
uint64_t id,
|
||||
char ** name_ptr_ptr,
|
||||
char ** command_ptr_ptr,
|
||||
bool * running_ptr,
|
||||
bool * terminal_ptr,
|
||||
uint8_t * level_ptr)
|
||||
{
|
||||
DBusMessage * reply_ptr;
|
||||
const char * name;
|
||||
const char * commandline;
|
||||
dbus_bool_t running;
|
||||
dbus_bool_t terminal;
|
||||
uint8_t level;
|
||||
char * name_buffer;
|
||||
char * commandline_buffer;
|
||||
|
||||
if (!dbus_call(proxy_ptr->service, proxy_ptr->object, IFACE_APP_SUPERVISOR, "GetAppProperties", "t", &id, NULL, &reply_ptr))
|
||||
{
|
||||
log_error("GetAppProperties() failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
reply_ptr,
|
||||
&g_dbus_error,
|
||||
DBUS_TYPE_STRING, &name,
|
||||
DBUS_TYPE_STRING, &commandline,
|
||||
DBUS_TYPE_BOOLEAN, &running,
|
||||
DBUS_TYPE_BOOLEAN, &terminal,
|
||||
DBUS_TYPE_BYTE, &level,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
dbus_message_unref(reply_ptr);
|
||||
dbus_error_free(&g_dbus_error);
|
||||
log_error("decoding reply of GetAppProperties failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
name_buffer = strdup(name);
|
||||
if (name_buffer == NULL)
|
||||
{
|
||||
log_error("strdup() for app name failed.");
|
||||
dbus_message_unref(reply_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
commandline_buffer = strdup(commandline);
|
||||
if (commandline_buffer == NULL)
|
||||
{
|
||||
log_error("strdup() for app commandline failed.");
|
||||
free(name_buffer);
|
||||
dbus_message_unref(reply_ptr);
|
||||
return false;
|
||||
}
|
||||
|
||||
*name_ptr_ptr = name_buffer;
|
||||
*command_ptr_ptr = commandline_buffer;
|
||||
*running_ptr = running;
|
||||
*terminal_ptr = terminal;
|
||||
*level_ptr = level;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ladish_app_supervisor_set_app_properties(
|
||||
ladish_app_supervisor_proxy_handle proxy,
|
||||
uint64_t id,
|
||||
const char * name,
|
||||
const char * command,
|
||||
bool run_in_terminal,
|
||||
uint8_t level)
|
||||
{
|
||||
dbus_bool_t terminal;
|
||||
|
||||
terminal = run_in_terminal;
|
||||
|
||||
if (!dbus_call(
|
||||
proxy_ptr->service,
|
||||
proxy_ptr->object,
|
||||
IFACE_APP_SUPERVISOR,
|
||||
"SetAppProperties",
|
||||
"tssby",
|
||||
&id,
|
||||
&name,
|
||||
&command,
|
||||
&terminal,
|
||||
&level,
|
||||
""))
|
||||
{
|
||||
log_error("SetAppProperties() failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef proxy_ptr
|
||||
|
|
|
@ -48,4 +48,23 @@ bool ladish_app_supervisor_proxy_stop_app(ladish_app_supervisor_proxy_handle pro
|
|||
bool ladish_app_supervisor_proxy_kill_app(ladish_app_supervisor_proxy_handle proxy, uint64_t id);
|
||||
bool ladish_app_supervisor_proxy_remove_app(ladish_app_supervisor_proxy_handle proxy, uint64_t id);
|
||||
|
||||
bool
|
||||
ladish_app_supervisor_get_app_properties(
|
||||
ladish_app_supervisor_proxy_handle proxy,
|
||||
uint64_t id,
|
||||
char ** name_ptr_ptr,
|
||||
char ** command_ptr_ptr,
|
||||
bool * running_ptr,
|
||||
bool * terminal_ptr,
|
||||
uint8_t * level_ptr);
|
||||
|
||||
bool
|
||||
ladish_app_supervisor_set_app_properties(
|
||||
ladish_app_supervisor_proxy_handle proxy,
|
||||
uint64_t id,
|
||||
const char * name,
|
||||
const char * command,
|
||||
bool terminal,
|
||||
uint8_t level);
|
||||
|
||||
#endif /* #ifndef APP_SUPERVISOR_PROXY_H__A48C609D_0AB6_4C91_A9B0_BC7F1B7E4CB4__INCLUDED */
|
||||
|
|
Loading…
Reference in New Issue