From: bg66 Date: Fri, 16 Mar 2007 05:05:34 +0000 (+0000) Subject: * mixi-ticker.el: New file. X-Git-Tag: mixi-el-1_0_0~51 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6860933aa1d61de79961c804c2e90cd8fa8882ce;p=elisp%2Fmixi.git * mixi-ticker.el: New file. * Makefile.am (MODULES_MIXI): Add it. --- diff --git a/ChangeLog b/ChangeLog index cb46f1c..01b9007 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-03-16 OHASHI Akira + + * mixi-ticker.el: New file. + * Makefile.am (MODULES_MIXI): Add it. + 2007-03-15 OHASHI Akira * contrib/atom.cgi: New file. diff --git a/Makefile.am b/Makefile.am index d4043f0..f0ec6bd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -MODULES_MIXI = mixi.el mixi-utils.el mixi-atom.el +MODULES_MIXI = mixi.el mixi-utils.el mixi-atom.el mixi-ticker.el MODULES_SHIMBUN = sb-mixi.el mixi-gnus.el mixi-wl.el MODULES_RIECE = riece-mixi.el CONTRIB = contrib/atom.cgi contrib/atom.sh diff --git a/mixi-ticker.el b/mixi-ticker.el new file mode 100644 index 0000000..3f52aa2 --- /dev/null +++ b/mixi-ticker.el @@ -0,0 +1,154 @@ +;; mixi-ticker.el --- ticker for mixi + +;; Copyright (C) 2007 OHASHI Akira + +;; Author: OHASHI Akira +;; Keywords: hypermedia + +;; This file is *NOT* a part of Emacs. + +;; 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 this program; if not, you can either send email to this +;; program's maintainer or write to: The Free Software Foundation, +;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; To use, add the following lines to your ~/.emacs: +;; +;; (autoload 'mixi-ticker-start "mixi-ticker") +;; +;; then M-x mixi-ticker-start will start mixi-ticker. + +;; Bug reports: +;; +;; If you have bug reports and/or suggestions for improvement, please +;; send them via . + +;;; Code: + +(require 'mixi) +(require 'mixi-utils) +(require 'timer) + +(defcustom mixi-ticker-check-list nil + "*A list for checking to detect new articles. +Each element looks like URL or FUNCTION. +URL is the URL for mixi access point of the channel. If URL is friend's, get +his/her diaries as article. If community's, get its BBSes. If diary's or +BBS's, get its comments. +FUNCTION is the function which has one `range' argument and returns the list +of mixi object." + :type '(repeat (radio (string :tag "URL") + (const :tag "New diaries" mixi-get-new-diaries) + (const :tag "New comments" mixi-get-new-comments) + (const :tag "New BBSes" mixi-get-new-bbses) + (const :tag "Messages" mixi-get-messages) + (const :tag "Logs" mixi-get-logs) + (function :tag "Other function"))) + :group 'mixi) + +(defcustom mixi-ticker-check-range 3 + "*The number of ranges that should be checked to detect new articles." + :type 'integer + :group 'mixi) + +(defcustom mixi-ticker-interval 3600 + "*Time interval for checking to detect new articles." + :type 'integer + :group 'mixi) + +(defcustom mixi-ticker-display-interval 0.3 + "*Time interval for displaying new articles." + :type 'number + :group 'mixi) + +(defvar mixi-ticker-timer nil) +(defvar mixi-ticker-display-timer nil) +(defvar mixi-ticker-objects nil) +(defvar mixi-ticker-message nil) +(defvar mixi-ticker-last-check nil) + +(defun mixi-ticker-display () + (when (not (or (active-minibuffer-window) + (and (current-message) + (not (string= (current-message) + mixi-ticker-message))))) + (if (and (stringp mixi-ticker-message) + (> (length mixi-ticker-message) 1)) + (setq mixi-ticker-message + (substring mixi-ticker-message 1)) + (setq mixi-ticker-message nil)) + (unless mixi-ticker-message + (while mixi-ticker-objects + (condition-case nil + (let ((string (mixi-make-title (car mixi-ticker-objects) t))) + (setq mixi-ticker-message (concat mixi-ticker-message " " + (mixi-message string)))) + (error nil)) + (setq mixi-ticker-objects (cdr mixi-ticker-objects)))) + (message mixi-ticker-message))) + +(defun mixi-ticker-check () + "Check to detect new articles." + (setq mixi-ticker-objects nil) + (mapc (lambda (url-or-function) + (let ((objects (mixi-make-objects url-or-function + mixi-ticker-check-range))) + (while objects + (let ((object (car objects))) + (when (mixi-parent-p object) + (let ((comments (mixi-get-comments + object mixi-ticker-check-range))) + (while comments + (let ((time (mixi-object-time (car comments)))) + (when (mixi-time-less-p mixi-ticker-last-check time) + (setq mixi-ticker-objects + (cons (car comments) mixi-ticker-objects)))) + (setq comments (cdr comments))))) + (let ((time (mixi-object-time object))) + (when (mixi-time-less-p mixi-ticker-last-check time) + (setq mixi-ticker-objects (cons object + mixi-ticker-objects))))) + (setq objects (cdr objects))))) + mixi-ticker-check-list) + (setq mixi-ticker-objects (reverse mixi-ticker-objects)) + (setq mixi-ticker-last-check (current-time))) + +;;;###autoload +(defun mixi-ticker-start () + (interactive) + (when mixi-ticker-check-list + (setq mixi-ticker-timer + (run-at-time mixi-ticker-interval mixi-ticker-interval + 'mixi-ticker-check)) + (setq mixi-ticker-display-timer + (run-at-time mixi-ticker-display-interval + mixi-ticker-display-interval + 'mixi-ticker-display)) + (unless mixi-ticker-last-check + (setq mixi-ticker-last-check (current-time))))) + +;;;###autoload +(defun mixi-ticker-stop () + (interactive) + (when (timerp mixi-ticker-timer) + (cancel-timer mixi-ticker-timer) + (setq mixi-ticker-timer nil)) + (when (timerp mixi-ticker-display-timer) + (cancel-timer mixi-ticker-display-timer) + (setq mixi-ticker-display-timer nil))) + +(provide 'mixi-ticker) + +;;; mixi-ticker.el ends here