[Commits] [SCM] claws branch, vfolder, updated. 3.10.1-113-gd28033a

miras at claws-mail.org miras at claws-mail.org
Mon Jun 23 00:52:55 CEST 2014


The branch vfolder of project "claws" (Claws Mail) has been updated
       via  d28033a73faaeeea87ed7befe9fcca19c38a727a (commit)
       via  a39a01587f110e9669d4f0cbd608296c16177f22 (commit)
      from  acda8d303a9c580e731957c18fef99e4c3d02b4b (commit)

Summary of changes:
 src/plugins/vfolder/vfolder.c      |    3 -
 src/plugins/vfolder/vfolder_gtk.c  |   59 +++++-----------
 src/plugins/vfolder/vfolder_prop.c |  133 +++++++++++++++++++++++++-----------
 src/plugins/vfolder/vfolder_prop.h |    3 +-
 4 files changed, 109 insertions(+), 89 deletions(-)


- Log -----------------------------------------------------------------
commit d28033a73faaeeea87ed7befe9fcca19c38a727a
Author: Michael Rasmussen <mir at datanom.net>
Date:   Mon Jun 23 00:52:31 2014 +0200

    Only use one dialog to crate new VFolders
    Added default button and set filter or foldername to default focus
    When enter is pressed in filter activate default widget (ok button)
    Align widgets and use all available space in vfolder create dialog

