~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to plugins/declarative/serviceframework/qdeclarativeservice.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
**
9
9
** $QT_BEGIN_LICENSE:LGPL$
10
10
** Commercial Usage
11
 
** Licensees holding valid Qt Commercial licenses may use this file in
12
 
** accordance with the Qt Solutions Commercial License Agreement provided
13
 
** with the Software or, alternatively, in accordance with the terms
 
11
** Licensees holding valid Qt Commercial licenses may use this file in 
 
12
** accordance with the Qt Commercial License Agreement provided with
 
13
** the Software or, alternatively, in accordance with the terms
14
14
** contained in a written agreement between you and Nokia.
15
15
**
16
16
** GNU Lesser General Public License Usage
33
33
** ensure the GNU General Public License version 3.0 requirements will be
34
34
** met: http://www.gnu.org/copyleft/gpl.html.
35
35
**
36
 
** Please note Third Party Software included with Qt Solutions may impose
37
 
** additional restrictions and it is the user's responsibility to ensure
38
 
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
 
** Solutions Commercial license and the relevant license of the Third
40
 
** Party Software they are using.
41
 
**
42
36
** If you are unsure which license is appropriate for your use, please
43
37
** contact the sales department at qt-sales@nokia.com.
44
38
** $QT_END_LICENSE$
50
44
QTM_BEGIN_NAMESPACE
51
45
 
52
46
/*!
53
 
    \qmlclass Service
 
47
    \qmlclass Service QDeclarativeService
54
48
    
55
49
    \brief The Service element holds an instance of a service object.
56
50
    \inherits QObject
58
52
    \ingroup qml-serviceframework
59
53
 
60
54
    The Service element is part of the \bold{QtMobility.serviceframework 1.1} module and
61
 
    provides a client instance of the service object by specifying the Service::interfaceName, 
62
 
    Service::serviceName and Service::versionNumber properties.
 
55
    provides a client instance of the service object. This element is a simplified 
 
56
    reflection of the QServiceInterfaceDescriptor class that allows the specification of
 
57
    the Service::interfaceName to locate the default service implemented at this interface.
63
58
 
64
59
    \sa ServiceList
65
60
*/
66
61
QDeclarativeService::QDeclarativeService()
67
 
: serviceInstance(0)
 
62
    : serviceInstance(0)
68
63
{
69
64
    serviceManager = new QServiceManager();
70
65
}
75
70
}
76
71
 
77
72
/*!
78
 
    \qmlproperty bool Service::valid
 
73
    \qmlproperty bool Service::valid read-only
79
74
 
80
75
    This property holds whether a default service was found at the
81
76
    interface name and corresponds to QServiceInterfaceDescriptor::isValid(). 
140
135
}
141
136
 
142
137
/*!
143
 
    \qmlproperty QString Service::versionNumber
144
 
 
145
 
    This property holds the version number of the service that
146
 
    represents \i major.minor corresponding to QServiceInterfaceDescriptor::majorVersion() 
147
 
    and QServiceInterfaceDescriptor::minorVersion(). 
148
 
*/
149
 
QString QDeclarativeService::versionNumber() const
150
 
