[Commits] [SCM] claws branch, vfolder, updated. 3.10.1-117-gebaba4a

miras at claws-mail.org miras at claws-mail.org
Sun Jun 29 00:48:44 CEST 2014


The branch vfolder of project "claws" (Claws Mail) has been updated
       via  ebaba4a40b5ec52be13df267917f4065273cbbbf (commit)
      from  18a5319a744697acf42eb3966c169614ca368a6d (commit)

Summary of changes:
 src/plugins/vfolder/vfolder.c      |   65 +++++++++++++++++++++++++++---------
 src/plugins/vfolder/vfolder.h      |    2 ++
 src/plugins/vfolder/vfolder_gtk.c  |   53 ++++++++++++++++++++++-------
 src/plugins/vfolder/vfolder_prop.c |   11 ++++--
 4 files changed, 101 insertions(+), 30 deletions(-)


- Log -----------------------------------------------------------------
commit ebaba4a40b5ec52be13df267917f4065273cbbbf
Author: Michael Rasmussen <mir at datanom.net>
Date:   Sun Jun 29 00:48:22 2014 +0200

    VFolder now supports sub folders

diff --git a/src/plugins/vfolder/vfolder.c b/src/plugins/vfolder/vfolder.c
index 7eaa88e..48598b4 100644
--- a/src/plugins/vfolder/vfolder.c
+++ b/src/plugins/vfolder/vfolder.c
@@ -298,6 +298,8 @@ static void vfolder_item_destroy(Folder* folder, FolderItem* item) {
 		g_hash_table_remove(vfolders, vitem->source_id);
 		g_free(vitem->source_id);
 		vitem->source_id = NULL;
+	} else {
+		vfolder_msgvault_free(vitem->msgvault);
 	}
 
 	g_free(vitem->filter);
@@ -319,43 +321,42 @@ static gchar* vfolder_item_get_path(Folder* folder, FolderItem* item) {
 	return result;
 }
 
