[evolution-data-server/wip/camel-more-gobject] Seal CameStoreSummary properties
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/camel-more-gobject] Seal CameStoreSummary properties
- Date: Wed, 2 Nov 2016 14:55:14 +0000 (UTC)
commit 66c85998410f1e7545bdd01dad6a181fc42f9be3
Author: Milan Crha <mcrha redhat com>
Date: Wed Nov 2 15:55:17 2016 +0100
Seal CameStoreSummary properties
src/camel/camel-store-summary.c | 70 ++++++++++++++++++---------
src/camel/camel-store-summary.h | 6 +-
src/camel/providers/nntp/camel-nntp-store.c | 8 ++--
3 files changed, 54 insertions(+), 30 deletions(-)
---
diff --git a/src/camel/camel-store-summary.c b/src/camel/camel-store-summary.c
index f43e6f8..ff9c206 100644
--- a/src/camel/camel-store-summary.c
+++ b/src/camel/camel-store-summary.c
@@ -66,6 +66,9 @@ struct _CamelStoreSummaryPrivate {
GHashTable *folder_summaries; /* CamelFolderSummary->path; doesn't add reference to
CamelFolderSummary */
guint scheduled_save_id;
+
+ GPtrArray *folders; /* CamelStoreInfo's */
+ GHashTable *folders_path; /* CamelStoreInfo's by path name */
};
G_DEFINE_TYPE (CamelStoreSummary, camel_store_summary, G_TYPE_OBJECT)
@@ -76,15 +79,15 @@ store_summary_finalize (GObject *object)
CamelStoreSummary *summary = CAMEL_STORE_SUMMARY (object);
guint ii;
- for (ii = 0; ii < summary->folders->len; ii++) {
+ for (ii = 0; ii < summary->priv->folders->len; ii++) {
CamelStoreInfo *info;
- info = g_ptr_array_index (summary->folders, ii);
+ info = g_ptr_array_index (summary->priv->folders, ii);
camel_store_summary_info_unref (summary, info);
}
- g_ptr_array_free (summary->folders, TRUE);
- g_hash_table_destroy (summary->folders_path);
+ g_ptr_array_free (summary->priv->folders, TRUE);
+ g_hash_table_destroy (summary->priv->folders_path);
g_hash_table_destroy (summary->priv->folder_summaries);
g_free (summary->priv->summary_path);
@@ -240,10 +243,10 @@ store_summary_store_info_set_string (CamelStoreSummary *summary,
{
switch (type) {
case CAMEL_STORE_INFO_PATH:
- g_hash_table_remove (summary->folders_path, (gchar *) camel_store_info_path (summary, info));
+ g_hash_table_remove (summary->priv->folders_path, (gchar *) camel_store_info_path (summary,
info));
g_free (info->path);
info->path = g_strdup (str);
- g_hash_table_insert (summary->folders_path, (gchar *) camel_store_info_path (summary, info),
info);
+ g_hash_table_insert (summary->priv->folders_path, (gchar *) camel_store_info_path (summary,
info), info);
summary->priv->dirty = TRUE;
break;
}
@@ -277,8 +280,8 @@ camel_store_summary_init (CamelStoreSummary *summary)
summary->priv->version = CAMEL_STORE_SUMMARY_VERSION;
- summary->folders = g_ptr_array_new ();
- summary->folders_path = g_hash_table_new (g_str_hash, g_str_equal);
+ summary->priv->folders = g_ptr_array_new ();
+ summary->priv->folders_path = g_hash_table_new (g_str_hash, g_str_equal);
summary->priv->folder_summaries = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
summary->priv->scheduled_save_id = 0;
@@ -333,7 +336,7 @@ camel_store_summary_count (CamelStoreSummary *summary)
{
g_return_val_if_fail (CAMEL_IS_STORE_SUMMARY (summary), -1);
- return summary->folders->len;
+ return summary->priv->folders->len;
}
/**
@@ -358,9 +361,9 @@ camel_store_summary_array (CamelStoreSummary *summary)
g_rec_mutex_lock (&summary->priv->summary_lock);
- res = g_ptr_array_sized_new (summary->folders->len);
- for (i = 0; i < summary->folders->len; i++) {
- info = g_ptr_array_index (summary->folders, i);
+ res = g_ptr_array_sized_new (summary->priv->folders->len);
+ for (i = 0; i < summary->priv->folders->len; i++) {
+ info = g_ptr_array_index (summary->priv->folders, i);
camel_store_summary_info_ref (summary, info);
g_ptr_array_add (res, info);
}
@@ -416,7 +419,7 @@ camel_store_summary_path (CamelStoreSummary *summary,
g_rec_mutex_lock (&summary->priv->summary_lock);
- info = g_hash_table_lookup (summary->folders_path, path);
+ info = g_hash_table_lookup (summary->priv->folders_path, path);
if (info != NULL)
camel_store_summary_info_ref (summary, info);
@@ -552,9 +555,9 @@ camel_store_summary_save (CamelStoreSummary *summary)
/* FIXME: Locking? */
- count = summary->folders->len;
+ count = summary->priv->folders->len;
for (i = 0; i < count; i++) {
- info = summary->folders->pdata[i];
+ info = summary->priv->folders->pdata[i];
class->store_info_save (summary, out, info);
}
@@ -604,8 +607,8 @@ camel_store_summary_add (CamelStoreSummary *summary,
g_rec_mutex_lock (&summary->priv->summary_lock);
- g_ptr_array_add (summary->folders, info);
- g_hash_table_insert (summary->folders_path, (gchar *) camel_store_info_path (summary, info), info);
+ g_ptr_array_add (summary->priv->folders, info);
+ g_hash_table_insert (summary->priv->folders_path, (gchar *) camel_store_info_path (summary, info),
info);
summary->priv->dirty = TRUE;
g_rec_mutex_unlock (&summary->priv->summary_lock);
@@ -631,7 +634,7 @@ camel_store_summary_add_from_path (CamelStoreSummary *summary,
g_rec_mutex_lock (&summary->priv->summary_lock);
- info = g_hash_table_lookup (summary->folders_path, path);
+ info = g_hash_table_lookup (summary->priv->folders_path, path);
if (info != NULL) {
g_warning ("Trying to add folder '%s' to summary that already has it", path);
info = NULL;
@@ -643,8 +646,8 @@ camel_store_summary_add_from_path (CamelStoreSummary *summary,
info = class->store_info_new (summary, path);
- g_ptr_array_add (summary->folders, info);
- g_hash_table_insert (summary->folders_path, (gchar *) camel_store_info_path (summary, info),
info);
+ g_ptr_array_add (summary->priv->folders, info);
+ g_hash_table_insert (summary->priv->folders_path, (gchar *) camel_store_info_path (summary,
info), info);
summary->priv->dirty = TRUE;
}
@@ -731,8 +734,8 @@ camel_store_summary_remove (CamelStoreSummary *summary,
g_return_if_fail (info != NULL);
g_rec_mutex_lock (&summary->priv->summary_lock);
- g_hash_table_remove (summary->folders_path, camel_store_info_path (summary, info));
- g_ptr_array_remove (summary->folders, info);
+ g_hash_table_remove (summary->priv->folders_path, camel_store_info_path (summary, info));
+ g_ptr_array_remove (summary->priv->folders, info);
summary->priv->dirty = TRUE;
g_rec_mutex_unlock (&summary->priv->summary_lock);
@@ -757,7 +760,7 @@ camel_store_summary_remove_path (CamelStoreSummary *summary,
g_return_if_fail (path != NULL);
g_rec_mutex_lock (&summary->priv->summary_lock);
- if (g_hash_table_lookup_extended (summary->folders_path, path, (gpointer) &oldpath, (gpointer)
&oldinfo)) {
+ if (g_hash_table_lookup_extended (summary->priv->folders_path, path, (gpointer) &oldpath, (gpointer)
&oldinfo)) {
/* make sure it doesn't vanish while we're removing it */
camel_store_summary_info_ref (summary, oldinfo);
g_rec_mutex_unlock (&summary->priv->summary_lock);
@@ -868,6 +871,27 @@ camel_store_info_name (CamelStoreSummary *summary,
return (cp != NULL) ? cp + 1 : info->path;
}
+/**
+ * camel_store_summary_sort:
+ * @summary: a #CamelStoreSummary
+ * @compare_func: (scope call) (closure user_data): a compare function
+ * @user_data: user data passed to the @compare_func
+ *
+ * Sorts the array of the folders using the @compare_func.
+ *
+ * Since: 3.24
+ **/
+void
+camel_store_summary_sort (CamelStoreSummary *summary,
+ GCompareDataFunc compare_func,
+ gpointer user_data)
+{
+ g_return_if_fail (CAMEL_IS_STORE_SUMMARY (summary));
+ g_return_if_fail (compare_func != NULL);
+
+ g_ptr_array_sort_with_data (summary->priv->folders, compare_func, user_data);
+}
+
static gboolean
store_summary_save_timeout (gpointer user_data)
{
diff --git a/src/camel/camel-store-summary.h b/src/camel/camel-store-summary.h
index a05e7ce..247439e 100644
--- a/src/camel/camel-store-summary.h
+++ b/src/camel/camel-store-summary.h
@@ -76,9 +76,6 @@ struct _CamelStoreInfo {
struct _CamelStoreSummary {
GObject parent;
CamelStoreSummaryPrivate *priv;
-
- GPtrArray *folders; /* CamelStoreInfo's */
- GHashTable *folders_path; /* CamelStoreInfo's by path name */
};
struct _CamelStoreSummaryClass {
@@ -174,6 +171,9 @@ const gchar * camel_store_info_path (CamelStoreSummary *summary,
CamelStoreInfo *info);
const gchar * camel_store_info_name (CamelStoreSummary *summary,
CamelStoreInfo *info);
+void camel_store_summary_sort (CamelStoreSummary *summary,
+ GCompareDataFunc compare_func,
+ gpointer user_data);
gboolean camel_store_summary_connect_folder_summary
(CamelStoreSummary *summary,
diff --git a/src/camel/providers/nntp/camel-nntp-store.c b/src/camel/providers/nntp/camel-nntp-store.c
index 6c2e5b4..8d0586e 100644
--- a/src/camel/providers/nntp/camel-nntp-store.c
+++ b/src/camel/providers/nntp/camel-nntp-store.c
@@ -1140,7 +1140,8 @@ store_info_remove (gpointer key,
static gint
store_info_sort (gconstpointer a,
- gconstpointer b)
+ gconstpointer b,
+ gpointer user_data)
{
return strcmp ((*(CamelNNTPStoreInfo **) a)->full_name, (*(CamelNNTPStoreInfo **) b)->full_name);
}
@@ -1276,9 +1277,8 @@ nntp_store_get_folder_info_all (CamelNNTPStore *nntp_store,
}
/* sort the list */
- g_ptr_array_sort (
- CAMEL_STORE_SUMMARY (nntp_store_summary)->folders,
- store_info_sort);
+ camel_store_summary_sort (CAMEL_STORE_SUMMARY (nntp_store_summary), store_info_sort, NULL);
+
if (ret < 0)
goto error;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]