2007-06-24 [colin] 2.9.2cvs73
[claws.git] / src / news_gtk.c
index 06143c3080997d8ddc8a58d3f8018a759e1b6e6c..00f0951e633c6461b7ed85a2c3160e52e1f38340 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto & the Claws Mail Team
  *
  * 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
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 
 #include <gtk/gtk.h>
 
-#include "intl.h"
 #include "utils.h"
 #include "folder.h"
 #include "folderview.h"
 #include "account.h"
 #include "alertpanel.h"
 #include "grouplistdialog.h"
+#include "prefs_common.h"
+#include "news_gtk.h"
 #include "common/hooks.h"
 #include "inc.h"
+#include "news.h"
 
 static void subscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static void unsubscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget);
-static void remove_news_server_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static void update_tree_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static void download_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void sync_cb(FolderView *folderview, guint action, GtkWidget *widget);
 
 static GtkItemFactoryEntry news_popup_entries[] =
 {
        {N_("/_Subscribe to newsgroup..."),     NULL, subscribe_newsgroup_cb,    0, NULL},
        {N_("/_Unsubscribe newsgroup"),         NULL, unsubscribe_newsgroup_cb,  0, NULL},
-       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
-       {N_("/Down_load"),                      NULL, download_cb,               0, NULL},
-       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
+       {"/---",                                NULL, NULL,                      0, "<Separator>"},
+       {N_("/Synchronise"),                    NULL, sync_cb,          0, NULL},
+       {N_("/Down_load messages"),             NULL, download_cb,               0, NULL},
+       {"/---",                                NULL, NULL,                      0, "<Separator>"},
        {N_("/_Check for new messages"),        NULL, update_tree_cb,            0, NULL},
-       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
-       {N_("/Remove _news account"),           NULL, remove_news_server_cb,     0, NULL},
-       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
+       {"/---",                                NULL, NULL,                      0, "<Separator>"},
 };
 
 static void set_sensitivity(GtkItemFactory *factory, FolderItem *item);
@@ -81,14 +83,26 @@ void news_gtk_init(void)
 
 static void set_sensitivity(GtkItemFactory *factory, FolderItem *item)
 {
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
 #define SET_SENS(name, sens) \
        menu_set_sensitive(factory, name, sens)
 
-       SET_SENS("/Subscribe to newsgroup...", folder_item_parent(item) == NULL);
-       SET_SENS("/Unsubscribe newsgroup",     folder_item_parent(item) != NULL);
-       SET_SENS("/Remove news account",       folder_item_parent(item) == NULL);
-
-       SET_SENS("/Check for new messages",    folder_item_parent(item) == NULL);
+       SET_SENS("/Subscribe to newsgroup...", 
+                folder_item_parent(item) == NULL 
+                && mainwin->lock_count == 0
+                && news_folder_locked(item->folder) == 0);
+       SET_SENS("/Unsubscribe newsgroup",     
+                folder_item_parent(item) != NULL 
+                && mainwin->lock_count == 0
+                && news_folder_locked(item->folder) == 0);
+       SET_SENS("/Check for new messages",    
+                folder_item_parent(item) == NULL 
+                && mainwin->lock_count == 0
+                && news_folder_locked(item->folder) == 0);
+       SET_SENS("/Synchronise",    
+                item ? (folder_item_parent(item) != NULL && folder_want_synchronise(item->folder))
+                        : FALSE);
 
 #undef SET_SENS
 }
@@ -104,11 +118,16 @@ static void subscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidg
        GSList *new_subscr;
        GSList *cur;
        GNode *gnode;
-
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
        if (!folderview->selected) return;
 
        item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
        g_return_if_fail(item != NULL);
+
+       if (mainwin->lock_count || news_folder_locked(item->folder))
+               return;
+
        folder = item->folder;
        g_return_if_fail(folder != NULL);
        g_return_if_fail(FOLDER_TYPE(folder) == F_NEWS);
