aboutsummaryrefslogtreecommitdiffstats
path: root/mail/importers
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2010-05-19 04:47:29 +0800
committerMilan Crha <mcrha@redhat.com>2010-05-19 04:47:29 +0800
commitef7690c3845e3c1cebcf3caba7f7667a10e7123d (patch)
treeab4a5bfa25bc5e25e0fed851c25226ce1930ec52 /mail/importers
parent0f92771be57383e5d6e7d0f3e05743d192066eb3 (diff)
downloadgsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.gz
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.tar.zst
gsoc2013-evolution-ef7690c3845e3c1cebcf3caba7f7667a10e7123d.zip
Bug #499320 - Preview before import from command line
Diffstat (limited to 'mail/importers')
-rw-r--r--mail/importers/Makefile.am1
-rw-r--r--mail/importers/elm-importer.c1
-rw-r--r--mail/importers/evolution-mbox-importer.c150
-rw-r--r--mail/importers/mail-importer.h7
-rw-r--r--mail/importers/pine-importer.c1
5 files changed, 160 insertions, 0 deletions
diff --git a/mail/importers/Makefile.am b/mail/importers/Makefile.am
index 65e099b461..4592de8eb5 100644
--- a/mail/importers/Makefile.am
+++ b/mail/importers/Makefile.am
@@ -27,6 +27,7 @@ libevolution_mail_importers_la_LIBADD = \
$(top_builddir)/filter/libfilter.la \
$(top_builddir)/mail/libevolution-mail.la \
$(top_builddir)/shell/libeshell.la \
+ $(top_builddir)/widgets/misc/libemiscwidgets.la \
$(GNOME_PLATFORM_LIBS) \
$(IMPORTERS_LIBS)
diff --git a/mail/importers/elm-importer.c b/mail/importers/elm-importer.c
index c9ddcf75d5..937bfa50de 100644
--- a/mail/importers/elm-importer.c
+++ b/mail/importers/elm-importer.c
@@ -357,6 +357,7 @@ static EImportImporter elm_importer = {
elm_getwidget,
elm_import,
elm_cancel,
+ NULL, /* get_preview */
};
EImportImporter *
diff --git a/mail/importers/evolution-mbox-importer.c b/mail/importers/evolution-mbox-importer.c
index 4fa4bf96f0..dc419dc89e 100644
--- a/mail/importers/evolution-mbox-importer.c
+++ b/mail/importers/evolution-mbox-importer.c
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
+#include <errno.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
@@ -53,6 +54,7 @@
#include "mail-importer.h"
#include "e-util/e-import.h"
+#include "misc/e-web-view-preview.h"
typedef struct {
EImport *import;
@@ -247,6 +249,153 @@ mbox_cancel(EImport *ei, EImportTarget *target, EImportImporter *im)
camel_operation_cancel(importer->cancel);
}
+static MboxImporterCreatePreviewFunc create_preview_func = NULL;
+static MboxImporterFillPreviewFunc fill_preview_func = NULL;
+
+void
+mbox_importer_set_preview_funcs (MboxImporterCreatePreviewFunc create_func, MboxImporterFillPreviewFunc fill_func)
+{
+ create_preview_func = create_func;
+ fill_preview_func = fill_func;
+}
+
+static void
+preview_selection_changed_cb (GtkTreeSelection *selection, EWebViewPreview *preview)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model = NULL;
+ gboolean found = FALSE;
+
+ g_return_if_fail (selection != NULL);
+ g_return_if_fail (preview != NULL);
+ g_return_if_fail (fill_preview_func != NULL);
+
+ if (gtk_tree_selection_get_selected (selection, &model, &iter) && model) {
+ CamelMimeMessage *msg = NULL;
+
+ gtk_tree_model_get (model, &iter, 2, &msg, -1);
+
+ if (msg) {
+ found = TRUE;
+ fill_preview_func (G_OBJECT (preview), msg);
+ g_object_unref (msg);
+ }
+ }
+
+ if (!found) {
+ e_web_view_preview_begin_update (preview);
+ e_web_view_preview_end_update (preview);
+ }
+}
+
+static GtkWidget *
+mbox_get_preview (EImport *ei, EImportTarget *target, EImportImporter *im)
+{
+ GtkWidget *preview = NULL;
+ EImportTargetURI *s = (EImportTargetURI *)target;
+ gchar *filename;
+ gint fd;
+ CamelMimeParser *mp;
+ GtkListStore *store = NULL;
+ GtkTreeIter iter;
+ GtkWidget *preview_widget = NULL;
+
+ if (!create_preview_func || !fill_preview_func)
+ return NULL;
+
+ filename = g_filename_from_uri (s->uri_src, NULL, NULL);
+ if (!filename) {
+ g_message (G_STRLOC ": Couldn't get filename from URI '%s'", s->uri_src);
+ return NULL;
+ }
+
+ fd = g_open (filename, O_RDONLY|O_BINARY, 0);
+ if (fd == -1) {
+ g_warning ("Cannot find source file to import '%s': %s", filename, g_strerror (errno));
+ g_free (filename);
+ return NULL;
+ }
+
+ g_free (filename);
+
+ mp = camel_mime_parser_new();
+ camel_mime_parser_scan_from (mp, TRUE);
+ if (camel_mime_parser_init_with_fd (mp, fd) == -1) {
+ g_object_unref (mp);
+ return NULL;
+ }
+
+ while (camel_mime_parser_step (mp, NULL, NULL) == CAMEL_MIME_PARSER_STATE_FROM) {
+ CamelMimeMessage *msg;
+ gchar *from;
+
+ msg = camel_mime_message_new();
+ if (camel_mime_part_construct_from_parser ((CamelMimePart *)msg, mp) == -1) {
+ g_object_unref (msg);
+ break;
+ }
+
+ if (!store)
+ store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, CAMEL_TYPE_MIME_MESSAGE);
+
+ from = NULL;
+ if (camel_mime_message_get_from (msg))
+ from = camel_address_encode (CAMEL_ADDRESS (camel_mime_message_get_from (msg)));
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, camel_mime_message_get_subject (msg) ? camel_mime_message_get_subject (msg) : "",
+ 1, from ? from : "",
+ 2, msg,
+ -1);
+
+ g_object_unref (msg);
+ g_free (from);
+
+ camel_mime_parser_step (mp, NULL, NULL);
+ }
+
+ if (store) {
+ GtkTreeView *tree_view;
+ GtkTreeSelection *selection;
+
+ preview = e_web_view_preview_new ();
+ gtk_widget_show (preview);
+
+ tree_view = e_web_view_preview_get_tree_view (E_WEB_VIEW_PREVIEW (preview));
+ g_return_val_if_fail (tree_view != NULL, NULL);
+
+ gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ /* Translators: Column header for a message subject */
+ gtk_tree_view_insert_column_with_attributes (tree_view, -1, C_("mboxImp", "Subject"),
+ gtk_cell_renderer_text_new (), "text", 0, NULL);
+
+ /* Translators: Column header for a message From address */
+ gtk_tree_view_insert_column_with_attributes (tree_view, -1, C_("mboxImp", "From"),
+ gtk_cell_renderer_text_new (), "text", 1, NULL);
+
+ if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) > 1)
+ e_web_view_preview_show_tree_view (E_WEB_VIEW_PREVIEW (preview));
+
+ create_preview_func (G_OBJECT (preview), &preview_widget);
+ g_return_val_if_fail (preview_widget != NULL, NULL);
+
+ e_web_view_preview_set_preview (E_WEB_VIEW_PREVIEW (preview), preview_widget);
+ gtk_widget_show (preview_widget);
+
+ selection = gtk_tree_view_get_selection (tree_view);
+ g_return_val_if_fail (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter), NULL);
+ gtk_tree_selection_select_iter (selection, &iter);
+ g_signal_connect (selection, "changed", G_CALLBACK (preview_selection_changed_cb), preview);
+
+ preview_selection_changed_cb (selection, E_WEB_VIEW_PREVIEW (preview));
+ }
+
+ return preview;
+}
+
static EImportImporter mbox_importer = {
E_IMPORT_TARGET_URI,
0,
@@ -254,6 +403,7 @@ static EImportImporter mbox_importer = {
mbox_getwidget,
mbox_import,
mbox_cancel,
+ mbox_get_preview,
};
EImportImporter *
diff --git a/mail/importers/mail-importer.h b/mail/importers/mail-importer.h
index 5f2f8c8b26..15de575f8b 100644
--- a/mail/importers/mail-importer.h
+++ b/mail/importers/mail-importer.h
@@ -29,6 +29,13 @@
EImportImporter *mbox_importer_peek(void);
+typedef void (*MboxImporterCreatePreviewFunc)(GObject *preview, GtkWidget **preview_widget);
+typedef void (*MboxImporterFillPreviewFunc)(GObject *preview, CamelMimeMessage *msg);
+
+/* 'create_func' is a function to create a view. 'fill_func' is to fill view with a preview of a message 'msg'
+ (mail importer cannot link to em-format-html-display directly) */
+void mbox_importer_set_preview_funcs (MboxImporterCreatePreviewFunc create_func, MboxImporterFillPreviewFunc fill_func);
+
EImportImporter *elm_importer_peek(void);
EImportImporter *pine_importer_peek(void);
diff --git a/mail/importers/pine-importer.c b/mail/importers/pine-importer.c
index 07b7f22fbb..ed3b62e0b1 100644
--- a/mail/importers/pine-importer.c
+++ b/mail/importers/pine-importer.c
@@ -410,6 +410,7 @@ static EImportImporter pine_importer = {
pine_getwidget,
pine_import,
pine_cancel,
+ NULL, /* get_preview */
};
EImportImporter *