diff options
| author | Michael Albinus | 2008-04-08 19:55:03 +0000 |
|---|---|---|
| committer | Michael Albinus | 2008-04-08 19:55:03 +0000 |
| commit | 074a226b428e67624b59e7169d875846ddbf1c40 (patch) | |
| tree | 96b2a8ee153fd43644693b69d1f8e4c14910fe9e | |
| parent | 96f59d64e4500ba8157e07aac9759a4a9fcdcb77 (diff) | |
| download | emacs-074a226b428e67624b59e7169d875846ddbf1c40.tar.gz emacs-074a226b428e67624b59e7169d875846ddbf1c40.zip | |
* ps-samp.el (ps-add-printer, ps-remove-printer)
(ps-make-dynamic-printer-menu): New functions.
| -rw-r--r-- | lisp/ps-samp.el | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lisp/ps-samp.el b/lisp/ps-samp.el index ffe434b1815..2908428625b 100644 --- a/lisp/ps-samp.el +++ b/lisp/ps-samp.el | |||
| @@ -237,6 +237,77 @@ | |||
| 237 | 237 | ||
| 238 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 238 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 239 | 239 | ||
| 240 | ;; If zeroconf is enabled, all CUPS printers can be detected. The | ||
| 241 | ;; "Postscript printer" menu will be modified dynamically, as printers | ||
| 242 | ;; are added or removed. | ||
| 243 | |||
| 244 | ;; Preconditions: | ||
| 245 | ;; | ||
| 246 | ;; * Emacs has D-Bus support enabled. That is, D-Bus is installed on | ||
| 247 | ;; the system, and Emacs has been configured and built with the | ||
| 248 | ;; --with-dbus option. | ||
| 249 | ;; | ||
| 250 | ;; * The zeroconf daemon avahi-daemon is running. | ||
| 251 | ;; | ||
| 252 | ;; * CUPS has enabled the option "Share published printers connected | ||
| 253 | ;; to this system" (see <http://localhost:631/admin>). | ||
| 254 | |||
| 255 | (eval-when-compile | ||
| 256 | (require 'cl)) | ||
| 257 | |||
| 258 | (eval-and-compile | ||
| 259 | (require 'printing) | ||
| 260 | (require 'zeroconf)) | ||
| 261 | |||
| 262 | ;; Add a Postscript printer to the "Postscript printer" menu. | ||
| 263 | (defun ps-add-printer (service) | ||
| 264 | (let ((name (zeroconf-service-name service)) | ||
| 265 | (text (zeroconf-service-txt service)) | ||
| 266 | (addr (zeroconf-service-address service)) | ||
| 267 | (port (zeroconf-service-port service)) | ||
| 268 | is-ps cups-queue) | ||
| 269 | ;; `text' is an array of key=value strings like ("Duplex=T" "Copies=T"). | ||
| 270 | (dolist (string text) | ||
| 271 | (let ((split (split-string string "=" t))) | ||
| 272 | ;; If it is a Postscript printer, there must be a string like | ||
| 273 | ;; "pdl=application/postscript,application/vnd.hp-PCL,...". | ||
| 274 | (when (and (string-equal "pdl" (car split)) | ||
| 275 | (string-match "application/postscript" (cadr split))) | ||
| 276 | (setq is-ps t)) | ||
| 277 | ;; A CUPS printer queue is coded as "rp=printers/<name>". | ||
| 278 | (when (and (string-equal "rp" (car split)) | ||
| 279 | (string-match "printers/\\(.+\\)" (cadr split))) | ||
| 280 | (setq cups-queue (match-string 1 (cadr split)))))) | ||
| 281 | ;; Add the printer. | ||
| 282 | (when is-ps | ||
| 283 | (if cups-queue | ||
| 284 | (add-to-list | ||
| 285 | 'pr-ps-printer-alist (list (intern name) "lpr" nil "-P" cups-queue)) | ||
| 286 | ;; No CUPS printer, but a network printer. | ||
| 287 | (add-to-list | ||
| 288 | 'pr-ps-printer-alist (list (intern name) "cupsdoprint" | ||
| 289 | '("-P" "default") | ||
| 290 | "-H" (format "%s:%s" addr port)))) | ||
| 291 | (pr-update-menus t)))) | ||
| 292 | |||
| 293 | ;; Remove a printer from the "Postscript printer" menu. | ||
| 294 | (defun ps-remove-printer (service) | ||
| 295 | (setq pr-ps-printer-alist | ||
| 296 | (delete (assoc (intern (zeroconf-service-name service)) | ||
| 297 | pr-ps-printer-alist) | ||
| 298 | pr-ps-printer-alist)) | ||
| 299 | (pr-update-menus t)) | ||
| 300 | |||
| 301 | ;; Activate the functions in zeroconf. | ||
| 302 | (defun ps-make-dynamic-printer-menu () | ||
| 303 | (when (featurep 'dbusbind) | ||
| 304 | (zeroconf-init) | ||
| 305 | (zeroconf-service-add-hook "_ipp._tcp" :new 'ps-add-printer) | ||
| 306 | (zeroconf-service-add-hook "_ipp._tcp" :removed 'ps-remove-printer))) | ||
| 307 | |||
| 308 | |||
| 309 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 310 | |||
| 240 | (provide 'ps-samp) | 311 | (provide 'ps-samp) |
| 241 | 312 | ||
| 242 | ;; arch-tag: 99c415d3-be39-43c6-aa32-7ee33ba19600 | 313 | ;; arch-tag: 99c415d3-be39-43c6-aa32-7ee33ba19600 |