views:

48

answers:

1

Hi all,

I am writing an elisp file to integrate GNU Emacs with Zeitgeist over dbus. Because of the lack of good documentation on dbus in emacs and my lack of experience with advanced elisp, I am coming up with the following error in my method zeitgeist-send:

Wrong type argument: D-Bus, (zeitgeist-event-timestamp)

I have tried correcting the issue by placing :string before all the arguments, but that gave me the error:

Wrong type argument: stringp, (zeitgeist-event-timestamp)

This makes no sense, as I am positive that the value of (zeitgeist-event-timestamp) is a string.

If you need, the dbus documentation for zeitgeist is here. The format for it is asaasay.

Here is the code:

(require 'dbus)
(defun zeitgeist-call (method &rest args)
  "Call the zeitgeist method METHOD with ARGS over dbus"
  (apply 'dbus-call-method 
    :session                            ; use the session (not system) bus
    "org.gnome.zeitgeist.Engine"        ; service name
    "/org/gnome/zeitgeist/log/activity" ; path name
    "org.gnome.zeitgeist.Log"           ; interface name
    method args))

(defun zeitgeist-event-timestamp ()
  "Get the timestamp in zeitgeist format."
  (let* ((now-time (current-time))
         (hi       (car now-time))
         (lo       (car (cdr now-time)))
         (msecs    (car (cdr (cdr now-time))))) ; This is *micro*seconds. 

    (number-to-string (+ (/ msecs 1000)
       (* (+ lo (* hi 65536))     1000))))) ; Convert system time to milliseconds.

(defun zeitgeist-event-interpretation (event)
  "Get the Event Interpretation of EVENT."
  (case event
    ('zeitgeist-open-event
       "http://zeitgeist-project.com/ontologies/2010/01/27/zg#AccessEvent")
    ('zeitgeist-close-event
       "http://zeitgeist-project.com/schema/1.0/core#CloseEvent")
    ('zeitgeist-create-event
       "http://zeitgeist-project.com/schema/1.0/core#CreateEvent")
    ('zeitgeist-modify-event
       "http://zeitgeist-project.com/schema/1.0/core#ModifyEvent")
    (otherwise nil)))

(defun zeitgeist-send (event fileurl filemime)
  "Send zeitgeist an event EVENT using the list FILEINFO."
  (let ((event-interpretation (zeitgeist-event-interpretation event)))
    (if (eq nil event-interpretation)
      (message "YOU FAIL")
      (zeitgeist-call "InsertEvents"
        '(""
        (zeitgeist-event-timestamp)
        event-interpretation
        "http://zeitgeist-project.com/schema/1.0/core#UserActivity"
        "app://emacs.desktop")
        '((fileurl
        "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#Document"
        "http://www.semanticdesktop.org/ontologies/nfo/#FileDataObject"
        fileurl
        filemime
        (file-name-sans-versions fileurl)
        "")) ; Some black magic later
        '(:array)))))

(defun zeitgeist-open-file ()
  "Tell zeitgeist we openned a file!"
  (if (eq nil (buffer-file-name))
    (message "You are not on a file.")
    (zeitgeist-send 'zeitgeist-open-event buffer-file-name "text/plain")))

(zeitgeist-open-file)

Thanks for any help! Patrick Niedzielski

+3  A: 

I asked on the mailing list, and I found out that since I was using (quote ...) instead of (list ...), the variables and functions were not evaluated. A stupid LISP mistake.

Also, if anyone is interested, I will send this patch into the Zeitgeist project.

Cheers, Patrick

Patrick Niedzielski
Please do! I've been thinking about Emacs-Zeitgeist integration as well.
Thomas Kappler
I'll post on my blog (http://freesoftwarehacker.blogspot.com/), when I figure out the exact procedure. ^_^
Patrick Niedzielski