X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsyncableobject.cpp;h=ac62f0802522f320ec19602fe74aee4bf595d881;hp=5b158ab3da8f256aa6ac6847c037e1f79d6a662f;hb=565743a41c93de874cb79fd145b22e2422bb754e;hpb=f6b9eeda207d42c99fc3e9085631722cf2ec83dc diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index 5b158ab3..ac62f080 100644 --- a/src/common/syncableobject.cpp +++ b/src/common/syncableobject.cpp @@ -27,6 +27,7 @@ #include "signalproxy.h" #include "util.h" +INIT_SYNCABLE_OBJECT(SyncableObject) SyncableObject::SyncableObject(QObject *parent) : QObject(parent), _initialized(false), @@ -49,6 +50,15 @@ SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent) { } +SyncableObject::~SyncableObject() { + QList::iterator proxyIter = _signalProxies.begin(); + while(proxyIter != _signalProxies.end()) { + SignalProxy *proxy = (*proxyIter); + proxyIter = _signalProxies.erase(proxyIter); + proxy->stopSynchronize(this); + } +} + SyncableObject &SyncableObject::operator=(const SyncableObject &other) { if(this == &other) return *this; @@ -95,15 +105,14 @@ QVariantMap SyncableObject::toVariantMap() { qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.signature() << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName()); continue; } - QVariant value = QVariant(variantType); - QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), &value); + + QVariant value(variantType, (const void *) 0); + QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), value.data()); QMetaObject::invokeMethod(this, methodname.toAscii(), genericvalue); properties[SignalProxy::ExtendedMetaObject::methodBaseName(method)] = value; } - // properties["Payload"] = QByteArray(10000000, 'a'); // for testing purposes return properties; - } void SyncableObject::fromVariantMap(const QVariantMap &properties) { @@ -132,6 +141,17 @@ void SyncableObject::fromVariantMap(const QVariantMap &properties) { bool SyncableObject::setInitValue(const QString &property, const QVariant &value) { QString handlername = QString("initSet") + property; handlername[7] = handlername[7].toUpper(); + + QString methodSignature = QString("%1(%2)").arg(handlername).arg(value.typeName()); + int methodIdx = metaObject()->indexOfMethod(methodSignature.toAscii().constData()); + if(methodIdx < 0) { + QByteArray normedMethodName = QMetaObject::normalizedSignature(methodSignature.toAscii().constData()); + methodIdx = metaObject()->indexOfMethod(normedMethodName.constData()); + } + if(methodIdx < 0) { + return false; + } + QGenericArgument param(value.typeName(), value.constData()); return QMetaObject::invokeMethod(this, handlername.toAscii(), param); } @@ -140,20 +160,23 @@ void SyncableObject::renameObject(const QString &newName) { const QString oldName = objectName(); if(oldName != newName) { setObjectName(newName); - emit objectRenamed(newName, oldName); + foreach(SignalProxy *proxy, _signalProxies) { + proxy->renameObject(this, newName, oldName); + } } } void SyncableObject::update(const QVariantMap &properties) { fromVariantMap(properties); - emit updated(properties); + SYNC(ARG(properties)) + emit updated(); } void SyncableObject::requestUpdate(const QVariantMap &properties) { if(allowClientUpdates()) { update(properties); } - emit updateRequested(properties); + REQUEST(ARG(properties)) } void SyncableObject::sync_call__(SignalProxy::ProxyMode modeType, const char *funcname, ...) const { @@ -171,3 +194,12 @@ void SyncableObject::synchronize(SignalProxy *proxy) { return; _signalProxies << proxy; } + +void SyncableObject::stopSynchronize(SignalProxy *proxy) { + for(int i = 0; i < _signalProxies.count(); i++) { + if(_signalProxies[i] == proxy) { + _signalProxies.removeAt(i); + break; + } + } +}