X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsyncableobject.cpp;h=b66626d66d1e2da0955f29c3b07aa6e3a06dc4f8;hp=ebe6ca0e17e713e0d49cabc6a44ffcb6d02d73cb;hb=62b7bed21f011037a34d7a4ea797d79fbdeff687;hpb=f7eb3911860f30e6bccce3c77d03fc25e87d7f93 diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index ebe6ca0e..b66626d6 100644 --- a/src/common/syncableobject.cpp +++ b/src/common/syncableobject.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -27,6 +27,7 @@ #include "signalproxy.h" #include "util.h" +INIT_SYNCABLE_OBJECT(SyncableObject) SyncableObject::SyncableObject(QObject *parent) : QObject(parent), _initialized(false), @@ -34,6 +35,14 @@ SyncableObject::SyncableObject(QObject *parent) { } +SyncableObject::SyncableObject(const QString &objectName, QObject *parent) + : QObject(parent), + _initialized(false), + _allowClientUpdates(false) +{ + setObjectName(objectName); +} + SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent) : QObject(parent), _initialized(other._initialized), @@ -41,10 +50,19 @@ 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; - + _initialized = other._initialized; _allowClientUpdates = other._allowClientUpdates; return *this; @@ -78,7 +96,7 @@ QVariantMap SyncableObject::toVariantMap() { // ...as well as methods, which have names starting with "init" for(int i = 0; i < meta->methodCount(); i++) { QMetaMethod method = meta->method(i); - QString methodname(::methodName(method)); + QString methodname(SignalProxy::ExtendedMetaObject::methodName(method)); if(!methodname.startsWith("init") || methodname.startsWith("initSet") || methodname.startsWith("initDone")) continue; @@ -91,8 +109,7 @@ QVariantMap SyncableObject::toVariantMap() { QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), &value); QMetaObject::invokeMethod(this, methodname.toAscii(), genericvalue); - properties[SignalProxy::methodBaseName(method)] = value; - // qDebug() << ">>> SYNC:" << methodBaseName(method) << value; + properties[SignalProxy::ExtendedMetaObject::methodBaseName(method)] = value; } // properties["Payload"] = QByteArray(10000000, 'a'); // for testing purposes return properties; @@ -110,7 +127,7 @@ void SyncableObject::fromVariantMap(const QVariantMap &properties) { iterator++; continue; } - + int propertyIndex = meta->indexOfProperty(propName.toAscii()); if(propertyIndex == -1 || !meta->property(propertyIndex).isWritable()) @@ -133,18 +150,46 @@ 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 { + //qDebug() << Q_FUNC_INFO << modeType << funcname; + foreach(SignalProxy *proxy, _signalProxies) { + va_list ap; + va_start(ap, funcname); + proxy->sync_call__(this, modeType, funcname, ap); + va_end(ap); + } +} + +void SyncableObject::synchronize(SignalProxy *proxy) { + if(_signalProxies.contains(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; + } + } }