2007-01-03 [colin] 2.6.1cvs99
[claws.git] / src / imap_gtk.c
index 1693191c187de94ef8d4450f78d223a009f446dc..bd76cb20bd0b77cc93ddaa7180b1fe97468a0cb4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto & the Sylpheed-Claws Team
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto & the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -45,8 +45,6 @@
 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 imap_settings_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);
@@ -55,20 +53,20 @@ static void sync_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static GtkItemFactoryEntry imap_popup_entries[] =
 {
        {N_("/Create _new folder..."),   NULL, new_folder_cb,    0, NULL},
+       {"/---",                         NULL, NULL,             0, "<Separator>"},
        {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_("/Cop_y folder..."),         NULL, move_folder_cb,   1, NULL},
+       {"/---",                         NULL, NULL,             0, "<Separator>"},
+       {N_("/_Delete folder..."),       NULL, delete_folder_cb, 0, NULL},
+       {"/---",                         NULL, NULL,             0, "<Separator>"},
        {N_("/Synchronise"),             NULL, sync_cb,         0, NULL},
        {N_("/Down_load messages"),      NULL, download_cb,      0, NULL},
-       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
+       {"/---",                         NULL, NULL,             0, "<Separator>"},
        {N_("/_Check for new messages"), NULL, update_tree_cb,   0, NULL},
        {N_("/C_heck for new folders"),  NULL, update_tree_cb,   1, NULL},
        {N_("/R_ebuild folder tree"),    NULL, update_tree_cb,   2, NULL},
-       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
-       {N_("/IMAP4 _account settings"), NULL, imap_settings_cb, 0, NULL},
-       {N_("/Remove _IMAP4 account"),   NULL, remove_server_cb, 0, NULL},
-       {N_("/---"),                     NULL, NULL,             0, "<Separator>"},
+       {"/---",                         NULL, NULL,             0, "<Separator>"},
 };
 
 static void set_sensitivity(GtkItemFactory *factory, FolderItem *item);
@@ -108,14 +106,12 @@ static void set_sensitivity(GtkItemFactory *factory, FolderItem *item)
        SET_SENS("/Create new folder...",   item->no_sub == FALSE);
        SET_SENS("/Rename folder...",       item->stype == F_NORMAL && folder_item_parent(item) != NULL);
        SET_SENS("/Move folder...",         folder_is_normal && folder_item_parent(item) != NULL);
-       SET_SENS("/Delete 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("/Check for new folders",  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
 }
 
@@ -128,7 +124,8 @@ static void new_folder_cb(FolderView *folderview, guint action,
        gchar *new_folder;
        gchar *name;
        gchar *p;
-
+       gchar separator = '/';
+       
        if (!folderview->selected) return;
 
        item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
@@ -145,10 +142,18 @@ static void new_folder_cb(FolderView *folderview, guint action,
        if (!new_folder) return;
        AUTORELEASE_STR(new_folder, {g_free(new_folder); return;});
 
-       p = strchr(new_folder, G_DIR_SEPARATOR);
+       separator = imap_get_path_separator_for_item(item);
+
+       p = strchr(new_folder, separator);
        if (p && *(p + 1) != '\0') {
                alertpanel_error(_("'%c' can't be included in folder name."),
-                                G_DIR_SEPARATOR);
+                                separator);
+               return;
+       }
+       p = strchr(new_folder, '/');
+       if (p && *(p + 1) != '\0') {
+               alertpanel_error(_("'%c' can't be included in folder name."),
+                                '/');
                return;
        }
 
@@ -180,6 +185,7 @@ static void rename_folder_cb(FolderView *folderview, guint action,
        gchar *old_id;
        gchar *new_id;
        gchar *base;
+       gchar separator = '/';
 
        item = folderview_get_selected_item(folderview);
        g_return_if_fail(item != NULL);
@@ -196,14 +202,18 @@ static void rename_folder_cb(FolderView *folderview, guint action,
        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) {
+       separator = imap_get_path_separator_for_item(item);
+       if (strchr(new_folder, separator) != NULL) {
+               alertpanel_error(_("`%c' can't be included in folder name."),
+                                separator);
+               return;
+       }
+       if (strchr(new_folder, '/') != 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);
@@ -222,10 +232,9 @@ static void rename_folder_cb(FolderView *folderview, guint action,
                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);
+       account_rename_path(old_id, new_id);
 
        g_free(old_id);
        g_free(new_id);
@@ -246,62 +255,7 @@ static void move_folder_cb(FolderView *folderview, guint action, GtkWidget *widg
        if (!to_folder)
                return;
        
-       folderview_move_folder(folderview, from_folder, to_folder);
-}
-
-static void imap_settings_cb(FolderView *folderview, guint action, GtkWidget *widget)
-{
-       FolderItem *item;
-
-       item = folderview_get_selected_item(folderview);
-       if (item == NULL)
-               return;
-
-       account_open(item->folder->account);
-}
-
-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_full(_("Delete IMAP4 account"), message,
-                                GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
-                                NULL, ALERT_WARNING, G_ALERTALTERNATE);
-       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();
+       folderview_move_folder(folderview, from_folder, to_folder, action);
 }
 
 static void delete_folder_cb(FolderView *folderview, guint action,
@@ -328,10 +282,10 @@ static void delete_folder_cb(FolderView *folderview, guint action,
                   "Recovery will not be possible.\n\n"
                   "Do you really want to delete?"), name);
        avalue = alertpanel_full(_("Delete folder"), message,
-                                GTK_STOCK_YES, GTK_STOCK_NO, NULL, FALSE,
-                                NULL, ALERT_WARNING, G_ALERTALTERNATE);
+                                GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, FALSE,
+                                NULL, ALERT_WARNING, G_ALERTDEFAULT);
        g_free(message);
-       if (avalue != G_ALERTDEFAULT) return;
+       if (avalue != G_ALERTALTERNATE) return;
 
        Xstrdup_a(old_path, item->path, return);
        old_id = folder_item_get_identifier(item);
@@ -402,7 +356,7 @@ void imap_gtk_synchronise(FolderItem *item)
        gtk_widget_set_sensitive(folderview->ctree, FALSE);
        main_window_progress_on(mainwin);
        GTK_EVENTS_FLUSH();
-       if (folder_item_fetch_all_msg(item) < 0) {
+       if (item->no_select == FALSE && folder_item_fetch_all_msg(item) < 0) {
                gchar *name;
 
                name = trim_string(item->name, 32);