[evolution-data-server] Add CamelMhSettings.



commit 2ff1e3b5e97e737c5cf16e166d0d08e571c51403
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Jul 9 11:31:44 2011 -0400

    Add CamelMhSettings.
    
    CamelMhSettings replaces the various URL parameters used in CamelMhStore
    with equivalent GObject properties.
    
    Adapt the mh provider to use CamelMhSettings.

 camel/providers/local/Makefile.am         |    2 +
 camel/providers/local/camel-mh-settings.c |  144 +++++++++++++++++++++++++++++
 camel/providers/local/camel-mh-settings.h |   67 +++++++++++++
 camel/providers/local/camel-mh-store.c    |   89 +++++++++---------
 camel/providers/local/camel-mh-store.h    |    4 -
 5 files changed, 256 insertions(+), 50 deletions(-)
---
diff --git a/camel/providers/local/Makefile.am b/camel/providers/local/Makefile.am
index cb52ac9..e3ecab3 100644
--- a/camel/providers/local/Makefile.am
+++ b/camel/providers/local/Makefile.am
@@ -27,6 +27,7 @@ libcamellocal_la_SOURCES = 			\
 	camel-mbox-store.c			\
 	camel-mbox-summary.c			\
 	camel-mh-folder.c			\
+	camel-mh-settings.c			\
 	camel-mh-store.c			\
 	camel-mh-summary.c			\
 	camel-maildir-folder.c			\
@@ -39,6 +40,7 @@ noinst_HEADERS =				\
 	camel-local-store.h			\
 	camel-local-summary.h			\
 	camel-mh-folder.h			\
+	camel-mh-settings.h			\
 	camel-mh-store.h			\
 	camel-mh-summary.h			\
 	camel-mbox-folder.h			\