@@ -187,11 +206,16 @@ static void unsubscribe_newsgroup_cb(FolderView *folderview, guint action,
        gchar *message;
        gchar *old_id;
        AlertValue avalue;
-
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
        if (!folderview->selected) return;
 
        item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
        g_return_if_fail(item != NULL);
+
+       if (mainwin->lock_count || news_folder_locked(item->folder))
+               return;
+
        g_return_if_fail(item->folder != NULL);
        g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
        g_return_if_fail(item->folder->account != NULL);
@@ -199,78 +223,44 @@ static void unsubscribe_newsgroup_cb(FolderView *folderview, guint action,
        old_id = folder_item_get_identifier(item);
 
        name = trim_string(item->path, 32);
-       message = g_strdup_printf(_("Really unsubscribe newsgroup `%s'?"), name);
-       avalue = alertpanel(_("Unsubscribe newsgroup"), message,
-                           _("Yes"), _("+No"), NULL);
+       message = g_strdup_printf(_("Really unsubscribe newsgroup '%s'?"), name);
+       avalue = alertpanel_full(_("Unsubscribe newsgroup"), message,
+                                GTK_STOCK_CANCEL, _("_Unsubscribe"), NULL, FALSE,
+                                NULL, ALERT_WARNING, G_ALERTDEFAULT);
        g_free(message);
        g_free(name);
-       if (avalue != G_ALERTDEFAULT) return;
+       if (avalue != G_ALERTALTERNATE) return;
 
        if (folderview->opened == folderview->selected) {
                summary_clear_all(folderview->summaryview);
                folderview->opened = NULL;
        }
 
-       folder_item_remove(item);
+       if(item->folder->klass->remove_folder(item->folder, item) < 0) {
+               folder_item_scan(item);
+               alertpanel_error(_("Can't remove the folder '%s'."), name);
+               g_free(old_id);
+               return;
+       }
+       
        folder_write_list();
        
        prefs_filtering_delete_path(old_id);
        g_free(old_id);
 }
 
-static void remove_news_server_cb(FolderView *folderview, guint action,
-                                 GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       PrefsAccount *account;
-       gchar *name;
-       gchar *message;
-       AlertValue avalue;
-
-       if (!folderview->selected) return;
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-       g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
-       g_return_if_fail(item->folder->account != NULL);
-
-       name = trim_string(item->folder->name, 32);
-       message = g_strdup_printf(_("Really delete news account `%s'?"), name);
-       avalue = alertpanel(_("Delete news account"), message,
-                           _("Yes"), _("+No"), NULL);
-       g_free(message);
-       g_free(name);
-
-       if (avalue != G_ALERTDEFAULT) return;
-
-       if (folderview->opened == folderview->selected ||
-           gtk_ctree_is_ancestor(ctree,
-                                 folderview->selected,
-                                 folderview->opened)) {
-               summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
-       }
-
-       account = item->folder->account;
-       folderview_unselect(folderview);
-       summary_clear_all(folderview->summaryview);
-       folder_destroy(item->folder);
-       account_destroy(account);
-       account_set_menu();
-       main_window_reflect_prefs_all();
-       folder_write_list();
-}
-
 static void update_tree_cb(FolderView *folderview, guint action,
                           GtkWidget *widget)
 {
        FolderItem *item;
-
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
        item = folderview_get_selected_item(folderview);
        g_return_if_fail(item != NULL);
 
+       if (mainwin->lock_count || news_folder_locked(item->folder))
+               return;
+
        summary_show(folderview->summaryview, NULL);
 
        g_return_if_fail(item->folder != NULL);
@@ -278,28 +268,27 @@ static void update_tree_cb(FolderView *folderview, guint action,
        folderview_check_new(item->folder);
 }
 
-static void download_cb(FolderView *folderview, guint action,
-                       GtkWidget *widget)
+static void sync_cb(FolderView *folderview, guint action,
+                          GtkWidget *widget)
 {
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       MainWindow *mainwin = folderview->mainwin;
        FolderItem *item;
 
-       if (!folderview->selected) return;
+       item = folderview_get_selected_item(folderview);
+       g_return_if_fail(item != NULL);
+       folder_synchronise(item->folder);
+}
 
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+void news_gtk_synchronise(FolderItem *item)
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       FolderView *folderview = mainwin->folderview;
+       
        g_return_if_fail(item != NULL);
        g_return_if_fail(item->folder != NULL);
-#if 0
-       if (!prefs_common.online_mode) {
-               if (alertpanel(_("Offline"),
-                              _("You are offline. Go online?"),
-                              _("Yes"), _("No"), NULL) == G_ALERTDEFAULT)
-                       main_window_toggle_online(folderview->mainwin, TRUE);
-               else
-                       return;
-       }
-#endif
+
+       if (mainwin->lock_count || news_folder_locked(item->folder))
+               return;
+
        main_window_cursor_wait(mainwin);
        inc_lock();
        main_window_lock(mainwin);
@@ -310,7 +299,10 @@ static void download_cb(FolderView *folderview, guint action,
                gchar *name;
 
                name = trim_string(item->name, 32);
-               alertpanel_error(_("Error occurred while downloading messages in `%s'."), name);
+               if (prefs_common.no_recv_err_panel)
+                       log_error(LOG_PROTOCOL, _("Error occurred while downloading messages in '%s'."), name);
+               else
+                       alertpanel_error(_("Error occurred while downloading messages in '%s'."), name);
                g_free(name);
        }
        folder_set_ui_func(item->folder, NULL, NULL);
@@ -320,3 +312,15 @@ static void download_cb(FolderView *folderview, guint action,
        inc_unlock();
        main_window_cursor_normal(mainwin);
 }
+
+static void download_cb(FolderView *folderview, guint action,
+                       GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       news_gtk_synchronise(item);
+}