sync with sylpheed 0.6.5cvs7
authorPaul Mangan <paul@claws-mail.org>
Fri, 16 Nov 2001 10:44:43 +0000 (10:44 +0000)
committerPaul Mangan <paul@claws-mail.org>
Fri, 16 Nov 2001 10:44:43 +0000 (10:44 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.in
src/folderview.c
src/grouplistdialog.c
src/grouplistdialog.h
src/news.c
src/news.h

index 58c0e79..89928a2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2001-11-16
+
+       * src/compose.c: modified so that it sends message when any of
+         To:, Cc:, Bcc:, or Newsgroups: fields have valid recipient.
+         compose_check_for_valid_recipient(): new.
+
+2001-11-15
+
+       * src/news.[ch]: news_session_get(): update the last access time
+         correctly.
+         news_group_list_free(): new.
+       * src/grouplistdialog.c: free resources correctly.
+
+2001-11-15
+
+       * src/folderview.c
+         src/grouplistdialog.[ch]: more merging of new newsgroup
+         subscription dialog.
+       * src/news.[ch]: renamed news_remove_group_list() to
+         news_remove_group_list_cache().
+
 2001-11-14
 
        * src/defs.h: added MAX_ENTRY_LENGTH definition.
index 916a639..18f69cf 100644 (file)
@@ -1,3 +1,8 @@
+2001-11-16 [paul]      0.6.5claws16
+
+       * sync with sylpheed 0.6.5cvs7
+               see ChangeLog entries 2001-11-15 and 2001-11-16
+
 2001-11-15 [hoa]       0.6.5claws15
 
        * src/compose.c
index e00d345..0cf9262 100644 (file)
@@ -1,3 +1,24 @@
+2001-11-16
+
+       * src/compose.c: To:, Cc:, Bcc:, Newsgroups: ¤Î¤É¤ì¤«¤¬Í­¸ú¤Ê
+         °¸Àè¤ò»ý¤Ã¤Æ¤¤¤ì¤Ð¥á¥Ã¥»¡¼¥¸¤òÁ÷¿®¤¹¤ë¤è¤¦¤Ë½¤Àµ¡£
+         compose_check_for_valid_recipient(): ¿·µ¬¡£
+
+2001-11-15
+
+       * src/news.c: news_session_get(): ºÇ½ª¥¢¥¯¥»¥¹»þ´Ö¤òÀµ¤·¤¯¹¹¿·¤¹¤ë
+         ¤è¤¦¤Ë¤·¤¿¡£
+         news_group_list_free(): ¿·µ¬¡£
+       * src/grouplistdialog.c: ¥ê¥½¡¼¥¹¤òÀµ¤·¤¯²òÊü¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
+
+2001-11-15
+
+       * src/folderview.c
+         src/grouplistdialog.[ch]: ¿·¥Ë¥å¡¼¥¹¥°¥ë¡¼¥×¹ØÆÉ¥À¥¤¥¢¥í¥°¤Î
+         ¤µ¤é¤Ê¤ë¥Þ¡¼¥¸¡£
+       * src/news.[ch]: news_remove_group_list() ¤ò
+         news_remove_group_list_cache() ¤Ë̾¾ÎÊѹ¹¡£
+
 2001-11-14
 
        * src/defs.h: MAX_ENTRY_LENGTH ¤ÎÄêµÁ¤òÄɲá£
index a1597a9..65264cf 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws15
+EXTRA_VERSION=claws16
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index 280f183..4de8dc8 100644 (file)
@@ -1968,134 +1968,93 @@ static void folderview_rm_imap_server_cb(FolderView *folderview, guint action,
        folder_write_list();
 }
 
-
-
-
-
-static GList *folderview_news_get_subscriptions(GtkCTree *ctree,
-                                               GtkCTreeNode *node)
-{
-       FolderItem *item;
-       GList * result;
-
-       result = NULL;
-
-       if (!node)
-               node = GTK_CTREE_NODE(GTK_CLIST(ctree)->row_list);
-       if (!node)
-               return NULL;
-
-       node = GTK_CTREE_ROW(node)->children;
-
-       while (node) {
-               item = gtk_ctree_node_get_row_data(ctree, node);
-
-               result = g_list_append(result, item->name);
-               node = GTK_CTREE_ROW(node)->sibling;
-       }
-
-       return result;
-}
-
-
 static void folderview_new_news_group_cb(FolderView *folderview, guint action,
                                         GtkWidget *widget)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        gchar *text[N_FOLDER_COLS] = {NULL, "0", "0", "0"};
        GtkCTreeNode *servernode, *node;
+       Folder *folder;
        FolderItem *item;
+       FolderItem *rootitem;
        FolderItem *newitem;
-       const gchar *server;
-       GList * subscriptions;
-       GList * new_subscriptions;
-       GList * l;
+       GSList *new_subscr;
+       GSList *cur;
+       GNode *gnode;
 
        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(item->folder->type == F_NEWS);
-       g_return_if_fail(item->folder->account != NULL);
+       folder = item->folder;
+       g_return_if_fail(folder != NULL);
+       g_return_if_fail(folder->type == 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;
 
-       subscriptions = folderview_news_get_subscriptions(ctree, servernode);
+       rootitem = gtk_ctree_node_get_row_data(ctree, servernode);
 
-       new_subscriptions = grouplist_dialog(item->folder, subscriptions);
+       new_subscr = grouplist_dialog(folder);
 
-       for(l = subscriptions ; l != NULL ; l = l->next) {
-         gchar * name;
-         
-         name = (gchar *) l->data;
+       /* remove unsubscribed newsgroups */
+       for (gnode = folder->node->children; gnode != NULL; ) {
+               GNode *next = gnode->next;
 
-         if (g_list_find_custom(new_subscriptions, name,
-                                (GCompareFunc) g_strcasecmp) == NULL) {
-           GtkCTreeNode * sel;
+               item = FOLDER_ITEM(gnode->data);
+               if (g_slist_find_custom(new_subscr, item->name,
+                                       (GCompareFunc)g_strcasecmp) != NULL) {
+                       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;
+               }
 
-           /* remove subscription */
+               folder_item_remove(item);
+               gtk_ctree_remove_node(ctree, node);
 
-           sel = folderview_find_by_name(ctree, servernode, name);
-           g_return_if_fail(sel != NULL);
+               gnode = next;
+       }
 
-           item = gtk_ctree_node_get_row_data(ctree, sel);
+       gtk_clist_freeze(GTK_CLIST(ctree));
 
-           g_return_if_fail(item != NULL);
-           g_return_if_fail(item->folder != NULL);
-           g_return_if_fail(item->folder->type == F_NEWS);
-           g_return_if_fail(item->folder->account != NULL);
+       /* add subscribed newsgroups */
+       for (cur = new_subscr; cur != NULL; cur = cur->next) {
+               gchar *name = (gchar *)cur->data;
 
-           if (folderview->opened == sel) {
-             summary_clear_all(folderview->summaryview);
-             folderview->opened = NULL;
-           }
-           
-           folder_item_remove(item);
-           gtk_ctree_remove_node(ctree, sel);
+               if (folderview_find_by_name(ctree, servernode, name) != NULL)
+                       continue;
 
-         }
-       }
+               text[COL_FOLDER] = name;
+               node = gtk_ctree_insert_node(ctree, servernode, NULL, text,
+                                            FOLDER_SPACING,
+                                            folderxpm, folderxpmmask,
+                                            folderopenxpm, folderopenxpmmask,
+                                            FALSE, FALSE);
+               gtk_ctree_expand(ctree, servernode);
 
-       g_list_free(subscriptions);
-
-       for(l = new_subscriptions ; l != NULL ; l = l->next) {
-         gchar * name;
-         
-         name = (gchar *) l->data;
-
-         if (folderview_find_by_name(ctree, servernode, name) == NULL) {
-
-           /* add newsgroup */
-
-           gtk_clist_freeze(GTK_CLIST(ctree));
-           
-           text[COL_FOLDER] = name;
-           node = gtk_ctree_insert_node(ctree, servernode, NULL, text,
-                                        FOLDER_SPACING,
-                                        folderxpm, folderxpmmask,
-                                        folderopenxpm, folderopenxpmmask,
-                                        FALSE, FALSE);
-           gtk_ctree_expand(ctree, servernode);
-           
-           item = gtk_ctree_node_get_row_data(ctree, servernode);
-           server = item->folder->account->nntp_server;
-           
-           newitem = folder_item_new(name, name);
-           folder_item_append(item, newitem);
-           gtk_ctree_node_set_row_data(ctree, node, newitem);
-           gtk_ctree_sort_node(ctree, servernode);
-           
-           gtk_clist_thaw(GTK_CLIST(ctree));
-           
-         }
+               newitem = folder_item_new(name, name);
+               folder_item_append(rootitem, newitem);
+               gtk_ctree_node_set_row_data(ctree, node, newitem);
        }
 
-       list_free_strings(new_subscriptions);
-       g_list_free(new_subscriptions);
+       gtk_ctree_sort_node(ctree, servernode);
+       gtk_clist_thaw(GTK_CLIST(ctree));
+
+       slist_free_strings(new_subscr);
+       g_slist_free(new_subscr);
 
        folder_write_list();
 }
index 975e2d1..cc90abe 100644 (file)
@@ -34,7 +34,6 @@
 #include <gtk/gtkhbox.h>
 #include <gtk/gtklabel.h>
 #include <gtk/gtkentry.h>
-// #include <gtk/gtkclist.h>
 #include <gtk/gtkctree.h>
 #include <gtk/gtkscrolledwindow.h>
 #include <gtk/gtkbutton.h>
 #include "recv.h"
 #include "socket.h"
 
-#define GROUPLIST_DIALOG_WIDTH 500
-#define GROUPLIST_NAMES                250
-#define GROUPLIST_DIALOG_HEIGHT        400
-
-static GList * subscribed = NULL;
-gboolean dont_unsubscribed = FALSE;
+#define GROUPLIST_DIALOG_WIDTH         480
+#define GROUPLIST_DIALOG_HEIGHT                400
+#define GROUPLIST_COL_NAME_WIDTH       250
 
 static gboolean ack;
 static gboolean locked;
 
 static GtkWidget *dialog;
 static GtkWidget *entry;
-// static GtkWidget *clist;
-static GtkWidget *groups_tree;
+static GtkWidget *ctree;
 static GtkWidget *status_label;
 static GtkWidget *ok_button;
+static GSList *group_list;
 static Folder *news_folder;
 
+static GSList *subscribed;
+
 static void grouplist_dialog_create    (void);
-static void grouplist_dialog_set_list  (gchar pattern);
+static void grouplist_dialog_set_list  (gchar          *pattern);
 static void grouplist_clear            (void);
 static void grouplist_recv_func                (SockInfo       *sock,
                                         gint            count,
@@ -88,22 +86,20 @@ static void refresh_clicked (GtkWidget      *widget,
 static void key_pressed                (GtkWidget      *widget,
                                 GdkEventKey    *event,
                                 gpointer        data);
-static void groups_tree_selected       (GtkCTree       *groups_tree,
-                                        GtkCTreeNode   * node,
-                                        gint            column,
-                                        GdkEventButton *event,
-                                        gpointer        user_data);
-static void groups_tree_unselected     (GtkCTree       *groups_tree,
-                                        GtkCTreeNode   * node,
-                                        gint            column,
-                                        GdkEventButton *event,
-                                        gpointer        user_data);
+static void ctree_selected     (GtkCTree       *ctree,
+                                GtkCTreeNode   *node,
+                                gint            column,
+                                gpointer        data);
+static void ctree_unselected   (GtkCTree       *ctree,
+                                GtkCTreeNode   *node,
+                                gint            column,
+                                gpointer        data);
 static void entry_activated    (GtkEditable    *editable);
 
-GList *grouplist_dialog(Folder *folder, GList * cur_subscriptions)
+GSList *grouplist_dialog(Folder *folder)
 {
-       gchar *str;
-       GList * l;
+       GNode *node;
+       FolderItem *item;
 
        if (dialog && GTK_WIDGET_VISIBLE(dialog)) return NULL;
 
@@ -115,12 +111,15 @@ GList *grouplist_dialog(Folder *folder, GList * cur_subscriptions)
        gtk_widget_show(dialog);
        gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
        manage_window_set_transient(GTK_WINDOW(dialog));
+       gtk_widget_grab_focus(ok_button);
+       gtk_widget_grab_focus(ctree);
        GTK_EVENTS_FLUSH();
 
        subscribed = NULL;
-
-       for(l = cur_subscriptions ; l != NULL ; l = l->next)
-         subscribed = g_list_append(subscribed, g_strdup((gchar *) l->data));
+       for (node = folder->node->children; node != NULL; node = node->next) {
+               item = FOLDER_ITEM(node->data);
+               subscribed = g_slist_append(subscribed, g_strdup(item->name));
+       }
 
        grouplist_dialog_set_list(NULL);
 
@@ -130,29 +129,23 @@ GList *grouplist_dialog(Folder *folder, GList * cur_subscriptions)
        gtk_widget_hide(dialog);
 
        if (!ack) {
-         list_free_strings(subscribed);
-         g_list_free(subscribed);
-
-         subscribed = NULL;
-         
-         for(l = cur_subscriptions ; l != NULL ; l = l->next)
-           subscribed = g_list_append(subscribed, g_strdup((gchar *) l->data));
+               slist_free_strings(subscribed);
+               g_slist_free(subscribed);
+               subscribed = NULL;
+
+               for (node = folder->node->children; node != NULL;
+                    node = node->next) {
+                       item = FOLDER_ITEM(node->data);
+                       subscribed = g_slist_append(subscribed,
+                                                   g_strdup(item->name));
+               }
        }
 
-       GTK_EVENTS_FLUSH();
+       grouplist_clear();
 
-       debug_print("return string = %s\n", str ? str : "(none)");
        return subscribed;
 }
 
-static void grouplist_clear(void)
-{
-       dont_unsubscribed = TRUE;
-       gtk_clist_clear(GTK_CLIST(groups_tree));
-       gtk_entry_set_text(GTK_ENTRY(entry), "");
-       dont_unsubscribed = FALSE;
-}
-
 static void grouplist_dialog_create(void)
 {
        GtkWidget *vbox;
@@ -162,9 +155,8 @@ static void grouplist_dialog_create(void)
        GtkWidget *cancel_button;       
        GtkWidget *refresh_button;      
        GtkWidget *scrolledwin;
-       gchar * col_names[3] = {
-               _("name"), _("count of messages"), _("type")
-       };
+       gchar *titles[3];
+       gint i;
 
        dialog = gtk_dialog_new();
        gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, FALSE);
@@ -206,18 +198,24 @@ static void grouplist_dialog_create(void)
                                       GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
 
-       groups_tree = gtk_ctree_new_with_titles(3, 0, col_names);
-       gtk_container_add(GTK_CONTAINER(scrolledwin), groups_tree);
-       gtk_clist_set_selection_mode(GTK_CLIST(groups_tree),
-                                    GTK_SELECTION_MULTIPLE);
-       /*
-       GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[0].button,
-                              GTK_CAN_FOCUS);
-       */
-       gtk_signal_connect(GTK_OBJECT(groups_tree), "tree_select_row",
-                          GTK_SIGNAL_FUNC(groups_tree_selected), NULL);
-       gtk_signal_connect(GTK_OBJECT(groups_tree), "tree_unselect_row",
-                          GTK_SIGNAL_FUNC(groups_tree_unselected), NULL);
+       titles[0] = _("Newsgroup name");
+       titles[1] = _("Messages");
+       titles[2] = _("Type");
+       ctree = gtk_ctree_new_with_titles(3, 0, titles);
+       gtk_container_add(GTK_CONTAINER(scrolledwin), ctree);
+       gtk_clist_set_column_width
+               (GTK_CLIST(ctree), 0, GROUPLIST_COL_NAME_WIDTH);
+       gtk_clist_set_selection_mode(GTK_CLIST(ctree), GTK_SELECTION_MULTIPLE);
+       gtk_ctree_set_line_style(GTK_CTREE(ctree), GTK_CTREE_LINES_DOTTED);
+       gtk_ctree_set_expander_style(GTK_CTREE(ctree),
+                                    GTK_CTREE_EXPANDER_SQUARE);
+       for (i = 0; i < 3; i++)
+               GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
+                                      GTK_CAN_FOCUS);
+       gtk_signal_connect(GTK_OBJECT(ctree), "tree_select_row",
+                          GTK_SIGNAL_FUNC(ctree_selected), NULL);
+       gtk_signal_connect(GTK_OBJECT(ctree), "tree_unselect_row",
+                          GTK_SIGNAL_FUNC(ctree_unselected), NULL);
 
        hbox = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
@@ -243,183 +241,162 @@ static void grouplist_dialog_create(void)
        gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
 }
 
-static GHashTable * hash_last_node;
-static GHashTable * hash_branch_node;
-
-static void hash_news_init()
-{
-       hash_last_node = g_hash_table_new(g_str_hash, g_str_equal);
-       hash_branch_node = g_hash_table_new(g_str_hash, g_str_equal);
-}
+static GHashTable *last_node_table;
+static GHashTable *branch_node_table;
 
-static void free_key(gchar * key, void * value, void * user_data)
+static void grouplist_hash_init(void)
 {
-       g_free(key);
+       last_node_table = g_hash_table_new(g_str_hash, g_str_equal);
+       branch_node_table = g_hash_table_new(g_str_hash, g_str_equal);
 }
 
-static void hash_news_done()
+static void grouplist_hash_done(void)
 {
-       g_hash_table_foreach(hash_branch_node, free_key, NULL);
-       g_hash_table_foreach(hash_last_node, free_key, NULL);
+       hash_free_strings(branch_node_table);
+       hash_free_strings(last_node_table);
 
-       g_hash_table_destroy(hash_branch_node);
-       g_hash_table_destroy(hash_last_node);
+       g_hash_table_destroy(branch_node_table);
+       g_hash_table_destroy(last_node_table);
 }
 
-static GtkCTreeNode * hash_news_get_branch_node(gchar * name)
+static GtkCTreeNode *grouplist_hash_get_branch_node(const gchar *name)
 {
-       return g_hash_table_lookup(hash_branch_node, name);
+       return g_hash_table_lookup(branch_node_table, name);
 }
 
-static void hash_news_set_branch_node(gchar * name, GtkCTreeNode * node)
+static void grouplist_hash_set_branch_node(const gchar *name,
+                                          GtkCTreeNode *node)
 {
-       g_hash_table_insert(hash_branch_node, g_strdup(name), node);
+       g_hash_table_insert(branch_node_table, g_strdup(name), node);
 }
 
-static GtkCTreeNode * hash_news_get_last_node(gchar * name)
+static GtkCTreeNode *grouplist_hash_get_last_node(const gchar *name)
 {
-       return g_hash_table_lookup(hash_last_node, name);
+       return g_hash_table_lookup(last_node_table, name);
 }
 
-static void hash_news_set_last_node(gchar * name, GtkCTreeNode * node)
+static void grouplist_hash_set_last_node(const gchar *name,
+                                        GtkCTreeNode *node)
 {
-       gchar * key;
-       void * value;
+       gchar *key;
+       gpointer value;
 
-       if (g_hash_table_lookup_extended(hash_last_node, name,
-                                        (void *) &key, &value)) {
-               g_hash_table_remove(hash_last_node, name);
+       if (g_hash_table_lookup_extended(last_node_table, name,
+                                        (gpointer *)&key, &value)) {
+               g_hash_table_remove(last_node_table, name);
                g_free(key);
        }
 
-       g_hash_table_insert(hash_last_node, g_strdup(name), node);
+       g_hash_table_insert(last_node_table, g_strdup(name), node);
 }
 
-static gchar * get_parent_name(gchar * name)
+static gchar *grouplist_get_parent_name(const gchar *name)
 {
-       gchar * p;
+       gchar *p;
 
-       p = (gchar *) strrchr(name, '.');
-       if (p == NULL)
+       p = strrchr(name, '.');
+       if (!p)
                return g_strdup("");
-
        return g_strndup(name, p - name);
 }
 
-static gchar * get_node_name(gchar * name)
+static GtkCTreeNode *grouplist_create_parent(const gchar *name)
 {
-       gchar * p;
-
-       p = (gchar *) strrchr(name, '.');
-       if (p == NULL)
-               return name;
+       GtkCTreeNode *parent;
+       GtkCTreeNode *node;
+       gchar *cols[3];
+       gchar *parent_name;
 
-       return p + 1;
-}
-
-static GtkCTreeNode * create_parent(GtkCTree * groups_tree, gchar * name)
-{
-       gchar * cols[3];
-       GtkCTreeNode * parent;
-       GtkCTreeNode * node;
-       gchar * parent_name;
+       if (*name == '\0') return NULL;
+       node = grouplist_hash_get_branch_node(name);
+       if (node != NULL) return node;
 
-       if (* name == 0)
-               return;
+       cols[0] = (gchar *)name;
+       cols[1] = cols[2] = "";
 
-       if (hash_news_get_branch_node(name) != NULL)
-               return;
+       parent_name = grouplist_get_parent_name(name);
+       parent = grouplist_create_parent(parent_name);
 
-       cols[0] = get_node_name(name);
-       cols[1] = "";
-       cols[2] = "";
-       
-       parent_name = get_parent_name(name);
-       create_parent(groups_tree, parent_name);
-
-       parent = hash_news_get_branch_node(parent_name);
-       node = hash_news_get_last_node(parent_name);
-       node = gtk_ctree_insert_node(groups_tree,
-                                    parent, node,
-                                    cols, 0, NULL, NULL,
-                                    NULL, NULL,
+       node = grouplist_hash_get_last_node(parent_name);
+       node = gtk_ctree_insert_node(GTK_CTREE(ctree), parent, node,
+                                    cols, 0, NULL, NULL, NULL, NULL,
                                     FALSE, FALSE);
-       gtk_ctree_node_set_selectable(groups_tree, node, FALSE);
-       hash_news_set_last_node(parent_name, node);
-       hash_news_set_branch_node(name, node);
+       gtk_ctree_node_set_selectable(GTK_CTREE(ctree), node, FALSE);
+       grouplist_hash_set_last_node(parent_name, node);
+       grouplist_hash_set_branch_node(name, node);
 
        g_free(parent_name);
+
+       return node;
 }
 
-static GtkCTreeNode * create_branch(GtkCTree * groups_tree, gchar * name,
-                                   struct NNTPGroupInfo * info)
+static GtkCTreeNode *grouplist_create_branch(NewsGroupInfo *ginfo)
 {
-       gchar * parent_name;
-
-       GtkCTreeNode * node;
-       GtkCTreeNode * parent;
-
-       gchar count_str[10];
-       gchar * cols[3];
+       GtkCTreeNode *node;
+       GtkCTreeNode *parent;
+       gchar *name = (gchar *)ginfo->name;
+       gchar *parent_name;
+       gchar *count_str;
+       gchar *cols[3];
        gint count;
 
-       count = info->last - info->first;
+       count = ginfo->last - ginfo->first;
        if (count < 0)
                count = 0;
-       snprintf(count_str, 10, "%i", count);
-       
-       cols[0] = get_node_name(info->name);
+       count_str = itos(count);
+
+       cols[0] = ginfo->name;
        cols[1] = count_str;
-       if (info->type == 'y')
+       if (ginfo->type == 'y')
                cols[2] = "";
-       else if (info->type == 'm')
-               cols[2] = "moderated";
-       else if (info->type == 'n')
-               cols[2] = "readonly";
+       else if (ginfo->type == 'm')
+               cols[2] = _("moderated");
+       else if (ginfo->type == 'n')
+               cols[2] = _("readonly");
        else
-               cols[2] = "unkown";
-       
-       parent_name = get_parent_name(name);
-
-       create_parent(groups_tree, parent_name);
-
-       parent = hash_news_get_branch_node(parent_name);
-       node = hash_news_get_last_node(parent_name);
-       node = gtk_ctree_insert_node(groups_tree,
-                                    parent, node,
-                                    cols, 0, NULL, NULL,
-                                    NULL, NULL,
-                                    TRUE, FALSE);
-       gtk_ctree_node_set_selectable(groups_tree, node, TRUE);
-       hash_news_set_last_node(parent_name, node);
-
-       g_free(parent_name);
+               cols[2] = _("unknown");
+
+       parent_name = grouplist_get_parent_name(name);
+       parent = grouplist_create_parent(parent_name);
+       node = grouplist_hash_get_branch_node(name);
+       if (node) {
+               gtk_ctree_set_node_info(GTK_CTREE(ctree), node, cols[0], 0,
+                                       NULL, NULL, NULL, NULL, FALSE, FALSE);
+               gtk_ctree_node_set_text(GTK_CTREE(ctree), node, 1, cols[1]);
+               gtk_ctree_node_set_text(GTK_CTREE(ctree), node, 2, cols[2]);
+       } else {
+               node = grouplist_hash_get_last_node(parent_name);
+               node = gtk_ctree_insert_node(GTK_CTREE(ctree), parent, node,
+                                            cols, 0, NULL, NULL, NULL, NULL,
+                                            TRUE, FALSE);
+       }
+       gtk_ctree_node_set_selectable(GTK_CTREE(ctree), node, TRUE);
+       if (node)
+               gtk_ctree_node_set_row_data(GTK_CTREE(ctree), node, ginfo);
 
-       if (node == NULL)
-               return NULL;
+       grouplist_hash_set_last_node(parent_name, node);
 
-       gtk_ctree_node_set_row_data(GTK_CTREE(groups_tree), node, info);
+       g_free(parent_name);
 
        return node;
 }
 
-static void grouplist_dialog_set_list(gchar * pattern)
+static void grouplist_dialog_set_list(gchar *pattern)
 {
        GSList *cur;
-       GtkCTreeNode * node;
-       GSList * group_list = NULL;
-       GSList * r_list;
-
-       if (pattern == NULL)
-               pattern = "*";
+       GtkCTreeNode *node;
 
        if (locked) return;
        locked = TRUE;
 
+       if (!pattern || *pattern == '\0')
+               pattern = "*";
+
        grouplist_clear();
 
        recv_set_ui_func(grouplist_recv_func, NULL);
        group_list = news_get_group_list(news_folder);
+       group_list = g_slist_reverse(group_list);
        recv_set_ui_func(NULL, NULL);
        if (group_list == NULL) {
                alertpanel_error(_("Can't retrieve newsgroup list."));
@@ -427,59 +404,53 @@ static void grouplist_dialog_set_list(gchar * pattern)
                return;
        }
 
-       dont_unsubscribed = TRUE;
-
-       hash_news_init();
-
-       gtk_clist_freeze(GTK_CLIST(groups_tree));
-
-       r_list = g_slist_copy(group_list);
-       r_list = g_slist_reverse(r_list);
-
-       for (cur = r_list; cur != NULL ; cur = cur->next) {
-               struct NNTPGroupInfo * info;
+       grouplist_hash_init();
 
-               info = (struct NNTPGroupInfo *) cur->data;
+       gtk_clist_freeze(GTK_CLIST(ctree));
 
-               if (fnmatch(pattern, info->name, 0) == 0) {
-                       GList * l;
+       gtk_signal_handler_block_by_func(GTK_OBJECT(ctree),
+                                        GTK_SIGNAL_FUNC(ctree_selected),
+                                        NULL);
 
-                       node = create_branch(GTK_CTREE(groups_tree),
-                                            info->name, info);
+       for (cur = group_list; cur != NULL ; cur = cur->next) {
+               NewsGroupInfo *ginfo = (NewsGroupInfo *)cur->data;
 
-                       l = g_list_find_custom(subscribed, info->name,
-                                              (GCompareFunc) g_strcasecmp);
-                       
-                       if (l != NULL)
-                         gtk_ctree_select(GTK_CTREE(groups_tree), node);
+               if (fnmatch(pattern, ginfo->name, 0) == 0) {
+                       node = grouplist_create_branch(ginfo);
+                       if (g_slist_find_custom(subscribed, ginfo->name,
+                                               (GCompareFunc)g_strcasecmp)
+                           != NULL)
+                               gtk_ctree_select(GTK_CTREE(ctree), node);
                }
        }
 
-       g_slist_free(r_list);
+       gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
+                                          GTK_SIGNAL_FUNC(ctree_selected),
+                                          NULL);
 
-       hash_news_done();
+       gtk_clist_thaw(GTK_CLIST(ctree));
 
-       node = gtk_ctree_node_nth(GTK_CTREE(groups_tree), 0);
-       gtk_ctree_node_moveto(GTK_CTREE(groups_tree), node, 0, 0, 0);
-
-       dont_unsubscribed = FALSE;
-
-       gtk_clist_set_column_width(GTK_CLIST(groups_tree), 0, GROUPLIST_NAMES);
-       gtk_clist_set_column_justification (GTK_CLIST(groups_tree), 1,
-                                           GTK_JUSTIFY_RIGHT);
-       gtk_clist_set_column_auto_resize(GTK_CLIST(groups_tree), 1, TRUE);
-       gtk_clist_set_column_auto_resize(GTK_CLIST(groups_tree), 2, TRUE);
-
-       gtk_clist_thaw(GTK_CLIST(groups_tree));
-
-       gtk_widget_grab_focus(ok_button);
-       gtk_widget_grab_focus(groups_tree);
+       grouplist_hash_done();
 
        gtk_label_set_text(GTK_LABEL(status_label), _("Done."));
 
        locked = FALSE;
 }
 
+static void grouplist_clear(void)
+{
+       gtk_signal_handler_block_by_func(GTK_OBJECT(ctree),
+                                        GTK_SIGNAL_FUNC(ctree_unselected),
+                                        NULL);
+       gtk_clist_clear(GTK_CLIST(ctree));
+       gtk_entry_set_text(GTK_ENTRY(entry), "");
+       news_group_list_free(group_list);
+       group_list = NULL;
+       gtk_signal_handler_unblock_by_func(GTK_OBJECT(ctree),
+                                          GTK_SIGNAL_FUNC(ctree_unselected),
+                                          NULL);
+}
+
 static void grouplist_recv_func(SockInfo *sock, gint count, gint read_bytes,
                                gpointer data)
 {
@@ -494,26 +465,19 @@ static void grouplist_recv_func(SockInfo *sock, gint count, gint read_bytes,
 
 static void ok_clicked(GtkWidget *widget, gpointer data)
 {
-       gchar * str;
-       gboolean update_list;
+       gchar *str;
 
        str = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
 
-       update_list = FALSE;
-
        if (strchr(str, '*') != NULL)
-         update_list = TRUE;
-
-       if (update_list) {
                grouplist_dialog_set_list(str);
-               g_free(str);
-       }
        else {
-               g_free(str);
                ack = TRUE;
                if (gtk_main_level() > 1)
                        gtk_main_quit();
        }
+
+       g_free(str);
 }
 
 static void cancel_clicked(GtkWidget *widget, gpointer data)
@@ -524,12 +488,12 @@ static void cancel_clicked(GtkWidget *widget, gpointer data)
 }
 
 static void refresh_clicked(GtkWidget *widget, gpointer data)
-{
-       gchar * str;
+{ 
+       gchar *str;
+
        if (locked) return;
 
-       news_cancel_group_list_cache(news_folder);
+       news_remove_group_list_cache(news_folder);
 
        str = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
        grouplist_dialog_set_list(str);
@@ -542,44 +506,31 @@ static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
                cancel_clicked(NULL, NULL);
 }
 
-static void groups_tree_selected(GtkCTree *groups_tree, GtkCTreeNode * node,
-                                gint column,
-                                GdkEventButton *event, gpointer user_data)
+static void ctree_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
+                          gpointer data)
 {
-       struct NNTPGroupInfo * group;
-       GList * l;
+       NewsGroupInfo *ginfo;
 
-       group = (struct NNTPGroupInfo *)
-         gtk_ctree_node_get_row_data(GTK_CTREE(groups_tree), node);
-
-       if (group == NULL)
-               return;
+       ginfo = gtk_ctree_node_get_row_data(ctree, node);
+       if (!ginfo) return;
 
-       if (!dont_unsubscribed) {
-               subscribed = g_list_append(subscribed, g_strdup(group->name));
-       }
+       subscribed = g_slist_append(subscribed, g_strdup(ginfo->name));
 }
 
-static void groups_tree_unselected(GtkCTree *groups_tree, GtkCTreeNode * node,
-                                  gint column,
-                                  GdkEventButton *event, gpointer user_data)
+static void ctree_unselected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
+                            gpointer data)
 {
-       struct NNTPGroupInfo * group;
-       GList * l;
-
-       group = (struct NNTPGroupInfo *)
-         gtk_ctree_node_get_row_data(GTK_CTREE(groups_tree), node);
+       NewsGroupInfo *ginfo;
+       GSList *list;
 
-       if (group == NULL)
-               return;
+       ginfo = gtk_ctree_node_get_row_data(ctree, node);
+       if (!ginfo) return;
 
-       if (!dont_unsubscribed) {
-               l = g_list_find_custom(subscribed, group->name,
-                                      (GCompareFunc) g_strcasecmp);
-               if (l != NULL) {
-                 g_free(l->data);
-                       subscribed = g_list_remove(subscribed, l->data);
-               }
+       list = g_slist_find_custom(subscribed, ginfo->name,
+                                  (GCompareFunc)g_strcasecmp);
+       if (list) {
+               g_free(list->data);
+               subscribed = g_slist_remove(subscribed, list->data);
        }
 }
 
index e5fd172..8743305 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "folder.h"
 
-GList *grouplist_dialog(Folder *folder, GList * cur_subscriptions);
-     //gchar *grouplist_dialog (Folder *folder);
+GSList *grouplist_dialog       (Folder *folder);
 
 #endif /* __GROUPLISTDIALOG_H__ */
index 3978528..56b86a8 100644 (file)
@@ -81,8 +81,6 @@ static GSList *news_delete_old_articles        (GSList        *alist,
                                          gint           first);
 static void news_delete_all_articles    (FolderItem    *item);
 
-static void news_group_list_free(GSList * list);
-
 
 static Session *news_session_new(const gchar *server, gushort port,
                                 const gchar *userid, const gchar *passwd)
@@ -112,7 +110,6 @@ static Session *news_session_new(const gchar *server, gushort port,
        SESSION(session)->last_access_time = time(NULL);
        SESSION(session)->data             = NULL;
        session->group = NULL;
-       session->group_list = NULL;
 
        return SESSION(session);
 }
@@ -123,9 +120,6 @@ void news_session_destroy(NNTPSession *session)
        session->nntp_sock = NULL;
        SESSION(session)->sock = NULL;
 
-       news_group_list_free(session->group_list);
-       session->group_list = NULL;
-
        g_free(session->group);
 }
 
@@ -171,40 +165,38 @@ static Session *news_session_new_for_folder(Folder *folder)
 
 NNTPSession *news_session_get(Folder *folder)
 {
-       NNTPSession *session;
+       RemoteFolder *rfolder = REMOTE_FOLDER(folder);
 
        g_return_val_if_fail(folder != NULL, NULL);
        g_return_val_if_fail(folder->type == F_NEWS, NULL);
        g_return_val_if_fail(folder->account != NULL, NULL);
 
-       if (!REMOTE_FOLDER(folder)->session) {
-               REMOTE_FOLDER(folder)->session =
-                       news_session_new_for_folder(folder);
+       if (!rfolder->session) {
+               rfolder->session = news_session_new_for_folder(folder);
                statusbar_pop_all();
-               return NNTP_SESSION(REMOTE_FOLDER(folder)->session);
+               return NNTP_SESSION(rfolder->session);
        }
 
-       session = NNTP_SESSION(REMOTE_FOLDER(folder)->session);
-
-       if (time(NULL) - SESSION(session)->last_access_time < SESSION_TIMEOUT) {
-               SESSION(session)->last_access_time = time(NULL);
+       if (time(NULL) - rfolder->session->last_access_time < SESSION_TIMEOUT) {
+               rfolder->session->last_access_time = time(NULL);
                statusbar_pop_all();
-               return session;
+               return NNTP_SESSION(rfolder->session);
        }
 
-       if (nntp_mode(session->nntp_sock, FALSE) != NN_SUCCESS) {
+       if (nntp_mode(NNTP_SESSION(rfolder->session)->nntp_sock, FALSE)
+           != NN_SUCCESS) {
                log_warning(_("NNTP connection to %s:%d has been"
                              " disconnected. Reconnecting...\n"),
                            folder->account->nntp_server,
                            folder->account->set_nntpport ?
                            folder->account->nntpport : NNTP_PORT);
-               session_destroy(REMOTE_FOLDER(folder)->session);
-               REMOTE_FOLDER(folder)->session =
-                       news_session_new_for_folder(folder);
+               session_destroy(rfolder->session);
+               rfolder->session = news_session_new_for_folder(folder);
        }
 
+       rfolder->session->last_access_time = time(NULL);
        statusbar_pop_all();
-       return NNTP_SESSION(REMOTE_FOLDER(folder)->session);
+       return NNTP_SESSION(rfolder->session);
 }
 
 GSList *news_get_article_list(Folder *folder, FolderItem *item,
@@ -303,39 +295,30 @@ void news_scan_group(Folder *folder, FolderItem *item)
 {
 }
 
-static struct NNTPGroupInfo * group_info_new(gchar * name,
-                                            gint first, gint last,
-                                            gchar type)
+static NewsGroupInfo *news_group_info_new(const gchar *name,
+                                         gint first, gint last, gchar type)
 {
-       struct NNTPGroupInfo * info;
-
-       info = g_new(struct NNTPGroupInfo, 1);
-       if (info == NULL)
-               return NULL;
-       info->name = g_strdup(name);
-       info->first = first;
-       info->last = last;
-       info->type = type;
+       NewsGroupInfo *ginfo;
 
-       return info;
-}
+       ginfo = g_new(NewsGroupInfo, 1);
+       ginfo->name = g_strdup(name);
+       ginfo->first = first;
+       ginfo->last = last;
+       ginfo->type = type;
 
-static void group_info_free(struct NNTPGroupInfo * info)
-{
-  g_free(info->name);
-  g_free(info);
+       return ginfo;
 }
 
-static void news_group_list_free(GSList * list)
+static void news_group_info_free(NewsGroupInfo *ginfo)
 {
-  g_slist_foreach(list, (GFunc) group_info_free, NULL);
-  g_slist_free(list);
+       g_free(ginfo->name);
+       g_free(ginfo);
 }
 
-gint news_group_info_compare(struct NNTPGroupInfo * info1,
-                            struct NNTPGroupInfo * info2)
+static gint news_group_info_compare(NewsGroupInfo *ginfo1,
+                                   NewsGroupInfo *ginfo2)
 {
-  return g_strcasecmp(info1->name, info2->name);
+       return g_strcasecmp(ginfo1->name, ginfo2->name);
 }
 
 GSList *news_get_group_list(Folder *folder)
@@ -345,7 +328,6 @@ GSList *news_get_group_list(Folder *folder)
        GSList *list = NULL;
        GSList *last = NULL;
        gchar buf[NNTPBUFSIZE];
-       NNTPSession *session;
 
        g_return_val_if_fail(folder != NULL, NULL);
        g_return_val_if_fail(folder->type == F_NEWS, NULL);
@@ -356,18 +338,15 @@ GSList *news_get_group_list(Folder *folder)
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
        g_free(path);
 
-       session = news_session_get(folder);
-       if (!session) {
-               g_free(filename);
-               return NULL;
-       }
+       if ((fp = fopen(filename, "r")) == NULL) {
+               NNTPSession *session;
 
-       if (session->group_list) {
-               g_free(filename);
-               return session->group_list;
-       }
+               session = news_session_get(folder);
+               if (!session) {
+                       g_free(filename);
+                       return NULL;
+               }
 
-       if ((fp = fopen(filename, "r")) == NULL) {
                if (nntp_list(session->nntp_sock) != NN_SUCCESS) {
                        g_free(filename);
                        statusbar_pop_all();
@@ -388,48 +367,28 @@ GSList *news_get_group_list(Folder *folder)
        }
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
-               gchar * p;
-               gchar * cur;
-               gchar * name;
-               gint last_article;
-               gint first_article;
+               gchar *p = buf;
+               gchar *name;
+               gint last_num;
+               gint first_num;
                gchar type;
-               struct NNTPGroupInfo * info;
+               NewsGroupInfo *ginfo;
 
-               cur = buf;
-               p = strchr(cur, ' ');
-               if (p == NULL)
-                       continue;
-               * p = 0;
-
-               name = cur;
-               
-               cur = p + 1;
-               p = strchr(cur, ' ');
-               if (p == NULL)
-                       continue;
-               * p = 0;
-               last_article = atoi(cur);
+               p = strchr(p, ' ');
+               if (!p) continue;
+               *p = '\0';
+               p++;
+               name = buf;
 
-               cur = p + 1;
-               p = strchr(cur, ' ');
-               if (p == NULL)
+               if (sscanf(p, "%d %d %c", &last_num, &first_num, &type) < 3)
                        continue;
-               * p = 0;
-               first_article = atoi(cur);
-
-               cur = p + 1;
-               type = * cur;
 
-               info = group_info_new(name, first_article,
-                                     last_article, type);
-               if (info == NULL)
-                       continue;
+               ginfo = news_group_info_new(name, first_num, last_num, type);
 
                if (!last)
-                       last = list = g_slist_append(NULL, info);
+                       last = list = g_slist_append(NULL, ginfo);
                else {
-                       last = g_slist_append(last, info);
+                       last = g_slist_append(last, ginfo);
                        last = last->next;
                }
        }
@@ -437,30 +396,31 @@ GSList *news_get_group_list(Folder *folder)
        fclose(fp);
        g_free(filename);
 
-       list = g_slist_sort(list, (GCompareFunc) news_group_info_compare);
-
-       session->group_list = list;
+       list = g_slist_sort(list, (GCompareFunc)news_group_info_compare);
 
        statusbar_pop_all();
 
        return list;
 }
 
-void news_cancel_group_list_cache(Folder *folder)
+void news_group_list_free(GSList *group_list)
+{
+       GSList *cur;
+
+       if (!group_list) return;
+
+       for (cur = group_list; cur != NULL; cur = cur->next)
+               news_group_info_free((NewsGroupInfo *)cur->data);
+       g_slist_free(group_list);
+}
+
+void news_remove_group_list_cache(Folder *folder)
 {
        gchar *path, *filename;
-       NNTPSession *session;
 
        g_return_if_fail(folder != NULL);
        g_return_if_fail(folder->type == F_NEWS);
 
-       session = news_session_get(folder);
-       if (!session)
-               return;
-
-       news_group_list_free(session->group_list);
-       session->group_list = NULL;
-
        path = folder_item_get_path(FOLDER_ITEM(folder->node->data));
        filename = g_strconcat(path, G_DIR_SEPARATOR_S, NEWSGROUP_LIST, NULL);
        g_free(path);
index a3d8654..3bb2eef 100644 (file)
@@ -27,6 +27,7 @@
 #include "nntp.h"
 
 typedef struct _NNTPSession    NNTPSession;
+typedef struct _NewsGroupInfo  NewsGroupInfo;
 
 #define NNTP_SESSION(obj)      ((NNTPSession *)obj)
 
@@ -36,18 +37,16 @@ struct _NNTPSession
 
        NNTPSockInfo *nntp_sock;
        gchar *group;
-       
-       GSList * group_list;
 };
 
-struct NNTPGroupInfo {
-       gint first;
-       gint last;
-       gchar * name;
+struct _NewsGroupInfo
+{
+       gchar *name;
+       gchar first;
+       gchar last;
        gchar type;
 };
 
-
 void news_session_destroy              (NNTPSession    *session);
 NNTPSession *news_session_get          (Folder         *folder);
 
@@ -62,12 +61,10 @@ void news_scan_group                        (Folder         *folder,
                                         FolderItem     *item);
 
 GSList *news_get_group_list            (Folder         *folder);
-void news_cancel_group_list_cache      (Folder         *folder);
+void news_group_list_free              (GSList         *group_list);
+void news_remove_group_list_cache      (Folder         *folder);
 
 gint news_post                         (Folder         *folder,
                                         const gchar    *file);
 
-gint news_group_info_compare(struct NNTPGroupInfo * info1,
-                            struct NNTPGroupInfo * info2);
-
 #endif /* __NEWS_H__ */