From 1708f77c843bd13bcf0244c8dee0db52aa421317 Mon Sep 17 00:00:00 2001 From: OHASHI Akira Date: Mon, 30 Mar 2009 11:41:58 +0000 Subject: [PATCH] * riece-desktop-notify.el: New add-on. * riece-addon-modules.el (riece-addon-modules): Add riece-desktop-notify. * riece-mcat-japanese.el (riece-mcat-japanese-alist): Translate "Display notification to desktop.". * Makefile.am (EXTRA_DIST): Add riece-desktop-notify.el. --- lisp/ChangeLog | 9 ++ lisp/Makefile.am | 2 +- lisp/riece-addon-modules.el | 2 + lisp/riece-desktop-notify.el | 187 +++++++++++++++++++++++++++++++++++ lisp/riece-mcat-japanese.el | 1 + 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 lisp/riece-desktop-notify.el diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2ff65e0..56679e7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2009-03-30 OHASHI Akira + + * riece-desktop-notify.el: New add-on. + * riece-addon-modules.el (riece-addon-modules): Add + riece-desktop-notify. + * riece-mcat-japanese.el (riece-mcat-japanese-alist): Translate + "Display notification to desktop.". + * Makefile.am (EXTRA_DIST): Add riece-desktop-notify.el. + 2009-03-30 OHASHI Akira * riece-keyword.el (riece-keyword-message-filter): Fix for the infinite diff --git a/lisp/Makefile.am b/lisp/Makefile.am index 66268d3..caee59d 100644 --- a/lisp/Makefile.am +++ b/lisp/Makefile.am @@ -20,7 +20,7 @@ EXTRA_DIST = COMPILE ChangeLog ChangeLog.Liece \ riece-kakasi.el riece-foolproof.el riece-yank.el riece-toolbar.el \ riece-eval.el riece-google.el riece-keepalive.el riece-eval-ruby.el \ riece-shrink-buffer.el riece-xfaceb.el riece-epg.el riece-twitter.el \ - riece-notify.el \ + riece-notify.el riece-desktop-notify.el \ url-riece.el \ riece-command-previous-channel.xpm riece-command-next-channel.xpm \ riece-command-configure-windows.xpm riece-command-list-addons.xpm \ diff --git a/lisp/riece-addon-modules.el b/lisp/riece-addon-modules.el index d9500e1..1a47848 100644 --- a/lisp/riece-addon-modules.el +++ b/lisp/riece-addon-modules.el @@ -14,6 +14,8 @@ (riece-mcat "CTCP (Client To Client Protocol) support.")) (cons 'riece-ctlseq (riece-mcat "Mark up control sequences in IRC buffers.")) + (cons 'riece-desktop-notify + (riece-mcat "Display notification to desktop.")) (cons 'riece-doctor (riece-mcat "Pretend to be a psychotherapist.")) (cons 'riece-epg diff --git a/lisp/riece-desktop-notify.el b/lisp/riece-desktop-notify.el new file mode 100644 index 0000000..ef4b771 --- /dev/null +++ b/lisp/riece-desktop-notify.el @@ -0,0 +1,187 @@ +;;; riece-desktop-notify.el --- Display notification to desktop +;; Copyright (C) 2009 OHASHI Akira + +;; Author: OHASHI Akira +;; Created: 2009-03-29 +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program 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 2, or (at your option) +;; any later version. + +;; 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 GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; NOTE: This is an add-on module for Riece. + +;; riece-desktop-notify.el needs an external program to notify desktop. +;; The setting prepared beforehand for most popular OS uses the +;; following external programs. +;; +;; Mac OS X: +;; growlnotify +;; (of course you need Growl ) +;; +;; GNU/Linux: +;; notify-send (which is included in libnotify) +;; +;; +;; If you use Debian, you can install it by the following command: +;; +;; % sudo aptitude install libnotify-bin +;; +;; Windows: +;; Snarl_CMD.exe +;; (of course you need Snarl ) + +;;; Code: + +(require 'riece-message) +(eval-when-compile (require 'riece-keyword)) + +(defconst riece-desktop-notify-description + "Display notification to desktop.") + +(defgroup riece-desktop-notify nil + "Display notification to desktop." + :group 'riece) + +(defcustom riece-desktop-notify-title-function + '(lambda (message) + (riece-identity-prefix (riece-message-target message))) + "*The function which make title. +This function must have only one message object as argument." + :type 'function + :group 'riece-desktop-notify) + +(defcustom riece-desktop-notify-message-function 'riece-format-message + "*The function which make message. +This function must have only one message object as argument." + :type 'function + :group 'riece-desktop-notify) + +(defcustom riece-desktop-notify-coding-system (terminal-coding-system) + "*Coding system used to notify desktop." + :type 'coding-system + :group 'riece-desktop-notify) + +(defcustom riece-desktop-notify-type + (if (eq system-type 'linux) 'gnu/linux system-type) + "*The type to notify desktop." + :type '(radio (const :tag "Like Darwin" darwin) + (const :tag "Like GNU/Linux" gnu/linux) + (const :tag "Like Windows" windows-nt) + (symbol :tag "The other type")) + :group 'riece-desktop-notify) + +;; for Darwin +(defcustom riece-desktop-notify-darwin-program "growlnotify" + "*The program name to notify for darwin." + :type 'file + :group 'riece-desktop-notify) + +(defcustom riece-desktop-notify-darwin-args + '("-t" title "-m" message "-H" "localhost") + "*The Arguments to notify for darwin." + :type '(repeat (radio (string :tag "Argument") + (const :tag "Title" title) + (const :tag "Message" message))) + :group 'riece-desktop-notify) + +;; for GNU/Linux +(defcustom riece-desktop-notify-gnu/linux-program "notify-send" + "*The program name to notify for GNU/Linux." + :type 'file + :group 'riece-desktop-notify) + +(defcustom riece-desktop-notify-gnu/linux-args '("-u" "low" title message) + "*The Arguments to notify for GNU/Linux." + :type '(repeat (radio (string :tag "Argument") + (const :tag "Title" title) + (const :tag "Message" message))) + :group 'riece-desktop-notify) + +;; for Windows +(defcustom riece-desktop-notify-windows-nt-program "snarl_cmd.exe" + "*The program name to notify for Windows." + :type 'file + :group 'riece-desktop-notify) + +(defcustom riece-desktop-notify-windows-nt-args + '("snShowMessage" "-1" title message) + "*The Arguments string to notify for Windows." + :type '(repeat (radio (string :tag "Argument") + (const :tag "Title" title) + (const :tag "Message" message))) + :group 'riece-desktop-notify) + +;; stolen and modified from riece-ruby.el +(defun riece-desktop-notify-substitute-variables (args alist) + "Substitute symbols in ARGS by looking up ALIST." + (setq args (copy-sequence args)) + (while alist + (let ((pointer args)) + (while pointer + (setq pointer (memq (car (car alist)) args)) + (if pointer + (setcar pointer (cdr (car alist)))))) + (setq alist (cdr alist))) + args) + +(defsubst riece-desktop-notify-make-symbol (symbol) + (intern (format "riece-desktop-notify-%s-%s" + (symbol-name riece-desktop-notify-type) + (symbol-name symbol)))) + +(defun riece-desktop-notify-keyword-notify-function (keyword message) + (let ((program-symbol (riece-desktop-notify-make-symbol 'program)) + (args-symbol (riece-desktop-notify-make-symbol 'args))) + (when (and (boundp program-symbol) (boundp args-symbol)) + (let ((program (eval program-symbol)) + (args (eval args-symbol))) + (when (fboundp 'executable-find) + (setq program (executable-find program))) + (when (stringp program) + (let ((title (funcall riece-desktop-notify-title-function message)) + (message (funcall riece-desktop-notify-message-function + message))) + (condition-case nil + (apply #'call-process program nil nil nil + (riece-desktop-notify-substitute-variables + args + (list (cons 'title + (encode-coding-string + title + riece-desktop-notify-coding-system)) + (cons 'message + (encode-coding-string + message + riece-desktop-notify-coding-system))))) + (file-error nil)))))))) + +(defun riece-desktop-notify-requires () + '(riece-keyword)) + +(defun riece-desktop-notify-insinuate () + (add-hook 'riece-keyword-notify-functions + 'riece-desktop-notify-keyword-notify-function)) + +(defun riece-desktop-notify-uninstall () + (remove-hook 'riece-keyword-notify-functions + 'riece-desktop-notify-keyword-notify-function)) + +(provide 'riece-desktop-notify) + +;;; riece-desktop-notify.el ends here diff --git a/lisp/riece-mcat-japanese.el b/lisp/riece-mcat-japanese.el index 91c9238..bdf5efd 100644 --- a/lisp/riece-mcat-japanese.el +++ b/lisp/riece-mcat-japanese.el @@ -107,6 +107,7 @@ ("Display X-Face & Colour Face images in IRC buffers (BBDB)." . "X-Face や色付きの Face 画像を表示 (BBDB 利用)") ("Display X-Face in IRC buffers." . "X-Face や色付き Face 画像を表示 (LSDB 利用)") ("Display icons in IRC buffers." . "アイコンを表示") + ("Display notification to desktop." . "デスクトップに通知") ("Display toolbar icons." . "ツールバーのアイコンを表示") ("Display useful buttons in IRC buffers." . "ボタンを表示") ("Encrypt/decrypt messages." . "メッセージの暗号化・復号") -- 2.25.1