MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Declarative Service Framework Notes Manager

Files:

Execution

This example requires the example Notes Manager service to be pre-registered in order for the application to obtain the default interface. This can be done by using the service framework command line tool to add the corresponding service XML file:

  • ./servicefw add notesmanagerservice.xml

There are 2 ways to run the example:

  • ./qmlnotes (only method for Symbian)
  • qmlviewer declarative-sfw-notes.qml

The XML files for all example services can be found in the QtMobility build directory under install/bin/xmldata

Explanation

This example demonstrates how to use the Notes Manager service plugin to implement a notes managing application with QML as the declarative user-interface. There is also a non-QML counterpart which demonstrates an identical application using standard Qt user-interface tools. See Service Framework Notes Manager for more details.

The QServiceManager and QServiceInterfaceDescriptor API are provided to QML through the use of a plugin-based system that allows users to describe a service as a QML element called Service. The service framework QML plugin also acces to an instance of the service from within QML so that clients can make metacalls on the service object.

This example demonstrates how QML can be used to completely control the logic of the application, using a combination of declarative elements and Javascript code. To run the application refer to the above execution instructions on how to setup and run the example.

There is also another service framework example that demonstrates how to use the QML library plugin browse a list of services to select for dialing usage. See Declarative Service Framework Dialer for a detailed explanation.

The section below explains how QML can be used to emulate to exact functionality of the alternate Qt/C++ example.

QML File

The very first step is to import our QtMobility Service Framework QML plugin library which containts the required QML elements:

 import QtMobility.serviceframework 1.1

In most cases we will need the service instance to be available to all parts of the QML file, meaning that we should declare a global variant for the QObject returned from the service instance. It is also good practice to initialise this value to 0.

 property variant notesManager: 0

Now we can initiate our Service element with a default interface name and obtain the service instance to our global object variable in the component on-completion section.

 Service {
     id: notesService
     interfaceName: "com.nokia.qt.examples.NotesManager"

     Component.onCompleted: {
         notesManager = notesService.serviceObject;
     }
 }

Although a default instance is obtained, the application allows for manually specifying the Service::interfaceName property of the Service element to check if there was a valid default service at this interface name. Similarly, if there is a valid descriptor then the service instance can be obtained and we can call the initialise code of our notes manager.

 notesService.interfaceName = input;

 if (notesService.valid) {
     notesManager = notesService.serviceObject;
     notesManager.init();

Connecting signals from our service object requires the following code. Note the use of the ignoreUnknownSignals property which removes warnings for connecting unknown signals before QML has obtained its QObject service instance.

 Connections {
     target: notesManager
     ignoreUnknownSignals: true

     onSoundAlarm: {
         alarmDialog.text = "ALERT SOUNDED!!!" + "\n\n" +
                            formatDateTime(alarm) + "\n\n" + notesManager.alarmMessage;
         alarmDialog.opacity = 1;
     }
 }

With a valid reference which points to the service plugin class we can now invoke methods directly from the Notes Manager plugin. The example below shows how to obtain a list of notes and delete one from the notes manager database through QML.

 var list = notesManager.noteSet;
 notesManager.removeNote(list[curr-1].index);

The Notes Manager plugin also provides readable functions which return the values of a single note and can be utilized to display on the UI as follows:

 notesManager.setSearch(searchText);
 var list = notesManager.noteSet;
 size = list.length;

 if (size > 0) {
     noteLabel.text = list[curr-1].message;
     datetimeLabel.text = formatDateTime(list[curr-1].alarm);
 }