[Commits] [SCM] claws branch, vfolder, updated. 3.10.1-122-g5ff57b5

miras at claws-mail.org miras at claws-mail.org
Wed Jul 2 01:48:38 CEST 2014


The branch vfolder of project "claws" (Claws Mail) has been updated
       via  5ff57b539a48ebca1fad1c670ff7d9e72020c0ac (commit)
      from  ee0bb195aa5ebab7e079160599ec4114eea66a25 (commit)

Summary of changes:
 src/plugins/vfolder/vfolder.c      |    2 +
 src/plugins/vfolder/vfolder_gtk.c  |   50 ++++----------------
 src/plugins/vfolder/vfolder_prop.c |   92 ++++++++++++++++++++++++++----------
 3 files changed, 76 insertions(+), 68 deletions(-)


- Log -----------------------------------------------------------------
commit 5ff57b539a48ebca1fad1c670ff7d9e72020c0ac
Author: Michael Rasmussen <mir at datanom.net>
Date:   Wed Jul 2 01:48:30 2014 +0200

    Create new folder from context menu used old code if selected folder was VFolder. Allow user to create a new virtual folder as a subfolder under an existing virtual folder

diff --git a/src/plugins/vfolder/vfolder.c b/src/plugins/vfolder/vfolder.c
index 48598b4..5782a03 100644
--- a/src/plugins/vfolder/vfolder.c
+++ b/src/plugins/vfolder/vfolder.c
@@ -327,6 +327,8 @@ static gint vfolder_remove_folder(FolderItem* item) {
 	gchar* cwd;
 	gint ret = -1;
 
+	if (! item->path || strlen(item->path) < 1) return 0;
+
 	cwd = g_get_current_dir();
 
 	debug_print("VFolder: removing folder item %s\n", item->path);
diff --git a/src/plugins/vfolder/vfolder_gtk.c b/src/plugins/vfolder/vfolder_gtk.c
index 775298a..0d9abbb 100644
--- a/src/plugins/vfolder/vfolder_gtk.c
+++ b/src/plugins/vfolder/vfolder_gtk.c
@@ -473,54 +473,20 @@ 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) {
-		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;
-			}
-
-			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"));
+		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 (not_empty_folder && ! vfolder_edit_item_dialog(&vitem, item)) {
+	if (! 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 b7095e4..1cc56bb 100644
--- a/src/plugins/vfolder/vfolder_prop.c
+++ b/src/plugins/vfolder/vfolder_prop.c
@@ -49,15 +49,17 @@
 #define BOTH	N_("_Both")
 
 typedef struct {
-	GtkWidget* folder_name;
-	GtkWidget* filter;
-	GtkWidget* frozen;
-	GtkWidget* source;
-	GtkWidget* label_btn;
-	GtkWidget* message_btn;
-	GtkWidget* both_btn;
+	GtkWidget*	folder_name;
+	GtkWidget*	filter;
+	GtkWidget*	frozen;
+	GtkWidget*	source;
+	GtkWidget*	label_btn;
+	GtkWidget*	message_btn;
+	GtkWidget*	both_btn;
 } PropsDialog;
 
+static FolderItem* dest_folder = NULL;
+
 static void add_current_config(VFolderItem* item, PropsDialog* props) {
 	if (item->filter)
 		gtk_entry_set_text(GTK_ENTRY(props->filter), item->filter);
@@ -102,10 +104,20 @@ static void foldersel_cb(GtkWidget *widget, gpointer data) {
 	}
 }
 
-static gboolean vfolder_source_widget(GtkWidget* widget) {
-	const gchar* name = gtk_widget_get_name(widget);
+static void dest_foldersel_cb(GtkWidget *widget, gpointer data) {
+	FolderItem *item;
+
+	item = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
+	if (item && IS_VFOLDER_FOLDER_ITEM(item)) {
+		dest_folder = item;
+		debug_print("Destination Folder: %s\n", dest_folder->name);
+	}
+}
+
+static gboolean vfolder_is_widget(GtkWidget* widget, const gchar* name) {
+	const gchar* s = gtk_widget_get_name(widget);
 
-	return (name && strcmp("source", name) == 0);
+	return (s && strcmp(s, name) == 0);
 }
 
 static GtkWidget* vfolder_prop_row(GtkWidget* widget,
@@ -121,12 +133,20 @@ static GtkWidget* vfolder_prop_row(GtkWidget* widget,
 	gtk_box_pack_start(GTK_BOX(row), label, FALSE, FALSE, 5);
 	gtk_box_pack_start(GTK_BOX(row), widget, FALSE, FALSE, 5);
 
-	if (vfolder_source_widget(widget)) {
+	if (vfolder_is_widget(widget, "source")) {
 		btn = gtk_button_new_from_stock(GTK_STOCK_OPEN);
+		CLAWS_SET_TIP(btn, _("Choose source folder for VFolder"));
 		g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(foldersel_cb), widget);
 		gtk_box_pack_start(GTK_BOX(row), btn, FALSE, FALSE, 5);
 	}
 
+	if (vfolder_is_widget(widget, "name")) {
+		btn = gtk_button_new_from_stock(GTK_STOCK_HOME);
+		CLAWS_SET_TIP(btn, _("Choose parent folder for VFolder"));
+		g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(dest_foldersel_cb), NULL);
+		gtk_box_pack_start(GTK_BOX(row), btn, FALSE, FALSE, 5);
+	}
+
 	if (GTK_IS_ENTRY(widget))
 		gtk_widget_set_size_request(widget, 300, -1);
 
@@ -296,6 +316,14 @@ static gboolean vfolder_create_msgs_list(VFolderItem* item) {
 	return ok;
 }
 
+static void gtk_container_foreach_cb(GtkWidget* widget, gpointer data) {
+	cm_return_if_fail(widget != NULL);
+
+	if (GTK_IS_BUTTON(widget)) {
+		gtk_widget_set_sensitive(widget, FALSE);
+	}
+}
+
 void vfolder_set_msgs_filter(VFolderItem* vfolder_item) {
 	cm_return_if_fail(vfolder_item != NULL);
 
@@ -325,7 +353,10 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 	MainWindow *mainwin = mainwindow_get_mainwindow();
 	props_dialog = g_new0(PropsDialog, 1);
 	props_dialog->folder_name = gtk_entry_new();
-	CLAWS_SET_TIP(props_dialog->folder_name, _("Name for VFolder"));
+	CLAWS_SET_TIP(props_dialog->folder_name, _("Name for VFolder.\n"
+											   "Unless home is selected\n"
+											   "the virtual folder will be create\n"
+											   "as child of 'VFolder'."));
 	props_dialog->filter = gtk_entry_new();
 	gtk_entry_set_activates_default(GTK_ENTRY(props_dialog->filter), TRUE);
 	CLAWS_SET_TIP(props_dialog->filter, _("Glob filter. '*' or '?' for wildcard.\n"
@@ -349,6 +380,7 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 			GTK_RADIO_BUTTON(props_dialog->label_btn), BOTH);
 	CLAWS_SET_TIP(props_dialog->both_btn, _("Scan both message headers and message body"));
 	gtk_widget_set_name(props_dialog->source, "source");
+	gtk_widget_set_name(props_dialog->folder_name, "name");
 
 	if (vitem)
 		add_current_config(vitem, props_dialog);
@@ -365,7 +397,22 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 	GtkWidget* vbox = gtk_vbox_new(FALSE, 5);
 
 	row = vfolder_prop_row(props_dialog->folder_name, _("VFolder _name"), 90, FALSE);
+	if (vitem) {
+		name = folder_item_get_name(FOLDER_ITEM(vitem));
+		if (name) {
+			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;
+		}
+	}
+
+	if ((item && IS_VFOLDER_FOLDER_ITEM(item)) ||
+		strlen(gtk_entry_get_text(GTK_ENTRY(props_dialog->folder_name))) > 0)
+		gtk_container_foreach(GTK_CONTAINER(row), gtk_container_foreach_cb, NULL);
+
 	gtk_box_pack_start(GTK_BOX(vbox), row, FALSE, FALSE, 5);
+
 	row = vfolder_prop_row(props_dialog->source, _("_Source folder"), 90, FALSE);
 	gtk_box_pack_start(GTK_BOX(vbox), row, FALSE, FALSE, 5);
 
@@ -379,16 +426,6 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 		g_free(id);
 	}
 
-	if (vitem) {
-		name = folder_item_get_name(FOLDER_ITEM(vitem));
-		if (name) {
-			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;
-		}
-	}
-
 	GtkWidget* frame1 = gtk_frame_new(_("Message filter"));
 	GtkWidget* vbox1 = gtk_vbox_new(TRUE, 2);
 	gtk_container_add(GTK_CONTAINER(frame1), vbox1);
@@ -434,16 +471,18 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 		debug_print("VFolder name from VFolder: %s\n", name ? name : "NULL");
 
 		if (! name || g_utf8_collate(name, str)) {
-			Folder* folder = folder_find_from_name(VFOLDER_DEFAULT_MAILBOX, vfolder_folder_get_class());
-			FolderItem* parent = FOLDER_ITEM(folder->node->data);
+			if (! dest_folder) {
+				Folder* folder = folder_find_from_name(VFOLDER_DEFAULT_MAILBOX, vfolder_folder_get_class());
+				dest_folder = FOLDER_ITEM(folder->node->data);
+			}
 			/* find whether the directory already exists */
-			if (folder_find_child_item_by_name(parent, str)) {
+			if (folder_find_child_item_by_name(dest_folder, str)) {
 				alertpanel_error(_("The folder '%s' already exists."), str);
 				goto error;
 			}
 			if (! vitem) {
 				debug_print("Create VFolder: %s\n", str);
-				vitem = VFOLDER_ITEM(folder_create_folder(parent, str));
+				vitem = VFOLDER_ITEM(folder_create_folder(dest_folder, str));
 				if (!vitem) {
 					alertpanel_error(_("Can't create the folder '%s'."), str);
 					goto error;
@@ -555,6 +594,7 @@ gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 	}
 
 error:
+	dest_folder = NULL;
 	gtk_widget_destroy(dialog);
 	g_free(props_dialog);
 	g_free(old_filter);

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


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list