Send notifications for incoming messages.
authorSteve Youngs <steve@emchat.org>
Sat, 4 Feb 2012 03:02:53 +0000 (13:02 +1000)
committerSteve Youngs <steve@emchat.org>
Sat, 4 Feb 2012 03:06:15 +0000 (13:06 +1000)
With this changeset EMchat will send notifications via libnotify's
`notify-send' for incoming messages.  It will only send the notification
if either the log buffer isn't the current buffer, or `emchat-frame' does
not have the window system focus.

* emchat-log.el (emchat-notify-flag): New.  Send notifications
when non-nil.

* emchat-log.el (emchat-notify-command): Shell command used to
send notifications.

* emchat-log.el (emchat-notify): New.  Send notifications via
notify-send from libnotify for incoming messages.

* emchat-log.el (emchat-log): Send a notification if either the
log buffer isn't the current buffer or the EMchat frame doesn't
have focus.

Signed-off-by: Steve Youngs <steve@emchat.org>
emchat-log.el

index f355880..87522f2 100644 (file)
@@ -186,6 +186,18 @@ Nil means mark read."
   :group 'emchat-interface
   :type '(choice (item t) (item nil)))
 
+(defcustom emchat-notify-flag t
+  "*Non-nil to send notifications via libnotify.
+
+Currently this simply uses `notify-send' shell command."
+  :group 'emchat-log
+  :type 'boolean)
+
+(defcustom emchat-notify-command (executable-find "notify-send")
+  "*The shell command used to send notifications."
+  :group 'emchat-log
+  :type 'string)
+
 ;;; Internal variables
 
 (defvar emchat-log-buffer nil
@@ -400,10 +412,26 @@ ID is the entity that sent MESSAGE."
        (set-extent-property exp 'face face)
        (set-extent-property exp 'balloon-help bhelp)))))
 
+(defun emchat-notify (id message)
+  "Send a notification about incoming MESSAGE from ID."
+  (let ((notify emchat-notify-command)
+       (icon (expand-file-name "emchat-icon.png" emchat-glyph-dir))
+       (urgency "normal")
+       (skip-id (member id '("!debug" "!info" "!system"))))
+    (when (and notify (not skip-id))
+      (call-process notify nil nil nil
+                   "-i" icon
+                   "-u" urgency
+                   (format "New Message From: %s" id)
+                   message))))
+
 (defun emchat-log (id message option mark-unread)
   "Log message under ID.
 Put MESSAGE at the end of log buffer if OPTION is non-nil.
 Mark MESSAGE unread if MARK-UNREAD is non-nil"
+  (unless (or (eq (current-buffer) emchat-log-buffer)
+             (frame-visible-p emchat-frame))
+    (emchat-notify id message))
   (if (and option (buffer-live-p emchat-log-buffer))
       (with-current-buffer emchat-log-buffer
        (save-excursion