{
151
 
    if (isValid())
152
 
        return (QString::number(m_descriptor.majorVersion())+"."+QString::number(m_descriptor.minorVersion()));
153
 
    else
154
 
        return "0.0";
 
138
    \qmlproperty int Service::majorVersion
 
139
 
 
140
    This property holds the major version number of the service that
 
141
    corresponds to QServiceInterfaceDescriptor::majorVersion(). 
 
142
*/
 
143
int QDeclarativeService::majorVersion() const
 
144
{
 
145
    if (isValid())
 
146
        return m_descriptor.majorVersion();
 
147
    else
 
148
        return 0;
 
149
}
 
150
 
 
151
/*!
 
152
    \qmlproperty int Service::minorVersion
 
153
 
 
154
    This property holds the minor version number of the service that
 
155
    corresponds to QServiceInterfaceDescriptor::minorVersion(). 
 
156
*/
 
157
int QDeclarativeService::minorVersion() const
 
158
{
 
159
    if (isValid())
 
160
        return m_descriptor.minorVersion();
 
161
    else
 
162
        return 0;
155
163
}
156
164
 
157
165
/*!
168
176
    }
169
177
 
170
178
    if (isValid()) {
171
 
        QServiceManager manager;
172
 
        serviceInstance = manager.loadInterface(m_descriptor);
173
 
       
 
179
        serviceInstance = serviceManager->loadInterface(m_descriptor);
174
180
        return serviceInstance;
175
181
    } else {
176
182
        return 0;
178
184
}
179
185
 
180
186
/*!
181
 
    \qmlclass ServiceList
 
187
    \qmlclass ServiceList QDeclarativeServiceList
182
188
    
183
189
    \brief The ServiceList element holds a list of \l Service elements.
184
190
    \inherits QObject
186
192
    \ingroup qml-serviceframework
187
193
 
188
194
    The ServiceList element is part of the \bold{QtMobility.serviceframework 1.1} module and
189
 
    provides a list of Service elements at the interface ServiceList::interfaceName with
 
195
    provides a list of \l Service elements at the interface ServiceList::interfaceName with
190
196
    minimum version match ServiceList::minVersion properties. This list can be used to 
191
197
    select the desired service and instantiate a service object for access via the QMetaObject.
192
198
 
 
199
    This element is a simplified reflection of the QServiceFilter class that provides a list
 
200
    of simplified QServiceInterfaceDescriptors. Similarly, if the ServiceList::serviceName 
 
201
    and ServiceList::versionMatch are not provided they will respectively default to an empty 
 
202
    string with a minimum verison match.
 
203
 
193
204
    \sa Service
194
205
*/
195
206
QDeclarativeServiceList::QDeclarativeServiceList()
 
207
    : m_service(QString()),
 
208
      m_match(QDeclarativeServiceList::Minimum)
196
209
{
197
210
    serviceManager = new QServiceManager();
198
211
}
200
213
QDeclarativeServiceList::~QDeclarativeServiceList()
201
214
{
202
215
}
 
216
/*!
 
217
    \qmlproperty QString ServiceList::serviceName
 
218
 
 
219
    This property holds the interface name of the services that
 
220
    corresponds to setting QServiceFilter::setService(). 
 
221
*/
 
222
void QDeclarativeServiceList::setServiceName(const QString &service)
 
223
{
 
224
    m_service = service;
 
225
}
 
226
 
 
227
QString QDeclarativeServiceList::serviceName() const
 
228
{
 
229
    return m_service;
 
230
}
203
231
 
204
232
/*!
205
233
    \qmlproperty QString ServiceList::interfaceName
210
238
void QDeclarativeServiceList::setInterfaceName(const QString &interface)
211
239
{
212
240
    m_interface = interface;
213
 
 
214
 
    // ![0]
215
 
    QDeclarativeService *service;
216
 
    QServiceFilter filter(m_interface, m_version);
217
 
    QList<QServiceInterfaceDescriptor> list = serviceManager->findInterfaces(filter);
218
 
    for (int i = 0; i < list.size(); i++) {
219
 
        service = new QDeclarativeService();
220
 
        service->setInterfaceDesc(list.at(i));
221
 
        m_services.append(service);
222
 
    }
223
 
    // ![0]
224
241
}
225
242
 
226
243
QString QDeclarativeServiceList::interfaceName() const
229
246
}
230
247
 
231
248
/*!
232
 
    \qmlproperty QString ServiceList::minVersion
233
 
 
234
 
    This property holds the minimum version for matching service interface
235
 
    descriptors with QServiceFilter::MinimumVersionMatch.
236
 
*/
237
 
void QDeclarativeServiceList::setMinVersion(const QString &version)
238
 
{
239
 
    m_version = version;
240
 
}
241
 
 
242
 
QString QDeclarativeServiceList::minVersion() const
243
 
{
244
 
    return m_version;
 
249
    \qmlproperty int ServiceList::majorVersion
 
250
    
 
251
    This property holds the major version number of the service filter that
 
252
    corresponds to QServiceFilter::majorVersion(). 
 
253
*/
 
254
void QDeclarativeServiceList::setMajorVersion(int major)
 
255
{
 
256
    m_major = major;
 
257
}
 
258
 
 
259
int QDeclarativeServiceList::majorVersion() const
 
260
{
 
261
    return m_major;
 
262
}
 
263
 
 
264
/*!
 
265
    \qmlproperty int ServiceList::minorVersion
 
266
    
 
267
    This property holds the minor version number of the service filter that
 
268
    corresponds to QServiceFilter::minorVersion(). 
 
269
*/
 
270
void QDeclarativeServiceList::setMinorVersion(int minor)
 
271
{
 
272
    m_minor = minor;
 
273
}
 
274
 
 
275
int QDeclarativeServiceList::minorVersion() const
 
276
{
 
277
    return m_minor;
 
278
}
 
279
 
 
280
/*!
 
281
    \qmlproperty enumeration ServiceList::versionMatch
 
282
    
 
283
    This property holds the veresion match rule of the service filter that
 
284
    corresponds to QServiceFilter::versionMatchRule(). Within QML the values
 
285
    ServiceList.Exact and ServiceList.Minimum correspond to 
 
286
    QServiceFilter::ExactVersionMatch and QServiceFilter::MinimumVersionMatch
 
287
    repsectively.
 
288
*/
 
289
void QDeclarativeServiceList::setVersionMatch(MatchRule match)
 
290
{
 
291
    m_match = match;
 
292
}
 
293
 
 
294
QDeclarativeServiceList::MatchRule QDeclarativeServiceList::versionMatch() const
 
295
{
 
296
    return m_match;
245
297
}
246
298
 
247
299
/*!
252
304
*/
253
305
QDeclarativeListProperty<QDeclarativeService> QDeclarativeServiceList::services()
254
306
{
 
307
    QString version = QString::number(m_major) + "." + QString::number(m_minor);
 
308
    
 
309
    QServiceFilter filter;
 
310
    filter.setServiceName(m_service);
 
311
    if (m_match == QDeclarativeServiceList::Exact)
 
312
        filter.setInterface(m_interface, version, QServiceFilter::ExactVersionMatch);
 
313
    else
 
314
        filter.setInterface(m_interface, version);
 
315
    
 
316
    QList<QServiceInterfaceDescriptor> list = serviceManager->findInterfaces(filter);
 
317
    for (int i = 0; i < list.size(); i++) {
 
318
        QDeclarativeService *service;
 
319
        service = new QDeclarativeService();
 
320
        service->setInterfaceDesc(list.at(i));
 
321
        m_services.append(service);
 
322
    }
 
323
    
255
324
    return QDeclarativeListProperty<QDeclarativeService>(this, m_services);
256
325
}
257
326