[gedit/dbus] Rewrote to make things nicer and better



commit c2f7778733625dc6cecfa23c79bfe5c041d1e2fc
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Thu May 6 22:42:02 2010 +0200

    Rewrote to make things nicer and better
    
    Mainly made all the non essential parameters optional in a
    hash, making the overall call nicer.

 gedit/gedit-dbus.c |  619 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 384 insertions(+), 235 deletions(-)
---
diff --git a/gedit/gedit-dbus.c b/gedit/gedit-dbus.c
index 92c337e..6a36a13 100644
--- a/gedit/gedit-dbus.c
+++ b/gedit/gedit-dbus.c
@@ -50,12 +50,32 @@ struct _WaitData
 	GeditDBus *dbus;
 	GeditWindow *window;
 	gboolean close_window;
-	guint wait_id;
+	guint32 wait_id;
 
 	guint num_handlers;
 	WaitHandlerFunc func;
 };
 
+typedef struct _DisplayParameters DisplayParameters;
+
+struct _DisplayParameters
+{
+	gchar *display_name;
+	gint32 screen_number;
+	gint32 workspace;
+	gint32 viewport_x;
+	gint32 viewport_y;
+};
+
+typedef struct _OpenParameters OpenParameters;
+
+struct _OpenParameters
+{
+	const GeditEncoding *encoding;
+	gint32 line_position;
+	gint32 column_position;
+};
+
 #define GEDIT_DBUS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_DBUS, GeditDBusPrivate))
 
 typedef struct
@@ -64,9 +84,8 @@ typedef struct
 	GCancellable *cancellable;
 
 	GeditWindow *window;
-	const GeditEncoding *encoding;
-	gint line_position;
-	gint column_position;
+
+	OpenParameters oparams;
 	gboolean jump_to;
 	WaitData *wait_data;
 } AsyncData;
