aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2009-08-04 07:08:14 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2009-08-04 07:08:14 +0000
commitc24bf4d56469351ead16dd9d917bcddeff9d4fc7 (patch)
tree6b593d9e5828f695e072533975e79e3d0adaabf5 /src
parentf9900e671911918612d952dd669aa2129c13227e (diff)
show progressbar on mbox import.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2196 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src')
-rw-r--r--src/import.c56
-rw-r--r--src/progressdialog.c100
-rw-r--r--src/progressdialog.h6
3 files changed, 112 insertions, 50 deletions
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,