diff options
author | Cristiano di Flora <cristiano.di-flora@nokia.com> | 2011-11-08 19:30:03 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-15 19:31:50 +0100 |
commit | a78a5748d3df8c0c2aea66e279b7a8076e3f4b29 (patch) | |
tree | db0b8d4d53ab340589b4edfaefdcbb5dc10ddcbc /src/contacts/qcontactmanager_p.cpp | |
parent | 549113b6cb7d236d46df4c5a3e90b6e524489df5 (diff) |
QContact Memory backend as a plugin.
Change-Id: Iac9b0169f78b8b5eb7fbcb9017f4016e32fde628
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Cristiano di Flora <cristiano.di-flora@nokia.com>
Diffstat (limited to 'src/contacts/qcontactmanager_p.cpp')
-rw-r--r-- | src/contacts/qcontactmanager_p.cpp | 117 |
1 files changed, 56 insertions, 61 deletions
diff --git a/src/contacts/qcontactmanager_p.cpp b/src/contacts/qcontactmanager_p.cpp index 950d4f3d4..65163a118 100644 --- a/src/contacts/qcontactmanager_p.cpp +++ b/src/contacts/qcontactmanager_p.cpp @@ -66,7 +66,6 @@ # include <f32file.h> #endif -#include "qcontactmemorybackend_p.h" #include "qcontactinvalidbackend_p.h" #include "qcontactspluginsearch_p.h" @@ -129,75 +128,70 @@ void QContactManagerData::createEngine(const QString& managerName, const QMap<QS m_engine = 0; QString builtManagerName = managerName.isEmpty() ? QContactManager::availableManagers().value(0) : managerName; - if (builtManagerName == QLatin1String("memory")) { - QContactManagerEngine* engine = QContactMemoryEngine::createMemoryEngine(parameters); - m_engine = new QContactManagerEngineV2Wrapper(engine); - m_signalSource = engine; #ifdef QT_SIMULATOR - } else if (builtManagerName == QLatin1String("simulator")) { + if (builtManagerName == QLatin1String("simulator")) { QContactManagerEngine* engine = QContactSimulatorEngine::createSimulatorEngine(parameters); m_engine = new QContactManagerEngineV2Wrapper(engine); m_signalSource = engine; + } #endif - } else { - int implementationVersion = parameterValue(parameters, QTCONTACTS_IMPLEMENTATION_VERSION_NAME, -1); - - bool found = false; - bool loadedDynamic = false; - - /* First check static factories */ - loadStaticFactories(); - - /* See if we got a fast hit */ - QList<QContactManagerEngineFactory*> factories = m_engines.values(builtManagerName); - m_lastError = QContactManager::NoError; - - while(!found) { - foreach (QContactManagerEngineFactory* f, factories) { - QList<int> versions = f->supportedImplementationVersions(); - if (implementationVersion == -1 ||//no given implementation version required - versions.isEmpty() || //the manager engine factory does not report any version - versions.contains(implementationVersion)) { - QContactManagerEngine* engine = f->engine(parameters, &m_lastError); - // if it's a V2, use it - // qobject_cast for QContactManagerEngineV2 broken, see QTMOBILITY-1798 - // Workaround: use code behind general qobject_cast explicitly: - //m_engine = qobject_cast<QContactManagerEngineV2*>(engine); - m_engine = static_cast<QContactManagerEngineV2*>(reinterpret_cast<QContactManagerEngineV2*>(0)->staticMetaObject.cast(engine)); - if (!m_engine && engine) { - // Nope, v1, so wrap it - m_engine = new QContactManagerEngineV2Wrapper(engine); - m_signalSource = engine; - } else { - m_signalSource = m_engine; // use the v2 engine directly - } - found = true; - break; + int implementationVersion = parameterValue(parameters, QTCONTACTS_IMPLEMENTATION_VERSION_NAME, -1); + + bool found = false; + bool loadedDynamic = false; + + /* First check static factories */ + loadStaticFactories(); + + /* See if we got a fast hit */ + QList<QContactManagerEngineFactory*> factories = m_engines.values(builtManagerName); + m_lastError = QContactManager::NoError; + + while (!found) { + foreach (QContactManagerEngineFactory* f, factories) { + QList<int> versions = f->supportedImplementationVersions(); + if (implementationVersion == -1 ||//no given implementation version required + versions.isEmpty() || //the manager engine factory does not report any version + versions.contains(implementationVersion)) { + QContactManagerEngine* engine = f->engine(parameters, &m_lastError); + // if it's a V2, use it + // qobject_cast for QContactManagerEngineV2 broken, see QTMOBILITY-1798 + // Workaround: use code behind general qobject_cast explicitly: + //m_engine = qobject_cast<QContactManagerEngineV2*>(engine); + m_engine = static_cast<QContactManagerEngineV2*>(reinterpret_cast<QContactManagerEngineV2*>(0)->staticMetaObject.cast(engine)); + if (!m_engine && engine) { + // Nope, v1, so wrap it + m_engine = new QContactManagerEngineV2Wrapper(engine); + m_signalSource = engine; + } else { + m_signalSource = m_engine; // use the v2 engine directly } + found = true; + break; } + } - // Break if found or if this is the second time through - if (loadedDynamic || found) - break; + // Break if found or if this is the second time through + if (loadedDynamic || found) + break; - // otherwise load dynamic factories and reloop - loadFactories(); - factories = m_engines.values(builtManagerName); - loadedDynamic = true; - } + // otherwise load dynamic factories and reloop + loadFactories(); + factories = m_engines.values(builtManagerName); + loadedDynamic = true; + } - // XXX remove this - // the engine factory could lie to us, so check the real implementation version - if (m_engine && (implementationVersion != -1 && m_engine->managerVersion() != implementationVersion)) { - m_lastError = QContactManager::VersionMismatchError; - m_signalSource = m_engine = 0; - } + // XXX remove this + // the engine factory could lie to us, so check the real implementation version + if (m_engine && (implementationVersion != -1 && m_engine->managerVersion() != implementationVersion)) { + m_lastError = QContactManager::VersionMismatchError; + m_signalSource = m_engine = 0; + } - if (!m_engine) { - if (m_lastError == QContactManager::NoError) - m_lastError = QContactManager::DoesNotExistError; - m_signalSource = m_engine = new QContactInvalidEngine(); - } + if (!m_engine) { + if (m_lastError == QContactManager::NoError) + m_lastError = QContactManager::DoesNotExistError; + m_signalSource = m_engine = new QContactInvalidEngine(); } } @@ -224,7 +218,7 @@ void QContactManagerData::loadStaticFactories() if (showDebug) qDebug() << "Static: found an engine plugin" << f << "with name" << name; #endif - if (name != QLatin1String("memory") && name != QLatin1String("invalid") && !name.isEmpty()) { + if (name != QLatin1String("invalid") && !name.isEmpty()) { // we also need to ensure that we haven't already loaded this factory. if (m_engines.keys().contains(name)) { qWarning() << "Static contacts plugin" << name << "has the same name as a currently loaded plugin; ignored"; @@ -279,11 +273,12 @@ void QContactManagerData::loadFactories() if (showDebug) qDebug() << "Dynamic: found a contact engine plugin" << f << "with name" << name; #endif - if (name != QLatin1String("memory") && name != QLatin1String("invalid") && !name.isEmpty()) { + if (name != QLatin1String("invalid") && !name.isEmpty()) { // we also need to ensure that we haven't already loaded this factory. if (m_engines.keys().contains(name)) { qWarning() << "Contacts plugin" << plugins.at(i) << "has the same name as currently loaded plugin" << name << "; ignored"; } else { + qDebug() << "ADDING ENGINE to m_engines: " << name << " factory: " << plugins.at(i); m_engines.insertMulti(name, f); } } else { |