Difference between revisions of "Projects/Marble/MarbleDBus"

Jump to: navigation, search
m
m (Text replace - "<code>" to "<syntaxhighlight lang="text">")
Line 5: Line 5:
 
Before you start you need to find out the PID of the Marble process: In your script you can do it like this.
 
Before you start you need to find out the PID of the Marble process: In your script you can do it like this.
  
<code>
+
<syntaxhighlight lang="text">
 
marble_pid="$(pidof marble)"
 
marble_pid="$(pidof marble)"
 
</code>
 
</code>
Line 12: Line 12:
 
Then you can pass this PID to the actual qdbus call
 
Then you can pass this PID to the actual qdbus call
  
<code>
+
<syntaxhighlight lang="text">
 
qdbus org.kde.marble-$marble_pid /MarbleWidget
 
qdbus org.kde.marble-$marble_pid /MarbleWidget
 
</code>
 
</code>
Line 20: Line 20:
 
From this list you can choose the one that you'd like to call, e.g.
 
From this list you can choose the one that you'd like to call, e.g.
  
<code>
+
<syntaxhighlight lang="text">
 
qdbus org.kde.marble-$marble_pid /MarbleWidget org.kde.MarbleWidget.zoomIn
 
qdbus org.kde.marble-$marble_pid /MarbleWidget org.kde.MarbleWidget.zoomIn
 
</code>
 
</code>
Line 33: Line 33:
  
 
To shorten the following dbus calls, we use
 
To shorten the following dbus calls, we use
<code>
+
<syntaxhighlight lang="text">
 
marble_pid="$(pidof marble)"
 
marble_pid="$(pidof marble)"
 
alias MCALL='qdbus org.kde.marble-${marble_pid} /MarbleWidget'
 
alias MCALL='qdbus org.kde.marble-${marble_pid} /MarbleWidget'
Line 39: Line 39:
  
 
Changing map themes can be done via
 
Changing map themes can be done via
<code>
+
<syntaxhighlight lang="text">
 
MCALL org.kde.MarbleWidget.setMapThemeId "earth/srtm/srtm.dgml"
 
MCALL org.kde.MarbleWidget.setMapThemeId "earth/srtm/srtm.dgml"
 
MCALL org.kde.MarbleWidget.setMapThemeId "earth/openstreetmap/openstreetmap.dgml"
 
MCALL org.kde.MarbleWidget.setMapThemeId "earth/openstreetmap/openstreetmap.dgml"
Line 45: Line 45:
  
 
Move to a place, specified by longitude and latitude
 
Move to a place, specified by longitude and latitude
<code>
+
<syntaxhighlight lang="text">
 
MCALL org.kde.MarbleWidget.centerOn 8.8 53.2
 
MCALL org.kde.MarbleWidget.centerOn 8.8 53.2
 
</code>
 
</code>
  
 
Set the zoom
 
Set the zoom
<code>
+
<syntaxhighlight lang="text">
 
MCALL org.kde.MarbleWidget.zoomView 2000
 
MCALL org.kde.MarbleWidget.zoomView 2000
 
</code>
 
</code>
Line 60: Line 60:
  
 
It is also possible to retrieve parameters from marble, e.g.
 
It is also possible to retrieve parameters from marble, e.g.
<code>
+
<syntaxhighlight lang="text">
 
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget latitude
 
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget latitude
 
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget longitude
 
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget longitude
Line 74: Line 74:
  
 
Opening a gpx file should work via
 
Opening a gpx file should work via
<code>
+
<syntaxhighlight lang="text">
 
MCALL org.kde.MarbleWidget.openGpxFile /tmp/test.gpx
 
MCALL org.kde.MarbleWidget.openGpxFile /tmp/test.gpx
 
</code>
 
</code>
Line 86: Line 86:
 
===No MarbleWidget or MarbleMap===
 
===No MarbleWidget or MarbleMap===
 
<b>Problem:</b> Neither the MarbleMap nor the MarbleWidget interfaces are available in my installation, and qdbus complains:
 
<b>Problem:</b> Neither the MarbleMap nor the MarbleWidget interfaces are available in my installation, and qdbus complains:
<code>
+
<syntaxhighlight lang="text">
 
org.freedesktop.DBus.Error.UnknownObject (No such object path '/MarbleWidget')
 
org.freedesktop.DBus.Error.UnknownObject (No such object path '/MarbleWidget')
 
