2005-06-14 [paul] 1.9.11cvs66
[claws.git] / src / inc.c
index 5f32f9e4088a621dfb3de3fdf6c92d8115218ca5..7329ac3873546356053f163bb82f67f951990d00 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 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
@@ -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>
@@ -39,7 +40,6 @@
 #include <signal.h>
 #include <errno.h>
 
-#include "intl.h"
 #include "main.h"
 #include "inc.h"
 #include "mainwindow.h"
@@ -71,12 +71,9 @@ static GList *inc_dialog_list = NULL;
 
 static guint inc_lock_count = 0;
 
-static GdkPixmap *currentxpm;
-static GdkBitmap *currentxpmmask;
-static GdkPixmap *errorxpm;
-static GdkBitmap *errorxpmmask;
-static GdkPixmap *okxpm;
-static GdkBitmap *okxpmmask;
+static GdkPixbuf *current_pixbuf;
+static GdkPixbuf *error_pixbuf;
+static GdkPixbuf *ok_pixbuf;
 
 #define MSGBUFSIZE     8192
 
@@ -123,7 +120,7 @@ static gint inc_drop_message                (Pop3Session    *session,
                                         const gchar    *file);
 
 static void inc_put_error              (IncState        istate,
-                                        const gchar    *msg);
+                                        Pop3Session    *session);
 
 static void inc_cancel_cb              (GtkWidget      *widget,
                                         gpointer        data);
@@ -388,12 +385,10 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
 
        progress_dialog_set_value(progress, 0.0);
 
