Re: Creating folders



Philip Van Hoof wrote:
> ps. I committed this for you
> 
I found that my patch had a bug, it used the folder short name in order
to set the subscription, but the full_name is required for that
operation. Now it's fixed.

I have just also added a new signal to TnyStoreAccount as you suggested,
called subscription_changed that is issued whenever the subscription
state of a folder changes.

Comments?

Br.
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c	(revision 1197)
+++ libtinymail-camel/tny-camel-folder.c	(working copy)
@@ -1112,6 +1112,10 @@
 	CamelFolder *retval = NULL;
 
 	/* g_mutex_lock (priv->folder_lock); */
+	if (G_UNLIKELY (!priv->loaded))
+		if (!load_folder (priv))
+			return NULL;
+	
 	retval = priv->folder;
 	if (retval)
 		camel_object_ref (CAMEL_OBJECT (retval));
@@ -1361,6 +1365,7 @@
 	}
 
 	tny_camel_folder_set_folder_info (self, TNY_CAMEL_FOLDER (folder), info);
+	_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), FALSE);
 
 	return folder;
 }
Index: libtinymail-camel/tny-camel-store-account.c
===================================================================
--- libtinymail-camel/tny-camel-store-account.c	(revision 1197)
+++ libtinymail-camel/tny-camel-store-account.c	(working copy)
@@ -171,6 +171,8 @@
 	TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
 	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
 	CamelStore *store;
+	CamelFolder *cfolder;
+	const gchar *folder_full_name;
 
 	g_assert (TNY_IS_CAMEL_FOLDER (folder));
 
@@ -179,15 +181,31 @@
 			apriv->url_string, &ex);
 	g_static_rec_mutex_unlock (apriv->service_lock);
 
+	/* Retrieve the folder full name */
+	cfolder = tny_camel_folder_get_folder (TNY_CAMEL_FOLDER (folder));
+	folder_full_name = camel_folder_get_full_name (cfolder);
+
 	if (camel_store_supports_subscriptions (store)
-	    && !camel_store_folder_subscribed (store, tny_folder_get_name (folder))) {
+	    && !camel_store_folder_subscribed (store, folder_full_name)) {
 		
-		camel_store_subscribe_folder (store, tny_folder_get_name (folder), &ex);
+		camel_store_subscribe_folder (store, folder_full_name, &ex);
 
-		/* Sync */
-		_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), TRUE);
+		if (camel_exception_is_set (&ex)) {
+			g_warning (N_("Could not subscribe to folder %s: %s\n"),
+				   tny_folder_get_name (folder), 
+				   camel_exception_get_description (&ex));
+			camel_exception_clear (&ex);
+		} else {
+			/* Sync */
+			_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), TRUE);
+
+			g_signal_emit (self, 
+				       tny_store_account_signals [TNY_STORE_ACCOUNT_SUBSCRIPTION_CHANGED], 
+				       0, folder);
+		}
 	}
 
+	camel_object_unref (CAMEL_OBJECT (cfolder));
     	camel_object_unref (CAMEL_OBJECT (store));
     
 	return;
@@ -209,9 +227,20 @@
 
 	camel_store_unsubscribe_folder (store, tny_folder_get_name (folder), &ex);
 
-	/* Sync */
-	_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), FALSE);
+	if (camel_exception_is_set (&ex)) {
+		g_warning (N_("Could not unsubscribe to folder %s: %s\n"),
+			   tny_folder_get_name (folder), 
+			   camel_exception_get_description (&ex));
+		camel_exception_clear (&ex);
+	} else {
+		/* Sync */
+		_tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), FALSE);
 
+		g_signal_emit (self, 
+			       tny_store_account_signals [TNY_STORE_ACCOUNT_SUBSCRIPTION_CHANGED], 
+			       0, folder);
+	}
+
 	camel_object_unref (CAMEL_OBJECT (store));
 
 	return;
Index: libtinymail/tny-folder.c
===================================================================
--- libtinymail/tny-folder.c	(revision 1197)
+++ libtinymail/tny-folder.c	(working copy)
@@ -565,6 +565,8 @@
 		};
 		type = g_type_register_static (G_TYPE_INTERFACE, 
 			"TnyFolder", &info, 0);
+
+		g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
 	}
 
 	return type;
Index: libtinymail/tny-store-account.c
===================================================================
--- libtinymail/tny-store-account.c	(revision 1197)
+++ libtinymail/tny-store-account.c	(working copy)
@@ -22,7 +22,7 @@
 #include <tny-store-account.h>
 #include <tny-folder-store.h>
 
-
+guint tny_store_account_signals [TNY_STORE_ACCOUNT_LAST_SIGNAL];
 /**
  * tny_store_account_unsubscribe:
  * @self: a #TnyStoreAccount object
@@ -74,7 +74,24 @@
 	static gboolean initialized = FALSE;
 
 	if (!initialized) {
-		/* create interface signals here. */
+		/**
+		 * TnyStoreAccount::subscription-changed
+		 * @self: the object on which the signal is emitted
+		 * @arg1: the #TnyFolder of the folder whose subscription has changed
+		 * @user_data: user data set when the signal handler was connected
+		 *
+		 * Emitted when the subscription of a folder change
+		 */
+		tny_store_account_signals[TNY_STORE_ACCOUNT_SUBSCRIPTION_CHANGED] =
+			g_signal_new ("subscription_changed",
+				      TNY_TYPE_STORE_ACCOUNT,
+				      G_SIGNAL_RUN_FIRST,
+				      G_STRUCT_OFFSET (TnyStoreAccountIface, subscription_changed),
+				      NULL, NULL,
+				      g_cclosure_marshal_VOID__POINTER,
+				      G_TYPE_NONE, 1, TNY_TYPE_FOLDER);
+
+
 		initialized = TRUE;
 	}
 }
Index: libtinymail/tny-store-account.h
===================================================================
--- libtinymail/tny-store-account.h	(revision 1197)
+++ libtinymail/tny-store-account.h	(working copy)
@@ -35,6 +35,14 @@
 #define TNY_IS_STORE_ACCOUNT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TNY_TYPE_STORE_ACCOUNT))
 #define TNY_STORE_ACCOUNT_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), TNY_TYPE_STORE_ACCOUNT, TnyStoreAccountIface))
 
+enum _TnyStoreAccountSignal
+{
+	TNY_STORE_ACCOUNT_SUBSCRIPTION_CHANGED,
+	TNY_STORE_ACCOUNT_LAST_SIGNAL
+};
+
+extern guint tny_store_account_signals [TNY_STORE_ACCOUNT_LAST_SIGNAL];
+
 #ifndef TNY_SHARED_H
 typedef struct _TnyStoreAccount TnyStoreAccount;
 typedef struct _TnyStoreAccountIface TnyStoreAccountIface;
@@ -44,6 +52,10 @@
 {
 	GTypeInterface parent;
 
+	/* Signals */
+	void (*subscription_changed) (TnyStoreAccount *self, TnyFolder *folder);
+
+	/* Methods */
 	void (*subscribe_func) (TnyStoreAccount *self, TnyFolder *folder);
 	void (*unsubscribe_func) (TnyStoreAccount *self, TnyFolder *folder);
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]