[evolution-ews] CamelEwsStoreSummary: Store enum values by their nickname.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] CamelEwsStoreSummary: Store enum values by their nickname.
- Date: Sat, 4 Aug 2012 01:30:44 +0000 (UTC)
commit 506265c25af53b73d6082ee17d0c73964118ac2e
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Aug 3 21:01:51 2012 -0400
CamelEwsStoreSummary: Store enum values by their nickname.
Never store enum values across sessions by their numeric value, because
the numeric value may be different the next time the application starts.
Always store enum values by a nickname string.
Case in point: the FolderType key broke when I added the UNKNOWN value.
src/camel/camel-ews-store-summary.c | 47 +++++++++++++++++++++++++--------
src/camel/camel-ews-store-summary.h | 8 +++--
src/camel/camel-ews-store.c | 2 +-
src/camel/camel-ews-utils.c | 3 +-
src/server/e-ews-folder.c | 49 +++++++++++++++++++++++++++++++++++
src/server/e-ews-folder.h | 2 +
6 files changed, 94 insertions(+), 17 deletions(-)
---
diff --git a/src/camel/camel-ews-store-summary.c b/src/camel/camel-ews-store-summary.c
index bb66972..cbf6b66 100644
--- a/src/camel/camel-ews-store-summary.c
+++ b/src/camel/camel-ews-store-summary.c
@@ -4,6 +4,8 @@
#include <string.h>
#include "camel-ews-store-summary.h"
+#include "server/e-ews-folder.h"
+
#define S_LOCK(x) (g_static_rec_mutex_lock(&(x)->priv->s_lock))
#define S_UNLOCK(x) (g_static_rec_mutex_unlock(&(x)->priv->s_lock))
@@ -342,10 +344,16 @@ camel_ews_store_summary_new_folder (CamelEwsStoreSummary *ews_summary,
const gchar *parent_fid,
const gchar *change_key,
const gchar *display_name,
- guint64 folder_type,
+ EEwsFolderType folder_type,
guint64 folder_flags,
guint64 total)
{
+ const gchar *folder_type_nick;
+
+ /* Store the folder type by its nickname. */
+ folder_type_nick = e_ews_folder_type_to_nick (folder_type);
+ g_return_if_fail (folder_type_nick != NULL);
+
S_LOCK (ews_summary);
g_key_file_set_string (
@@ -357,9 +365,9 @@ camel_ews_store_summary_new_folder (CamelEwsStoreSummary *ews_summary,
g_key_file_set_string (
ews_summary->priv->key_file,
folder_id, "DisplayName", display_name);
- g_key_file_set_uint64 (
+ g_key_file_set_string (
ews_summary->priv->key_file,
- folder_id, "FolderType", folder_type);
+ folder_id, "FolderType", folder_type_nick);
g_key_file_set_uint64 (
ews_summary->priv->key_file,
folder_id, "Flags", folder_flags);
@@ -475,13 +483,19 @@ camel_ews_store_summary_set_folder_total (CamelEwsStoreSummary *ews_summary,
void
camel_ews_store_summary_set_folder_type (CamelEwsStoreSummary *ews_summary,
const gchar *folder_id,
- guint64 ews_folder_type)
+ EEwsFolderType folder_type)
{
+ const gchar *folder_type_nick;
+
+ /* Store the folder type by its nickname. */
+ folder_type_nick = e_ews_folder_type_to_nick (folder_type);
+ g_return_if_fail (folder_type_nick != NULL);
+
S_LOCK (ews_summary);
- g_key_file_set_uint64 (
+ g_key_file_set_string (
ews_summary->priv->key_file,
- folder_id, "FolderType", ews_folder_type);
+ folder_id, "FolderType", folder_type_nick);
ews_summary->priv->dirty = TRUE;
S_UNLOCK (ews_summary);
@@ -647,22 +661,31 @@ camel_ews_store_summary_get_folder_total (CamelEwsStoreSummary *ews_summary,
return ret;
}
-guint64
+EEwsFolderType
camel_ews_store_summary_get_folder_type (CamelEwsStoreSummary *ews_summary,
const gchar *folder_id,
GError **error)
{
- guint64 ret;
+ EEwsFolderType folder_type;
+ gchar *folder_type_nick;
S_LOCK (ews_summary);
- ret = g_key_file_get_uint64 (
- ews_summary->priv->key_file, folder_id,
- "FolderType", error);
+ folder_type_nick = g_key_file_get_string (
+ ews_summary->priv->key_file,
+ folder_id, "FolderType", error);
S_UNLOCK (ews_summary);
- return ret;
+ /* Look up the folder type by its nickname. */
+ if (folder_type_nick != NULL)
+ folder_type = e_ews_folder_type_from_nick (folder_type_nick);
+ else
+ folder_type = E_EWS_FOLDER_TYPE_UNKNOWN;
+
+ g_free (folder_type_nick);
+
+ return folder_type;
}
gchar *
diff --git a/src/camel/camel-ews-store-summary.h b/src/camel/camel-ews-store-summary.h
index 2f9b10e..7fdb63e 100644
--- a/src/camel/camel-ews-store-summary.h
+++ b/src/camel/camel-ews-store-summary.h
@@ -3,6 +3,8 @@
#include <camel/camel.h>
+#include "server/e-ews-enums.h"
+
/* Standard GObject macros */
#define CAMEL_TYPE_EWS_STORE_SUMMARY \
(camel_ews_store_summary_get_type ())
@@ -82,7 +84,7 @@ void camel_ews_store_summary_set_folder_total
void camel_ews_store_summary_set_folder_type
(CamelEwsStoreSummary *ews_summary,
const gchar *folder_id,
- guint64 folder_type);
+ EEwsFolderType folder_type);
gchar * camel_ews_store_summary_get_folder_name
(CamelEwsStoreSummary *ews_summary,
@@ -116,7 +118,7 @@ guint64 camel_ews_store_summary_get_folder_total
(CamelEwsStoreSummary *ews_summary,
const gchar *folder_id,
GError **error);
-guint64 camel_ews_store_summary_get_folder_type
+EEwsFolderType camel_ews_store_summary_get_folder_type
(CamelEwsStoreSummary *ews_summary,
const gchar *folder_id,
GError **error);
@@ -146,7 +148,7 @@ void camel_ews_store_summary_new_folder
const gchar *parent_fid,
const gchar *change_key,
const gchar *display_name,
- guint64 folder_type,
+ EEwsFolderType folder_type,
guint64 folder_flags,
guint64 total);
diff --git a/src/camel/camel-ews-store.c b/src/camel/camel-ews-store.c
index 3e771a8..786fdd6 100644
--- a/src/camel/camel-ews-store.c
+++ b/src/camel/camel-ews-store.c
@@ -552,7 +552,7 @@ folder_info_from_store_summary (CamelEwsStore *store,
for (l = folders; l != NULL; l = g_slist_next (l)) {
CamelFolderInfo *fi;
- gint64 ftype;
+ EEwsFolderType ftype;
ftype = camel_ews_store_summary_get_folder_type (ews_summary, l->data, NULL);
if (ftype != E_EWS_FOLDER_TYPE_MAILBOX)
diff --git a/src/camel/camel-ews-utils.c b/src/camel/camel-ews-utils.c
index 45a7f5e..e1e5cc8 100644
--- a/src/camel/camel-ews-utils.c
+++ b/src/camel/camel-ews-utils.c
@@ -463,7 +463,8 @@ add_folder_to_summary (CamelEwsStore *store,
CamelEwsStoreSummary *ews_summary = store->summary;
const EwsFolderId *pfid, *fid;
const gchar *dname;
- gint64 unread, total, ftype;
+ gint64 unread, total;
+ EEwsFolderType ftype;
fid = e_ews_folder_get_id (folder);
pfid = e_ews_folder_get_parent_id (folder);
diff --git a/src/server/e-ews-folder.c b/src/server/e-ews-folder.c
index f5dfbf0..7872549 100644
--- a/src/server/e-ews-folder.c
+++ b/src/server/e-ews-folder.c
@@ -25,6 +25,7 @@
#include <string.h>
#include "e-ews-folder.h"
#include "e-ews-message.h"
+#include "e-ews-enumtypes.h"
G_DEFINE_TYPE (EEwsFolder, e_ews_folder, G_TYPE_OBJECT)
@@ -191,6 +192,54 @@ e_ews_folder_set_from_soap_parameter (EEwsFolder *folder,
return TRUE;
}
+const gchar *
+e_ews_folder_type_to_nick (EEwsFolderType folder_type)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ const gchar *folder_type_nick;
+
+ enum_class = g_type_class_ref (E_TYPE_EWS_FOLDER_TYPE);
+ enum_value = g_enum_get_value (enum_class, folder_type);
+
+ if (enum_value == NULL) {
+ folder_type = E_EWS_FOLDER_TYPE_UNKNOWN;
+ enum_value = g_enum_get_value (enum_class, folder_type);
+ }
+
+ g_return_val_if_fail (enum_value != NULL, NULL);
+
+ folder_type_nick = g_intern_string (enum_value->value_nick);
+
+ g_type_class_unref (enum_class);
+
+ return folder_type_nick;
+}
+
+EEwsFolderType
+e_ews_folder_type_from_nick (const gchar *folder_type_nick)
+{
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+ EEwsFolderType folder_type;
+
+ g_return_val_if_fail (
+ folder_type_nick != NULL,
+ E_EWS_FOLDER_TYPE_UNKNOWN);
+
+ enum_class = g_type_class_ref (E_TYPE_EWS_FOLDER_TYPE);
+ enum_value = g_enum_get_value_by_nick (enum_class, folder_type_nick);
+
+ if (enum_value != NULL)
+ folder_type = enum_value->value;
+ else
+ folder_type = E_EWS_FOLDER_TYPE_UNKNOWN;
+
+ g_type_class_unref (enum_class);
+
+ return folder_type;
+}
+
EEwsFolder *
e_ews_folder_new_from_soap_parameter (ESoapParameter *param)
{
diff --git a/src/server/e-ews-folder.h b/src/server/e-ews-folder.h
index bc39ceb..a721e53 100644
--- a/src/server/e-ews-folder.h
+++ b/src/server/e-ews-folder.h
@@ -53,6 +53,8 @@ typedef struct {
} EwsFolderId;
GType e_ews_folder_get_type (void);
+const gchar * e_ews_folder_type_to_nick (EEwsFolderType folder_type);
+EEwsFolderType e_ews_folder_type_from_nick (const gchar *folder_type_nick);
EEwsFolder * e_ews_folder_new_from_soap_parameter (ESoapParameter *param);
const gchar * e_ews_folder_get_name (EEwsFolder *folder);
void e_ews_folder_set_name (EEwsFolder *folder, const gchar *new_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]