diff options
author | Jani Honkonen <jani.honkonen@digia.com> | 2010-05-04 10:36:26 +0300 |
---|---|---|
committer | Jani Honkonen <jani.honkonen@digia.com> | 2010-05-04 10:55:38 +0300 |
commit | c1ad5d6b9b51303f8aee4fc8575a60023ac5987d (patch) | |
tree | bc217e3073fb8c3b2099f0b16b1df88af8f11262 | |
parent | 43b52fad96718a8629848ac4e789e35ece745f50 (diff) |
Symbian SIM: Implemented special handling for phone number filtering.
Phonenumber must be matched by using specified number of digits from the right.
The number of digits is configured through a cenrep key which is locale specific.
6 files changed, 106 insertions, 20 deletions
diff --git a/plugins/contacts/symbiansim/inc/cntsymbiansimengine.h b/plugins/contacts/symbiansim/inc/cntsymbiansimengine.h index eafdfc3fd3..c43f77d170 100644 --- a/plugins/contacts/symbiansim/inc/cntsymbiansimengine.h +++ b/plugins/contacts/symbiansim/inc/cntsymbiansimengine.h @@ -97,7 +97,8 @@ public: ~CntSymbianSimEngineData(); CntSimStore *m_simStore; - QMap<QContactAbstractRequest *, CntAbstractSimRequest *> m_asyncRequests; + QMap<QContactAbstractRequest *, CntAbstractSimRequest *> m_asyncRequests; + int m_phoneNumberMatchLen; }; class CntSymbianSimEngine : public QContactManagerEngine @@ -141,15 +142,18 @@ public: /* Capabilities reporting */ bool hasFeature(QContactManager::ManagerFeature feature, const QString& contactType = QContactType::TypeContact) const; + bool isFilterSupported(const QContactFilter& filter) const; QStringList supportedContactTypes() const; public: void updateDisplayLabel(QContact& contact) const; CntSimStore* simStore() { return d->m_simStore; } void setReadOnlyAccessConstraint(QContactDetail* detail) const; + bool filter(const QContactFilter &filter, const QContact &contact); private: bool executeRequest(QContactAbstractRequest *req, QContactManager::Error* qtError) const; + void getMatchLengthL(int &matchLength); private: QExplicitlySharedDataPointer<CntSymbianSimEngineData> d; diff --git a/plugins/contacts/symbiansim/src/cntsimcontactfetchrequest.cpp b/plugins/contacts/symbiansim/src/cntsimcontactfetchrequest.cpp index 005c697c8b..725fb30e86 100644 --- a/plugins/contacts/symbiansim/src/cntsimcontactfetchrequest.cpp +++ b/plugins/contacts/symbiansim/src/cntsimcontactfetchrequest.cpp @@ -108,7 +108,7 @@ void CntSimContactFetchRequest::readComplete(QList<QContact> contacts, QContactM // Filter & sort results QList<QContact> filteredAndSorted; for (int i=0; i<contacts.count(); i++) { - if (QContactManagerEngine::testFilter(r->filter(), contacts.at(i))) + if (engine()->filter(r->filter(), contacts.at(i))) QContactManagerEngine::addSorted(&filteredAndSorted, contacts.at(i), r->sorting()); } diff --git a/plugins/contacts/symbiansim/src/cntsimcontactlocalidfetchrequest.cpp b/plugins/contacts/symbiansim/src/cntsimcontactlocalidfetchrequest.cpp index 7de87d2c93..e8149c5fbc 100644 --- a/plugins/contacts/symbiansim/src/cntsimcontactlocalidfetchrequest.cpp +++ b/plugins/contacts/symbiansim/src/cntsimcontactlocalidfetchrequest.cpp @@ -95,7 +95,7 @@ void CntSimContactLocalIdFetchRequest::readComplete(QList<QContact> contacts, QC // Filter & sort results QList<QContact> filteredAndSorted; for (int i=0; i<contacts.count(); i++) { - if (QContactManagerEngine::testFilter(r->filter(), contacts.at(i))) + if (engine()->filter(r->filter(), contacts.at(i))) QContactManagerEngine::addSorted(&filteredAndSorted, contacts.at(i), r->sorting()); } diff --git a/plugins/contacts/symbiansim/src/cntsymbiansimengine.cpp b/plugins/contacts/symbiansim/src/cntsymbiansimengine.cpp index 249a2b674c..04209790df 100644 --- a/plugins/contacts/symbiansim/src/cntsymbiansimengine.cpp +++ b/plugins/contacts/symbiansim/src/cntsymbiansimengine.cpp @@ -53,8 +53,20 @@ #include <QTimer> #include <QDebug> +#include <centralrepository.h> + const int KRequestTimeout = 30000; // in ms +// Telephony Configuration API +// Keys under this category are used in defining telephony configuration. +const TUid KCRUidTelConfiguration = {0x102828B8}; +// Amount of digits to be used in contact matching. +// This allows a customer to variate the amount of digits to be matched. +const TUint32 KTelMatchDigits = 0x00000001; +// Default match length +const TInt KDefaultMatchLength(7); + + CntSymbianSimEngineData::CntSymbianSimEngineData() :m_simStore(0) { @@ -85,6 +97,10 @@ CntSymbianSimEngine::CntSymbianSimEngine(const QMap<QString, QString>& parameter //qDebug() << "Failed to open SIM store" << error; return; } + + // Get phone number match length from cenrep + d->m_phoneNumberMatchLen = KDefaultMatchLength; + TRAP_IGNORE(getMatchLengthL(d->m_phoneNumberMatchLen)); // ignore error and use default value if(d->m_simStore->storeInfo().m_storeName == KParameterValueSimStoreNameSdn) { // In case of SDN store we need to check if any SDN contacts exist to @@ -460,6 +476,23 @@ bool CntSymbianSimEngine::hasFeature(QContactManager::ManagerFeature feature, co } /*! + Returns a whether the supplied \a filter can be implemented + natively by this engine. If not, the base class implementation + will emulate the functionality. + */ +bool CntSymbianSimEngine::isFilterSupported(const QContactFilter& filter) const +{ + if (filter.type() == QContactFilter::ContactDetailFilter) { + QContactDetailFilter f(filter); + if (f.detailDefinitionName() == QContactPhoneNumber::DefinitionName && + f.detailFieldName() == QContactPhoneNumber::FieldNumber && + f.matchFlags() == QContactFilter::MatchPhoneNumber) + return true; + } + return false; +} + +/*! * Returns the list of data types supported by the manager */ QStringList CntSymbianSimEngine::supportedContactTypes() const @@ -482,6 +515,36 @@ void CntSymbianSimEngine::setReadOnlyAccessConstraint(QContactDetail* detail) co setDetailAccessConstraints(detail, QContactDetail::ReadOnly); } + +/*! + Returns true if the supplied contact \a contact matches the supplied filter \a filter. + */ +bool CntSymbianSimEngine::filter(const QContactFilter &filter, const QContact &contact) +{ + // Special handling for phonenumber matching: + // Matching is done from the right by using a configurable number of digits. + // Default number of digits is 7. So for example if we filter with number + // +358505555555 the filter should match to +358505555555 and 0505555555. + if (filter.type() == QContactFilter::ContactDetailFilter) + { + QContactDetailFilter f(filter); + if (f.detailDefinitionName() == QContactPhoneNumber::DefinitionName && + f.detailFieldName() == QContactPhoneNumber::FieldNumber && + f.matchFlags() == QContactFilter::MatchPhoneNumber) + { + QString matchNumber = f.value().toString().right(d->m_phoneNumberMatchLen); + QList<QContactPhoneNumber> pns = contact.details<QContactPhoneNumber>(); + foreach (QContactPhoneNumber pn, pns) { + QString number = pn.number().right(d->m_phoneNumberMatchLen); + if (number == matchNumber) + return true; + } + return false; + } + } + return QContactManagerEngine::testFilter(filter, contact); +} + /*! * Executes an asynchronous request so that it will appear synchronous. This is * used internally in all synchronous functions. This way we only need to @@ -519,6 +582,20 @@ bool CntSymbianSimEngine::executeRequest(QContactAbstractRequest *req, QContactM return (*qtError == QContactManager::NoError); } +/* + * Get the match length setting used in MatchPhoneNumber type filtering. + * \a matchLength Phone number digits to be used in matching (counted from + * right). + */ +void CntSymbianSimEngine::getMatchLengthL(int &matchLength) +{ + //Get number of digits used to match + CRepository* repository = CRepository::NewL(KCRUidTelConfiguration); + CleanupStack::PushL(repository); + User::LeaveIfError(repository->Get(KTelMatchDigits, matchLength)); + CleanupStack::PopAndDestroy(repository); +} + QContactManagerEngine* CntSymbianSimFactory::engine(const QMap<QString, QString>& parameters, QContactManager::Error* error) { CntSymbianSimEngine *engine = new CntSymbianSimEngine(parameters, error); diff --git a/plugins/contacts/symbiansim/symbiansim.pro b/plugins/contacts/symbiansim/symbiansim.pro index f9d2a0c0c9..456600f206 100644 --- a/plugins/contacts/symbiansim/symbiansim.pro +++ b/plugins/contacts/symbiansim/symbiansim.pro @@ -57,7 +57,8 @@ symbian: { LIBS += -lcntmodel \ -lflogger \ - -lefsrv + -lefsrv \ + -lcentralrepository target.path = /sys/bin INSTALLS += target diff --git a/plugins/contacts/symbiansim/tsrc/tst_simcm/tst_simcm.cpp b/plugins/contacts/symbiansim/tsrc/tst_simcm/tst_simcm.cpp index 073713d0cd..3bab4d9749 100644 --- a/plugins/contacts/symbiansim/tsrc/tst_simcm/tst_simcm.cpp +++ b/plugins/contacts/symbiansim/tsrc/tst_simcm/tst_simcm.cpp @@ -999,6 +999,7 @@ void tst_SimCM::detailFilter_data() QTest::addColumn<QString>("detailField"); QTest::addColumn<QString>("value"); QTest::addColumn<int>("flags"); + QTest::addColumn<bool>("filterSupported"); QTest::addColumn<QString>("expected"); // Phone number @@ -1007,59 +1008,59 @@ void tst_SimCM::detailFilter_data() QString field = QContactPhoneNumber::FieldNumber; QTest::newRow("phonenumber=123456789, flags=MatchExactly") - << detail << field << "123456789" << (int) QContactFilter::MatchExactly << "a"; + << detail << field << "123456789" << (int) QContactFilter::MatchExactly << false << "a"; QTest::newRow("phonenumber=123456789, flags=MatchContains") - << detail << field << "123456789" << (int) QContactFilter::MatchContains << "abc"; + << detail << field << "123456789" << (int) QContactFilter::MatchContains << false << "abc"; QTest::newRow("phonenumber=#, flags=MatchContains") - << detail << field << "#" << (int) QContactFilter::MatchContains << "f"; + << detail << field << "#" << (int) QContactFilter::MatchContains << false << "f"; QTest::newRow("phonenumber=p, flags=MatchContains") - << detail << field << "p" << (int) QContactFilter::MatchContains << "e"; + << detail << field << "p" << (int) QContactFilter::MatchContains << false << "e"; QTest::newRow("phonenumber=0, flags=MatchStartsWith") - << detail << field << "0" << (int) QContactFilter::MatchStartsWith << "defi"; + << detail << field << "0" << (int) QContactFilter::MatchStartsWith << false << "defi"; QTest::newRow("phonenumber=012, flags=MatchEndsWith") - << detail << field << "012" << (int) QContactFilter::MatchEndsWith << "c"; + << detail << field << "012" << (int) QContactFilter::MatchEndsWith << false << "c"; QTest::newRow("phonenumber=+358505555555, flags=MatchPhoneNumber") - << detail << field << "+358505555555" << (int) QContactFilter::MatchPhoneNumber << "ij"; // should match to 0505555555 also + << detail << field << "+358505555555" << (int) QContactFilter::MatchPhoneNumber << true << "ij"; QTest::newRow("phonenumber=313, flags=MatchPhoneNumber") - << detail << field << "313" << (int) QContactFilter::MatchPhoneNumber << "h"; + << detail << field << "313" << (int) QContactFilter::MatchPhoneNumber << true << "h"; // Custom label detail = (QLatin1String) QContactName::DefinitionName; field = (QLatin1String) QContactName::FieldCustomLabel; QTest::newRow("customlabel=frederik") - << detail << field << "frederik" << 0 << "c"; + << detail << field << "frederik" << 0 << false << "c"; QTest::newRow("customlabel=Kallasvuo flags=MatchContains") - << detail << field << "Kallasvuo" << (int) (QContactFilter::MatchContains) << "d"; + << detail << field << "Kallasvuo" << (int) (QContactFilter::MatchContains) << false << "d"; QTest::newRow("customlabel=Matti flags=MatchStartsWith") - << detail << field << "Matti" << (int) (QContactFilter::MatchStartsWith) << "b"; + << detail << field << "Matti" << (int) (QContactFilter::MatchStartsWith) << false << "b"; QTest::newRow("customlabel=co flags=MatchEndsWith") - << detail << field << "co" << (int) (QContactFilter::MatchEndsWith) << "f"; + << detail << field << "co" << (int) (QContactFilter::MatchEndsWith) << false << "f"; // ITU-T standard keypad collation: // 2 = abc, 3 = def, 4 = ghi, 5 = jkl, 6 = mno, 7 = pqrs, 8 = tuv, 9 = wxyz, 0 = space QTest::newRow("customlabel T9 olli, flags=MatchKeypadCollation|MatchExactly") - << detail << field << "6554" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchExactly)<< "g"; + << detail << field << "6554" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchExactly) << false << "g"; QTest::newRow("customlabel T9 olli, flags=MatchKeypadCollation|MatchContains") - << detail << field << "6554" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchContains)<< "adg"; + << detail << field << "6554" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchContains) << false << "adg"; QTest::newRow("customlabel T9 jorma, flags=MatchKeypadCollation|MatchStartsWith") - << detail << field << "56762" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchStartsWith)<< "a"; + << detail << field << "56762" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchStartsWith) << false << "a"; QTest::newRow("customlabel T9 nen, flags=MatchKeypadCollation|MatchEndsWith") - << detail << field << "636" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchEndsWith)<< "b"; + << detail << field << "636" << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchEndsWith) << false << "b"; } void tst_SimCM::detailFilter() @@ -1068,6 +1069,7 @@ void tst_SimCM::detailFilter() QFETCH(QString, detailField); QFETCH(QString, value); QFETCH(int, flags); + QFETCH(bool, filterSupported); QFETCH(QString, expected); initManager("ADN"); @@ -1089,6 +1091,8 @@ void tst_SimCM::detailFilter() f.setDetailDefinitionName(detailName, detailField); f.setMatchFlags(QContactFilter::MatchFlags(flags)); f.setValue(value); + + QVERIFY(m_cm->isFilterSupported(f) == filterSupported); QList<QContactLocalId> ids = m_cm->contactIds(f); QVERIFY(m_cm->error() == QContactManager::NoError); |