From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Julien Danjou Newsgroups: gmane.emacs.devel Subject: [PATCH] Add notifications.el Date: Sat, 5 Jun 2010 19:07:37 +0200 Message-ID: <1275757657-15244-1-git-send-email-julien@danjou.info> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1275758582 11394 80.91.229.12 (5 Jun 2010 17:23:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 5 Jun 2010 17:23:02 +0000 (UTC) Cc: Julien Danjou To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 05 19:23:00 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OKx5G-00083E-Pi for ged-emacs-devel@m.gmane.org; Sat, 05 Jun 2010 19:22:59 +0200 Original-Received: from localhost ([127.0.0.1]:44045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKx5B-0004eB-KD for ged-emacs-devel@m.gmane.org; Sat, 05 Jun 2010 13:22:53 -0400 Original-Received: from [140.186.70.92] (port=46065 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKwqY-0007O8-Me for emacs-devel@gnu.org; Sat, 05 Jun 2010 13:07:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKwqX-0006ro-0F for emacs-devel@gnu.org; Sat, 05 Jun 2010 13:07:46 -0400 Original-Received: from prometheus.naquadah.org ([212.85.154.174]:60988 helo=mx1.naquadah.org) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKwqW-0006rd-Kx for emacs-devel@gnu.org; Sat, 05 Jun 2010 13:07:44 -0400 Original-Received: by mx1.naquadah.org (Postfix, from userid 8) id C82395C115; Sat, 5 Jun 2010 19:07:41 +0200 (CEST) Original-Received: from keller.adm.naquadah.org (chapai.naquadah.org [82.227.158.144]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.naquadah.org (Postfix) with ESMTPSA id 3F1DF5C104; Sat, 5 Jun 2010 19:07:39 +0200 (CEST) Original-Received: from jd by keller.adm.naquadah.org with local (Exim 4.72) (envelope-from ) id 1OKwqQ-0003yR-Ec; Sat, 05 Jun 2010 19:07:38 +0200 X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Mailman-Approved-At: Sat, 05 Jun 2010 13:22:47 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:125549 Archived-At: Signed-off-by: Julien Danjou --- FYI I've signed the copyright assignment papers. lisp/ChangeLog | 4 + lisp/net/notifications.el | 174 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 0 deletions(-) create mode 100644 lisp/net/notifications.el diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a33c43f..378449c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2010-06-05 Julien Danjou + + * net/notifications.el: New file. + 2010-06-04 Juanma Barranquero * subr.el (directory-sep-char): Move from fileio.c and make a defconst. diff --git a/lisp/net/notifications.el b/lisp/net/notifications.el new file mode 100644 index 0000000..aeeea31 --- /dev/null +++ b/lisp/net/notifications.el @@ -0,0 +1,174 @@ +;;; notifications.el --- Client interface to desktop notifications. + +;; Copyright (C) 2010 Free Software Foundation, Inc. + +;; Author: Julien Danjou +;; Keywords: comm desktop notifications + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs 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 GNU Emacs. If not, see . + +;;; Commentary: + +;; This package provides an implementation of the Desktop Notifications +;; . + +;; In order to activate this package, you must add the following code +;; into your .emacs: +;; +;; (require 'notifications) + +;;; Code: + +;; Pacify byte-compiler. D-Bus support in the Emacs core can be +;; disabled with configuration option "--without-dbus". Declare used +;; subroutines and variables of `dbus' therefore. +(declare-function dbus-call-method "dbusbind.c") + +(require 'dbus) + +(defconst notifications-application-name "Emacs" + "Default application name.") + +(defconst notifications-service "org.freedesktop.Notifications" + "D-Bus notifications service name.") + +(defconst notifications-path "/org/freedesktop/Notifications" + "D-Bus notifications service path.") + +(defconst notifications-interface "org.freedesktop.Notifications" + "D-Bus notifications service path.") + +(defconst notifications-notify-method "Notify" + "D-Bus notifications service path.") + +(defconst notifications-close-notification-method "CloseNotification" + "D-Bus notifications service path.") + +(defun notifications-notify (&rest params) + "Send notification via D-Bus using the Freedesktop notification protocol. +Various PARAMS can be set: + + :title The notification title. + :body The notification body text. + :app-name The name of the application sending the notification. + Default to `notifications-application-name'. + :replaces-id The notification ID that this notification replaces. + :app-icon The notification icon. + :action A list of actions. + :timeout The timeout time in milliseconds since the display + of the notification at which the notification should + automatically close. + If -1, the notification's expiration time is dependent + on the notification server's settings, and may vary for + the type of notification (default). + If 0, the notification never expires. + :urgency The urgency level. + Either `low', `normal' or `critical'. + :category The type of notification this is. + :desktop-entry This specifies the name of the desktop filename representing + the calling program. + :image-data This is a raw data image format which describes the width, + height, rowstride, has alpha, bits per sample, channels and + image data respectively. + :sound-file The path to a sound file to play when the notification pops up. + :suppress-sound Causes the server to suppress playing any sounds, if it has + that ability. + :x Specifies the X location on the screen that the notification + should point to. The \"y\" hint must also be specified. + :y Specifies the Y location on the screen that the notification + should point to. The \"x\" hint must also be specified. + +This function returns a notification id, an integer, which can be +used to manipulate the notification item with +`notifications-close'." + (let ((title (plist-get params :title)) + (body (plist-get params :body)) + (app-name (plist-get params :app-name)) + (replaces-id (plist-get params :replaces-id)) + (app-icon (plist-get params :app-icon)) + (action (plist-get params :action)) + (timeout (plist-get params :timeout)) + ;; Hints + (hints '(:array)) + (urgency (plist-get params :urgency)) + (category (plist-get params :category)) + (desktop-entry (plist-get params :desktop-entry)) + (image-data (plist-get params :image-data)) + (sound-file (plist-get params :sound-file)) + (suppress-sound (plist-get params :suppress-sound)) + (x (plist-get params :x)) + (y (plist-get params :y))) + ;; Build hints array + (when urgency + (add-to-list 'hints `(:dict-entry + "urgency" + (:variant :byte ,(case urgency + ('low 0) + ('critical 2) + (t 1)))) t)) + (when category + (add-to-list 'hints `(:dict-entry + "category" + (:variant :string ,category)) t)) + (when desktop-entry + (add-to-list 'hints `(:dict-entry + "desktop-entry" + (:variant :string ,desktop-entry)) t)) + (when image-data + (add-to-list 'hints `(:dict-entry + "image_data" + (:variant :struct ,image-data)) t)) + (when sound-file + (add-to-list 'hints `(:dict-entry + "sound-file" + (:variant :string ,sound-file)) t)) + (when suppress-sound + (add-to-list 'hints `(:dict-entry + "suppress-sound" + (:variant :boolean ,suppress-sound)) t)) + (when x + (add-to-list 'hints `(:dict-entry "x" (:variant :int32 ,x)) t)) + (when y + (add-to-list 'hints `(:dict-entry "y" (:variant :int32 ,y)) t)) + + ;; Call Notify method + (dbus-call-method :session + notifications-service + notifications-path + notifications-interface + notifications-notify-method + :string (or app-name + notifications-application-name) + :uint32 (or replaces-id 0) + :string (if app-icon + (expand-file-name app-icon) + "") + :string (or title "") + :string (or body "") + `(:array ,@action) + hints + :int32 (or timeout -1)))) + +(defun notifications-close-notification (id) + "Close a notification with identifier ID." + (dbus-call-method :session + notifications-service + notifications-path + notifications-interface + notifications-close-notification-method + :int32 id)) + +(provide 'notifications) -- 1.7.1