comparison lisp/net/secrets.el @ 108760:f528b6459bdd

merge trunk
author Kenichi Handa <handa@etlken>
date Tue, 25 May 2010 09:35:50 +0900
parents 69ac0d220a1c
children 68a3b6b312ee
comparison
equal deleted inserted replaced
108759:0bb727f1d547 108760:f528b6459bdd
149 (declare-function dbus-register-signal "dbusbind.c") 149 (declare-function dbus-register-signal "dbusbind.c")
150 (defvar dbus-debug) 150 (defvar dbus-debug)
151 151
152 (require 'dbus) 152 (require 'dbus)
153 153
154 (declare-function tree-widget-set-theme "tree-widget") 154 (autoload 'tree-widget-set-theme "tree-widget")
155 (declare-function widget-create-child-and-convert "wid-edit") 155 (autoload 'widget-create-child-and-convert "wid-edit")
156 (declare-function widget-default-value-set "wid-edit") 156 (autoload 'widget-default-value-set "wid-edit")
157 (declare-function widget-field-end "wid-edit") 157 (autoload 'widget-field-end "wid-edit")
158 (declare-function widget-member "wid-edit") 158 (autoload 'widget-member "wid-edit")
159 (defvar tree-widget-after-toggle-functions) 159 (defvar tree-widget-after-toggle-functions)
160 160
161 (defvar secrets-enabled nil 161 (defvar secrets-enabled nil
162 "Whether there is a daemon offering the Secret Service API.") 162 "Whether there is a daemon offering the Secret Service API.")
163 163
561 (unless (keywordp (car attributes)) 561 (unless (keywordp (car attributes))
562 (error 'wrong-type-argument (car attributes))) 562 (error 'wrong-type-argument (car attributes)))
563 (setq props (add-to-list 563 (setq props (add-to-list
564 'props 564 'props
565 (list :dict-entry 565 (list :dict-entry
566 (symbol-name (car attributes)) 566 (substring (symbol-name (car attributes)) 1)
567 (cadr attributes)) 567 (cadr attributes))
568 'append) 568 'append)
569 attributes (cddr attributes))) 569 attributes (cddr attributes)))
570 ;; Search. The result is a list of two lists, the object paths 570 ;; Search. The result is a list of two lists, the object paths
571 ;; of the unlocked and the locked items. 571 ;; of the unlocked and the locked items.
599 (unless (keywordp (car attributes)) 599 (unless (keywordp (car attributes))
600 (error 'wrong-type-argument (car attributes))) 600 (error 'wrong-type-argument (car attributes)))
601 (setq props (add-to-list 601 (setq props (add-to-list
602 'props 602 'props
603 (list :dict-entry 603 (list :dict-entry
604 (symbol-name (car attributes)) 604 (substring (symbol-name (car attributes)) 1)
605 (cadr attributes)) 605 (cadr attributes))
606 'append) 606 'append)
607 attributes (cddr attributes))) 607 attributes (cddr attributes)))
608 ;; Create the item. 608 ;; Create the item.
609 (setq result 609 (setq result
654 If there is no such item, or the item has no attributes, return nil." 654 If there is no such item, or the item has no attributes, return nil."
655 (unless (stringp collection) (setq collection "default")) 655 (unless (stringp collection) (setq collection "default"))
656 (let ((item-path (secrets-item-path collection item))) 656 (let ((item-path (secrets-item-path collection item)))
657 (unless (secrets-empty-path item-path) 657 (unless (secrets-empty-path item-path)
658 (mapcar 658 (mapcar
659 (lambda (attribute) (cons (intern (car attribute)) (cadr attribute))) 659 (lambda (attribute)
660 (cons (intern (concat ":" (car attribute))) (cadr attribute)))
660 (dbus-get-property 661 (dbus-get-property
661 :session secrets-service item-path 662 :session secrets-service item-path
662 secrets-interface-item "Attributes"))))) 663 secrets-interface-item "Attributes")))))
663 664
664 (defun secrets-get-attribute (collection item attribute) 665 (defun secrets-get-attribute (collection item attribute)
676 secrets-interface-item "Delete"))))) 677 secrets-interface-item "Delete")))))
677 678
678 ;;; Visualization. 679 ;;; Visualization.
679 680
680 (define-derived-mode secrets-mode nil "Secrets" 681 (define-derived-mode secrets-mode nil "Secrets"
681 "Major mode for presenting search results of a Xesam search. 682 "Major mode for presenting password entries retrieved by Security Service.
682 In this mode, widgets represent the search results. 683 In this mode, widgets represent the search results.
683 684
684 \\{secrets-mode-map} 685 \\{secrets-mode-map}"
685 Turning on Xesam mode runs the normal hook `xesam-mode-hook'. It
686 can be used to set `xesam-notify-function', which must a search
687 engine specific, widget :notify function to visualize xesam:url."
688 ;; Keymap. 686 ;; Keymap.
689 (setq secrets-mode-map (copy-keymap special-mode-map)) 687 (setq secrets-mode-map (copy-keymap special-mode-map))
690 (set-keymap-parent secrets-mode-map widget-keymap) 688 (set-keymap-parent secrets-mode-map widget-keymap)
691 (define-key secrets-mode-map "z" 'kill-this-buffer) 689 (define-key secrets-mode-map "z" 'kill-this-buffer)
692 690
705 703
706 ;; The very first buffer created with `secrets-mode' does not have the 704 ;; The very first buffer created with `secrets-mode' does not have the
707 ;; keymap etc. So we create a dummy buffer. Stupid. 705 ;; keymap etc. So we create a dummy buffer. Stupid.
708 (with-temp-buffer (secrets-mode)) 706 (with-temp-buffer (secrets-mode))
709 707
710 ;;;###autoload 708 ;; We autoload `secrets-show-secrets' only on systems with D-Bus support.
709 ;;;###autoload(when (featurep 'dbusbind)
710 ;;;###autoload (autoload 'secrets-show-secrets "secrets" nil t))
711
711 (defun secrets-show-secrets () 712 (defun secrets-show-secrets ()
712 "Display a list of collections from the Secret Service API. 713 "Display a list of collections from the Secret Service API.
713 The collections are in tree view, that means they can be expanded 714 The collections are in tree view, that means they can be expanded
714 to the corresponding secret items, which could also be expanded 715 to the corresponding secret items, which could also be expanded
715 to their attributes." 716 to their attributes."
716 (interactive) 717 (interactive)
717 ;; Create the search buffer. 718
718 (with-current-buffer (get-buffer-create "*Secrets*") 719 ;; Check, whether the Secret Service API is enabled.
719 (switch-to-buffer-other-window (current-buffer)) 720 (if (null secrets-enabled)
720 ;; Inialize buffer with `secrets-mode'. 721 (message "Secret Service not available")
721 (secrets-mode) 722
722 (secrets-show-collections))) 723 ;; Create the search buffer.
724 (with-current-buffer (get-buffer-create "*Secrets*")
725 (switch-to-buffer-other-window (current-buffer))
726 ;; Inialize buffer with `secrets-mode'.
727 (secrets-mode)
728 (secrets-show-collections))))
723 729
724 (defun secrets-show-collections () 730 (defun secrets-show-collections ()
725 "Show all available collections." 731 "Show all available collections."
726 (let ((inhibit-read-only t) 732 (let ((inhibit-read-only t)
727 (alias (secrets-get-alias "default"))) 733 (alias (secrets-get-alias "default")))
755 (let* ((coll (widget-get widget :collection)) 761 (let* ((coll (widget-get widget :collection))
756 (item (widget-get widget :item)) 762 (item (widget-get widget :item))
757 (attributes (secrets-get-attributes coll item)) 763 (attributes (secrets-get-attributes coll item))
758 ;; padding is needed to format attribute names. 764 ;; padding is needed to format attribute names.
759 (padding 765 (padding
760 (1+ 766 (apply
761 (apply 767 'max
762 'max 768 (cons
763 (cons 769 (1+ (length "password"))
764 (length "password") 770 (mapcar
765 (mapcar 771 ;; Atribute names have a leading ":", which will be suppressed.
766 (lambda (attribute) (length (symbol-name (car attribute)))) 772 (lambda (attribute) (length (symbol-name (car attribute))))
767 attributes)))))) 773 attributes)))))
768 (cons 774 (cons
769 ;; The password widget. 775 ;; The password widget.
770 `(editable-field :tag "password" 776 `(editable-field :tag "password"
771 :secret ?* 777 :secret ?*
772 :value ,(secrets-get-secret coll item) 778 :value ,(secrets-get-secret coll item)
777 "%{%t%}:" 783 "%{%t%}:"
778 (make-string (- padding (length "password")) ? ) 784 (make-string (- padding (length "password")) ? )
779 "%v\n")) 785 "%v\n"))
780 (mapcar 786 (mapcar
781 (lambda (attribute) 787 (lambda (attribute)
782 (let ((name (symbol-name (car attribute))) 788 (let ((name (substring (symbol-name (car attribute)) 1))
783 (value (cdr attribute))) 789 (value (cdr attribute)))
784 ;; The attribute widget. 790 ;; The attribute widget.
785 `(editable-field :tag ,name 791 `(editable-field :tag ,name
786 :value ,value 792 :value ,value
787 :sample-face widget-documentation 793 :sample-face widget-documentation