Qt4 and Hildon home widget interaction

m (Added categories)
m (links)
 
(One intermediate revision not shown)
Line 2: Line 2:
== Service ==
== Service ==
-
The com.nokia.dlh.service file defines the D-Bus service provided by the Qt4 application:
+
The com.nokia.dlh.service file defines the D-Bus service provided by the [[Qt-Maemo|Qt4]] application:
  [D-BUS Service]
  [D-BUS Service]

Latest revision as of 11:28, 15 April 2010

The code in this wiki page is taken from the dlh application and the dlh widget. Since it is FOSS, the source code is available for anyone to adapt freely.

[edit] Service

The com.nokia.dlh.service file defines the D-Bus service provided by the Qt4 application:

[D-BUS Service]
Name=com.nokia.dlh
Exec=/opt/maemo/usr/bin/dlh

There's a reference to this service in the dlh.desktop file too:

X-Osso-Service=com.nokia.dlh

[edit] Application

In the class definition of the objects which will interact with the home widget you need the Q_CLASSINFO macro:

class Widget : public QWidget
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "com.nokia.dlh")
    [...]

The slots have the same name of the D-Bus messages; Q_NOREPLY mark a method to be called and not wait for it to finish processing before returning (see Qt docs):

Q_NOREPLY void CallStartDialog();

The class constructor contains the service and the object registration:

QDBusConnection::sessionBus().registerService("com.nokia.dlh");
QDBusConnection::sessionBus().registerObject("/com/nokia/dlh",this, QDBusConnection::ExportAllContents);

[edit] Home Widget

Some defines:

#define DLH_SERVICE "com.nokia.dlh"
#define DLH_OBJECT  "/com/nokia/dlh"
#define DLH_IFACE   "com.nokia.dlh"

In the init function you have to initialize the osso library (see libosso docs):

osso_context = osso_initialize ("com.nokia.dlh-widget", "0.1", 0, NULL);

When you want to execute the Qt object's slot CallStartDialog from the home widget you will use the following instruction:

osso_rpc_run(osso_context,
             DLH_SERVICE,
             DLH_OBJECT,
             DLH_IFACE,
             "CallStartDialog", NULL, DBUS_TYPE_INVALID);

That's all!