-static gint vfolder_folder_remove(Folder* folder, FolderItem* item) {
+static gint vfolder_remove_folder(FolderItem* item) {
 	GDir* dp;
 	const gchar* name;
 	gchar* cwd;
 	gint ret = -1;
 
-	cm_return_val_if_fail(folder != NULL, -1);
-	cm_return_val_if_fail(item != NULL, -1);
-	cm_return_val_if_fail(item->path != NULL, -1);
-	cm_return_val_if_fail(item->stype == F_NORMAL, -1);
+	cwd = g_get_current_dir();
 
 	debug_print("VFolder: removing folder item %s\n", item->path);
 
 	gchar* path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
 		VFOLDER_DIR, G_DIR_SEPARATOR_S, item->path, NULL);
-	remove_numbered_files(path, item->last_num - item->total_msgs + 1, item->last_num);
-
-	folder_item_remove(item);
-
-	cwd = g_get_current_dir();
 
 	if (change_dir(path) < 0 ) {
-		g_free(path);
 		return ret;
 	}
 
+	remove_numbered_files(path, item->last_num - item->total_msgs + 1, item->last_num);
+
 	if( (dp = g_dir_open(".", 0, NULL)) == NULL ) {
 		FILE_OP_ERROR(path, "g_dir_open");
 		change_dir(cwd);
 		g_free(cwd);
-		g_free(path);
 		return ret;
 	}
 
 	while ((name = g_dir_read_name(dp)) != NULL) {
-		debug_print("Removing: %s\n", name);
-		claws_unlink(name);
+		if (is_dir_exist(name)) {
+			gchar* child = g_strconcat(path, "/", name, NULL);
+			FolderItem* sub_item = folder_find_item_from_real_path(child);
+			vfolder_remove_folder(sub_item);
+			g_free(child);
+		} else {
+			debug_print("Removing: %s\n", name);
+			claws_unlink(name);
+		}
 	}
 
 	g_dir_close(dp);
@@ -369,10 +370,25 @@ static gint vfolder_folder_remove(Folder* folder, FolderItem* item) {
 	return ret;
 }
 
+static gint vfolder_folder_remove(Folder* folder, FolderItem* item) {
+	gint ret = 0;
+
+	cm_return_val_if_fail(folder != NULL, -1);
+	cm_return_val_if_fail(item != NULL, -1);
+	cm_return_val_if_fail(item->path != NULL, -1);
+	cm_return_val_if_fail(item->stype == F_NORMAL, -1);
+
+	ret = vfolder_remove_folder(item);
+	folder_item_remove(item);
+
+	return ret;
+}
+
 static FolderItem* vfolder_folder_create(Folder* folder,
 									   	 FolderItem* parent,
 									   	 const gchar* name) {
 	gchar* path = NULL;
+	gchar* parent_path = NULL;
 	FolderItem* newitem = NULL;
 
 	cm_return_val_if_fail(folder != NULL, NULL);
@@ -382,9 +398,14 @@ static FolderItem* vfolder_folder_create(Folder* folder,
 	if (parent->no_sub)
 		return NULL;
 
-	path = g_strconcat((parent->path != NULL) ? parent->path : "", name, NULL);
+	if (parent->path != NULL)
+		parent_path = g_strconcat(parent->path , "/", NULL);
+	else
+		parent_path = g_strdup("");
+
+	path = g_strconcat(parent_path, name, NULL);
+	g_free(parent_path);
 	newitem = folder_item_new(folder, name, path);
-	newitem->no_sub = TRUE;
 
 	folder_item_append(parent, newitem);
 	g_free(path);
@@ -1067,3 +1088,15 @@ void vfolder_source_folder_remove(VFolderItem* vitem) {
 		vfolder_folder_remove(FOLDER_ITEM(vitem)->folder, FOLDER_ITEM(vitem));
 	}
 }
+
+void vfolder_vfolders_change_key(VFolderItem* vitem, const gchar* key) {
+	gpointer old_key, value;
+
+	cm_return_if_fail(vitem != NULL);
+
+	if (g_hash_table_lookup_extended(vfolders, vitem->source_id, &old_key, &value)) {
+		g_hash_table_steal(vfolders, old_key);
+		g_free(old_key);
+		g_hash_table_replace(vfolders, g_strdup(key), value);
+	}
+}
diff --git a/src/plugins/vfolder/vfolder.h b/src/plugins/vfolder/vfolder.h
index 71c992f..5f897a4 100644
--- a/src/plugins/vfolder/vfolder.h
+++ b/src/plugins/vfolder/vfolder.h
@@ -93,6 +93,8 @@ gint vfolder_get_virtual_msg_num(VFolderItem* vitem, gint srcnum);
 gint vfolder_get_source_msg_num(VFolderItem* vitem, gint virtnum);
 void vfolder_set_last_num(Folder *folder, FolderItem *item);
 gboolean vfolder_msgvault_add(VFolderItem* vitem);
+void vfolder_vfolders_change_key(VFolderItem* vitem, const gchar* key);
+
 void vfolder_msgvault_free(MsgVault* data);
 MsgVault* vfolder_msgvault_new();
 gboolean vfolder_msgvault_serialize(VFolderItem* vitem, GKeyFile* config);
diff --git a/src/plugins/vfolder/vfolder_gtk.c b/src/plugins/vfolder/vfolder_gtk.c
index 7a51a76..9cdc646 100644
--- a/src/plugins/vfolder/vfolder_gtk.c
+++ b/src/plugins/vfolder/vfolder_gtk.c
@@ -114,7 +114,7 @@ static void vfolder_set_sensitivity(GtkUIManager *ui_manager, FolderItem *item)
 	SET_SENS("FolderViewPopup/RefreshAllFolders", folder_item_parent(item) == NULL);
 	SET_SENS("FolderViewPopup/FolderProperties", folder_item_parent(item) != NULL);
 	SET_SENS("FolderViewPopup/RenameFolder", folder_item_parent(item) != NULL);
-	SET_SENS("FolderViewPopup/NewFolder", folder_item_parent(item) != NULL && ! IS_VFOLDER_FOLDER_ITEM(item));
+	SET_SENS("FolderViewPopup/NewFolder", TRUE);
 	SET_SENS("FolderViewPopup/RemoveFolder", folder_item_parent(item) != NULL);
 
 #undef SET_SENS
@@ -473,25 +473,54 @@ void vfolder_new_folder_cb(GtkAction* action, gpointer data) {
 	FolderView *folderview = (FolderView *)data;
 	FolderItem *item;
 	VFolderItem* vitem = NULL;
+	gchar* new_folder;
+	gboolean not_empty_folder = TRUE;
 
     item = folderview_get_selected_item(folderview);
     if (item) {
-		FolderItem* parent = folder_item_parent(item);
-		if (! parent) {
-			alertpanel_error(_("%s: Is a root folder. You must choose a message folder like Inbox."),
-							 item->name);
-			return;
-		}
-		cm_return_if_fail(item->path != NULL);
-		cm_return_if_fail(item->folder != NULL);
+		if (IS_VFOLDER_FOLDER_ITEM(item)) {
+			new_folder = input_dialog(_("New virtual folder"),
+									  _("Input the name of the folder:"),
+									  _("Virtual Folder"));
+			if (!new_folder) return;
+			debug_print("Create VFolder: %s\n", new_folder);
+
+			// find whether the directory already exists
+			if (folder_find_child_item_by_name(item, new_folder)) {
+				alertpanel_error(_("The folder '%s' already exists."), new_folder);
+				g_free(new_folder);
+				return;
+			}
 
-		if (item->no_sub) {
+			vitem = VFOLDER_ITEM(folder_create_folder(item, new_folder));
+			if (!vitem) {
+				alertpanel_error(_("Can't create the folder '%s'."), new_folder);
+				g_free(new_folder);
+				return;
+			}
+			g_free(new_folder);
+			vitem->source_id = folder_item_get_identifier(FOLDER_ITEM(vitem));
+			vitem->changed = TRUE;
+			not_empty_folder = FALSE;
+			FolderPropsResponse resp = vfolder_folder_item_props_write(vitem);
+			vfolder_item_props_response(resp);
+		} else {
+			FolderItem* parent = folder_item_parent(item);
+			if (! parent) {
+				alertpanel_error(_("%s: Is a root folder. You must choose a message folder like Inbox."),
+								 item->name);
+				return;
+			}
+			cm_return_if_fail(item->path != NULL);
+			cm_return_if_fail(item->folder != NULL);
+		}
+/*		if (item->no_sub) {
 			alertpanel_error(N_("Virtual folders cannot contain subfolders"));
 			return;
-		}
+		}*/
 	}
 
-	if (! vfolder_edit_item_dialog(&vitem, item)) {
+	if (not_empty_folder && ! vfolder_edit_item_dialog(&vitem, item)) {
 		if (vitem) {
 			FOLDER_ITEM(vitem)->folder->klass->remove_folder(
 				FOLDER_ITEM(vitem)->folder, FOLDER_ITEM(vitem));
diff --git a/src/plugins/vfolder/vfolder_prop.c b/src/plugins/vfolder/vfolder_prop.c
index 57be81c..fcd19a7 100644
--- a/src/plugins/vfolder/vfolder_prop.c
+++ b/src/plugins/vfolder/vfolder_prop.c
@@ -352,6 +352,7 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 			gtk_entry_set_text(GTK_ENTRY(props_dialog->folder_name), name);
 			gtk_widget_set_sensitive(props_dialog->folder_name, FALSE);
 			g_free(name);
+			name = NULL;
 		}
 	}
 
@@ -487,11 +488,17 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 					ok = FALSE;
 					goto error;
 				}
-				if (vitem->source_id)
+				id = folder_item_get_identifier(vitem->source);
+				if (vitem->source_id) {
+					vfolder_vfolders_change_key(vitem, id);
 					g_free(vitem->source_id);
-				vitem->source_id = folder_item_get_identifier(vitem->source);
+				}
+				vitem->source_id = g_strdup(id);
+				g_free(id);
 				if (FOLDER_ITEM(vitem)->total_msgs > 0)
 					folder_item_remove_all_msg(FOLDER_ITEM(vitem));
+				if (! vitem->msg_filter_func)
+					vfolder_set_msgs_filter(vitem);
 				ok =  vfolder_create_msgs_list(vitem);
 				if (ok == FALSE) {
 					g_free(vitem->filter);

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list