diff options
| author | Michael Albinus | 2008-08-01 18:56:08 +0000 |
|---|---|---|
| committer | Michael Albinus | 2008-08-01 18:56:08 +0000 |
| commit | 818f12ceb98044f081ff720ffe08df1b03ba223b (patch) | |
| tree | faa94767bcfb45680f5f12737ddea39fc3adb22f | |
| parent | ba0b66b030088a3fd53172006bbbe67828db8172 (diff) | |
| download | emacs-818f12ceb98044f081ff720ffe08df1b03ba223b.tar.gz emacs-818f12ceb98044f081ff720ffe08df1b03ba223b.zip | |
* net/xesam.el (xesam-all-fields): Remove source and content
identifiers.
(xesam-dbus-unique-names): New defvar.
(xesam-dbus-call-method): New defun. Replace all calls of
`dbus-call-method' by `xesam-dbus-call-method'.
(xesam-get-cached-property, xesam-set-cached-property): New
defuns.
(xesam-get-property, xesam-set-property, xesam-refresh-entry)
(xesam-new-search, xesam-search): Apply
`xesam-get-cached-property'.
(xesam-search-engines): Make it an association list. Take changed
layout into account in the corresponding function.
(xesam-delete-search-engine): Remove check for consistency of
`xesam-search-engines', not needed anymore.
(xesam-mode): Show XML query string only in the debug case.
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/net/xesam.el | 141 |
2 files changed, 109 insertions, 55 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bd9b340f9f7..de5d31ed7bb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2008-08-01 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * net/dbus.el (dbus-check-event, dbus-handle-event): Handle D-Bus | ||
| 4 | error messages. | ||
| 5 | (dbus-set-property): Call `dbus-introspect-get-property' instead | ||
| 6 | of `dbus-get-property'. | ||
| 7 | |||
| 8 | * net/xesam.el (xesam-all-fields): Remove source and content | ||
| 9 | identifiers. | ||
| 10 | (xesam-dbus-unique-names): New defvar. | ||
| 11 | (xesam-dbus-call-method): New defun. Replace all calls of | ||
| 12 | `dbus-call-method' by `xesam-dbus-call-method'. | ||
| 13 | (xesam-get-cached-property, xesam-set-cached-property): New | ||
| 14 | defuns. | ||
| 15 | (xesam-get-property, xesam-set-property, xesam-refresh-entry) | ||
| 16 | (xesam-new-search, xesam-search): Apply | ||
| 17 | `xesam-get-cached-property'. | ||
| 18 | (xesam-search-engines): Make it an association list. Take changed | ||
| 19 | layout into account in the corresponding function. | ||
| 20 | (xesam-delete-search-engine): Remove check for consistency of | ||
| 21 | `xesam-search-engines', not needed anymore. | ||
| 22 | (xesam-mode): Show XML query string only in the debug case. | ||
| 23 | |||
| 1 | 2008-07-31 Juanma Barranquero <lekktu@gmail.com> | 24 | 2008-07-31 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 25 | ||
| 3 | * files.el (read-file-modes): Fix tpo in docstring. | 26 | * files.el (read-file-modes): Fix tpo in docstring. |
diff --git a/lisp/net/xesam.el b/lisp/net/xesam.el index 53581d6b6f7..c864bc2cb83 100644 --- a/lisp/net/xesam.el +++ b/lisp/net/xesam.el | |||
| @@ -163,20 +163,11 @@ | |||
| 163 | "The D-Bus Xesam search interface.") | 163 | "The D-Bus Xesam search interface.") |
| 164 | 164 | ||
| 165 | (defconst xesam-all-fields | 165 | (defconst xesam-all-fields |
| 166 | '("xesam:35mmEquivalent" "xesam:Alarm" "xesam:Archive" "xesam:Audio" | 166 | '("xesam:35mmEquivalent" "xesam:aimContactMedium" "xesam:aperture" |
| 167 | "xesam:AudioList" "xesam:Content" "xesam:DataObject" "xesam:DeletedFile" | 167 | "xesam:aspectRatio" "xesam:attachmentEncoding" "xesam:attendee" |
| 168 | "xesam:Document" "xesam:Email" "xesam:EmailAttachment" "xesam:Event" | 168 | "xesam:audioBirate" "xesam:audioChannels" "xesam:audioCodec" |
| 169 | "xesam:File" "xesam:FileSystem" "xesam:FreeBusy" "xesam:IMMessage" | 169 | "xesam:audioCodecType" "xesam:audioSampleFormat" "xesam:audioSampleRate" |
| 170 | "xesam:Image" "xesam:Journal" "xesam:Mailbox" "xesam:Media" | 170 | "xesam:author" "xesam:bcc" "xesam:birthDate" "xesam:blogContactURL" |
| 171 | "xesam:MediaList" "xesam:Message" "xesam:PIM" "xesam:Partition" | ||
| 172 | "xesam:Photo" "xesam:Presentation" "xesam:Project" "xesam:RemoteResource" | ||
| 173 | "xesam:Software" "xesam:SourceCode" "xesam:Spreadsheet" "xesam:Storage" | ||
| 174 | "xesam:Task" "xesam:TextDocument" "xesam:Video" "xesam:Visual" | ||
| 175 | "xesam:aimContactMedium" "xesam:aperture" "xesam:aspectRatio" | ||
| 176 | "xesam:attachmentEncoding" "xesam:attendee" "xesam:audioBirate" | ||
| 177 | "xesam:audioChannels" "xesam:audioCodec" "xesam:audioCodecType" | ||
| 178 | "xesam:audioSampleFormat" "xesam:audioSampleRate" "xesam:author" | ||
| 179 | "xesam:bcc" "xesam:birthDate" "xesam:blogContactURL" | ||
| 180 | "xesam:cameraManufacturer" "xesam:cameraModel" "xesam:cc" "xesam:ccdWidth" | 171 | "xesam:cameraManufacturer" "xesam:cameraModel" "xesam:cc" "xesam:ccdWidth" |
| 181 | "xesam:cellPhoneNumber" "xesam:characterCount" "xesam:charset" | 172 | "xesam:cellPhoneNumber" "xesam:characterCount" "xesam:charset" |
| 182 | "xesam:colorCount" "xesam:colorSpace" "xesam:columnCount" "xesam:comment" | 173 | "xesam:colorCount" "xesam:colorSpace" "xesam:columnCount" "xesam:comment" |
| @@ -247,13 +238,32 @@ fields are supported.") | |||
| 247 | </request>" | 238 | </request>" |
| 248 | "The Xesam fulltext query XML.") | 239 | "The Xesam fulltext query XML.") |
| 249 | 240 | ||
| 241 | (defvar xesam-dbus-unique-names | ||
| 242 | (list (cons :system (dbus-get-unique-name :system)) | ||
| 243 | (cons :session (dbus-get-unique-name :session))) | ||
| 244 | "The unique names, under which Emacs is registered at D-Bus.") | ||
| 245 | |||
| 246 | (defun xesam-dbus-call-method (&rest args) | ||
| 247 | "Apply a D-Bus method call. | ||
| 248 | `dbus-call-method' is to be preferred, because it is more | ||
| 249 | performant. If the target D-Bus service is owned by Emacs, this | ||
| 250 | is not applicable, and `dbus-call-method-non-blocking' must be | ||
| 251 | used instead. ARGS are identical to the argument list of both | ||
| 252 | functions." | ||
| 253 | (apply | ||
| 254 | ;; The first argument is the bus, the second argument the targt service. | ||
| 255 | (if (string-equal (cdr (assoc (car args) xesam-dbus-unique-names)) | ||
| 256 | (cadr args)) | ||
| 257 | 'dbus-call-method-non-blocking 'dbus-call-method) | ||
| 258 | args)) | ||
| 259 | |||
| 250 | (defun xesam-get-property (engine property) | 260 | (defun xesam-get-property (engine property) |
| 251 | "Return the PROPERTY value of ENGINE." | 261 | "Return the PROPERTY value of ENGINE." |
| 252 | ;; "GetProperty" returns a variant, so we must use the car. | 262 | ;; "GetProperty" returns a variant, so we must use the car. |
| 253 | (car (dbus-call-method | 263 | (car (xesam-dbus-call-method |
| 254 | :session (car engine) xesam-path-search | 264 | :session (car engine) xesam-path-search |
| 255 | xesam-interface-search "GetProperty" | 265 | xesam-interface-search "GetProperty" |
| 256 | (cdr engine) property))) | 266 | (xesam-get-cached-property engine "session") property))) |
| 257 | 267 | ||
| 258 | (defun xesam-set-property (engine property value) | 268 | (defun xesam-set-property (engine property value) |
| 259 | "Set the PROPERTY of ENGINE to VALUE. | 269 | "Set the PROPERTY of ENGINE to VALUE. |
| @@ -262,10 +272,10 @@ value (nil or t), or a list of them. It returns the new value of | |||
| 262 | PROPERTY in the search engine. This new value can be different | 272 | PROPERTY in the search engine. This new value can be different |
| 263 | from VALUE, depending on what the search engine accepts." | 273 | from VALUE, depending on what the search engine accepts." |
| 264 | ;; "SetProperty" returns a variant, so we must use the car. | 274 | ;; "SetProperty" returns a variant, so we must use the car. |
| 265 | (car (dbus-call-method | 275 | (car (xesam-dbus-call-method |
| 266 | :session (car engine) xesam-path-search | 276 | :session (car engine) xesam-path-search |
| 267 | xesam-interface-search "SetProperty" | 277 | xesam-interface-search "SetProperty" |
| 268 | (cdr engine) property | 278 | (xesam-get-cached-property engine "session") property |
| 269 | ;; The value must be a variant. It can be only a string, an | 279 | ;; The value must be a variant. It can be only a string, an |
| 270 | ;; unsigned int, a boolean, or an array of them. So we need | 280 | ;; unsigned int, a boolean, or an array of them. So we need |
| 271 | ;; no type keyword; we let the type check to the search | 281 | ;; no type keyword; we let the type check to the search |
| @@ -294,21 +304,39 @@ from VALUE, depending on what the search engine accepts." | |||
| 294 | 304 | ||
| 295 | (defvar xesam-search-engines nil | 305 | (defvar xesam-search-engines nil |
| 296 | "List of available Xesam search engines. | 306 | "List of available Xesam search engines. |
| 297 | Every entry is a triple of the unique D-Bus service name of the | 307 | Every entry is an association list, with a car denoting the |
| 298 | engine, the session identifier, and the display name. Example: | 308 | unique D-Bus service name of the engine. The rest of the entry |
| 299 | 309 | are cached associations of engine attributes, like the session | |
| 300 | \(\(\":1.59\" \"0t1214948020ut358230u0p2698r3912347765k3213849828\" \"Tracker Xesam Service\") | 310 | identifier, and the display name. Example: |
| 301 | \(\":1.27\" \"strigisession1369133069\" \"Strigi Desktop Search\")) | 311 | |
| 312 | \(\(\":1.59\" | ||
| 313 | \(\"session\" . \"0t1214948020ut358230u0p2698r3912347765k3213849828\") | ||
| 314 | \(\"vendor.display\" . \"Tracker Xesam Service\")) | ||
| 315 | \(\":1.27\" | ||
| 316 | \(\"session\" . \"strigisession1369133069\") | ||
| 317 | \(\"vendor.display\" . \"Strigi Desktop Search\"))) | ||
| 302 | 318 | ||
| 303 | A Xesam-compatible search engine is identified as a queued D-Bus | 319 | A Xesam-compatible search engine is identified as a queued D-Bus |
| 304 | service of `xesam-service-search'.") | 320 | service of the known service `xesam-service-search'.") |
| 321 | |||
| 322 | (defun xesam-get-cached-property (engine property) | ||
| 323 | "Return the PROPERTY value of ENGINE from the cache. | ||
| 324 | If PROPERTY is not existing, retrieve it from ENGINE first." | ||
| 325 | ;; If the property has not been cached yet, we retrieve it from the | ||
| 326 | ;; engine, and cache it. | ||
| 327 | (unless (assoc property engine) | ||
| 328 | (xesam-set-cached-property | ||
| 329 | engine property (xesam-get-property engine property))) | ||
| 330 | (cdr (assoc property engine))) | ||
| 331 | |||
| 332 | (defun xesam-set-cached-property (engine property value) | ||
| 333 | "Set the PROPERTY of ENGINE to VALUE in the cache." | ||
| 334 | (setcdr engine (append (cdr engine) (list (cons property value))))) | ||
| 305 | 335 | ||
| 306 | (defun xesam-delete-search-engine (&rest args) | 336 | (defun xesam-delete-search-engine (&rest args) |
| 307 | "Removes service from `xesam-search-engines'." | 337 | "Remove service from `xesam-search-engines'." |
| 308 | (when (and (= (length args) 3) (stringp (car args))) | 338 | (setq xesam-search-engines |
| 309 | (setq xesam-search-engines | 339 | (delete (assoc (car args) xesam-search-engines) xesam-search-engines))) |
| 310 | (delete (assoc (car args) xesam-search-engines) | ||
| 311 | xesam-search-engines)))) | ||
| 312 | 340 | ||
| 313 | (defun xesam-search-engines () | 341 | (defun xesam-search-engines () |
| 314 | "Return Xesam search engines, stored in `xesam-search-engines'. | 342 | "Return Xesam search engines, stored in `xesam-search-engines'. |
| @@ -322,18 +350,19 @@ If there is no registered search engine at all, the function returns `nil'." | |||
| 322 | (unless (assoc-string service xesam-search-engines) | 350 | (unless (assoc-string service xesam-search-engines) |
| 323 | 351 | ||
| 324 | ;; Open a new session, and add it to the search engines list. | 352 | ;; Open a new session, and add it to the search engines list. |
| 325 | (add-to-list | 353 | (add-to-list 'xesam-search-engines (list service) 'append) |
| 326 | 'xesam-search-engines | 354 | (setq engine (assoc service xesam-search-engines)) |
| 327 | (setq engine | 355 | |
| 328 | (cons service | 356 | ;; Add the session string. |
| 329 | (dbus-call-method | 357 | (xesam-set-cached-property |
| 330 | :session service xesam-path-search | 358 | engine "session" |
| 331 | xesam-interface-search "NewSession"))) | 359 | (xesam-dbus-call-method |
| 332 | 'append) | 360 | :session service xesam-path-search |
| 333 | 361 | xesam-interface-search "NewSession")) | |
| 334 | ;; Set the "search.live" property; otherwise the search engine | 362 | |
| 335 | ;; might refuse to answer. | 363 | ;; Unset the "search.live" property; we don't want to be |
| 336 | ; (xesam-set-property engine "search.live" t) | 364 | ;; informed by changed results. |
| 365 | (xesam-set-property engine "search.live" nil) | ||
| 337 | 366 | ||
| 338 | ;; Check the vendor properties. | 367 | ;; Check the vendor properties. |
| 339 | (setq vendor-id (xesam-get-property engine "vendor.id") | 368 | (setq vendor-id (xesam-get-property engine "vendor.id") |
| @@ -417,7 +446,7 @@ Turning on Xesam mode runs the normal hook `xesam-mode-hook'." | |||
| 417 | (propertize | 446 | (propertize |
| 418 | xesam-query | 447 | xesam-query |
| 419 | 'face 'font-lock-type-face | 448 | 'face 'font-lock-type-face |
| 420 | 'help-echo xesam-xml-string)))))) | 449 | 'help-echo (when xesam-debug xesam-xml-string))))))) |
| 421 | 450 | ||
| 422 | (when (not (interactive-p)) | 451 | (when (not (interactive-p)) |
| 423 | ;; Initialize buffer. | 452 | ;; Initialize buffer. |
| @@ -438,7 +467,7 @@ SEARCH is the search identification in that engine. Both must be strings." | |||
| 438 | "Refreshes one entry in the search buffer." | 467 | "Refreshes one entry in the search buffer." |
| 439 | (let* ((result | 468 | (let* ((result |
| 440 | (car | 469 | (car |
| 441 | (dbus-call-method | 470 | (xesam-dbus-call-method |
| 442 | :session (car engine) xesam-path-search | 471 | :session (car engine) xesam-path-search |
| 443 | xesam-interface-search "GetHits" search 1))) | 472 | xesam-interface-search "GetHits" search 1))) |
| 444 | (snippet) | 473 | (snippet) |
| @@ -446,7 +475,7 @@ SEARCH is the search identification in that engine. Both must be strings." | |||
| 446 | ;; engines don't return usable values so far. | 475 | ;; engines don't return usable values so far. |
| 447 | ; (caaar | 476 | ; (caaar |
| 448 | ; (dbus-ignore-errors | 477 | ; (dbus-ignore-errors |
| 449 | ; (dbus-call-method | 478 | ; (xesam-dbus-call-method |
| 450 | ; :session (car engine) xesam-path-search | 479 | ; :session (car engine) xesam-path-search |
| 451 | ; xesam-interface-search "GetHitData" | 480 | ; xesam-interface-search "GetHitData" |
| 452 | ; search (list xesam-current) '("snippet"))))) | 481 | ; search (list xesam-current) '("snippet"))))) |
| @@ -458,7 +487,7 @@ SEARCH is the search identification in that engine. Both must be strings." | |||
| 458 | (widget-put widget :help-echo "")) | 487 | (widget-put widget :help-echo "")) |
| 459 | 488 | ||
| 460 | ;; Take all results. | 489 | ;; Take all results. |
| 461 | (dolist (field (xesam-get-property engine "hit.fields")) | 490 | (dolist (field (xesam-get-cached-property engine "hit.fields")) |
| 462 | (when (not (zerop (length (caar result)))) | 491 | (when (not (zerop (length (caar result)))) |
| 463 | (when xesam-debug | 492 | (when xesam-debug |
| 464 | (widget-put | 493 | (widget-put |
| @@ -613,12 +642,12 @@ can be either `fulltext-query', or `user-query'. QUERY is a | |||
| 613 | string in the Xesam query language. A string, identifying the | 642 | string in the Xesam query language. A string, identifying the |
| 614 | search, is returned." | 643 | search, is returned." |
| 615 | (let* ((service (car engine)) | 644 | (let* ((service (car engine)) |
| 616 | (session (cdr engine)) | 645 | (session (xesam-get-cached-property engine "session")) |
| 617 | (xml-string | 646 | (xml-string |
| 618 | (format | 647 | (format |
| 619 | (if (eq type 'user-query) xesam-user-query xesam-fulltext-query) | 648 | (if (eq type 'user-query) xesam-user-query xesam-fulltext-query) |
| 620 | query)) | 649 | query)) |
| 621 | (search (dbus-call-method | 650 | (search (xesam-dbus-call-method |
| 622 | :session service xesam-path-search | 651 | :session service xesam-path-search |
| 623 | xesam-interface-search "NewSearch" session xml-string))) | 652 | xesam-interface-search "NewSearch" session xml-string))) |
| 624 | 653 | ||
| @@ -653,11 +682,13 @@ search, is returned." | |||
| 653 | (if (not xesam-debug) | 682 | (if (not xesam-debug) |
| 654 | (list | 683 | (list |
| 655 | 12 (propertized-buffer-identification | 684 | 12 (propertized-buffer-identification |
| 656 | (xesam-get-property engine "vendor.id"))) | 685 | (xesam-get-cached-property engine "vendor.id"))) |
| 657 | (propertize | 686 | (propertize |
| 658 | (xesam-get-property engine "vendor.id") 'help-echo | 687 | (xesam-get-cached-property engine "vendor.id") |
| 688 | 'help-echo | ||
| 659 | (mapconcat | 689 | (mapconcat |
| 660 | '(lambda (x) (format "%s: %s" x (xesam-get-property engine x))) | 690 | '(lambda (x) |
| 691 | (format "%s: %s" x (xesam-get-cached-property engine x))) | ||
| 661 | '("vendor.id" "vendor.version" "vendor.display" "vendor.xesam" | 692 | '("vendor.id" "vendor.version" "vendor.display" "vendor.xesam" |
| 662 | "vendor.ontology.fields" "vendor.ontology.contents" | 693 | "vendor.ontology.fields" "vendor.ontology.contents" |
| 663 | "vendor.ontology.sources" "vendor.extensions" | 694 | "vendor.ontology.sources" "vendor.extensions" |
| @@ -666,7 +697,7 @@ search, is returned." | |||
| 666 | (force-mode-line-update)) | 697 | (force-mode-line-update)) |
| 667 | 698 | ||
| 668 | ;; Start the search. | 699 | ;; Start the search. |
| 669 | (dbus-call-method | 700 | (xesam-dbus-call-method |
| 670 | :session (car engine) xesam-path-search | 701 | :session (car engine) xesam-path-search |
| 671 | xesam-interface-search "StartSearch" search) | 702 | xesam-interface-search "StartSearch" search) |
| 672 | 703 | ||
| @@ -686,7 +717,7 @@ Example: | |||
| 686 | (xesam-search (car (xesam-search-engines)) \"emacs\")" | 717 | (xesam-search (car (xesam-search-engines)) \"emacs\")" |
| 687 | (interactive | 718 | (interactive |
| 688 | (let* ((vendors (mapcar | 719 | (let* ((vendors (mapcar |
| 689 | '(lambda (x) (xesam-get-property x "vendor.display")) | 720 | '(lambda (x) (xesam-get-cached-property x "vendor.display")) |
| 690 | (xesam-search-engines))) | 721 | (xesam-search-engines))) |
| 691 | (vendor | 722 | (vendor |
| 692 | (if (> (length vendors) 1) | 723 | (if (> (length vendors) 1) |
| @@ -698,7 +729,8 @@ Example: | |||
| 698 | ;; ENGINE. | 729 | ;; ENGINE. |
| 699 | (when vendor | 730 | (when vendor |
| 700 | (dolist (elt (xesam-search-engines) engine) | 731 | (dolist (elt (xesam-search-engines) engine) |
| 701 | (when (string-equal (xesam-get-property elt "vendor.display") vendor) | 732 | (when (string-equal |
| 733 | (xesam-get-cached-property elt "vendor.display") vendor) | ||
| 702 | (setq engine elt)))) | 734 | (setq engine elt)))) |
| 703 | ;; QUERY. | 735 | ;; QUERY. |
| 704 | (when vendor | 736 | (when vendor |
| @@ -719,8 +751,7 @@ Example: | |||
| 719 | ;; * Solve error, that xesam-mode does not work the very first time. | 751 | ;; * Solve error, that xesam-mode does not work the very first time. |
| 720 | ;; * Retrieve several results at once. | 752 | ;; * Retrieve several results at once. |
| 721 | ;; * Retrieve hits for the next page in advance. | 753 | ;; * Retrieve hits for the next page in advance. |
| 722 | ;; * With prefix, let's chosse search engine. | 754 | ;; * With prefix, let's choose search engine. |
| 723 | ;; * Improve mode-line handling. Show search string etc. | ||
| 724 | ;; * Minibuffer completion for user queries. | 755 | ;; * Minibuffer completion for user queries. |
| 725 | ;; * `revert-buffer-function' implementation. | 756 | ;; * `revert-buffer-function' implementation. |
| 726 | ;; * Close search when search buffer is killed. | 757 | ;; * Close search when search buffer is killed. |