2005-08-19 [colin] 1.9.13cvs43
[claws.git] / src / inc.c
index 20ebb7499a91b869bbb533c33a1a95c4b03c73dd..522dd68e9213e141805879b3310921f8474a98b6 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -24,6 +24,7 @@
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtkwindow.h>
 #include <gtk/gtksignal.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
-#include <time.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <signal.h>
-#include <errno.h>
-
-#include "intl.h"
+
 #include "main.h"
 #include "inc.h"
 #include "mainwindow.h"
@@ -176,7 +169,7 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
        if (prefs_common.work_offline)
                if (alertpanel(_("Offline warning"), 
                               _("You're working offline. Override?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                              GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
                return;
 
        inc_lock();
@@ -281,7 +274,7 @@ gint inc_account_mail(MainWindow *mainwin, PrefsAccount *account)
        if (prefs_common.work_offline)
                if (alertpanel(_("Offline warning"), 
                               _("You're working offline. Override?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                              GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
                        return 0;
 
        inc_autocheck_timer_remove();
@@ -307,7 +300,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
        if (prefs_common.work_offline)
                if (alertpanel(_("Offline warning"), 
                               _("You're working offline. Override?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+                              GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
                return;
 
        if (inc_lock_count) return;
@@ -385,11 +378,11 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
 
        progress_dialog_get_fraction(progress);
 
-       stock_pixbuf_gdk(progress->list_view, STOCK_PIXMAP_COMPLETE,
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_COMPLETE,
                         &okpix);
-       stock_pixbuf_gdk(progress->list_view, STOCK_PIXMAP_CONTINUE,
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_CONTINUE,
                         &currentpix);
-       stock_pixbuf_gdk(progress->list_view, STOCK_PIXMAP_ERROR,
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_ERROR,
                         &errorpix);
 
        if (prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS ||
@@ -400,8 +393,8 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
        }
 
        dialog->dialog = progress;
-       gettimeofday(&dialog->progress_tv, NULL);
-       gettimeofday(&dialog->folder_tv, NULL);
+       g_get_current_time(&dialog->progress_tv);
+       g_get_current_time(&dialog->folder_tv);
        dialog->queue_list = NULL;
        dialog->cur_row = 0;
 
@@ -496,6 +489,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
        FolderItem *processing, *inbox;
        MsgInfo *msginfo;
        GSList *msglist, *msglist_element;
+       gboolean cancelled = FALSE;
 
        qlist = inc_dialog->queue_list;
        while (qlist != NULL) {
@@ -546,7 +540,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                                 str);                                     \
 }
 
-       for (; inc_dialog->queue_list != NULL; inc_dialog->cur_row++) {
+       for (; inc_dialog->queue_list != NULL && !cancelled; inc_dialog->cur_row++) {
+               int cur = 0, total = 0;
                session = inc_dialog->queue_list->data;
                pop3_session = POP3_SESSION(session->session);
 
@@ -559,8 +554,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                }
 
                inc_progress_dialog_clear(inc_dialog);
-               progress_dialog_list_select_row(inc_dialog->dialog,
-                                               inc_dialog->cur_row);
+               progress_dialog_scroll_to_row(inc_dialog->dialog,
+                                             inc_dialog->cur_row);
 
                SET_PIXMAP_AND_TEXT(currentpix, _("Retrieving"));
 
@@ -570,8 +565,10 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                switch (inc_state) {
                case INC_SUCCESS:
                        if (pop3_session->cur_total_num > 0)
-                               msg = g_strdup_printf
-                                       (_("Done (%d message(s) (%s) received)"),
+                               msg = g_strdup_printf(
+                                       ngettext("Done (%d message (%s) received)",
+                                                "Done (%d messages (%s) received)",
+                                        pop3_session->cur_total_num),
                                         pop3_session->cur_total_num,
                                         to_human_readable(pop3_session->cur_total_recv_bytes));
                        else
@@ -600,6 +597,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                        break;
                case INC_CANCEL:
                        SET_PIXMAP_AND_TEXT(okpix, _("Cancelled"));
+                       if (!inc_dialog->show_dialog)
+                               cancelled = TRUE;
                        break;
                default:
                        break;
@@ -630,13 +629,30 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 
                /* process messages */
                folder_item_update_freeze();
-               for(msglist_element = msglist; msglist_element != NULL; msglist_element = msglist_element->next) {
+               if (pop3_session->ac_prefs->filter_on_recv)
+                       statusbar_print_all(_("Filtering messages...\n"));
+               total = g_slist_length(msglist);
+
+               for(msglist_element = msglist; msglist_element != NULL; 
+                   msglist_element = msglist_element->next) {
+                       gchar *filename;
                        msginfo = (MsgInfo *) msglist_element->data;
-                       if (!pop3_session->ac_prefs->filter_on_recv || !procmsg_msginfo_filter(msginfo))
+                       filename = folder_item_fetch_msg(processing, msginfo->msgnum);
+                       g_free(filename);
+
+                       if (pop3_session->ac_prefs->filter_on_recv)
+                               statusbar_progress_all(cur++,total, prefs_common.statusbar_update_step);
+
+                       if (!pop3_session->ac_prefs->filter_on_recv || 
+                           !procmsg_msginfo_filter(msginfo))
                                folder_item_move_msg(inbox, msginfo);
                        procmsg_msginfo_free(msginfo);
                }
                folder_item_update_thaw();
+               
+               statusbar_progress_all(0,0,0);
+               statusbar_pop_all();
+
                g_slist_free(msglist);
 
                statusbar_pop_all();
@@ -675,8 +691,9 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 #undef SET_PIXMAP_AND_TEXT
 
        if (new_msgs > 0)
-               fin_msg = g_strdup_printf(_("Finished (%d new message(s))"),
-                                         new_msgs);
+               fin_msg = g_strdup_printf(ngettext("Finished (%d new message)",
+                                                  "Finished (%d new messages)",
+                                                  new_msgs), new_msgs);
        else
                fin_msg = g_strdup_printf(_("Finished (no new messages)"));
 
@@ -706,8 +723,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
        else {
                gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window),
                                     fin_msg);
-               gtk_label_set_text(GTK_LABEL(GTK_BIN(inc_dialog->dialog->cancel_btn)->child),
-                                  _("Close"));
+               gtk_button_set_label(GTK_BUTTON(inc_dialog->dialog->cancel_btn),
+                                    GTK_STOCK_CLOSE);
        }
 
        g_free(fin_msg);
@@ -925,7 +942,9 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
 
        if (pop3_session->cur_total_num > 0) {
                g_snprintf(buf, sizeof(buf),
-                          _("Retrieving (%d message(s) (%s) received)"),
+                          ngettext("Retrieving (%d message (%s) received)",
+                                   "Retrieving (%d messages (%s) received)",
+                                   pop3_session->cur_total_num),
                           pop3_session->cur_total_num,
                           to_human_readable
                           (pop3_session->cur_total_recv_bytes));
@@ -938,17 +957,17 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
 static void inc_progress_dialog_update_periodic(IncProgressDialog *inc_dialog,
                                                IncSession *inc_session)
 {
-       struct timeval tv_cur;
-       struct timeval tv_result;
+       GTimeVal tv_cur;
+       GTimeVal tv_result;
        gint msec;
 
-       gettimeofday(&tv_cur, NULL);
+       g_get_current_time(&tv_cur);
 
        tv_result.tv_sec = tv_cur.tv_sec - inc_dialog->progress_tv.tv_sec;
        tv_result.tv_usec = tv_cur.tv_usec - inc_dialog->progress_tv.tv_usec;
        if (tv_result.tv_usec < 0) {
                tv_result.tv_sec--;
-               tv_result.tv_usec += 1000000;
+               tv_result.tv_usec += G_USEC_PER_SEC;
        }
 
        msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
@@ -1054,7 +1073,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        } else
                inbox = folder_get_default_inbox();
        if (!inbox) {
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -1064,7 +1083,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        /* add msg file to drop folder */
        if ((msgnum = folder_item_add_msg(
                        dropfolder, file, NULL, TRUE)) < 0) {
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -1300,7 +1319,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
 
        msgs = proc_mbox(dest, tmp_mbox, TRUE);
 
-       unlink(tmp_mbox);
+       g_unlink(tmp_mbox);
        if (msgs >= 0) empty_mbox(mbox);
        unlock_mbox(mbox, lockfd, LOCK_FLOCK);