@@ -75,9 +94,9 @@ struct _GeditDBusPrivate
 {
 	GeditDBusResult result;
 	GMainLoop *main_loop;
-	guint wait_id;
+	guint32 wait_id;
 
-	guint next_wait_id;
+	guint32 next_wait_id;
 
 	GeditFifo *stdin_fifo;
 	GInputStream *stdin_in_stream;
@@ -262,12 +281,7 @@ activate_service (GeditDBus *dbus,
 
 static void
 get_display_arguments (GeditDBus         *dbus,
-                       GeditCommandLine  *command_line,
-                       const gchar      **display_name,
-                       gint              *screen_number,
-                       gint              *workspace,
-                       gint              *viewport_x,
-                       gint              *viewport_y)
+                       DisplayParameters *dparams)
 {
 	GdkScreen *screen;
 	GdkDisplay *display;
@@ -275,78 +289,134 @@ get_display_arguments (GeditDBus         *dbus,
 	screen = gdk_screen_get_default ();
 	display = gdk_screen_get_display (screen);
 
-	*display_name = gdk_display_get_name (display);
-	*screen_number = gdk_screen_get_number (screen);
+	dparams->display_name = g_strdup (gdk_display_get_name (display));
+	dparams->screen_number = gdk_screen_get_number (screen);
 
-	*workspace = gedit_utils_get_current_workspace (screen);
-	gedit_utils_get_current_viewport (screen, viewport_x, viewport_y);
+	dparams->workspace = gedit_utils_get_current_workspace (screen);
+	gedit_utils_get_current_viewport (screen, &dparams->viewport_x, &dparams->viewport_y);
 }
 
 static GVariant *
 compose_open_parameters (GeditDBus *dbus)
 {
 	GVariantBuilder file_list;
-	GSList *files;
+	GVariantBuilder options;
+	GSList *item;
 	const GeditEncoding *encoding;
-	const gchar *display_name;
-	gint screen_number;
-	gint workspace;
-	gint viewport_x;
-	gint viewport_y;
-	GVariant *ret;
+	DisplayParameters dparams;
 	GeditCommandLine *command_line;
-	gchar *stdin_path;
 
 	command_line = gedit_command_line_get_default ();
 
+	/* Compose files as uris */
 	g_variant_builder_init (&file_list, G_VARIANT_TYPE ("as"));
 
-	for (files = gedit_command_line_get_file_list (command_line); files; files = g_slist_next (files))
+	item = gedit_command_line_get_file_list (command_line);
+
+	while (item)
 	{
-		gchar *uri = g_file_get_uri (files->data);
+		gchar *uri = g_file_get_uri (item->data);
 		g_variant_builder_add (&file_list, "s", uri);
 		g_free (uri);
-	}
 
-	encoding = gedit_command_line_get_encoding (command_line);
+		item = g_slist_next (item);
+	}
 
-	get_display_arguments (dbus,
-	                       command_line,
-	                       &display_name,
-	                       &screen_number,
-	                       &workspace,
-	                       &viewport_x,
-	                       &viewport_y);
+	/* Compose additional options */
+	g_variant_builder_init (&options, G_VARIANT_TYPE ("a{sv}"));
 
+	/* see if we need to add the pipe_path */
 	if (dbus->priv->stdin_fifo)
 	{
-		GFile *file = gedit_fifo_get_file (dbus->priv->stdin_fifo);
-		stdin_path = g_file_get_path (file);
+		GFile *file;
+		gchar *path;
+
+		file = gedit_fifo_get_file (dbus->priv->stdin_fifo);
+		path = g_file_get_path (file);
+
+		g_variant_builder_add (&options,
+		                       "{sv}",
+		                       "pipe_path",
+		                       g_variant_new_string (path));
+
 		g_object_unref (file);
+		g_free (path);
 	}
-	else
-	{
-		stdin_path = g_strdup ("");
-	}
-
-	ret = g_variant_new ("(assiibbbusiiiis)",
-	                     &file_list,
-	                     encoding ? gedit_encoding_get_charset (encoding) : "",
-	                     gedit_command_line_get_line_position (command_line),
-	                     gedit_command_line_get_column_position (command_line),
-	                     gedit_command_line_get_new_window (command_line),
-	                     gedit_command_line_get_new_document (command_line),
-	                     gedit_command_line_get_wait (command_line),
-	                     get_startup_timestamp (),
-	                     display_name,
-	                     screen_number,
-	                     workspace,
-	                     viewport_x,
-	                     viewport_y,
-	                     stdin_path);
-
-	g_free (stdin_path);
-	return ret;
+
+	/* add the encoding, line position, column position */
+	encoding = gedit_command_line_get_encoding (command_line);
+
+	if (encoding)
+	{
+		g_variant_builder_add (&options,
+		                       "{sv}", "encoding",
+		                       g_variant_new_string (gedit_encoding_get_charset (encoding)));
+	}
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "line_position",
+	                       g_variant_new_int32 (gedit_command_line_get_line_position (command_line)));
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "column_position",
+	                       g_variant_new_int32 (gedit_command_line_get_column_position (command_line)));
+
+	/* whether the make a new window, new document */
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "new_window",
+	                       g_variant_new_boolean (gedit_command_line_get_new_window (command_line)));
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "new_document",
+	                       g_variant_new_boolean (gedit_command_line_get_new_document (command_line)));
+
+	/* whether to wait */
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "wait",
+	                       g_variant_new_boolean (gedit_command_line_get_wait (command_line)));
+
+	/* the proper startup time */
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "startup_time",
+	                       g_variant_new_uint32 (get_startup_timestamp ()));
+
+	/* display parameters like display name, screen, workspace, viewport */
+	get_display_arguments (dbus, &dparams);
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "display_name",
+	                       g_variant_new_string (dparams.display_name));
+
+	g_free (dparams.display_name);
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "screen_number",
+	                       g_variant_new_int32 (dparams.screen_number));
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "workspace",
+	                       g_variant_new_int32 (dparams.workspace));
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "viewport_x",
+	                       g_variant_new_int32 (dparams.viewport_x));
+
+	g_variant_builder_add (&options,
+	                       "{sv}",
+	                       "viewport_y",
+	                       g_variant_new_int32 (dparams.viewport_y));
+
+	return g_variant_new ("(asa{sv})", &file_list, &options);
 }
 
 static void