diff --git a/src/plugins/vfolder/vfolder.c b/src/plugins/vfolder/vfolder.c
index 3c4a9ee..937e1a1 100644
--- a/src/plugins/vfolder/vfolder.c
+++ b/src/plugins/vfolder/vfolder.c
@@ -712,9 +712,6 @@ FolderClass* vfolder_folder_get_class() {
 		vfolder_class.scan_required = vfolder_scan_required;
 
 		/* Message functions */
-/*
-		vfolder_class.copy_msgs = vfolder_copy_msgs;
-*/
 		vfolder_class.get_msginfo = vfolder_get_msginfo;
 		vfolder_class.fetch_msg = vfolder_fetch_msg;
 		vfolder_class.copy_msgs = NULL;
diff --git a/src/plugins/vfolder/vfolder_gtk.c b/src/plugins/vfolder/vfolder_gtk.c
index 300ef26..7a51a76 100644
--- a/src/plugins/vfolder/vfolder_gtk.c
+++ b/src/plugins/vfolder/vfolder_gtk.c
@@ -429,8 +429,9 @@ void vfolder_gtk_done(void) {
 }
 
 void vfolder_properties_cb(GtkAction* action, gpointer data) {
-	FolderView *folderview = (FolderView *)data;
-	FolderItem *item;
+	FolderView* folderview = (FolderView *)data;
+	FolderItem* item;
+	VFolderItem* vitem;
 
 	g_return_if_fail(folderview != NULL);
 
@@ -440,8 +441,9 @@ void vfolder_properties_cb(GtkAction* action, gpointer data) {
 	g_return_if_fail(item->path != NULL);
 	g_return_if_fail(item->folder != NULL);
 
-	if (vfolder_edit_item_dialog(VFOLDER_ITEM(item), NULL)) {
-		FolderPropsResponse resp = vfolder_folder_item_props_write(VFOLDER_ITEM(item));
+	vitem = VFOLDER_ITEM(item);
+	if (vfolder_edit_item_dialog(&vitem, NULL)) {
+		FolderPropsResponse resp = vfolder_folder_item_props_write(vitem);
 		vfolder_item_props_response(resp);
 	}
 }
@@ -469,10 +471,8 @@ void vfolder_rename_cb(GtkAction* action, gpointer data) {
 
 void vfolder_new_folder_cb(GtkAction* action, gpointer data) {
 	FolderView *folderview = (FolderView *)data;
-	FolderItem *item, *new_item, *parent;
-	gchar* new_folder;
-	gchar* name;
-	gchar* p;
+	FolderItem *item;
+	VFolderItem* vitem = NULL;
 
     item = folderview_get_selected_item(folderview);
     if (item) {
@@ -490,45 +490,18 @@ void vfolder_new_folder_cb(GtkAction* action, gpointer data) {
 			return;
 		}
 	}
-	new_folder = input_dialog(_("New virtual folder"),
-				  _("Input the name of the folder:"),
-				  _("Virtual Folder"));
-	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;});
-
-	Folder* folder = folder_find_from_name(VFOLDER_DEFAULT_MAILBOX, vfolder_folder_get_class());
-	parent = FOLDER_ITEM(folder->node->data);
-	/* find whether the directory already exists */
-	if (folder_find_child_item_by_name(parent, new_folder)) {
-		alertpanel_error(_("The folder '%s' already exists."), name);
-		return;
-	}
-
-	new_item = folder_create_folder(parent, new_folder);
-	if (!new_item) {
-		alertpanel_error(_("Can't create the folder '%s'."), name);
-		return;
-	}
 
-	if (! vfolder_create_item_dialog(VFOLDER_ITEM(new_item), item)) {
-		new_item->folder->klass->remove_folder(new_item->folder, new_item);
-		new_item = NULL;
+	if (! vfolder_edit_item_dialog(&vitem, item)) {
+		if (vitem) {
+			FOLDER_ITEM(vitem)->folder->klass->remove_folder(
+				FOLDER_ITEM(vitem)->folder, FOLDER_ITEM(vitem));
+		}
 		return;
 	}
 
-	if (vfolder_msgvault_add(VFOLDER_ITEM(new_item))) {
-		new_item->folder->klass->remove_folder(new_item->folder, new_item);
-		new_item = NULL;
+	if (vfolder_msgvault_add(vitem)) {
+		FOLDER_ITEM(vitem)->folder->klass->remove_folder(
+			FOLDER_ITEM(vitem)->folder, FOLDER_ITEM(vitem));
 		return;
 	}
 
diff --git a/src/plugins/vfolder/vfolder_prop.c b/src/plugins/vfolder/vfolder_prop.c
index 458334d..59c4f46 100644
--- a/src/plugins/vfolder/vfolder_prop.c
+++ b/src/plugins/vfolder/vfolder_prop.c
@@ -49,6 +49,7 @@
 #define BOTH	N_("_Both")
 
 typedef struct {
+	GtkWidget* folder_name;
 	GtkWidget* filter;
 	GtkWidget* frozen;
 	GtkWidget* source;
@@ -78,12 +79,6 @@ static void add_current_config(VFolderItem* item, PropsDialog* props) {
 	}
 }
 
-static gboolean is_source_widget(GtkWidget* widget) {
-	const gchar* name = gtk_widget_get_name(widget);
-
-	return (name && strcmp("source", name) == 0);
-}
-
 static void foldersel_cb(GtkWidget *widget, gpointer data) {
 	FolderItem *item;
 	gchar *item_id;
@@ -107,24 +102,34 @@ static void foldersel_cb(GtkWidget *widget, gpointer data) {
 	}
 }
 
+static gboolean vfolder_source_widget(GtkWidget* widget) {
+	const gchar* name = gtk_widget_get_name(widget);
+
+	return (name && strcmp("source", name) == 0);
+}
+
 static GtkWidget* vfolder_prop_row(GtkWidget* widget,
 								   const gchar* label_markup,
 								   gint width, gboolean center) {
 	GtkWidget* row = gtk_hbox_new(FALSE, 5);
-	GtkWidget* label = gtk_label_new(NULL);
+	GtkWidget* label = NULL;
+	GtkWidget* btn;
 
+	label = gtk_label_new_with_mnemonic(label_markup);
 	gtk_widget_set_size_request(label, width, -1);
-	gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), label_markup);
 	gtk_label_set_mnemonic_widget(GTK_LABEL(label), widget);
 	gtk_box_pack_start(GTK_BOX(row), label, FALSE, FALSE, 5);
-	gtk_box_pack_start(GTK_BOX(row), widget, TRUE, FALSE, 5);
+	gtk_box_pack_start(GTK_BOX(row), widget, FALSE, FALSE, 5);
 
-	if (is_source_widget(widget)) {
-		GtkWidget* btn = gtk_button_new_from_stock(GTK_STOCK_OPEN);
+	if (vfolder_source_widget(widget)) {
+		btn = gtk_button_new_from_stock(GTK_STOCK_OPEN);
 		g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(foldersel_cb), widget);
 		gtk_box_pack_start(GTK_BOX(row), btn, FALSE, FALSE, 5);
 	}
 
+	if (GTK_IS_ENTRY(widget))
+		gtk_widget_set_size_request(widget, 300, -1);
+
 	return row;
 }
 
@@ -266,20 +271,7 @@ void vfolder_set_msgs_filter(VFolderItem* vfolder_item) {
 	vfolder_item->msg_filter_func = vfolder_filter_msgs_list;
 }
 
-gboolean vfolder_create_item_dialog(VFolderItem* vitem, FolderItem* item) {
-	gboolean created = FALSE;
-
-	cm_return_val_if_fail(vitem != NULL, created);
-
-	vfolder_set_msgs_filter(vitem);
-
-	if (vfolder_edit_item_dialog(vitem, item))
-		created = TRUE;
-
-	return created;
-}
-
-gboolean vfolder_edit_item_dialog(VFolderItem* vitem, FolderItem* item) {
+gboolean vfolder_edit_item_dialog(VFolderItem** vitem_ptr, FolderItem* item) {
 	gboolean ok = FALSE;
 	PropsDialog* props_dialog;
 	GtkWidget* dialog;
@@ -293,16 +285,23 @@ gboolean vfolder_edit_item_dialog(VFolderItem* vitem, FolderItem* item) {
 	gchar* old_filter = NULL;
 	FolderItem* old_source;
 	gboolean update = TRUE;
+	VFolderItem* vitem;
+
+	cm_return_val_if_fail(vitem_ptr != NULL, ok);
 
-	cm_return_val_if_fail(vitem != NULL, ok);
+	vitem = *vitem_ptr;
 
 	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"));
 	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"));
 	props_dialog->frozen = gtk_check_button_new();
 	CLAWS_SET_TIP(props_dialog->frozen, _("Disable automatic update. Manual refresh is not affected"));
 	props_dialog->source = gtk_entry_new();
+	gtk_entry_set_activates_default(GTK_ENTRY(props_dialog->source), TRUE);
 	CLAWS_SET_TIP(props_dialog->source, _("Folder to watch"));
 	props_dialog->label_btn =
 		gtk_radio_button_new_with_mnemonic(NULL, HEADERS);
@@ -316,24 +315,27 @@ gboolean vfolder_edit_item_dialog(VFolderItem* vitem, 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");
-	add_current_config(vitem, props_dialog);
+
+	if (vitem)
+		add_current_config(vitem, props_dialog);
 
 	dialog = gtk_dialog_new_with_buttons(
 			N_("Edit VFolder Properties"),
 			GTK_WINDOW(mainwin->window),
 			GTK_DIALOG_DESTROY_WITH_PARENT,
-			GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
 			GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+			GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
 			NULL);
-	gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);
 	content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
 
 	GtkWidget* vbox = gtk_vbox_new(FALSE, 5);
 
-	row = vfolder_prop_row(props_dialog->source, N_("_Source folder"), 130, FALSE);
+	row = vfolder_prop_row(props_dialog->folder_name, _("VFolder _name"), 90, FALSE);
+	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);
 
-	if (item || vitem->source) {
+	if (item || (vitem && vitem->source)) {
 		if (!item)
 			id = folder_item_get_identifier(vitem->source);
 		else
@@ -343,34 +345,83 @@ gboolean vfolder_edit_item_dialog(VFolderItem* vitem, 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);
+		}
+	}
+
 	GtkWidget* frame1 = gtk_frame_new(_("Message filter"));
 	GtkWidget* vbox1 = gtk_vbox_new(TRUE, 2);
 	gtk_container_add(GTK_CONTAINER(frame1), vbox1);
 
-	row = vfolder_prop_row(props_dialog->filter, N_("_Filter"), 110, FALSE);
+	row = vfolder_prop_row(props_dialog->filter, _("Glob _filter"), 90, FALSE);
 	gtk_box_pack_start(GTK_BOX(vbox1), row, FALSE, FALSE, 5);
 
-	box = gtk_hbox_new(TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(box), props_dialog->label_btn, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(box), props_dialog->message_btn, TRUE, TRUE, 2);
-	gtk_box_pack_start(GTK_BOX(box), props_dialog->both_btn, TRUE, TRUE, 2);
+	box = gtk_hbox_new(FALSE, 20);
+	gtk_box_pack_start(GTK_BOX(box), props_dialog->label_btn, TRUE, TRUE, 5);
+	gtk_box_pack_start(GTK_BOX(box), props_dialog->message_btn, TRUE, TRUE, 5);
+	gtk_box_pack_start(GTK_BOX(box), props_dialog->both_btn, TRUE, TRUE, 5);
 	gtk_box_pack_start(GTK_BOX(vbox1), box, FALSE, FALSE, 5);
 
 	gtk_box_pack_start(GTK_BOX(vbox), frame1, FALSE, FALSE, 5);
 
-	row = vfolder_prop_row(props_dialog->frozen, N_("F_reeze content"), 110, TRUE);
+	row = vfolder_prop_row(props_dialog->frozen, _("F_reeze content"), 110, TRUE);
 	gtk_box_pack_start(GTK_BOX(vbox), row, FALSE, FALSE, 5);
 
-	name = g_strconcat(FOLDER_ITEM(vitem)->name, N_(": settings"), NULL);
-	GtkWidget* frame = gtk_frame_new(name);
-	g_free(name);
+	GtkWidget* frame = gtk_frame_new(_("settings"));
 	gtk_container_add(GTK_CONTAINER(frame), vbox);
 
 	gtk_container_add(GTK_CONTAINER(content), frame);
-	gtk_widget_show_all(content);
 
+	if (vitem)
+		gtk_widget_grab_focus(props_dialog->filter);
+	else
+		gtk_widget_grab_focus(props_dialog->folder_name);
+	GtkWidget* ok_btn = gtk_dialog_get_widget_for_response(
+					   GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+	gtk_widget_grab_default(ok_btn);
+
+	gtk_widget_show_all(content);
 	response = gtk_dialog_run(GTK_DIALOG(dialog));
+
 	if (response == GTK_RESPONSE_ACCEPT) {
+		str = gtk_entry_get_text(GTK_ENTRY(props_dialog->folder_name));
+		debug_print("VFolder name from dialog: %s\n", str);
+		if (! str) goto error;
+
+		name = NULL;
+		if (vitem)
+			name = folder_item_get_name(FOLDER_ITEM(vitem));
+		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);
+			/* find whether the directory already exists */
+			if (folder_find_child_item_by_name(parent, 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));
+				if (!vitem) {
+					alertpanel_error(_("Can't create the folder '%s'."), str);
+					goto error;
+				}
+				vfolder_set_msgs_filter(vitem);
+				*vitem_ptr = vitem;
+			} else {
+				debug_print("Rename VFolder to: %s\n", str);
+				folder_item_rename(FOLDER_ITEM(vitem), (gchar *) str);
+			}
+			g_free(name);
+		}
+
 		frozen = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(props_dialog->frozen));
 
 		str = gtk_entry_get_text(GTK_ENTRY(props_dialog->filter));
diff --git a/src/plugins/vfolder/vfolder_prop.h b/src/plugins/vfolder/vfolder_prop.h
index b081371..bb7917f 100644
--- a/src/plugins/vfolder/vfolder_prop.h
+++ b/src/plugins/vfolder/vfolder_prop.h
@@ -33,8 +33,7 @@ G_BEGIN_DECLS
 #include "vfolder.h"
 #include <gtk/gtk.h>
 
-gboolean vfolder_create_item_dialog(VFolderItem* vitem, FolderItem* item);
-gboolean vfolder_edit_item_dialog(VFolderItem* vitem, FolderItem* item);
+gboolean vfolder_edit_item_dialog(VFolderItem** vitem, FolderItem* item);
 void vfolder_set_msgs_filter(VFolderItem* vfolder_item);
 void vfolder_item_props_response(FolderPropsResponse resp);
 

commit a39a01587f110e9669d4f0cbd608296c16177f22
Author: Michael Rasmussen <mir at datanom.net>
Date:   Sun Jun 22 19:39:53 2014 +0200

    use function instead of manually add it

diff --git a/src/plugins/vfolder/vfolder_prop.c b/src/plugins/vfolder/vfolder_prop.c
index aa9cb79..458334d 100644
--- a/src/plugins/vfolder/vfolder_prop.c
+++ b/src/plugins/vfolder/vfolder_prop.c
@@ -271,7 +271,7 @@ gboolean vfolder_create_item_dialog(VFolderItem* vitem, FolderItem* item) {
 
 	cm_return_val_if_fail(vitem != NULL, created);
 
-	vitem->msg_filter_func = vfolder_filter_msgs_list;
+	vfolder_set_msgs_filter(vitem);
 
 	if (vfolder_edit_item_dialog(vitem, item))
 		created = TRUE;

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


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list