diff --git a/camel/providers/local/camel-mh-settings.c b/camel/providers/local/camel-mh-settings.c
new file mode 100644
index 0000000..a37073a
--- /dev/null
+++ b/camel/providers/local/camel-mh-settings.c
@@ -0,0 +1,144 @@
+/*
+ * camel-mh-settings.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "camel-mh-settings.h"
+
+#define CAMEL_MH_SETTINGS_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), CAMEL_TYPE_MH_SETTINGS, CamelMhSettingsPrivate))
+
+struct _CamelMhSettingsPrivate {
+	gboolean use_dot_folders;
+};
+
+enum {
+	PROP_0,
+	PROP_USE_DOT_FOLDERS
+};
+
+G_DEFINE_TYPE (
+	CamelMhSettings,
+	camel_mh_settings,
+	CAMEL_TYPE_STORE_SETTINGS)
+
+static void
+mh_settings_set_property (GObject *object,
+                             guint property_id,
+                             const GValue *value,
+                             GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_USE_DOT_FOLDERS:
+			camel_mh_settings_set_use_dot_folders (
+				CAMEL_MH_SETTINGS (object),
+				g_value_get_boolean (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+mh_settings_get_property (GObject *object,
+                             guint property_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_USE_DOT_FOLDERS:
+			g_value_set_boolean (
+				value,
+				camel_mh_settings_get_use_dot_folders (
+				CAMEL_MH_SETTINGS (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+camel_mh_settings_class_init (CamelMhSettingsClass *class)
+{
+	GObjectClass *object_class;
+
+	g_type_class_add_private (class, sizeof (CamelMhSettingsPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = mh_settings_set_property;
+	object_class->get_property = mh_settings_get_property;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USE_DOT_FOLDERS,
+		g_param_spec_boolean (
+			"use-dot-folders",
+			"Use Dot Folders",
+			"Update the exmh .folders file",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			G_PARAM_STATIC_STRINGS));
+}
+
+static void
+camel_mh_settings_init (CamelMhSettings *settings)
+{
+	settings->priv = CAMEL_MH_SETTINGS_GET_PRIVATE (settings);
+}
+
+/**
+ * camel_mh_settings_get_use_dot_folders:
+ * @settings: a #CamelMhSettings
+ *
+ * Returns whether @settings should keep the .folders summary file used by
+ * the exmh (http://www.beedub.com/exmh/) mail client updated as it makes
+ * changes to the MH folders.
+ *
+ * Returns: whether to use exmh's .folders file
+ *
+ * Since: 3.2
+ **/
+gboolean
+camel_mh_settings_get_use_dot_folders (CamelMhSettings *settings)
+{
+	g_return_val_if_fail (CAMEL_IS_MH_SETTINGS (settings), FALSE);
+
+	return settings->priv->use_dot_folders;
+}
+
+/**
+ * camel_mh_settings_set_use_dot_folders:
+ * @settings: a #CamelMhSettings
+ * @use_dot_folders: whether to use exmh's .folders file
+ *
+ * Sets whether @settings should keep the .folders summary file used by
+ * the exmh (http://www.beedub.com/exmh/) mail client updated as it makes
+ * changes to the MH folders.
+ *
+ * Since: 3.2
+ **/
+void
+camel_mh_settings_set_use_dot_folders (CamelMhSettings *settings,
+                                       gboolean use_dot_folders)
+{
+	g_return_if_fail (CAMEL_IS_MH_SETTINGS (settings));
+
+	settings->priv->use_dot_folders = use_dot_folders;
+
+	g_object_notify (G_OBJECT (settings), "use-dot-folders");
+}
diff --git a/camel/providers/local/camel-mh-settings.h b/camel/providers/local/camel-mh-settings.h
new file mode 100644
index 0000000..cad65cd
--- /dev/null
+++ b/camel/providers/local/camel-mh-settings.h
@@ -0,0 +1,67 @@
+/*
+ * camel-mh-settings.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef CAMEL_MH_SETTINGS_H
+#define CAMEL_MH_SETTINGS_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_MH_SETTINGS \
+	(camel_mh_settings_get_type ())
+#define CAMEL_MH_SETTINGS(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_MH_SETTINGS, CamelMhSettings))
+#define CAMEL_MH_SETTINGS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_MH_SETTINGS, CamelMhSettingsClass))
+#define CAMEL_IS_MH_SETTINGS(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_MH_SETTINGS))
+#define CAMEL_IS_MH_SETTINGS_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_MH_SETTINGS))
+#define CAMEL_MH_SETTINGS_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_MH_SETTINGS, CamelMhSettingsClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelMhSettings CamelMhSettings;
+typedef struct _CamelMhSettingsClass CamelMhSettingsClass;
+typedef struct _CamelMhSettingsPrivate CamelMhSettingsPrivate;
+
+struct _CamelMhSettings {
+	CamelStoreSettings parent;
+	CamelMhSettingsPrivate *priv;
+};
+
+struct _CamelMhSettingsClass {
+	CamelStoreSettingsClass parent_class;
+};
+
+GType		camel_mh_settings_get_type	(void) G_GNUC_CONST;
+gboolean	camel_mh_settings_get_use_dot_folders
+						(CamelMhSettings *settings);
+void		camel_mh_settings_set_use_dot_folders
+						(CamelMhSettings *settings,
+						 gboolean use_dot_folders);
+
+G_END_DECLS
+
+#endif /* CAMEL_MH_SETTINGS_H */
diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c
index 6056f99..0ef3215 100644
--- a/camel/providers/local/camel-mh-store.c
+++ b/camel/providers/local/camel-mh-store.c
@@ -33,19 +33,12 @@
 #include <glib/gi18n-lib.h>
 
 #include "camel-mh-folder.h"
+#include "camel-mh-settings.h"
 #include "camel-mh-store.h"
 #include "camel-mh-summary.h"
 