@@ -416,6 +486,7 @@ stdin_write_finish (GOutputStream *stream,
 	GError *error = NULL;
 	gssize written;
 	GeditDBusPrivate *priv;
+	GeditCommandLine *command_line;
 
 	if (g_cancellable_is_cancelled (async->cancellable))
 	{
@@ -446,8 +517,12 @@ stdin_write_finish (GOutputStream *stream,
 	g_object_unref (priv->stdin_cancellable);
 	priv->stdin_cancellable = NULL;
 
-	if (priv->main_loop)
+	command_line = gedit_command_line_get_default ();
+
+	if (priv->main_loop && !gedit_command_line_get_wait (command_line))
 	{
+		/* only quit the main loop if it's there and if we don't need
+		   to wait */
 		g_main_loop_quit (priv->main_loop);
 	}
 }
@@ -733,25 +808,22 @@ display_open_if_needed (const gchar *name)
 }
 
 static GeditWindow *
-window_from_display_arguments (gboolean     new_window,
-                               const gchar *display_name,
-                               gint         screen_number,
-                               gint         workspace,
-                               gint         viewport_x,
-                               gint         viewport_y,
-                               gboolean     create)
+window_from_display_arguments (gboolean           new_window,
+                               DisplayParameters *dparams,
+                               gboolean           create)
 {
 	GdkScreen *screen;
 	GeditApp *app;
 	GeditWindow *ret;
 
 	/* get correct screen using the display_name and screen_number */
-	if (display_name != NULL && *display_name)
+	if (dparams->display_name != NULL && *dparams->display_name)
 	{
 		GdkDisplay *display;
 
-		display = display_open_if_needed (display_name);
-		screen = gdk_display_get_screen (display, screen_number == -1 ? 0 : screen_number);
+		display = display_open_if_needed (dparams->display_name);
+		screen = gdk_display_get_screen (display,
+		                                 dparams->screen_number == -1 ? 0 : dparams->screen_number);
 	}
 
 	app = gedit_app_get_default ();
@@ -765,9 +837,9 @@ window_from_display_arguments (gboolean     new_window,
 	{
 		ret = _gedit_app_get_window_in_viewport (app,
 		                                         screen,
-		                                         workspace == -1 ? 0 : workspace,
-		                                         viewport_x == -1 ? 0 : viewport_x,
-		                                         viewport_y == -1 ? 0 : viewport_y);
+		                                         dparams->workspace == -1 ? 0 : dparams->workspace,
+		                                         dparams->viewport_x == -1 ? 0 : dparams->viewport_x,
+		                                         dparams->viewport_y == -1 ? 0 : dparams->viewport_y);
 	}
 	else
 	{
@@ -905,12 +977,10 @@ install_wait_handler (GeditDBus       *dbus,
 
 #ifdef G_OS_UNIX
 static GeditTab *
-tab_from_stream (GeditWindow         *window,
-                 GInputStream        *stream,
-                 const GeditEncoding *encoding,
-                 gint                 line_position,
-                 gint                 column_position,
-                 gboolean             jump_to)
+tab_from_stream (GeditWindow    *window,
+                 GInputStream   *stream,
+                 OpenParameters *oparams,
+                 gboolean        jump_to)
 {
 	GList *documents;
 	GeditDocument *doc = NULL;
@@ -935,17 +1005,17 @@ tab_from_stream (GeditWindow         *window,
 
 		_gedit_tab_load_stream (tab,
 		                        stream,
-		                        encoding,
-		                        line_position,
-		                        column_position);
+		                        oparams->encoding,
+		                        oparams->line_position,
+		                        oparams->column_position);
 	}
 	else
 	{
 		tab = gedit_window_create_tab_from_stream (window,
 		                                           stream,
-		                                           encoding,
-		                                           line_position,
-		                                           column_position,
+		                                           oparams->encoding,
+		                                           oparams->line_position,
+		                                           oparams->column_position,
 		                                           jump_to);
 	}
 
@@ -958,9 +1028,7 @@ static GSList *
 create_tabs_for_fds (GeditDBus             *dbus,
                      GDBusMethodInvocation *invocation,
                      GeditWindow           *window,
-                     const GeditEncoding   *encoding,
-                     gint                   line_position,
-                     gint                   column_position,
+                     OpenParameters        *oparams,
                      gboolean               jump_to)
 {
 #ifdef G_OS_UNIX
@@ -1012,9 +1080,7 @@ create_tabs_for_fds (GeditDBus             *dbus,
 
 			tab = tab_from_stream (window,
 			                       stream,
-			                       encoding,
-			                       line_position,
-			                       column_position,
+			                       oparams,
 			                       jump_to);
 
 			g_object_unref (stream);
@@ -1069,9 +1135,7 @@ stdin_pipe_ready_to_read (GeditFifo    *fifo,
 
 	tab = tab_from_stream (async->window,
 	                       stream,
-	                       async->encoding,
-	                       async->line_position,
-	                       async->column_position,
+	                       &async->oparams,
 	                       async->jump_to);
 
 	g_object_unref (stream);
@@ -1086,35 +1150,36 @@ stdin_pipe_ready_to_read (GeditFifo    *fifo,
 }
 #endif
 
-static void
-create_tab_for_pipe (GeditDBus           *dbus,
-                     const gchar         *pipe,
-                     GeditWindow         *window,
-                     const GeditEncoding *encoding,
-                     gint                 line_position,
-                     gint                 column_position,
-                     gboolean             jump_to,
-                     WaitData            *wait_data)
+static gboolean
+handle_open_pipe (GeditDBus      *dbus,
+                  const gchar    *pipe_path,
+                  GeditWindow    *window,
+                  OpenParameters *oparams,
+                  gboolean        jump_to,
+                  WaitData       *wait_data)
 {
 #ifdef G_OS_UNIX
 	/* We'll do this async */
 	GFile *file;
 	AsyncData *async;
 
-	file = g_file_new_for_path (pipe);
+	if (!pipe_path)
+	{
+		return FALSE;
+	}
+
+	file = g_file_new_for_path (pipe_path);
 	dbus->priv->stdin_fifo = gedit_fifo_new (file);
 	g_object_unref (file);
 
 	if (dbus->priv->stdin_fifo == NULL)
 	{
-		return;
+		return FALSE;
 	}
 
 	async = async_data_new (dbus);
 	async->window = window;
-	async->encoding = encoding;
-	async->line_position = line_position;
-	async->column_position = column_position;
+	async->oparams = *oparams;
 	async->jump_to = jump_to;
 	async->wait_data = wait_data;
 
@@ -1127,183 +1192,279 @@ create_tab_for_pipe (GeditDBus           *dbus,
 	                            async->cancellable,
 	                            (GAsyncReadyCallback)stdin_pipe_ready_to_read,
 	                            async);
+
+	return TRUE;
+#else
+	return FALSE;
 #endif
 }
 
 static void
+extract_optional_parameters (GHashTable  *parameters,
+                             ...) G_GNUC_NULL_TERMINATED;
+
+static void
+extract_optional_parameters (GHashTable  *parameters,
+                             ...)
+{
+	va_list va_args;
+	const gchar *key;
+
+	va_start (va_args, parameters);
+
+	while ((key = va_arg (va_args, const gchar *)) != NULL)
+	{
+		GVariant *value;
+
+		value = g_hash_table_lookup (parameters, key);
+
+		if (!value)
+		{
+			/* ignore the next */
+			va_arg (va_args, gpointer);
+			continue;
+		}
+
+		g_variant_get_va (value,
+		                  g_variant_get_type_string (value),
+		                  NULL,
+		                  &va_args);
+	}
+
+	va_end (va_args);
+}
+
+static GHashTable *
+optional_parameters_hash_table (GVariantIter *iter)
+{
+	GVariant *value;
+	GHashTable *ret;
+	const gchar *key;
+
+	ret = g_hash_table_new_full (g_str_hash,
+	                             g_str_equal,
+	                             (GDestroyNotify)g_free,
+	                             (GDestroyNotify)g_variant_unref);
+
+	while (g_variant_iter_loop (iter, "{sv}", &key, &value))
+	{
+		g_hash_table_insert (ret,
+		                     g_strdup (key),
+		                     g_variant_ref (value));
+	}
+
+	return ret;
+}
+
+static GSList *
+handle_open_fds (GeditDBus             *dbus,
+                 GDBusMethodInvocation *invocation,
+                 GSList                *loaded,
+                 GeditWindow           *window,
+                 OpenParameters        *oparams)
+{
+	GSList *item;
+	GSList *tabs;
+	GSList *ret = NULL;
+
+	/* This is for creating tabs from unix file descriptors supplied with
+	   the dbus message */
+	tabs = create_tabs_for_fds (dbus,
+	                            invocation,
+	                            window,
+	                            oparams,
+	                            loaded == NULL);
+
+	for (item = tabs; item; item = g_slist_next (item))
+	{
+		ret = g_slist_prepend (ret, gedit_tab_get_document (item->data));
+	}
+
+	g_slist_free (tabs);
+
+	return g_slist_concat (loaded, g_slist_reverse (ret));
+
+}
+
+static void
 dbus_handle_open (GeditDBus             *dbus,
                   GVariant              *parameters,
                   GDBusMethodInvocation *invocation)
 {
 	GVariantIter *file_list;
-	gchar *charset_encoding;
-	gint line_position;
-	gint column_position;
-	gboolean new_window;
-	gboolean new_document;
-	gboolean wait;
-	guint startup_time;
-	gchar *display_name;
-	gint screen_number;
-	gint workspace;
-	gint viewport_x;
-	gint viewport_y;
+	GVariantIter *optional_parameters;
+	GHashTable *options_hash;
+
+	gchar *charset_encoding = NULL;
+	guint32 startup_time;
+
+	OpenParameters open_parameters = {NULL, 0, 0};
+
+	gboolean new_window = FALSE;
+	gboolean new_document = FALSE;
+	gboolean wait = FALSE;
+	gchar *pipe_path = NULL;
+
 	GSList *locations = NULL;
-	const GeditEncoding *encoding = NULL;
 	GeditWindow *window;
 	GSList *loaded_documents = NULL;
 	gboolean empty_window;
 	WaitData *data;
-	GSList *item;
-	GSList *tabs;
-	gchar *stdin_pipe;
+	guint32 wait_id = 0;
 
 	g_variant_get (parameters,
-	               "(assiibbbusiiiis)",
+	               "(asa{sv})",
 	               &file_list,
-	               &charset_encoding,
-	               &line_position,
-	               &column_position,
-	               &new_window,
-	               &new_document,
-	               &wait,
-	               &startup_time,
-	               &display_name,
-	               &screen_number,
-	               &workspace,
-	               &viewport_x,
-	               &viewport_y,
-	               &stdin_pipe);
+	               &optional_parameters);
 
 	locations = variant_iter_list_to_locations (file_list);
 	g_variant_iter_free (file_list);
 
+	options_hash = optional_parameters_hash_table (optional_parameters);
+	g_variant_iter_free (optional_parameters);
+
+	{
+		DisplayParameters display_parameters = {NULL, -1, -1, -1, -1};
+
+		extract_optional_parameters (options_hash,
+		                             "new_window", &new_window,
+		                             "display_name", &display_parameters.display_name,
+		                             "screen_number", &display_parameters.screen_number,
+		                             "workspace", &display_parameters.workspace,
+		                             "viewport_x", &display_parameters.viewport_x,
+		                             "viewport_y", &display_parameters.viewport_y,
+		                             NULL);
+
+		window = window_from_display_arguments (new_window,
+		                                        &display_parameters,
+		                                        TRUE);
+
+		g_free (display_parameters.display_name);
+	}
+
+	extract_optional_parameters (options_hash, "encoding", &charset_encoding, NULL);
+
 	if (charset_encoding && *charset_encoding)
 	{
-		encoding = gedit_encoding_get_from_charset (charset_encoding);
+		open_parameters.encoding = gedit_encoding_get_from_charset (charset_encoding);
 	}
 
 	g_free (charset_encoding);
 
-	window = window_from_display_arguments (new_window,
-	                                        display_name,
-	                                        screen_number,
-	                                        workspace,
-	                                        viewport_x,
-	                                        viewport_y,
-	                                        TRUE);
-
 	empty_window = is_empty_window (window, TRUE);
 
+	extract_optional_parameters (options_hash,
+	                             "line_position", &open_parameters.line_position,
+	                             "column_position", &open_parameters.column_position,
+	                             NULL);
+
 	if (locations)
 	{
 		loaded_documents = _gedit_cmd_load_files_from_prompt (window,
 		                                                      locations,
-		                                                      encoding,
-		                                                      line_position,
-		                                                      column_position);
+		                                                      open_parameters.encoding,
+		                                                      open_parameters.line_position,
+		                                                      open_parameters.column_position);
 	}
 
 	g_slist_free (locations);
 
-	tabs = create_tabs_for_fds (dbus,
-	                            invocation,
-	                            window,
-	                            encoding,
-	                            line_position,
-	                            column_position,
-	                            loaded_documents == NULL);
-
-	for (item = tabs; item; item = g_slist_next (item))
-	{
-		loaded_documents = g_slist_append (loaded_documents, gedit_tab_get_document (item->data));
-	}
+	loaded_documents = handle_open_fds (dbus,
+	                                    invocation,
+	                                    loaded_documents,
+	                                    window,
+	                                    &open_parameters);
 
-	g_slist_free (tabs);
+	extract_optional_parameters (options_hash,
+	                             "wait", &wait,
+	                             "pipe_path", &pipe_path,
+	                             "new_document", &new_document,
+	                             "startup_time", &startup_time,
+	                             NULL);
 
 	set_interaction_time_and_present (window, startup_time);
 
 	if (!wait)
 	{
-		if (stdin_pipe && *stdin_pipe)
-		{
-			create_tab_for_pipe (dbus,
-			                     stdin_pipe,
-			                     window,
-			                     encoding,
-			                     line_position,
-			                     column_position,
-			                     loaded_documents == NULL && !new_document,
-			                     NULL);
-		}
-
-		g_free (stdin_pipe);
+		gboolean jump_to = loaded_documents == NULL;
 
 		if (new_document)
 		{
-			gedit_window_create_tab (window, loaded_documents == NULL);
+			gedit_window_create_tab (window, jump_to);
+			jump_to = FALSE;
 		}
 
-		g_slist_free (loaded_documents);
-		g_dbus_method_invocation_return_value (invocation,
-		                                       g_variant_new ("(u)", 0));
-		return;
+		handle_open_pipe (dbus,
+		                  pipe_path,
+		                  window,
+		                  &open_parameters,
+		                  jump_to,
+		                  NULL);
 	}
+	else
+	{
+		gboolean jump_to = loaded_documents == NULL;
+		gboolean has_pipe;
 
-	data = g_slice_new (WaitData);
+		data = g_slice_new (WaitData);
 
-	data->dbus = dbus;
-	data->window = window;
-	data->close_window = empty_window;
-	data->wait_id = ++dbus->priv->next_wait_id;
+		data->dbus = dbus;
+		data->window = window;
+		data->close_window = empty_window;
+		data->wait_id = ++dbus->priv->next_wait_id;
 
-	if (stdin_pipe && *stdin_pipe)
-	{
-		create_tab_for_pipe (dbus,
-		                     stdin_pipe,
-		                     window,
-		                     encoding,
-		                     line_position,
-		                     column_position,
-		                     loaded_documents == NULL && !new_document,
-		                     data);
-	}
+		/* for the return value */
+		wait_id = data->wait_id;
 
-	if (new_document)
-	{
-		GeditTab *tab;
-		tab = gedit_window_create_tab (window, loaded_documents == NULL);
+		if (new_document)
+		{
+			GeditTab *tab;
+			tab = gedit_window_create_tab (window, jump_to);
+			jump_to = FALSE;
 
-		loaded_documents = g_slist_append (loaded_documents,
-		                                   gedit_tab_get_document (tab));
-	}
+			loaded_documents = g_slist_append (loaded_documents,
+			                                   gedit_tab_get_document (tab));
+		}
 
-	if (loaded_documents == NULL && !(stdin_pipe && *stdin_pipe))
-	{
-		/* Add wait handler on the window */
-		install_wait_handler (dbus,
-		                      data,
-		                      G_OBJECT (window),
-		                      wait_handler_dbus);
-	}
-	else
-	{
-		GSList *item;
+		has_pipe = handle_open_pipe (dbus,
+		                             pipe_path,
+		                             window,
+		                             &open_parameters,
+		                             jump_to,
+		                             data);
 
-		/* Add wait handler on the documents */
-		for (item = loaded_documents; item; item = item->next)
+		/* Install wait handler on the window if there were no documents
+		   opened */
+		if (loaded_documents == NULL && !has_pipe)
 		{
+			/* Add wait handler on the window */
 			install_wait_handler (dbus,
 			                      data,
-			                      G_OBJECT (item->data),
+			                      G_OBJECT (window),
 			                      wait_handler_dbus);
 		}
+		else
+		{
+			GSList *item;
+
+			/* Add wait handler on the documents */
+			for (item = loaded_documents; item; item = item->next)
+			{
+				install_wait_handler (dbus,
+				                      data,
+				                      G_OBJECT (item->data),
+				                      wait_handler_dbus);
+			}
+		}
 	}
 
-	g_free (stdin_pipe);
+	g_free (pipe_path);
 
 	g_slist_free (loaded_documents);
-	g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", data->wait_id));
+	g_hash_table_destroy (options_hash);
+
+	g_dbus_method_invocation_return_value (invocation,
+	                                       g_variant_new ("(u)", wait_id));
 }
 
 static void
@@ -1332,19 +1493,7 @@ dbus_command_line_method_call_cb (GDBusConnection       *connection,
 /* Introspection data for the service we are exporting */
 static const GDBusArgInfo in_args[] = {
 	{"files"          , "as"},
-	{"encoding"       , "s"},
-	{"line_position"  , "i"},
-	{"column_position", "i"},
-	{"new_window"     , "b"},
-	{"new_document"   , "b"},
-	{"wait"           , "b"},
-	{"startup_time"   , "u"},
-	{"display_name"   , "s"},
-	{"screen_number"  , "i"},
-	{"workspace"      , "i"},
-	{"viewport_x"     , "i"},
-	{"viewport_y"     , "i"},
-	{"stdin_pipe"     , "s"}
+	{"parameters"     , "a{sv}"}
 };
 
 static const GDBusArgInfo out_args[] = {
@@ -1352,7 +1501,7 @@ static const GDBusArgInfo out_args[] = {
 };
 
 static const GDBusMethodInfo command_line_methods[] = {
-	{"Open", "assiibbbusiiiis", 14, in_args, "u", 1, out_args}
+	{"Open", "asa{sv}", 2, in_args, "u", 1, out_args}
 };
 
 static const GDBusArgInfo signal_args[] = {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]