| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifndef QDECLARATIVESERVICE_P_H |
| 41 |
#define QDECLARATIVESERVICE_P_H |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#include <QtCore> |
| 55 |
#include <qserviceinterfacedescriptor.h> |
| 56 |
#include <qservicemanager.h> |
| 57 |
#include <qqml.h> |
| 58 |
#include <qqmllist.h> |
| 59 |
|
| 60 |
QT_BEGIN_NAMESPACE |
| 61 |
|
| 62 |
class QDeclarativeServiceDescriptor : public QObject, public QServiceInterfaceDescriptor { |
| 63 |
Q_OBJECT |
| 64 |
Q_PROPERTY(QString serviceName READ serviceName CONSTANT) |
| 65 |
Q_PROPERTY(QString interfaceName READ interfaceName CONSTANT) |
| 66 |
Q_PROPERTY(int majorVersion READ majorVersion CONSTANT) |
| 67 |
Q_PROPERTY(int minorVersion READ minorVersion CONSTANT) |
| 68 |
Q_PROPERTY(bool valid READ isValid CONSTANT) |
| 69 |
|
| 70 |
public: |
| 71 |
QDeclarativeServiceDescriptor(QObject* parent = 0) : QObject(parent) {} |
| 72 |
QDeclarativeServiceDescriptor(const QDeclarativeServiceDescriptor& other) |
| 73 |
: QObject(0), QServiceInterfaceDescriptor(other) {} |
| 74 |
QDeclarativeServiceDescriptor(const QServiceInterfaceDescriptor& other) |
| 75 |
: QObject(0), QServiceInterfaceDescriptor(other) {} |
| 76 |
bool operator==(const QServiceInterfaceDescriptor& other) const |
| 77 |
{ return QServiceInterfaceDescriptor::operator==(other); } |
| 78 |
QDeclarativeServiceDescriptor& operator=(const QServiceInterfaceDescriptor& other) |
| 79 |
{ |
| 80 |
QServiceInterfaceDescriptor::operator=(other); |
| 81 |
return *this; |
| 82 |
} |
| 83 |
QDeclarativeServiceDescriptor& operator=(const QDeclarativeServiceDescriptor& other) |
| 84 |
{ |
| 85 |
QServiceInterfaceDescriptor::operator=(other); |
| 86 |
return *this; |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
class QDeclarativeServiceLoader : public QObject, public QQmlParserStatus { |
| 91 |
Q_OBJECT |
| 92 |
Q_INTERFACES(QQmlParserStatus) |
| 93 |
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged) |
| 94 |
|
| 95 |
Q_PROPERTY(QDeclarativeServiceDescriptor* serviceDescriptor READ serviceDescriptor WRITE setServiceDescriptor NOTIFY serviceDescriptorChanged RESET resetServiceDescriptor) |
| 96 |
Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
| 97 |
Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) |
| 98 |
|
| 99 |
Q_PROPERTY(QObject* serviceObject READ serviceObject NOTIFY serviceObjectChanged) |
| 100 |
Q_ENUMS(Status) |
| 101 |
|
| 102 |
public: |
| 103 |
enum Status { |
| 104 |
Null = 0, |
| 105 |
Ready, |
| 106 |
Loading, |
| 107 |
Error |
| 108 |
}; |
| 109 |
|
| 110 |
QDeclarativeServiceLoader(); |
| 111 |
~QDeclarativeServiceLoader(); |
| 112 |
|
| 113 |
Q_INVOKABLE QString errorString() const |
| 114 |
{ |
| 115 |
if (m_status == Error) |
| 116 |
return m_errorString; |
| 117 |
else |
| 118 |
return ""; |
| 119 |
} |
| 120 |
|
| 121 |
QString interfaceName() const |
| 122 |
{ |
| 123 |
return m_interfaceName; |
| 124 |
} |
| 125 |
|
| 126 |
QDeclarativeServiceDescriptor* serviceDescriptor() const |
| 127 |
{ |
| 128 |
return m_serviceDescriptor; |
| 129 |
} |
| 130 |
|
| 131 |
void resetServiceDescriptor() |
| 132 |
{ |
| 133 |
setServiceDescriptor(0); |
| 134 |
} |
| 135 |
|
| 136 |
Status status() const |
| 137 |
{ |
| 138 |
return m_status; |
| 139 |
} |
| 140 |
|
| 141 |
bool asynchronous() const |
| 142 |
{ |
| 143 |
return m_asynchronous; |
| 144 |
} |
| 145 |
|
| 146 |
QObject* serviceObject() const |
| 147 |
{ |
| 148 |
return m_serviceObject; |
| 149 |
} |
| 150 |
|
| 151 |
public slots: |
| 152 |
void setInterfaceName(QString arg) |
| 153 |
{ |
| 154 |
if (m_interfaceName != arg) { |
| 155 |
m_interfaceName = arg; |
| 156 |
emit interfaceNameChanged(arg); |
| 157 |
if (!m_serviceDescriptor && m_componentComplete) |
| 158 |
startLoading(); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
void setServiceDescriptor(QDeclarativeServiceDescriptor* arg) |
| 163 |
{ |
| 164 |
if (m_serviceDescriptor != arg) { |
| 165 |
m_serviceDescriptor = arg; |
| 166 |
emit serviceDescriptorChanged(arg); |
| 167 |
if (m_componentComplete) |
| 168 |
startLoading(); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
void setAsynchronous(bool arg) |
| 173 |
{ |
| 174 |
if (m_asynchronous != arg) { |
| 175 |
m_asynchronous = arg; |
| 176 |
emit asynchronousChanged(arg); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
private Q_SLOTS: |
| 181 |
void setStatus(Status arg) |
| 182 |
{ |
| 183 |
if (m_status != arg) { |
| 184 |
m_status = arg; |
| 185 |
emit statusChanged(arg); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
protected: |
| 190 |
virtual void classBegin() {} |
| 191 |
virtual void componentComplete(); |
| 192 |
|
| 193 |
signals: |
| 194 |
void interfaceNameChanged(QString arg); |
| 195 |
|
| 196 |
void serviceDescriptorChanged(QServiceInterfaceDescriptor* arg); |
| 197 |
|
| 198 |
void statusChanged(Status arg); |
| 199 |
|
| 200 |
void asynchronousChanged(bool arg); |
| 201 |
|
| 202 |
void serviceObjectChanged(QObject* arg); |
| 203 |
|
| 204 |
private slots: |
| 205 |
void startLoading(); |
| 206 |
void finishLoading(); |
| 207 |
void IPCFault(QService::UnrecoverableIPCError); |
| 208 |
|
| 209 |
private: |
| 210 |
QString m_interfaceName; |
| 211 |
QDeclarativeServiceDescriptor* m_serviceDescriptor; |
| 212 |
Status m_status; |
| 213 |
bool m_asynchronous; |
| 214 |
QObject* m_serviceObject; |
| 215 |
QString m_errorString; |
| 216 |
|
| 217 |
bool m_componentComplete; |
| 218 |
QServiceManager* m_serviceManager; |
| 219 |
QServiceReply* m_serviceReply; |
| 220 |
}; |
| 221 |
|
| 222 |
class QDeclarativeServiceFilter : public QObject, public QQmlParserStatus { |
| 223 |
Q_OBJECT |
| 224 |
Q_INTERFACES(QQmlParserStatus) |
| 225 |
Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged) |
| 226 |
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged) |
| 227 |
Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged) |
| 228 |
Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged) |
| 229 |
Q_PROPERTY(bool exactVersionMatching READ exactVersionMatching WRITE setExactVersionMatching NOTIFY exactVersionMatchingChanged) |
| 230 |
|
| 231 |
Q_PROPERTY(bool monitorServiceRegistrations READ monitorServiceRegistrations WRITE setMonitorServiceRegistrations NOTIFY monitorServiceRegistrationsChanged) |
| 232 |
|
| 233 |
Q_PROPERTY(QQmlListProperty<QDeclarativeServiceDescriptor> serviceDescriptions READ serviceDescriptions NOTIFY serviceDescriptionsChanged) |
| 234 |
public: |
| 235 |
QDeclarativeServiceFilter(QObject* parent = 0); |
| 236 |
~QDeclarativeServiceFilter(); |
| 237 |
QString serviceName() const |
| 238 |
{ |
| 239 |
return m_serviceName; |
| 240 |
} |
| 241 |
|
| 242 |
QString interfaceName() const |
| 243 |
{ |
| 244 |
return m_interfaceName; |
| 245 |
} |
| 246 |
|
| 247 |
int majorVersion() const |
| 248 |
{ |
| 249 |
return m_majorVersion; |
| 250 |
} |
| 251 |
|
| 252 |
int minorVersion() const |
| 253 |
{ |
| 254 |
return m_minorVersion; |
| 255 |
} |
| 256 |
|
| 257 |
bool exactVersionMatching() const |
| 258 |
{ |
| 259 |
return m_exactVersionMatching; |
| 260 |
} |
| 261 |
|
| 262 |
bool monitorServiceRegistrations() const |
| 263 |
{ |
| 264 |
return m_monitorServiceRegistrations; |
| 265 |
} |
| 266 |
|
| 267 |
QQmlListProperty<QDeclarativeServiceDescriptor> serviceDescriptions() |
| 268 |
{ |
| 269 |
return QQmlListProperty<QDeclarativeServiceDescriptor> (this, 0, s_append, s_count, s_at, s_clear); |
| 270 |
} |
| 271 |
|
| 272 |
public slots: |
| 273 |
void setServiceName(QString arg) |
| 274 |
{ |
| 275 |
if (m_serviceName != arg) { |
| 276 |
m_serviceName = arg; |
| 277 |
emit serviceNameChanged(arg); |
| 278 |
updateServiceList(); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
void setInterfaceName(QString arg) |
| 283 |
{ |
| 284 |
if (m_interfaceName != arg) { |
| 285 |
m_interfaceName = arg; |
| 286 |
emit interfaceNameChanged(arg); |
| 287 |
updateServiceList(); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
void setMajorVersion(int arg) |
| 292 |
{ |
| 293 |
if (m_majorVersion != arg) { |
| 294 |
m_majorVersion = arg; |
| 295 |
emit majorVersionChanged(arg); |
| 296 |
updateServiceList(); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
void setMinorVersion(int arg) |
| 301 |
{ |
| 302 |
if (m_minorVersion != arg) { |
| 303 |
m_minorVersion = arg; |
| 304 |
emit minorVersionChanged(arg); |
| 305 |
updateServiceList(); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
void setExactVersionMatching(bool arg) |
| 310 |
{ |
| 311 |
if (m_exactVersionMatching != arg) { |
| 312 |
m_exactVersionMatching = arg; |
| 313 |
emit exactVersionMatchingChanged(arg); |
| 314 |
updateServiceList(); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
void setMonitorServiceRegistrations(bool updates); |
| 319 |
|
| 320 |
protected: |
| 321 |
virtual void classBegin() {} |
| 322 |
virtual void componentComplete(); |
| 323 |
signals: |
| 324 |
void serviceNameChanged(QString arg); |
| 325 |
|
| 326 |
void interfaceNameChanged(QString arg); |
| 327 |
|
| 328 |
void majorVersionChanged(int arg); |
| 329 |
|
| 330 |
void minorVersionChanged(int arg); |
| 331 |
|
| 332 |
void exactVersionMatchingChanged(bool arg); |
| 333 |
|
| 334 |
void monitorServiceRegistrationsChanged(bool arg); |
| 335 |
|
| 336 |
void serviceDescriptionsChanged(); |
| 337 |
|
| 338 |
private slots: |
| 339 |
void updateServiceList(); |
| 340 |
void servicesAddedRemoved(); |
| 341 |
private: |
| 342 |
QString m_serviceName; |
| 343 |
QString m_interfaceName; |
| 344 |
int m_majorVersion; |
| 345 |
int m_minorVersion; |
| 346 |
bool m_exactVersionMatching; |
| 347 |
bool m_monitorServiceRegistrations; |
| 348 |
QQmlListProperty<QDeclarativeServiceDescriptor*> m_serviceDescriptions; |
| 349 |
QList<QDeclarativeServiceDescriptor> m_services; |
| 350 |
|
| 351 |
QServiceManager* m_serviceManager; |
| 352 |
bool m_componentComplete; |
| 353 |
|
| 354 |
static void s_append(QQmlListProperty<QDeclarativeServiceDescriptor> *prop, QDeclarativeServiceDescriptor *service); |
| 355 |
static int s_count(QQmlListProperty<QDeclarativeServiceDescriptor> *prop); |
| 356 |
static QDeclarativeServiceDescriptor* s_at(QQmlListProperty<QDeclarativeServiceDescriptor> *prop, int index); |
| 357 |
static void s_clear(QQmlListProperty<QDeclarativeServiceDescriptor> *prop); |
| 358 |
}; |
| 359 |
|
| 360 |
QT_END_NAMESPACE |
| 361 |
|
| 362 |
QML_DECLARE_TYPE(QDeclarativeServiceLoader); |
| 363 |
QML_DECLARE_TYPE(QDeclarativeServiceDescriptor); |
| 364 |
QML_DECLARE_TYPE(QDeclarativeServiceFilter); |
| 365 |
|
| 366 |
|
| 367 |
#endif |