diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | libsylph/folder.c | 42 | ||||
-rw-r--r-- | libsylph/folder.h | 22 | ||||
-rw-r--r-- | libsylph/mbox.c | 18 | ||||
-rw-r--r-- | src/export.c | 45 | ||||
-rw-r--r-- | src/import.c | 36 |
6 files changed, 130 insertions, 40 deletions
@@ -1,5 +1,12 @@ 2012-07-27 + * libsylph/folder.[ch] + libsylph/mbox.c: added interface to cancel mbox import/export. + * src/export.c + src/import.c: made export/import progress dialog cancellable. + +2012-07-27 + * libsylph/mbox.[ch] src/export.c: added 'Export only selected messages' option to the export dialog. diff --git a/libsylph/folder.c b/libsylph/folder.c index fb5b983d..6c48d355 100644 --- a/libsylph/folder.c +++ b/libsylph/folder.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2011 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -48,6 +48,10 @@ typedef struct _FolderPrivData FolderPrivData; struct _FolderPrivData { Folder *folder; FolderItem *junk; + + FolderUIFunc2 ui_func2; + gpointer ui_func2_data; + gpointer data; }; @@ -442,6 +446,42 @@ void folder_set_ui_func(Folder *folder, FolderUIFunc func, gpointer data) folder->ui_func_data = data; } +void folder_set_ui_func2(Folder *folder, FolderUIFunc2 func, gpointer data) +{ + FolderPrivData *priv; + + priv = folder_get_priv(folder); + if (priv) { + priv->ui_func2 = func; + priv->ui_func2_data = data; + } +} + +FolderUIFunc2 folder_get_ui_func2(Folder *folder) +{ + FolderPrivData *priv; + + priv = folder_get_priv(folder); + if (priv) + return priv->ui_func2; + + return NULL; +} + +gboolean folder_call_ui_func2(Folder *folder, FolderItem *item, guint count, + guint total) +{ + FolderPrivData *priv; + + priv = folder_get_priv(folder); + if (priv && priv->ui_func2) { + return priv->ui_func2(folder, item, count, total, + priv->ui_func2_data); + } + + return TRUE; +} + void folder_set_name(Folder *folder, const gchar *name) { g_return_if_fail(folder != NULL); diff --git a/libsylph/folder.h b/libsylph/folder.h index 221f3e23..5a9e9669 100644 --- a/libsylph/folder.h +++ b/libsylph/folder.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2011 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -115,6 +115,11 @@ typedef enum typedef void (*FolderUIFunc) (Folder *folder, FolderItem *item, gpointer data); +typedef gboolean (*FolderUIFunc2) (Folder *folder, + FolderItem *item, + guint count, + guint total, + gpointer data); typedef void (*FolderDestroyNotify) (Folder *folder, FolderItem *item, gpointer data); @@ -354,9 +359,18 @@ void folder_item_destroy (FolderItem *item); gint folder_item_compare (FolderItem *item_a, FolderItem *item_b); -void folder_set_ui_func (Folder *folder, - FolderUIFunc func, - gpointer data); +void folder_set_ui_func (Folder *folder, + FolderUIFunc func, + gpointer data); +void folder_set_ui_func2 (Folder *folder, + FolderUIFunc2 func, + gpointer data); +FolderUIFunc2 folder_get_ui_func2 (Folder *folder); +gboolean folder_call_ui_func2 (Folder *folder, + FolderItem *item, + guint count, + guint total); + void folder_set_name (Folder *folder, const gchar *name); void folder_tree_destroy (Folder *folder); diff --git a/libsylph/mbox.c b/libsylph/mbox.c index a88e555e..4a241aa1 100644 --- a/libsylph/mbox.c +++ b/libsylph/mbox.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2010 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -71,7 +71,7 @@ gint proc_mbox_full(FolderItem *dest, const gchar *mbox, gchar buf[BUFFSIZE], from_line[BUFFSIZE]; gchar *tmp_file; gint new_msgs = 0; - gint count = 0; + guint count = 0; Folder *folder; FilterRule *junk_rule = NULL; GSList junk_fltlist = {NULL, NULL}; @@ -132,7 +132,11 @@ gint proc_mbox_full(FolderItem *dest, const gchar *mbox, count++; if (folder->ui_func) - folder->ui_func(folder, dest, folder->ui_func_data ? dest->folder->ui_func_data : GINT_TO_POINTER(count)); + folder->ui_func(folder, dest, folder->ui_func_data ? dest->folder->ui_func_data : GUINT_TO_POINTER(count)); + if (folder_call_ui_func2(folder, dest, count, 0) == FALSE) { + debug_print("Import of mbox cancelled at %u\n", count); + break; + } if ((tmp_fp = g_fopen(tmp_file, "wb")) == NULL) { FILE_OP_ERROR(tmp_file, "fopen"); @@ -494,7 +498,7 @@ gint export_msgs_to_mbox(FolderItem *src, GSList *mlist, const gchar *mbox) FILE *mbox_fp; gchar buf[BUFFSIZE]; PrefsAccount *cur_ac; - gint count = 0, length; + guint count = 0, length; g_return_val_if_fail(src != NULL, -1); g_return_val_if_fail(src->folder != NULL, -1); @@ -518,7 +522,11 @@ gint export_msgs_to_mbox(FolderItem *src, GSList *mlist, const gchar *mbox) count++; if (src->folder->ui_func) - src->folder->ui_func(src->folder, src, src->folder->ui_func_data ? src->folder->ui_func_data : GINT_TO_POINTER(count)); + src->folder->ui_func(src->folder, src, src->folder->ui_func_data ? src->folder->ui_func_data : GUINT_TO_POINTER(count)); + if (folder_call_ui_func2(src->folder, src, count, length) == FALSE) { + debug_print("Export to mbox cancelled at %u/%u\n", count, length); + break; + } msg_fp = procmsg_open_message(msginfo); if (!msg_fp) diff --git a/src/export.c b/src/export.c index 4135cb0b..e4500a02 100644 --- a/src/export.c +++ b/src/export.c @@ -81,6 +81,8 @@ static gboolean export_finished; static gboolean export_ack; static ProgressDialog *progress; +static gboolean progress_cancel = FALSE; + static void export_create (void); static gint export_do (void); static gint export_eml (FolderItem *src, @@ -106,19 +108,18 @@ static gboolean key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data); +static void export_progress_cancel_cb (GtkWidget *widget, + gpointer data); + -static void export_mbox_func(Folder *folder, FolderItem *item, gpointer data) +static gboolean export_mbox_func(Folder *folder, FolderItem *item, guint count, guint total, gpointer data) { gchar str[64]; - gint count = GPOINTER_TO_INT(data); static GTimeVal tv_prev = {0, 0}; GTimeVal tv_cur; g_get_current_time(&tv_cur); - if (item->total > 0) - g_snprintf(str, sizeof(str), "%d / %d", count, item->total); - else - g_snprintf(str, sizeof(str), "%d", count); + g_snprintf(str, sizeof(str), "%u / %d", count, total); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->progressbar), str); if (tv_prev.tv_sec == 0 || @@ -131,6 +132,11 @@ static void export_mbox_func(Folder *folder, FolderItem *item, gpointer data) ui_update(); tv_prev = tv_cur; } + + if (progress_cancel) + return FALSE; + else + return TRUE; } gint export_mail(FolderItem *default_src) @@ -215,7 +221,8 @@ static gint export_do(void) g_free(msg); gtk_window_set_modal(GTK_WINDOW(progress->window), TRUE); manage_window_set_transient(GTK_WINDOW(progress->window)); - gtk_widget_hide(progress->cancel_btn); + g_signal_connect(G_OBJECT(progress->cancel_btn), "clicked", + G_CALLBACK(export_progress_cancel_cb), NULL); g_signal_connect(G_OBJECT(progress->window), "delete_event", G_CALLBACK(gtk_true), NULL); gtk_widget_show(progress->window); @@ -228,13 +235,15 @@ static gint export_do(void) mlist = summary_get_selected_msg_list(mainwin->summaryview); } + progress_cancel = FALSE; + if (type == EXPORT_MBOX) { - folder_set_ui_func(src->folder, export_mbox_func, NULL); + folder_set_ui_func2(src->folder, export_mbox_func, NULL); if (mlist) ok = export_msgs_to_mbox(src, mlist, mbox); else ok = export_to_mbox(src, mbox); - folder_set_ui_func(src->folder, NULL, NULL); + folder_set_ui_func2(src->folder, NULL, NULL); } else if (type == EXPORT_EML || type == EXPORT_MH) { ok = export_eml(src, mlist, mbox, type); } @@ -246,7 +255,7 @@ static gint export_do(void) g_slist_free(mlist); g_free(mbox); - if (ok < 0) + if (ok == -1) alertpanel_error(_("Error occurred on export.")); return ok; @@ -259,7 +268,8 @@ static gint export_eml(FolderItem *src, GSList *sel_mlist, const gchar *path, GSList *mlist, *cur; MsgInfo *msginfo; gchar *file, *dest; - gint count = 0; + guint count = 0; + guint total; gint ok = 0; g_return_val_if_fail(src != NULL, -1); @@ -287,19 +297,23 @@ static gint export_eml(FolderItem *src, GSList *sel_mlist, const gchar *path, if (!mlist) return 0; } + total = g_slist_length(mlist); for (cur = mlist; cur != NULL; cur = cur->next) { msginfo = (MsgInfo *)cur->data; count++; - export_mbox_func(src->folder, src, GINT_TO_POINTER(count)); + if (export_mbox_func(src->folder, src, count, total, NULL) == FALSE) { + ok = -2; + break; + } file = folder_item_fetch_msg(src, msginfo->msgnum); if (!file) { ok = -1; break; } - dest = g_strdup_printf("%s%c%d%s", path, G_DIR_SEPARATOR, + dest = g_strdup_printf("%s%c%u%s", path, G_DIR_SEPARATOR, count, ext); if (g_file_test(dest, G_FILE_TEST_EXISTS)) { g_warning("export_eml(): %s already exists.", dest); @@ -528,3 +542,8 @@ static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data export_cancel_cb(NULL, NULL); return FALSE; } + +static void export_progress_cancel_cb(GtkWidget *widget, gpointer data) +{ + progress_cancel = TRUE; +} diff --git a/src/import.c b/src/import.c index 7e17e35c..2e48a9ac 100644 --- a/src/import.c +++ b/src/import.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2010 Hiroyuki Yamamoto + * Copyright (C) 1999-2012 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -119,15 +119,14 @@ static gint import_progress_delete_event(GtkWidget *widget, gpointer data); -static void proc_mbox_func(Folder *folder, FolderItem *item, gpointer data) +static gboolean import_mbox_func(Folder *folder, FolderItem *item, guint count, guint total, gpointer data) { gchar str[64]; - gint count = GPOINTER_TO_INT(data); static GTimeVal tv_prev = {0, 0}; GTimeVal tv_cur; g_get_current_time(&tv_cur); - g_snprintf(str, sizeof(str), "%d", count); + g_snprintf(str, sizeof(str), "%u", count); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->progressbar), str); if (tv_prev.tv_sec == 0 || @@ -137,6 +136,11 @@ static void proc_mbox_func(Folder *folder, FolderItem *item, gpointer data) ui_update(); tv_prev = tv_cur; } + + if (import_progress_cancelled) + return FALSE; + else + return TRUE; } gint import_mail(FolderItem *default_dest) @@ -235,10 +239,9 @@ static gint import_do(void) ui_update(); if (type == IMPORT_MBOX) { - gtk_widget_set_sensitive(progress->cancel_btn, FALSE); - folder_set_ui_func(dest->folder, proc_mbox_func, NULL); + folder_set_ui_func2(dest->folder, import_mbox_func, NULL); ok = proc_mbox(dest, filename, NULL); - folder_set_ui_func(dest->folder, NULL, NULL); + folder_set_ui_func2(dest->folder, NULL, NULL); } else if (type == IMPORT_EML_FOLDER) { ok = import_eml_folder(dest, filename); } else if (type == IMPORT_DBX) { @@ -255,7 +258,7 @@ static gint import_do(void) g_free(filename); - if (ok < 0) + if (ok == -1) alertpanel_error(_("Error occurred on import.")); return ok; @@ -299,16 +302,16 @@ static gint import_eml_folder(FolderItem *dest, const gchar *path) msginfo->file_path = file; file = NULL; count++; - proc_mbox_func(dest->folder, dest, - GINT_TO_POINTER(count)); + if (import_mbox_func(dest->folder, dest, count, 0, NULL) == FALSE) { + ok = -2; + break; + } ok = folder_item_add_msg_msginfo(dest, msginfo, FALSE); procmsg_msginfo_free(msginfo); if (ok < 0) { g_warning("import_eml_folder(): folder_item_add_msg_msginfo() failed."); break; } - if (import_progress_cancelled) - break; } } @@ -443,7 +446,7 @@ static gint import_dbx(FolderItem *dest, const gchar *file) FILE *fp; gint32 dw; gint32 table_pos; - gint count = 0; + guint count = 0; GArray *array; gint i; @@ -467,15 +470,14 @@ static gint import_dbx(FolderItem *dest, const gchar *file) get_dbx_index(fp, table_pos, array); for (i = 0; i < array->len; i++) { - proc_mbox_func(dest->folder, dest, GINT_TO_POINTER(count + 1)); + if (import_mbox_func(dest->folder, dest, count + 1, 0, NULL) == FALSE) + break; if (get_dbx_data(fp, g_array_index(array, gint32, i), dest) < 0) break; count++; - if (import_progress_cancelled) - break; } - debug_print("import_dbx: %d imported\n", count); + debug_print("import_dbx: %u imported\n", count); g_array_free(array, TRUE); fclose(fp); |