[evolution/express2-daemon: 4/9] Emit multiple events while receiving new mails. Also add a api to get folder_uri from cache.
- From: Srinivasa Ragavan <sragavan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/express2-daemon: 4/9] Emit multiple events while receiving new mails. Also add a api to get folder_uri from cache.
- Date: Thu, 17 Jun 2010 08:05:40 +0000 (UTC)
commit 17bcd58db21bdc7eb9b0502707ebf60f13d65a1b
Author: Srinivasa Ragavan <sragavan gnome org>
Date: Thu Jun 17 08:55:18 2010 +0530
Emit multiple events while receiving new mails. Also add a api to get
folder_uri from cache.
mail/mail-folder-cache.c | 80 +++++++++++++++++++++++++++++----------------
mail/mail-folder-cache.h | 1 +
2 files changed, 52 insertions(+), 29 deletions(-)
---
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c
index b1a332d..e686148 100644
--- a/mail/mail-folder-cache.c
+++ b/mail/mail-folder-cache.c
@@ -296,12 +296,13 @@ free_folder_info(struct _folder_info *mfi)
* it's correct. */
static void
-update_1folder(MailFolderCache *self, struct _folder_info *mfi, gint new, const gchar *msg_uid, const gchar *msg_sender, const gchar *msg_subject, CamelFolderInfo *info)
+update_1folder(MailFolderCache *self, struct _folder_info *mfi, gint new, GPtrArray *msg_uid, GPtrArray *msg_sender, GPtrArray *msg_subject, CamelFolderInfo *info)
{
struct _folder_update *up;
CamelFolder *folder;
gint unread = -1;
gint deleted;
+ int i;
folder = mfi->folder;
if (folder) {
@@ -340,17 +341,20 @@ update_1folder(MailFolderCache *self, struct _folder_info *mfi, gint new, const
if (unread == -1)
return;
- up = g_malloc0(sizeof(*up));
- up->full_name = g_strdup(mfi->full_name);
- up->unread = unread;
- up->new = new;
- up->store = mfi->store_info->store;
- up->uri = g_strdup(mfi->uri);
- up->msg_uid = g_strdup (msg_uid);
- up->msg_sender = g_strdup (msg_sender);
- up->msg_subject = g_strdup (msg_subject);
- camel_object_ref(up->store);
- g_queue_push_head (&self->priv->updates, up);
+ for (i=0; i< new; i++) {
+ up = g_malloc0(sizeof(*up));
+ up->full_name = g_strdup(mfi->full_name);
+ up->unread = unread;
+ up->new = 1;
+ up->store = mfi->store_info->store;
+ up->uri = g_strdup(mfi->uri);
+ up->msg_uid = g_strdup (msg_uid->pdata[i]);
+ up->msg_sender = g_strdup (msg_sender->pdata[i]);
+ up->msg_subject = g_strdup (msg_subject->pdata[i]);
+ camel_object_ref(up->store);
+ g_queue_push_head (&self->priv->updates, up);
+ }
+
flush_updates(self);
}
@@ -420,9 +424,13 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data)
gint new = 0;
gint i;
guint32 flags;
- gchar *uid = NULL, *sender = NULL, *subject = NULL;
+ GPtrArray *uid = NULL, *sender = NULL, *subject = NULL;
MailFolderCache *self = (MailFolderCache*) user_data;
+ uid = g_ptr_array_new ();
+ sender = g_ptr_array_new ();
+ subject = g_ptr_array_new ();
+
d(printf("folder '%s' changed\n", folder->full_name));
local_drafts = e_mail_local_get_folder (E_MAIL_FOLDER_DRAFTS);
@@ -445,19 +453,9 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data)
((flags & CAMEL_MESSAGE_DELETED) == 0) &&
(camel_message_info_date_received (info) > last_newmail)) {
new++;
- if (new == 1) {
- uid = g_strdup (camel_message_info_uid (info));
- sender = g_strdup (camel_message_info_from (info));
- subject = g_strdup (camel_message_info_subject (info));
- } else {
- g_free (uid);
- g_free (sender);
- g_free (subject);
-
- uid = NULL;
- sender = NULL;
- subject = NULL;
- }
+ g_ptr_array_add(uid, g_strdup (camel_message_info_uid (info)));
+ g_ptr_array_add (sender, g_strdup (camel_message_info_from (info)));
+ g_ptr_array_add (subject, g_strdup (camel_message_info_subject (info)));
}
camel_message_info_free (info);
}
@@ -476,9 +474,13 @@ folder_changed (CamelObject *o, gpointer event_data, gpointer user_data)
}
g_mutex_unlock (self->priv->stores_mutex);
- g_free (uid);
- g_free (sender);
- g_free (subject);
+ g_ptr_array_foreach (uid, (GFunc) g_free, NULL);
+ g_ptr_array_foreach (sender, (GFunc) g_free, NULL);
+ g_ptr_array_foreach (subject, (GFunc) g_free, NULL);
+
+ g_ptr_array_free (uid, TRUE);
+ g_ptr_array_free (sender, TRUE);
+ g_ptr_array_free (subject, TRUE);
}
static void
@@ -555,6 +557,26 @@ void mail_folder_cache_note_folder(MailFolderCache *self, CamelFolder *folder)
camel_object_hook_event(folder, "finalize", folder_finalised, self);
}
+char *
+mail_folder_cache_get_folder_uri (MailFolderCache *self, CamelFolder *folder)
+{
+ CamelStore *store = folder->parent_store;
+ struct _store_info *si;
+ struct _folder_info *mfi;
+
+ g_mutex_lock (self->priv->stores_mutex);
+ if (self->priv->stores == NULL
+ || (si = g_hash_table_lookup(self->priv->stores, store)) == NULL
+ || (mfi = g_hash_table_lookup(si->folders, folder->full_name)) == NULL) {
+ g_mutex_unlock (self->priv->stores_mutex);
+ return NULL;
+ }
+
+ g_mutex_unlock (self->priv->stores_mutex);
+
+ return g_strdup(mfi->uri);
+}
+
static void
store_folder_subscribed(CamelObject *o, gpointer event_data, gpointer data)
{
diff --git a/mail/mail-folder-cache.h b/mail/mail-folder-cache.h
index dd3a108..1c3c725 100644
--- a/mail/mail-folder-cache.h
+++ b/mail/mail-folder-cache.h
@@ -78,6 +78,7 @@ void mail_folder_cache_note_store_remove (MailFolderCache *self, CamelStore *sto
void mail_folder_cache_note_folder (MailFolderCache *self, CamelFolder *folder);
gboolean mail_folder_cache_get_folder_from_uri (MailFolderCache *self, const gchar *uri, CamelFolder **folderp);
gboolean mail_folder_cache_get_folder_info_flags (MailFolderCache *self, CamelFolder *folder, gint *flags);
+char * mail_folder_cache_get_folder_uri (MailFolderCache *self, CamelFolder *folder);
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]