Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to use dbus to control things in kde4
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
coolsnowmen
Veteran
Veteran


Joined: 30 Jun 2004
Posts: 1479
Location: No.VA

PostPosted: Mon Oct 13, 2008 7:42 pm    Post subject: How to use dbus to control things in kde4 Reply with quote

How to use dbus to control things in kde4

My apologies if this is somewhere on the forums, but I found very little information on it, and thought that people who used to love dcop would appreciate a primer.

I did this on kde 4.1.69 from the kdesvn overlay
Utilities I used
dbus-send, dbus-monitor [ sys-apps/dbus ]
qdbusviewer [ x11-libs/qt-gui ]

your dbus-send command will look something like this:
Code:
dbus-send --print-reply --type=method_call --dest=$DESTINATION /$OBJECTPATH $MESSSAGENAME.$METHOD $ARGUMENTLIST


I'm going to use telling kde to logout as an example.
Running qdbusviewer one can browse all the messages that are made available currently. For kde 4.1++ there is a lot of interface information installed already.

If your method is going to take arguments, be sure to leave a man dbus-send window open to figure out how to put them in. For simple arguments it will be of the form type1:value type2:value ...

On to my search, not wanting to browse everything just yet I'm going to grep for it to see if I get lucky.
Code:
my_computer # cd / usr/kde/4.2/share/dbus-1/
my_computer # find -name "*.xml" -exec grep -Hi shutdown '{}' \;
./interfaces/org.kde.nsplugins.instance.xml:    <method name="shutdown">
./interfaces/org.kde.KSMServerInterface.xml:    <method name="canShutdown">
./interfaces/org.kde.nsplugins.viewer.xml:    <method name="shutdown">
./interfaces/org.kde.nepomuk.ServiceControl.xml:    <method name="shutdown" />
./interfaces/org.kde.kopete.Client.xml:    <signal name="shutdownRequested">
./interfaces/org.kde.KCookieServer.xml:    <method name="shutdown">
my_computer # find -name "*.xml" -exec grep -Hi logo '{}' \;
./interfaces/org.kde.KSMServerInterface.xml:    <method name="logout">
./interfaces/org.kde.cervisia.cvsservice.xml:    <method name="logout">


Looking through, I would say that ./interfaces/org.kde.KSMServerInterface.xml is of interest.
opening it up I see the interface information I need to help narrow down my search.

Code:
<interface name="org.kde.KSMServerInterface">
    <method name="logout">
      <arg type="i" direction="in"/>
      <arg type="i" direction="in"/>
      <arg type="i" direction="in"/>
    </method>
    <method name="canShutdown">
      <arg type="b" direction="out"/>
    </method>


in a window can see at all times I run dbus-monitor, if you don't have the window space, then consider sshing in to do this. Because dbus event notifications get sent when you change windows in kde4 and this will push out the stuff you want to see.

So I run qdbusviewer with this I can browse various dbus interfaces and test them and see what is sent to the monitor
I can browse org.kde.kwin and force a screen refresh, or a desktop switch. If the method takes arguments then qdbusviewer will prompt for them. Sadly I don't know if important argument values are published anywhere,

Clicking on the refresh method I see this in my monitor:
method call sender=:1.53 -> dest=org.kde.kwin path=/KWin; interface=org.kde.KWin; member=refresh
This tells everything I need to know to form my command:
dbus-send --print-reply --type=method_call --dest=org.kde.kwin /KWin org.kde.KWin.refresh

well with compositing on we don't see anything special but
Code:
dbus-send --print-reply --type=method_call --dest=org.kde.kwin /KWin org.kde.KWin.currentDesktop

returns int32 1
Code:
dbus-send --print-reply --type=method_call --dest=org.kde.kwin /KWin org.kde.KWin.nextDesktop

ooOO, it works

The whole purpose for me was to script cleaning shutdowns so here is my final test (don't test this unless you are prepared for it to work!!)
Code:
dbus-send --print-reply --type=method_call --dest="org.kde.ksmserver" /KSMServer org.kde.KSMServerInterface.logout int32:0 int32:0 int32:0

I don't know what other arguments would do, but I know this worked for me.
_________________
emerge: there are no ebuilds to satisfy "moo"
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 2162
Location: The Peanut Gallery

PostPosted: Wed Oct 15, 2008 10:38 pm    Post subject: Re: How to use dbus to control things in kde4 Reply with quote

coolsnowmen wrote:
My apologies if this is somewhere on the forums, but I found very little information on it, and thought that people who used to love dcop would appreciate a primer.

Wow this rocks coolsnowmen; I used to love dcop so much appreciated :-)
Back to top
View user's profile Send private message
coolsnowmen
Veteran
Veteran


Joined: 30 Jun 2004
Posts: 1479
Location: No.VA

PostPosted: Thu Oct 16, 2008 4:39 am    Post subject: Reply with quote

I appreciate the thanks. feel free to ask any questions, or point out information that would have helped in the original post...
_________________
emerge: there are no ebuilds to satisfy "moo"
Back to top
View user's profile Send private message
steveL
Advocate
Advocate


Joined: 13 Sep 2006
Posts: 2162
Location: The Peanut Gallery

PostPosted: Thu Oct 16, 2008 2:43 pm    Post subject: Reply with quote

I will when I finally upgrade (4.2.1 or sth I reckon) :-)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum