| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 1999-2008 Novell, Inc. (www.novell.com) |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "evolution-ews-config.h" |
| 7 |
|
| 8 |
#include <glib.h> |
| 9 |
#include <glib/gstdio.h> |
| 10 |
#include <gio/gio.h> |
| 11 |
#include <string.h> |
| 12 |
#include "camel-ews-store-summary.h" |
| 13 |
|
| 14 |
#include "common/e-ews-folder.h" |
| 15 |
|
| 16 |
#define S_LOCK(x) (g_rec_mutex_lock(&(x)->priv->s_lock)) |
| 17 |
#define S_UNLOCK(x) (g_rec_mutex_unlock(&(x)->priv->s_lock)) |
| 18 |
|
| 19 |
#define STORE_GROUP_NAME "##storepriv" |
| 20 |
#define CATEGORIES_KEY "Categories" |
| 21 |
#define CURRENT_SUMMARY_VERSION 3 |
| 22 |
|
| 23 |
struct _CamelEwsStoreSummaryPrivate { |
| 24 |
GKeyFile *key_file; |
| 25 |
gboolean dirty; |
| 26 |
gchar *path; |
| 27 |
/* Note: We use the *same* strings in both of these hash tables, and |
| 28 |
* only id_fname_hash has g_free() hooked up as the destructor func. |
| 29 |
* So entries must always be removed from fname_id_hash *first*. */ |
| 30 |
GHashTable *id_fname_hash; |
| 31 |
GHashTable *fname_id_hash; |
| 32 |
GRecMutex s_lock; |
| 33 |
|
| 34 |
GFileMonitor *monitor_delete; |
| 35 |
}; |
| 36 |
|
| 37 |
G_DEFINE_TYPE_WITH_PRIVATE (CamelEwsStoreSummary, camel_ews_store_summary, CAMEL_TYPE_OBJECT) |
| 38 |
|
| 39 |
static void |
| 40 |
ews_store_summary_finalize (GObject *object) |
| 41 |
{ |
| 42 |
CamelEwsStoreSummary *ews_summary = CAMEL_EWS_STORE_SUMMARY (object); |
| 43 |
CamelEwsStoreSummaryPrivate *priv = ews_summary->priv; |
| 44 |
|
| 45 |
g_key_file_free (priv->key_file); |
| 46 |
g_free (priv->path); |
| 47 |
g_hash_table_destroy (priv->fname_id_hash); |
| 48 |
g_hash_table_destroy (priv->id_fname_hash); |
| 49 |
g_rec_mutex_clear (&priv->s_lock); |
| 50 |
if (priv->monitor_delete) |
| 51 |
g_object_unref (priv->monitor_delete); |
| 52 |
|
| 53 |
/* Chain up to parent's finalize() method. */ |
| 54 |
G_OBJECT_CLASS (camel_ews_store_summary_parent_class)->finalize (object); |
| 55 |
} |
| 56 |
|
| 57 |
static void |
| 58 |
camel_ews_store_summary_class_init (CamelEwsStoreSummaryClass *class) |
| 59 |
{ |
| 60 |
GObjectClass *object_class; |
| 61 |
|
| 62 |
object_class = G_OBJECT_CLASS (class); |
| 63 |
object_class->finalize = ews_store_summary_finalize; |
| 64 |
} |
| 65 |
|
| 66 |
static void |
| 67 |
camel_ews_store_summary_init (CamelEwsStoreSummary *ews_summary) |
| 68 |
{ |
| 69 |
ews_summary->priv = camel_ews_store_summary_get_instance_private (ews_summary); |
| 70 |
|
| 71 |
ews_summary->priv->key_file = g_key_file_new (); |
| 72 |
ews_summary->priv->dirty = FALSE; |
| 73 |
ews_summary->priv->fname_id_hash = g_hash_table_new (g_str_hash, g_str_equal); |
| 74 |
ews_summary->priv->id_fname_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); |
| 75 |
g_rec_mutex_init (&ews_summary->priv->s_lock); |
| 76 |
} |
| 77 |
|
| 78 |
static gchar *build_full_name (CamelEwsStoreSummary *ews_summary, const gchar *fid) |
| 79 |
{ |
| 80 |
gchar *pfid, *dname, *ret; |
| 81 |
gchar *pname = NULL; |
| 82 |
|
| 83 |
dname = camel_ews_store_summary_get_folder_name (ews_summary, fid, NULL); |
| 84 |
if (!dname) |
| 85 |
return NULL; |
| 86 |
|
| 87 |
pfid = camel_ews_store_summary_get_parent_folder_id (ews_summary, fid, NULL); |
| 88 |
if (pfid) { |
| 89 |
pname = build_full_name (ews_summary, pfid); |
| 90 |
g_free (pfid); |
| 91 |
} |
| 92 |
|
| 93 |
if (pname) { |
| 94 |
ret = g_strdup_printf ("%s/%s", pname, dname); |
| 95 |
g_free (pname); |
| 96 |
g_free (dname); |
| 97 |
} else |
| 98 |
ret = dname; |
| 99 |
|
| 100 |
return ret; |
| 101 |
} |
| 102 |
|
| 103 |
static void |
| 104 |
load_id_fname_hash (CamelEwsStoreSummary *ews_summary) |
| 105 |
{ |
| 106 |
GSList *folders, *l; |
| 107 |
|
| 108 |
g_hash_table_remove_all (ews_summary->priv->fname_id_hash); |
| 109 |
g_hash_table_remove_all (ews_summary->priv->id_fname_hash); |
| 110 |
|
| 111 |
folders = camel_ews_store_summary_get_folders (ews_summary, NULL, FALSE); |
| 112 |
|
| 113 |
for (l = folders; l != NULL; l = g_slist_next (l)) { |
| 114 |
gchar *id = l->data; |
| 115 |
gchar *fname; |
| 116 |
|
| 117 |
fname = build_full_name (ews_summary, id); |
| 118 |
|
| 119 |
if (!fname) { |
| 120 |
/* eep */ |
| 121 |
g_warning ("Cannot build full name for folder %s", id); |
| 122 |
g_free (id); |
| 123 |
continue; |
| 124 |
} |
| 125 |
g_hash_table_insert (ews_summary->priv->fname_id_hash, fname, id); |
| 126 |
g_hash_table_insert (ews_summary->priv->id_fname_hash, id, fname); |
| 127 |
} |
| 128 |
|
| 129 |
g_slist_free (folders); |
| 130 |
} |
| 131 |
|
| 132 |
/* we only care about delete and ignore create */ |
| 133 |
static void |
| 134 |
monitor_delete_cb (GFileMonitor *monitor, |
| 135 |
GFile *file, |
| 136 |
GFile *other_file, |
| 137 |
GFileMonitorEvent event, |
| 138 |
gpointer user_data) |
| 139 |
{ |
| 140 |
CamelEwsStoreSummary *ews_summary = (CamelEwsStoreSummary *) user_data; |
| 141 |
|
| 142 |
if (event == G_FILE_MONITOR_EVENT_DELETED) { |
| 143 |
S_LOCK (ews_summary); |
| 144 |
|
| 145 |
if (ews_summary->priv->key_file) |
| 146 |
camel_ews_store_summary_clear (ews_summary); |
| 147 |
|
| 148 |
S_UNLOCK (ews_summary); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
CamelEwsStoreSummary * |
| 153 |
camel_ews_store_summary_new (const gchar *path) |
| 154 |
{ |
| 155 |
CamelEwsStoreSummary *ews_summary; |
| 156 |
GError *error = NULL; |
| 157 |
GFile *file; |
| 158 |
|
| 159 |
ews_summary = g_object_new (CAMEL_TYPE_EWS_STORE_SUMMARY, NULL); |
| 160 |
|
| 161 |
ews_summary->priv->path = g_strdup (path); |
| 162 |
file = g_file_new_for_path (path); |
| 163 |
ews_summary->priv->monitor_delete = g_file_monitor_file ( |
| 164 |
file, G_FILE_MONITOR_SEND_MOVED, NULL, &error); |
| 165 |
|
| 166 |
/* Remove this once we have camel_store_remove_storage api, |
| 167 |
* which should be available from 3.2 */ |
| 168 |
if (!error) { |
| 169 |
g_signal_connect ( |
| 170 |
ews_summary->priv->monitor_delete, "changed", |
| 171 |
G_CALLBACK (monitor_delete_cb), ews_summary); |
| 172 |
} else { |
| 173 |
g_warning ( |
| 174 |
"CamelEwsStoreSummary: " |
| 175 |
"Error create monitor_delete: %s \n", |
| 176 |
error->message); |
| 177 |
g_clear_error (&error); |
| 178 |
} |
| 179 |
|
| 180 |
g_object_unref (file); |
| 181 |
|
| 182 |
return ews_summary; |
| 183 |
} |
| 184 |
|
| 185 |
gboolean |
| 186 |
camel_ews_store_summary_load (CamelEwsStoreSummary *ews_summary, |
| 187 |
GError **error) |
| 188 |
{ |
| 189 |
CamelEwsStoreSummaryPrivate *priv = ews_summary->priv; |
| 190 |
gboolean ret; |
| 191 |
gint version; |
| 192 |
|
| 193 |
S_LOCK (ews_summary); |
| 194 |
|
| 195 |
ret = g_key_file_load_from_file ( |
| 196 |
priv->key_file, priv->path, 0, error); |
| 197 |
|
| 198 |
version = g_key_file_get_integer ( |
| 199 |
priv->key_file, STORE_GROUP_NAME, "Version", NULL); |
| 200 |
|
| 201 |
if (version != CURRENT_SUMMARY_VERSION) { |
| 202 |
/* version doesn't match, get folders again */ |
| 203 |
camel_ews_store_summary_clear (ews_summary); |
| 204 |
|
| 205 |
g_key_file_set_integer ( |
| 206 |
priv->key_file, STORE_GROUP_NAME, |
| 207 |
"Version", CURRENT_SUMMARY_VERSION); |
| 208 |
} |
| 209 |
|
| 210 |
load_id_fname_hash (ews_summary); |
| 211 |
|
| 212 |
S_UNLOCK (ews_summary); |
| 213 |
|
| 214 |
return ret; |
| 215 |
} |
| 216 |
|
| 217 |
gboolean |
| 218 |
camel_ews_store_summary_save (CamelEwsStoreSummary *ews_summary, |
| 219 |
GError **error) |
| 220 |
{ |
| 221 |
CamelEwsStoreSummaryPrivate *priv = ews_summary->priv; |
| 222 |
gboolean ret = TRUE; |
| 223 |
GFile *file; |
| 224 |
gchar *contents = NULL; |
| 225 |
|
| 226 |
S_LOCK (ews_summary); |
| 227 |
|
| 228 |
if (!priv->dirty) |
| 229 |
goto exit; |
| 230 |
|
| 231 |
contents = g_key_file_to_data ( |
| 232 |
priv->key_file, NULL, NULL); |
| 233 |
file = g_file_new_for_path (priv->path); |
| 234 |
ret = g_file_replace_contents ( |
| 235 |
file, contents, strlen (contents), |
| 236 |
NULL, FALSE, G_FILE_CREATE_PRIVATE, |
| 237 |
NULL, NULL, error); |
| 238 |
g_object_unref (file); |
| 239 |
priv->dirty = FALSE; |
| 240 |
|
| 241 |
exit: |
| 242 |
S_UNLOCK (ews_summary); |
| 243 |
|
| 244 |
g_free (contents); |
| 245 |
return ret; |
| 246 |
} |
| 247 |
|
| 248 |
gboolean |
| 249 |
camel_ews_store_summary_clear (CamelEwsStoreSummary *ews_summary) |
| 250 |
{ |
| 251 |
|
| 252 |
S_LOCK (ews_summary); |
| 253 |
|
| 254 |
g_key_file_free (ews_summary->priv->key_file); |
| 255 |
ews_summary->priv->key_file = g_key_file_new (); |
| 256 |
ews_summary->priv->dirty = TRUE; |
| 257 |
|
| 258 |
S_UNLOCK (ews_summary); |
| 259 |
|
| 260 |
return TRUE; |
| 261 |
} |
| 262 |
|
| 263 |
gboolean |
| 264 |
camel_ews_store_summary_remove (CamelEwsStoreSummary *ews_summary) |
| 265 |
{ |
| 266 |
gint ret; |
| 267 |
|
| 268 |
S_LOCK (ews_summary); |
| 269 |
|
| 270 |
if (ews_summary->priv->key_file) |
| 271 |
camel_ews_store_summary_clear (ews_summary); |
| 272 |
|
| 273 |
ret = g_unlink (ews_summary->priv->path); |
| 274 |
|
| 275 |
S_UNLOCK (ews_summary); |
| 276 |
|
| 277 |
return (ret == 0); |
| 278 |
} |
| 279 |
|
| 280 |
void |
| 281 |
camel_ews_store_summary_rebuild_hashes (CamelEwsStoreSummary *ews_summary) |
| 282 |
{ |
| 283 |
g_return_if_fail (CAMEL_IS_EWS_STORE_SUMMARY (ews_summary)); |
| 284 |
|
| 285 |
S_LOCK (ews_summary); |
| 286 |
load_id_fname_hash (ews_summary); |
| 287 |
S_UNLOCK (ews_summary); |
| 288 |
} |
| 289 |
|
| 290 |
struct subfolder_match { |
| 291 |
GSList *ids; |
| 292 |
gchar *match; |
| 293 |
gsize matchlen; |
| 294 |
}; |
| 295 |
|
| 296 |
static void |
| 297 |
match_subfolder (gpointer key, |
| 298 |
gpointer value, |
| 299 |
gpointer user_data) |
| 300 |
{ |
| 301 |
struct subfolder_match *sm = user_data; |
| 302 |
|
| 303 |
if (!strncmp (key, sm->match, sm->matchlen)) |
| 304 |
sm->ids = g_slist_prepend (sm->ids, g_strdup (value)); |
| 305 |
} |
| 306 |
|
| 307 |
/* Must be called with the summary lock held, and gets to keep |
| 308 |
* both its string arguments */ |
| 309 |
static void |
| 310 |
ews_ss_hash_replace (CamelEwsStoreSummary *ews_summary, |
| 311 |
gchar *folder_id, |
| 312 |
gchar *full_name, |
| 313 |
gboolean recurse) |
| 314 |
{ |
| 315 |
const gchar *ofname; |
| 316 |
struct subfolder_match sm = { NULL, NULL }; |
| 317 |
|
| 318 |
if (!full_name) |
| 319 |
full_name = build_full_name (ews_summary, folder_id); |
| 320 |
|
| 321 |
ofname = g_hash_table_lookup ( |
| 322 |
ews_summary->priv->id_fname_hash, folder_id); |
| 323 |
/* Remove the old fullname->id hash entry *iff* it's pointing |
| 324 |
* to this folder id. */ |
| 325 |
if (ofname) { |
| 326 |
gchar *ofid = g_hash_table_lookup ( |
| 327 |
ews_summary->priv->fname_id_hash, ofname); |
| 328 |
if (ofid && !strcmp (folder_id, ofid)) { |
| 329 |
g_hash_table_remove ( |
| 330 |
ews_summary->priv->fname_id_hash, ofname); |
| 331 |
if (recurse) |
| 332 |
sm.match = g_strdup_printf ("%s/", ofname); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
g_hash_table_insert (ews_summary->priv->fname_id_hash, full_name, folder_id); |
| 337 |
|
| 338 |
/* Replace, not insert. The difference is that it frees the *old* folder_id |
| 339 |
* key, not the new one which we just inserted into fname_id_hash too. */ |
| 340 |
g_hash_table_replace (ews_summary->priv->id_fname_hash, folder_id, full_name); |
| 341 |
|
| 342 |
if (sm.match) { |
| 343 |
GSList *l; |
| 344 |
|
| 345 |
sm.matchlen = strlen (sm.match); |
| 346 |
|
| 347 |
g_hash_table_foreach ( |
| 348 |
ews_summary->priv->fname_id_hash, |
| 349 |
match_subfolder, &sm); |
| 350 |
|
| 351 |
for (l = sm.ids; l; l = g_slist_next (l)) |
| 352 |
ews_ss_hash_replace (ews_summary, l->data, NULL, FALSE); |
| 353 |
|
| 354 |
g_slist_free (sm.ids); |
| 355 |
g_free (sm.match); |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
void |
| 360 |
camel_ews_store_summary_set_folder_name (CamelEwsStoreSummary *ews_summary, |
| 361 |
const gchar *folder_id, |
| 362 |
const gchar *display_name) |
| 363 |
{ |
| 364 |
S_LOCK (ews_summary); |
| 365 |
|
| 366 |
g_key_file_set_string ( |
| 367 |
ews_summary->priv->key_file, |
| 368 |
folder_id, "DisplayName", display_name); |
| 369 |
|
| 370 |
ews_ss_hash_replace (ews_summary, g_strdup (folder_id), NULL, TRUE); |
| 371 |
ews_summary->priv->dirty = TRUE; |
| 372 |
|
| 373 |
S_UNLOCK (ews_summary); |
| 374 |
} |
| 375 |
|
| 376 |
void |
| 377 |
camel_ews_store_summary_new_folder (CamelEwsStoreSummary *ews_summary, |
| 378 |
const gchar *folder_id, |
| 379 |
const gchar *parent_fid, |
| 380 |
const gchar *change_key, |
| 381 |
const gchar *display_name, |
| 382 |
EEwsFolderType folder_type, |
| 383 |
guint64 folder_flags, |
| 384 |
guint64 total, |
| 385 |
gboolean foreign, |
| 386 |
gboolean public_folder) |
| 387 |
{ |
| 388 |
const gchar *folder_type_nick; |
| 389 |
|
| 390 |
/* Store the folder type by its nickname. */ |
| 391 |
folder_type_nick = e_ews_folder_type_to_nick (folder_type); |
| 392 |
g_return_if_fail (folder_type_nick != NULL); |
| 393 |
|
| 394 |
S_LOCK (ews_summary); |
| 395 |
|
| 396 |
if (parent_fid) |
| 397 |
g_key_file_set_string ( |
| 398 |
ews_summary->priv->key_file, |
| 399 |
folder_id, "ParentFolderId", parent_fid); |
| 400 |
if (change_key) |
| 401 |
g_key_file_set_string ( |
| 402 |
ews_summary->priv->key_file, |
| 403 |
folder_id, "ChangeKey", change_key); |
| 404 |
g_key_file_set_string ( |
| 405 |
ews_summary->priv->key_file, |
| 406 |
folder_id, "DisplayName", display_name); |
| 407 |
g_key_file_set_string ( |
| 408 |
ews_summary->priv->key_file, |
| 409 |
folder_id, "FolderType", folder_type_nick); |
| 410 |
if (folder_flags) |
| 411 |
g_key_file_set_uint64 ( |
| 412 |
ews_summary->priv->key_file, |
| 413 |
folder_id, "Flags", folder_flags); |
| 414 |
g_key_file_set_uint64 ( |
| 415 |
ews_summary->priv->key_file, |
| 416 |
folder_id, "Total", total); |
| 417 |
g_key_file_set_boolean ( |
| 418 |
ews_summary->priv->key_file, |
| 419 |
folder_id, "Foreign", foreign); |
| 420 |
g_key_file_set_boolean ( |
| 421 |
ews_summary->priv->key_file, |
| 422 |
folder_id, "Public", public_folder); |
| 423 |
|
| 424 |
ews_ss_hash_replace (ews_summary, g_strdup (folder_id), NULL, FALSE); |
| 425 |
|
| 426 |
ews_summary->priv->dirty = TRUE; |
| 427 |
|
| 428 |
S_UNLOCK (ews_summary); |
| 429 |
} |
| 430 |
|
| 431 |
void |
| 432 |
camel_ews_store_summary_set_parent_folder_id (CamelEwsStoreSummary *ews_summary, |
| 433 |
const gchar *folder_id, |
| 434 |
const gchar *parent_id) |
| 435 |
{ |
| 436 |
S_LOCK (ews_summary); |
| 437 |
|
| 438 |
if (parent_id) |
| 439 |
g_key_file_set_string ( |
| 440 |
ews_summary->priv->key_file, |
| 441 |
folder_id, "ParentFolderId", parent_id); |
| 442 |
else |
| 443 |
g_key_file_remove_key ( |
| 444 |
ews_summary->priv->key_file, |
| 445 |
folder_id, "ParentFolderId", NULL); |
| 446 |
|
| 447 |
ews_ss_hash_replace (ews_summary, g_strdup (folder_id), NULL, TRUE); |
| 448 |
|
| 449 |
ews_summary->priv->dirty = TRUE; |
| 450 |
|
| 451 |
S_UNLOCK (ews_summary); |
| 452 |
} |
| 453 |
|
| 454 |
void |
| 455 |
camel_ews_store_summary_set_change_key (CamelEwsStoreSummary *ews_summary, |
| 456 |
const gchar *folder_id, |
| 457 |
const gchar *change_key) |
| 458 |
{ |
| 459 |
S_LOCK (ews_summary); |
| 460 |
|
| 461 |
g_key_file_set_string ( |
| 462 |
ews_summary->priv->key_file, |
| 463 |
folder_id, "ChangeKey", change_key); |
| 464 |
ews_summary->priv->dirty = TRUE; |
| 465 |
|
| 466 |
S_UNLOCK (ews_summary); |
| 467 |
} |
| 468 |
|
| 469 |
void |
| 470 |
camel_ews_store_summary_set_sync_state (CamelEwsStoreSummary *ews_summary, |
| 471 |
const gchar *folder_id, |
| 472 |
const gchar *sync_state) |
| 473 |
{ |
| 474 |
S_LOCK (ews_summary); |
| 475 |
|
| 476 |
g_key_file_set_string ( |
| 477 |
ews_summary->priv->key_file, |
| 478 |
folder_id, "SyncState", sync_state); |
| 479 |
ews_summary->priv->dirty = TRUE; |
| 480 |
|
| 481 |
S_UNLOCK (ews_summary); |
| 482 |
} |
| 483 |
|
| 484 |
void |
| 485 |
camel_ews_store_summary_set_folder_flags (CamelEwsStoreSummary *ews_summary, |
| 486 |
const gchar *folder_id, |
| 487 |
guint64 flags) |
| 488 |
{ |
| 489 |
S_LOCK (ews_summary); |
| 490 |
|
| 491 |
g_key_file_set_uint64 ( |
| 492 |
ews_summary->priv->key_file, |
| 493 |
folder_id, "Flags", flags); |
| 494 |
ews_summary->priv->dirty = TRUE; |
| 495 |
|
| 496 |
S_UNLOCK (ews_summary); |
| 497 |
} |
| 498 |
|
| 499 |
void |
| 500 |
camel_ews_store_summary_set_folder_unread (CamelEwsStoreSummary *ews_summary, |
| 501 |
const gchar *folder_id, |
| 502 |
guint64 unread) |
| 503 |
{ |
| 504 |
S_LOCK (ews_summary); |
| 505 |
|
| 506 |
g_key_file_set_uint64 ( |
| 507 |
ews_summary->priv->key_file, |
| 508 |
folder_id, "UnRead", unread); |
| 509 |
ews_summary->priv->dirty = TRUE; |
| 510 |
|
| 511 |
S_UNLOCK (ews_summary); |
| 512 |
} |
| 513 |
|
| 514 |
void |
| 515 |
camel_ews_store_summary_set_folder_total (CamelEwsStoreSummary *ews_summary, |
| 516 |
const gchar *folder_id, |
| 517 |
guint64 total) |
| 518 |
{ |
| 519 |
S_LOCK (ews_summary); |
| 520 |
|
| 521 |
g_key_file_set_uint64 ( |
| 522 |
ews_summary->priv->key_file, |
| 523 |
folder_id, "Total", total); |
| 524 |
ews_summary->priv->dirty = TRUE; |
| 525 |
|
| 526 |
S_UNLOCK (ews_summary); |
| 527 |
} |
| 528 |
|
| 529 |
void |
| 530 |
camel_ews_store_summary_set_folder_type (CamelEwsStoreSummary *ews_summary, |
| 531 |
const gchar *folder_id, |
| 532 |
EEwsFolderType folder_type) |
| 533 |
{ |
| 534 |
const gchar *folder_type_nick; |
| 535 |
|
| 536 |
/* Store the folder type by its nickname. */ |
| 537 |
folder_type_nick = e_ews_folder_type_to_nick (folder_type); |
| 538 |
g_return_if_fail (folder_type_nick != NULL); |
| 539 |
|
| 540 |
S_LOCK (ews_summary); |
| 541 |
|
| 542 |
g_key_file_set_string ( |
| 543 |
ews_summary->priv->key_file, |
| 544 |
folder_id, "FolderType", folder_type_nick); |
| 545 |
ews_summary->priv->dirty = TRUE; |
| 546 |
|
| 547 |
S_UNLOCK (ews_summary); |
| 548 |
} |
| 549 |
|
| 550 |
void |
| 551 |
camel_ews_store_summary_set_foreign (CamelEwsStoreSummary *ews_summary, |
| 552 |
const gchar *folder_id, |
| 553 |
gboolean is_foreign) |
| 554 |
{ |
| 555 |
S_LOCK (ews_summary); |
| 556 |
|
| 557 |
g_key_file_set_boolean ( |
| 558 |
ews_summary->priv->key_file, |
| 559 |
folder_id, "Foreign", is_foreign); |
| 560 |
ews_summary->priv->dirty = TRUE; |
| 561 |
|
| 562 |
S_UNLOCK (ews_summary); |
| 563 |
} |
| 564 |
|
| 565 |
void |
| 566 |
camel_ews_store_summary_set_foreign_subfolders (CamelEwsStoreSummary *ews_summary, |
| 567 |
const gchar *folder_id, |
| 568 |
gboolean foreign_subfolders) |
| 569 |
{ |
| 570 |
S_LOCK (ews_summary); |
| 571 |
|
| 572 |
g_key_file_set_boolean ( |
| 573 |
ews_summary->priv->key_file, |
| 574 |
folder_id, "ForeignSubfolders", foreign_subfolders); |
| 575 |
ews_summary->priv->dirty = TRUE; |
| 576 |
|
| 577 |
S_UNLOCK (ews_summary); |
| 578 |
} |
| 579 |
|
| 580 |
void |
| 581 |
camel_ews_store_summary_set_public (CamelEwsStoreSummary *ews_summary, |
| 582 |
const gchar *folder_id, |
| 583 |
gboolean is_public) |
| 584 |
{ |
| 585 |
S_LOCK (ews_summary); |
| 586 |
|
| 587 |
g_key_file_set_boolean ( |
| 588 |
ews_summary->priv->key_file, |
| 589 |
folder_id, "Public", is_public); |
| 590 |
ews_summary->priv->dirty = TRUE; |
| 591 |
|
| 592 |
S_UNLOCK (ews_summary); |
| 593 |
} |
| 594 |
|
| 595 |
void |
| 596 |
camel_ews_store_summary_store_string_val (CamelEwsStoreSummary *ews_summary, |
| 597 |
const gchar *key, |
| 598 |
const gchar *value) |
| 599 |
{ |
| 600 |
S_LOCK (ews_summary); |
| 601 |
|
| 602 |
g_key_file_set_string ( |
| 603 |
ews_summary->priv->key_file, |
| 604 |
STORE_GROUP_NAME, key, value); |
| 605 |
ews_summary->priv->dirty = TRUE; |
| 606 |
|
| 607 |
S_UNLOCK (ews_summary); |
| 608 |
} |
| 609 |
|
| 610 |
gchar * |
| 611 |
camel_ews_store_summary_get_folder_name (CamelEwsStoreSummary *ews_summary, |
| 612 |
const gchar *folder_id, |
| 613 |
GError **error) |
| 614 |
{ |
| 615 |
gchar *ret; |
| 616 |
|
| 617 |
S_LOCK (ews_summary); |
| 618 |
|
| 619 |
ret = g_key_file_get_string ( |
| 620 |
ews_summary->priv->key_file, folder_id, |
| 621 |
"DisplayName", error); |
| 622 |
|
| 623 |
S_UNLOCK (ews_summary); |
| 624 |
|
| 625 |
return ret; |
| 626 |
} |
| 627 |
|
| 628 |
gchar * |
| 629 |
camel_ews_store_summary_get_folder_full_name (CamelEwsStoreSummary *ews_summary, |
| 630 |
const gchar *folder_id, |
| 631 |
GError **error) |
| 632 |
{ |
| 633 |
gchar *ret; |
| 634 |
|
| 635 |
S_LOCK (ews_summary); |
| 636 |
|
| 637 |
ret = g_hash_table_lookup (ews_summary->priv->id_fname_hash, folder_id); |
| 638 |
|
| 639 |
if (ret) |
| 640 |
ret = g_strdup (ret); |
| 641 |
|
| 642 |
S_UNLOCK (ews_summary); |
| 643 |
|
| 644 |
return ret; |
| 645 |
} |
| 646 |
|
| 647 |
gchar * |
| 648 |
camel_ews_store_summary_get_parent_folder_id (CamelEwsStoreSummary *ews_summary, |
| 649 |
const gchar *folder_id, |
| 650 |
GError **error) |
| 651 |
{ |
| 652 |
gchar *ret; |
| 653 |
|
| 654 |
S_LOCK (ews_summary); |
| 655 |
|
| 656 |
ret = g_key_file_get_string ( |
| 657 |
ews_summary->priv->key_file, folder_id, |
| 658 |
"ParentFolderId", error); |
| 659 |
|
| 660 |
S_UNLOCK (ews_summary); |
| 661 |
|
| 662 |
return ret; |
| 663 |
} |
| 664 |
|
| 665 |
gchar * |
| 666 |
camel_ews_store_summary_get_change_key (CamelEwsStoreSummary *ews_summary, |
| 667 |
const gchar *folder_id, |
| 668 |
GError **error) |
| 669 |
{ |
| 670 |
gchar *ret; |
| 671 |
|
| 672 |
S_LOCK (ews_summary); |
| 673 |
|
| 674 |
ret = g_key_file_get_string ( |
| 675 |
ews_summary->priv->key_file, folder_id, |
| 676 |
"ChangeKey", error); |
| 677 |
|
| 678 |
S_UNLOCK (ews_summary); |
| 679 |
|
| 680 |
return ret; |
| 681 |
} |
| 682 |
|
| 683 |
gchar * |
| 684 |
camel_ews_store_summary_get_sync_state (CamelEwsStoreSummary *ews_summary, |
| 685 |
const gchar *folder_id, |
| 686 |
GError **error) |
| 687 |
{ |
| 688 |
gchar *ret; |
| 689 |
|
| 690 |
S_LOCK (ews_summary); |
| 691 |
|
| 692 |
ret = g_key_file_get_string ( |
| 693 |
ews_summary->priv->key_file, folder_id, |
| 694 |
"SyncState", error); |
| 695 |
|
| 696 |
S_UNLOCK (ews_summary); |
| 697 |
|
| 698 |
return ret; |
| 699 |
} |
| 700 |
|
| 701 |
guint64 |
| 702 |
camel_ews_store_summary_get_folder_flags (CamelEwsStoreSummary *ews_summary, |
| 703 |
const gchar *folder_id, |
| 704 |
GError **error) |
| 705 |
{ |
| 706 |
guint64 ret; |
| 707 |
|
| 708 |
S_LOCK (ews_summary); |
| 709 |
|
| 710 |
ret = g_key_file_get_uint64 ( |
| 711 |
ews_summary->priv->key_file, folder_id, |
| 712 |
"Flags", error); |
| 713 |
|
| 714 |
S_UNLOCK (ews_summary); |
| 715 |
|
| 716 |
return ret; |
| 717 |
} |
| 718 |
|
| 719 |
guint64 |
| 720 |
camel_ews_store_summary_get_folder_unread (CamelEwsStoreSummary *ews_summary, |
| 721 |
const gchar *folder_id, |
| 722 |
GError **error) |
| 723 |
{ |
| 724 |
guint64 ret; |
| 725 |
|
| 726 |
S_LOCK (ews_summary); |
| 727 |
|
| 728 |
ret = g_key_file_get_uint64 ( |
| 729 |
ews_summary->priv->key_file, folder_id, |
| 730 |
"UnRead", error); |
| 731 |
|
| 732 |
S_UNLOCK (ews_summary); |
| 733 |
|
| 734 |
return ret; |
| 735 |
} |
| 736 |
|
| 737 |
guint64 |
| 738 |
camel_ews_store_summary_get_folder_total (CamelEwsStoreSummary *ews_summary, |
| 739 |
const gchar *folder_id, |
| 740 |
GError **error) |
| 741 |
{ |
| 742 |
guint64 ret; |
| 743 |
|
| 744 |
S_LOCK (ews_summary); |
| 745 |
|
| 746 |
ret = g_key_file_get_uint64 ( |
| 747 |
ews_summary->priv->key_file, folder_id, |
| 748 |
"Total", error); |
| 749 |
|
| 750 |
S_UNLOCK (ews_summary); |
| 751 |
|
| 752 |
return ret; |
| 753 |
} |
| 754 |
|
| 755 |
EEwsFolderType |
| 756 |
camel_ews_store_summary_get_folder_type (CamelEwsStoreSummary *ews_summary, |
| 757 |
const gchar *folder_id, |
| 758 |
GError **error) |
| 759 |
{ |
| 760 |
EEwsFolderType folder_type; |
| 761 |
gchar *folder_type_nick; |
| 762 |
|
| 763 |
S_LOCK (ews_summary); |
| 764 |
|
| 765 |
folder_type_nick = g_key_file_get_string ( |
| 766 |
ews_summary->priv->key_file, |
| 767 |
folder_id, "FolderType", error); |
| 768 |
|
| 769 |
S_UNLOCK (ews_summary); |
| 770 |
|
| 771 |
/* Look up the folder type by its nickname. */ |
| 772 |
if (folder_type_nick != NULL) |
| 773 |
folder_type = e_ews_folder_type_from_nick (folder_type_nick); |
| 774 |
else |
| 775 |
folder_type = E_EWS_FOLDER_TYPE_UNKNOWN; |
| 776 |
|
| 777 |
g_free (folder_type_nick); |
| 778 |
|
| 779 |
return folder_type; |
| 780 |
} |
| 781 |
|
| 782 |
gboolean |
| 783 |
camel_ews_store_summary_get_foreign (CamelEwsStoreSummary *ews_summary, |
| 784 |
const gchar *folder_id, |
| 785 |
GError **error) |
| 786 |
{ |
| 787 |
gboolean ret; |
| 788 |
|
| 789 |
S_LOCK (ews_summary); |
| 790 |
|
| 791 |
ret = g_key_file_get_boolean ( |
| 792 |
ews_summary->priv->key_file, folder_id, "Foreign", error); |
| 793 |
|
| 794 |
S_UNLOCK (ews_summary); |
| 795 |
|
| 796 |
return ret; |
| 797 |
} |
| 798 |
|
| 799 |
gboolean |
| 800 |
camel_ews_store_summary_get_foreign_subfolders (CamelEwsStoreSummary *ews_summary, |
| 801 |
const gchar *folder_id, |
| 802 |
GError **error) |
| 803 |
{ |
| 804 |
gboolean ret; |
| 805 |
|
| 806 |
S_LOCK (ews_summary); |
| 807 |
|
| 808 |
ret = g_key_file_get_boolean ( |
| 809 |
ews_summary->priv->key_file, folder_id, "ForeignSubfolders", error); |
| 810 |
|
| 811 |
S_UNLOCK (ews_summary); |
| 812 |
|
| 813 |
return ret; |
| 814 |
} |
| 815 |
|
| 816 |
gboolean |
| 817 |
camel_ews_store_summary_get_public (CamelEwsStoreSummary *ews_summary, |
| 818 |
const gchar *folder_id, |
| 819 |
GError **error) |
| 820 |
{ |
| 821 |
gboolean ret; |
| 822 |
|
| 823 |
S_LOCK (ews_summary); |
| 824 |
|
| 825 |
ret = g_key_file_get_boolean ( |
| 826 |
ews_summary->priv->key_file, folder_id, "Public", error); |
| 827 |
|
| 828 |
S_UNLOCK (ews_summary); |
| 829 |
|
| 830 |
return ret; |
| 831 |
} |
| 832 |
|
| 833 |
gchar * |
| 834 |
camel_ews_store_summary_get_string_val (CamelEwsStoreSummary *ews_summary, |
| 835 |
const gchar *key, |
| 836 |
GError **error) |
| 837 |
{ |
| 838 |
gchar *ret; |
| 839 |
|
| 840 |
S_LOCK (ews_summary); |
| 841 |
|
| 842 |
ret = g_key_file_get_string ( |
| 843 |
ews_summary->priv->key_file, STORE_GROUP_NAME, |
| 844 |
key, error); |
| 845 |
|
| 846 |
S_UNLOCK (ews_summary); |
| 847 |
|
| 848 |
return ret; |
| 849 |
} |
| 850 |
|
| 851 |
GSList * |
| 852 |
camel_ews_store_summary_get_folders (CamelEwsStoreSummary *ews_summary, |
| 853 |
const gchar *prefix, |
| 854 |
gboolean only_direct_subfolders) |
| 855 |
{ |
| 856 |
GSList *folders = NULL; |
| 857 |
gchar **groups = NULL; |
| 858 |
gsize length; |
| 859 |
gint prefixlen = 0; |
| 860 |
gint i; |
| 861 |
|
| 862 |
if (prefix) |
| 863 |
prefixlen = strlen (prefix); |
| 864 |
|
| 865 |
S_LOCK (ews_summary); |
| 866 |
|
| 867 |
groups = g_key_file_get_groups (ews_summary->priv->key_file, &length); |
| 868 |
|
| 869 |
S_UNLOCK (ews_summary); |
| 870 |
|
| 871 |
for (i = 0; i < length; i++) { |
| 872 |
if (!g_ascii_strcasecmp (groups[i], STORE_GROUP_NAME)) |
| 873 |
continue; |
| 874 |
if (prefixlen) { |
| 875 |
const gchar *fname; |
| 876 |
|
| 877 |
fname = g_hash_table_lookup ( |
| 878 |
ews_summary->priv->id_fname_hash, groups[i]); |
| 879 |
|
| 880 |
if (!fname || strncmp (fname, prefix, prefixlen) || |
| 881 |
(fname[prefixlen] && fname[prefixlen] != '/') || |
| 882 |
(only_direct_subfolders && (!fname[prefixlen] || strchr (fname + prefixlen + 1, '/')))) |
| 883 |
continue; |
| 884 |
} |
| 885 |
folders = g_slist_append (folders, g_strdup (groups[i])); |
| 886 |
} |
| 887 |
|
| 888 |
g_strfreev (groups); |
| 889 |
return folders; |
| 890 |
} |
| 891 |
|
| 892 |
/* get list of folder IDs, which are foreign folders */ |
| 893 |
GSList * |
| 894 |
camel_ews_store_summary_get_foreign_folders (CamelEwsStoreSummary *ews_summary, |
| 895 |
const gchar *prefix) |
| 896 |
{ |
| 897 |
GSList *folders = NULL; |
| 898 |
gchar **groups = NULL; |
| 899 |
gsize length; |
| 900 |
gint prefixlen = 0; |
| 901 |
gint i; |
| 902 |
|
| 903 |
if (prefix) |
| 904 |
prefixlen = strlen (prefix); |
| 905 |
|
| 906 |
S_LOCK (ews_summary); |
| 907 |
|
| 908 |
groups = g_key_file_get_groups (ews_summary->priv->key_file, &length); |
| 909 |
|
| 910 |
S_UNLOCK (ews_summary); |
| 911 |
|
| 912 |
for (i = 0; i < length; i++) { |
| 913 |
if (!g_ascii_strcasecmp (groups[i], STORE_GROUP_NAME)) |
| 914 |
continue; |
| 915 |
|
| 916 |
if (!camel_ews_store_summary_get_foreign (ews_summary, groups[i], NULL)) |
| 917 |
continue; |
| 918 |
|
| 919 |
if (prefixlen) { |
| 920 |
const gchar *fname; |
| 921 |
|
| 922 |
fname = g_hash_table_lookup ( |
| 923 |
ews_summary->priv->id_fname_hash, groups[i]); |
| 924 |
|
| 925 |
if (!fname || strncmp (fname, prefix, prefixlen) || |
| 926 |
(fname[prefixlen] && fname[prefixlen] != '/')) |
| 927 |
continue; |
| 928 |
} |
| 929 |
|
| 930 |
folders = g_slist_append (folders, g_strdup (groups[i])); |
| 931 |
} |
| 932 |
|
| 933 |
g_strfreev (groups); |
| 934 |
|
| 935 |
return folders; |
| 936 |
} |
| 937 |
|
| 938 |
gboolean |
| 939 |
camel_ews_store_summary_remove_folder (CamelEwsStoreSummary *ews_summary, |
| 940 |
const gchar *folder_id, |
| 941 |
GError **error) |
| 942 |
{ |
| 943 |
gboolean ret = FALSE; |
| 944 |
gchar *full_name; |
| 945 |
|
| 946 |
S_LOCK (ews_summary); |
| 947 |
|
| 948 |
full_name = g_hash_table_lookup (ews_summary->priv->id_fname_hash, folder_id); |
| 949 |
if (!full_name) |
| 950 |
goto unlock; |
| 951 |
|
| 952 |
ret = g_key_file_remove_group ( |
| 953 |
ews_summary->priv->key_file, folder_id, error); |
| 954 |
|
| 955 |
g_hash_table_remove (ews_summary->priv->fname_id_hash, full_name); |
| 956 |
g_hash_table_remove (ews_summary->priv->id_fname_hash, folder_id); |
| 957 |
|
| 958 |
ews_summary->priv->dirty = TRUE; |
| 959 |
|
| 960 |
unlock: |
| 961 |
S_UNLOCK (ews_summary); |
| 962 |
|
| 963 |
return ret; |
| 964 |
} |
| 965 |
|
| 966 |
gchar * |
| 967 |
camel_ews_store_summary_get_folder_id_from_name (CamelEwsStoreSummary *ews_summary, |
| 968 |
const gchar *folder_name) |
| 969 |
{ |
| 970 |
gchar *folder_id; |
| 971 |
|
| 972 |
g_return_val_if_fail (ews_summary != NULL, NULL); |
| 973 |
g_return_val_if_fail (folder_name != NULL, NULL); |
| 974 |
|
| 975 |
S_LOCK (ews_summary); |
| 976 |
|
| 977 |
folder_id = g_hash_table_lookup (ews_summary->priv->fname_id_hash, folder_name); |
| 978 |
if (folder_id) |
| 979 |
folder_id = g_strdup (folder_id); |
| 980 |
|
| 981 |
S_UNLOCK (ews_summary); |
| 982 |
|
| 983 |
return folder_id; |
| 984 |
} |
| 985 |
|
| 986 |
gchar * |
| 987 |
camel_ews_store_summary_get_folder_id_from_folder_type (CamelEwsStoreSummary *ews_summary, |
| 988 |
guint64 folder_type) |
| 989 |
{ |
| 990 |
gchar *folder_id = NULL; |
| 991 |
GSList *folders, *l; |
| 992 |
|
| 993 |
g_return_val_if_fail (ews_summary != NULL, NULL); |
| 994 |
g_return_val_if_fail ((folder_type & CAMEL_FOLDER_TYPE_MASK) != 0, NULL); |
| 995 |
|
| 996 |
folder_type = folder_type & CAMEL_FOLDER_TYPE_MASK; |
| 997 |
|
| 998 |
S_LOCK (ews_summary); |
| 999 |
|
| 1000 |
folders = camel_ews_store_summary_get_folders (ews_summary, NULL, FALSE); |
| 1001 |
|
| 1002 |
for (l = folders; l != NULL; l = g_slist_next (l)) { |
| 1003 |
gchar *id = l->data; |
| 1004 |
guint64 folder_flags; |
| 1005 |
|
| 1006 |
folder_flags = camel_ews_store_summary_get_folder_flags ( |
| 1007 |
ews_summary, id, NULL); |
| 1008 |
if ((folder_flags & CAMEL_FOLDER_TYPE_MASK) == folder_type && |
| 1009 |
(folder_flags & CAMEL_FOLDER_SYSTEM) != 0) { |
| 1010 |
folder_id = id; |
| 1011 |
l->data = NULL; |
| 1012 |
break; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
g_slist_free_full (folders, g_free); |
| 1017 |
|
| 1018 |
S_UNLOCK (ews_summary); |
| 1019 |
|
| 1020 |
return folder_id; |
| 1021 |
} |
| 1022 |
|
| 1023 |
gboolean |
| 1024 |
camel_ews_store_summary_has_folder (CamelEwsStoreSummary *ews_summary, |
| 1025 |
const gchar *folder_id) |
| 1026 |
{ |
| 1027 |
gboolean ret; |
| 1028 |
|
| 1029 |
S_LOCK (ews_summary); |
| 1030 |
|
| 1031 |
ret = g_key_file_has_group (ews_summary->priv->key_file, folder_id); |
| 1032 |
|
| 1033 |
S_UNLOCK (ews_summary); |
| 1034 |
|
| 1035 |
return ret; |
| 1036 |
} |
| 1037 |
|
| 1038 |
static gchar * |
| 1039 |
camel_ews_category_to_string (const CamelEwsCategory *cat) |
| 1040 |
{ |
| 1041 |
gchar *guid, *name, *color_def = NULL, *str; |
| 1042 |
|
| 1043 |
g_return_val_if_fail (cat != NULL, NULL); |
| 1044 |
|
| 1045 |
guid = g_uri_escape_string (cat->guid, NULL, TRUE); |
| 1046 |
name = g_uri_escape_string (cat->name, NULL, TRUE); |
| 1047 |
|
| 1048 |
if (cat->color_def) |
| 1049 |
color_def = g_uri_escape_string (cat->color_def, NULL, TRUE); |
| 1050 |
|
| 1051 |
str = g_strconcat ( |
| 1052 |
guid ? guid : "", "\t", |
| 1053 |
name ? name : "", "\t", |
| 1054 |
color_def ? color_def : "", |
| 1055 |
NULL); |
| 1056 |
|
| 1057 |
g_free (guid); |
| 1058 |
g_free (name); |
| 1059 |
g_free (color_def); |
| 1060 |
|
| 1061 |
return str; |
| 1062 |
} |
| 1063 |
|
| 1064 |
static CamelEwsCategory * |
| 1065 |
camel_ews_category_from_string (const gchar *str) |
| 1066 |
{ |
| 1067 |
CamelEwsCategory *cat; |
| 1068 |
gchar **strv, *guid, *name, *color_def; |
| 1069 |
|
| 1070 |
g_return_val_if_fail (str != NULL, NULL); |
| 1071 |
|
| 1072 |
strv = g_strsplit (str, "\t", -1); |
| 1073 |
if (!strv || !strv[0] || !strv[1]) { |
| 1074 |
g_strfreev (strv); |
| 1075 |
return NULL; |
| 1076 |
} |
| 1077 |
|
| 1078 |
guid = g_uri_unescape_string (strv[0], NULL); |
| 1079 |
name = g_uri_unescape_string (strv[1], NULL); |
| 1080 |
color_def = (strv[2] && strv[2][0]) ? g_uri_unescape_string (strv[2], NULL) : NULL; |
| 1081 |
|
| 1082 |
cat = camel_ews_category_new (guid, name, color_def); |
| 1083 |
|
| 1084 |
g_free (guid); |
| 1085 |
g_free (name); |
| 1086 |
g_free (color_def); |
| 1087 |
g_strfreev (strv); |
| 1088 |
|
| 1089 |
return cat; |
| 1090 |
} |
| 1091 |
|
| 1092 |
GHashTable * /* gchar *guid ~> CamelEwsCategory * */ |
| 1093 |
camel_ews_store_summary_get_categories (CamelEwsStoreSummary *ews_summary) |
| 1094 |
{ |
| 1095 |
GHashTable *categories; |
| 1096 |
gchar **strv; |
| 1097 |
g_return_val_if_fail (CAMEL_IS_EWS_STORE_SUMMARY (ews_summary), NULL); |
| 1098 |
|
| 1099 |
S_LOCK (ews_summary); |
| 1100 |
|
| 1101 |
strv = g_key_file_get_string_list (ews_summary->priv->key_file, STORE_GROUP_NAME, CATEGORIES_KEY, NULL, NULL); |
| 1102 |
|
| 1103 |
S_UNLOCK (ews_summary); |
| 1104 |
|
| 1105 |
categories = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, camel_ews_category_free); |
| 1106 |
|
| 1107 |
if (strv) { |
| 1108 |
gint ii; |
| 1109 |
|
| 1110 |
for (ii = 0; strv[ii]; ii++) { |
| 1111 |
CamelEwsCategory *cat; |
| 1112 |
|
| 1113 |
cat = camel_ews_category_from_string (strv[ii]); |
| 1114 |
if (cat) |
| 1115 |
g_hash_table_insert (categories, cat->guid, cat); |
| 1116 |
} |
| 1117 |
|
| 1118 |
g_strfreev (strv); |
| 1119 |
} |
| 1120 |
|
| 1121 |
return categories; |
| 1122 |
} |
| 1123 |
|
| 1124 |
void |
| 1125 |
camel_ews_store_summary_set_categories (CamelEwsStoreSummary *ews_summary, |
| 1126 |
GHashTable *categories) /* gchar *guid ~> CamelEwsCategory * */ |
| 1127 |
{ |
| 1128 |
GPtrArray *array; |
| 1129 |
GHashTableIter iter; |
| 1130 |
gpointer value; |
| 1131 |
|
| 1132 |
g_return_if_fail (CAMEL_IS_EWS_STORE_SUMMARY (ews_summary)); |
| 1133 |
g_return_if_fail (categories != NULL); |
| 1134 |
|
| 1135 |
array = g_ptr_array_new_full (g_hash_table_size (categories), g_free); |
| 1136 |
|
| 1137 |
g_hash_table_iter_init (&iter, categories); |
| 1138 |
while (g_hash_table_iter_next (&iter, NULL, &value)) { |
| 1139 |
CamelEwsCategory *cat = value; |
| 1140 |
|
| 1141 |
if (cat) { |
| 1142 |
gchar *str; |
| 1143 |
|
| 1144 |
str = camel_ews_category_to_string (cat); |
| 1145 |
|
| 1146 |
if (str) |
| 1147 |
g_ptr_array_add (array, str); |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
S_LOCK (ews_summary); |
| 1152 |
|
| 1153 |
g_key_file_set_string_list (ews_summary->priv->key_file, STORE_GROUP_NAME, CATEGORIES_KEY, |
| 1154 |
(const gchar * const *) array->pdata, array->len); |
| 1155 |
|
| 1156 |
ews_summary->priv->dirty = TRUE; |
| 1157 |
|
| 1158 |
S_UNLOCK (ews_summary); |
| 1159 |
|
| 1160 |
g_ptr_array_free (array, TRUE); |
| 1161 |
} |
| 1162 |
|
| 1163 |
CamelEwsCategory * |
| 1164 |
camel_ews_category_new (const gchar *guid, |
| 1165 |
const gchar *name, |
| 1166 |
const gchar *color_def) |
| 1167 |
{ |
| 1168 |
CamelEwsCategory *cat; |
| 1169 |
|
| 1170 |
g_return_val_if_fail (guid != NULL, NULL); |
| 1171 |
g_return_val_if_fail (name != NULL, NULL); |
| 1172 |
|
| 1173 |
cat = g_new0 (CamelEwsCategory, 1); |
| 1174 |
cat->guid = g_strdup (guid); |
| 1175 |
cat->name = g_strdup (name); |
| 1176 |
cat->color_def = g_strdup (color_def); |
| 1177 |
|
| 1178 |
return cat; |
| 1179 |
} |
| 1180 |
|
| 1181 |
void |
| 1182 |
camel_ews_category_free (gpointer ptr) |
| 1183 |
{ |
| 1184 |
CamelEwsCategory *cat = ptr; |
| 1185 |
|
| 1186 |
if (cat) { |
| 1187 |
g_free (cat->guid); |
| 1188 |
g_free (cat->name); |
| 1189 |
g_free (cat->color_def); |
| 1190 |
g_free (cat); |
| 1191 |
} |
| 1192 |
} |