Commit 40f90b29 authored by mvogt's avatar mvogt

Merge pull request #200 from matthewvogt/mer-1368

[qtcontacts-sqlite] Allow enum property extensions to be stored. Contributes to MER#1368
parents bd16866b 4b06f2f3
......@@ -31,7 +31,6 @@
#include "contactreader.h"
#include "contactsengine.h"
#include "conversion_p.h"
#include "trace_p.h"
#include "../extensions/qtcontacts-extensions.h"
......@@ -79,8 +78,6 @@
#include <QtDebug>
using namespace Conversion;
static const int ReportBatchSize = 50;
static const QString aggregateSyncTarget(QString::fromLatin1("aggregate"));
......@@ -203,6 +200,15 @@ static const FieldInfo addressFields[] =
};
static QList<int> subTypeList(const QStringList &subTypeValues)
{
QList<int> rv;
foreach (const QString &value, subTypeValues) {
rv.append(value.toInt());
}
return rv;
}
static void setValues(QContactAddress *detail, QSqlQuery *query, const int offset)
{
typedef QContactAddress T;
......@@ -213,9 +219,8 @@ static void setValues(QContactAddress *detail, QSqlQuery *query, const int offse
setValue(detail, T::FieldLocality , query->value(offset + 3));
setValue(detail, T::FieldPostcode , query->value(offset + 4));
setValue(detail, T::FieldCountry , query->value(offset + 5));
QStringList subTypeNames(query->value(offset + 6).toString().split(QLatin1Char(';'), QString::SkipEmptyParts));
setValue(detail, T::FieldSubTypes , QVariant::fromValue<QList<int> >(Address::subTypeList(subTypeNames)));
const QStringList subTypeValues(query->value(offset + 6).toString().split(QLatin1Char(';'), QString::SkipEmptyParts));
setValue(detail, T::FieldSubTypes , QVariant::fromValue<QList<int> >(subTypeList(subTypeValues)));
}
static const FieldInfo anniversaryFields[] =
......@@ -232,7 +237,7 @@ static void setValues(QContactAnniversary *detail, QSqlQuery *query, const int o
setValue(detail, T::FieldOriginalDate, dateValue(query->value(offset + 0)));
setValue(detail, T::FieldCalendarId , query->value(offset + 1));
setValue(detail, T::FieldSubType , QVariant::fromValue<int>(Anniversary::subType(query->value(offset + 2).toString())));
setValue(detail, T::FieldSubType , QVariant::fromValue<int>(query->value(offset + 2).toString().toInt()));
setValue(detail, T::FieldEvent , query->value(offset + 3));
}
......@@ -394,12 +399,12 @@ static void setValues(QContactOnlineAccount *detail, QSqlQuery *query, const int
setValue(detail, T::FieldAccountUri , query->value(offset + 0));
// ignore lowerAccountUri
setValue(detail, T::FieldProtocol , QVariant::fromValue<int>(OnlineAccount::protocol(query->value(offset + 2).toString())));
setValue(detail, T::FieldProtocol , QVariant::fromValue<int>(query->value(offset + 2).toString().toInt()));
setValue(detail, T::FieldServiceProvider, query->value(offset + 3));
setValue(detail, T::FieldCapabilities , stringListValue(query->value(offset + 4)));
QStringList subTypeNames(query->value(offset + 5).toString().split(QLatin1Char(';'), QString::SkipEmptyParts));
setValue(detail, T::FieldSubTypes, QVariant::fromValue<QList<int> >(OnlineAccount::subTypeList(subTypeNames)));
const QStringList subTypeValues(query->value(offset + 5).toString().split(QLatin1Char(';'), QString::SkipEmptyParts));
setValue(detail, T::FieldSubTypes, QVariant::fromValue<QList<int> >(subTypeList(subTypeValues)));
setValue(detail, QContactOnlineAccount__FieldAccountPath, query->value(offset + 6));
setValue(detail, QContactOnlineAccount__FieldAccountIconPath, query->value(offset + 7));
......@@ -445,8 +450,8 @@ static void setValues(QContactPhoneNumber *detail, QSqlQuery *query, const int o
setValue(detail, T::FieldNumber , query->value(offset + 0));
QStringList subTypeNames(query->value(offset + 1).toString().split(QLatin1Char(';'), QString::SkipEmptyParts));
setValue(detail, T::FieldSubTypes, QVariant::fromValue<QList<int> >(PhoneNumber::subTypeList(subTypeNames)));
const QStringList subTypeValues(query->value(offset + 1).toString().split(QLatin1Char(';'), QString::SkipEmptyParts));
setValue(detail, T::FieldSubTypes, QVariant::fromValue<QList<int> >(subTypeList(subTypeValues)));
setValue(detail, QContactPhoneNumber__FieldNormalizedNumber, query->value(offset + 2));
}
......@@ -516,7 +521,7 @@ static void setValues(QContactTag *detail, QSqlQuery *query, const int offset)
static const FieldInfo urlFields[] =
{
{ QContactUrl::FieldUrl, "url", StringField },
{ QContactUrl::FieldSubType, "subTypes", StringListField }
{ QContactUrl::FieldSubType, "subTypes", StringField }
};
static void setValues(QContactUrl *detail, QSqlQuery *query, const int offset)
......@@ -524,7 +529,7 @@ static void setValues(QContactUrl *detail, QSqlQuery *query, const int offset)
typedef QContactUrl T;
setValue(detail, T::FieldUrl , urlValue(query->value(offset + 0)));
setValue(detail, T::FieldSubType, QVariant::fromValue<int>(Url::subType(query->value(offset + 1).toString())));
setValue(detail, T::FieldSubType, QVariant::fromValue<int>(query->value(offset + 1).toString().toInt()));
}
static const FieldInfo originMetadataFields[] =
......@@ -833,30 +838,30 @@ static bool validFilterField(F filter)
static QString convertFilterValueToString(const QContactDetailFilter &filter, const QString &defaultValue)
{
// Some enum types are stored in textual form
// Some enum values are stored in textual columns
if (filter.detailType() == QContactOnlineAccount::Type) {
if (filter.detailField() == QContactOnlineAccount::FieldProtocol) {
return OnlineAccount::protocol(filter.value().toInt());
return QString::number(filter.value().toInt());
} else if (filter.detailField() == QContactOnlineAccount::FieldSubTypes) {
// TODO: what if the value is a list?
return OnlineAccount::subTypeList(QList<int>() << filter.value().toInt()).first();
return QString::number(filter.value().toInt());
}
} else if (filter.detailType() == QContactPhoneNumber::Type) {
if (filter.detailField() == QContactPhoneNumber::FieldSubTypes) {
// TODO: what if the value is a list?
return PhoneNumber::subTypeList(QList<int>() << filter.value().toInt()).first();
return QString::number(filter.value().toInt());
}
} else if (filter.detailType() == QContactAnniversary::Type) {
if (filter.detailField() == QContactAnniversary::FieldSubType) {
return Anniversary::subType(filter.value().toInt());
return QString::number(filter.value().toInt());
}
} else if (filter.detailType() == QContactUrl::Type) {
if (filter.detailField() == QContactUrl::FieldSubType) {
return Url::subType(filter.value().toInt());
return QString::number(filter.value().toInt());
}
} else if (filter.detailType() == QContactGender::Type) {
if (filter.detailField() == QContactGender::FieldGender) {
return Gender::gender(filter.value().toInt());
return QString::number(filter.value().toInt());
}
}
......@@ -2139,15 +2144,8 @@ QContactManager::Error ContactReader::queryContacts(
QContactGender gender;
// Gender is an enum in qtpim
QString genderText = contactQuery.value(13).toString();
if (genderText.startsWith(QChar::fromLatin1('f'), Qt::CaseInsensitive)) {
gender.setGender(QContactGender::GenderFemale);
} else if (genderText.startsWith(QChar::fromLatin1('m'), Qt::CaseInsensitive)) {
gender.setGender(QContactGender::GenderMale);
} else {
gender.setGender(QContactGender::GenderUnspecified);
}
if (!gender.isEmpty())
contact.saveDetail(&gender);
gender.setGender(static_cast<QContactGender::GenderField>(genderText.toInt()));
contact.saveDetail(&gender);
QContactFavorite favorite;
setValue(&favorite, QContactFavorite::FieldFavorite, contactQuery.value(14).toBool());
......
This diff is collapsed.
......@@ -33,7 +33,6 @@
#include "contactsengine.h"
#include "contactreader.h"
#include "conversion_p.h"
#include "trace_p.h"
#include "../extensions/qcontactdeactivated.h"
......@@ -124,8 +123,6 @@ namespace {
}
}
using namespace Conversion;
static const QString aggregateSyncTarget(QString::fromLatin1("aggregate"));
static const QString localSyncTarget(QString::fromLatin1("local"));
static const QString wasLocalSyncTarget(QString::fromLatin1("was_local"));
......@@ -1618,6 +1615,15 @@ static void adjustAggregateDetailProperties(QContactDetail &detail)
namespace {
QStringList subTypeList(const QList<int> &subTypes)
{
QStringList rv;
foreach (int subType, subTypes) {
rv.append(QString::number(subType));
}
return rv;
}
ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quint32 detailId, const QContactAddress &detail)
{
const QString statement(QStringLiteral(
......@@ -1654,7 +1660,7 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.addBindValue(detail.value<QString>(T::FieldLocality).trimmed());
query.addBindValue(detail.value<QString>(T::FieldPostcode).trimmed());
query.addBindValue(detail.value<QString>(T::FieldCountry).trimmed());
query.addBindValue(Address::subTypeList(detail.subTypes()).join(QLatin1String(";")));
query.addBindValue(subTypeList(detail.subTypes()).join(QLatin1String(";")));
return query;
}
......@@ -1684,7 +1690,7 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.addBindValue(contactId);
query.addBindValue(detailValue(detail, T::FieldOriginalDate));
query.addBindValue(detailValue(detail, T::FieldCalendarId));
query.addBindValue(Anniversary::subType(detail.subType()));
query.addBindValue(QString::number(detail.subType()));
query.addBindValue(detail.value<QString>(T::FieldEvent).trimmed());
return query;
}
......@@ -2009,10 +2015,10 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.addBindValue(contactId);
query.addBindValue(uri);
query.addBindValue(uri.toLower());
query.addBindValue(OnlineAccount::protocol(detail.protocol()));
query.addBindValue(QString::number(detail.protocol()));
query.addBindValue(detailValue(detail, T::FieldServiceProvider));
query.addBindValue(detailValue(detail, T::FieldCapabilities).value<QStringList>().join(QLatin1String(";")));
query.addBindValue(OnlineAccount::subTypeList(detail.subTypes()).join(QLatin1String(";")));
query.addBindValue(subTypeList(detail.subTypes()).join(QLatin1String(";")));
query.addBindValue(detailValue(detail, QContactOnlineAccount__FieldAccountPath));
query.addBindValue(detailValue(detail, QContactOnlineAccount__FieldAccountIconPath));
query.addBindValue(detailValue(detail, QContactOnlineAccount__FieldEnabled));
......@@ -2084,7 +2090,7 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.addBindValue(detailId);
query.addBindValue(contactId);
query.addBindValue(detail.value<QString>(T::FieldNumber).trimmed());
query.addBindValue(PhoneNumber::subTypeList(detail.subTypes()).join(QLatin1String(";")));
query.addBindValue(subTypeList(detail.subTypes()).join(QLatin1String(";")));
query.addBindValue(QVariant(ContactsEngine::normalizedPhoneNumber(detail.number())));
return query;
}
......@@ -2197,7 +2203,7 @@ ContactsDatabase::Query bindDetail(ContactsDatabase &db, quint32 contactId, quin
query.addBindValue(detailId);
query.addBindValue(contactId);
query.addBindValue(detail.value<QString>(T::FieldUrl).trimmed());
query.addBindValue(Url::subType(detail.subType()));
query.addBindValue(QString::number(detail.subType()));
return query;
}
......@@ -3382,14 +3388,12 @@ QContactManager::Error ContactWriter::updateOrCreateAggregate(QContact *contact,
}
const QContactGender gender(contact->detail<QContactGender>());
const QString gv(gender.gender() == QContactGender::GenderFemale ? QString::fromLatin1("Female") :
gender.gender() == QContactGender::GenderMale ? QString::fromLatin1("Male") : QString());
if (gv == QString::fromLatin1("Male")) {
excludeGender = QString::fromLatin1("Female");
} else if (gv == QString::fromLatin1("Female")) {
excludeGender = QString::fromLatin1("Male");
if (gender.gender() == QContactGender::GenderMale) {
excludeGender = QString::number(static_cast<int>(QContactGender::GenderFemale));
} else if (gender.gender() == QContactGender::GenderFemale) {
excludeGender = QString::number(static_cast<int>(QContactGender::GenderMale));
} else {
excludeGender = QString::fromLatin1("none");
excludeGender = QStringLiteral("none");
}
/*
......@@ -5629,9 +5633,7 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
query.bindValue(11, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldModificationTimestamp).toUTC()));
const QContactGender gender = contact.detail<QContactGender>();
const QString gv(gender.gender() == QContactGender::GenderFemale ? QString::fromLatin1("Female") :
gender.gender() == QContactGender::GenderMale ? QString::fromLatin1("Male") : QString());
query.bindValue(12, gv);
query.bindValue(12, QString::number(static_cast<int>(gender.gender())));
const QContactFavorite favorite = contact.detail<QContactFavorite>();
query.bindValue(13, favorite.isFavorite());
......
......@@ -25,6 +25,9 @@ SOURCES += ../../../src/engine/contactstransientstore.cpp
HEADERS += ../../../src/engine/memorytable.h
SOURCES += ../../../src/engine/memorytable.cpp
HEADERS += ../../../src/engine/conversion_p.h
SOURCES += ../../../src/engine/conversion.cpp
SOURCES += stub_contactsengine.cpp
SOURCES += tst_database.cpp
......@@ -8,4 +8,5 @@ HEADERS += \
../../util.h
SOURCES += \
tst_memorytable.cpp \
../../../src/engine/conversion.cpp \
../../../src/engine/memorytable.cpp
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment