aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2014-02-24 20:35:47 +0800
committerMilan Crha <mcrha@redhat.com>2014-02-24 20:35:47 +0800
commite6686ae2d9fa9bb6b373259567b0f59be76e8795 (patch)
treeb8526d592a070e5af43b14eb4789e786970d8e9a
parentaceed006fdfbe40bdfd4816dd2baab0f27259246 (diff)
downloadgsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.tar
gsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.tar.gz
gsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.tar.bz2
gsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.tar.lz
gsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.tar.xz
gsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.tar.zst
gsoc2013-evolution-e6686ae2d9fa9bb6b373259567b0f59be76e8795.zip
Bug #711758 - Handle relative path when importing from command line
-rw-r--r--shell/e-shell.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/shell/e-shell.c b/shell/e-shell.c
index c9c38b26cd..7c1893e12d 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -30,7 +30,9 @@
#include "e-shell.h"
+#include <errno.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <libebackend/libebackend.h>
#include "e-util/e-util-private.h"
@@ -191,11 +193,33 @@ shell_action_handle_uris_cb (GSimpleAction *action,
EShell *shell)
{
const gchar **uris;
+ gchar *change_dir = NULL;
+ gint ii;
/* Do not use g_strfreev() here. */
uris = g_variant_get_strv (parameter, NULL);
+ if (uris && g_strcmp0 (uris[0], "--use-cwd") == 0 && uris[1] && *uris[1]) {
+ change_dir = g_get_current_dir ();
+
+ if (g_chdir (uris[1]) != 0)
+ g_warning ("%s: Failed to change directory to '%s': %s", G_STRFUNC, uris[1], g_strerror (errno));
+
+ for (ii = 0; uris[ii + 2]; ii++) {
+ uris[ii] = uris[ii + 2];
+ }
+
+ uris[ii] = NULL;
+ }
+
e_shell_handle_uris (shell, uris, FALSE);
g_free (uris);
+
+ if (change_dir) {
+ if (g_chdir (change_dir) != 0)
+ g_warning ("%s: Failed to return back to '%s': %s", G_STRFUNC, change_dir, g_strerror (errno));
+
+ g_free (change_dir);
+ }
}
static void
@@ -1423,6 +1447,8 @@ e_shell_handle_uris (EShell *shell,
const gchar * const *uris,
gboolean do_import)
{
+ GPtrArray *args;
+ gchar *cwd;
guint n_handled = 0;
guint ii;
@@ -1452,9 +1478,22 @@ e_shell_handle_uris (EShell *shell,
remote: /* Send a message to the other Evolution process. */
+ cwd = g_get_current_dir ();
+ args = g_ptr_array_sized_new (g_strv_length ((gchar **) uris) + 2);
+
+ g_ptr_array_add (args, (gchar *) "--use-cwd");
+ g_ptr_array_add (args, cwd);
+
+ for (ii = 0; uris[ii]; ii++) {
+ g_ptr_array_add (args, (gchar *) uris[ii]);
+ }
+
g_action_group_activate_action (
G_ACTION_GROUP (shell), "handle-uris",
- g_variant_new_strv (uris, -1));
+ g_variant_new_strv ((const gchar * const *) args->pdata, args->len));
+
+ g_ptr_array_free (args, TRUE);
+ g_free (cwd);
/* As far as we're concerned, all URIs have been handled. */