Re: Some fixes
- From: Sergio Villar Senin <svillar igalia com>
- To: tinymail-devel-list gnome org
- Subject: Re: Some fixes
- Date: Thu, 15 Mar 2007 15:55:16 +0100
Sergio Villar Senin wrote:
> Hi,
>
> playing with folder copies I noticed that tinymail was not notifying the
> UI about the deleted folder, I added the needed coded to the
> TnyCamelFolder. The folder store used to create the change object was
> also wrong.
>
> I changed also a little bit the deleter method of
> TnyGtkFolderStoreTreeModel, this method was the responsible of finding
> and deleting the removed folder. The problem was that it was always
> returning FALSE, so even if you already deleted the folder the
> gtk_tree_model_foreach would try to continue, but it wouldn't be able to
> because the iter returned by gtk_tree_store_remove is invalid.
Second version of the patch. And... a present for Philip :-), a new
functional test to check folder transfers.
Br
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c (revision 1721)
+++ libtinymail-camel/tny-camel-folder.c (working copy)
@@ -1419,6 +1422,7 @@
CamelFolderInfo *iter;
gchar *final_name;
TnyFolderStoreChange *change;
+ TnyFolderStore *old_parent;
if (!_tny_session_check_operation (TNY_FOLDER_PRIV_GET_SESSION(priv), err,
TNY_FOLDER_ERROR, TNY_FOLDER_ERROR_COPY))
@@ -1575,19 +1579,48 @@
goto exception;
}
- retval = _tny_camel_folder_new ();
- fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (retval);
+ old_parent = tny_folder_get_folder_store (self);
+ if (tostore == fromstore && del) {
+ retval = self;
+
+ /* No need to notify the folder if there was not an
+ actual change in the short (visual) name */
+ if (strcmp (tny_folder_get_name (self), new_name)) {
+ TnyFolderChange *change;
+
+ change = tny_folder_change_new (self);
+ tny_folder_change_set_rename (change, new_name);
+ notify_folder_observers_about (self, change);
+ g_object_unref (G_OBJECT (change));
+ }
+ } else {
+ retval = _tny_camel_folder_new ();
+
+ fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (retval);
+ camel_object_ref (CAMEL_OBJECT (tostore));
+ fpriv->store = tostore;
+ }
+
+ /* Notify the deletion before the addition because otherwise
+ we could delete the recently created folder instead of the
+ old one. */
+ if (del) {
+ TnyFolderStoreChange *change = tny_folder_store_change_new (old_parent);
+ tny_folder_store_change_add_removed_folder (change, self);
+ notify_folder_store_observers_about (old_parent, change);
+ g_object_unref (G_OBJECT (change));
+ }
+
_tny_camel_folder_set_folder_info (into, TNY_CAMEL_FOLDER (retval), iter);
- camel_object_ref (CAMEL_OBJECT (tostore));
- fpriv->store = tostore;
- _tny_camel_folder_set_parent (TNY_CAMEL_FOLDER (retval), into);
- change = tny_folder_store_change_new (TNY_FOLDER_STORE (self));
+ /* Notify addition */
+ change = tny_folder_store_change_new (into);
tny_folder_store_change_add_created_folder (change, retval);
- notify_folder_store_observers_about (TNY_FOLDER_STORE (self), change);
+ notify_folder_store_observers_about (into, change);
g_object_unref (G_OBJECT (change));
+ g_object_unref (G_OBJECT (old_parent));
camel_object_unref (CAMEL_OBJECT (tostore));
camel_object_unref (CAMEL_OBJECT (fromstore));
Index: libtinymailui-gtk/tny-gtk-folder-store-tree-model.c
===================================================================
--- libtinymailui-gtk/tny-gtk-folder-store-tree-model.c (revision 1729)
+++ libtinymailui-gtk/tny-gtk-folder-store-tree-model.c (working copy)
@@ -599,6 +599,7 @@
static gboolean
deleter (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data1)
{
+ gboolean retval = FALSE;
gint type;
GObject *folder = user_data1;
@@ -614,13 +615,15 @@
TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
&fol, -1);
- if (fol == folder)
+ if (fol == folder) {
gtk_tree_store_remove (GTK_TREE_STORE (model), iter);
+ retval = TRUE;
+ }
g_object_unref (G_OBJECT (fol));
}
- return FALSE;
+ return retval;
}
Index: tests/functional/Makefile.am
===================================================================
--- tests/functional/Makefile.am (revision 1721)
+++ tests/functional/Makefile.am (working copy)
@@ -15,7 +15,7 @@
INCLUDES += -DMOZEMBED
endif
-bin_PROGRAMS = folder-lister folder-lister-async msg-transfer msg-sender anything
+bin_PROGRAMS = folder-lister folder-lister-async msg-transfer msg-sender anything folder-transfer
anything_SOURCES = anything.c
anything_LDADD = \
@@ -61,3 +61,12 @@
$(top_builddir)/libtinymailui-gtk/libtinymailui-gtk-$(API_VERSION).la \
$(top_builddir)/libtinymail-camel/libtinymail-camel-$(API_VERSION).la \
$(top_builddir)/tests/shared/libtestsshared.a
+
+folder_transfer_SOURCES = folder-transfer.c
+folder_transfer_LDADD = \
+ $(TINYMAIL_LIBS) $(LIBTINYMAIL_GNOME_DESKTOP_LIBS) \
+ $(top_builddir)/libtinymail/libtinymail-$(API_VERSION).la \
+ $(top_builddir)/libtinymailui/libtinymailui-$(API_VERSION).la \
+ $(top_builddir)/libtinymailui-gtk/libtinymailui-gtk-$(API_VERSION).la \
+ $(top_builddir)/libtinymail-camel/libtinymail-camel-$(API_VERSION).la \
+ $(top_builddir)/tests/shared/libtestsshared.a
Index: tests/functional/folder-transfer.c
===================================================================
--- tests/functional/folder-transfer.c (revision 0)
+++ tests/functional/folder-transfer.c (revision 0)
@@ -0,0 +1,164 @@
+/* tinymail - Tiny Mail
+ * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof gnome org>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with self program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+
+#include <tny-list.h>
+#include <tny-iterator.h>
+#include <tny-simple-list.h>
+#include <tny-account-store.h>
+#include <tny-store-account.h>
+#include <tny-folder.h>
+#include <tny-folder-store.h>
+#include <tny-folder-store-query.h>
+
+#include <account-store.h>
+
+static gchar *cachedir=NULL;
+static gboolean online=FALSE;
+static gboolean move=FALSE;
+static const gchar *src_name = NULL;
+static const gchar *dst_name = NULL;
+static TnyFolder *src_folder = NULL;
+static TnyFolder *dst_folder = NULL;
+static gint recursion_level=0;
+
+static const GOptionEntry options[] = {
+ { "from", 'f', 0, G_OPTION_ARG_STRING, &src_name,
+ "Source folder", NULL},
+ { "to", 't', 0, G_OPTION_ARG_STRING, &dst_name,
+ "Destination folder", NULL},
+ { "cachedir", 'c', 0, G_OPTION_ARG_STRING, &cachedir,
+ "Cache directory", NULL },
+ { "online", 'o', 0, G_OPTION_ARG_NONE, &online,
+ "Online or offline", NULL },
+ { "move", 'm', 0, G_OPTION_ARG_NONE, &move,
+ "Move the messages instead of copy them", NULL },
+ { NULL }
+};
+
+static void
+recurse_folders (TnyFolderStore *store, TnyFolderStoreQuery *query)
+{
+ TnyIterator *iter;
+ TnyList *folders = tny_simple_list_new ();
+
+ tny_folder_store_get_folders (store, folders, query, NULL);
+ iter = tny_list_create_iterator (folders);
+
+ while (!tny_iterator_is_done (iter))
+ {
+ TnyFolderStore *folder = (TnyFolderStore*) tny_iterator_get_current (iter);
+ gint i=0;
+ const gchar *folder_name = NULL;
+
+ for (i=0; i<recursion_level; i++)
+ g_print ("\t");
+
+ folder_name = tny_folder_get_name (TNY_FOLDER (folder));
+ g_print ("%s\n", folder_name);
+
+ if (!strcmp (folder_name, src_name))
+ src_folder = g_object_ref (folder);
+
+ if (!strcmp (folder_name, dst_name))
+ dst_folder = g_object_ref (folder);
+
+ recursion_level++;
+ recurse_folders (folder, query);
+ recursion_level--;
+
+ g_object_unref (G_OBJECT (folder));
+
+ tny_iterator_next (iter);
+ }
+
+ g_object_unref (G_OBJECT (iter));
+ g_object_unref (G_OBJECT (folders));
+}
+
+int
+main (int argc, char **argv)
+{
+ GOptionContext *context;
+ TnyAccountStore *account_store;
+ TnyList *accounts;
+ TnyFolderStoreQuery *query;
+ TnyStoreAccount *account;
+ TnyIterator *iter;
+ gint i;
+ GError *err = NULL;
+
+ free (malloc (10));
+
+ g_type_init ();
+
+ context = g_option_context_new ("- The tinymail functional tester");
+ g_option_context_add_main_entries (context, options, "tinymail");
+ g_option_context_parse (context, &argc, &argv, NULL);
+
+ account_store = tny_test_account_store_new (online, cachedir);
+
+ if (cachedir)
+ g_print ("Using %s as cache directory\n", cachedir);
+
+ g_option_context_free (context);
+ accounts = tny_simple_list_new ();
+
+ tny_account_store_get_accounts (account_store, accounts,
+ TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+ g_object_unref (G_OBJECT (account_store));
+ iter = tny_list_create_iterator (accounts);
+ account = (TnyStoreAccount*) tny_iterator_get_current (iter);
+
+ recursion_level = 0;
+ for (i=0; i<1; i++)
+ recurse_folders (TNY_FOLDER_STORE (account), NULL);
+
+ /* Test 1 */
+ if (!(src_folder && dst_folder)) {
+ g_message ("Folders not found");
+ goto cleanup;
+ }
+
+ g_print ("%s folder %s to %s\n",
+ (move) ? "Moving" : "Copying",
+ tny_folder_get_name (src_folder),
+ tny_folder_get_name (dst_folder));
+
+ tny_folder_copy (src_folder,
+ TNY_FOLDER_STORE (dst_folder),
+ tny_folder_get_name (src_folder),
+ move,
+ &err);
+
+ if (err)
+ g_warning ("%s", err->message);
+
+ for (i=0; i<1; i++)
+ recurse_folders (TNY_FOLDER_STORE (account), NULL);
+
+ cleanup:
+ g_object_unref (G_OBJECT (account));
+ g_object_unref (G_OBJECT (iter));
+ g_object_unref (G_OBJECT (accounts));
+
+ return 0;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]