0.9.10claws48
authorChristoph Hohmann <reboot@gmx.ch>
Tue, 20 Apr 2004 21:29:37 +0000 (21:29 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Tue, 20 Apr 2004 21:29:37 +0000 (21:29 +0000)
* src/mainwindow.c
* src/foldersel.c
        remove new/rename/delete folder GUI functions because
        they are always active, even for news folders, and can
        not be easily made folder class dependent

* src/gtk/menu.[ch]
        make menu_translate() public

* src/Makefile.am
* src/folder.[ch]
* src/folderview.[ch]
* src/imap_gtk.[ch]                     ** NEW **
* src/main.c
* src/mh_gtk.[ch]                       ** NEW **
* src/news_gtk.[ch]                     ** NEW **
        o dynamically build FolderView popup menus from a folder
          specific part, with callbacks to seperated code, and
          a common part
        o remove the folder class dependent code from folderview.c

18 files changed:
ChangeLog.claws
configure.ac
src/Makefile.am
src/folder.c
src/folder.h
src/foldersel.c
src/folderview.c
src/folderview.h
src/gtk/menu.c
src/gtk/menu.h
src/imap_gtk.c [new file with mode: 0644]
src/imap_gtk.h [new file with mode: 0644]
src/main.c
src/mainwindow.c
src/mh_gtk.c [new file with mode: 0644]
src/mh_gtk.h [new file with mode: 0644]
src/news_gtk.c [new file with mode: 0644]
src/news_gtk.h [new file with mode: 0644]

index e7fb376..e2efeac 100644 (file)
@@ -1,3 +1,26 @@
+2004-04-20 [christoph] 0.9.10claws48
+
+       * src/mainwindow.c
+       * src/foldersel.c
+               remove new/rename/delete folder GUI functions because
+               they are always active, even for news folders, and can
+               not be easily made folder class dependent
+
+       * src/gtk/menu.[ch]
+               make menu_translate() public
+
+       * src/Makefile.am
+       * src/folder.[ch]
+       * src/folderview.[ch]
+       * src/imap_gtk.[ch]                     ** NEW **
+       * src/main.c
+       * src/mh_gtk.[ch]                       ** NEW **
+       * src/news_gtk.[ch]                     ** NEW **
+               o dynamically build FolderView popup menus from a folder
+                 specific part, with callbacks to seperated code, and
+                  a common part
+               o remove the folder class dependent code from folderview.c
+
 2004-04-15 [luke]      0.9.10claws47
 
        * src/prefs_folder_item.c
index cc0ec94..3afb22a 100644 (file)
@@ -11,7 +11,8 @@ MINOR_VERSION=9
 MICRO_VERSION=10
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=47
+EXTRA_VERSION=48
+
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index ead94f5..fe99b1c 100644 (file)
@@ -47,6 +47,7 @@ sylpheed_SOURCES = \
        headerview.c \
        html.c \
        imap.c \
+       imap_gtk.c \
        import.c \
        importldif.c \
        importmutt.c \
@@ -71,10 +72,12 @@ sylpheed_SOURCES = \
        message_search.c \
        messageview.c \
        mh.c \
+       mh_gtk.c \
        mimeview.c \
        msgcache.c \
        mutt.c \
        news.c \
+       news_gtk.c \
        noticeview.c \
        passphrase.c \
        pgpmime.c \
@@ -173,6 +176,7 @@ sylpheedinclude_HEADERS = \
        headerview.h \
        html.h \
        imap.h \
+       imap_gtk.h \
        import.h \
        importldif.h \
        importmutt.h \
@@ -198,10 +202,12 @@ sylpheedinclude_HEADERS = \
        message_search.h \
        messageview.h \
        mh.h \
+       mh_gtk.h \
        mimeview.h \
        msgcache.h \
        mutt.h \
        news.h \
+       news_gtk.h \
        noticeview.h \
        passphrase.h \
        pgpmime.h \
index e063b26..028430f 100644 (file)
@@ -281,7 +281,7 @@ FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path
        item->threaded  = TRUE;
        item->ret_rcpt  = FALSE;
        item->opened    = FALSE;
-       item->node = NULL;
+       item->node = g_node_new(item);
        item->folder = NULL;
        item->account = NULL;
        item->apply_sub = FALSE;
@@ -301,7 +301,7 @@ void folder_item_append(FolderItem *parent, FolderItem *item)
        g_return_if_fail(item != NULL);
 
        item->folder = parent->folder;
-       item->node = g_node_append_data(parent->node, item);
+       g_node_append(parent->node, item->node);
 }
 
 static gboolean folder_item_remove_func(GNode *node, gpointer data)
@@ -766,10 +766,11 @@ void folder_scan_tree(Folder *folder)
 FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
 {
        FolderItem *new_item;
-       FolderUpdateData hookdata;
 
        new_item = parent->folder->klass->create_folder(parent->folder, parent, name);
        if (new_item) {
+               FolderUpdateData hookdata;
+
                new_item->cache = msgcache_new();
 
                hookdata.folder = new_item->folder;
@@ -781,6 +782,26 @@ FolderItem *folder_create_folder(FolderItem *parent, const gchar *name)
        return new_item;
 }
 
+gint folder_item_rename(FolderItem *item, gchar *newname)
+{
+       gint retval;
+
+       g_return_val_if_fail(item != NULL, -1);
+       g_return_val_if_fail(newname != NULL, -1);
+
+       retval = item->folder->klass->rename_folder(item->folder, item, newname);
+
+       if (retval >= 0) {
+               FolderItemUpdateData hookdata;
+
+               hookdata.item = item;
+               hookdata.update_flags = FOLDER_TREE_CHANGED;
+               hooks_invoke(FOLDER_ITEM_UPDATE_HOOKLIST, &hookdata);
+       }
+
+       return retval;
+}
+
 struct TotalMsgCount
 {
        guint new_msgs;
index 0df7eaf..6e6ada0 100644 (file)
@@ -111,6 +111,7 @@ typedef enum
 {
        F_ITEM_UPDATE_MSGCNT = 1 << 0,
        F_ITEM_UPDATE_CONTENT = 1 << 1,
+       F_ITEM_UPDATE_NAME = 1 << 2,
 } FolderItemUpdateFlags;
 
 typedef void (*FolderUIFunc)           (Folder         *folder,
@@ -675,6 +676,7 @@ gint   folder_read_list             (void);
 void   folder_write_list       (void);
 void   folder_scan_tree                (Folder *folder);
 FolderItem *folder_create_folder(FolderItem    *parent, const gchar *name);
+gint   folder_item_rename      (FolderItem *item, gchar *newname);
 void   folder_update_op_count          (void);
 void   folder_func_to_all_folders      (FolderItemFunc function,
                                         gpointer data);
index f444e74..43f94c9 100644 (file)
@@ -46,8 +46,6 @@
 #include "foldersel.h"
 #include "alertpanel.h"
 #include "manage_window.h"
-#include "folderview.h"
-#include "inputdialog.h"
 #include "folder.h"
 
 static GdkPixmap *folderxpm;
@@ -60,7 +58,6 @@ 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;
@@ -83,8 +80,6 @@ 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,
@@ -203,7 +198,7 @@ static void foldersel_create(void)
        gtkut_button_set_create(&confirm_area,
                                &ok_button,     _("OK"),
                                &cancel_button, _("Cancel"),
-                               &new_button,    _("New folder"));
+                               NULL,           NULL);
 
        gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_button);
@@ -212,8 +207,6 @@ 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);
 }
@@ -346,66 +339,6 @@ 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 = folder_create_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 61003fd..f1a1c12 100644 (file)
@@ -44,7 +44,6 @@
 #include "summaryview.h"
 #include "summary_search.h"
 #include "inputdialog.h"
-#include "grouplistdialog.h"
 #include "manage_window.h"
 #include "alertpanel.h"
 #include "menu.h"
