| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2018 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 QtSystems module of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 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 Lesser General Public License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 |
** General Public License version 3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 |
** packaging of this file. Please review the following information to |
| 22 |
** ensure the GNU Lesser General Public License version 3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 |
** |
| 25 |
** GNU General Public License Usage |
| 26 |
** Alternatively, this file may be used under the terms of the GNU |
| 27 |
** General Public License version 2.0 or (at your option) the GNU General |
| 28 |
** Public license version 3 or any later version approved by the KDE Free |
| 29 |
** Qt Foundation. The licenses are as published by the Free Software |
| 30 |
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 |
** included in the packaging of this file. Please review the following |
| 32 |
** information to ensure the GNU General Public License requirements will |
| 33 |
** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 |
** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 |
** |
| 36 |
** $QT_END_LICENSE$ |
| 37 |
** |
| 38 |
****************************************************************************/ |
| 39 |
|
| 40 |
#include "qdeclarativeserviceold_p.h" |
| 41 |
|
| 42 |
#include <QQmlEngine> |
| 43 |
#include <QQmlInfo> |
| 44 |
|
| 45 |
QT_BEGIN_NAMESPACE |
| 46 |
|
| 47 |
/*! |
| 48 |
\qmltype Service |
| 49 |
\instantiates QDeclarativeService |
| 50 |
|
| 51 |
\brief The Service element holds an instance of a service object. |
| 52 |
\inherits QObject |
| 53 |
|
| 54 |
\ingroup qml-serviceframework |
| 55 |
|
| 56 |
The Service element is part of the Qt ServiceFramework API and |
| 57 |
provides a client instance of the service object. This element is a simplified |
| 58 |
reflection of the QServiceInterfaceDescriptor class that allows the specification of |
| 59 |
the Service::interfaceName to locate the default service implemented at this interface. |
| 60 |
|
| 61 |
\sa ServiceList |
| 62 |
*/ |
| 63 |
QDeclarativeService::QDeclarativeService() |
| 64 |
: m_serviceInstance(0), m_componentComplete(false) |
| 65 |
{ |
| 66 |
m_serviceManager = new QServiceManager(); |
| 67 |
} |
| 68 |
|
| 69 |
QDeclarativeService::~QDeclarativeService() |
| 70 |
{ |
| 71 |
delete m_serviceInstance; |
| 72 |
} |
| 73 |
|
| 74 |
/*! |
| 75 |
\qmlproperty bool Service::valid read-only |
| 76 |
|
| 77 |
This property holds whether a default service was found at the |
| 78 |
interface name and corresponds to QServiceInterfaceDescriptor::isValid(). |
| 79 |
*/ |
| 80 |
bool QDeclarativeService::isValid() const |
| 81 |
{ |
| 82 |
return m_descriptor.isValid(); |
| 83 |
} |
| 84 |
|
| 85 |
void QDeclarativeService::setInterfaceDesc(const QServiceInterfaceDescriptor &desc) |
| 86 |
{ |
| 87 |
if (desc == m_descriptor) |
| 88 |
return; |
| 89 |
|
| 90 |
m_descriptor = desc; |
| 91 |
|
| 92 |
if (m_serviceInstance) |
| 93 |
delete m_serviceInstance; |
| 94 |
setServiceObject(0); |
| 95 |
} |
| 96 |
|
| 97 |
QServiceInterfaceDescriptor QDeclarativeService::interfaceDesc() const |
| 98 |
{ |
| 99 |
return m_descriptor; |
| 100 |
} |
| 101 |
|
| 102 |
/*! |
| 103 |
\qmlproperty QString Service::interfaceName |
| 104 |
|
| 105 |
This property holds the interface name of the service that |
| 106 |
corresponds to QServiceInterfaceDescriptor::interfaceName(). |
| 107 |
*/ |
| 108 |
void QDeclarativeService::setInterfaceName(const QString &serviceInterface) |
| 109 |
{ |
| 110 |
m_interface = serviceInterface; |
| 111 |
updateDescriptor(); |
| 112 |
} |
| 113 |
|
| 114 |
QString QDeclarativeService::interfaceName() const |
| 115 |
{ |
| 116 |
if (isValid()) |
| 117 |
return m_descriptor.interfaceName(); |
| 118 |
else |
| 119 |
return "No Interface"; |
| 120 |
} |
| 121 |
|
| 122 |
/*! |
| 123 |
\qmlproperty QString Service::serviceName |
| 124 |
|
| 125 |
This property holds the service name of the service that |
| 126 |
corresponds to QServiceInterfaceDescriptor::serviceName(). |
| 127 |
*/ |
| 128 |
QString QDeclarativeService::serviceName() const |
| 129 |
{ |
| 130 |
if (isValid()) |
| 131 |
return m_descriptor.serviceName(); |
| 132 |
else |
| 133 |
return "No Service"; |
| 134 |
} |
| 135 |
|
| 136 |
void QDeclarativeService::setServiceName(const QString &service) |
| 137 |
{ |
| 138 |
m_service = service; |
| 139 |
} |
| 140 |
|
| 141 |
/*! |
| 142 |
\qmlproperty int Service::majorVersion |
| 143 |
|
| 144 |
This property holds the major version number of the service that |
| 145 |
corresponds to QServiceInterfaceDescriptor::majorVersion(). |
| 146 |
*/ |
| 147 |
int QDeclarativeService::majorVersion() const |
| 148 |
{ |
| 149 |
if (isValid()) |
| 150 |
return m_descriptor.majorVersion(); |
| 151 |
else |
| 152 |
return 0; |
| 153 |
} |
| 154 |
|
| 155 |
void QDeclarativeService::setMajorVersion(int version) |
| 156 |
{ |
| 157 |
m_major = version; |
| 158 |
updateDescriptor(); |
| 159 |
} |
| 160 |
|
| 161 |
/*! |
| 162 |
\qmlproperty int Service::minorVersion |
| 163 |
|
| 164 |
This property holds the minor version number of the service that |
| 165 |
corresponds to QServiceInterfaceDescriptor::minorVersion(). |
| 166 |
*/ |
| 167 |
int QDeclarativeService::minorVersion() const |
| 168 |
{ |
| 169 |
if (isValid()) |
| 170 |
return m_descriptor.minorVersion(); |
| 171 |
else |
| 172 |
return 0; |
| 173 |
} |
| 174 |
|
| 175 |
void QDeclarativeService::setMinorVersion(int version) |
| 176 |
{ |
| 177 |
m_minor = version; |
| 178 |
updateDescriptor(); |
| 179 |
} |
| 180 |
|
| 181 |
/*! |
| 182 |
\qmlproperty QObject* Service::serviceObject |
| 183 |
|
| 184 |
This property holds an instance of the service object which |
| 185 |
can be used to make metaobject calls to the service. This |
| 186 |
corresponds to QServiceManager::loadInterface(). |
| 187 |
*/ |
| 188 |
QObject* QDeclarativeService::serviceObject() |
| 189 |
{ |
| 190 |
if (m_serviceInstance) { |
| 191 |
return m_serviceInstance; |
| 192 |
} |
| 193 |
|
| 194 |
if (isValid()) { |
| 195 |
QObject *object = m_serviceManager->loadInterface(m_descriptor); |
| 196 |
setServiceObject(object); |
| 197 |
if (!m_serviceInstance) { |
| 198 |
emit error(QLatin1String("Failed to create object")); |
| 199 |
return m_serviceInstance; |
| 200 |
} |
| 201 |
emit serviceObjectChanged(); |
| 202 |
connect(m_serviceInstance, SIGNAL(errorUnrecoverableIPCFault(QService::UnrecoverableIPCError)), |
| 203 |
this, SLOT(IPCFault(QService::UnrecoverableIPCError))); |
| 204 |
m_error.clear(); |
| 205 |
return m_serviceInstance; |
| 206 |
} else { |
| 207 |
return 0; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/*! |
| 212 |
\qmlproperty QString Service::error |
| 213 |
|
| 214 |
This property holds the last error the was received, if any |
| 215 |
|
| 216 |
*/ |
| 217 |
|
| 218 |
QString QDeclarativeService::lastError() const |
| 219 |
{ |
| 220 |
return m_error; |
| 221 |
} |
| 222 |
|
| 223 |
void QDeclarativeService::IPCFault(QService::UnrecoverableIPCError errorValue) |
| 224 |
{ |
| 225 |
switch (errorValue) { |
| 226 |
default: |
| 227 |
case QService::ErrorUnknown: |
| 228 |
m_error = QLatin1String("IPC Error: Unkown Error"); |
| 229 |
break; |
| 230 |
case QService::ErrorServiceNoLongerAvailable: |
| 231 |
m_error = QLatin1String("IPC Error: Service no longer available"); |
| 232 |
break; |
| 233 |
case QService::ErrorOutofMemory: |
| 234 |
m_error = QLatin1String("IPC Error: Out of memory"); |
| 235 |
break; |
| 236 |
case QService::ErrorPermissionDenied: |
| 237 |
m_error = QLatin1String("IPC Error: Permission Denied"); |
| 238 |
break; |
| 239 |
case QService::ErrorInvalidArguments: |
| 240 |
m_error = QLatin1String("IPC Error: Invalid Arguments"); |
| 241 |
break; |
| 242 |
} |
| 243 |
emit error(m_error); |
| 244 |
m_serviceInstance->deleteLater(); |
| 245 |
setServiceObject(0); |
| 246 |
} |
| 247 |
|
| 248 |
void QDeclarativeService::updateDescriptor() |
| 249 |
{ |
| 250 |
if (!m_componentComplete) |
| 251 |
return; |
| 252 |
|
| 253 |
if (m_interface.isEmpty()) |
| 254 |
return; |
| 255 |
|
| 256 |
QServiceInterfaceDescriptor new_desc; |
| 257 |
|
| 258 |
if (m_minor == 0 && m_major == 0 && m_service.isEmpty()){ |
| 259 |
new_desc = m_serviceManager->interfaceDefault(m_interface); |
| 260 |
} |
| 261 |
else { |
| 262 |
QServiceFilter filter; |
| 263 |
if (!m_service.isEmpty()) |
| 264 |
filter.setServiceName(m_service); |
| 265 |
|
| 266 |
|
| 267 |
if (m_minor != 0 || m_major != 0) { |
| 268 |
const QString version = QString::number(m_major) + "." + QString::number(m_minor); |
| 269 |
filter.setInterface(m_interface, version); |
| 270 |
} |
| 271 |
|
| 272 |
QList<QServiceInterfaceDescriptor> list = m_serviceManager->findInterfaces(filter); |
| 273 |
if (!list.isEmpty()) |
| 274 |
new_desc = list.takeFirst(); |
| 275 |
} |
| 276 |
|
| 277 |
if (new_desc != m_descriptor) { |
| 278 |
m_descriptor = new_desc; |
| 279 |
if (m_serviceInstance) |
| 280 |
emit serviceObjectChanged(); |
| 281 |
} |
| 282 |
|
| 283 |
if (!isValid()) { |
| 284 |
qWarning() << "WARNING: No service found for interface name: " << m_interface << m_service << m_major << m_minor; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
void QDeclarativeService::setServiceObject(QObject *object) |
| 289 |
{ |
| 290 |
if (m_serviceInstance != object) { |
| 291 |
m_serviceInstance = object; |
| 292 |
emit serviceObjectChanged(); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
void QDeclarativeService::classBegin() |
| 297 |
{ |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
void QDeclarativeService::componentComplete() |
| 302 |
{ |
| 303 |
m_componentComplete = true; |
| 304 |
updateDescriptor(); |
| 305 |
} |
| 306 |
|
| 307 |
bool QDeclarativeService::operator ==(const QServiceInterfaceDescriptor& other ) const |
| 308 |
{ |
| 309 |
if ( m_descriptor == other) |
| 310 |
return true; |
| 311 |
|
| 312 |
return false; |
| 313 |
} |
| 314 |
|
| 315 |
/*! |
| 316 |
\qmltype ServiceList |
| 317 |
\instantiates QDeclarativeServiceList |
| 318 |
|
| 319 |
\brief The ServiceList element holds a list of \l Service elements. |
| 320 |
\inherits QObject |
| 321 |
|
| 322 |
\ingroup qml-serviceframework |
| 323 |
|
| 324 |
The ServiceList element is part of the Qt ServiceFramework API and |
| 325 |
provides a list of \l Service elements at the interface ServiceList::interfaceName with |
| 326 |
minimum version match ServiceList::minVersion properties. This list can be used to |
| 327 |
select the desired service and instantiate a service object for access via the QMetaObject. |
| 328 |
|
| 329 |
This element is a simplified reflection of the QServiceFilter class that provides a list |
| 330 |
of simplified QServiceInterfaceDescriptors. Similarly, if the ServiceList::serviceName |
| 331 |
and ServiceList::versionMatch are not provided they will respectively default to an empty |
| 332 |
string with a minimum verison match. |
| 333 |
|
| 334 |
\sa Service |
| 335 |
*/ |
| 336 |
QDeclarativeServiceList::QDeclarativeServiceList() |
| 337 |
: m_service(QString()), |
| 338 |
m_interface(), |
| 339 |
m_major(1), |
| 340 |
m_minor(1), |
| 341 |
m_match(QDeclarativeServiceList::Minimum), |
| 342 |
m_componentComplete(false) |
| 343 |
{ |
| 344 |
serviceManager = new QServiceManager(this); |
| 345 |
} |
| 346 |
|
| 347 |
QDeclarativeServiceList::~QDeclarativeServiceList() |
| 348 |
{ |
| 349 |
while (m_services.count()) |
| 350 |
delete m_services.takeFirst(); |
| 351 |
} |
| 352 |
/*! |
| 353 |
\qmlproperty QString ServiceList::serviceName |
| 354 |
|
| 355 |
This property holds the interface name of the services that |
| 356 |
corresponds to setting QServiceFilter::setService(). |
| 357 |
*/ |
| 358 |
void QDeclarativeServiceList::setServiceName(const QString &service) |
| 359 |
{ |
| 360 |
m_service = service; |
| 361 |
updateFilterResults(); |
| 362 |
if (m_componentComplete) |
| 363 |
emit serviceNameChanged(); |
| 364 |
} |
| 365 |
|
| 366 |
QString QDeclarativeServiceList::serviceName() const |
| 367 |
{ |
| 368 |
return m_service; |
| 369 |
} |
| 370 |
|
| 371 |
/*! |
| 372 |
\qmlproperty QString ServiceList::interfaceName |
| 373 |
|
| 374 |
This property holds the interface name of the services that |
| 375 |
corresponds to setting QServiceFilter::setInterface(). |
| 376 |
*/ |
| 377 |
void QDeclarativeServiceList::setInterfaceName(const QString &serviceInterface) |
| 378 |
{ |
| 379 |
m_interface = serviceInterface; |
| 380 |
updateFilterResults(); |
| 381 |
if (m_componentComplete) |
| 382 |
emit interfaceNameChanged(); |
| 383 |
} |
| 384 |
|
| 385 |
QString QDeclarativeServiceList::interfaceName() const |
| 386 |
{ |
| 387 |
return m_interface; |
| 388 |
} |
| 389 |
|
| 390 |
/*! |
| 391 |
\qmlproperty int ServiceList::majorVersion |
| 392 |
|
| 393 |
This property holds the major version number of the service filter that |
| 394 |
corresponds to QServiceFilter::majorVersion(). |
| 395 |
*/ |
| 396 |
void QDeclarativeServiceList::setMajorVersion(int major) |
| 397 |
{ |
| 398 |
m_major = major; |
| 399 |
updateFilterResults(); |
| 400 |
if (m_componentComplete) |
| 401 |
emit majorVersionChanged(); |
| 402 |
} |
| 403 |
|
| 404 |
int QDeclarativeServiceList::majorVersion() const |
| 405 |
{ |
| 406 |
return m_major; |
| 407 |
} |
| 408 |
|
| 409 |
/*! |
| 410 |
\qmlproperty int ServiceList::minorVersion |
| 411 |
|
| 412 |
This property holds the minor version number of the service filter that |
| 413 |
corresponds to QServiceFilter::minorVersion(). |
| 414 |
*/ |
| 415 |
void QDeclarativeServiceList::setMinorVersion(int minor) |
| 416 |
{ |
| 417 |
m_minor = minor; |
| 418 |
updateFilterResults(); |
| 419 |
if (m_componentComplete) |
| 420 |
emit minorVersionChanged(); |
| 421 |
} |
| 422 |
|
| 423 |
int QDeclarativeServiceList::minorVersion() const |
| 424 |
{ |
| 425 |
return m_minor; |
| 426 |
} |
| 427 |
|
| 428 |
/*! |
| 429 |
\qmlproperty int ServiceList::monitorServiceRegistrations |
| 430 |
|
| 431 |
This property controls the behaviour of the list when new services are |
| 432 |
registered or deregistered. Setting this property to true means the list |
| 433 |
will be automatically updated when a service is added or removed. Caution, |
| 434 |
your service object will be deleted if the service is unregistered, even if |
| 435 |
the service is still running. |
| 436 |
*/ |
| 437 |
|
| 438 |
void QDeclarativeServiceList::setMonitorServiceRegistrations(bool updates) |
| 439 |
{ |
| 440 |
if (updates == false) { |
| 441 |
disconnect(this, SLOT(servicesAddedRemoved())); |
| 442 |
} |
| 443 |
else { |
| 444 |
connect(serviceManager, SIGNAL(serviceAdded(QString,QService::Scope)), |
| 445 |
this, SLOT(servicesAddedRemoved())); |
| 446 |
connect(serviceManager, SIGNAL(serviceRemoved(QString,QService::Scope)), |
| 447 |
this, SLOT(servicesAddedRemoved())); |
| 448 |
} |
| 449 |
|
| 450 |
if (m_dynamicUpdates != updates) |
| 451 |
emit monitorServiceRegistrationsChanged(); |
| 452 |
|
| 453 |
m_dynamicUpdates = updates; |
| 454 |
} |
| 455 |
|
| 456 |
void QDeclarativeServiceList::servicesAddedRemoved() |
| 457 |
{ |
| 458 |
// invoke in another event loop run |
| 459 |
QMetaObject::invokeMethod(this, "updateServiceList", Qt::QueuedConnection); |
| 460 |
} |
| 461 |
|
| 462 |
bool QDeclarativeServiceList::monitorServiceRegistrations() const |
| 463 |
{ |
| 464 |
return m_dynamicUpdates; |
| 465 |
} |
| 466 |
|
| 467 |
/*! |
| 468 |
\qmlproperty enumeration ServiceList::versionMatch |
| 469 |
|
| 470 |
This property holds the version match rule of the service filter that |
| 471 |
corresponds to QServiceFilter::versionMatchRule(). Within QML the values |
| 472 |
ServiceList.Exact and ServiceList.Minimum correspond to |
| 473 |
QServiceFilter::ExactVersionMatch and QServiceFilter::MinimumVersionMatch |
| 474 |
respectively. |
| 475 |
*/ |
| 476 |
void QDeclarativeServiceList::setVersionMatch(MatchRule match) |
| 477 |
{ |
| 478 |
m_match = match; |
| 479 |
updateFilterResults(); |
| 480 |
if (m_componentComplete) |
| 481 |
emit versionMatchChanged(); |
| 482 |
} |
| 483 |
|
| 484 |
QDeclarativeServiceList::MatchRule QDeclarativeServiceList::versionMatch() const |
| 485 |
{ |
| 486 |
return m_match; |
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
void QDeclarativeServiceList::updateServiceList() |
| 491 |
{ |
| 492 |
if (!m_componentComplete) |
| 493 |
return; |
| 494 |
|
| 495 |
const QString version = QString::number(m_major) + "." + QString::number(m_minor); |
| 496 |
|
| 497 |
QServiceFilter filter; |
| 498 |
|
| 499 |
if (!m_service.isEmpty()) |
| 500 |
filter.setServiceName(m_service); |
| 501 |
|
| 502 |
if (m_match == QDeclarativeServiceList::Exact) |
| 503 |
filter.setInterface(m_interface, version, QServiceFilter::ExactVersionMatch); |
| 504 |
else if (!m_interface.isEmpty()) |
| 505 |
filter.setInterface(m_interface, version); |
| 506 |
|
| 507 |
const QList<QServiceInterfaceDescriptor> newlist = serviceManager->findInterfaces(filter); |
| 508 |
|
| 509 |
QSet<QServiceInterfaceDescriptor> currentServices = QSet<QServiceInterfaceDescriptor>::fromList(m_currentList); |
| 510 |
QSet<QServiceInterfaceDescriptor> newServices = QSet<QServiceInterfaceDescriptor>::fromList(newlist); |
| 511 |
|
| 512 |
if (currentServices == newServices) { |
| 513 |
return; |
| 514 |
} |
| 515 |
|
| 516 |
const QSet<QServiceInterfaceDescriptor> addServices = newServices.subtract(currentServices); |
| 517 |
const QSet<QServiceInterfaceDescriptor> delServices = currentServices.subtract( |
| 518 |
QSet<QServiceInterfaceDescriptor>::fromList(newlist)); |
| 519 |
|
| 520 |
foreach (const QServiceInterfaceDescriptor &desc, delServices) { |
| 521 |
foreach (QDeclarativeService *service, m_services) { |
| 522 |
if (*service == desc) { |
| 523 |
m_services.removeOne(service); |
| 524 |
delete service; |
| 525 |
} |
| 526 |
} |
| 527 |
m_currentList.removeOne(desc); |
| 528 |
} |
| 529 |
|
| 530 |
foreach (const QServiceInterfaceDescriptor &desc, addServices) { |
| 531 |
QDeclarativeService *service = new QDeclarativeService(); |
| 532 |
service->setInterfaceDesc(desc); |
| 533 |
m_services.append(service); |
| 534 |
m_currentList.append(desc); |
| 535 |
} |
| 536 |
|
| 537 |
emit resultsChanged(); |
| 538 |
} |
| 539 |
|
| 540 |
void QDeclarativeServiceList::updateFilterResults() |
| 541 |
{ |
| 542 |
if (!m_componentComplete) |
| 543 |
return; |
| 544 |
|
| 545 |
const QString version = QString::number(m_major) + "." + QString::number(m_minor); |
| 546 |
|
| 547 |
QServiceFilter filter; |
| 548 |
|
| 549 |
if (!m_service.isEmpty()) |
| 550 |
filter.setServiceName(m_service); |
| 551 |
|
| 552 |
if (m_match == QDeclarativeServiceList::Exact) |
| 553 |
filter.setInterface(m_interface, version, QServiceFilter::ExactVersionMatch); |
| 554 |
else if (!m_interface.isEmpty()) |
| 555 |
filter.setInterface(m_interface, version); |
| 556 |
|
| 557 |
QList<QServiceInterfaceDescriptor> list = serviceManager->findInterfaces(filter); |
| 558 |
|
| 559 |
if (list == m_currentList) { |
| 560 |
return; |
| 561 |
} |
| 562 |
|
| 563 |
m_currentList = list; |
| 564 |
|
| 565 |
while (m_services.count()) //for now we refresh the entire list |
| 566 |
delete m_services.takeFirst(); |
| 567 |
|
| 568 |
for (int i = 0; i < list.size(); i++) { |
| 569 |
QDeclarativeService *service = new QDeclarativeService(); |
| 570 |
service->setInterfaceDesc(list.at(i)); |
| 571 |
m_services.append(service); |
| 572 |
} |
| 573 |
|
| 574 |
emit resultsChanged(); |
| 575 |
} |
| 576 |
|
| 577 |
/*! |
| 578 |
\qmlproperty QQmlListProperty ServiceList::services |
| 579 |
|
| 580 |
This property holds the list of \l Service elements that match |
| 581 |
the Service::interfaceName and minimum Service::versionNumber properties. |
| 582 |
*/ |
| 583 |
QQmlListProperty<QDeclarativeService> QDeclarativeServiceList::services() |
| 584 |
{ |
| 585 |
return QQmlListProperty<QDeclarativeService>(this, |
| 586 |
0, |
| 587 |
s_append, |
| 588 |
s_count, |
| 589 |
s_at, |
| 590 |
s_clear); |
| 591 |
} |
| 592 |
|
| 593 |
void QDeclarativeServiceList::classBegin() |
| 594 |
{ |
| 595 |
} |
| 596 |
|
| 597 |
void QDeclarativeServiceList::componentComplete() |
| 598 |
{ |
| 599 |
if (!m_componentComplete) { |
| 600 |
m_componentComplete = true; |
| 601 |
updateFilterResults(); |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
void QDeclarativeServiceList::listUpdated() |
| 606 |
{ |
| 607 |
if (m_componentComplete) |
| 608 |
emit resultsChanged(); |
| 609 |
} |
| 610 |
|
| 611 |
void QDeclarativeServiceList::s_append(QQmlListProperty<QDeclarativeService> *prop, QDeclarativeService *service) |
| 612 |
{ |
| 613 |
QDeclarativeServiceList* list = static_cast<QDeclarativeServiceList*>(prop->object); |
| 614 |
list->m_services.append(service); |
| 615 |
list->listUpdated(); |
| 616 |
} |
| 617 |
int QDeclarativeServiceList::s_count(QQmlListProperty<QDeclarativeService> *prop) |
| 618 |
{ |
| 619 |
return static_cast<QDeclarativeServiceList*>(prop->object)->m_services.count(); |
| 620 |
} |
| 621 |
|
| 622 |
QDeclarativeService* QDeclarativeServiceList::s_at(QQmlListProperty<QDeclarativeService> *prop, int index) |
| 623 |
{ |
| 624 |
return static_cast<QDeclarativeServiceList*>(prop->object)->m_services[index]; |
| 625 |
} |
| 626 |
|
| 627 |
void QDeclarativeServiceList::s_clear(QQmlListProperty<QDeclarativeService> *prop) |
| 628 |
{ |
| 629 |
QDeclarativeServiceList* list = static_cast<QDeclarativeServiceList*>(prop->object); |
| 630 |
qDeleteAll(list->m_services); |
| 631 |
list->m_services.clear(); |
| 632 |
list->listUpdated(); |
| 633 |
} |
| 634 |
#include "moc_qdeclarativeserviceold_p.cpp" |
| 635 |
|
| 636 |
QT_END_NAMESPACE |