-#define CAMEL_MH_STORE_GET_PRIVATE(obj) \
-	(G_TYPE_INSTANCE_GET_PRIVATE \
-	((obj), CAMEL_TYPE_MH_STORE, CamelMhStorePrivate))
-
 #define d(x)
 
-struct _CamelMhStorePrivate {
-	guint32 flags;
-};
-
 G_DEFINE_TYPE (CamelMhStore, camel_mh_store, CAMEL_TYPE_LOCAL_STORE)
 
 enum {
@@ -470,25 +463,6 @@ inode_free (gpointer k, gpointer v, gpointer d)
 	g_free (k);
 }
 
-static void
-mh_store_constructed (GObject *object)
-{
-	CamelMhStore *mh_store;
-	CamelService *service;
-	CamelURL *url;
-
-	mh_store = CAMEL_MH_STORE (object);
-
-	/* Chain up to parent's constructed() method. */
-	G_OBJECT_CLASS (camel_mh_store_parent_class)->constructed (object);
-
-	service = CAMEL_SERVICE (object);
-	url = camel_service_get_camel_url (service);
-
-	if (camel_url_get_param(url, "dotfolders"))
-		mh_store->priv->flags |= CAMEL_MH_DOTFOLDERS;
-}
-
 static CamelFolder *
 mh_store_get_folder_sync (CamelStore *store,
                           const gchar *folder_name,
@@ -498,13 +472,20 @@ mh_store_get_folder_sync (CamelStore *store,
 {
 	CamelStoreClass *store_class;
 	CamelLocalStore *local_store;
-	CamelMhStore *mh_store;
+	CamelService *service;
+	CamelSettings *settings;
+	gboolean use_dot_folders;
 	gchar *name;
 	struct stat st;
 
-	mh_store = CAMEL_MH_STORE (store);
 	local_store = CAMEL_LOCAL_STORE (store);
 
+	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
+
+	use_dot_folders = camel_mh_settings_get_use_dot_folders (
+		CAMEL_MH_SETTINGS (settings));
+
 	/* Chain up to parent's get_folder() method. */
 	store_class = CAMEL_STORE_CLASS (camel_mh_store_parent_class);
 	if (store_class->get_folder_sync (
@@ -546,7 +527,7 @@ mh_store_get_folder_sync (CamelStore *store,
 
 		/* add to .folders if we are supposed to */
 		/* FIXME: throw exception on error */
-		if (mh_store->priv->flags & CAMEL_MH_DOTFOLDERS)
+		if (use_dot_folders)
 			folders_update (
 				local_store->toplevel_dir,
 				UPDATE_ADD, folder_name, NULL, cancellable);
@@ -582,16 +563,21 @@ mh_store_get_folder_info_sync (CamelStore *store,
                                GCancellable *cancellable,
                                GError **error)
 {
-	CamelMhStore *mh_store;
+	CamelService *service;
+	CamelSettings *settings;
 	CamelFolderInfo *fi = NULL;
 	CamelURL *url;
+	gboolean use_dot_folders;
 
-	mh_store = CAMEL_MH_STORE (store);
+	service = CAMEL_SERVICE (store);
+	url = camel_service_get_camel_url (service);
+	settings = camel_service_get_settings (service);
 
-	url = camel_service_get_camel_url (CAMEL_SERVICE (store));
+	use_dot_folders = camel_mh_settings_get_use_dot_folders (
+		CAMEL_MH_SETTINGS (settings));
 
 	/* use .folders if we are supposed to */
-	if (mh_store->priv->flags & CAMEL_MH_DOTFOLDERS) {
+	if (use_dot_folders) {
 		folders_scan (
 			store, url->path, top, &fi, flags, cancellable);
 	} else {
@@ -641,12 +627,19 @@ mh_store_delete_folder_sync (CamelStore *store,
 {
 	CamelStoreClass *store_class;
 	CamelLocalStore *local_store;
-	CamelMhStore *mh_store;
+	CamelService *service;
+	CamelSettings *settings;
+	gboolean use_dot_folders;
 	gchar *name;
 
-	mh_store = CAMEL_MH_STORE (store);
 	local_store = CAMEL_LOCAL_STORE (store);
 
+	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
+
+	use_dot_folders = camel_mh_settings_get_use_dot_folders (
+		CAMEL_MH_SETTINGS (settings));
+
 	/* remove folder directory - will fail if not empty */
 	name = g_strconcat (local_store->toplevel_dir, folder_name, NULL);
 	if (rmdir (name) == -1) {
@@ -661,7 +654,7 @@ mh_store_delete_folder_sync (CamelStore *store,
 	g_free (name);
 
 	/* remove from .folders if we are supposed to */
-	if (mh_store->priv->flags & CAMEL_MH_DOTFOLDERS)
+	if (use_dot_folders)
 		folders_update (
 			local_store->toplevel_dir,
 			UPDATE_REMOVE, folder_name, NULL, cancellable);
@@ -681,18 +674,25 @@ mh_store_rename_folder_sync (CamelStore *store,
 {
 	CamelStoreClass *store_class;
 	CamelLocalStore *local_store;
-	CamelMhStore *mh_store;
+	CamelService *service;
+	CamelSettings *settings;
+	gboolean use_dot_folders;
 
-	mh_store = CAMEL_MH_STORE (store);
 	local_store = CAMEL_LOCAL_STORE (store);
 
+	service = CAMEL_SERVICE (store);
+	settings = camel_service_get_settings (service);
+
+	use_dot_folders = camel_mh_settings_get_use_dot_folders (
+		CAMEL_MH_SETTINGS (settings));
+
 	/* Chain up to parent's rename_folder() method. */
 	store_class = CAMEL_STORE_CLASS (camel_mh_store_parent_class);
 	if (!store_class->rename_folder_sync (
 		store, old, new, cancellable, error))
 		return FALSE;
 
-	if (mh_store->priv->flags & CAMEL_MH_DOTFOLDERS) {
+	if (use_dot_folders) {
 		/* yeah this is messy, but so is mh! */
 		folders_update (
 			local_store->toplevel_dir,
@@ -705,13 +705,11 @@ mh_store_rename_folder_sync (CamelStore *store,
 static void
 camel_mh_store_class_init (CamelMhStoreClass *class)
 {
-	GObjectClass *object_class;
+	CamelServiceClass *service_class;
 	CamelStoreClass *store_class;
 
-	g_type_class_add_private (class, sizeof (CamelMhStorePrivate));
-
-	object_class = G_OBJECT_CLASS (class);
-	object_class->constructed = mh_store_constructed;
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->settings_type = CAMEL_TYPE_MH_SETTINGS;
 
 	store_class = CAMEL_STORE_CLASS (class);
 	store_class->get_folder_sync = mh_store_get_folder_sync;
@@ -724,6 +722,5 @@ camel_mh_store_class_init (CamelMhStoreClass *class)
 static void
 camel_mh_store_init (CamelMhStore *mh_store)
 {
-	mh_store->priv = CAMEL_MH_STORE_GET_PRIVATE (mh_store);
 }
 
diff --git a/camel/providers/local/camel-mh-store.h b/camel/providers/local/camel-mh-store.h
index 4b2919d..3a8d84c 100644
--- a/camel/providers/local/camel-mh-store.h
+++ b/camel/providers/local/camel-mh-store.h
@@ -49,10 +49,6 @@ typedef struct _CamelMhStore CamelMhStore;
 typedef struct _CamelMhStoreClass CamelMhStoreClass;
 typedef struct _CamelMhStorePrivate CamelMhStorePrivate;
 
-enum {
-	CAMEL_MH_DOTFOLDERS = (1 << 0) /* update/use .folders file */
-};
-
 struct _CamelMhStore {
 	CamelLocalStore parent;
 	CamelMhStorePrivate *priv;



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