@@ -167,60 +166,16 @@ static void folderview_tree_expanded      (GtkCTree       *ctree,
 static void folderview_tree_collapsed  (GtkCTree       *ctree,
                                         GtkCTreeNode   *node,
                                         FolderView     *folderview);
-static void folderview_popup_close     (GtkMenuShell   *menu_shell,
-                                        FolderView     *folderview);
+static void folderview_popup_close      (GtkMenuShell   *menu_shell,
+                                         FolderView     *folderview);
 static void folderview_col_resized     (GtkCList       *clist,
                                         gint            column,
                                         gint            width,
                                         FolderView     *folderview);
 
-static void folderview_download_cb     (FolderView     *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-
-static void folderview_update_tree_cb  (FolderView     *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-
 static void mark_all_read_cb            (FolderView    *folderview,
                                          guint           action,
                                          GtkWidget      *widget);
-static void folderview_new_folder_cb   (FolderView     *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-#if 0
-static void folderview_new_mbox_folder_cb(FolderView *folderview,
-                                         guint action,
-                                         GtkWidget *widget);
-#endif
-static void folderview_rename_folder_cb        (FolderView     *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-#if 0
-static void folderview_rename_mbox_folder_cb(FolderView *folderview,
-                                            guint action,
-                                            GtkWidget *widget);
-#endif
-static void folderview_delete_folder_cb        (FolderView     *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-static void folderview_remove_mailbox_cb(FolderView    *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-
-static void folderview_rm_imap_server_cb (FolderView   *folderview,
-                                         guint          action,
-                                         GtkWidget     *widget);
-
-static void folderview_new_news_group_cb(FolderView    *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-static void folderview_rm_news_group_cb        (FolderView     *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
-static void folderview_rm_news_server_cb(FolderView    *folderview,
-                                        guint           action,
-                                        GtkWidget      *widget);
 
 static void folderview_search_cb       (FolderView     *folderview,
                                         guint           action,
@@ -268,91 +223,80 @@ gboolean folderview_update_item_claws      (gpointer          source,
                                          gpointer          data);
 static void folderview_processing_cb(FolderView *folderview, guint action,
                                     GtkWidget *widget);
-static void folderview_move_to(FolderView *folderview, FolderItem *from_folder,
-                              FolderItem *to_folder);
-static void folderview_move_to_cb(FolderView *folderview);
 
-#if 0
-static GtkItemFactoryEntry folderview_mbox_popup_entries[] =
-{
-       {N_("/Create _new folder..."),  NULL, folderview_new_mbox_folder_cb,    0, NULL},
-       {N_("/_Rename folder..."),      NULL, folderview_rename_mbox_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_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Remove _mailbox"),        NULL, folderview_remove_mailbox_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Properties..."),         NULL, NULL, 0, NULL},
-       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
-};
-#endif
+GHashTable *folderview_popups;
 
-static GtkItemFactoryEntry folderview_mail_popup_entries[] =
+static GtkItemFactoryEntry folderview_common_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_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_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Check for new messages"),
-                                       NULL, folderview_update_tree_cb, 0, NULL},
-       {N_("/R_ebuild folder tree"),   NULL, folderview_update_tree_cb, 1, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Remove _mailbox"),        NULL, folderview_remove_mailbox_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
        {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
        {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
        {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
 };
 
-static GtkItemFactoryEntry folderview_imap_popup_entries[] =
+GtkTargetEntry folderview_drag_types[] =
 {
-       {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {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_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Down_load"),              NULL, folderview_download_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Check for new messages"),
-                                       NULL, folderview_update_tree_cb, 0, NULL},
-       {N_("/R_ebuild folder tree"),   NULL, folderview_update_tree_cb, 1, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Remove _IMAP4 account"),  NULL, folderview_rm_imap_server_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
-       {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
-       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
+       {"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
 };
 
-static GtkItemFactoryEntry folderview_news_popup_entries[] =
+void folderview_initialize(void)
 {
-       {N_("/Mark all _read"),         NULL, mark_all_read_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Subscribe to newsgroup..."),
-                                       NULL, folderview_new_news_group_cb, 0, NULL},
-       {N_("/_Remove newsgroup"),      NULL, folderview_rm_news_group_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Down_load"),              NULL, folderview_download_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Check for new messages"),
-                                       NULL, folderview_update_tree_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/Remove _news account"),   NULL, folderview_rm_news_server_cb, 0, NULL},
-       {N_("/---"),                    NULL, NULL, 0, "<Separator>"},
-       {N_("/_Search folder..."),      NULL, folderview_search_cb, 0, NULL},
-       {N_("/_Properties..."),         NULL, folderview_property_cb, 0, NULL},
-       {N_("/_Processing..."),         NULL, folderview_processing_cb, 0, NULL},
-};
+       FolderViewPopup *fpopup;
+       guint i, n_entries;
+       GSList *entries = NULL;
 
-GtkTargetEntry folderview_drag_types[] =
+       fpopup = g_new0(FolderViewPopup, 1);
+
+       n_entries = sizeof(folderview_common_popup_entries) /
+               sizeof(folderview_common_popup_entries[0]);
+       for (i = 0; i < n_entries; i++)
+               entries = g_slist_append(entries, &folderview_common_popup_entries[i]);
+
+       fpopup->klass = "common";
+       fpopup->path = "<CommonFolder>";
+       fpopup->entries = entries;
+       fpopup->set_sensitivity = NULL;
+
+       folderview_popups = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(folderview_popups, "common", fpopup);
+}
+
+static GtkItemFactory *create_ifactory(FolderView *folderview, FolderViewPopup *fpopup)
 {
-       {"text/plain", GTK_TARGET_SAME_APP, TARGET_DUMMY}
-};
+       GSList *entries;
+       GtkItemFactory *factory;
+       FolderViewPopup *fpopup_common;
+       GtkWidget *popup;
+
+       factory = gtk_item_factory_new(GTK_TYPE_MENU, fpopup->path, NULL);
+       gtk_item_factory_set_translate_func(factory, menu_translate,
+                                           NULL, NULL);
+
+       for (entries = fpopup->entries; entries != NULL; entries = g_slist_next(entries))
+               gtk_item_factory_create_item(factory, entries->data, folderview, 1);
+
+       fpopup_common = g_hash_table_lookup(folderview_popups, "common");
+       if (fpopup_common != fpopup)
+               for (entries = fpopup_common->entries; entries != NULL; entries = g_slist_next(entries))
+                       gtk_item_factory_create_item(factory, entries->data, folderview, 1);
+
+       popup = gtk_item_factory_get_widget(factory, fpopup->path);
+        gtk_signal_connect(GTK_OBJECT(popup), "selection_done",
+                           GTK_SIGNAL_FUNC(folderview_popup_close),
+                           folderview);
+
+       return factory;
+}
+
+static void create_ifactories(gpointer key, gpointer value, gpointer data)
+{
+       FolderView *folderview = data;
+       FolderViewPopup *fpopup = value;
+       GtkItemFactory *factory;
+
+       factory = create_ifactory(folderview, fpopup);
+       g_hash_table_insert(folderview->popups, fpopup->klass, factory);
+}
 
 FolderView *folderview_create(void)
 {
@@ -360,19 +304,6 @@ FolderView *folderview_create(void)
        GtkWidget *scrolledwin;
        GtkWidget *ctree;
        gchar *titles[N_FOLDER_COLS];
-       GtkWidget *mail_popup;
-       GtkWidget *news_popup;
-       GtkWidget *imap_popup;
-#if 0
-       GtkWidget *mbox_popup;
-#endif
-       GtkItemFactory *mail_factory;
-       GtkItemFactory *news_factory;
-       GtkItemFactory *imap_factory;
-#if 0
-       GtkItemFactory *mbox_factory;
-#endif
-       gint n_entries;
        gint i;
 
        debug_print("Creating folder view...\n");
@@ -418,39 +349,15 @@ FolderView *folderview_create(void)
        gtk_ctree_set_indent(GTK_CTREE(ctree), CTREE_INDENT);
        gtk_clist_set_compare_func(GTK_CLIST(ctree), folderview_clist_compare);
 
+       /* create popup factories */
+       folderview->popups = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_foreach(folderview_popups, create_ifactories, folderview);
+
        /* don't let title buttons take key focus */
        for (i = 0; i < N_FOLDER_COLS; i++)
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(ctree)->column[i].button,
                                       GTK_CAN_FOCUS);
 
-       /* popup menu */
-       n_entries = sizeof(folderview_mail_popup_entries) /
-               sizeof(folderview_mail_popup_entries[0]);
-       mail_popup = menu_create_items(folderview_mail_popup_entries,
-                                      n_entries,
-                                      "<MailFolder>", &mail_factory,
-                                      folderview);
-       n_entries = sizeof(folderview_imap_popup_entries) /
-               sizeof(folderview_imap_popup_entries[0]);
-       imap_popup = menu_create_items(folderview_imap_popup_entries,
-                                      n_entries,
-                                      "<IMAPFolder>", &imap_factory,
-                                      folderview);
-       n_entries = sizeof(folderview_news_popup_entries) /
-               sizeof(folderview_news_popup_entries[0]);
-       news_popup = menu_create_items(folderview_news_popup_entries,
-                                      n_entries,
-                                      "<NewsFolder>", &news_factory,
-                                      folderview);
-#if 0
-       n_entries = sizeof(folderview_mbox_popup_entries) /
-               sizeof(folderview_mbox_popup_entries[0]);
-       mbox_popup = menu_create_items(folderview_mbox_popup_entries,
-                                      n_entries,
-                                      "<MboxFolder>", &mbox_factory,
-                                      folderview);
-#endif
-
        gtk_signal_connect(GTK_OBJECT(ctree), "key_press_event",
                           GTK_SIGNAL_FUNC(folderview_key_pressed),
                           folderview);
@@ -479,21 +386,6 @@ FolderView *folderview_create(void)
                           GTK_SIGNAL_FUNC(folderview_col_resized),
                           folderview);
 
-       gtk_signal_connect(GTK_OBJECT(mail_popup), "selection_done",
-                          GTK_SIGNAL_FUNC(folderview_popup_close),
-                          folderview);
-       gtk_signal_connect(GTK_OBJECT(imap_popup), "selection_done",
-                          GTK_SIGNAL_FUNC(folderview_popup_close),
-                          folderview);
-       gtk_signal_connect(GTK_OBJECT(news_popup), "selection_done",
-                          GTK_SIGNAL_FUNC(folderview_popup_close),
-                          folderview);
-#if 0
-       gtk_signal_connect(GTK_OBJECT(mbox_popup), "selection_done",
-                          GTK_SIGNAL_FUNC(folderview_popup_close),
-                          folderview);
-#endif
-
         /* drop callback */
        gtk_drag_dest_set(ctree, GTK_DEST_DEFAULT_ALL & ~GTK_DEST_DEFAULT_HIGHLIGHT,
                          summary_drag_types, 1,
@@ -513,16 +405,6 @@ FolderView *folderview_create(void)
 
        folderview->scrolledwin  = scrolledwin;
        folderview->ctree        = ctree;
-       folderview->mail_popup   = mail_popup;
-       folderview->mail_factory = mail_factory;
-       folderview->imap_popup   = imap_popup;
-       folderview->imap_factory = imap_factory;
-       folderview->news_popup   = news_popup;
-       folderview->news_factory = news_factory;
-#if 0
-       folderview->mbox_popup   = mbox_popup;
-       folderview->mbox_factory = mbox_factory;
-#endif
 
        folderview->folder_update_callback_id =
                hooks_register_hook(FOLDER_UPDATE_HOOKLIST, folderview_update_folder, (gpointer) folderview);
@@ -671,8 +553,10 @@ void folderview_select(FolderView *folderview, FolderItem *item)
 static void mark_all_read_cb(FolderView *folderview, guint action,
                              GtkWidget *widget)
 {
+/* TODO: claws can do this in all folders not just the opened folder
        if (folderview->selected)
                summary_mark_all_read(folderview->summaryview);
+*/
 }
 
 static void folderview_select_node(FolderView *folderview, GtkCTreeNode *node)
@@ -1299,7 +1183,7 @@ gboolean folderview_update_item_claws(gpointer source, gpointer data)
 
        node = gtk_ctree_find_by_row_data(ctree, NULL, update_info->item);
        if (node) {
-               if (update_info->update_flags & F_ITEM_UPDATE_MSGCNT)
+               if (update_info->update_flags & (F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_NAME))
                        folderview_update_node(folderview, node);
                if ((update_info->update_flags & F_ITEM_UPDATE_CONTENT) && (folderview->opened == node))
                        summary_show(folderview->summaryview, update_info->item);
@@ -1360,36 +1244,37 @@ static void folderview_expand_func(GtkCTree *ctree, GtkCTreeNode *node,
        }
 }
 
-#define SET_SPECIAL_FOLDER(ctree, item) \
-{ \
-       if (item) { \
-               GtkCTreeNode *node, *parent, *sibling; \
- \
-               node = gtk_ctree_find_by_row_data(ctree, root, item); \
-               if (!node) \
-                       g_warning("%s not found.\n", item->path); \
-               else { \
-                       parent = GTK_CTREE_ROW(node)->parent; \
-                       if (prev && parent == GTK_CTREE_ROW(prev)->parent) \
-                               sibling = GTK_CTREE_ROW(prev)->sibling; \
-                       else \
-                               sibling = GTK_CTREE_ROW(parent)->children; \
-                       while (sibling) { \
-                               FolderItem *tmp; \
- \
-                               tmp = gtk_ctree_node_get_row_data \
-                                       (ctree, sibling); \
-                               if (tmp->stype != F_NORMAL) \
-                                       sibling = GTK_CTREE_ROW(sibling)->sibling; \
-                               else \
-                                       break; \
-                       } \
-                       if (node != sibling) \
-                               gtk_ctree_move(ctree, node, parent, sibling); \
-               } \
- \
-               prev = node; \
-       } \
+static void set_special_folder(GtkCTree *ctree, FolderItem *item,
+                              GtkCTreeNode *root, GtkCTreeNode **prev)
+{
+       if (item) {
+               GtkCTreeNode *node, *parent, *sibling;
+
+               node = gtk_ctree_find_by_row_data(ctree, root, item);
+               if (!node)
+                       g_warning("%s not found.\n", item->path);
+               else {
+                       parent = GTK_CTREE_ROW(node)->parent;
+                       if (*prev && parent == GTK_CTREE_ROW(*prev)->parent)
+                               sibling = GTK_CTREE_ROW(*prev)->sibling;
+                       else
+                               sibling = GTK_CTREE_ROW(parent)->children;
+                       while (sibling) {
+                               FolderItem *tmp;
+
+                               tmp = gtk_ctree_node_get_row_data
+                                       (ctree, sibling);
+                               if (tmp->stype != F_NORMAL)
+                                       sibling = GTK_CTREE_ROW(sibling)->sibling;
+                               else
+                                       break;
+                       }
+                       if (node != sibling)
+                               gtk_ctree_move(ctree, node, parent, sibling);
+               }
+
+               *prev = node;
+       }
 }
 
 static void folderview_sort_folders(FolderView *folderview, GtkCTreeNode *root,
@@ -1402,11 +1287,11 @@ static void folderview_sort_folders(FolderView *folderview, GtkCTreeNode *root,
 
        if (root && GTK_CTREE_ROW(root)->parent) return;
 
-       SET_SPECIAL_FOLDER(ctree, folder->inbox);
-       SET_SPECIAL_FOLDER(ctree, folder->outbox);
-       SET_SPECIAL_FOLDER(ctree, folder->draft);
-       SET_SPECIAL_FOLDER(ctree, folder->queue);
-       SET_SPECIAL_FOLDER(ctree, folder->trash);
+       set_special_folder(ctree, folder->inbox, root, &prev);
+       set_special_folder(ctree, folder->outbox, root, &prev);
+       set_special_folder(ctree, folder->draft, root, &prev);
+       set_special_folder(ctree, folder->queue, root, &prev);
+       set_special_folder(ctree, folder->trash, root, &prev);
 }
 
 static void folderview_append_folder(FolderView *folderview, Folder *folder)
@@ -1423,88 +1308,6 @@ static void folderview_append_folder(FolderView *folderview, Folder *folder)
        folderview_sort_folders(folderview, root, folder);
 }
 
-void folderview_new_folder(FolderView *folderview)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-
-       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);
-
-       switch (FOLDER_TYPE(item->folder)) {
-       case F_MH:
-       case F_MAILDIR:
-       case F_IMAP:
-               folderview_new_folder_cb(folderview, 0, NULL);
-               break;
-       case F_NEWS:
-       default:
-               break;
-       }
-}
-
-void folderview_rename_folder(FolderView *folderview)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-
-       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);
-       if (!item->path) return;
-       if (item->stype != F_NORMAL) return;
-
-       switch (FOLDER_TYPE(item->folder)) {
-#if 0
-       case F_MBOX:
-               folderview_rename_mbox_folder_cb(folderview, 0, NULL);
-               break;
-#endif
-       case F_MH:
-       case F_MAILDIR:
-       case F_IMAP:
-               folderview_rename_folder_cb(folderview, 0, NULL);
-               break;
-       case F_NEWS:
-       default:
-               break;
-       }
-}
-
-void folderview_delete_folder(FolderView *folderview)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-
-       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);
-       if (!item->path) return;
-       if (item->stype != F_NORMAL) return;
-
-       switch (FOLDER_TYPE(item->folder)) {
-       case F_MH:
-#if 0
-       case F_MBOX:
-#endif
-       case F_MAILDIR:
-       case F_IMAP:
-               folderview_delete_folder_cb(folderview, 0, NULL);
-               break;
-       case F_NEWS:
-       default:
-               break;
-       }
-}
-
-
 /* callback functions */
 
 static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
@@ -1514,20 +1317,9 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        gint prev_row = -1, row = -1, column = -1;
        FolderItem *item;
        Folder *folder;
+       FolderViewPopup *fpopup;
+       GtkItemFactory *fpopup_factory;
        GtkWidget *popup;
-       gboolean mark_all_read   = FALSE;
-       gboolean new_folder      = FALSE;
-       gboolean rename_folder   = FALSE;
-       gboolean move_folder     = FALSE;
-       gboolean delete_folder   = FALSE;
-       gboolean download_msg    = FALSE;
-       gboolean update_tree     = FALSE;
-       gboolean rescan_tree     = FALSE;
-       gboolean remove_tree     = FALSE;
-       gboolean search_folder   = FALSE;
-       gboolean folder_property = FALSE;
-       gboolean folder_processing  = FALSE;
-       gboolean folder_scoring  = FALSE;
 
        if (!event) return;
 
@@ -1569,106 +1361,28 @@ static void folderview_button_pressed(GtkWidget *ctree, GdkEventButton *event,
        g_return_if_fail(item->folder != NULL);
        folder = item->folder;
 
-       if (folderview->mainwin->lock_count == 0) {
-               new_folder = TRUE;
-               if (folder_item_parent(item) == NULL) {
-                       update_tree = remove_tree = TRUE;
-                       if (folder->account)
-                               folder_property = TRUE;
-               } else
-                       mark_all_read = search_folder = folder_property = TRUE;
-                       
-               if (FOLDER_IS_LOCAL(folder) || FOLDER_TYPE(folder) == F_IMAP /* || FOLDER_TYPE(folder) == F_MBOX */) {
-                       if (folder_item_parent(item) == NULL)
-                               update_tree = rescan_tree = TRUE;
-                       else if (item->stype == F_NORMAL)
-                               move_folder = rename_folder = delete_folder = folder_scoring = folder_processing = TRUE;
-                       else if (item->stype == F_INBOX)
-                               folder_scoring = folder_processing = TRUE;
-                       else if (item->stype == F_TRASH)
-                               folder_processing = TRUE;
-                       else if (item->stype == F_OUTBOX)
-                               folder_processing = TRUE;
-                       if (0 == item->total_msgs)
-                               search_folder = FALSE;
-               } else if (FOLDER_TYPE(folder) == F_NEWS) {
-                       if (folder_item_parent(item) != NULL)
-                               delete_folder = folder_scoring = folder_processing = TRUE;
-               }
-               if (FOLDER_TYPE(folder) == F_IMAP ||
-                   FOLDER_TYPE(folder) == F_NEWS) {
-                       if (folder_item_parent(item) != NULL && 
-                           item->no_select == FALSE &&
-                           !prefs_common.work_offline)
-                               download_msg = TRUE;
-               }
-               if (item->unread_msgs < 1) 
-                       mark_all_read = FALSE;
+       fpopup = g_hash_table_lookup(folderview_popups, folder->klass->idstr);
+       if (fpopup != NULL)
+               fpopup_factory = g_hash_table_lookup(folderview->popups, folder->klass->idstr);
+       else {
+               fpopup = g_hash_table_lookup(folderview_popups, "common");
+               fpopup_factory = g_hash_table_lookup(folderview->popups, "common");
        }
 
-#define SET_SENS(factory, name, sens) \
-       menu_set_sensitive(folderview->factory, name, sens)
-       
-       mark_all_read = mark_all_read && 
-                       (item == folderview->summaryview->folder_item);
-
-       if (FOLDER_IS_LOCAL(folder)) {
-               popup = folderview->mail_popup;
-               menu_set_insensitive_all(GTK_MENU_SHELL(popup));
-               SET_SENS(mail_factory, "/Mark all read", mark_all_read);
-               SET_SENS(mail_factory, "/Create new folder...", new_folder);
-               SET_SENS(mail_factory, "/Rename folder...", rename_folder);
-               SET_SENS(mail_factory, "/Move folder...", move_folder);
-               SET_SENS(mail_factory, "/Delete folder", delete_folder);
-               SET_SENS(mail_factory, "/Check for new messages", update_tree);
-               SET_SENS(mail_factory, "/Rebuild folder tree", rescan_tree);
-               SET_SENS(mail_factory, "/Remove mailbox", remove_tree);
-               SET_SENS(mail_factory, "/Search folder...", search_folder);
-               SET_SENS(mail_factory, "/Properties...", folder_property);
-               SET_SENS(mail_factory, "/Processing...", folder_processing);
-       } else if (FOLDER_TYPE(folder) == F_IMAP) {
-               popup = folderview->imap_popup;
-               menu_set_insensitive_all(GTK_MENU_SHELL(popup));
-               SET_SENS(imap_factory, "/Mark all read", mark_all_read);
-               SET_SENS(imap_factory, "/Create new folder...", new_folder);
-               SET_SENS(imap_factory, "/Rename folder...", rename_folder);
-               SET_SENS(imap_factory, "/Move folder...", move_folder);
-               SET_SENS(imap_factory, "/Delete folder", delete_folder);
-               SET_SENS(imap_factory, "/Download", download_msg);
-               SET_SENS(imap_factory, "/Check for new messages", update_tree);
-               SET_SENS(imap_factory, "/Rebuild folder tree", rescan_tree);
-               SET_SENS(imap_factory, "/Remove IMAP4 account", remove_tree);
-               SET_SENS(imap_factory, "/Search folder...", search_folder);
-               SET_SENS(imap_factory, "/Properties...", folder_property);
-               SET_SENS(imap_factory, "/Processing...", folder_processing);
-       } else if (FOLDER_TYPE(folder) == F_NEWS) {
-               popup = folderview->news_popup;
-               menu_set_insensitive_all(GTK_MENU_SHELL(popup));
-               SET_SENS(news_factory, "/Mark all read", mark_all_read);
-               SET_SENS(news_factory, "/Subscribe to newsgroup...", new_folder);
-               SET_SENS(news_factory, "/Remove newsgroup", delete_folder);
-               SET_SENS(news_factory, "/Download", download_msg);
-               SET_SENS(news_factory, "/Check for new messages", update_tree);
-               SET_SENS(news_factory, "/Remove news account", remove_tree);
-               SET_SENS(news_factory, "/Search folder...", search_folder);
-               SET_SENS(news_factory, "/Properties...", folder_property);
-               SET_SENS(news_factory, "/Processing...", folder_processing);
-#if 0
-       } else if (FOLDER_TYPE(folder) == F_MBOX) {
-               popup = folderview->mbox_popup;
-               menu_set_insensitive_all(GTK_MENU_SHELL(popup));
-               SET_SENS(mbox_factory, "/Create new folder...", new_folder);
-               SET_SENS(mbox_factory, "/Rename folder...", rename_folder);
-               SET_SENS(mbox_factory, "/Move folder...", move_folder);
-               SET_SENS(mbox_factory, "/Delete folder", delete_folder);
-               SET_SENS(news_factory, "/Properties...", folder_property);
-               SET_SENS(mbox_factory, "/Processing...", folder_processing);
-#endif
-       } else
-               return;
+       if (fpopup->set_sensitivity != NULL)
+               fpopup->set_sensitivity(fpopup_factory, item);
+
+#define SET_SENS(name, sens) \
+       menu_set_sensitive(fpopup_factory, name, sens)
+
+       SET_SENS("/Mark all read", item->unread_msgs >= 1);
+       SET_SENS("/Search folder...", item->total_msgs >= 1);
+       SET_SENS("/Properties...", TRUE);
+       SET_SENS("/Processing...", item->node->parent != NULL);
 
 #undef SET_SENS
 
+       popup = gtk_item_factory_get_widget(fpopup_factory, fpopup->path);
        gtk_menu_popup(GTK_MENU(popup), NULL, NULL, NULL, NULL,
                       event->button, event->time);
 }
@@ -1839,7 +1553,7 @@ static void folderview_tree_collapsed(GtkCTree *ctree, GtkCTreeNode *node,
 
        item = gtk_ctree_node_get_row_data(ctree, node);
        g_return_if_fail(item != NULL);
-       item->collapsed= TRUE;
+       item->collapsed = TRUE;
        folderview_update_node(folderview, node);
 }
 
@@ -1874,90 +1588,6 @@ static void folderview_col_resized(GtkCList *clist, gint column, gint width,
        }
 }
 
-static void folderview_download_func(Folder *folder, FolderItem *item,
-                                    gpointer data)
-{
-       GList *list;
-
-       for (list = folderview_list; list != NULL; list = list->next) {
-               FolderView *folderview = (FolderView *)list->data;
-               MainWindow *mainwin = folderview->mainwin;
-               gchar *str;
-
-               str = g_strdup_printf
-                       (_("Downloading messages in %s ..."), item->path);
-               main_window_progress_set(mainwin,
-                                        GPOINTER_TO_INT(data), item->total_msgs);
-               STATUSBAR_PUSH(mainwin, str);
-               STATUSBAR_POP(mainwin);
-               g_free(str);
-       }
-}
-
-static void folderview_download_cb(FolderView *folderview, guint action,
-                                  GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       MainWindow *mainwin = folderview->mainwin;
-       FolderItem *item;
-
-       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);
-#if 0
-       if (!prefs_common.online_mode) {
-               if (alertpanel(_("Offline"),
-                              _("You are offline. Go online?"),
-                              _("Yes"), _("No"), NULL) == G_ALERTDEFAULT)
-                       main_window_toggle_online(folderview->mainwin, TRUE);
-               else
-                       return;
-       }
-#endif
-       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();
-       folder_set_ui_func(item->folder, folderview_download_func, NULL);
-       if (folder_item_fetch_all_msg(item) < 0) {
-               gchar *name;
-
-               name = trim_string(item->name, 32);
-               alertpanel_error(_("Error occurred while downloading messages in `%s'."), name);
-               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);
-}
-
-static void folderview_update_tree_cb(FolderView *folderview, guint action,
-                                     GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-
-       if (!folderview->selected) return;
-
-       summary_show(folderview->summaryview, NULL);
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-
-       if (action == 0)
-               folderview_check_new(item->folder);
-       else
-               folderview_rescan_tree(item->folder);
-}
-
 void folderview_create_folder_node_recursive(FolderView *folderview, FolderItem *item)
 {
        GNode *srcnode;
@@ -2003,456 +1633,6 @@ void folderview_create_folder_node(FolderView *folderview, FolderItem *item)
        gtk_clist_thaw(GTK_CLIST(ctree));
 }
 
-static void folderview_new_folder_cb(FolderView *folderview, guint action,
-                                    GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       FolderItem *new_item;
-       gchar *new_folder;
-       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);
-       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;});
-
-       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);
-       AUTORELEASE_STR(name, {g_free(name); return;});
-
-       /* find whether the directory already exists */
-       if (folder_find_child_item_by_name(item, new_folder)) {
-               alertpanel_error(_("The folder `%s' already exists."), name);
-               return;
-       }
-
-       new_item = folder_create_folder(item, new_folder);
-       if (!new_item) {
-               alertpanel_error(_("Can't create the folder `%s'."), name);
-               return;
-       }
-
-       folderview_append_item(new_item);
-       folder_write_list();
-}
-
-static void folderview_rename_folder_cb(FolderView *folderview, guint action,
-                                       GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       gchar *new_folder;
-       gchar *name;
-       gchar *message;
-       gchar *old_path;
-       gchar *old_id;
-       gchar *new_id;
-
-       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);
-
-       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);
-               return;
-       }
-
-       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);
-               return;
-       }
-
-       Xstrdup_a(old_path, item->path, {g_free(new_folder); return;});
-
-       old_id = folder_item_get_identifier(item);
-       
-       if (item->folder->klass->rename_folder(item->folder, item, new_folder) < 0) {
-               alertpanel_error(_("The folder could not be renamed.\n"
-                                  "The new folder name is not allowed."));
-               g_free(old_id);
-               return;
-       }
-
-       /* if (FOLDER_TYPE(item->folder) == F_MH)
-               prefs_filtering_rename_path(old_path, item->path); */
-       new_id = folder_item_get_identifier(item);
-       prefs_filtering_rename_path(old_id, new_id);
-
-       g_free(old_id);
-       g_free(new_id);
-
-       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 ||
-           gtk_ctree_is_ancestor(ctree,
-                                 folderview->selected,
-                                 folderview->opened)) {
-               GtkCTreeNode *node = folderview->opened;
-               folderview_unselect(folderview);
-               folderview_select_node(folderview, node);
-       }
-
-       gtk_clist_thaw(GTK_CLIST(ctree));
-       
-       folder_item_prefs_save_config(item);
-       folder_write_list();
-}
-
-static void folderview_delete_folder_cb(FolderView *folderview, guint action,
-                                       GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       gchar *message, *name;
-       AlertValue avalue;
-       gchar *old_path;
-       gchar *old_id;
-
-       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);
-
-       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);
-       avalue = alertpanel(_("Delete folder"), message,
-                           _("Yes"), _("+No"), NULL);
-       g_free(message);
-       if (avalue != G_ALERTDEFAULT) return;
-
-       Xstrdup_a(old_path, item->path, return);
-       old_id = folder_item_get_identifier(item);
-
-       if (folderview->opened == folderview->selected ||
-           gtk_ctree_is_ancestor(ctree,
-                                 folderview->selected,
-                                 folderview->opened)) {
-               summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
-       }
-
-       if (item->folder->klass->remove_folder(item->folder, item) < 0) {
-               alertpanel_error(_("Can't remove the folder `%s'."), name);
-               if (folderview->opened == folderview->selected)
-                       summary_show(folderview->summaryview,
-                                    folderview->summaryview->folder_item);
-               g_free(old_id);
-               return;
-       }
-
-       folder_write_list();
-
-       prefs_filtering_delete_path(old_id);
-       g_free(old_id);
-
-}
-
-static void folderview_remove_mailbox_cb(FolderView *folderview, guint action,
-                                        GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       GtkCTreeNode *node;
-       FolderItem *item;
-       gchar *name;
-       gchar *message;
-       AlertValue avalue;
-
-       if (!folderview->selected) return;
-       node = folderview->selected;
-       item = gtk_ctree_node_get_row_data(ctree, node);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-       if (folder_item_parent(item)) return;
-
-       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);
-       summary_clear_all(folderview->summaryview);
-
-       folder_destroy(item->folder);
-}
-
-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;
-       gchar *message;
-       AlertValue avalue;
-
-       if (!folderview->selected) return;
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-       g_return_if_fail(FOLDER_TYPE(item->folder) == F_IMAP);
-       g_return_if_fail(item->folder->account != NULL);
-
-       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;
-
-       if (folderview->opened == folderview->selected ||
-           gtk_ctree_is_ancestor(ctree,
-                                 folderview->selected,
-                                 folderview->opened)) {
-               summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
-       }
-
-       account = item->folder->account;
-       folderview_unselect(folderview);
-       summary_clear_all(folderview->summaryview);
-       folder_destroy(item->folder);
-       account_destroy(account);
-       account_set_menu();
-       main_window_reflect_prefs_all();
-       folder_write_list();
-}
-
-static void 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;
-       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);
-       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,
-                                       (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;
-               }
-
-               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;
-
-               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_sort_folders(folderview, servernode, folder);
-       gtk_clist_thaw(GTK_CLIST(ctree));
-
-       slist_free_strings(new_subscr);
-       g_slist_free(new_subscr);
-
-       folder_write_list();
-}
-
-static void folderview_rm_news_group_cb(FolderView *folderview, guint action,
-                                       GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       gchar *name;
-       gchar *message;
-       gchar *old_id;
-       AlertValue avalue;
-
-       if (!folderview->selected) return;
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-       g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
-       g_return_if_fail(item->folder->account != NULL);
-
-       old_id = folder_item_get_identifier(item);
-
-       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) {
-               summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
-       }
-
-       folder_item_remove(item);
-       folder_write_list();
-       
-       prefs_filtering_delete_path(old_id);
-       g_free(old_id);
-}
-
-static void folderview_rm_news_server_cb(FolderView *folderview, guint action,
-                                        GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-       PrefsAccount *account;
-       gchar *name;
-       gchar *message;
-       AlertValue avalue;
-
-       if (!folderview->selected) return;
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-       g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
-       g_return_if_fail(item->folder->account != NULL);
-
-       name = trim_string(item->folder->name, 32);
-       message = g_strdup_printf(_("Really delete news account `%s'?"), name);
-       avalue = alertpanel(_("Delete news account"), message,
-                           _("Yes"), _("+No"), NULL);
-       g_free(message);
-       g_free(name);
-
-       if (avalue != G_ALERTDEFAULT) return;
-
-       if (folderview->opened == folderview->selected ||
-           gtk_ctree_is_ancestor(ctree,
-                                 folderview->selected,
-                                 folderview->opened)) {
-               summary_clear_all(folderview->summaryview);
-               folderview->opened = NULL;
-       }
-
-       account = item->folder->account;
-       folderview_unselect(folderview);
-       summary_clear_all(folderview->summaryview);
-       folder_destroy(item->folder);
-       account_destroy(account);
-       account_set_menu();
-       main_window_reflect_prefs_all();
-       folder_write_list();
-}
-
 static void folderview_search_cb(FolderView *folderview, guint action,
                                 GtkWidget *widget)
 {
@@ -2498,25 +1678,8 @@ static void folderview_recollapse_nodes(FolderView *folderview, GtkCTreeNode *no
        g_slist_free(done);
 }
 
-static void folderview_move_to_cb(FolderView *folderview) 
-{
-       FolderItem *from_folder = NULL, *to_folder = NULL;
-
-       if (folderview->selected)
-               from_folder = gtk_ctree_node_get_row_data(GTK_CTREE(folderview->ctree), folderview->selected);
-       if (!from_folder || FOLDER_TYPE(from_folder->folder) == F_NEWS)
-               return;
-
-       to_folder = foldersel_folder_sel(from_folder->folder, FOLDER_SEL_MOVE, NULL);
-       
-       if (!to_folder || FOLDER_TYPE(to_folder->folder) == F_NEWS)
-               return;
-
-       folderview_move_to(folderview, from_folder, to_folder);
-}
-
-static void folderview_move_to(FolderView *folderview, FolderItem *from_folder,
-                              FolderItem *to_folder)
+void folderview_move_folder(FolderView *folderview, FolderItem *from_folder,
+                           FolderItem *to_folder)
 {
        FolderItem *from_parent = NULL;
        FolderItem *new_folder = NULL;
@@ -2524,6 +1687,10 @@ static void folderview_move_to(FolderView *folderview, FolderItem *from_folder,
        gchar *buf;
        gint status;
 
+       g_return_if_fail(folderview != NULL);
+       g_return_if_fail(from_folder != NULL);
+       g_return_if_fail(to_folder != NULL);
+
        src_node = gtk_ctree_find_by_row_data(GTK_CTREE(folderview->ctree), NULL, from_folder);
        from_parent = folder_item_parent(from_folder);
        buf = g_strdup_printf(_("Moving %s to %s..."), from_folder->name, to_folder->name);
@@ -2883,7 +2050,7 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
                        return;
                }
 
-               folderview_move_to(folderview, src_item, item);
+               folderview_move_folder(folderview, src_item, item);
                gtk_drag_finish(drag_context, TRUE, TRUE, time);
        }
        folderview->nodes_to_recollapse = NULL;
@@ -2900,5 +2067,32 @@ static void folderview_drag_end_cb(GtkWidget         *widget,
 
 FolderItem *folderview_get_selected(FolderView *folderview)
 {
-       return (FolderItem *) gtk_ctree_node_get_row_data(folderview->ctree, folderview->opened);
+       return (FolderItem *) gtk_ctree_node_get_row_data(
+               GTK_CTREE(folderview->ctree), folderview->selected);
+}
+
+void folderview_register_popup(FolderViewPopup *fpopup)
+{
+       GList *folderviews;
+
+       for (folderviews = folderview_list; folderviews != NULL; folderviews = g_list_next(folderviews)) {
+               FolderView *folderview = folderviews->data;
+               GtkItemFactory *factory;
+
+               factory = create_ifactory(folderview, fpopup);
+               g_hash_table_insert(folderview->popups, fpopup->klass, factory);
+       }       
+       g_hash_table_insert(folderview_popups, fpopup->klass, fpopup);
+}
+
+void folderview_unregister_popup(FolderViewPopup *fpopup)
+{
+       GList *folderviews;
+
+       for (folderviews = folderview_list; folderviews != NULL; folderviews = g_list_next(folderviews)) {
+               FolderView *folderview = folderviews->data;
+
+               g_hash_table_remove(folderview->popups, fpopup->klass);
+       }       
+       g_hash_table_remove(folderview_popups, fpopup->klass);
 }
index 56490ac..f589a76 100644 (file)
@@ -21,6 +21,7 @@
 #define __FOLDERVIEW_H__
 
 typedef struct _FolderView     FolderView;
+typedef struct _FolderViewPopup        FolderViewPopup;
 
 #include <glib.h>
 #include <gtk/gtkwidget.h>
@@ -34,19 +35,8 @@ struct _FolderView
 {
        GtkWidget *scrolledwin;
        GtkWidget *ctree;
-       GtkWidget *mail_popup;
-       GtkWidget *imap_popup;
-       GtkWidget *news_popup;
-#if 0
-       GtkWidget *mbox_popup;
-#endif
-
-       GtkItemFactory *mail_factory;
-       GtkItemFactory *imap_factory;
-       GtkItemFactory *news_factory;
-#if 0
-       GtkItemFactory *mbox_factory;
-#endif
+
+       GHashTable *popups;
 
        GtkCTreeNode *selected;
        GtkCTreeNode *opened;
@@ -71,6 +61,15 @@ struct _FolderView
        GtkTargetList *target_list; /* DnD */
 };
 
+struct _FolderViewPopup
+{
+       gchar            *klass;
+       gchar            *path;
+       GSList           *entries;
+       void            (*set_sensitivity)      (GtkItemFactory *menu, FolderItem *item);
+};
+
+void folderview_initialize             (void);
 FolderView *folderview_create          (void);
 void folderview_init                   (FolderView     *folderview);
 void folderview_set                    (FolderView     *folderview);
@@ -94,12 +93,15 @@ void folderview_update_item_foreach (GHashTable     *table,
                                         gboolean        update_summary);
 void folderview_update_all_updated     (gboolean        update_summary);
 
-void folderview_new_folder             (FolderView     *folderview);
-void folderview_rename_folder          (FolderView     *folderview);
-void folderview_delete_folder          (FolderView     *folderview);
+void folderview_move_folder            (FolderView     *folderview,
+                                        FolderItem     *from_folder,
+                                        FolderItem     *to_folder);
 
 void folderview_set_target_folder_color (gint          color_op);
 
 void folderview_reflect_prefs_pixmap_theme     (FolderView *folderview);
 
+void folderview_register_popup         (FolderViewPopup        *fpopup);
+void folderview_unregister_popup       (FolderViewPopup        *fpopup);
+
 #endif /* __FOLDERVIEW_H__ */
index eec7bb4..5298a0b 100644 (file)
@@ -34,8 +34,6 @@
 #include "menu.h"
 #include "utils.h"
 
-static gchar *menu_translate(const gchar *path, gpointer data);
-
 static void menu_item_add_accel( GtkWidget *widget, guint accel_signal_id, GtkAccelGroup *accel_group,
                                 guint accel_key, GdkModifierType accel_mods, GtkAccelFlags accel_flags,
                                 gpointer user_data);
@@ -89,7 +87,7 @@ GtkWidget *popupmenu_create(GtkWidget *window, GtkItemFactoryEntry *entries,
        return gtk_item_factory_get_widget(factory, path);
 }
 
-static gchar *menu_translate(const gchar *path, gpointer data)
+gchar *menu_translate(const gchar *path, gpointer data)
 {
        gchar *retval;
 
index 467e616..2f6377c 100644 (file)
@@ -50,11 +50,12 @@ GtkWidget *menu_create_items        (GtkItemFactoryEntry    *entries,
                                 const gchar            *path,
                                 GtkItemFactory        **factory,
                                 gpointer                data);
-GtkWidget *popupmenu_create(GtkWidget *window,
+GtkWidget *popupmenu_create    (GtkWidget *window,
                                 GtkItemFactoryEntry *entries,
-                            guint n_entries,
+                                guint n_entries,
                                 const gchar *path,
                                 gpointer data);
+gchar *menu_translate          (const gchar *path, gpointer data);
 
 GString *menu_factory_get_rc   (const gchar            *path);
 void menu_factory_clear_rc     (const gchar            *rc_str);
diff --git a/src/imap_gtk.c b/src/imap_gtk.c
new file mode 100644 (file)
index 0000000..e73cbda
--- /dev/null
@@ -0,0 +1,390 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "utils.h"
+#include "folder.h"
+#include "folderview.h"
+#include "menu.h"
+#include "account.h"
+#include "alertpanel.h"
+#include "foldersel.h"
+#include "inputdialog.h"
+#include "imap.h"
+#include "inc.h"
+
+static void new_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void rename_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void move_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void remove_server_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void delete_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void update_tree_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void download_cb(FolderView *folderview, guint action, GtkWidget *widget);
+
+static GtkItemFactoryEntry imap_popup_entries[] =
+{
+       {N_("/Create _new folder..."),   NULL, new_folder_cb,    0, NULL},
+       {N_("/_Rename folder..."),       NULL, rename_folder_cb, 0, NULL},
+       {N_("/M_ove folder..."),         NULL, move_folder_cb,   0, NULL},
+       {N_("/_Delete folder"),          NULL, delete_folder_cb, 0, NULL},
+       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
+       {N_("/Down_load messages"),      NULL, download_cb,      0, NULL},
+       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
+       {N_("/_Check for new messages"), NULL, update_tree_cb,   0, NULL},
+       {N_("/R_ebuild folder tree"),    NULL, update_tree_cb,   1, NULL},
+       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
+       {N_("/Remove _IMAP4 account"),   NULL, remove_server_cb, 0, NULL},
+       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
+};
+
+static void set_sensitivity(GtkItemFactory *factory, FolderItem *item);
+
+static FolderViewPopup imap_popup =
+{
+       "imap",
+       "<IMAPFolder>",
+       NULL,
+       set_sensitivity
+};
+
+void imap_gtk_init(void)
+{
+       guint i, n_entries;
+
+       n_entries = sizeof(imap_popup_entries) /
+               sizeof(imap_popup_entries[0]);
+       for (i = 0; i < n_entries; i++)
+               imap_popup.entries = g_slist_append(imap_popup.entries, &imap_popup_entries[i]);
+
+       folderview_register_popup(&imap_popup);
+}
+
+static void set_sensitivity(GtkItemFactory *factory, FolderItem *item)
+{
+#define SET_SENS(name, sens) \
+       menu_set_sensitive(factory, name, sens)
+
+       SET_SENS("/Create new folder...",   TRUE);
+       SET_SENS("/Rename folder...",       item->stype == F_NORMAL && folder_item_parent(item) != NULL);
+       SET_SENS("/Move folder...",         item->stype == F_NORMAL && folder_item_parent(item) != NULL);
+       SET_SENS("/Delete folder",          item->stype == F_NORMAL && folder_item_parent(item) != NULL);
+
+       SET_SENS("/Check for new messages", folder_item_parent(item) == NULL);
+       SET_SENS("/Rebuild folder tree",    folder_item_parent(item) == NULL);
+
+       SET_SENS("/Remove IMAP4 account",   folder_item_parent(item) == NULL);
+
+#undef SET_SENS
+}
+
+static void new_folder_cb(FolderView *folderview, guint action,
+                         GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       FolderItem *new_item;
+       gchar *new_folder;
+       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);
+       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;
+       AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
+
+       p = strchr(new_folder, G_DIR_SEPARATOR);
+       if (p && *(p + 1) != '\0') {
+               alertpanel_error(_("`%c' can't be included in folder name."),
+                                G_DIR_SEPARATOR);
+               return;
+       }
+
+       name = trim_string(new_folder, 32);
+       AUTORELEASE_STR(name, {g_free(name); return;});
+
+       /* find whether the directory already exists */
+       if (folder_find_child_item_by_name(item, new_folder)) {
+               alertpanel_error(_("The folder `%s' already exists."), name);
+               return;
+       }
+
+       new_item = folder_create_folder(item, new_folder);
+       if (!new_item) {
+               alertpanel_error(_("Can't create the folder `%s'."), name);
+               return;
+       }
+       folder_write_list();
+}
+
+static void rename_folder_cb(FolderView *folderview, guint action,
+                            GtkWidget *widget)
+{
+       FolderItem *item;
+       gchar *new_folder;
+       gchar *name;
+       gchar *message;
+       gchar *old_path;
+       gchar *old_id;
+       gchar *new_id;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->path != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       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;});
+
+/*
+       TODO: check new name for IMAP namespace separator
+       if (strchr(new_folder, G_DIR_SEPARATOR) != NULL) {
+               alertpanel_error(_("`%c' can't be included in folder name."),
+                                G_DIR_SEPARATOR);
+               return;
+       }
+*/
+       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);
+               return;
+       }
+
+       Xstrdup_a(old_path, item->path, {g_free(new_folder); return;});
+
+       old_id = folder_item_get_identifier(item);
+       
+       if (folder_item_rename(item, new_folder) < 0) {
+               alertpanel_error(_("The folder could not be renamed.\n"
+                                  "The new folder name is not allowed."));
+               g_free(old_id);
+               return;
+       }
+
+       /* if (FOLDER_TYPE(item->folder) == F_MH)
+               prefs_filtering_rename_path(old_path, item->path); */
+       new_id = folder_item_get_identifier(item);
+       prefs_filtering_rename_path(old_id, new_id);
+
+       g_free(old_id);
+       g_free(new_id);
+
+       folder_item_prefs_save_config(item);
+       folder_write_list();
+}
+
+static void move_folder_cb(FolderView *folderview, guint action, GtkWidget *widget)
+{
+       FolderItem *from_folder = NULL, *to_folder = NULL;
+
+       from_folder = folderview_get_selected(folderview);
+       if (!from_folder || from_folder->folder->klass != imap_get_class())
+               return;
+
+       to_folder = foldersel_folder_sel(from_folder->folder, FOLDER_SEL_MOVE, NULL);
+       if (!to_folder)
+               return;
+       
+       folderview_move_folder(folderview, from_folder, to_folder);
+}
+
+static void remove_server_cb(FolderView *folderview, guint action, GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       PrefsAccount *account;
+       gchar *name;
+       gchar *message;
+       AlertValue avalue;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       g_return_if_fail(item->folder->account != NULL);
+
+       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;
+
+       if (folderview->opened == folderview->selected ||
+           gtk_ctree_is_ancestor(ctree,
+                                 folderview->selected,
+                                 folderview->opened)) {
+               summary_clear_all(folderview->summaryview);
+               folderview->opened = NULL;
+       }
+
+       account = item->folder->account;
+       folderview_unselect(folderview);
+       summary_clear_all(folderview->summaryview);
+       folder_destroy(item->folder);
+       account_destroy(account);
+       account_set_menu();
+       main_window_reflect_prefs_all();
+       folder_write_list();
+}
+
+static void delete_folder_cb(FolderView *folderview, guint action,
+                            GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       gchar *message, *name;
+       AlertValue avalue;
+       gchar *old_path;
+       gchar *old_id;
+
+       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);
+
+       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);
+       avalue = alertpanel(_("Delete folder"), message,
+                           _("Yes"), _("+No"), NULL);
+       g_free(message);
+       if (avalue != G_ALERTDEFAULT) return;
+
+       Xstrdup_a(old_path, item->path, return);
+       old_id = folder_item_get_identifier(item);
+
+       if (folderview->opened == folderview->selected ||
+           gtk_ctree_is_ancestor(ctree,
+                                 folderview->selected,
+                                 folderview->opened)) {
+               summary_clear_all(folderview->summaryview);
+               folderview->opened = NULL;
+       }
+
+       if (item->folder->klass->remove_folder(item->folder, item) < 0) {
+               alertpanel_error(_("Can't remove the folder `%s'."), name);
+               if (folderview->opened == folderview->selected)
+                       summary_show(folderview->summaryview,
+                                    folderview->summaryview->folder_item);
+               g_free(old_id);
+               return;
+       }
+
+       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;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+
+       summary_show(folderview->summaryview, NULL);
+
+       g_return_if_fail(item->folder != NULL);
+
+       if (action == 0)
+               folderview_check_new(item->folder);
+       else
+               folderview_rescan_tree(item->folder);
+}
+
+static void download_cb(FolderView *folderview, guint action,
+                       GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       MainWindow *mainwin = folderview->mainwin;
+       FolderItem *item;
+
+       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);
+#if 0
+       if (!prefs_common.online_mode) {
+               if (alertpanel(_("Offline"),
+                              _("You are offline. Go online?"),
+                              _("Yes"), _("No"), NULL) == G_ALERTDEFAULT)
+                       main_window_toggle_online(folderview->mainwin, TRUE);
+               else
+                       return;
+       }
+#endif
+       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);
+               alertpanel_error(_("Error occurred while downloading messages in `%s'."), name);
+               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);
+}
diff --git a/src/imap_gtk.h b/src/imap_gtk.h
new file mode 100644 (file)
index 0000000..957714b
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef IMAP_GTK_H
+#define IMAP_GTK_H
+
+void imap_gtk_init(void);
+
+#endif /* IMAP_GTK_H */
index a09b6a5..8b2c545 100644 (file)
@@ -73,6 +73,9 @@
 #include "log.h"
 #include "prefs_toolbar.h"
 #include "plugin.h"
