[evolution-data-server] Add a CamelFolder:uri property.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add a CamelFolder:uri property.
- Date: Mon, 11 Oct 2010 15:14:07 +0000 (UTC)
commit 24446cde6be0c3edcdb41520e0a433c99d17f9f9
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Oct 11 10:57:56 2010 -0400
Add a CamelFolder:uri property.
Replaces mail_tools_folder_to_url() in Evolution. The URI is computed
on-demand and then cached, so the return value is const. Renaming the
folder invalidates the cached URI and emits a "notify::uri" signal.
camel/camel-folder.c | 88 ++++++++++++++++++++++++++-
camel/camel-folder.h | 1 +
docs/reference/camel/camel-sections.txt | 1 +
docs/reference/camel/tmpl/camel-folder.sgml | 5 ++
4 files changed, 93 insertions(+), 2 deletions(-)
---
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 00b7aaf..bf580f5 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -65,6 +65,7 @@ struct _CamelFolderPrivate {
gchar *name;
gchar *full_name;
gchar *description;
+ gchar *uri;
};
struct _AsyncContext {
@@ -110,7 +111,8 @@ enum {
PROP_DESCRIPTION,
PROP_FULL_NAME,
PROP_NAME,
- PROP_PARENT_STORE
+ PROP_PARENT_STORE,
+ PROP_URI
};
enum {
@@ -472,6 +474,12 @@ folder_get_property (GObject *object,
value, camel_folder_get_parent_store (
CAMEL_FOLDER (object)));
return;
+
+ case PROP_URI:
+ g_value_set_string (
+ value, camel_folder_get_uri (
+ CAMEL_FOLDER (object)));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -511,6 +519,7 @@ folder_finalize (GObject *object)
g_free (priv->name);
g_free (priv->full_name);
g_free (priv->description);
+ g_free (priv->uri);
camel_folder_change_info_free (priv->changed_frozen);
@@ -1567,6 +1576,23 @@ camel_folder_class_init (CamelFolderClass *class)
G_PARAM_CONSTRUCT_ONLY));
/**
+ * CamelFolder:uri
+ *
+ * The folder's URI.
+ *
+ * Since: 2.92
+ **/
+ g_object_class_install_property (
+ object_class,
+ PROP_URI,
+ g_param_spec_string (
+ "uri",
+ "URI",
+ "The folder's URI",
+ NULL,
+ G_PARAM_READABLE));
+
+ /**
* CamelFolder::changed
* @folder: the #CamelFolder which emitted the signal
**/
@@ -1744,12 +1770,22 @@ void
camel_folder_set_full_name (CamelFolder *folder,
const gchar *full_name)
{
+ GObject *object;
+
g_return_if_fail (CAMEL_IS_FOLDER (folder));
g_free (folder->priv->full_name);
folder->priv->full_name = g_strdup (full_name);
- g_object_notify (G_OBJECT (folder), "full-name");
+ /* The URI property will need to be reconstructed. */
+ g_free (folder->priv->uri);
+ folder->priv->uri = NULL;
+
+ object = G_OBJECT (folder);
+ g_object_freeze_notify (object);
+ g_object_notify (object, "full-name");
+ g_object_notify (object, "uri");
+ g_object_thaw_notify (object);
}
/**
@@ -1810,6 +1846,54 @@ camel_folder_get_parent_store (CamelFolder *folder)
}
/**
+ * camel_folder_get_uri:
+ * @folder: a #CamelFolder
+ *
+ * Returns the folder's URI.
+ *
+ * Returns: the folder's URI
+ *
+ * Since: 2.92
+ **/
+const gchar *
+camel_folder_get_uri (CamelFolder *folder)
+{
+ CamelService *service;
+ CamelStore *parent_store;
+ const gchar *full_name;
+ CamelURL *url;
+
+ g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+
+ /* The URI is constructed on demand and then cached. */
+
+ if (folder->priv->uri != NULL)
+ goto exit;
+
+ full_name = camel_folder_get_full_name (folder);
+ parent_store = camel_folder_get_parent_store (folder);
+ service = CAMEL_SERVICE (parent_store);
+
+ url = camel_url_copy (service->url);
+
+ if (service->provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH) {
+ camel_url_set_fragment (url, full_name);
+ } else {
+ gchar *path = g_strdup_printf ("/%s", full_name);
+ camel_url_set_path (url, path);
+ g_free (path);
+ }
+
+ g_free (folder->priv->uri);
+ folder->priv->uri = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
+
+ camel_url_free (url);
+
+exit:
+ return folder->priv->uri;
+}
+
+/**
* camel_folder_get_message_count:
* @folder: a #CamelFolder
*
diff --git a/camel/camel-folder.h b/camel/camel-folder.h
index 01abda3..9024344 100644
--- a/camel/camel-folder.h
+++ b/camel/camel-folder.h
@@ -347,6 +347,7 @@ void camel_folder_set_full_name (CamelFolder *folder,
const gchar * camel_folder_get_description (CamelFolder *folder);
void camel_folder_set_description (CamelFolder *folder,
const gchar *description);
+const gchar * camel_folder_get_uri (CamelFolder *folder);
CamelMessageFlags
camel_folder_get_permanent_flags
(CamelFolder *folder);
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index c80f936..ff9c217 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -436,6 +436,7 @@ camel_folder_get_full_name
camel_folder_set_full_name
camel_folder_get_description
camel_folder_set_description
+camel_folder_get_uri
camel_folder_get_permanent_flags
camel_folder_get_message_flags
camel_folder_set_message_flags
diff --git a/docs/reference/camel/tmpl/camel-folder.sgml b/docs/reference/camel/tmpl/camel-folder.sgml
index bd7c5ba..7362fb3 100644
--- a/docs/reference/camel/tmpl/camel-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-folder.sgml
@@ -82,6 +82,11 @@ CamelFolder
</para>
+<!-- ##### ARG CamelFolder:uri ##### -->
+<para>
+
+</para>
+
<!-- ##### MACRO CAMEL_FOLDER_ERROR ##### -->
<para>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]