From ca40a11a3c196c24fb122bad0a831d07e8748b80 Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Thu, 3 May 2007 08:04:47 +0000 Subject: Initial commit for Mail notification plugin. svn path=/trunk/; revision=33474 --- plugins/mail-notification/ChangeLog | 7 ++ plugins/mail-notification/Makefile.am | 24 ++++ plugins/mail-notification/mail-notification.c | 137 +++++++++++++++++++++ .../org-gnome-mail-notification.eplug.xml | 34 +++++ 4 files changed, 202 insertions(+) create mode 100644 plugins/mail-notification/ChangeLog create mode 100644 plugins/mail-notification/Makefile.am create mode 100644 plugins/mail-notification/mail-notification.c create mode 100644 plugins/mail-notification/org-gnome-mail-notification.eplug.xml 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 + + ** 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 + * + * 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 +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +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 @@ + + + + <_description>Notifies the user with tray icon and a notify message whenever a new message is arrived. + + + + + + + + + + + + -- cgit v1.2.3