+#include "mh_gtk.h"
+#include "imap_gtk.h"
+#include "news_gtk.h"
 
 #if USE_GPGME
 #  include "sgpgme.h"
@@ -270,6 +273,10 @@ int main(int argc, char *argv[])
 
        gtkut_widget_init();
 
+       folderview_initialize();
+       mh_gtk_init();
+       imap_gtk_init();
+       news_gtk_init();
        mainwin = main_window_create
                (prefs_common.sep_folder | prefs_common.sep_msg << 1);
        folderview = mainwin->folderview;
index 0f1b102..7d9fa15 100644 (file)
@@ -144,15 +144,6 @@ static void message_window_size_allocate_cb        (GtkWidget      *widget,
                                                 GtkAllocation  *allocation,
                                                 gpointer        data);
 
-static void new_folder_cb       (MainWindow    *mainwin,
-                                 guint          action,
-                                 GtkWidget     *widget);
-static void rename_folder_cb    (MainWindow    *mainwin,
-                                 guint          action,
-                                 GtkWidget     *widget);
-static void delete_folder_cb    (MainWindow    *mainwin,
-                                 guint          action,
-                                 GtkWidget     *widget);
 static void update_folderview_cb (MainWindow   *mainwin,
                                  guint          action,
                                  GtkWidget     *widget);
