aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-08-20 01:59:34 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-08-20 01:59:34 +0800
commit1fcc2835b5a466d11c29299e3ae20919e37bce52 (patch)
tree1a3449d5c5325ae6df2d9926e2c8d395cae2209c /mail
parent0a68edd9a45e81372577ef76d74017e107c69e3e (diff)
downloadgsoc2013-evolution-1fcc2835b5a466d11c29299e3ae20919e37bce52.tar.gz
gsoc2013-evolution-1fcc2835b5a466d11c29299e3ae20919e37bce52.tar.zst
gsoc2013-evolution-1fcc2835b5a466d11c29299e3ae20919e37bce52.zip
Removed the new-mail-notification mess.
2003-08-18 Jeffrey Stedfast <fejj@ximian.com> * mail-session.c (main_get_filter_driver): Removed the new-mail-notification mess. * mail-folder-cache.c (notify_idle_cb): New idle callback to alert the user about new mail. (notify_type_changed): New function to intercept user changes to his/her notification settings changes. (real_flush_updates): Initialise new mail notification if not yet initialised and setup an idle callback if none is already set. (update_1folder): Now takes an additional argument `new' which states whether or not the fodler got any new mail so that we may handle notify the user (if needed). (folder_changed): Pass in the number of new messages received. svn path=/trunk/; revision=22290
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog16
-rw-r--r--mail/mail-folder-cache.c112
-rw-r--r--mail/mail-session.c34
3 files changed, 115 insertions, 47 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index e7c7e92570..b3dd16eedd 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,19 @@
+2003-08-18 Jeffrey Stedfast <fejj@ximian.com>
+
+ * mail-session.c (main_get_filter_driver): Removed the
+ new-mail-notification mess.
+
+ * mail-folder-cache.c (notify_idle_cb): New idle callback to alert
+ the user about new mail.
+ (notify_type_changed): New function to intercept user changes to
+ his/her notification settings changes.
+ (real_flush_updates): Initialise new mail notification if not yet
+ initialised and setup an idle callback if none is already set.
+ (update_1folder): Now takes an additional argument `new' which
+ states whether or not the fodler got any new mail so that we may
+ handle notify the user (if needed).
+ (folder_changed): Pass in the number of new messages received.
+
2003-08-19 Not Zed <NotZed@Ximian.com>
* mail-callbacks.c (mail_generate_reply): Added a comment for
diff --git a/mail/mail-folder-cache.c b/mail/mail-folder-cache.c
index ed50689630..cbdfacf3d6 100644
--- a/mail/mail-folder-cache.c
+++ b/mail/mail-folder-cache.c
@@ -31,7 +31,9 @@
#include <pthread.h>
#include <string.h>
+#include <time.h>
+#include <libgnome/gnome-sound.h>
#include <bonobo/bonobo-exception.h>
#include <camel/camel-store.h>
#include <camel/camel-folder.h>
@@ -78,6 +80,7 @@ struct _folder_update {
unsigned int delete:1; /* deleting as well? */
unsigned int add:1; /* add to vfolder */
unsigned int unsub:1; /* unsubcribing? */
+ unsigned int new:1; /* new mail arrived? */
char *path;
char *name;
@@ -111,6 +114,13 @@ static void folder_finalised(CamelObject *o, gpointer event_data, gpointer user_
static guint ping_id = 0;
static gboolean ping_cb (gpointer user_data);
+static guint notify_id = 0;
+static int notify_type = -1;
+
+static time_t last_notify = 0;
+static guint notify_idle_id = 0;
+static gboolean notify_idle_cb (gpointer user_data);
+
/* Store to storeinfo table, active stores */
static GHashTable *stores = NULL;
@@ -130,12 +140,49 @@ free_update(struct _folder_update *up)
g_free(up->name);
g_free(up->uri);
if (up->store)
- camel_object_unref((CamelObject *)up->store);
+ camel_object_unref(up->store);
g_free(up->oldpath);
g_free(up->olduri);
g_free(up);
}
+static gboolean
+notify_idle_cb (gpointer user_data)
+{
+ GConfClient *gconf;
+ char *filename;
+
+ gconf = mail_config_get_gconf_client ();
+
+ switch (notify_type) {
+ case MAIL_CONFIG_NOTIFY_PLAY_SOUND:
+ filename = gconf_client_get_string (gconf, "/apps/evolution/mail/notify/sound", NULL);
+ if (filename != NULL) {
+ gnome_sound_play (filename);
+ g_free (filename);
+ }
+ break;
+ case MAIL_CONFIG_NOTIFY_BEEP:
+ gdk_beep ();
+ break;
+ default:
+ break;
+ }
+
+ time (&last_notify);
+
+ notify_idle_id = 0;
+
+ return FALSE;
+}
+
+static void
+notify_type_changed (GConfClient *client, guint cnxn_id,
+ GConfEntry *entry, gpointer user_data)
+{
+ notify_type = gconf_client_get_int (client, "/apps/evolution/mail/notify/type", NULL);
+}
+
static void
real_flush_updates(void *o, void *event_data, void *data)
{
@@ -144,10 +191,10 @@ real_flush_updates(void *o, void *event_data, void *data)
EvolutionStorage *storage;
GNOME_Evolution_Storage corba_storage;
CORBA_Environment ev;
+ time_t now;
LOCK(info_lock);
while ((up = (struct _folder_update *)e_dlist_remhead(&updates))) {
-
si = g_hash_table_lookup(stores, up->store);
if (si) {
storage = si->storage;
@@ -185,7 +232,8 @@ real_flush_updates(void *o, void *event_data, void *data)
d(printf("renaming folder '%s' to '%s'\n", up->olduri, up->uri));
mail_vfolder_rename_uri(up->store, up->olduri, up->uri);
mail_filter_rename_uri(up->store, up->olduri, up->uri);
- mail_config_uri_renamed(CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(up->store))->compare_folder_name, up->olduri, up->uri);
+ mail_config_uri_renamed(CAMEL_STORE_CLASS(CAMEL_OBJECT_GET_CLASS(up->store))->compare_folder_name,
+ up->olduri, up->uri);
}
if (up->name == NULL) {
@@ -211,9 +259,26 @@ real_flush_updates(void *o, void *event_data, void *data)
if (!up->olduri && up->add)
mail_vfolder_add_uri(up->store, up->uri, FALSE);
}
-
+
+ /* new mail notification */
+ if (notify_type == -1) {
+ /* need to track the user's new-mail-notification settings... */
+ GConfClient *gconf;
+
+ gconf = mail_config_get_gconf_client ();
+ gconf_client_add_dir (gconf, "/apps/evolution/mail/notify",
+ GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/notify",
+ notify_type_changed, NULL, NULL, NULL);
+ notify_type = gconf_client_get_int (gconf, "/apps/evolution/mail/notify/type", NULL);
+ }
+
+ time (&now);
+ if (notify_type != 0 && up->new && notify_idle_id == 0 && (now - last_notify >= 5))
+ notify_idle_id = g_idle_add_full (G_PRIORITY_LOW, notify_idle_cb, NULL, NULL);
+
free_update(up);
-
+
if (storage)
bonobo_object_unref((BonoboObject *)storage);
@@ -295,7 +360,7 @@ free_folder_info(struct _folder_info *mfi)
* it's correct. */
static void
-update_1folder(struct _folder_info *mfi, CamelFolderInfo *info)
+update_1folder(struct _folder_info *mfi, int new, CamelFolderInfo *info)
{
struct _store_info *si;
struct _folder_update *up;
@@ -328,6 +393,7 @@ update_1folder(struct _folder_info *mfi, CamelFolderInfo *info)
up = g_malloc0(sizeof(*up));
up->path = g_strdup(mfi->path);
up->unread = unread;
+ up->new = new ? 1 : 0;
up->store = mfi->store_info->store;
camel_object_ref(up->store);
e_dlist_addtail(&updates, (EDListNode *)up);
@@ -342,7 +408,7 @@ setup_folder(CamelFolderInfo *fi, struct _store_info *si)
mfi = g_hash_table_lookup(si->folders, fi->full_name);
if (mfi) {
- update_1folder(mfi, fi);
+ update_1folder(mfi, 0, fi);
} else {
/* always 'add it', but only 'add it' to non-local stores */
/*d(printf("Adding new folder: %s (%s) %d unread\n", fi->path, fi->url, fi->unread_message_count));*/
@@ -385,15 +451,35 @@ create_folders(CamelFolderInfo *fi, struct _store_info *si)
}
static void
-folder_changed(CamelObject *o, gpointer event_data, gpointer user_data)
+folder_changed (CamelObject *o, gpointer event_data, gpointer user_data)
{
+ extern CamelFolder *outbox_folder, *sent_folder;
+ CamelFolderChangeInfo *changes = event_data;
+ CamelFolder *folder = (CamelFolder *) o;
struct _folder_info *mfi = user_data;
-
- if (mfi->folder != CAMEL_FOLDER(o))
+ int new = 0;
+
+ if (mfi->folder != folder)
return;
+
+ if (!CAMEL_IS_VTRASH_FOLDER (folder) && folder != outbox_folder && folder != sent_folder && changes && changes->uid_added)
+ new = changes->uid_added->len;
+
+ LOCK(info_lock);
+ update_1folder(mfi, new, NULL);
+ UNLOCK(info_lock);
+}
+static void
+message_changed (CamelObject *o, gpointer event_data, gpointer user_data)
+{
+ struct _folder_info *mfi = user_data;
+
+ if (mfi->folder != CAMEL_FOLDER (o))
+ return;
+
LOCK(info_lock);
- update_1folder(mfi, NULL);
+ update_1folder(mfi, 0, NULL);
UNLOCK(info_lock);
}
@@ -458,11 +544,11 @@ void mail_note_folder(CamelFolder *folder)
mfi->folder = folder;
camel_object_hook_event(folder, "folder_changed", folder_changed, mfi);
- camel_object_hook_event(folder, "message_changed", folder_changed, mfi);
+ camel_object_hook_event(folder, "message_changed", message_changed, mfi);
camel_object_hook_event(folder, "renamed", folder_renamed, mfi);
camel_object_hook_event(folder, "finalize", folder_finalised, mfi);
- update_1folder(mfi, NULL);
+ update_1folder(mfi, 0, NULL);
UNLOCK(info_lock);
}
diff --git a/mail/mail-session.c b/mail/mail-session.c
index a411d3756d..66a41099b9 100644
--- a/mail/mail-session.c
+++ b/mail/mail-session.c
@@ -616,40 +616,6 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException
fsearch = g_string_new ("");
faction = g_string_new ("");
- /* add the new-mail notification rule first to be sure that it gets invoked */
-
- /* FIXME: we need a way to distinguish between filtering new
- mail and re-filtering a folder because both use the
- "incoming" filter type */
- notify = gconf_client_get_int (gconf, "/apps/evolution/mail/notify/type", NULL);
- if (notify != MAIL_CONFIG_NOTIFY_NOT && !strcmp (type, "incoming")) {
- char *filename;
-
- g_string_truncate (faction, 0);
-
- g_string_append (faction, "(only-once \"new-mail-notification\" ");
-
- switch (notify) {
- case MAIL_CONFIG_NOTIFY_PLAY_SOUND:
- filename = gconf_client_get_string (gconf, "/apps/evolution/mail/notify/sound", NULL);
- if (filename) {
- g_string_append_printf (faction, "\"(play-sound \\\"%s\\\")\"", filename);
- g_free (filename);
- break;
- }
- /* fall through */
- case MAIL_CONFIG_NOTIFY_BEEP:
- g_string_append (faction, "\"(beep)\"");
- break;
- default:
- break;
- }
-
- g_string_append (faction, ")");
-
- camel_filter_driver_add_rule (driver, "new-mail-notification", "(begin #t)", faction->str);
- }
-
/* add the user-defined rules next */
while ((rule = rule_context_next_rule (fc, rule, type))) {
g_string_truncate (fsearch, 0);