From: Steve Youngs Date: Sat, 4 Feb 2012 03:02:53 +0000 (+1000) Subject: Send notifications for incoming messages. X-Git-Url: http://cgit.sxemacs.org/?p=emchat;a=commitdiff_plain;h=0ceabd814bbf0f68f2c2332c8090e4e77e5e1b06;hp=f76c7ce619419ff80076fc36e8e3e58ea608ce21 Send notifications for incoming messages. 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 --- diff --git a/emchat-log.el b/emchat-log.el index f355880..87522f2 100644 --- a/emchat-log.el +++ b/emchat-log.el @@ -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