</code>
 
</code>
Line 92: Line 92:
 
<b>Solution:</b> The D-BUS interface is only available in Marble trunk (and eventually in Marble >= 0.8). Additionally you need to make sure that the "BUILD_WITH_DBUS" cmake flag is set to "ON" once you are building Marble from the source code:
 
<b>Solution:</b> The D-BUS interface is only available in Marble trunk (and eventually in Marble >= 0.8). Additionally you need to make sure that the "BUILD_WITH_DBUS" cmake flag is set to "ON" once you are building Marble from the source code:
  
<code>
+
<syntaxhighlight lang="text">
 
cmake -DBUILD_WITH_DBUS=ON ../marble
 
cmake -DBUILD_WITH_DBUS=ON ../marble
 
</code>
 
</code>

Revision as of 21:49, 29 June 2011

Scripting Marble from the shell using D-BUS

MarbleWidget and MarbleMap provide their full amount of methods as a D-BUS Interface. Therefore you can easily create a shell-script to control Marble using the qdbus command line tool.

Before you start you need to find out the PID of the Marble process: In your script you can do it like this.

marble_pid="$(pidof marble)"
</code>
 
 
Then you can pass this PID to the actual qdbus call
 
<syntaxhighlight lang="text">
qdbus org.kde.marble-$marble_pid /MarbleWidget
</code>
 
 
This call returns a list of all the methods that MarbleWidget supports.
From this list you can choose the one that you'd like to call, e.g.
 
<syntaxhighlight lang="text">
qdbus org.kde.marble-$marble_pid /MarbleWidget org.kde.MarbleWidget.zoomIn
</code>
 
 
to zoom into the map. Note that for function calls you shouldn't pass the brackets "()".
 
As a convenient tool you can use <b>qdbusviewer</b> to get a graphical list of the interfaces and methods that get provided through D-BUS.
 
 
=== Further examples ===
 
To shorten the following dbus calls, we use
<syntaxhighlight lang="text">
marble_pid="$(pidof marble)"
alias MCALL='qdbus org.kde.marble-${marble_pid} /MarbleWidget'
</code>
 
Changing map themes can be done via
<syntaxhighlight lang="text">
MCALL org.kde.MarbleWidget.setMapThemeId "earth/srtm/srtm.dgml"
MCALL org.kde.MarbleWidget.setMapThemeId "earth/openstreetmap/openstreetmap.dgml"
</code>
 
Move to a place, specified by longitude and latitude
<syntaxhighlight lang="text">
MCALL org.kde.MarbleWidget.centerOn 8.8 53.2
</code>
 
Set the zoom
<syntaxhighlight lang="text">
MCALL org.kde.MarbleWidget.zoomView 2000
</code>
 
Note that the range of values passed to zoomView
is defined  in the .dgml files, eg for
marble/data/maps/earth/openstreetmap/openstreetmap.dgml
the range is from 900 to 4000, while for bluemarble it is from 900 to 2400.
 
It is also possible to retrieve parameters from marble, e.g.
<syntaxhighlight lang="text">
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget latitude
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget longitude
MCALL org.freedesktop.DBus.Properties.Get org.kde.MarbleWidget zoom
</code>
to get the current latitude, longitude or zoom.
 
Note that one has to go through org.freedesktop.DBus.Properties.Get
as latitude is not a method, but a property.
 
 
=== Things which (currently) don't work ===
 
Opening a gpx file should work via
<syntaxhighlight lang="text">
MCALL org.kde.MarbleWidget.openGpxFile /tmp/test.gpx
</code>
but gives: "Invalid number of parameters".
This might be a bug on  the qdbus side.
 
----------------
----------------
 
==Trouble shooting==
===No MarbleWidget or MarbleMap===
<b>Problem:</b> Neither the MarbleMap nor the MarbleWidget interfaces are available in my installation, and qdbus complains:
<syntaxhighlight lang="text">
org.freedesktop.DBus.Error.UnknownObject (No such object path '/MarbleWidget')
</code>
 
<b>Solution:</b> The D-BUS interface is only available in Marble trunk (and eventually in Marble >= 0.8). Additionally you need to make sure that the "BUILD_WITH_DBUS" cmake flag is set to "ON" once you are building Marble from the source code:
 
<syntaxhighlight lang="text">
cmake -DBUILD_WITH_DBUS=ON ../marble
</code>

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal