X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsyncableobject.cpp;h=aab2857c668e590822a0439d0bbf478d6daabc60;hp=781dd15109e5123d63cf70df0440d0a8ce429913;hb=e89cfe68c0b4d117ce79d0d38fcc085de77a3083;hpb=57d44eafac4d353d1523e93cc7613debc1826e94 diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index 781dd151..aab2857c 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,13 +27,41 @@ #include "signalproxy.h" #include "util.h" -SyncableObject::SyncableObject(QObject *parent) : QObject(parent) { - _initialized = false; +SyncableObject::SyncableObject(QObject *parent) + : QObject(parent), + _initialized(false), + _allowClientUpdates(false) +{ } -SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent) : 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), + _allowClientUpdates(other._allowClientUpdates) +{ +} + +SyncableObject &SyncableObject::operator=(const SyncableObject &other) { + if(this == &other) + return *this; + _initialized = other._initialized; + _allowClientUpdates = other._allowClientUpdates; + return *this; +} +void SyncableObject::synchronize(SignalProxy *proxy) { + if(_signalProxies.contains(proxy)) + return; + _signalProxies << proxy; } bool SyncableObject::isInitialized() const { @@ -51,15 +79,20 @@ QVariantMap SyncableObject::toVariantMap() { const QMetaObject* meta = metaObject(); // we collect data from properties + QMetaProperty prop; + QString propName; for(int i = 0; i < meta->propertyCount(); i++) { - QMetaProperty prop = meta->property(i); - properties[QString(prop.name())] = prop.read(this); + prop = meta->property(i); + propName = QString(prop.name()); + if(propName == "objectName") + continue; + properties[propName] = prop.read(this); } // ...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; @@ -72,8 +105,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; @@ -84,14 +116,20 @@ void SyncableObject::fromVariantMap(const QVariantMap &properties) { const QMetaObject *meta = metaObject(); QVariantMap::const_iterator iterator = properties.constBegin(); + QString propName; while(iterator != properties.constEnd()) { - QString name = iterator.key(); - int propertyIndex = meta->indexOfProperty(name.toAscii()); + propName = iterator.key(); + if(propName == "objectName") { + iterator++; + continue; + } + + int propertyIndex = meta->indexOfProperty(propName.toAscii()); if(propertyIndex == -1 || !meta->property(propertyIndex).isWritable()) - setInitValue(name, iterator.value()); + setInitValue(propName, iterator.value()); else - setProperty(name.toAscii(), iterator.value()); + setProperty(propName.toAscii(), iterator.value()); // qDebug() << "<<< SYNC:" << name << iterator.value(); iterator++; } @@ -111,3 +149,25 @@ void SyncableObject::renameObject(const QString &newName) { emit objectRenamed(newName, oldName); } } + +void SyncableObject::update(const QVariantMap &properties) { + fromVariantMap(properties); + emit updated(properties); +} + +void SyncableObject::requestUpdate(const QVariantMap &properties) { + if(allowClientUpdates()) { + update(properties); + } + emit updateRequested(properties); +} + +void SyncableObject::sync_call__(SignalProxy::ProxyMode modeType, const char *funcname, ...) { + qDebug() << Q_FUNC_INFO << modeType << funcname; + foreach(SignalProxy *proxy, _signalProxies) { + va_list ap; + va_start(ap, funcname); + proxy->syncCall(this, modeType, funcname, ap); + va_end(ap); + } +}