@@ -437,14 +428,6 @@ gboolean mainwindow_progressindicator_hook (gpointer        source,
 static GtkItemFactoryEntry mainwin_entries[] =
 {
        {N_("/_File"),                          NULL, NULL, 0, "<Branch>"},
-       {N_("/_File/_Folder"),                  NULL, NULL, 0, "<Branch>"},
-       {N_("/_File/_Folder/Create _new folder..."),
-                                               NULL, new_folder_cb, 0, NULL},
-       {N_("/_File/_Folder/_Rename folder..."),NULL, rename_folder_cb, 0, NULL},
-       {N_("/_File/_Folder/_Delete folder"),   NULL, delete_folder_cb, 0, NULL},
-       {N_("/_File/_Folder/---"),                      NULL, NULL, 0, "<Separator>"},
-       {N_("/_File/_Folder/_Check for new messages in all folders"),
-                                               NULL, update_folderview_cb, 0, NULL},
        {N_("/_File/_Add mailbox"),             NULL, NULL, 0, "<Branch>"},
        {N_("/_File/_Add mailbox/MH..."),       NULL, add_mailbox_cb, 0, NULL},
        {N_("/_File/_Import mbox file..."),     NULL, import_mbox_cb, 0, NULL},
@@ -707,6 +690,8 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
        {N_("/_Tools/Actio_ns"),                NULL, NULL, 0, "<Branch>"},
        {N_("/_Tools/---"),                     NULL, NULL, 0, "<Separator>"},
+       {N_("/_Tools/_Check for new messages in all folders"),
+                                               NULL, update_folderview_cb, 0, NULL},
        {N_("/_Tools/Delete du_plicated messages"),
                                                NULL, NULL, 0, "<Branch>"},
        {N_("/_Tools/Delete du_plicated messages/In selected folder"),
@@ -1703,7 +1688,6 @@ void main_window_set_menu_sensitive(MainWindow *mainwin)
                gchar *const entry;
                SensitiveCond cond;
        } entry[] = {
-               {"/File/Folder"                               , M_UNLOCKED},
                {"/File/Add mailbox"                          , M_UNLOCKED},
 
                 {"/File/Add mailbox/MH..."                   , M_UNLOCKED},
@@ -2320,24 +2304,6 @@ static void update_folderview_cb(MainWindow *mainwin, guint action,
        folderview_check_new_all();
 }
 
-static void new_folder_cb(MainWindow *mainwin, guint action,
-                         GtkWidget *widget)
-{
-       folderview_new_folder(mainwin->folderview);
-}
-
-static void rename_folder_cb(MainWindow *mainwin, guint action,
-                            GtkWidget *widget)
-{
-       folderview_rename_folder(mainwin->folderview);
-}
-
-static void delete_folder_cb(MainWindow *mainwin, guint action,
-                            GtkWidget *widget)
-{
-       folderview_delete_folder(mainwin->folderview);
-}
-
 static void import_mbox_cb(MainWindow *mainwin, guint action,
                           GtkWidget *widget)
 {
diff --git a/src/mh_gtk.c b/src/mh_gtk.c
new file mode 100644 (file)
index 0000000..3e801ad
--- /dev/null
@@ -0,0 +1,327 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "utils.h"
+#include "folder.h"
+#include "folderview.h"
+#include "menu.h"
+#include "account.h"
+#include "alertpanel.h"
+#include "inputdialog.h"
+#include "mh.h"
+#include "foldersel.h"
+
+static void new_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void delete_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void rename_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void move_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void update_tree_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void remove_mailbox_cb(FolderView *folderview, guint action, GtkWidget *widget);
+
+static GtkItemFactoryEntry mh_popup_entries[] =
+{
+       {N_("/Create _new folder..."),   NULL, new_folder_cb,     0, NULL},
+       {N_("/_Rename folder..."),       NULL, rename_folder_cb,  0, NULL},
+       {N_("/M_ove folder..."),         NULL, move_folder_cb,    0, NULL},
+       {N_("/_Delete folder"),          NULL, delete_folder_cb,  0, NULL},
+       {N_("/---"),                     NULL, NULL,              0, "<Separator>"},
+       {N_("/_Check for new messages"), NULL, update_tree_cb,    0, NULL},
+       {N_("/R_ebuild folder tree"),    NULL, update_tree_cb,    1, NULL},
+       {N_("/---"),                     NULL, NULL,              0, "<Separator>"},
+       {N_("/Remove _mailbox"),         NULL, remove_mailbox_cb, 0, NULL},
+       {N_("/---"),                     NULL, NULL,              0, "<Separator>"},
+};
+
+static void set_sensitivity(GtkItemFactory *factory, FolderItem *item);
+
+static FolderViewPopup mh_popup =
+{
+       "mh",
+       "<MHFolder>",
+       NULL,
+       set_sensitivity
+};
+
+void mh_gtk_init(void)
+{
+       guint i, n_entries;
+
+       n_entries = sizeof(mh_popup_entries) /
+               sizeof(mh_popup_entries[0]);
+       for (i = 0; i < n_entries; i++)
+               mh_popup.entries = g_slist_append(mh_popup.entries, &mh_popup_entries[i]);
+
+       folderview_register_popup(&mh_popup);
+}
+
+static void set_sensitivity(GtkItemFactory *factory, FolderItem *item)
+{
+#define SET_SENS(name, sens) \
+       menu_set_sensitive(factory, name, sens)
+
+       SET_SENS("/Create new folder...",   TRUE);
+       SET_SENS("/Rename folder...",       item->stype == F_NORMAL && folder_item_parent(item) != NULL);
+       SET_SENS("/Move folder...",         item->stype == F_NORMAL && folder_item_parent(item) != NULL);
+       SET_SENS("/Delete folder",          item->stype == F_NORMAL && folder_item_parent(item) != NULL);
+
+       SET_SENS("/Check for new messages", folder_item_parent(item) == NULL);
+       SET_SENS("/Rebuild folder tree",    folder_item_parent(item) == NULL);
+
+       SET_SENS("/Remove mailbox",         folder_item_parent(item) == NULL);
+
+#undef SET_SENS
+}
+
+static void new_folder_cb(FolderView *folderview, guint action,
+                         GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       FolderItem *new_item;
+       gchar *new_folder;
+       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);
+       if (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:"),
+                                 _("NewFolder"));
+       if (!new_folder) return;
+       AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
+
+       p = strchr(new_folder, G_DIR_SEPARATOR);
+       if (p) {
+               alertpanel_error(_("`%c' can't be included in folder name."),
+                                G_DIR_SEPARATOR);
+               return;
+       }
+
+       name = trim_string(new_folder, 32);
+       AUTORELEASE_STR(name, {g_free(name); return;});
+
+       /* find whether the directory already exists */
+       if (folder_find_child_item_by_name(item, new_folder)) {
+               alertpanel_error(_("The folder `%s' already exists."), name);
+               return;
+       }
+
+       new_item = folder_create_folder(item, new_folder);
+       if (!new_item) {
+               alertpanel_error(_("Can't create the folder `%s'."), name);
+               return;
+       }
+
+       folder_write_list();
+}
+
+static void delete_folder_cb(FolderView *folderview, guint action,
+                            GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       gchar *message, *name;
+       AlertValue avalue;
+       gchar *old_path;
+       gchar *old_id;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->path != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       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);
+       avalue = alertpanel(_("Delete folder"), message,
+                           _("Yes"), _("+No"), NULL);
+       g_free(message);
+       if (avalue != G_ALERTDEFAULT) return;
+
+       Xstrdup_a(old_path, item->path, return);
+       old_id = folder_item_get_identifier(item);
+
+       if (folderview->opened == folderview->selected ||
+           gtk_ctree_is_ancestor(ctree,
+                                 folderview->selected,
+                                 folderview->opened)) {
+               summary_clear_all(folderview->summaryview);
+               folderview->opened = NULL;
+       }
+
+       if (item->folder->klass->remove_folder(item->folder, item) < 0) {
+               alertpanel_error(_("Can't remove the folder `%s'."), name);
+               if (folderview->opened == folderview->selected)
+                       summary_show(folderview->summaryview,
+                                    folderview->summaryview->folder_item);
+               g_free(old_id);
+               return;
+       }
+
+       folder_write_list();
+
+       prefs_filtering_delete_path(old_id);
+       g_free(old_id);
+
+}
+
+static void rename_folder_cb(FolderView *folderview, guint action,
+                            GtkWidget *widget)
+{
+       FolderItem *item;
+       gchar *new_folder;
+       gchar *name;
+       gchar *message;
+       gchar *old_path;
+       gchar *old_id;
+       gchar *new_id;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->path != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       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);
+               return;
+       }
+
+       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);
+               return;
+       }
+
+       Xstrdup_a(old_path, item->path, {g_free(new_folder); return;});
+
+       old_id = folder_item_get_identifier(item);
+       
+       if (folder_item_rename(item, new_folder) < 0) {
+               alertpanel_error(_("The folder could not be renamed.\n"
+                                  "The new folder name is not allowed."));
+               g_free(old_id);
+               return;
+       }
+
+       /* if (FOLDER_TYPE(item->folder) == F_MH)
+               prefs_filtering_rename_path(old_path, item->path); */
+       new_id = folder_item_get_identifier(item);
+       prefs_filtering_rename_path(old_id, new_id);
+
+       g_free(old_id);
+       g_free(new_id);
+
+       folder_item_prefs_save_config(item);
+       folder_write_list();
+}
+
+static void move_folder_cb(FolderView *folderview, guint action, GtkWidget *widget)
+{
+       FolderItem *from_folder = NULL, *to_folder = NULL;
+
+       from_folder = folderview_get_selected(folderview);
+       if (!from_folder || from_folder->folder->klass != mh_get_class())
+               return;
+
+       to_folder = foldersel_folder_sel(from_folder->folder, FOLDER_SEL_MOVE, NULL);
+       if (!to_folder)
+               return;
+       
+       folderview_move_folder(folderview, from_folder, to_folder);
+}
+
+static void update_tree_cb(FolderView *folderview, guint action,
+                          GtkWidget *widget)
+{
+       FolderItem *item;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+
+       summary_show(folderview->summaryview, NULL);
+
+       g_return_if_fail(item->folder != NULL);
+
+       if (action == 0)
+               folderview_check_new(item->folder);
+       else
+               folderview_rescan_tree(item->folder);
+}
+
+static void remove_mailbox_cb(FolderView *folderview, guint action,
+                             GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       GtkCTreeNode *node;
+       FolderItem *item;
+       gchar *name;
+       gchar *message;
+       AlertValue avalue;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       if (folder_item_parent(item)) return;
+
+       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);
+       summary_clear_all(folderview->summaryview);
+
+       folder_destroy(item->folder);
+}
+
diff --git a/src/mh_gtk.h b/src/mh_gtk.h
new file mode 100644 (file)
index 0000000..f017201
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef MH_GTK_H
+#define MH_GTK_H
+
+void mh_gtk_init(void);
+
+#endif /* MH_GTK_H */
diff --git a/src/news_gtk.c b/src/news_gtk.c
new file mode 100644 (file)
index 0000000..95975e4
--- /dev/null
@@ -0,0 +1,322 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "utils.h"
+#include "folder.h"
+#include "folderview.h"
+#include "menu.h"
+#include "account.h"
+#include "alertpanel.h"
+#include "grouplistdialog.h"
+#include "common/hooks.h"
+#include "inc.h"
+
+static void subscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void unsubscribe_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void remove_news_server_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void update_tree_cb(FolderView *folderview, guint action, GtkWidget *widget);
+static void download_cb(FolderView *folderview, guint action, GtkWidget *widget);
+
+static GtkItemFactoryEntry news_popup_entries[] =
+{
+       {N_("/_Subscribe to newsgroup..."),     NULL, subscribe_newsgroup_cb,    0, NULL},
+       {N_("/_Unsubscribe newsgroup"),         NULL, unsubscribe_newsgroup_cb,  0, NULL},
+       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
+       {N_("/Down_load"),                      NULL, download_cb,               0, NULL},
+       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
+       {N_("/_Check for new messages"),        NULL, update_tree_cb,            0, NULL},
+       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
+       {N_("/Remove _news account"),           NULL, remove_news_server_cb,     0, NULL},
+       {N_("/---"),                            NULL, NULL,                      0, "<Separator>"},
+};
+
+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)
+{
+#define SET_SENS(name, sens) \
+       menu_set_sensitive(factory, name, sens)
+
+       SET_SENS("/Subscribe to newsgroup...", folder_item_parent(item) == NULL);
+       SET_SENS("/Unsubscribe newsgroup",     folder_item_parent(item) != NULL);
+       SET_SENS("/Remove news account",       folder_item_parent(item) == NULL);
+
+       SET_SENS("/Check for new messages",    folder_item_parent(item) == NULL);
+
+#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;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       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,
+                                       (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;
+               }
+
+               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_NEW_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;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
+       g_return_if_fail(item->folder->account != NULL);
+
+       old_id = folder_item_get_identifier(item);
+
+       name = trim_string(item->path, 32);
+       message = g_strdup_printf(_("Really unsubscribe newsgroup `%s'?"), name);
+       avalue = alertpanel(_("Unsubscribe newsgroup"), message,
+                           _("Yes"), _("+No"), NULL);
+       g_free(message);
+       g_free(name);
+       if (avalue != G_ALERTDEFAULT) return;
+
+       if (folderview->opened == folderview->selected) {
+               summary_clear_all(folderview->summaryview);
+               folderview->opened = NULL;
+       }
+
+       folder_item_remove(item);
+       folder_write_list();
+       
+       prefs_filtering_delete_path(old_id);
+       g_free(old_id);
+}
+
+static void remove_news_server_cb(FolderView *folderview, guint action,
+                                 GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+       PrefsAccount *account;
+       gchar *name;
+       gchar *message;
+       AlertValue avalue;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       g_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
+       g_return_if_fail(item->folder->account != NULL);
+
+       name = trim_string(item->folder->name, 32);
+       message = g_strdup_printf(_("Really delete news account `%s'?"), name);
+       avalue = alertpanel(_("Delete news account"), message,
+                           _("Yes"), _("+No"), NULL);
+       g_free(message);
+       g_free(name);
+
+       if (avalue != G_ALERTDEFAULT) return;
+
+       if (folderview->opened == folderview->selected ||
+           gtk_ctree_is_ancestor(ctree,
+                                 folderview->selected,
+                                 folderview->opened)) {
+               summary_clear_all(folderview->summaryview);
+               folderview->opened = NULL;
+       }
+
+       account = item->folder->account;
+       folderview_unselect(folderview);
+       summary_clear_all(folderview->summaryview);
+       folder_destroy(item->folder);
+       account_destroy(account);
+       account_set_menu();
+       main_window_reflect_prefs_all();
+       folder_write_list();
+}
+
+static void update_tree_cb(FolderView *folderview, guint action,
+                          GtkWidget *widget)
+{
+       FolderItem *item;
+
+       item = folderview_get_selected(folderview);
+       g_return_if_fail(item != NULL);
+
+       summary_show(folderview->summaryview, NULL);
+
+       g_return_if_fail(item->folder != NULL);
+
+       folderview_check_new(item->folder);
+}
+
+static void download_cb(FolderView *folderview, guint action,
+                       GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       MainWindow *mainwin = folderview->mainwin;
+       FolderItem *item;
+
+       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);
+#if 0
+       if (!prefs_common.online_mode) {
+               if (alertpanel(_("Offline"),
+                              _("You are offline. Go online?"),
+                              _("Yes"), _("No"), NULL) == G_ALERTDEFAULT)
+                       main_window_toggle_online(folderview->mainwin, TRUE);
+               else
+                       return;
+       }
+#endif
+       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);
+               alertpanel_error(_("Error occurred while downloading messages in `%s'."), name);
+               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);
+}
diff --git a/src/news_gtk.h b/src/news_gtk.h
new file mode 100644 (file)
index 0000000..8cbf08b
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef NEWS_GTK_H
+#define NEWS_GTK_H
+
+void news_gtk_init(void);
+
+#endif /* NEWS_GTK_H */