2004-05-06 16:41:59 +02:00
|
|
|
/*
|
|
|
|
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
|
2006-01-13 18:24:38 +01:00
|
|
|
* Copyright (C) 1999-2006 Hiroyuki Yamamoto & the Sylpheed-Claws Team
|
2004-05-06 16:41:59 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-09-21 20:22:51 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-05-06 16:41:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
2005-02-10 13:06:07 +01:00
|
|
|
#include <glib/gi18n.h>
|
2004-05-06 16:41:59 +02:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
#include "folder.h"
|
|
|
|
#include "folderview.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "account.h"
|
|
|
|
#include "alertpanel.h"
|
|
|
|
#include "grouplistdialog.h"
|
2005-08-04 20:01:14 +02:00
|
|
|
#include "prefs_common.h"
|
|
|
|
#include "news_gtk.h"
|
2004-05-06 16:41:59 +02:00
|
|
|
#include "common/hooks.h"
|
|
|
|
#include "inc.h"
|
2006-02-24 09:25:19 +01:00
|
|
|
#include "news.h"
|
2004-05-06 16:41:59 +02:00
|
|
|
|
|
|
|
static void subscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget);
|
|
|
|
static void unsubscribe_newsgroup_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);
|
2005-09-08 20:28:36 +02:00
|
|
|
static void sync_cb(FolderView *folderview, guint action, GtkWidget *widget);
|
2004-05-06 16:41:59 +02:00
|
|
|
|
|
|
|
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>"},
|
2005-09-08 20:28:36 +02:00
|
|
|
{N_("/Synchronise"), NULL, sync_cb, 0, NULL},
|
|
|
|
{N_("/Down_load messages"), NULL, download_cb, 0, NULL},
|
2004-05-06 16:41:59 +02:00
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
|
|
|
{N_("/_Check for new messages"), NULL, update_tree_cb, 0, NULL},
|
|
|
|
{N_("/---"), NULL, NULL, 0, "<Separator>"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void set_sensitivity(GtkItemFactory *factory, FolderItem *item);
|
|
|
|
|
|
|
|
static FolderViewPopup news_popup =
|
|
|
|
{
|
|
|
|
"news",
|
|
|
|
"<NewsFolder>",
|
|
|
|
NULL,
|
|
|
|
set_sensitivity
|
|
|
|
};
|
|
|
|
|
|
|
|
void news_gtk_init(void)
|
|
|
|
{
|
|
|
|
guint i, n_entries;
|
|
|
|
|
|
|
|
n_entries = sizeof(news_popup_entries) /
|
|
|
|
sizeof(news_popup_entries[0]);
|
|
|
|
for (i = 0; i < n_entries; i++)
|
|
|
|
news_popup.entries = g_slist_append(news_popup.entries, &news_popup_entries[i]);
|
|
|
|
|
|
|
|
folderview_register_popup(&news_popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_sensitivity(GtkItemFactory *factory, FolderItem *item)
|
|
|
|
{
|
2006-02-24 09:25:19 +01:00
|
|
|
MainWindow *mainwin = mainwindow_get_mainwindow();
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
#define SET_SENS(name, sens) \
|
|
|
|
menu_set_sensitive(factory, name, sens)
|
|
|
|
|
2006-02-24 09:25:19 +01:00
|
|
|
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);
|
2004-05-06 16:41:59 +02:00
|
|
|
|
|
|
|
#undef SET_SENS
|
|
|
|
}
|
|
|
|
|
|
|
|
static void subscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkCTree *ctree = GTK_CTREE(folderview->ctree);
|
|
|
|
GtkCTreeNode *servernode, *node;
|
|
|
|
Folder *folder;
|
|
|
|
FolderItem *item;
|
|
|
|
FolderItem *rootitem;
|
|
|
|
FolderItem *newitem;
|
|
|
|
GSList *new_subscr;
|
|
|
|
GSList *cur;
|
|
|
|
GNode *gnode;
|
2006-02-24 09:25:19 +01:00
|
|
|
MainWindow *mainwin = mainwindow_get_mainwindow();
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
if (!folderview->selected) return;
|
|
|
|
|
|
|
|
item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
|
|
|
|
g_return_if_fail(item != NULL);
|
2006-02-24 09:25:19 +01:00
|
|
|
|
|
|
|
if (mainwin->lock_count || news_folder_locked(item->folder))
|
|
|
|
return;
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
folder = item->folder;
|
|
|
|
g_return_if_fail(folder != NULL);
|
|
|
|
g_return_if_fail(FOLDER_TYPE(folder) == F_NEWS);
|
|
|
|
g_return_if_fail(folder->account != NULL);
|
|
|
|
|
|
|
|
if (GTK_CTREE_ROW(folderview->selected)->parent != NULL)
|
|
|
|
servernode = GTK_CTREE_ROW(folderview->selected)->parent;
|
|
|
|
else
|
|
|
|
servernode = folderview->selected;
|
|
|
|
|
|
|
|
rootitem = gtk_ctree_node_get_row_data(ctree, servernode);
|
|
|
|
|
|
|
|
new_subscr = grouplist_dialog(folder);
|
|
|
|
|
|
|
|
/* remove unsubscribed newsgroups */
|
|
|
|
for (gnode = folder->node->children; gnode != NULL; ) {
|
|
|
|
GNode *next = gnode->next;
|
|
|
|
|
|
|
|
item = FOLDER_ITEM(gnode->data);
|
|
|
|
if (g_slist_find_custom(new_subscr, item->path,
|
2004-10-26 12:43:50 +02:00
|
|
|
(GCompareFunc)g_ascii_strcasecmp) != NULL) {
|
2004-05-06 16:41:59 +02:00
|
|
|
gnode = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = gtk_ctree_find_by_row_data(ctree, servernode, item);
|
|
|
|
if (!node) {
|
|
|
|
gnode = next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folderview->opened == node) {
|
|
|
|
summary_clear_all(folderview->summaryview);
|
|
|
|
folderview->opened = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_ctree_remove_node(ctree, node);
|
|
|
|
folder_item_remove(item);
|
|
|
|
|
|
|
|
gnode = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_clist_freeze(GTK_CLIST(ctree));
|
|
|
|
|
|
|
|
/* add subscribed newsgroups */
|
|
|
|
for (cur = new_subscr; cur != NULL; cur = cur->next) {
|
|
|
|
gchar *name = (gchar *)cur->data;
|
|
|
|
FolderUpdateData hookdata;
|
|
|
|
|
|
|
|
if (folder_find_child_item_by_name(rootitem, name) != NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
newitem = folder_item_new(folder, name, name);
|
|
|
|
folder_item_append(rootitem, newitem);
|
|
|
|
|
|
|
|
hookdata.folder = newitem->folder;
|
|
|
|
hookdata.update_flags = FOLDER_TREE_CHANGED | FOLDER_ADD_FOLDERITEM;
|
|
|
|
hookdata.item = newitem;
|
|
|
|
hooks_invoke(FOLDER_UPDATE_HOOKLIST, &hookdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_clist_thaw(GTK_CLIST(ctree));
|
|
|
|
|
|
|
|
slist_free_strings(new_subscr);
|
|
|
|
g_slist_free(new_subscr);
|
|
|
|
|
|
|
|
folder_write_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unsubscribe_newsgroup_cb(FolderView *folderview, guint action,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkCTree *ctree = GTK_CTREE(folderview->ctree);
|
|
|
|
FolderItem *item;
|
|
|
|
gchar *name;
|
|
|
|
gchar *message;
|
|
|
|
gchar *old_id;
|
|
|
|
AlertValue avalue;
|
2006-02-24 09:25:19 +01:00
|
|
|
MainWindow *mainwin = mainwindow_get_mainwindow();
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
if (!folderview->selected) return;
|
|
|
|
|
|
|
|
item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
|
|
|
|
g_return_if_fail(item != NULL);
|
2006-02-24 09:25:19 +01:00
|
|
|
|
|
|
|
if (mainwin->lock_count || news_folder_locked(item->folder))
|
|
|
|
return;
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
old_id = folder_item_get_identifier(item);
|
|
|
|
|
|
|
|
name = trim_string(item->path, 32);
|
2005-07-17 09:30:07 +02:00
|
|
|
message = g_strdup_printf(_("Really unsubscribe newsgroup '%s'?"), name);
|
2005-07-17 14:14:10 +02:00
|
|
|
avalue = alertpanel_full(_("Unsubscribe newsgroup"), message,
|
2006-01-14 12:04:52 +01:00
|
|
|
GTK_STOCK_CANCEL, _("_Unsubscribe"), NULL, FALSE,
|
2006-01-14 10:45:39 +01:00
|
|
|
NULL, ALERT_WARNING, G_ALERTDEFAULT);
|
2004-05-06 16:41:59 +02:00
|
|
|
g_free(message);
|
|
|
|
g_free(name);
|
2006-01-14 10:45:39 +01:00
|
|
|
if (avalue != G_ALERTALTERNATE) return;
|
2004-05-06 16:41:59 +02:00
|
|
|
|
|
|
|
if (folderview->opened == folderview->selected) {
|
|
|
|
summary_clear_all(folderview->summaryview);
|
|
|
|
folderview->opened = NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-07 10:35:31 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
folder_write_list();
|
|
|
|
|
|
|
|
prefs_filtering_delete_path(old_id);
|
|
|
|
g_free(old_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_tree_cb(FolderView *folderview, guint action,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
FolderItem *item;
|
2006-02-24 09:25:19 +01:00
|
|
|
MainWindow *mainwin = mainwindow_get_mainwindow();
|
|
|
|
|
2004-11-12 07:41:50 +01:00
|
|
|
item = folderview_get_selected_item(folderview);
|
2004-05-06 16:41:59 +02:00
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
|
2006-02-24 09:25:19 +01:00
|
|
|
if (mainwin->lock_count || news_folder_locked(item->folder))
|
|
|
|
return;
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
summary_show(folderview->summaryview, NULL);
|
|
|
|
|
|
|
|
g_return_if_fail(item->folder != NULL);
|
|
|
|
|
|
|
|
folderview_check_new(item->folder);
|
|
|
|
}
|
|
|
|
|
2005-09-08 20:28:36 +02:00
|
|
|
static void sync_cb(FolderView *folderview, guint action,
|
|
|
|
GtkWidget *widget)
|
2004-05-06 16:41:59 +02:00
|
|
|
{
|
|
|
|
FolderItem *item;
|
|
|
|
|
2005-09-08 20:28:36 +02:00
|
|
|
item = folderview_get_selected_item(folderview);
|
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
folder_synchronise(item->folder);
|
|
|
|
}
|
2004-05-06 16:41:59 +02:00
|
|
|
|
2005-09-08 20:28:36 +02:00
|
|
|
void news_gtk_synchronise(FolderItem *item)
|
|
|
|
{
|
|
|
|
MainWindow *mainwin = mainwindow_get_mainwindow();
|
|
|
|
FolderView *folderview = mainwin->folderview;
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
g_return_if_fail(item != NULL);
|
|
|
|
g_return_if_fail(item->folder != NULL);
|
2005-08-04 20:01:14 +02:00
|
|
|
|
2006-02-24 09:25:19 +01:00
|
|
|
if (mainwin->lock_count || news_folder_locked(item->folder))
|
|
|
|
return;
|
|
|
|
|
2004-05-06 16:41:59 +02:00
|
|
|
main_window_cursor_wait(mainwin);
|
|
|
|
inc_lock();
|
|
|
|
main_window_lock(mainwin);
|
|
|
|
gtk_widget_set_sensitive(folderview->ctree, FALSE);
|
|
|
|
main_window_progress_on(mainwin);
|
|
|
|
GTK_EVENTS_FLUSH();
|
|
|
|
if (folder_item_fetch_all_msg(item) < 0) {
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
name = trim_string(item->name, 32);
|
2005-07-17 09:30:07 +02:00
|
|
|
alertpanel_error(_("Error occurred while downloading messages in '%s'."), name);
|
2004-05-06 16:41:59 +02:00
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
folder_set_ui_func(item->folder, NULL, NULL);
|
|
|
|
main_window_progress_off(mainwin);
|
|
|
|
gtk_widget_set_sensitive(folderview->ctree, TRUE);
|
|
|
|
main_window_unlock(mainwin);
|
|
|
|
inc_unlock();
|
|
|
|
main_window_cursor_normal(mainwin);
|
|
|
|
}
|
2005-09-08 20:28:36 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|