[gnome-terminal] server: Allow specifying a different unique name
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] server: Allow specifying a different unique name
- Date: Thu, 3 May 2012 19:04:40 +0000 (UTC)
commit 2ad5b75b5effb2831a21d5872e8c9e8bbd093b55
Author: Christian Persch <chpe gnome org>
Date: Wed Mar 14 21:44:36 2012 +0100
server: Allow specifying a different unique name
This is for testing purposes.
src/client.c | 21 ++++++++++++++++-
src/server.c | 54 +++++++++++++++++++++++++++++++----------------
src/terminal-options.c | 10 ++++++++
src/terminal-options.h | 1 +
src/terminal.c | 9 +++++--
5 files changed, 71 insertions(+), 24 deletions(-)
---
diff --git a/src/client.c b/src/client.c
index 99959cf..ed10f60 100644
--- a/src/client.c
+++ b/src/client.c
@@ -139,6 +139,8 @@ modify_argv0_for_command (gint *argc, gchar **argv[], const gchar *command)
typedef struct
{
+ char *server_bus_name;
+
/* Window options */
char *startup_id;
const char *display_name;
@@ -205,6 +207,11 @@ option_zoom_cb (const gchar *option_name,
static GOptionContext *
get_goption_context (OptionData *data)
{
+ const GOptionEntry server_goptions[] = {
+ { "bus-name", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &data->server_bus_name, N_("Server D-Bus name"), N_("NAME") },
+ { NULL }
+ };
+
const GOptionEntry window_goptions[] = {
{ "maximize", 0, 0, G_OPTION_ARG_NONE, &data->start_maximized,
N_("Maximise the window"), NULL },
@@ -247,6 +254,13 @@ get_goption_context (OptionData *data)
g_option_context_set_description (context, N_("GNOME Terminal Client"));
g_option_context_set_ignore_unknown_options (context, FALSE);
+ group = g_option_group_new ("server-options", "", "",
+ data,
+ NULL);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+ g_option_group_add_entries (group, server_goptions);
+ g_option_context_add_group (context, group);
+
group = g_option_group_new ("window-options",
N_("Window options:"),
N_("Show window options"),
@@ -284,6 +298,7 @@ option_data_free (OptionData *data)
if (data == NULL)
return;
+ g_free (data->server_bus_name);
g_free (data->startup_id);
g_free (data->geometry);
g_free (data->role);
@@ -425,7 +440,8 @@ handle_open (int *argc,
factory = terminal_factory_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- TERMINAL_UNIQUE_NAME,
+ data->server_bus_name ? data->server_bus_name
+ : TERMINAL_UNIQUE_NAME,
TERMINAL_FACTORY_OBJECT_PATH,
NULL /* cancellable */,
&error);
@@ -455,7 +471,8 @@ handle_open (int *argc,
receiver = terminal_receiver_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
- TERMINAL_UNIQUE_NAME,
+ data->server_bus_name ? data->server_bus_name
+ : TERMINAL_UNIQUE_NAME,
object_path,
NULL /* cancellable */,
&error);
diff --git a/src/server.c b/src/server.c
index ba245ac..444d236 100644
--- a/src/server.c
+++ b/src/server.c
@@ -50,17 +50,10 @@ bus_acquired_cb (GDBusConnection *connection,
const char *name,
gpointer user_data)
{
- TerminalObjectSkeleton *object;
_terminal_debug_print (TERMINAL_DEBUG_FACTORY,
"Bus %s acquired\n", name);
- object = terminal_object_skeleton_new (TERMINAL_FACTORY_OBJECT_PATH);
- terminal_object_skeleton_set_factory (object, TERMINAL_FACTORY (terminal_app_get ()));
- g_dbus_object_manager_server_export (object_manager, G_DBUS_OBJECT_SKELETON (object));
- g_object_unref (object);
-
- /* And export the object */
g_dbus_object_manager_server_set_connection (object_manager, connection);
}
@@ -92,9 +85,17 @@ name_lost_cb (GDBusConnection *connection,
gtk_main_quit ();
}
+static char *bus_name = NULL;
+static const GOptionEntry options[] = {
+ { "bus-name", 0, 0, G_OPTION_ARG_STRING, &bus_name, N_("Server D-Bus name"), N_("NAME") },
+ { NULL }
+};
+
int
main (int argc, char **argv)
{
+ GDBusConnection *connection;
+ TerminalObjectSkeleton *object;
OwnData data;
guint owner_id;
const char *home_dir;
@@ -121,22 +122,38 @@ main (int argc, char **argv)
g_set_application_name (_("Terminal"));
- if (!gtk_init_with_args (&argc, &argv, "", NULL, NULL, &error)) {
+ if (!gtk_init_with_args (&argc, &argv, "", options, NULL, &error)) {
g_printerr ("Failed to parse arguments: %s\n", error->message);
g_error_free (error);
exit (EXIT_FAILURE);
}
+ connection = g_bus_get_sync (G_BUS_TYPE_STARTER, NULL, &error);
+ if (connection == NULL) {
+ g_printerr ("Failed to connect: %s\n", error->message);
+ g_error_free (error);
+ g_free (bus_name);
+ }
+
object_manager = g_dbus_object_manager_server_new (TERMINAL_OBJECT_PATH_PREFIX);
+ /* Export our interface. */
+ object = terminal_object_skeleton_new (TERMINAL_FACTORY_OBJECT_PATH);
+ terminal_object_skeleton_set_factory (object, TERMINAL_FACTORY (terminal_app_get ()));
+ g_dbus_object_manager_server_export (object_manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
+
+ /* And export the object */
+ g_dbus_object_manager_server_set_connection (object_manager, connection);
+
data.exit_code = EXIT_FAILURE;
- owner_id = g_bus_own_name (G_BUS_TYPE_STARTER,
- TERMINAL_UNIQUE_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- bus_acquired_cb,
- name_acquired_cb,
- name_lost_cb,
- &data, NULL);
+ owner_id = g_bus_own_name_on_connection (connection,
+ bus_name ? bus_name : TERMINAL_UNIQUE_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ name_acquired_cb,
+ name_lost_cb,
+ &data, NULL);
+ g_free (bus_name);
gtk_main ();
@@ -144,10 +161,9 @@ main (int argc, char **argv)
g_dbus_object_manager_server_unexport (object_manager, TERMINAL_FACTORY_OBJECT_PATH);
if (data.exit_code == EXIT_SUCCESS)
- g_dbus_connection_flush_sync (g_dbus_object_manager_server_get_connection (object_manager),
- NULL /* cancellable */, NULL /* error */);
- g_object_unref (object_manager);
- object_manager = NULL;
+ g_dbus_connection_flush_sync (connection, NULL /* cancellable */, NULL /* error */);
+ g_clear_object (&object_manager);
+ g_clear_object (&connection);
terminal_app_shutdown ();
diff --git a/src/terminal-options.c b/src/terminal-options.c
index 3eb3d5b..a4c7ea7 100644
--- a/src/terminal-options.c
+++ b/src/terminal-options.c
@@ -953,6 +953,7 @@ terminal_options_free (TerminalOptions *options)
g_free (options->display_name);
g_free (options->startup_id);
+ g_free (options->server_bus_name);
g_free (options->sm_client_state_file);
g_free (options->sm_client_id);
@@ -966,6 +967,15 @@ get_goption_context (TerminalOptions *options)
{
const GOptionEntry global_unique_goptions[] = {
{
+ "bus-name",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_STRING,
+ &options->server_bus_name,
+ N_("Server D-Bus name"),
+ N_("NAME")
+ },
+ {
"disable-factory",
0,
G_OPTION_FLAG_NO_ARG,
diff --git a/src/terminal-options.h b/src/terminal-options.h
index eee9afd..2254a61 100644
--- a/src/terminal-options.h
+++ b/src/terminal-options.h
@@ -52,6 +52,7 @@ G_BEGIN_DECLS
typedef struct
{
+ char *server_bus_name;
gboolean remote_arguments;
char *startup_id;
char *display_name;
diff --git a/src/terminal.c b/src/terminal.c
index 5d92afc..483de58 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -186,7 +186,8 @@ handle_options (TerminalFactory *factory,
receiver = terminal_receiver_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- TERMINAL_UNIQUE_NAME,
+ options->server_bus_name ? options->server_bus_name
+ : TERMINAL_UNIQUE_NAME,
object_path,
NULL /* cancellable */,
&err);
@@ -282,13 +283,15 @@ main (int argc, char **argv)
factory = terminal_factory_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- TERMINAL_UNIQUE_NAME,
+ options->server_bus_name ? options->server_bus_name
+ : TERMINAL_UNIQUE_NAME,
TERMINAL_FACTORY_OBJECT_PATH,
NULL /* cancellable */,
&error);
if (factory == NULL) {
g_printerr ("Error constructing proxy for %s:%s: %s\n",
- TERMINAL_UNIQUE_NAME, TERMINAL_FACTORY_OBJECT_PATH,
+ options->server_bus_name ? options->server_bus_name : TERMINAL_UNIQUE_NAME,
+ TERMINAL_FACTORY_OBJECT_PATH,
error->message);
g_error_free (error);
goto out;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]