Re: Adding tny_folder_get_folder_store and some other minor things
- From: Sergio Villar Senin <svillar igalia com>
- To: tinymail-devel-list gnome org
- Subject: Re: Adding tny_folder_get_folder_store and some other minor things
- Date: Thu, 15 Feb 2007 18:34:32 +0100
After the very stupid first implementation of get_folder_store feature
here it comes the second version. Note that I changed the
set_folder_info visibility because I think with some slightly changes we
could remove most of the "protected" methods of TnyCamelFolder.
Br
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c (revisión: 1640)
+++ libtinymail-camel/tny-camel-folder.c (copia de trabajo)
@@ -1322,7 +1322,27 @@
return priv->folder_name;
}
+void
+_tny_camel_folder_set_folder_info (TnyFolderStore *self, TnyCamelFolder *folder, CamelFolderInfo *info)
+{
+ _tny_camel_folder_set_id (folder, info->full_name);
+ _tny_camel_folder_set_folder_type (folder, info);
+ _tny_camel_folder_set_unread_count (folder, info->unread);
+ _tny_camel_folder_set_all_count (folder, info->total);
+ _tny_camel_folder_set_name (folder, info->name);
+ _tny_camel_folder_set_iter (folder, info);
+ if (TNY_IS_CAMEL_STORE_ACCOUNT (self))
+ {
+ TnyCamelStoreAccountPriv *apriv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (self);
+ apriv->managed_folders = g_list_prepend (apriv->managed_folders, folder);
+ _tny_camel_folder_set_account (folder, TNY_ACCOUNT (self));
+ } else if (TNY_IS_CAMEL_FOLDER (self)) {
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+ _tny_camel_folder_set_account (folder, priv->account);
+ }
+ _tny_camel_folder_set_parent (folder, self);
+}
static TnyFolder*
tny_camel_folder_copy (TnyFolder *self, TnyFolderStore *into, const gchar *new_name, gboolean del, GError **err)
@@ -1510,13 +1530,8 @@
retval = _tny_camel_folder_new ();
fpriv = TNY_CAMEL_FOLDER_GET_PRIVATE (retval);
- _tny_camel_folder_set_id (TNY_CAMEL_FOLDER (retval), iter->full_name);
- _tny_camel_folder_set_folder_type (TNY_CAMEL_FOLDER (retval), iter);
- _tny_camel_folder_set_unread_count (TNY_CAMEL_FOLDER (retval), iter->unread);
- _tny_camel_folder_set_all_count (TNY_CAMEL_FOLDER (retval), iter->total);
- _tny_camel_folder_set_name (TNY_CAMEL_FOLDER (retval), iter->name);
- _tny_camel_folder_set_iter (TNY_CAMEL_FOLDER (retval), iter);
- _tny_camel_folder_set_account (TNY_CAMEL_FOLDER (retval), acc);
+ _tny_camel_folder_set_folder_info (into, TNY_CAMEL_FOLDER (retval), iter);
+
camel_object_ref (CAMEL_OBJECT (tostore));
fpriv->store = tostore;
@@ -2044,27 +2059,6 @@
return;
}
-static void
-tny_camel_folder_set_folder_info (TnyFolderStore *self, TnyCamelFolder *folder, CamelFolderInfo *info)
-{
- TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
-
- _tny_camel_folder_set_id (folder, info->full_name);
- _tny_camel_folder_set_folder_type (folder, info);
- _tny_camel_folder_set_unread_count (folder, info->unread);
- _tny_camel_folder_set_all_count (folder, info->total);
- _tny_camel_folder_set_name (folder, info->name);
- _tny_camel_folder_set_iter (folder, info);
-
- if (TNY_IS_CAMEL_STORE_ACCOUNT (priv->account))
- {
- TnyCamelStoreAccountPriv *apriv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (priv->account);
- apriv->managed_folders = g_list_prepend (apriv->managed_folders, folder);
- }
-
- _tny_camel_folder_set_account (folder, priv->account);
-}
-
static TnyFolder*
tny_camel_folder_create_folder (TnyFolderStore *self, const gchar *name, GError **err)
{
@@ -2078,7 +2072,8 @@
TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
CamelException ex = CAMEL_EXCEPTION_INITIALISER;
CamelStore *store; gchar *folname;
- TnyFolder *folder; CamelFolderInfo *info;
+ TnyFolder *folder;
+ CamelFolderInfo *info;
if (!_tny_session_check_operation (TNY_FOLDER_PRIV_GET_SESSION(priv), err,
TNY_FOLDER_STORE_ERROR, TNY_FOLDER_STORE_ERROR_CREATE_FOLDER))
@@ -2131,8 +2126,7 @@
}
folder = _tny_camel_folder_new ();
- tny_camel_folder_set_folder_info (self, TNY_CAMEL_FOLDER (folder), info);
- _tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), FALSE);
+ _tny_camel_folder_set_folder_info (self, TNY_CAMEL_FOLDER (folder), info);
_tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv));
@@ -2140,6 +2134,19 @@
}
+void
+_tny_camel_folder_set_parent (TnyCamelFolder *self, TnyFolderStore *parent)
+{
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+
+ if (priv->parent)
+ g_object_unref (G_OBJECT (priv->parent));
+
+ priv->parent = g_object_ref (G_OBJECT (parent));
+
+ return;
+}
+
void
_tny_camel_folder_set_folder_type (TnyCamelFolder *folder, CamelFolderInfo *folder_info)
{
@@ -2236,10 +2243,7 @@
TnyCamelFolder *folder = _tny_camel_store_account_folder_factory_get_folder (apriv, iter->full_name, &was_new);
if (was_new)
- {
- tny_camel_folder_set_folder_info (self, folder, iter);
- apriv->managed_folders = g_list_prepend (apriv->managed_folders, folder);
- }
+ _tny_camel_folder_set_folder_info (self, folder, iter);
tny_list_prepend (list, G_OBJECT (folder));
g_object_unref (G_OBJECT (folder));
@@ -2538,8 +2542,24 @@
return;
}
+static TnyFolderStore*
+tny_camel_folder_get_folder_store (TnyFolder *self)
+{
+ return TNY_CAMEL_FOLDER_GET_CLASS (self)->get_folder_store_func (self);
+}
+static TnyFolderStore*
+tny_camel_folder_get_folder_store_default (TnyFolder *self)
+{
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+ if (priv->parent)
+ g_object_ref (priv->parent);
+
+ return priv->parent;
+}
+
+
static void
tny_camel_folder_store_add_observer (TnyFolderStore *self, TnyFolderStoreObserver *observer)
{
@@ -2641,6 +2661,10 @@
g_object_unref (G_OBJECT (priv->receive_strat));
priv->receive_strat = NULL;
+ if (G_LIKELY (priv->parent))
+ g_object_unref (G_OBJECT (priv->parent));
+ priv->parent = NULL;
+
g_mutex_unlock (priv->folder_lock);
g_mutex_free (priv->folder_lock);
@@ -2685,6 +2709,7 @@
klass->poke_status_func = tny_camel_folder_poke_status;
klass->add_observer_func = tny_camel_folder_add_observer;
klass->remove_observer_func = tny_camel_folder_remove_observer;
+ klass->get_folder_store_func = tny_camel_folder_get_folder_store;
return;
}
@@ -2740,6 +2765,7 @@
class->poke_status_func = tny_camel_folder_poke_status_default;
class->add_observer_func = tny_camel_folder_add_observer_default;
class->remove_observer_func = tny_camel_folder_remove_observer_default;
+ class->get_folder_store_func = tny_camel_folder_get_folder_store_default;
class->get_folders_async_func = tny_camel_folder_get_folders_async_default;
class->get_folders_func = tny_camel_folder_get_folders_default;
Index: libtinymail-camel/tny-camel-folder.h
===================================================================
--- libtinymail-camel/tny-camel-folder.h (revisión: 1640)
+++ libtinymail-camel/tny-camel-folder.h (copia de trabajo)
@@ -84,6 +84,7 @@
void (*get_folders_func) (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err);
void (*remove_folder_func) (TnyFolderStore *self, TnyFolder *folder, GError **err);
TnyFolder* (*create_folder_func) (TnyFolderStore *self, const gchar *name, GError **err);
+ TnyFolderStore* (*get_folder_store_func) (TnyFolder *self);
void (*add_store_observer_func) (TnyFolderStore *self, TnyFolderStoreObserver *observer);
void (*remove_store_observer_func) (TnyFolderStore *self, TnyFolderStoreObserver *observer);
Index: libtinymail-camel/tny-camel-store-account.c
===================================================================
--- libtinymail-camel/tny-camel-store-account.c (revisión: 1640)
+++ libtinymail-camel/tny-camel-store-account.c (copia de trabajo)
@@ -524,6 +524,7 @@
folder = _tny_camel_folder_new ();
_tny_camel_folder_set_id (TNY_CAMEL_FOLDER (folder), info->full_name);
+ _tny_camel_folder_set_parent (TNY_CAMEL_FOLDER (folder), self);
camel_store_free_folder_info (store, info);
camel_object_unref (CAMEL_OBJECT (store));
@@ -650,16 +651,7 @@
TnyCamelFolder *folder = _tny_camel_store_account_folder_factory_get_folder (priv, iter->full_name, &was_new);
if (was_new)
- {
- _tny_camel_folder_set_id (folder, iter->full_name);
- _tny_camel_folder_set_folder_type (folder, iter);
- _tny_camel_folder_set_unread_count (folder, iter->unread);
- _tny_camel_folder_set_all_count (folder, iter->total);
- _tny_camel_folder_set_name (folder, iter->name);
- _tny_camel_folder_set_iter (folder, iter);
- priv->managed_folders = g_list_prepend (priv->managed_folders, folder);
- _tny_camel_folder_set_account (folder, TNY_ACCOUNT (self));
- }
+ _tny_camel_folder_set_folder_info (self, folder, iter);
tny_list_prepend (list, G_OBJECT (folder));
g_object_unref (G_OBJECT (folder));
Index: libtinymail-camel/tny-camel-folder-priv.h
===================================================================
--- libtinymail-camel/tny-camel-folder-priv.h (revisión: 1640)
+++ libtinymail-camel/tny-camel-folder-priv.h (copia de trabajo)
@@ -48,6 +48,7 @@
TnyMsgReceiveStrategy *receive_strat;
TnyList *observers, *sobservers; TnyFolder *self;
gboolean want_changes, dont_fkill;
+ TnyFolderStore *parent;
};
CamelFolder* _tny_camel_folder_get_camel_folder (TnyCamelFolder *self);
@@ -62,6 +63,8 @@
void _tny_camel_folder_set_account (TnyCamelFolder *self, TnyAccount *account);
gboolean _tny_camel_folder_load_folder_no_lock (TnyCamelFolderPriv *priv);
void _tny_camel_folder_set_folder (TnyCamelFolder *self, CamelFolder *camel_folder);
+void _tny_camel_folder_set_parent (TnyCamelFolder *self, TnyFolderStore *parent);
+void _tny_camel_folder_set_folder_info (TnyFolderStore *self, TnyCamelFolder *folder, CamelFolderInfo *info);
#define TNY_CAMEL_FOLDER_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_CAMEL_FOLDER, TnyCamelFolderPriv))
Index: libtinymail/tny-folder.c
===================================================================
--- libtinymail/tny-folder.c (revisión: 1640)
+++ libtinymail/tny-folder.c (copia de trabajo)
@@ -789,8 +789,30 @@
}
+/**
+ * tny_folder_get_folder_store:
+ * @self: a TnyFolder object
+ *
+ * Get a the parent account of this folder. You must unreference the
+ * return value after use. Note that not every folder strictly has to
+ * be inside a folder store.
+ *
+ * Return value: the folder store of this folder, or NULL if the
+ * folder is not inside a folder store
+ *
+ **/
+TnyFolderStore*
+tny_folder_get_folder_store (TnyFolder *self)
+{
+#ifdef DEBUG
+ if (!TNY_FOLDER_GET_IFACE (self)->get_folder_store_func)
+ g_critical ("You must implement tny_folder_get_folder_store\n");
+#endif
+ return TNY_FOLDER_GET_IFACE (self)->get_folder_store_func (self);
+}
+
static void
tny_folder_base_init (gpointer g_class)
{
Index: libtinymail/tny-folder.h
===================================================================
--- libtinymail/tny-folder.h (revisión: 1640)
+++ libtinymail/tny-folder.h (copia de trabajo)
@@ -103,6 +103,7 @@
void (*poke_status_func) (TnyFolder *self);
void (*add_observer_func) (TnyFolder *self, TnyFolderObserver *observer);
void (*remove_observer_func) (TnyFolder *self, TnyFolderObserver *observer);
+ TnyFolderStore* (*get_folder_store_func) (TnyFolder *self);
};
@@ -135,6 +136,7 @@
void tny_folder_poke_status (TnyFolder *self);
void tny_folder_add_observer (TnyFolder *self, TnyFolderObserver *observer);
void tny_folder_remove_observer (TnyFolder *self, TnyFolderObserver *observer);
+TnyFolderStore* tny_folder_get_folder_store (TnyFolder *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]