aboutsummaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-11-12 19:32:06 +0800
committerMilan Crha <mcrha@redhat.com>2009-11-12 19:32:06 +0800
commit13d07fdb631a6c2157d9650649ee612c05ff5b57 (patch)
tree4c1fdfb4346dce80728512998f4be81cc5bcd3c4 /shell
parent12a23558d0f34c7dc84a81e50c8cf71535f2416b (diff)
downloadgsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.tar
gsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.tar.gz
gsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.tar.bz2
gsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.tar.lz
gsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.tar.xz
gsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.tar.zst
gsoc2013-evolution-13d07fdb631a6c2157d9650649ee612c05ff5b57.zip
Bug #588093 - Allow import of local files from command line
Diffstat (limited to 'shell')
-rw-r--r--shell/e-shell-utils.c60
-rw-r--r--shell/e-shell-utils.h4
-rw-r--r--shell/e-shell.c66
-rw-r--r--shell/e-shell.h3
-rw-r--r--shell/main.c5
5 files changed, 125 insertions, 13 deletions
diff --git a/shell/e-shell-utils.c b/shell/e-shell-utils.c
index 4d4f0fd2ea..30b658aef0 100644
--- a/shell/e-shell-utils.c
+++ b/shell/e-shell-utils.c
@@ -23,6 +23,8 @@
#include <glib/gi18n-lib.h>
+#include "widgets/misc/e-import-assistant.h"
+
/**
* e_shell_run_open_dialog:
* @shell: an #EShell
@@ -180,3 +182,61 @@ exit:
return chosen_file;
}
+
+static void
+assistant_weak_notify_cb (EShell *shell, GObject *where_the_object_was)
+{
+ /* close the application if the import assistant was the only window here */
+ if (e_shell_get_watched_windows (shell) == NULL)
+ gtk_main_quit ();
+}
+
+/**
+ * e_shell_utils_import_uris:
+ * @shell: The #EShell instance
+ * @uris: %NULL-terminated list of URIs to import or preview
+ * @preview: rather preview than import given URIs
+ *
+ * Imports given URIs to Evolution, giving user a choice what to import
+ * if more than one importer can be applied, and where to import it, if
+ * the importer itself is configurable. It can preview data, instead of
+ * importing if requested and the imported has that implemented.
+ *
+ * URIs should be either a filename or URI of form file://.
+ * All others are skipped.
+ *
+ * Returns: the number of URIs successfully handled
+ **/
+guint
+e_shell_utils_import_uris (EShell *shell, gchar **uris, gboolean preview)
+{
+ GtkWindow *parent;
+ GtkWidget *assistant;
+
+ g_return_val_if_fail (shell != NULL, 0);
+ g_return_val_if_fail (uris != NULL, 0);
+
+ parent = e_shell_get_active_window (shell);
+ assistant = e_import_assistant_new_simple (parent, uris, preview);
+
+ if (assistant) {
+ g_signal_connect_after (
+ assistant, "cancel",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ g_signal_connect_after (
+ assistant, "finished",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ g_object_weak_ref (
+ G_OBJECT (assistant), (GWeakNotify)
+ assistant_weak_notify_cb, shell);
+
+ gtk_widget_show (assistant);
+ } else {
+ g_warning ("%s: Cannot %s any of the given URIs", G_STRFUNC, preview ? "preview" : "import");
+ }
+
+ /* like when all of them */
+ return g_strv_length (uris);
+}
diff --git a/shell/e-shell-utils.h b/shell/e-shell-utils.h
index 24ca617369..24b44a9622 100644
--- a/shell/e-shell-utils.h
+++ b/shell/e-shell-utils.h
@@ -43,6 +43,10 @@ GFile * e_shell_run_save_dialog (EShell *shell,
GtkCallback customize_func,
gpointer customize_data);
+guint e_shell_utils_import_uris (EShell *shell,
+ gchar **uris,
+ gboolean preview);
+
G_END_DECLS
#endif /* E_SHELL_UTILS_H */
diff --git a/shell/e-shell.c b/shell/e-shell.c
index b0a1490148..6224021ff9 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -31,6 +31,7 @@
#include "e-shell-backend.h"
#include "e-shell-window.h"
+#include "e-shell-utils.h"
#define E_SHELL_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -605,7 +606,23 @@ shell_message_handle_open (EShell *shell,
gchar **uris;
uris = unique_message_data_get_uris (data);
- e_shell_handle_uris (shell, uris);
+ if (uris && uris[0] && g_str_equal (uris[0], "--import")) {
+ gint ii;
+ GPtrArray *arr = g_ptr_array_new ();
+
+ /* skip the first argument */
+ for (ii = 1; uris[ii] != NULL; ii++) {
+ g_ptr_array_add (arr, uris[ii]);
+ }
+
+ g_ptr_array_add (arr, NULL);
+
+ e_shell_handle_uris (shell, (gchar **)arr->pdata, TRUE);
+
+ g_ptr_array_free (arr, TRUE);
+ } else {
+ e_shell_handle_uris (shell, uris, FALSE);
+ }
g_strfreev (uris);
return TRUE;
@@ -1229,6 +1246,7 @@ unique: /* Send a message to the other Evolution process. */
* e_shell_handle_uris:
* @shell: an #EShell
* @uris: %NULL-terminated list of URIs
+ * @do_import: request an import of the URIs
*
* Emits the #EShell::handle-uri signal for each URI.
*
@@ -1236,7 +1254,8 @@ unique: /* Send a message to the other Evolution process. */
**/
guint
e_shell_handle_uris (EShell *shell,
- gchar **uris)
+ gchar **uris,
+ gboolean do_import)
{
UniqueApp *app;
UniqueMessageData *data;
@@ -1251,13 +1270,20 @@ e_shell_handle_uris (EShell *shell,
if (unique_app_is_running (app))
goto unique;
- for (ii = 0; uris[ii] != NULL; ii++) {
- gboolean handled;
+ if (do_import) {
+ n_handled = e_shell_utils_import_uris (shell, uris, FALSE);
+ } else {
+ for (ii = 0; uris[ii] != NULL; ii++) {
+ gboolean handled;
+
+ g_signal_emit (
+ shell, signals[HANDLE_URI],
+ 0, uris[ii], &handled);
+ n_handled += handled ? 1 : 0;
+ }
- g_signal_emit (
- shell, signals[HANDLE_URI],
- 0, uris[ii], &handled);
- n_handled += handled ? 1 : 0;
+ if (n_handled == 0)
+ n_handled = e_shell_utils_import_uris (shell, uris, TRUE);
}
return n_handled;
@@ -1267,7 +1293,23 @@ unique: /* Send a message to the other Evolution process. */
/* XXX Do something with UniqueResponse? */
data = unique_message_data_new ();
- unique_message_data_set_uris (data, uris);
+ if (do_import) {
+ GPtrArray *arr = g_ptr_array_new ();
+
+ g_ptr_array_add (arr, (gpointer)"--import");
+
+ for (ii = 0; uris[ii] != NULL; ii++) {
+ g_ptr_array_add (arr, uris[ii]);
+ }
+
+ g_ptr_array_add (arr, NULL);
+
+ unique_message_data_set_uris (data, (gchar **)arr->pdata);
+
+ g_ptr_array_free (arr, TRUE);
+ } else {
+ unique_message_data_set_uris (data, uris);
+ }
unique_app_send_message (app, UNIQUE_OPEN, data);
unique_message_data_free (data);
@@ -1365,8 +1407,10 @@ e_shell_get_active_window (EShell *shell)
watched_windows = e_shell_get_watched_windows (shell);
- /* Sanity checks */
- g_return_val_if_fail (watched_windows != NULL, NULL);
+ if (!watched_windows)
+ return NULL;
+
+ /* Sanity check */
g_return_val_if_fail (GTK_IS_WINDOW (watched_windows->data), NULL);
return GTK_WINDOW (watched_windows->data);
diff --git a/shell/e-shell.h b/shell/e-shell.h
index 2872608809..468cc3a6f1 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -88,7 +88,8 @@ GConfClient * e_shell_get_gconf_client (EShell *shell);
GtkWidget * e_shell_create_shell_window (EShell *shell,
const gchar *view_name);
guint e_shell_handle_uris (EShell *shell,
- gchar **uris);
+ gchar **uris,
+ gboolean do_import);
void e_shell_watch_window (EShell *shell,
GtkWindow *window);
GList * e_shell_get_watched_windows (EShell *shell);
diff --git a/shell/main.c b/shell/main.c
index cb7cee4f59..42b1fbcf11 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -88,6 +88,7 @@ static gboolean force_migrate = FALSE;
#endif
static gboolean disable_eplugin = FALSE;
static gboolean disable_preview = FALSE;
+static gboolean import_uris = FALSE;
static gboolean idle_cb (gchar **uris);
static gchar *requested_view = NULL;
@@ -238,7 +239,7 @@ idle_cb (gchar **uris)
/* These calls do the right thing when another Evolution
* process is running. */
if (uris != NULL && *uris != NULL) {
- if (e_shell_handle_uris (shell, uris) == 0)
+ if (e_shell_handle_uris (shell, uris, import_uris) == 0)
gtk_main_quit ();
} else
e_shell_create_shell_window (shell, requested_view);
@@ -330,6 +331,8 @@ static GOptionEntry entries[] = {
N_("Disable preview pane of Mail, Contacts and Tasks."), NULL },
{ "setup-only", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,
&setup_only, NULL, NULL },
+ { "import", 'i', 0, G_OPTION_ARG_NONE, &import_uris,
+ N_("Import URIs or file names given as rest of arguments."), NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, NULL },
{ NULL }
};