From d3a00c189c75012524497fd5abca92ec940212fa Mon Sep 17 00:00:00 2001 From: Tadashi MATSUO Date: Sun, 6 Dec 2009 00:31:09 +0900 Subject: [PATCH] The icon images can be retrieved without 'wget'. --- ChangeLog | 9 ++++++ twittering-mode.el | 70 +++++++++++++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index b11d5b75..c7793a7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-12-06 Tadashi MATSUO + + * twittering-mode.el (twittering-use-wget): new variable for + specifying whether the external command `wget' should be used. + (twittering-retrieve-image): new function for retrieving icon + images with/without wget. + (twittering-get-twits): retrieve images with + `twittering-retrieve-image'. + 2009-12-04 Yuto Hayamizu * test/test-twittering-mode.el (sign-string): add test diff --git a/twittering-mode.el b/twittering-mode.el index 9c65ccbb..21222f36 100644 --- a/twittering-mode.el +++ b/twittering-mode.el @@ -291,6 +291,9 @@ directory. You should change through function'twittering-icon-mode'") (defvar twittering-image-type-cache nil) (defvar twittering-convert-program "/usr/bin/convert") (defvar twittering-convert-fix-size nil) +(defvar twittering-use-wget nil + "*If non-nil, icon images are retrieved by invoking \"wget\". +Otherwise, they are retrieved by `url-retrieve'.") (defun twittering-image-type (file-name) (if (and (not (assoc file-name twittering-image-type-cache)) @@ -1277,28 +1280,51 @@ If STATUS-DATUM is already in DATA-VAR, return nil. If not, return t." (twittering-http-get (twittering-last-host) method noninteractive parameters)))) - (if (and twittering-icon-mode window-system) - (if twittering-image-stack - (dolist (url twittering-image-stack) - (let ((file (concat twittering-tmp-dir "/" (twittering-icon-path url)))) - (unless (file-exists-p file) - (let ((proc - (funcall - #'start-process - "wget-images" - (twittering-wget-buffer) - "wget" - "--quiet" - (format "--directory-prefix=%s" twittering-tmp-dir) - "-O" file - url))) - (set-process-sentinel - proc - (lambda (proc stat) - (clear-image-cache) - (save-excursion - (set-buffer (twittering-wget-buffer)) - )))))))))) + (if (and twittering-icon-mode window-system + twittering-image-stack) + (twittering-retrieve-image twittering-image-stack) + )) + +(defun twittering-retrieve-image (images) + (if twittering-use-wget + (twittering-retrieve-image-with-wget images) + (twittering-retrieve-image-without-wget images))) + +(defun twittering-retrieve-image-without-wget (image-urls) + (require 'url) + (dolist (url image-urls) + (let ((file (concat twittering-tmp-dir "/" (twittering-icon-path url)))) + (unless (file-exists-p file) + (url-retrieve + url `(lambda (status) + (goto-char (point-min)) + (search-forward-regexp "^$") + (goto-char (1+ (point))) + (delete-region (point-min) (point)) + (write-file ,file))) + )))) + +(defun twittering-retrieve-image-with-wget (image-urls) + (dolist (url image-urls) + (let ((file (concat twittering-tmp-dir "/" (twittering-icon-path url)))) + (unless (file-exists-p file) + (let ((proc + (funcall + #'start-process + "wget-images" + (twittering-wget-buffer) + "wget" + "--quiet" + (format "--directory-prefix=%s" twittering-tmp-dir) + "-O" file + url))) + (set-process-sentinel + proc + (lambda (proc stat) + (clear-image-cache) + (save-excursion + (set-buffer (twittering-wget-buffer)) + )))))))) (defun twittering-friends-timeline () (interactive)