diff options
author | NotZed <NotZed@HelixCode.com> | 2000-05-18 03:24:24 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-05-18 03:24:24 +0800 |
commit | 14bc1cbfc8a8c492e4a280655238159e004c53b3 (patch) | |
tree | a7c0f3dd3a277667989ca4f2d5f17a7a0d3a4b42 /camel/camel-mime-message.c | |
parent | da0a13df5e4c8fdbf524a1a9f1ee9e593f5f0100 (diff) | |
download | gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.tar gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.tar.gz gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.tar.bz2 gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.tar.lz gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.tar.xz gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.tar.zst gsoc2013-evolution-14bc1cbfc8a8c492e4a280655238159e004c53b3.zip |
All this basically to support user flags in the summary. They are not yet
All this basically to support user flags in the summary. They
are not yet saved to the message headers (complicates things a bit).
2000-05-17 NotZed <NotZed@HelixCode.com>
* providers/mbox/camel-mbox-folder.c (message_changed): Snoop
changes to user flags on the message into the summary as well.
* providers/mbox/camel-mbox-summary.c (camel_mbox_summary_init):
Changed version init to include the parent class version info
(i.e. add it not overwrite it).
* camel-folder-summary.c (message_info_new): Initialise user_flags
to empty.
(message_info_load): And load user flags.
(message_info_save): And save user flags.
(message_info_free): And free them.
(CAMEL_FOLDER_SUMMARY_VERSION): Bumped file revision.
* camel-folder-summary.h: Added user-flags to summary.
* camel-mime-message.c (camel_mime_message_set_user_flag): Dont
use a hashtable for user flags.
(camel_mime_message_get_user_flag): And changed here too.
(camel_flag_get): New interface to get a flag from a flag
list. Flag lists are easier to work with than hash tables, and
save memory too.
(camel_flag_set): And set.
(camel_flag_list_free): And free.
(free_key_only): Discard.
(finalize): Remove the flag list.
svn path=/trunk/; revision=3107
Diffstat (limited to 'camel/camel-mime-message.c')
-rw-r--r-- | camel/camel-mime-message.c | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c index 7c28949856..f65691909f 100644 --- a/camel/camel-mime-message.c +++ b/camel/camel-mime-message.c @@ -136,7 +136,7 @@ camel_mime_message_init (gpointer object, gpointer klass) g_hash_table_insert(mime_message->recipients, recipient_names[i], camel_internet_address_new()); } - mime_message->user_flags = g_hash_table_new (g_strcase_hash, g_strcase_equal); + mime_message->user_flags = NULL; mime_message->flags = 0; mime_message->subject = NULL; @@ -179,11 +179,6 @@ static void g_lib_is_uber_crappy_shit(gpointer whocares, gpointer getlost, gpoin gtk_object_unref((GtkObject *)getlost); } -static void free_key_only(gpointer whocares, gpointer getlost, gpointer blah) -{ - g_free(whocares); -} - static void finalize (GtkObject *object) { @@ -199,9 +194,7 @@ finalize (GtkObject *object) g_hash_table_foreach (message->recipients, g_lib_is_uber_crappy_shit, NULL); g_hash_table_destroy(message->recipients); - if (message->user_flags) - g_hash_table_foreach (message->user_flags, free_key_only, NULL); - g_hash_table_destroy(message->user_flags); + camel_flag_list_free(&message->user_flags); if (message->folder) gtk_object_unref (GTK_OBJECT (message->folder)); @@ -455,28 +448,87 @@ camel_mime_message_set_flags (CamelMimeMessage *m, guint32 flags, guint32 set) } gboolean +camel_flag_get(CamelFlag **list, const char *name) +{ + CamelFlag *flag; + flag = *list; + while (flag) { + if (!strcmp(flag->name, name)) + return TRUE; + flag = flag->next; + } + return FALSE; +} + +void +camel_flag_set(CamelFlag **list, const char *name, gboolean value) +{ + CamelFlag *flag, *tmp; + + /* this 'trick' works because flag->next is the first element */ + flag = (CamelFlag *)list; + while (flag->next) { + tmp = flag->next; + if (!strcmp(flag->next->name, name)) { + if (!value) { + flag->next = tmp->next; + g_free(tmp); + } + return; + } + flag = tmp; + } + + if (value) { + tmp = g_malloc(sizeof(*tmp) + strlen(name)); + strcpy(tmp->name, name); + tmp->next = 0; + flag->next = tmp; + } +} + +int +camel_flag_list_size(CamelFlag **list) +{ + int count=0; + CamelFlag *flag; + + flag = *list; + while (flag) { + count++; + flag = flag->next; + } + return count; +} + +void +camel_flag_list_free(CamelFlag **list) +{ + CamelFlag *flag, *tmp; + flag = *list; + while (flag) { + tmp = flag->next; + g_free(flag); + flag = tmp; + } + *list = NULL; +} + +gboolean camel_mime_message_get_user_flag (CamelMimeMessage *m, const char *name) { - return (gboolean)g_hash_table_lookup(m->user_flags, name); + g_return_val_if_fail(m->flags & CAMEL_MESSAGE_USER, FALSE); + + return camel_flag_get(&m->user_flags, name); } void camel_mime_message_set_user_flag (CamelMimeMessage *m, const char *name, gboolean value) { - gboolean there; - char *oldname; - gboolean oldvalue; - - there = g_hash_table_lookup_extended(m->user_flags, name, (void *)&oldname, (void *)&oldvalue); + g_return_if_fail(m->flags & CAMEL_MESSAGE_USER); - if (value && !there) { - g_hash_table_insert(m->user_flags, g_strdup(name), (void *)TRUE); - gtk_signal_emit((GtkObject *)m, signals[MESSAGE_CHANGED], MESSAGE_FLAGS_CHANGED); - } else if (there) { - g_hash_table_remove(m->user_flags, name); - g_free(oldname); - gtk_signal_emit((GtkObject *)m, signals[MESSAGE_CHANGED], MESSAGE_FLAGS_CHANGED); - } + camel_flag_set(&m->user_flags, name, value); + gtk_signal_emit((GtkObject *)m, signals[MESSAGE_CHANGED], MESSAGE_FLAGS_CHANGED); } |