-       stock_pixmap_gdk(progress->clist, STOCK_PIXMAP_COMPLETE,
-                        &okxpm, &okxpmmask);
-       stock_pixmap_gdk(progress->clist, STOCK_PIXMAP_CONTINUE,
-                        &currentxpm, &currentxpmmask);
-       stock_pixmap_gdk(progress->clist, STOCK_PIXMAP_ERROR,
-                        &errorxpm, &errorxpmmask);
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_COMPLETE, &ok_pixbuf);
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_CONTINUE,
+                        &current_pixbuf);
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_ERROR, &error_pixbuf);
 
        if (prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS ||
            (prefs_common.recv_dialog_mode == RECV_DIALOG_MANUAL &&
@@ -420,14 +415,11 @@ static void inc_progress_dialog_set_list(IncProgressDialog *inc_dialog)
        for (list = inc_dialog->queue_list; list != NULL; list = list->next) {
                IncSession *session = list->data;
                Pop3Session *pop3_session = POP3_SESSION(session->session);
-               gchar *text[3];
 
                session->data = inc_dialog;
-
-               text[0] = NULL;
-               text[1] = pop3_session->ac_prefs->account_name;
-               text[2] = _("Standby");
-               gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
+               progress_dialog_append(inc_dialog->dialog, NULL,
+                                      pop3_session->ac_prefs->account_name,
+                                      _("Standby"), NULL);
        }
 }
 
@@ -458,7 +450,7 @@ static IncSession *inc_session_new(PrefsAccount *account)
 
        g_return_val_if_fail(account != NULL, NULL);
 
-       if (account->protocol != A_POP3 && account->protocol != A_APOP)
+       if (account->protocol != A_POP3)
                return NULL;
        if (!account->recv_server || !account->userid)
                return NULL;
@@ -490,7 +482,6 @@ static void inc_session_destroy(IncSession *session)
 static gint inc_start(IncProgressDialog *inc_dialog)
 {
        IncSession *session;
-       GtkCList *clist = GTK_CLIST(inc_dialog->dialog->clist);
        GList *qlist;
        Pop3Session *pop3_session;
        IncState inc_state;
@@ -501,6 +492,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) {
@@ -542,18 +534,20 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                qlist = next;
        }
 
-#define SET_PIXMAP_AND_TEXT(xpm, xpmmask, str)                            \
-{                                                                         \
-       gtk_clist_set_pixmap(clist, inc_dialog->cur_row, 0, xpm, xpmmask); \
-       gtk_clist_set_text(clist, inc_dialog->cur_row, 2, str);            \
+#define SET_PIXMAP_AND_TEXT(pixbuf, str)                               \
+{                                                                      \
+       progress_dialog_set_row_pixbuf(inc_dialog->dialog,              \
+                                      inc_dialog->cur_row, pixbuf);    \
+       progress_dialog_set_row_status(inc_dialog->dialog,              \
+                                      inc_dialog->cur_row, str);       \
 }
 
-       for (; inc_dialog->queue_list != NULL; inc_dialog->cur_row++) {
+       for (; inc_dialog->queue_list != NULL && !cancelled; inc_dialog->cur_row++) {
                session = inc_dialog->queue_list->data;
                pop3_session = POP3_SESSION(session->session);
 
                if (pop3_session->pass == NULL) {
-                       SET_PIXMAP_AND_TEXT(okxpm, okxpmmask, _("Cancelled"));
+                       SET_PIXMAP_AND_TEXT(ok_pixbuf, _("Cancelled"));
                        inc_session_destroy(session);
                        inc_dialog->queue_list =
                                g_list_remove(inc_dialog->queue_list, session);
@@ -561,10 +555,10 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                }
 
                inc_progress_dialog_clear(inc_dialog);
-               gtk_clist_moveto(clist, inc_dialog->cur_row, -1, 1.0, 0.0);
+               progress_dialog_scroll_to_row(inc_dialog->dialog,
+                                             inc_dialog->cur_row);
 
-               SET_PIXMAP_AND_TEXT(currentxpm, currentxpmmask,
-                                   _("Retrieving"));
+               SET_PIXMAP_AND_TEXT(current_pixbuf, _("Retrieving"));
 
                /* begin POP3 session */
                inc_state = inc_pop3_session_do(session);
@@ -572,39 +566,41 @@ 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
                                msg = g_strdup_printf(_("Done (no new messages)"));
-                       SET_PIXMAP_AND_TEXT(okxpm, okxpmmask, msg);
+                       SET_PIXMAP_AND_TEXT(ok_pixbuf, msg);
                        g_free(msg);
                        break;
                case INC_CONNECT_ERROR:
-                       SET_PIXMAP_AND_TEXT(errorxpm, errorxpmmask,
+                       SET_PIXMAP_AND_TEXT(error_pixbuf,
                                            _("Connection failed"));
                        break;
                case INC_AUTH_FAILED:
-                       SET_PIXMAP_AND_TEXT(errorxpm, errorxpmmask,
-                                           _("Auth failed"));
+                       SET_PIXMAP_AND_TEXT(error_pixbuf, _("Auth failed"));
                        break;
                case INC_LOCKED:
-                       SET_PIXMAP_AND_TEXT(errorxpm, errorxpmmask,
-                                           _("Locked"));
+                       SET_PIXMAP_AND_TEXT(error_pixbuf, _("Locked"));
                        break;
                case INC_ERROR:
                case INC_NO_SPACE:
                case INC_IO_ERROR:
                case INC_SOCKET_ERROR:
                case INC_EOF:
-                       SET_PIXMAP_AND_TEXT(errorxpm, errorxpmmask, _("Error"));
+                       SET_PIXMAP_AND_TEXT(error_pixbuf, _("Error"));
                        break;
                case INC_TIMEOUT:
-                       SET_PIXMAP_AND_TEXT(errorxpm, errorxpmmask, _("Timeout"));
+                       SET_PIXMAP_AND_TEXT(error_pixbuf, _("Timeout"));
                        break;
                case INC_CANCEL:
-                       SET_PIXMAP_AND_TEXT(okxpm, okxpmmask, _("Cancelled"));
+                       SET_PIXMAP_AND_TEXT(ok_pixbuf, _("Cancelled"));
+                       if (!inc_dialog->show_dialog)
+                               cancelled = TRUE;
                        break;
                default:
                        break;
@@ -634,12 +630,18 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                msglist = folder_item_get_msg_list(processing);
 
                /* process messages */
+               folder_item_update_freeze();
                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 || 
+                           !procmsg_msginfo_filter(msginfo))
                                folder_item_move_msg(inbox, msginfo);
                        procmsg_msginfo_free(msginfo);
                }
+               folder_item_update_thaw();
                g_slist_free(msglist);
 
                statusbar_pop_all();
@@ -660,7 +662,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                                manage_window_focus_in
                                        (inc_dialog->dialog->window,
                                         NULL, NULL);
-                       inc_put_error(inc_state, pop3_session->error_msg);
+                       inc_put_error(inc_state, pop3_session);
                        if (inc_dialog->show_dialog)
                                manage_window_focus_out
                                        (inc_dialog->dialog->window,
@@ -678,8 +680,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)"));
 
@@ -709,8 +712,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);
@@ -930,12 +933,14 @@ 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));
-               gtk_clist_set_text(GTK_CLIST(inc_dialog->dialog->clist),
-                                  inc_dialog->cur_row, 2, buf);
+               progress_dialog_set_row_status(inc_dialog->dialog,
+                                              inc_dialog->cur_row, buf);
        }
 }
 
@@ -1075,7 +1080,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        return 0;
 }
 
