Skip to content

Commit

Permalink
[qtcontacts-sqlite] Don't require QtContacts/private
Browse files Browse the repository at this point in the history
Use QCoreApplication to pass the engine from the plugin to the extension
code.
  • Loading branch information
mardy committed Oct 18, 2017
1 parent 9c00e39 commit f0ac23e
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/engine/contactsengine.cpp
Expand Up @@ -855,10 +855,16 @@ ContactsEngine::ContactsEngine(const QString &name, const QMap<QString, QString>
autoTest.toInt() == 1) {
setAutoTest(true);
}

/* Store the engine into a property of QCoreApplication, so that it can be
* retrieved by the extension code */
QCoreApplication::instance()->setProperty(CONTACT_MANAGER_ENGINE_PROP,
QVariant::fromValue(this));
}

ContactsEngine::~ContactsEngine()
{
QCoreApplication::instance()->setProperty(CONTACT_MANAGER_ENGINE_PROP, 0);
}

QString ContactsEngine::databaseUuid()
Expand Down
3 changes: 3 additions & 0 deletions src/extensions/qtcontacts-extensions.h
Expand Up @@ -108,4 +108,7 @@ ContactManagerEngine *contactManagerEngine(QContactManager &manager);

Q_DECLARE_OPERATORS_FOR_FLAGS(QtContactsSqliteExtensions::NormalizePhoneNumberFlags)

/* We define the name of the QCoreApplication property which holds our ContactsEngine */
#define CONTACT_MANAGER_ENGINE_PROP "qc_sqlite_extension_engine"

#endif
11 changes: 7 additions & 4 deletions src/extensions/qtcontacts-extensions_manager_impl.h
Expand Up @@ -35,15 +35,18 @@
#include <qtcontacts-extensions.h>
#include <contactmanagerengine.h>

// Needed for access to the QContactManager's internal engine
#include <private/qcontactmanager_p.h>
#include <QCoreApplication>
#include <QVariant>

namespace QtContactsSqliteExtensions {

ContactManagerEngine *contactManagerEngine(QContactManager &manager)
{
if (QContactManagerData *data = QContactManagerData::managerData(&manager)) {
return static_cast<QtContactsSqliteExtensions::ContactManagerEngine *>(data->m_engine);
QCoreApplication *app = QCoreApplication::instance();
QVariant v = app->property(CONTACT_MANAGER_ENGINE_PROP);
QContactManagerEngine *engine = static_cast<QContactManagerEngine*>(v.value<QObject*>());
if (engine && engine->managerName() == manager.managerName()) {
return static_cast<QtContactsSqliteExtensions::ContactManagerEngine *>(engine);
}

return 0;
Expand Down
1 change: 0 additions & 1 deletion src/extensions/twowaycontactsyncadapter_impl.h
Expand Up @@ -37,7 +37,6 @@
#include <contactmanagerengine.h>
#include <twowaycontactsyncadapter.h>
#include <qcontactoriginmetadata.h>
#include <private/qcontactmanager_p.h>

#include <QContactManager>
#include <QContactGuid>
Expand Down
2 changes: 0 additions & 2 deletions tests/auto/aggregation/aggregation.pro
@@ -1,8 +1,6 @@
TARGET = tst_aggregation
include(../../common.pri)

QT += contacts-private

INCLUDEPATH += \
../../../src/engine/

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/database/database.pro
Expand Up @@ -2,7 +2,7 @@ include(../../common.pri)

TARGET = tst_database

QT += sql contacts-private
QT += sql

# copied from src/engine/engine.pro, modified for test db
DEFINES += 'QTCONTACTS_SQLITE_PRIVILEGED_DIR=\'\"privileged\"\''
Expand Down
2 changes: 0 additions & 2 deletions tests/auto/memorytable/memorytable.pro
Expand Up @@ -2,8 +2,6 @@ include(../../common.pri)

TARGET = tst_memorytable

QT += contacts-private

HEADERS += \
../../util.h
SOURCES += \
Expand Down
2 changes: 0 additions & 2 deletions tests/auto/phonenumber/phonenumber.pro
Expand Up @@ -2,8 +2,6 @@ include(../../common.pri)

TARGET = tst_phonenumber

QT += contacts-private

HEADERS += \
../../util.h
SOURCES += \
Expand Down
2 changes: 0 additions & 2 deletions tests/auto/qcontactmanager/qcontactmanager.pro
Expand Up @@ -2,8 +2,6 @@ include(../../common.pri)

TARGET = tst_qcontactmanager

QT += contacts-private

INCLUDEPATH += \
../../../src/engine/

Expand Down
3 changes: 0 additions & 3 deletions tests/auto/qcontactmanager/tst_qcontactmanager.cpp
Expand Up @@ -48,9 +48,6 @@
#include "qversitreader.h"
#endif

// Needed for access to the QContactManager's internal engine
#include "private/qcontactmanager_p.h"

#include "../../util.h"
#include "../../qcontactmanagerdataholder.h"

Expand Down
Expand Up @@ -2,8 +2,6 @@ include(../../common.pri)

TARGET = tst_qcontactmanagerfiltering

QT += contacts-private

INCLUDEPATH += \
../../../src/engine/

Expand Down
2 changes: 0 additions & 2 deletions tests/benchmarks/deltadetection/deltadetection.pro
Expand Up @@ -8,7 +8,5 @@ HEADERS = deltasyncadapter.h ../../../src/extensions/contactmanagerengine.h

INCLUDEPATH += ../../../src/extensions ../../../src/engine/

QT += contacts-private

target.path = /opt/tests/qtcontacts-sqlite-qt5
INSTALLS += target

0 comments on commit f0ac23e

Please sign in to comment.