sync with 0.9.9cvs4
authorPaul Mangan <paul@claws-mail.org>
Thu, 12 Feb 2004 10:07:38 +0000 (10:07 +0000)
committerPaul Mangan <paul@claws-mail.org>
Thu, 12 Feb 2004 10:07:38 +0000 (10:07 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.ac
src/common/utils.h
src/compose.c
src/folder.c
src/folder.h
src/foldersel.c
src/folderview.c
src/folderview.h

index 1e9d727..500e0c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2004-02-06
+
+       * src/folderview.[ch]: code cleanup.
+         folderview_append_item(): new. It appends the folder to the folder
+         view.
+       * src/foldersel.c: foldersel_new_folder(): use
+         folderview_append_item().
+
+2004-02-06
+
+       * src/foldersel.c: implemented 'create new folder' function.
+       * src/folder.[ch]: folder_find_child_item_by_name(): new.
+       * src/utils.h: AUTORELEASE_STR(): convert malloc'd string into
+         auto-release (alloca'd) one.
+
+2004-02-05
+
+       * src/folderview.c: put together folderview_new_imap_folder_cb() into
+         folderview_new_folder_cb().
+
+2004-02-04
+
+       * src/compose.c: compose_write_to_file(): removed redundant strlen()
+         (thanks to Alfons).
+       * src/textview.c: textview_button_pressed(): select correct account
+         when address is clicked.
+
 2004-01-29
 
        * version 0.9.9
index 0de94a1..fb58311 100644 (file)
@@ -1,3 +1,8 @@
+2004-02-12 [paul]      0.9.9claws4
+
+       * sync with 0.9.9cvs4
+               see ChangeLog 2004-02-04, 2004-02-05, and 2004-02-06
+
 2004-02-11 [luke]      0.9.9claws3
        * src/mimeview.c
                remove redundant check introduced in 0.9.9claws1
index 4d44e7b..cf4ba35 100644 (file)
@@ -1,3 +1,29 @@
+2004-02-06
+
+       * src/folderview.[ch]: ¥³¡¼¥É¤ÎÀ°Íý¡£
+         folderview_append_item(): ¿·µ¬¡£¥Õ¥©¥ë¥À¤ò¥Õ¥©¥ë¥À¥Ó¥å¡¼¤ËÄɲ乤롣
+       * src/foldersel.c: foldersel_new_folder(): folderview_append_item()
+         ¤ò»ÈÍÑ¡£
+
+2004-02-06
+
+       * src/foldersel.c: ¡Ö¿·µ¬¥Õ¥©¥ë¥À¤òºîÀ®¡×µ¡Ç½¤ò¼ÂÁõ¡£
+       * src/folder.[ch]: folder_find_child_item_by_name(): ¿·µ¬¡£
+       * src/utils.h: AUTORELEASE_STR(): malloc Ê¸»úÎó¤ò¼«Æ°³«Êü(alloca)
+         Ê¸»úÎó¤ËÊÑ´¹¡£
+
+2004-02-05
+
+       * src/folderview.c: folderview_new_imap_folder_cb() ¤ò
+         folderview_new_folder_cb() ¤Ë¤Þ¤È¤á¤¿¡£
+
+2004-02-04
+
+       * src/compose.c: compose_write_to_file(): ÌµÂ̤ʠstrlen() ¤ò½üµî
+         (Alfons ¤µ¤ó thanks)¡£
+       * src/textview.c: textview_button_pressed(): ¥¢¥É¥ì¥¹¤ò¥¯¥ê¥Ã¥¯¤·¤¿
+         ¤È¤­Àµ¤·¤¤¥¢¥«¥¦¥ó¥È¤òÁªÂò¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
+
 2004-01-29
 
        * version 0.9.9
index 073895b..30e81fe 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=9
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=3
+EXTRA_VERSION=4
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index cef9f76..f87d705 100644 (file)
        ptr = __tmp; \
 }
 
+#define AUTORELEASE_STR(str, iffail) \
+{ \
+       gchar *__str; \
+       Xstrdup_a(__str, str, iffail); \
+       g_free(str); \
+       str = __str; \
+}
+
 #define FILE_OP_ERROR(file, func) \
 { \
        fprintf(stderr, "%s: ", file); \
index 0f58b86..fd28749 100644 (file)
@@ -3531,7 +3531,6 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
 
        /* get all composed text */
        chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
-       len = strlen(chars);
        if (is_ascii_str(chars)) {
                buf = chars;
                chars = NULL;
index 71f7688..1c37981 100644 (file)
@@ -1022,6 +1022,20 @@ FolderItem *folder_find_item_from_path(const gchar *path)
        return d[1];
 }
 
+FolderItem *folder_find_child_item_by_name(FolderItem *item, const gchar *name)
+{
+       GNode *node;
+       FolderItem *child;
+
+       for (node = item->node->children; node != NULL; node = node->next) {
+               child = FOLDER_ITEM(node->data);
+               if (strcmp2(g_basename(child->path), name) == 0)
+                       return child;
+       }
+
+       return NULL;
+}
+
 FolderClass *folder_get_class_from_string(const gchar *str)
 {
        GSList *classlist;
index 2c2e4a0..4e04b1b 100644 (file)
@@ -376,6 +376,8 @@ Folder     *folder_find_from_name           (const gchar    *name,
                                                 FolderClass    *klass);
 FolderItem *folder_find_item_from_path         (const gchar    *path);
 FolderClass *folder_get_class_from_string      (const gchar    *str);
+FolderItem *folder_find_child_item_by_name     (FolderItem     *item,
+                                                const gchar    *name);
 gchar      *folder_get_identifier              (Folder         *folder);
 gchar      *folder_item_get_identifier         (FolderItem     *item);
 FolderItem *folder_find_item_from_identifier   (const gchar    *identifier);
index 0c26393..e5fed1b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2004 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
@@ -46,6 +46,8 @@
 #include "foldersel.h"
 #include "alertpanel.h"
 #include "manage_window.h"
+#include "folderview.h"
+#include "inputdialog.h"
 #include "folder.h"
 
 static GdkPixmap *folderxpm;
@@ -58,8 +60,10 @@ static GtkWidget *ctree;
 static GtkWidget *entry;
 static GtkWidget *ok_button;
 static GtkWidget *cancel_button;
+static GtkWidget *new_button;
 
 static FolderItem *folder_item;
+static FolderItem *selected_item;
 
 static gboolean cancelled;
 static gboolean finished;
@@ -79,6 +83,8 @@ static void foldersel_ok      (GtkButton      *button,
                                 gpointer        data);
 static void foldersel_cancel   (GtkButton      *button,
                                 gpointer        data);
+static void foldersel_new_folder(GtkButton     *button,
+                                gpointer        data);
 static void foldersel_activated        (void);
 static gint delete_event       (GtkWidget      *widget,
                                 GdkEventAny    *event,
@@ -97,6 +103,8 @@ FolderItem *foldersel_folder_sel(Folder *cur_folder,
 {
        GtkCTreeNode *node;
 
+       selected_item = NULL;
+
        if (!window) {
                foldersel_create();
                foldersel_init();
@@ -132,9 +140,11 @@ FolderItem *foldersel_folder_sel(Folder *cur_folder,
        gtk_entry_set_text(GTK_ENTRY(entry), "");
        gtk_clist_clear(GTK_CLIST(ctree));
 
-       if (!cancelled && folder_item && folder_item->path)
+       if (!cancelled &&
+           selected_item && selected_item->path) {
+               folder_item = selected_item;
                return folder_item;
-       else
+       else
                return NULL;
 }
 
@@ -146,11 +156,10 @@ static void foldersel_create(void)
 
        window = gtk_window_new(GTK_WINDOW_DIALOG);
        gtk_window_set_title(GTK_WINDOW(window), _("Select folder"));
-       gtk_widget_set_usize(window, 300, 400);
-       gtk_container_set_border_width(GTK_CONTAINER(window), BORDER_WIDTH);
+       gtk_container_set_border_width(GTK_CONTAINER(window), 4);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
-       gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);
+       gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
        gtk_window_set_wmclass
                (GTK_WINDOW(window), "folder_selection", "Sylpheed");
        gtk_signal_connect(GTK_OBJECT(window), "delete_event",
@@ -163,6 +172,7 @@ static void foldersel_create(void)
        gtk_container_add(GTK_CONTAINER(window), vbox);
 
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+       gtk_widget_set_usize(scrolledwin, 300, 360);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
        gtk_box_pack_start(GTK_BOX(vbox), scrolledwin, TRUE, TRUE, 0);
@@ -185,6 +195,7 @@ static void foldersel_create(void)
                           GTK_SIGNAL_FUNC(foldersel_selected), NULL);
 
        entry = gtk_entry_new();
+       gtk_entry_set_editable(GTK_ENTRY(entry), FALSE);
        gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
        gtk_signal_connect(GTK_OBJECT(entry), "activate",
                           GTK_SIGNAL_FUNC(foldersel_activated), NULL);
@@ -192,7 +203,7 @@ static void foldersel_create(void)
        gtkut_button_set_create(&confirm_area,
                                &ok_button,     _("OK"),
                                &cancel_button, _("Cancel"),
-                               NULL, NULL);
+                               &new_button,    _("New folder"));
 
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_button);
@@ -201,6 +212,8 @@ static void foldersel_create(void)
                           GTK_SIGNAL_FUNC(foldersel_ok), NULL);
        gtk_signal_connect(GTK_OBJECT(cancel_button), "clicked",
                           GTK_SIGNAL_FUNC(foldersel_cancel), NULL);
+       gtk_signal_connect(GTK_OBJECT(new_button), "clicked",
+                          GTK_SIGNAL_FUNC(foldersel_new_folder), NULL);
 
        gtk_widget_show_all(window);
 }
@@ -307,12 +320,13 @@ static void foldersel_set_tree(Folder *cur_folder, FolderSelectionType type)
 static void foldersel_selected(GtkCList *clist, gint row, gint column,
                               GdkEvent *event, gpointer data)
 {
-       FolderItem *item;
        GdkEventButton *ev = (GdkEventButton *)event;
 
-       item = gtk_clist_get_row_data(clist, row);
-       if (item) gtk_entry_set_text(GTK_ENTRY(entry),
-                                    item->path ? item->path : "");
+       selected_item = gtk_clist_get_row_data(clist, row);
+       if (selected_item && selected_item->path)
+               gtk_entry_set_text(GTK_ENTRY(entry), selected_item->path);
+       else
+               gtk_entry_set_text(GTK_ENTRY(entry), "");
 
        if (ev && GDK_2BUTTON_PRESS == ev->type)
                gtk_button_clicked(GTK_BUTTON(ok_button));
@@ -320,13 +334,6 @@ static void foldersel_selected(GtkCList *clist, gint row, gint column,
 
 static void foldersel_ok(GtkButton *button, gpointer data)
 {
-       GList *list;
-
-       list = GTK_CLIST(ctree)->selection;
-       if (list)
-               folder_item = gtk_ctree_node_get_row_data
-                       (GTK_CTREE(ctree), GTK_CTREE_NODE(list->data));
-
        finished = TRUE;
 }
 
@@ -336,6 +343,67 @@ static void foldersel_cancel(GtkButton *button, gpointer data)
        finished = TRUE;
 }
 
+static void foldersel_new_folder(GtkButton *button, gpointer data)
+{
+       FolderItem *new_item;
+       gchar *new_folder;
+       gchar *disp_name;
+       gchar *p;
+       gchar *text[1] = {NULL};
+       GtkCTreeNode *selected_node;
+       GtkCTreeNode *node;
+
+       if (!selected_item || FOLDER_TYPE(selected_item->folder) == F_NEWS)
+               return;
+       selected_node = gtk_ctree_find_by_row_data(GTK_CTREE(ctree), NULL,
+                                                  selected_item);
+       if (!selected_node) return;
+
+       new_folder = input_dialog(_("New folder"),
+                                 _("Input the name of new folder:"),
+                                 _("NewFolder"));
+       if (!new_folder) return;
+       AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
+
+       p = strchr(new_folder, G_DIR_SEPARATOR);
+       if ((p && FOLDER_TYPE(selected_item->folder) != F_MBOX) ||
+           (p && FOLDER_TYPE(selected_item->folder) != F_IMAP) ||
+           (p && FOLDER_TYPE(selected_item->folder) == F_IMAP &&
+            *(p + 1) != '\0')) {
+               alertpanel_error(_("`%c' can't be included in folder name."),
+                               G_DIR_SEPARATOR);
+               return;
+       }
+
+       disp_name = trim_string(new_folder, 32);
+       AUTORELEASE_STR(disp_name, {g_free(new_folder); return;});
+
+       /* find whether the directory already exists */
+       if (folder_find_child_item_by_name(selected_item, new_folder)) {
+               alertpanel_error(_("The folder `%s' already exists."),
+                                disp_name);
+               return;
+       }
+
+       new_item = selected_item->folder->klass->create_folder
+               (selected_item->folder, selected_item, new_folder);
+       if (!new_item) {
+               alertpanel_error(_("Can't create the folder `%s'."), disp_name);
+               return;
+       }
+
+       text[0] = new_item->name;
+       node = gtk_ctree_insert_node(GTK_CTREE(ctree), selected_node,
+                                    NULL, text, FOLDER_SPACING,
+                                    folderxpm, folderxpmmask,
+                                    folderopenxpm, folderopenxpmmask,
+                                    FALSE, FALSE);
+       gtk_ctree_expand(GTK_CTREE(ctree), selected_node);
+       gtk_ctree_node_set_row_data(GTK_CTREE(ctree), node, new_item);
+       gtk_ctree_sort_recursive(GTK_CTREE(ctree), selected_node);
+       folderview_append_item(new_item);
+}
+
 static void foldersel_activated(void)
 {
        gtk_button_clicked(GTK_BUTTON(ok_button));
index 7bae72c..82561cb 100644 (file)
@@ -143,15 +143,9 @@ static void folderview_append_folder        (FolderView    *folderview,
 static void folderview_update_node      (FolderView    *folderview,
                                          GtkCTreeNode  *node);
 
-static GtkCTreeNode *folderview_find_by_name   (GtkCTree       *ctree,
-                                                GtkCTreeNode   *node,
-                                                const gchar    *name);
-
 static gint folderview_clist_compare   (GtkCList       *clist,
                                         gconstpointer   ptr1,
                                         gconstpointer   ptr2);
-static gint folderview_compare_name    (gconstpointer   a,
-                                        gconstpointer   b);
 
 /* callback functions */
 static void folderview_button_pressed  (GtkWidget      *ctree,
@@ -214,9 +208,6 @@ static void folderview_remove_mailbox_cb(FolderView *folderview,
                                         guint           action,
                                         GtkWidget      *widget);
 
-static void folderview_new_imap_folder_cb(FolderView   *folderview,
-                                         guint          action,
-                                         GtkWidget     *widget);
 static void folderview_rm_imap_server_cb (FolderView   *folderview,
                                          guint          action,
                                          GtkWidget     *widget);
@@ -321,10 +312,10 @@ static GtkItemFactoryEntry folderview_imap_popup_entries[] =
 {
        {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Create _new folder..."),  NULL, folderview_new_imap_folder_cb, 0, NULL},
-       {N_("/_Rename folder..."),      NULL, folderview_rename_folder_cb,   0, NULL},
+       {N_("/Create _new folder..."),  NULL, folderview_new_folder_cb,    0, NULL},
+       {N_("/_Rename folder..."),      NULL, folderview_rename_folder_cb, 0, NULL},
        {N_("/M_ove folder..."),        NULL, folderview_move_to_cb, 0, NULL},
-       {N_("/_Delete folder"),         NULL, folderview_delete_folder_cb,   0, NULL},
+       {N_("/_Delete folder"),         NULL, folderview_delete_folder_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/Down_load"),              NULL, folderview_download_cb, 0, NULL},
        {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
@@ -775,6 +766,48 @@ void folderview_update_msg_num(FolderView *folderview, GtkCTreeNode *row)
        folderview_update_node(folderview, row);
 }
 
+void folderview_append_item(FolderItem *item)
+{
+       GList *list;
+
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       if (folder_item_parent(item)) return;
+
+       for (list = folderview_list; list != NULL; list = list->next) {
+               FolderView *folderview = (FolderView *)list->data;
+               GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+               GtkCTreeNode *node, *child;
+
+               node = gtk_ctree_find_by_row_data(ctree, NULL, 
+                                                 folder_item_parent(item));
+               if (node) {
+                       child = gtk_ctree_find_by_row_data(ctree, node, item);
+                       if (!child) {
+                               gchar *text[N_FOLDER_COLS] =
+                                       {NULL, "0", "0", "0"};
+
+                               gtk_clist_freeze(GTK_CLIST(ctree));
+
+                               text[COL_FOLDER] = item->name;
+                               child = gtk_ctree_insert_node
+                                       (ctree, node, NULL, text,
+                                        FOLDER_SPACING,
+                                        folderxpm, folderxpmmask,
+                                        folderopenxpm, folderopenxpmmask,
+                                        FALSE, FALSE);
+                               gtk_ctree_node_set_row_data(ctree, child, item);
+                               gtk_ctree_expand(ctree, node);
+                               folderview_update_node(folderview, child);
+                               folderview_sort_folders(folderview, node,
+                                                       item->folder);
+
+                               gtk_clist_thaw(GTK_CLIST(ctree));
+                       }
+               }
+       }
+}
+
 static void folderview_set_folders(FolderView *folderview)
 {
        GList *list;
@@ -1358,17 +1391,10 @@ void folderview_new_folder(FolderView *folderview)
        g_return_if_fail(item->folder != NULL);
 
        switch (FOLDER_TYPE(item->folder)) {
-#if 0
-       case F_MBOX:
-               folderview_new_mbox_folder_cb(folderview, 0, NULL);
-               break;
-#endif
        case F_MH:
        case F_MAILDIR:
-               folderview_new_folder_cb(folderview, 0, NULL);
-               break;
        case F_IMAP:
-               folderview_new_imap_folder_cb(folderview, 0, NULL);
+               folderview_new_folder_cb(folderview, 0, NULL);
                break;
        case F_NEWS:
        default:
@@ -1804,29 +1830,6 @@ static void folderview_col_resized(GtkCList *clist, gint column, gint width,
        }
 }
 
-static GtkCTreeNode *folderview_find_by_name(GtkCTree *ctree,
-                                            GtkCTreeNode *node,
-                                            const gchar *name)
-{
-       FolderItem *item;
-
-       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);
-               if (!folderview_compare_name(item, name))
-                       return node;
-               node = GTK_CTREE_ROW(node)->sibling;
-       }
-
-       return NULL;
-}
-
 static void folderview_download_func(Folder *folder, FolderItem *item,
                                     gpointer data)
 {
@@ -1963,85 +1966,59 @@ static void folderview_new_folder_cb(FolderView *folderview, guint action,
        FolderItem *item;
        FolderItem *new_item;
        gchar *new_folder;
-       gchar *name, *name_;
+       gchar *name;
+       gchar *p;
 
        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);
-
-       new_folder = input_dialog(_("New folder"),
-                                 _("Input the name of new folder:"),
-                                 _("NewFolder"));
+       if (FOLDER_TYPE(item->folder) == F_IMAP)
+               g_return_if_fail(item->folder->account != NULL);
+
+       if (FOLDER_TYPE(item->folder) == F_IMAP) {
+               new_folder = input_dialog
+                       (_("New folder"),
+                        _("Input the name of new folder:\n"
+                          "(if you want to create a folder to store subfolders,\n"
+                          " append `/' at the end of the name)"),
+                        _("NewFolder"));
+       } else {
+               new_folder = input_dialog(_("New folder"),
+                                         _("Input the name of new folder:"),
+                                         _("NewFolder"));
+       }
        if (!new_folder) return;
+       AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
 
-       if (FOLDER_TYPE(item->folder) != F_MBOX) {
-               if (strchr(new_folder, G_DIR_SEPARATOR) != NULL) {
-                       alertpanel_error(_("`%c' can't be included in folder name."),
-                                        G_DIR_SEPARATOR);
-                       g_free(new_folder);
-                       return;
-               }
+       p = strchr(new_folder, G_DIR_SEPARATOR);
+       if ((p && FOLDER_TYPE(item->folder) != F_MBOX) ||
+           (p && FOLDER_TYPE(item->folder) != F_IMAP) ||
+           (p && FOLDER_TYPE(item->folder) == F_IMAP && *(p + 1) != '\0')) {
+               alertpanel_error(_("`%c' can't be included in folder name."),
+                                G_DIR_SEPARATOR);
+               return;
        }
 
-       name_ = trim_string(new_folder, 32);
-       Xstrdup_a(name, name_, {g_free(new_folder); return;});
-       g_free(name_);
+       name = trim_string(new_folder, 32);
+       AUTORELEASE_STR(name, {g_free(name); return;});
 
        /* find whether the directory already exists */
-       if (folderview_find_by_name(ctree, folderview->selected, new_folder)) {
+       if (folder_find_child_item_by_name(item, new_folder)) {
                alertpanel_error(_("The folder `%s' already exists."), name);
-               g_free(new_folder);
                return;
        }
 
        new_item = folder_create_folder(item, new_folder);
        if (!new_item) {
                alertpanel_error(_("Can't create the folder `%s'."), name);
-               g_free(new_folder);
-               return;
-       } 
-       g_free(new_folder);
-
-       folder_write_list();
-}
-
-#if 0
-static void folderview_new_mbox_folder_cb(FolderView *folderview, guint action,
-                                         GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       FolderItem *new_item;
-       gchar *new_folder;
-
-       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);
-
-       new_folder = input_dialog(_("New folder"),
-                                 _("Input the name of new folder:"),
-                                 _("NewFolder"));
-       if (!new_folder) return;
-
-       /* find whether the directory already exists */
-       if (folderview_find_by_name(ctree, folderview->selected, new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."),
-                                new_folder);
-               g_free(new_folder);
                return;
        }
 
-       new_item = folder_create_folder(item, new_folder);
-       g_free(new_folder);
-       if (!new_item) return;
-
+       folderview_append_item(new_item);
        folder_write_list();
 }
-#endif
 
 static void folderview_rename_folder_cb(FolderView *folderview, guint action,
                                        GtkWidget *widget)
@@ -2049,7 +2026,7 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
        gchar *new_folder;
-       gchar *name, *name_;
+       gchar *name;
        gchar *message;
        gchar *old_path;
        gchar *old_id;
@@ -2062,29 +2039,25 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->path != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       name_ = trim_string(item->name, 32);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
+       name = trim_string(item->name, 32);
        message = g_strdup_printf(_("Input new name for `%s':"), name);
        new_folder = input_dialog(_("Rename folder"), message,
                                  g_basename(item->path));
        g_free(message);
+       g_free(name);
        if (!new_folder) return;
+       AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
 
        if (strchr(new_folder, G_DIR_SEPARATOR) != NULL) {
                alertpanel_error(_("`%c' can't be included in folder name."),
                                 G_DIR_SEPARATOR);
-               g_free(new_folder);
                return;
        }
 
-       if (folderview_find_by_name
-               (ctree, GTK_CTREE_ROW(folderview->selected)->parent,
-                new_folder)) {
+       if (folder_find_child_item_by_name(folder_item_parent(item), new_folder)) {
                name = trim_string(new_folder, 32);
                alertpanel_error(_("The folder `%s' already exists."), name);
                g_free(name);
-               g_free(new_folder);
                return;
        }
 
@@ -2093,10 +2066,8 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
 
        if (item->folder->klass->rename_folder(item->folder, item, new_folder) < 0) {
                g_free(old_id);
-               g_free(new_folder);
                return;
        }
-       g_free(new_folder);
 
        /* if (FOLDER_TYPE(item->folder) == F_MH)
                prefs_filtering_rename_path(old_path, item->path); */
@@ -2126,69 +2097,12 @@ static void folderview_rename_folder_cb(FolderView *folderview, guint action,
        folder_write_list();
 }
 
-#if 0
-static void folderview_rename_mbox_folder_cb(FolderView *folderview,
-                                            guint action,
-                                            GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       gchar *new_folder;
-       gchar *message;
-
-       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->path != NULL);
-       g_return_if_fail(item->folder != NULL);
-
-       message = g_strdup_printf(_("Input new name for `%s':"),
-                                 g_basename(item->path));
-       new_folder = input_dialog(_("Rename folder"), message,
-                                 g_basename(item->path));
-       g_free(message);
-       if (!new_folder) return;
-
-       if (folderview_find_by_name
-               (ctree, GTK_CTREE_ROW(folderview->selected)->parent,
-                new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."),
-                                new_folder);
-               g_free(new_folder);
-               return;
-       }
-
-       if (item->folder->klass->rename_folder(item->folder, item, new_folder) < 0) {
-               g_free(new_folder);
-               return;
-       }
-       g_free(new_folder);
-
-       gtk_clist_freeze(GTK_CLIST(ctree));
-
-       folderview_update_node(folderview, folderview->selected);
-       folderview_sort_folders(folderview,
-                               GTK_CTREE_ROW(folderview->selected)->parent,
-                               item->folder);
-       if (folderview->opened == folderview->selected) {
-               if (!GTK_CTREE_ROW(folderview->opened)->children)
-                       gtk_ctree_expand(ctree, folderview->opened);
-               summary_show(folderview->summaryview, item);
-       }
-
-       gtk_clist_thaw(GTK_CLIST(ctree));
-
-       folder_write_list();
-}
-#endif
-
 static void folderview_delete_folder_cb(FolderView *folderview, guint action,
                                        GtkWidget *widget)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
-       gchar *message, *name, *name_;
+       gchar *message, *name;
        AlertValue avalue;
        gchar *old_path;
        gchar *old_id;
@@ -2200,9 +2114,8 @@ static void folderview_delete_folder_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->path != NULL);
        g_return_if_fail(item->folder != NULL);
 
-       name_ = trim_string(item->name, 32);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
+       name = trim_string(item->name, 32);
+       AUTORELEASE_STR(name, {g_free(name); return;});
        message = g_strdup_printf
                (_("All folder(s) and message(s) under `%s' will be deleted.\n"
                   "Do you really want to delete?"), name);
@@ -2244,7 +2157,7 @@ static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        GtkCTreeNode *node;
        FolderItem *item;
-       gchar *name, *name_;
+       gchar *name;
        gchar *message;
        AlertValue avalue;
 
@@ -2255,15 +2168,14 @@ static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
        g_return_if_fail(item->folder != NULL);
        if (folder_item_parent(item)) return;
 
-       name_ = trim_string(item->folder->name, 32);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
+       name = trim_string(item->folder->name, 32);
        message = g_strdup_printf
                (_("Really remove the mailbox `%s' ?\n"
                   "(The messages are NOT deleted from the disk)"), name);
        avalue = alertpanel(_("Remove mailbox"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
+       g_free(name);
        if (avalue != G_ALERTDEFAULT) return;
 
        folderview_unselect(folderview);
@@ -2272,69 +2184,13 @@ static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
        folder_destroy(item->folder);
 }
 
-static void folderview_new_imap_folder_cb(FolderView *folderview, guint action,
-                                         GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       FolderItem *new_item;
-       gchar *new_folder;
-       gchar *name, *name_;
-       gchar *p;
-
-       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_IMAP);
-       g_return_if_fail(item->folder->account != NULL);
-
-       new_folder = input_dialog
-               (_("New folder"),
-                _("Input the name of new folder:\n"
-                  "(if you want to create a folder to store subfolders,\n"
-                  " append `/' at the end of the name)"),
-                _("NewFolder"));
-       if (!new_folder) return;
-
-       if ((p = strchr(new_folder, G_DIR_SEPARATOR)) != NULL &&
-           *(p + 1) != '\0') {
-               alertpanel_error(_("`%c' can't be included in folder name."),
-                                G_DIR_SEPARATOR);
-               g_free(new_folder);
-               return;
-       }
-
-       name_ = trim_string(new_folder, 32);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
-
-       /* find whether the directory already exists */
-       if (folderview_find_by_name(ctree, folderview->selected, new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."), name);
-               g_free(new_folder);
-               return;
-       }
-
-       new_item = folder_create_folder(item, new_folder);
-       if (!new_item) {
-               alertpanel_error(_("Can't create the folder `%s'."), name);
-               g_free(new_folder);
-               return;
-       }
-       g_free(new_folder);
-
-       folder_write_list();
-}
-
 static void folderview_rm_imap_server_cb(FolderView *folderview, guint action,
                                         GtkWidget *widget)
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
        PrefsAccount *account;
-       gchar *name, *name_;
+       gchar *name;
        gchar *message;
        AlertValue avalue;
 
@@ -2346,13 +2202,12 @@ static void folderview_rm_imap_server_cb(FolderView *folderview, guint action,
        g_return_if_fail(FOLDER_TYPE(item->folder) == F_IMAP);
        g_return_if_fail(item->folder->account != NULL);
 
-       name_ = trim_string(item->folder->name, 32);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
+       name = trim_string(item->folder->name, 32);
        message = g_strdup_printf(_("Really delete IMAP4 account `%s'?"), name);
        avalue = alertpanel(_("Delete IMAP4 account"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
+       g_free(name);
 
        if (avalue != G_ALERTDEFAULT) return;
 
@@ -2377,7 +2232,6 @@ 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;
@@ -2439,23 +2293,14 @@ static void folderview_new_news_group_cb(FolderView *folderview, guint action,
        for (cur = new_subscr; cur != NULL; cur = cur->next) {
                gchar *name = (gchar *)cur->data;
 
-               if (folderview_find_by_name(ctree, servernode, name) != NULL)
+               if (folder_find_child_item_by_name(rootitem, 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);
-
                newitem = folder_item_new(folder, name, name);
                folder_item_append(rootitem, newitem);
-               gtk_ctree_node_set_row_data(ctree, node, newitem);
+               folderview_append_item(newitem);
        }
 
-       folderview_sort_folders(folderview, servernode, folder);
        gtk_clist_thaw(GTK_CLIST(ctree));
 
        slist_free_strings(new_subscr);
@@ -2469,7 +2314,7 @@ static void folderview_rm_news_group_cb(FolderView *folderview, guint action,
 {
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
-       gchar *name, *name_;
+       gchar *name;
        gchar *message;
        AlertValue avalue;
 
@@ -2481,13 +2326,12 @@ static void folderview_rm_news_group_cb(FolderView *folderview, guint action,
        g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
        g_return_if_fail(item->folder->account != NULL);
 
-       name_ = trim_string(item->path, 32);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
+       name = trim_string(item->path, 32);
        message = g_strdup_printf(_("Really delete newsgroup `%s'?"), name);
        avalue = alertpanel(_("Delete newsgroup"), message,
                            _("Yes"), _("+No"), NULL);
        g_free(message);
+       g_free(name);
        if (avalue != G_ALERTDEFAULT) return;
 
        if (folderview->opened == folderview->selected) {
@@ -2507,7 +2351,7 @@ static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
        GtkCTree *ctree = GTK_CTREE(folderview->ctree);
        FolderItem *item;
        PrefsAccount *account;
-       gchar *name, *name_;
+       gchar *name;
        gchar *message;
        AlertValue avalue;
 
@@ -2519,13 +2363,12 @@ static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
        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);
-       Xstrdup_a(name, name_, return);
-       g_free(name_);
+       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;
 
@@ -2679,15 +2522,6 @@ static gint folderview_clist_compare(GtkCList *clist,
        return g_strcasecmp(item1->name, item2->name);
 }
 
-static gint folderview_compare_name(gconstpointer a, gconstpointer b)
-{
-       const FolderItem *item = a;
-       const gchar *name = b;
-
-       if (!item->path) return -1;
-       return strcmp2(g_basename(item->path), name);
-}
-
 static void folderview_processing_cb(FolderView *folderview, guint action,
                                     GtkWidget *widget)
 {
index b93a49f..e28b50f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2004 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
@@ -81,6 +81,9 @@ void folderview_unselect              (FolderView     *folderview);
 void folderview_select_next_unread     (FolderView     *folderview);
 void folderview_update_msg_num         (FolderView     *folderview,
                                         GtkCTreeNode   *row);
+
+void folderview_append_item            (FolderItem     *item);
+
 void folderview_rescan_tree            (Folder         *folder);
 void folderview_rescan_all             (void);
 gint folderview_check_new              (Folder         *folder);