+2008-11-24 Ulf Jasper <ulf@web.de>
+
+ * net/newst-treeview.el (newsticker--treeview-current-feed): Doc
+ string.
+ (newsticker--treeview-item-show): Renamed arg FEED to
+ FEED-NAME-SYMBOL.
+ (newsticker--treeview-tree-update-tag): Removed dead code.
+ (newsticker-treeview-update): Don't update cache.
+ (newsticker-treeview-quit): Don't save cache.
+ (newsticker-treeview-save): Don't save cache. Use `newsticker-dir'.
+ (newsticker-treeview-save): Use `newsticker-dir'.
+ (newsticker--treeview-load): Use `newsticker-dir'.
+ (newsticker--treeview-mark-item): Call `newsticker--cache-save-feed'.
+ Update tags.
+ (newsticker-treeview-tree-do-click): Slightly simplified.
+
+ * net/newst-backend.el (newsticker-dir): New.
+ (newsticker-start): Use `newsticker--cache-read'.
+ (newsticker-stop): Use `newsticker--cache-save'.
+ (newsticker--sentinel-work): Use `newsticker--cache-save-feed'.
+ (newsticker--images-dir): New.
+ (newsticker--image-get, newsticker--image-sentinel): Use
+ `newsticker--images-dir'.
+ (newsticker--cache-save-version1): Backuped version of
+ `newsticker--cache-save'.
+ (newsticker--cache-update): Create newsticker-dir if necessary.
+ (newsticker--cache-dir): New.
+ (newsticker--cache-save): Save feeds separately in `newsticker-dir'.
+ (newsticker--cache-save-feed): New.
+ (newsticker--cache-read-version1): New. Backuped version for reading
+ cache data..
+ (newsticker--cache-read, newsticker--cache-do-read): New.
+
+ * net/newst-reader.el (newsticker--image-read): Use `newsticker--images-dir'.
+
2008-11-24 Chong Yidong <cyd@stupidchicken.com>
* files.el (confirm-nonexistent-file-or-buffer): Allow
;; Filename: newst-backend.el
;; URL: http://www.nongnu.org/newsticker
;; Keywords: News, RSS, Atom
-;; Time-stamp: "31. Oktober 2008, 21:07:17 (ulf)"
+;; Time-stamp: "24. November 2008, 19:39:24 (ulf)"
;; ======================================================================
:type 'string
:group 'newsticker-miscellaneous)
-(defcustom newsticker-imagecache-dirname
- "~/.newsticker-images"
- "Name of the directory where newsticker stores cached images."
+(defcustom newsticker-dir
+ "~/.newsticker"
+ "Name of the directory where newsticker saves cached data."
:type 'string
:group 'newsticker-miscellaneous)
(let ((running (newsticker-running-p)))
;; read old cache if it exists and newsticker is not running
(unless running
- (let ((coding-system-for-read 'utf-8))
- (when (file-exists-p newsticker-cache-filename)
- (with-temp-buffer
- (insert-file-contents newsticker-cache-filename)
- (goto-char (point-min))
- (condition-case nil
- (setq newsticker--cache (read (current-buffer)))
- (error
- (message "Error while reading newsticker cache file!")
- (setq newsticker--cache nil)))))))
+ (newsticker--cache-read))
;; start retrieval timers -- one timer for each feed
(dolist (feed (append newsticker-url-list-defaults newsticker-url-list))
(newsticker--start-feed feed))
Cancel the timers for display and retrieval. Run `newsticker-stop-hook'
if newsticker has been running."
(interactive)
- (newsticker--cache-update t)
+ (newsticker--cache-save)
(when (fboundp 'newsticker-stop-ticker) ; silence compiler warnings
(newsticker-stop-ticker))
(when (newsticker-running-p)
See `newsticker-get-news'."
(let ((coding-system-for-read 'no-conversion))
(condition-case error-data
- (url-retrieve url 'newsticker--get-news-by-url-callback
+ (url-retrieve url 'newsticker--get-news-by-url-callback
(list feed-name))
(error (message "Error retrieving news from %s: %s" feed-name
error-data))))
(setq newsticker--latest-update-time (current-time))
(when something-was-added
;; FIXME: should we care about removed items as well?
- (newsticker--cache-update)
+ (newsticker--cache-save-feed
+ (newsticker--cache-get-feed name-symbol))
(when (fboundp 'newsticker--buffer-set-uptodate) ;silence
;compiler
;warnings
;; ======================================================================
;;; Images
;; ======================================================================
+(defun newsticker--images-dir ()
+ "Return directory where feed images are saved."
+ (concat newsticker-dir "/images"))
+
(defun newsticker--image-get (feed-name url)
"Get image of the news site FEED-NAME from URL.
If the image has been downloaded in the last 24h do nothing."
- (let ((image-name (concat newsticker-imagecache-dirname "/"
- feed-name)))
+ (let ((image-name (concat (newsticker--images-dir) feed-name)))
(if (and (file-exists-p image-name)
(time-less-p (current-time)
(time-add (nth 5 (file-attributes image-name))
(let (image-name)
(save-excursion
(set-buffer (process-buffer process))
- (setq image-name (concat newsticker-imagecache-dirname "/"
- feed-name))
+ (setq image-name (concat (newsticker--images-dir) feed-name))
(set-buffer-file-coding-system 'no-conversion)
;; make sure the cache dir exists
- (unless (file-directory-p newsticker-imagecache-dirname)
- (make-directory newsticker-imagecache-dirname))
+ (unless (file-directory-p (newsticker--images-dir))
+ (make-directory (newsticker--images-dir)))
;; write and close buffer
(let ((require-final-newline nil)
(backup-inhibited t)
(set-buffer-modified-p nil)
(kill-buffer (current-buffer)))))))
-
-
(defun newsticker--insert-image (img string)
"Insert IMG with STRING at point."
(insert-image img string))
newsticker-desc-comp-max))
(string= (substring
(newsticker--desc anitem)
- 0
+ 0
newsticker-desc-comp-max)
desc)
(string= (newsticker--desc anitem)
desc)))))))
- ;;(newsticker--debug-msg "Found %s guid=%s"
+ ;;(newsticker--debug-msg "Found %s guid=%s"
;; (newsticker--title anitem)
;; (newsticker--guid anitem))
(throw 'found anitem)))
(if item
;; does exist already -- change age, update time and position
(progn
- ;;(newsticker--debug-msg "Updating item %s %s %s %s %s -> %s %s
+ ;;(newsticker--debug-msg "Updating item %s %s %s %s %s -> %s %s
;; (guid %s -> %s)"
;; feed-name-symbol title link time age
;; updated-time updated-age
(throw 'result t)))))
(< (or (newsticker--pos item1) 0) (or (newsticker--pos item2) 0))))
-
-
-(defun newsticker--cache-save ()
+(defun newsticker--cache-save-version1 ()
"Update and save newsticker cache file."
(interactive)
(newsticker--cache-update t))
"Update newsticker cache file.
If optional argument SAVE is not nil the cache file is saved to disk."
(save-excursion
+ (unless (file-directory-p newsticker-dir)
+ (make-directory newsticker-dir t))
(let ((coding-system-for-write 'utf-8)
(buf (find-file-noselect newsticker-cache-filename)))
(when buf
FEED is a symbol!"
(assoc feed newsticker--cache))
+(defun newsticker--cache-dir ()
+ "Return directory for saving cache data."
+ (concat newsticker-dir "/feeds"))
+
+(defun newsticker--cache-save ()
+ "Save cache data for all feeds."
+ (unless (file-directory-p newsticker-dir)
+ (make-directory newsticker-dir t))
+ (mapc 'newsticker--cache-save-feed newsticker--cache)
+ nil)
+
+(defun newsticker--cache-save-feed (feed)
+ "Save cache data for FEED."
+ (let ((dir (concat (newsticker--cache-dir) "/" (symbol-name (car feed)))))
+ (unless (file-directory-p dir)
+ (make-directory dir t))
+ (let ((coding-system-for-write 'utf-8))
+ (with-temp-file (concat dir "/data")
+ (insert ";; -*- coding: utf-8 -*-\n")
+ (insert (prin1-to-string (cdr feed)))))))
+
+(defun newsticker--cache-read-version1 ()
+ "Read version1 cache data."
+ (let ((coding-system-for-read 'utf-8))
+ (when (file-exists-p newsticker-cache-filename)
+ (with-temp-buffer
+ (insert-file-contents newsticker-cache-filename)
+ (goto-char (point-min))
+ (condition-case nil
+ (setq newsticker--cache (read (current-buffer)))
+ (error
+ (message "Error while reading newsticker cache file!")
+ (setq newsticker--cache nil)))))))
+
+(defun newsticker--cache-read ()
+ "Read cache data."
+ (setq newsticker--cache nil)
+ (if (file-exists-p newsticker-cache-filename)
+ (progn
+ (when (y-or-n-p "Old newsticker cache file exists. Read it? ")
+ (newsticker--cache-read-version1))
+ (message "Please remove/rename the old cache file (%s) now."
+ newsticker-cache-filename))
+ (mapc (lambda (f)
+ (newsticker--cache-read-feed (car f)))
+ (append newsticker-url-list-defaults newsticker-url-list))))
+
+(defun newsticker--cache-read-feed (feed-name)
+ "Read cache data for feed named FEED-NAME."
+ (let ((file-name (concat (newsticker--cache-dir) "/" feed-name "/data"))
+ (coding-system-for-read 'utf-8))
+ (when (file-exists-p file-name)
+ (with-temp-buffer
+ (insert-file-contents file-name)
+ (goto-char (point-min))
+ (condition-case nil
+ (add-to-list 'newsticker--cache (cons (intern feed-name)
+ (read (current-buffer))))
+ (error
+ (message "Error while reading newsticker cache file %s!"
+ file-name))
+ (setq newsticker--cache nil))))))
+
;; ======================================================================
;;; Statistics
;; ======================================================================
;; arch-tag: 0e37b658-56e9-49ab-90f9-f2df57e1a659
;;; newsticker-backend.el ends here
+
+(provide 'newst-backend)
+
+;;; newst-backend.el ends here
;; URL: http://www.nongnu.org/newsticker
;; Created: 2007
;; Keywords: News, RSS, Atom
-;; Time-stamp: "31. Oktober 2008, 20:44:46 (ulf)"
+;; Time-stamp: "24. November 2008, 19:49:20 (ulf)"
;; ======================================================================
;; ======================================================================
(defvar newsticker--treeview-windows nil)
(defvar newsticker--treeview-buffers nil)
-(defvar newsticker--treeview-current-feed nil)
+(defvar newsticker--treeview-current-feed nil
+ "Feed name of currently shown item.")
(defvar newsticker--treeview-current-vfeed nil)
(defvar newsticker--treeview-list-show-feed nil)
(defvar newsticker--saved-window-config nil)
(newsticker-treeview-mode)
(goto-char (point-min)))))
-(defun newsticker--treeview-item-show (item feed)
- "Show news ITEM coming from FEED in treeview item buffer."
+(defun newsticker--treeview-item-show (item feed-name-symbol)
+ "Show news ITEM coming from FEED-NAME-SYMBOL in treeview item buffer."
+ (setq newsticker--treeview-current-feed (symbol-name feed-name-symbol))
(save-excursion
(set-buffer (newsticker--treeview-item-buffer))
(when (fboundp 'w3m-process-stop)
(kill-all-local-variables)
(remove-overlays)
- (when (and item feed)
+ (when (and item feed-name-symbol)
(let ((wwidth (1- (window-width (newsticker--treeview-item-window)))))
(if newsticker-use-full-width
(set (make-local-variable 'fill-column) wwidth))
(goto-char (point-min))
;; insert logo at top
(let* ((newsticker-enable-logo-manipulations nil)
- (img (newsticker--image-read feed nil)))
+ (img (newsticker--image-read feed-name-symbol nil)))
(if (and (display-images-p) img)
(newsticker--insert-image img (car item))
- (insert (newsticker--real-feed-name feed))))
+ (insert (newsticker--real-feed-name feed-name-symbol))))
(add-text-properties (point-min) (point)
(list 'face 'newsticker-feed-face
'mouse-face 'highlight
well. Argument IGNORE is ignored. Note that this function, if
called recursively, makes w invalid. You should keep w's nt-id in
that case."
- ;;(message "newsticker--treeview-tree-update-tag %s, %s" (widget-get w :tag)
- ;; (widget-type w))
(let* ((parent (widget-get w :parent))
(feed (or (widget-get w :nt-feed) (widget-get parent :nt-feed)))
(vfeed (or (widget-get w :nt-vfeed) (widget-get parent :nt-vfeed)))
"Update all treeview buffers and windows.
Note: does not update the layout."
(interactive)
- (newsticker--cache-update)
(newsticker--group-manage-orphan-feeds)
(newsticker--treeview-list-update t)
(newsticker--treeview-item-update)
(defun newsticker-treeview-quit ()
"Quit newsticker treeview."
(interactive)
- (newsticker-treeview-save)
(setq newsticker--sentinel-callback nil)
(bury-buffer "*Newsticker Tree*")
(bury-buffer "*Newsticker List*")
(defun newsticker-treeview-save ()
"Save newsticker data including treeview settings."
(interactive)
- (newsticker--cache-save)
(save-excursion
(let ((coding-system-for-write 'utf-8)
- (buf (find-file-noselect newsticker-groups-filename)))
+ (buf (find-file-noselect (concat newsticker-dir "/groups"))))
(when buf
(set-buffer buf)
(setq buffer-undo-list t)
(defun newsticker--treeview-load ()
"Load treeview settings."
(let* ((coding-system-for-read 'utf-8)
- (buf (and (file-exists-p newsticker-groups-filename)
- (find-file-noselect newsticker-groups-filename))))
+ (filename
+ (or (and (file-exists-p newsticker-groups-filename)
+ (y-or-n-p
+ (format "Old newsticker groups (%s) file exists. Read it? "
+ newsticker-groups-filename))
+ newsticker-groups-filename)
+ (concat newsticker-dir "/groups")))
+ (buf (find-file-noselect filename)))
(when buf
(set-buffer buf)
(goto-char (point-min))
(setcar (nthcdr 4 item) new-age)
;; clean up ticker FIXME
)
- (newsticker--cache-update))
+ (newsticker--cache-save-feed
+ (newsticker--cache-get-feed (intern newsticker--treeview-current-feed)))
+ (newsticker--treeview-tree-do-update-tags newsticker--treeview-vfeed-tree))
(defun newsticker-treeview-mark-list-items-old ()
"Mark all listed items as old."
"Actually handle click event.
POS gives the position where EVENT occurred."
(interactive)
- (unless pos (setq pos (point)))
- (let ((pos (or pos (point)))
- (nt-id (get-text-property pos :nt-id))
- (item (get-text-property pos :nt-item)))
+ (let* ((pos (or pos (point)))
+ (nt-id (get-text-property pos :nt-id))
+ (item (get-text-property pos :nt-item)))
(cond (item
;; click in list buffer
(newsticker-treeview-show-item))