diff options
author | Srinivasa Ragavan <sragavan@src.gnome.org> | 2007-05-03 16:04:47 +0800 |
---|---|---|
committer | Srinivasa Ragavan <sragavan@src.gnome.org> | 2007-05-03 16:04:47 +0800 |
commit | ca40a11a3c196c24fb122bad0a831d07e8748b80 (patch) | |
tree | 99de2c0688c0e2d72dde5b0f4392cf0b9756b0cc | |
parent | b92eff4a79b7210ea699e6d857c6126003aa5d16 (diff) | |
download | gsoc2013-evolution-ca40a11a3c196c24fb122bad0a831d07e8748b80.tar.gz gsoc2013-evolution-ca40a11a3c196c24fb122bad0a831d07e8748b80.tar.zst gsoc2013-evolution-ca40a11a3c196c24fb122bad0a831d07e8748b80.zip |
Initial commit for Mail notification plugin.
svn path=/trunk/; revision=33474
-rw-r--r-- | plugins/mail-notification/ChangeLog | 7 | ||||
-rw-r--r-- | plugins/mail-notification/Makefile.am | 24 | ||||
-rw-r--r-- | plugins/mail-notification/mail-notification.c | 137 | ||||
-rw-r--r-- | plugins/mail-notification/org-gnome-mail-notification.eplug.xml | 34 |
4 files changed, 202 insertions, 0 deletions
diff --git a/plugins/mail-notification/ChangeLog b/plugins/mail-notification/ChangeLog new file mode 100644 index 0000000000..39dd335414 --- /dev/null +++ b/plugins/mail-notification/ChangeLog @@ -0,0 +1,7 @@ +2006-08-21 Srinivasa Ragavan <sragavan@novell.com> + + ** Initial commit for Mail notification plugin. + + * mail-notification.c: + * Makefile.am: + * org-gnome-mail-notification.eplug.xml: diff --git a/plugins/mail-notification/Makefile.am b/plugins/mail-notification/Makefile.am new file mode 100644 index 0000000000..6644bf97b5 --- /dev/null +++ b/plugins/mail-notification/Makefile.am @@ -0,0 +1,24 @@ +INCLUDES = \ + -I$(top_srcdir) \ + -DDBUS_API_SUBJECT_TO_CHANGE=1 \ + -DDBUS_VERSION=$(DBUS_VERSION) \ + $(EVOLUTION_MAIL_CFLAGS) \ + $(LIBNOTIFY_CFLAGS) + $(NMN_CFLAGS) + +LIBS = \ + $(LIBNOTIFY_LIBS) \ + $(NMN_LIBS) + +@EVO_PLUGIN_RULE@ + +plugin_DATA = org-gnome-mail-notification.eplug +plugin_LTLIBRARIES = liborg-gnome-mail-notification.la + +liborg_gnome_mail_notification_la_SOURCES = mail-notification.c +liborg_gnome_mail_notification_la_LDFLAGS = -module -avoid-version + +EXTRA_DIST = org-gnome-mail-notification.eplug.xml + +BUILT_SOURCES = $(plugin_DATA) +CLEANFILES = $(BUILT_SOURCES) diff --git a/plugins/mail-notification/mail-notification.c b/plugins/mail-notification/mail-notification.c new file mode 100644 index 0000000000..5ce66240a3 --- /dev/null +++ b/plugins/mail-notification/mail-notification.c @@ -0,0 +1,137 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Author: Miguel Angel Lopez Hernandez <miguel@gulev.org.mx> + * + * Copyright 2004 Novell, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <glib.h> +#include <glib/gi18n.h> +#include <gtk/gtk.h> +#include <gconf/gconf-client.h> +#include <e-util/e-config.h> +#include <e-util/e-icon-factory.h> + +#include <mail/em-utils.h> +#include <mail/em-event.h> +#include <mail/em-folder-tree-model.h> +#include <camel/camel-folder.h> + +#include <libnotify/notify.h> + +int e_plugin_lib_enable (EPluginLib *ep, int enable); +void org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t); +void org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t); + +static gboolean enabled = FALSE; +GtkStatusIcon *status_icon = NULL; + +static GStaticMutex mlock = G_STATIC_MUTEX_INIT; + +void +org_gnome_mail_read_notify (EPlugin *ep, EMEventTargetMessage *t) +{ + g_static_mutex_lock (&mlock); + + if (!status_icon) { + g_static_mutex_unlock (&mlock); + return; + } + + gtk_status_icon_set_visible (status_icon, FALSE); + + g_static_mutex_unlock (&mlock); + +} + +static void +icon_activated (GtkStatusIcon *icon) +{ + g_static_mutex_lock (&mlock); + gtk_status_icon_set_visible (status_icon, FALSE); + g_static_mutex_unlock (&mlock); + +} + +void +org_gnome_mail_new_notify (EPlugin *ep, EMEventTargetFolder *t) +{ + char *msg = NULL; + char *folder; + NotifyUrgency urgency = NOTIFY_URGENCY_NORMAL; + long expire_timeout = NOTIFY_EXPIRES_DEFAULT; + NotifyNotification *notify; + + /* FIXME: Should this is_inbox be configurable? */ + if (!t->new || !t->is_inbox) + return; + + g_static_mutex_lock (&mlock); + + if (!status_icon) { + status_icon = gtk_status_icon_new (); + gtk_status_icon_set_from_pixbuf (status_icon, e_icon_factory_get_icon ("stock_mail", E_ICON_SIZE_LARGE_TOOLBAR)); + gtk_status_icon_set_blinking (status_icon, TRUE); + } + + folder = em_utils_folder_name_from_uri (t->uri); + msg = g_strdup_printf (_("You have received %d new messages in %s."), t->new, folder); + + gtk_status_icon_set_tooltip (status_icon, msg); + gtk_status_icon_set_visible (status_icon, TRUE); + + if (!notify_init("notify-send")) + fprintf(stderr,"notify init error"); + + notify = notify_notification_new("New email in Evolution", + msg, + "stock_mail", + NULL); + if(notify==NULL) + fprintf(stderr,"notify = NULL !!\n"); + else { + notify_notification_set_urgency(notify, urgency); + notify_notification_set_timeout(notify, expire_timeout); + notify_notification_show(notify, NULL); + } + + g_free (folder); + g_free (msg); + g_signal_connect (G_OBJECT (status_icon), "activate", + G_CALLBACK (icon_activated), NULL); + g_static_mutex_unlock (&mlock); +} + + + + +int +e_plugin_lib_enable (EPluginLib *ep, int enable) +{ + if (enable) + enabled = TRUE; + else + enabled = FALSE; + + return 0; +} + diff --git a/plugins/mail-notification/org-gnome-mail-notification.eplug.xml b/plugins/mail-notification/org-gnome-mail-notification.eplug.xml new file mode 100644 index 0000000000..56b9cc7c2b --- /dev/null +++ b/plugins/mail-notification/org-gnome-mail-notification.eplug.xml @@ -0,0 +1,34 @@ +<e-plugin-list> + <e-plugin + id="org.gnome.evolution.mail_notification" + type="shlib" + _name="Mail Notification" + location="@PLUGINDIR@/liborg-gnome-mail-notification@SOEXT@"> + + <_description>Notifies the user with tray icon and a notify message whenever a new message is arrived.</_description> + <author name="Srinivasa Ragavan" email="sragavan@novell.com"/> + + <hook class="org.gnome.evolution.mail.events:1.0"> + <event id="folder.changed" + enable="newmail" + handle="org_gnome_mail_new_notify" + target="folder"/> + </hook> + + <hook class="org.gnome.evolution.mail.events:1.0"> + <event id="message.reading" + handle="org_gnome_mail_read_notify" + target="message"/> + </hook> + <!-- + <hook class="org.gnome.evolution.mail.config:1.0"> + <group id="org.gnome.evolution.mail.prefs" target="prefs"> + <item type="item" + path="00.general/30.notify/00.new_mail_notify" + _label="New mail notify" + factory="org_gnome_new_mail_config"/> + </group> + </hook> + --> + </e-plugin> +</e-plugin-list> |