Skip to content

Commit

Permalink
[qtcontacts-sqlite] Add function to access contact manager engine
Browse files Browse the repository at this point in the history
The contact manager engine must be used to access functions which
extend the Contacts API; to access these functions, use the new
contactManagerEngine() function to retrieve a typed pointer to the
engine from the QContactManager.

Note that 'QT += contacts-private' is necessary to access the engine
property of the contact manager class.
  • Loading branch information
matthewvogt committed Mar 5, 2014
1 parent 0efad1f commit 73b2e8b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/extensions/qtcontacts-extensions.h
Expand Up @@ -99,6 +99,9 @@ enum { DefaultMaximumPhoneNumberCharacters = 8 };
QString normalizePhoneNumber(const QString &input, NormalizePhoneNumberFlags flags);
QString minimizePhoneNumber(const QString &input, int maxCharacters = DefaultMaximumPhoneNumberCharacters);

class ContactManagerEngine;
ContactManagerEngine *contactManagerEngine(QContactManager &manager);

}

Q_DECLARE_OPERATORS_FOR_FLAGS(QtContactsSqliteExtensions::NormalizePhoneNumberFlags)
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/qtcontacts-extensions_impl.h
Expand Up @@ -32,7 +32,7 @@
#ifndef QTCONTACTS_EXTENSIONS_IMPL_H
#define QTCONTACTS_EXTENSIONS_IMPL_H

#include "qtcontacts-extensions.h"
#include <qtcontacts-extensions.h>

namespace {

Expand Down
54 changes: 54 additions & 0 deletions src/extensions/qtcontacts-extensions_manager_impl.h
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2013 Jolla Ltd. <matthew.vogt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/

#ifndef QTCONTACTS_EXTENSIONS_MANAGER_IMPL_H
#define QTCONTACTS_EXTENSIONS_MANAGER_IMPL_H

#include <qtcontacts-extensions.h>
#include <contactmanagerengine.h>

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

namespace QtContactsSqliteExtensions {

ContactManagerEngine *contactManagerEngine(QContactManager &manager)
{
if (QContactManagerData *data = QContactManagerData::managerData(&manager)) {
return qobject_cast<QtContactsSqliteExtensions::ContactManagerEngine *>(data->m_engine);
}

return 0;
}

}

#endif
12 changes: 3 additions & 9 deletions tests/auto/aggregation/tst_aggregation.cpp
Expand Up @@ -31,9 +31,6 @@

#define QT_STATICPLUGIN

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

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

#define TRIM_MSECS(t) t.addMSecs(0 - t.msec())
Expand Down Expand Up @@ -3885,8 +3882,7 @@ void tst_Aggregation::deactivationMultiple()

void tst_Aggregation::fetchSyncContacts()
{
typedef QtContactsSqliteExtensions::ContactManagerEngine EngineType;
EngineType *cme = qobject_cast<EngineType *>(QContactManagerData::managerData(m_cm)->m_engine);
QtContactsSqliteExtensions::ContactManagerEngine *cme = QtContactsSqliteExtensions::contactManagerEngine(*m_cm);

QSignalSpy syncSpy(cme, SIGNAL(syncContactsChanged(QStringList)));

Expand Down Expand Up @@ -4458,8 +4454,7 @@ void tst_Aggregation::fetchSyncContacts()

void tst_Aggregation::storeSyncContacts()
{
typedef QtContactsSqliteExtensions::ContactManagerEngine EngineType;
EngineType *cme = qobject_cast<EngineType *>(QContactManagerData::managerData(m_cm)->m_engine);
QtContactsSqliteExtensions::ContactManagerEngine *cme = QtContactsSqliteExtensions::contactManagerEngine(*m_cm);

QSignalSpy syncSpy(cme, SIGNAL(syncContactsChanged(QStringList)));

Expand Down Expand Up @@ -5191,8 +5186,7 @@ void tst_Aggregation::storeSyncContacts()

void tst_Aggregation::testOOB()
{
typedef QtContactsSqliteExtensions::ContactManagerEngine EngineType;
EngineType *cme = qobject_cast<EngineType *>(QContactManagerData::managerData(m_cm)->m_engine);
QtContactsSqliteExtensions::ContactManagerEngine *cme = QtContactsSqliteExtensions::contactManagerEngine(*m_cm);

const QString &scope(QString::fromLatin1("tst_Aggregation"));

Expand Down
4 changes: 2 additions & 2 deletions tests/auto/qcontactmanager/tst_qcontactmanager.cpp
Expand Up @@ -1669,8 +1669,8 @@ void tst_QContactManager::presenceReporting()

// The contactsPresenceChanged signal is not exported by QContactManager, so we
// need to find it from the manager's engine object
typedef QtContactsSqliteExtensions::ContactManagerEngine EngineType;
EngineType *cme = qobject_cast<EngineType *>(QContactManagerData::managerData(cm.data())->m_engine);
QtContactsSqliteExtensions::ContactManagerEngine *cme = QtContactsSqliteExtensions::contactManagerEngine(*cm.data());

QSignalSpy presenceChangedSpy(cme, contactsPresenceChangedSignal);

QContact a;
Expand Down
Expand Up @@ -3,11 +3,14 @@ include(../../common.pri)

TARGET = tst_qcontactmanagerfiltering

QT += contacts-private

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

HEADERS += \
../../../src/engine/contactid_p.h \
../../../src/extensions/contactmanagerengine.h \
../../util.h \
../../qcontactmanagerdataholder.h
SOURCES += \
Expand Down
4 changes: 2 additions & 2 deletions tests/util.h
Expand Up @@ -51,8 +51,8 @@

#include "contactid_p.h"

#include "../../../src/extensions/qtcontacts-extensions.h"
#include "../../../src/extensions/contactmanagerengine.h"
#include "../../../src/extensions/qtcontacts-extensions_impl.h"
#include "../../../src/extensions/qtcontacts-extensions_manager_impl.h"

#include "../../../src/extensions/qcontactdeactivated.h"
#include "../../../src/extensions/qcontactdeactivated_impl.h"
Expand Down

0 comments on commit 73b2e8b

Please sign in to comment.