-static void inc_put_error(IncState istate, const gchar *msg)
+static void inc_put_error(IncState istate, Pop3Session *session)
 {
        gchar *log_msg = NULL;
        gchar *err_msg = NULL;
@@ -1086,16 +1091,18 @@ static void inc_put_error(IncState istate, const gchar *msg)
                log_msg = _("Connection failed.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               err_msg = g_strdup(log_msg);
+               err_msg = g_strdup_printf(_("Connection to %s:%d failed."),
+                                         SESSION(session)->server, 
+                                         SESSION(session)->port);
                break;
        case INC_ERROR:
                log_msg = _("Error occurred while processing mail.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               if (msg)
+               if (session->error_msg)
                        err_msg = g_strdup_printf
                                (_("Error occurred while processing mail:\n%s"),
-                                msg);
+                                session->error_msg);
                else
                        err_msg = g_strdup(log_msg);
                break;
@@ -1113,21 +1120,25 @@ static void inc_put_error(IncState istate, const gchar *msg)
                log_msg = _("Socket error.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               err_msg = g_strdup(log_msg);
+               err_msg = g_strdup_printf(_("Socket error on connection to %s:%d."),
+                                         SESSION(session)->server, 
+                                         SESSION(session)->port);
                break;
        case INC_EOF:
                log_msg = _("Connection closed by the remote host.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               err_msg = g_strdup(log_msg);
+               err_msg = g_strdup_printf(_("Connection to %s:%d closed by the remote host."), 
+                                         SESSION(session)->server, 
+                                         SESSION(session)->port);
                break;
        case INC_LOCKED:
                log_msg = _("Mailbox is locked.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               if (msg)
+               if (session->error_msg)
                        err_msg = g_strdup_printf(_("Mailbox is locked:\n%s"),
-                                                 msg);
+                                                 session->error_msg);
                else
                        err_msg = g_strdup(log_msg);
                break;
@@ -1135,9 +1146,9 @@ static void inc_put_error(IncState istate, const gchar *msg)
                log_msg = _("Authentication failed.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               if (msg)
+               if (session->error_msg)
                        err_msg = g_strdup_printf
-                               (_("Authentication failed:\n%s"), msg);
+                               (_("Authentication failed:\n%s"), session->error_msg);
                else
                        err_msg = g_strdup(log_msg);
                break;
@@ -1145,7 +1156,9 @@ static void inc_put_error(IncState istate, const gchar *msg)
                log_msg = _("Session timed out.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               err_msg = g_strdup(log_msg);
+               err_msg = g_strdup_printf(_("Connection to %s:%d timed out."), 
+                                         SESSION(session)->server, 
+                                         SESSION(session)->port);
                break;
        default:
                break;
@@ -1213,11 +1226,9 @@ static gint inc_dialog_delete_cb(GtkWidget *widget, GdkEventAny *event,
 static gint inc_spool_account(PrefsAccount *account)
 {
        FolderItem *inbox;
-       gchar *mbox, *logname;
+       gchar *mbox;
        gint result;
 
-       logname = g_get_user_name();
-
        if (account->inbox) {
                inbox = folder_find_item_from_path(account->inbox);
                if (!inbox)
@@ -1227,9 +1238,14 @@ static gint inc_spool_account(PrefsAccount *account)
 
        if (is_file_exist(account->local_mbox))
                mbox = g_strdup(account->local_mbox);
-       else 
-               mbox = g_strconcat(account->local_mbox,
-                                  G_DIR_SEPARATOR_S, logname, NULL);
+       else if (is_dir_exist(account->local_mbox)) 
+               mbox = g_strconcat(account->local_mbox, G_DIR_SEPARATOR_S,
+                                  g_get_user_name(), NULL);
+       else {
+               debug_print("%s: local mailbox not found.\n", 
+                           account->local_mbox);
+               return -1;
+       }
        
        result = get_spool(inbox, mbox);
        g_free(mbox);
@@ -1272,7 +1288,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
        g_return_val_if_fail(mbox != NULL, -1);
 
        if (!is_file_exist(mbox) || (size = get_file_size(mbox)) == 0) {
-               debug_print("no messages in local mailbox.\n");
+               debug_print("%s: no messages in local mailbox.\n", mbox);
                return 0;
        } else if (size < 0)
                return -1;
@@ -1317,7 +1333,8 @@ static gpointer autocheck_data = NULL;
 static void inc_notify_cmd(gint new_msgs, gboolean notify)
 {
 
-       gchar *buf, *numpos;
+       gchar *buf, *numpos, *ret_str;
+       gssize by_read = 0, by_written = 0;
 
        if (!(new_msgs && notify && prefs_common.newmail_notify_cmd &&
            *prefs_common.newmail_notify_cmd))
@@ -1332,6 +1349,12 @@ static void inc_notify_cmd(gint new_msgs, gboolean notify)
                buf = buf2;
        }
 
+       ret_str = g_locale_from_utf8(buf, strlen(buf), &by_read, &by_written,
+                                    NULL);
+       if (ret_str && by_written) {
+               g_free(buf);
+               buf = ret_str;
+       }
        debug_print("executing new mail notification command: %s\n", buf);
        execute_command_line(buf, TRUE);