| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies). |
| 4 |
** Contact: http://www.qt-project.org/legal |
| 5 |
** |
| 6 |
** This file is part of the documentation of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:FDL$ |
| 9 |
** Commercial License Usage |
| 10 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 11 |
** accordance with the commercial license agreement provided with the |
| 12 |
** Software or, alternatively, in accordance with the terms contained in |
| 13 |
** a written agreement between you and The Qt Company. For licensing terms |
| 14 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 |
** information use the contact form at https://www.qt.io/contact-us. |
| 16 |
** |
| 17 |
** GNU Free Documentation License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Free |
| 19 |
** Documentation License version 1.3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file included in the packaging of |
| 21 |
** this file. Please review the following information to ensure |
| 22 |
** the GNU Free Documentation License version 1.3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/fdl-1.3.html. |
| 24 |
** $QT_END_LICENSE$ |
| 25 |
** |
| 26 |
****************************************************************************/ |
| 27 |
|
| 28 |
/*! |
| 29 |
\group qml-serviceframework |
| 30 |
\title QML Service Framework Plugin |
| 31 |
QML Support for the QtMobility Project Service Framework API. |
| 32 |
*/ |
| 33 |
|
| 34 |
/*! |
| 35 |
\page qml-serviceframework.html |
| 36 |
|
| 37 |
\title Service Framework QML Plugin |
| 38 |
|
| 39 |
\brief A QML plugin for the QtMobility Project Service Framework API. |
| 40 |
|
| 41 |
\section1 Overview |
| 42 |
|
| 43 |
The Service Framework API in the QtMobility Project gives developers a mechanism for |
| 44 |
discovering and instantiating arbitrary services. The QML Service Framework Plugin |
| 45 |
enables accessing services in a very easy and simple manner by allowing users to |
| 46 |
declare a service or find a list of services using QML. |
| 47 |
|
| 48 |
\section1 Elements |
| 49 |
The service framework QML plugin provides two elements that allow access to |
| 50 |
registered services via QML script. In general, the QML plugin can only discover |
| 51 |
and load pre-registered services and does not support any run-time registration or |
| 52 |
unregistration of services. The servicefw tool can be used to register services |
| 53 |
to the service framework system prior to running any QML script utilising this |
| 54 |
plugin. The two available elements are in the subsequent sections. |
| 55 |
|
| 56 |
\section2 Service |
| 57 |
The \l Service element provides QML with functionality reflecting the |
| 58 |
QServiceInterfaceDescriptor class which represents the details of a single service |
| 59 |
registered on the service framework system. This element also allows the service to |
| 60 |
be loaded so that it will return a QObject reference of the instantiated service |
| 61 |
object. If this element is used on its own and not in conjunction to the ServiceList |
| 62 |
element below, it will represent the default interface at the specified interface |
| 63 |
name, which is the most convenient use-case of the QML plugin. The code snippet below |
| 64 |
demonstrates a typical way to load an interface in QML. |
| 65 |
|
| 66 |
\qml |
| 67 |
import QtQuick 2.0 |
| 68 |
import Qt.serviceframework 5.0 |
| 69 |
|
| 70 |
// ... |
| 71 |
property variant myObject: 0 |
| 72 |
|
| 73 |
Service { |
| 74 |
id: myService |
| 75 |
interfaceName: "com.nokia.qt.examples.ExampleService" |
| 76 |
|
| 77 |
Component.onCompleted: { |
| 78 |
myObject = myService.serviceObject; |
| 79 |
} |
| 80 |
} |
| 81 |
\endqml |
| 82 |
|
| 83 |
In the above code we use a variant to store the QObject reference provided by the |
| 84 |
Service::serviceObject. In this case it will be an instance of the default service |
| 85 |
found at the interface address "com.nokia.qt.examples.ExampleService". The code |
| 86 |
inside the QML component element is recommended so that the variable \e myObject |
| 87 |
holds a valid object instance which can be used throughout the entire QML script. |
| 88 |
|
| 89 |
This element also provides several readable properties about the service interface. |
| 90 |
A useful one is the Service::valid property which will help debug if the system |
| 91 |
has found a valid default interface descriptor at the specified interface name. The |
| 92 |
plugin also allows connecting to signals provided by the service. Here is a typical |
| 93 |
example of receiving service signals within QML for the above code. |
| 94 |
|
| 95 |
\qml |
| 96 |
Connections { |
| 97 |
target: myObject |
| 98 |
ignoreUnknownSignals: true |
| 99 |
|
| 100 |
onMySignal: { |
| 101 |
// do something |
| 102 |
} |
| 103 |
} |
| 104 |
\endqml |
| 105 |
|
| 106 |
Note the usage of the ignoreUnkownSignals attribute which is useful for ignoring |
| 107 |
uknown signals, especially in the case where Service::serviceObject has not been |
| 108 |
called yet or provides an invalid interface. |
| 109 |
|
| 110 |
Once a valid service instance has been obtained its methods and properties can be |
| 111 |
called and accessed as if it were normal QObject in QML. The service framework |
| 112 |
example \l{dialer}{Declarative Dialer Example} demonstrates the use |
| 113 |
of the QML plugin. |
| 114 |
|
| 115 |
\section2 ServiceList |
| 116 |
The \l ServiceList element provides QML with functionality reflecting the |
| 117 |
QServiceFilter class which provides a list of \l Service elements. A very specific |
| 118 |
service list element can be defined by using the following code. |
| 119 |
|
| 120 |
\qml |
| 121 |
ServiceList { |
| 122 |
id: myServiceList |
| 123 |
serviceName: "MyExampleService" |
| 124 |
interfaceName: "com.nokia.qt.examples.ExampleService" |
| 125 |
versionMatch: ServiceList.Exact |
| 126 |
majorVersion: 1 |
| 127 |
minorVersion: 3 |
| 128 |
} |
| 129 |
\endqml |
| 130 |
|
| 131 |
If the ServiceList::serviceName is not supplied the filter will search with a default |
| 132 |
empty string as the service name, meaning all interfaces will be returned regardless |
| 133 |
of the service name. Similarly if no ServiceList::versionMatch is provided the filter |
| 134 |
will search with a minimum version match rule. |
| 135 |
|
| 136 |
The actual QQmlListProperty of \l Service elements can be obtained by reading |
| 137 |
the ServiceList::services property which searches based on the filter values. This |
| 138 |
list model can then be used in a list view element. |
| 139 |
|
| 140 |
\qml |
| 141 |
ListView { |
| 142 |
id: myListView |
| 143 |
model: myServiceList.services |
| 144 |
delegate: myDelegate |
| 145 |
// ... |
| 146 |
} |
| 147 |
\endqml |
| 148 |
|
| 149 |
The service framework example \l{dialer}{Declarative Dialer Example} better |
| 150 |
demonstrates the use of ServiceList coupled with the \l Service element to search |
| 151 |
and select a service instance to implement the QML dialer application. |
| 152 |
|
| 153 |
\section1 Examples |
| 154 |
\list |
| 155 |
\li \l{dialer}{Declarative Serviceframework Dialer Example} |
| 156 |
\endlist |
| 157 |
|
| 158 |
\section1 QML Elements |
| 159 |
\annotatedlist qml-serviceframework |
| 160 |
*/ |