diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2009-08-04 07:08:14 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2009-08-04 07:08:14 +0000 |
commit | c24bf4d56469351ead16dd9d917bcddeff9d4fc7 (patch) | |
tree | 6b593d9e5828f695e072533975e79e3d0adaabf5 | |
parent | f9900e671911918612d952dd669aa2129c13227e (diff) |
show progressbar on mbox import.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2196 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | libsylph/mbox.c | 17 | ||||
-rw-r--r-- | src/import.c | 56 | ||||
-rw-r--r-- | src/progressdialog.c | 100 | ||||
-rw-r--r-- | src/progressdialog.h | 6 |
5 files changed, 135 insertions, 54 deletions
@@ -1,3 +1,13 @@ +2009-08-04 + + libsylph/mbox.c + src/progressdialog.[ch] + src/import.c: show progressbar on mbox import. + +2009-07-21 + + * version 2.7.0 + 2009-07-01 * PLUGIN.txt diff --git a/libsylph/mbox.c b/libsylph/mbox.c index 34aad016..cbc461d1 100644 --- a/libsylph/mbox.c +++ b/libsylph/mbox.c @@ -69,13 +69,18 @@ gint proc_mbox_full(FolderItem *dest, const gchar *mbox, FILE *mbox_fp; gchar buf[BUFFSIZE], from_line[BUFFSIZE]; gchar *tmp_file; - gint msgs = 0; + gint new_msgs = 0; + gint count = 0; + Folder *folder; g_return_val_if_fail(dest != NULL, -1); + g_return_val_if_fail(dest->folder != NULL, -1); g_return_val_if_fail(mbox != NULL, -1); debug_print(_("Getting messages from %s into %s...\n"), mbox, dest->path); + folder = dest->folder; + if ((mbox_fp = g_fopen(mbox, "rb")) == NULL) { FILE_OP_ERROR(mbox, "fopen"); return -1; @@ -114,6 +119,10 @@ gint proc_mbox_full(FolderItem *dest, const gchar *mbox, gboolean is_junk = FALSE; FilterInfo *fltinfo; + count++; + if (folder->ui_func) + folder->ui_func(folder, dest, folder->ui_func_data ? dest->folder->ui_func_data : GINT_TO_POINTER(count)); + if ((tmp_fp = g_fopen(tmp_file, "wb")) == NULL) { FILE_OP_ERROR(tmp_file, "fopen"); g_warning(_("can't open temporary file\n")); @@ -268,7 +277,7 @@ gint proc_mbox_full(FolderItem *dest, const gchar *mbox, if (!is_junk && fltinfo->actions[FLT_ACTION_DELETE] == FALSE && fltinfo->actions[FLT_ACTION_MARK_READ] == FALSE) - msgs++; + new_msgs++; filter_info_free(fltinfo); g_unlink(tmp_file); @@ -276,9 +285,9 @@ gint proc_mbox_full(FolderItem *dest, const gchar *mbox, g_free(tmp_file); fclose(mbox_fp); - debug_print("%d new messages found.\n", msgs); + debug_print("%d new messages found.\n", new_msgs); - return msgs; + return new_msgs; } gint lock_mbox(const gchar *base, LockType type) diff --git a/src/import.c b/src/import.c index 139ea18a..3a247385 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-2006 Hiroyuki Yamamoto + * Copyright (C) 1999-2009 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 @@ -37,6 +37,7 @@ #include <gtk/gtkbutton.h> #include <gtk/gtksignal.h> #include <gtk/gtkstock.h> +#include <gtk/gtkprogressbar.h> #include "main.h" #include "inc.h" @@ -47,6 +48,8 @@ #include "gtkutils.h" #include "manage_window.h" #include "folder.h" +#include "progressdialog.h" +#include "alertpanel.h" static GtkWidget *window; static GtkWidget *file_entry; @@ -57,6 +60,7 @@ static GtkWidget *ok_button; static GtkWidget *cancel_button; static gboolean import_finished; static gboolean import_ack; +static ProgressDialog *progress; static void import_create (void); static void import_ok_cb (GtkWidget *widget, @@ -74,6 +78,26 @@ static gboolean key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer data); + +static void proc_mbox_func(Folder *folder, FolderItem *item, 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 (tv_prev.tv_sec == 0 || + (tv_cur.tv_sec - tv_prev.tv_sec) * G_USEC_PER_SEC + + tv_cur.tv_usec - tv_prev.tv_usec > 100 * 1000) { + g_snprintf(str, sizeof(str), "%d", count); + gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->progressbar), str); + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress->progressbar)); + ui_update(); + tv_prev = tv_cur; + } +} + gint import_mbox(FolderItem *default_dest) { gint ok = 0; @@ -121,11 +145,29 @@ gint import_mbox(FolderItem *default_dest) (destdir); if (!dest) { - g_warning("Can't find the folder.\n"); + alertpanel_error(_("Can't find the destination folder.")); } else { + gchar *msg; + + msg = g_strdup_printf + (_("Importing %s ..."), + g_basename(utf8filename)); + progress = progress_dialog_simple_create(); + gtk_window_set_title + (GTK_WINDOW(progress->window), + _("Importing")); + progress_dialog_set_label(progress, msg); + gtk_widget_hide(progress->cancel_btn); + gtk_widget_show(progress->window); + ui_update(); + folder_set_ui_func(dest->folder, proc_mbox_func, NULL); ok = proc_mbox(dest, filename, NULL); + folder_set_ui_func(dest->folder, NULL, NULL); folder_item_scan(dest); folderview_update_item(dest, TRUE); + progress_dialog_destroy(progress); + progress = NULL; + g_free(msg); } g_free(filename); @@ -260,10 +302,16 @@ static void import_filesel_cb(GtkWidget *widget, gpointer data) static void import_destsel_cb(GtkWidget *widget, gpointer data) { FolderItem *dest; + gchar *dest_id; dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL); - if (dest && dest->path) - gtk_entry_set_text(GTK_ENTRY(dest_entry), dest->path); + if (dest && dest->path) { + dest_id = folder_item_get_identifier(dest); + if (dest_id) { + gtk_entry_set_text(GTK_ENTRY(dest_entry), dest_id); + g_free(dest_id); + } + } } static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data) diff --git a/src/progressdialog.c b/src/progressdialog.c index a015ad31..e650d504 100644 --- a/src/progressdialog.c +++ b/src/progressdialog.c @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2008 Hiroyuki Yamamoto + * Copyright (C) 1999-2009 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 @@ -43,11 +43,6 @@ ProgressDialog *progress_dialog_create(void) { ProgressDialog *progress; - GtkWidget *dialog; - GtkWidget *hbox; - GtkWidget *label; - GtkWidget *cancel_btn; - GtkWidget *progressbar; GtkWidget *scrolledwin; GtkWidget *treeview; GtkListStore *store; @@ -55,45 +50,12 @@ ProgressDialog *progress_dialog_create(void) GtkTreeViewColumn *column; GtkCellRenderer *renderer; - debug_print(_("Creating progress dialog...\n")); - progress = g_new0(ProgressDialog, 1); - - dialog = gtk_dialog_new(); - gtk_widget_set_size_request(dialog, 460, -1); - gtk_container_set_border_width(GTK_CONTAINER(dialog), 8); - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); - gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, TRUE); - gtk_widget_realize(dialog); - - gtk_container_set_border_width - (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 0); - gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 8); - gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); - - hbox = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, - FALSE, FALSE, 8); - gtk_widget_show(hbox); - - label = gtk_label_new(""); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8); - gtk_widget_show(label); - - cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), - GTK_STOCK_CANCEL, - GTK_RESPONSE_NONE); - gtk_widget_grab_default(cancel_btn); - gtk_widget_grab_focus(cancel_btn); - - progressbar = gtk_progress_bar_new(); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), progressbar, - FALSE, FALSE, 0); - gtk_widget_show(progressbar); + progress = progress_dialog_simple_create(); scrolledwin = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrolledwin); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolledwin, - TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(progress->window)->vbox), + scrolledwin, TRUE, TRUE, 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); @@ -147,12 +109,62 @@ ProgressDialog *progress_dialog_create(void) gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + progress->treeview = treeview; + progress->store = store; + + return progress; +} + +ProgressDialog *progress_dialog_simple_create(void) +{ + ProgressDialog *progress; + GtkWidget *dialog; + GtkWidget *hbox; + GtkWidget *label; + GtkWidget *cancel_btn; + GtkWidget *progressbar; + + debug_print("Creating progress dialog\n"); + progress = g_new0(ProgressDialog, 1); + + dialog = gtk_dialog_new(); + gtk_widget_set_size_request(dialog, 460, -1); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 8); + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); + gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, TRUE); + gtk_widget_realize(dialog); + + gtk_container_set_border_width + (GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 0); + gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 8); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); + + hbox = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, + FALSE, FALSE, 8); + gtk_widget_show(hbox); + + label = gtk_label_new(""); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8); + gtk_widget_show(label); + + cancel_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), + GTK_STOCK_CANCEL, + GTK_RESPONSE_NONE); + gtk_widget_grab_default(cancel_btn); + gtk_widget_grab_focus(cancel_btn); + + progressbar = gtk_progress_bar_new(); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), progressbar, + FALSE, FALSE, 0); + gtk_widget_show(progressbar); + progress->window = dialog; progress->label = label; progress->cancel_btn = cancel_btn; progress->progressbar = progressbar; - progress->treeview = treeview; - progress->store = store; + progress->treeview = NULL; + progress->store = NULL; return progress; } diff --git a/src/progressdialog.h b/src/progressdialog.h index 1a722b3a..fd5a3278 100644 --- a/src/progressdialog.h +++ b/src/progressdialog.h @@ -1,6 +1,6 @@ /* * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client - * Copyright (C) 1999-2008 Hiroyuki Yamamoto + * Copyright (C) 1999-2009 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 @@ -48,7 +48,9 @@ typedef enum PROG_N_COLS } ProgressColumn; -ProgressDialog *progress_dialog_create (void); +ProgressDialog *progress_dialog_create (void); +ProgressDialog *progress_dialog_simple_create (void); + void progress_dialog_destroy (ProgressDialog *progress); void progress_dialog_set_label (ProgressDialog *progress, |