2008-07-05 [colin] 3.5.0cvs11
authorColin Leroy <colin@colino.net>
Sat, 5 Jul 2008 13:55:03 +0000 (13:55 +0000)
committerColin Leroy <colin@colino.net>
Sat, 5 Jul 2008 13:55:03 +0000 (13:55 +0000)
* src/news.c
* src/news_gtk.c
Provide ability to rename newsgroups. Closes
bug 1444, 'Add GUI option for renaming
newsgroups'. Patch by Pawel Pekala

ChangeLog
PATCHSETS
configure.ac
src/news.c
src/news_gtk.c

index 2575e5e..23bc83d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-05 [colin]     3.5.0cvs11
+
+       * src/news.c
+       * src/news_gtk.c
+               Provide ability to rename newsgroups. Closes
+               bug 1444, 'Add GUI option for renaming 
+               newsgroups'. Patch by Pawel Pekala
+
 2008-07-05 [colin]     3.5.0cvs10
 
        * src/plugins/pgpcore/passphrase.c
index ec97201..7bfeea8 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.105.2.136 -r 1.105.2.137 src/prefs_account.c;  cvs diff -u -r 1.8.2.12 -r 1.8.2.13 src/common/session.h;  cvs diff -u -r 1.9.2.30 -r 1.9.2.31 src/common/ssl.c;  ) > 3.5.0cvs8.patchset
 ( cvs diff -u -r 1.1.2.69 -r 1.1.2.70 src/wizard.c;  ) > 3.5.0cvs9.patchset
 ( cvs diff -u -r 1.1.2.29 -r 1.1.2.30 src/plugins/pgpcore/passphrase.c;  cvs diff -u -r 1.1.2.28 -r 1.1.2.29 src/plugins/pgpcore/prefs_gpg.c;  cvs diff -u -r 1.1.2.19 -r 1.1.2.20 src/plugins/pgpcore/select-keys.c;  ) > 3.5.0cvs10.patchset
+( cvs diff -u -r 1.101.2.51 -r 1.101.2.52 src/news.c;  cvs diff -u -r 1.2.2.25 -r 1.2.2.26 src/news_gtk.c;  ) > 3.5.0cvs11.patchset
index 2c953d7..3f08ee2 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=5
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=10
+EXTRA_VERSION=11
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index edee3ec..7d1a87f 100644 (file)
@@ -37,7 +37,6 @@
 
 #include "nntp-thread.h"
 #include "news.h"
-#include "news.h"
 #include "news_gtk.h"
 #include "socket.h"
 #include "recv.h"
@@ -147,6 +146,9 @@ static void news_synchronise                 (FolderItem    *item, gint days);
 static int news_remove_msg              (Folder        *folder, 
                                          FolderItem    *item, 
                                          gint           msgnum);
+static gint news_rename_folder          (Folder *folder,
+                                         FolderItem *item,
+                                         const gchar *name);
 static gint news_remove_folder          (Folder        *folder,
                                          FolderItem    *item);
 static FolderClass news_class;
@@ -166,6 +168,7 @@ FolderClass *news_get_class(void)
                news_class.item_get_path = news_item_get_path;
                news_class.get_num_list = news_get_num_list;
                news_class.scan_required = news_scan_required;
+               news_class.rename_folder = news_rename_folder;
                news_class.remove_folder = news_remove_folder;
 
                /* Message functions */
@@ -1212,6 +1215,26 @@ void news_synchronise(FolderItem *item, gint days)
        news_gtk_synchronise(item, days);
 }
 
+static gint news_rename_folder(Folder *folder, FolderItem *item,
+                               const gchar *name)
+{
+       gchar *path;
+        
+       g_return_val_if_fail(folder != NULL, -1);
+       g_return_val_if_fail(item != NULL, -1);
+       g_return_val_if_fail(item->path != NULL, -1);
+       g_return_val_if_fail(name != NULL, -1);
+
+       path = folder_item_get_path(item);
+       if (!is_dir_exist(path))
+               make_dir_hier(path);
+
+       g_free(item->name);
+       item->name = g_strdup(name);
+
+       return 0;
+}
+
 static gint news_remove_folder(Folder *folder, FolderItem *item)
 {
        gchar *path;
index b71bb79..51cd00d 100644 (file)
 #include "inc.h"
 #include "news.h"
 #include "statusbar.h"
+#include "inputdialog.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 rename_newsgroup_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static void update_tree_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static void download_cb(FolderView *folderview, guint action, GtkWidget *widget);
 static void sync_cb(FolderView *folderview, guint action, GtkWidget *widget);
@@ -55,6 +57,7 @@ static GtkItemFactoryEntry news_popup_entries[] =
        {"/---",                                NULL, NULL,                      0, "<Separator>"},
        {N_("/Synchronise"),                    NULL, sync_cb,          0, NULL},
        {N_("/Down_load messages"),             NULL, download_cb,               0, NULL},
+       {N_("/_Rename folder..."),              NULL, rename_newsgroup_cb,       0, NULL},
        {"/---",                                NULL, NULL,                      0, "<Separator>"},
        {N_("/_Check for new messages"),        NULL, update_tree_cb,            0, NULL},
        {"/---",                                NULL, NULL,                      0, "<Separator>"},
@@ -104,7 +107,10 @@ static void set_sensitivity(GtkItemFactory *factory, FolderItem *item)
        SET_SENS("/Synchronise",    
                 item ? (folder_item_parent(item) != NULL && folder_want_synchronise(item->folder))
                         : FALSE);
-
+       SET_SENS("/Rename folder...", 
+                folder_item_parent(item) != NULL 
+                && mainwin->lock_count == 0
+                && news_folder_locked(item->folder) == 0);
 #undef SET_SENS
 }
 
@@ -250,6 +256,65 @@ static void unsubscribe_newsgroup_cb(FolderView *folderview, guint action,
        g_free(old_id);
 }
 
+static FolderItem *find_child_by_name(FolderItem *item, const gchar *name)
+{
+       GNode *node;
+       FolderItem *child;
+
+       for (node = item->node->children; node != NULL; node = node->next) {
+               child = FOLDER_ITEM(node->data);
+               if (strcmp2(child->name, name) == 0) {
+                       return child;
+               }
+       }
+
+       return NULL;
+}
+
+static void rename_newsgroup_cb(FolderView *folderview, guint action,
+                               GtkWidget *widget)
+{
+       FolderItem *item;
+       gchar *new_folder;
+       gchar *name;
+       gchar *message;
+
+       item = folderview_get_selected_item(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 newsgroup folder"), message, item->name);
+       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 (find_child_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;
+       }
+
+       if (folder_item_rename(item, new_folder) < 0) {
+               alertpanel_error(_("The folder could not be renamed.\n"
+                                  "The new folder name is not allowed."));
+               return;
+       }
+
+       folder_write_list();
+}
+
 static void update_tree_cb(FolderView *folderview, guint action,
                           GtkWidget *widget)
 {