maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Tinkering with DBus on Jolla (https://talk.maemo.org/showthread.php?t=92303)

EmaNymton 2014-01-07 20:16

Tinkering with DBus on Jolla
 
Hi,
first of all, I'm not an expert using dbus but I wonder, if it is possible to use dbus to show messages on the event-screen of sailfish like on the N9. I started with dbus-monitor and logged for example an incoming email notification:
Code:

...
method call sender=:1.33 -> dest=org.freedesktop.Notifications serial=1070 path=/org/freedesktop/Notifications; interface=org.freedesktop.Notifications; member=Notify
  string "messageserver5"
  uint32 0
  string ""
  string "MY_NAME"
  string "HEADER_OF_MAIL"
  array [
      string "default"
      string ""
  ]
  array [
      dict entry(
        string "x-nemo.email.published-messages"
        variant            string "1400"
      )
      dict entry(
        string "category"
        variant            string "x-nemo.email"
      )
      dict entry(
        string "x-nemo-item-count"
        variant            int32 1
      )
      dict entry(
        string "x-nemo-timestamp"
        variant            string "2014-01-07T19:38:53Z"
      )
      dict entry(
        string "x-nemo-preview-body"
        variant            string "HEADER_OF_MAIL"
      )
      dict entry(
        string "x-nemo-remote-action-default"
        variant            string "com.jolla.email.ui /com/jolla/email/ui com.jolla.email.ui openMessage AAAAAgAAAAV4"
      )
      dict entry(
        string "x-nemo-preview-summary"
        variant            string "MY_NAME"
      )
  ]
  int32 -1
...

So I tried to send a notification via dbus-send
Code:

dbus-send --dest=org.freedesktop.Notifications --print-reply /org/freedesktop/Notifications org.freedesktop.Notifications.Notify string:"" uint32:0 string:"" string:"summary" string:"body"
Error org.freedesktop.DBus.Error.UnknownMethod: No such method 'Notify' in interface 'org.freedesktop.Notifications' at object path '/org/freedesktop/Notifications' (signature 'susss')

:(

The error message is weird, because Notify is a known method
Code:

[nemo@localhost ~]$ dbus-send --session --type=method_call --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.DBus.Introspectable.Introspect
method return sender=:1.29 -> dest=:1.807 reply_serial=2
  string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
  <interface name="org.freedesktop.Notifications">
    <method name="GetCapabilities">
      <arg direction="out" type="as" name="capabilities"/>
    </method>
<method name="Notify">
      <arg direction="in" type="s" name="app_name"/>
      <arg direction="in" type="u" name="replaces_id"/>
      <arg direction="in" type="s" name="app_icon"/>
      <arg direction="in" type="s" name="summary"/>
      <arg direction="in" type="s" name="body"/>
      <arg direction="in" type="as" name="actions"/>
      <arg direction="in" type="a{sv}" name="hints"/>
      <arg direction="in" type="i" name="expire_timeout"/>
      <arg direction="out" type="u" name="id"/>
      <annotation value="QVariantHash" name="org.qtproject.QtDBus.QtTypeName.In6"/>
    </method>
    <method name="CloseNotification">
      <arg direction="in" type="u" name="id"/>
    </method>
    <method name="GetServerInformation">
      <arg direction="out" type="s"/>
      <arg direction="out" type="s" name="name"/>
      <arg direction="out" type="s" name="vendor"/>
      <arg direction="out" type="s" name="version"/>
    </method>
    <signal name="NotificationClosed">
      <arg type="u" name="id"/>
      <arg type="u" name="reason"/>
    </signal>
    <signal name="ActionInvoked">
      <arg type="u" name="id"/>
      <arg type="s" name="action_key"/>
    </signal>
    <method name="GetNotifications">
      <arg direction="in" type="s" name="app_name"/>
      <arg direction="out" type="a(sussasa{sv}i)" name="notifications"/>
      <annotation value="NotificationList" name="org.qtproject.QtDBus.QtTypeName.Out0"/>
    </method>
  </interface>
  <interface name="org.freedesktop.DBus.Properties">
    <method name="Get">
      <arg name="interface_name" type="s" direction="in"/>
      <arg name="property_name" type="s" direction="in"/>
      <arg name="value" type="v" direction="out"/>
    </method>
    <method name="Set">
      <arg name="interface_name" type="s" direction="in"/>
      <arg name="property_name" type="s" direction="in"/>
      <arg name="value" type="v" direction="in"/>
    </method>
    <method name="GetAll">
      <arg name="interface_name" type="s" direction="in"/>
      <arg name="values" type="a{sv}" direction="out"/>
      <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
    </method>
  </interface>
  <interface name="org.freedesktop.DBus.Introspectable">
    <method name="Introspect">
      <arg name="xml_data" type="s" direction="out"/>
    </method>
  </interface>
  <interface name="org.freedesktop.DBus.Peer">
    <method name="Ping"/>
    <method name="GetMachineId">
      <arg name="machine_uuid" type="s" direction="out"/>
    </method>
  </interface>
</node>
"

What am I doing wrong?

pycage 2014-01-07 21:28

Re: Tinkering with DBus on Jolla
 
You can use the notification framework from Nemo (also has easy-to-use QML bindings).
Using D-Bus directly is of course possible as well, but a bit harder.

javispedro 2014-01-07 22:04

Re: Tinkering with DBus on Jolla
 
Quote:

Originally Posted by EmaNymton (Post 1404635)
What am I doing wrong?

That error is also generated even if the method exists but you call it with the wrong number of arguments or the wrong types for the arguments (this is because D-Bus supports Polimorphism).

You might want to read the following thread:
https://bbs.archlinux.org/viewtopic.php?id=114632

As far as I know Sailfish uses the standard "Freedesktop" notification interface, which means it is the same that is used on Gnome, KDE, and other GNU/Linux desktop environments (finally!). This means that any examples designed for those environments should work in your Jolla device, too.
In desktop environments the "notify-send" program can be used to send the appropiate D-Bus calls, too.

EmaNymton 2014-01-08 08:49

Re: Tinkering with DBus on Jolla
 
Thank you for your answers!

I got a simple script working with python-dbus.

After a little research on the web, it seems that dbus-sent does not permit empty containers or nested containers (e.g. arrays of variants), what Notify needs as arguments.
Because I wanted this to write with a python script anyway I gave python-dbus a try, so here it is:
Code:

#!/usr/bin/python
import dbus

bus = dbus.SessionBus()
object = bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications')
interface = dbus.Interface(object,'org.freedesktop.Notifications')
#print(interface.GetCapabilities())

interface.Notify("app_name",
                0,
                "/usr/share/icons/hicolor/86x86/apps/harbour-tidings.png",
                "Here is the title",
                "and here the body",
                dbus.Array(),
                dbus.Array(),
                0)

If you set the icon-path it shows the notification on the event screen and the icon on the lock screen.

https://dl.dropboxusercontent.com/u/...0108094718.jpg

kimmoli 2014-01-08 08:54

Re: Tinkering with DBus on Jolla
 
Quote:

Originally Posted by EmaNymton (Post 1404716)
...dbus-sent does not permit...

It doesn't permit null interface either...

I made my own dbus server, and tried to test it with dbus-send... adding interface to the server and it works.

Thanks for the script, i'll try this from the qt/QML side next.

evk 2014-01-08 09:51

Re: Tinkering with DBus on Jolla
 
Thanks for that. I've just started tinkering with dbus on Jolla, and it's nice to see some simple examples.

kimmoli 2014-01-08 10:06

Re: Tinkering with DBus on Jolla
 
:)
dbus-monitor can show nice things
Code:

signal sender=:1.198 -> dest=(null destination) serial=590 path=/org/freedesktop/Telepathy/Connection/gabble/jabber/gmail_2ecom_1a4623dead_5f0xdabeef; interface=org.freedesktop.Telepathy.Connection.Interface.SimplePresence; member=PresencesChanged
  array [
      dict entry(
        uint32 21
        struct {
            uint32 3
            string "away"
            string "Hell yeah!!!

"
        }
      )
  ]

and also shows your passwords in plain text
Code:

signal sender=:1.433 -> dest=(null destination) serial=12 path=/com/google/code/AccountsSSO/SingleSignOn/AuthSession_0; interface=com.google.code.AccountsSSO.SingleSignOn.AuthSession; member=stateChanged
  int32 8
  string "The request is started successfully"
method return sender=:1.433 -> dest=:1.34 reply_serial=848
  array [
      dict entry(
        string "Secret"
        variant            string "plaintextpassword"
      )
      dict entry(
        string "UserName"
        variant            string "youmightquessthisone"
      )
  ]


EmaNymton 2014-01-08 10:23

Re: Tinkering with DBus on Jolla
 
Ok, now with working pop up notification and using jolla icons placed in /usr/share/themes/jolla-ambient/meegotouch/icons/

https://dl.dropboxusercontent.com/u/...0108112941.jpg

Code:

#!/usr/bin/python
import dbus

bus = dbus.SessionBus()
object = bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications')
interface = dbus.Interface(object,'org.freedesktop.Notifications')
#print(interface.GetCapabilities())

interface.Notify("app_name",
                0,
                "icon-m-notifications",
                "Here is the title",
                "and here the body",
                dbus.Array(["default", ""]),
                dbus.Dictionary({"x-nemo-preview-body": "preview body",
                                  "x-nemo-preview-summary": "preview summary"},
                                  signature='sv'),
                0)


kimmoli 2014-01-08 10:36

Re: Tinkering with DBus on Jolla
 
crap... How i can cast uint32 inside QML ...

junnuvi 2014-01-08 19:26

Re: Tinkering with DBus on Jolla
 
Does anyone know if there is possibility to add sounds for those notifications? Or should that been added seperately?

I'm testing notifications to tell when Sauna is ready :)


All times are GMT. The time now is 01:07.

vBulletin® Version 3.8.8