Commit 3b97cb96 authored by chriadam's avatar chriadam

Merge branch 'jb44707-core-apps' into 'master'

Jb44707 core apps

See merge request !15
parents 1b709ae3 e0a0fc6f
...@@ -10,6 +10,7 @@ BuildRequires: pkgconfig(Qt5Core) ...@@ -10,6 +10,7 @@ BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Sql) BuildRequires: pkgconfig(Qt5Sql)
BuildRequires: pkgconfig(Qt5DBus) BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Contacts) BuildRequires: pkgconfig(Qt5Contacts)
BuildRequires: pkgconfig(mlite5)
Requires: qt5-plugin-sqldriver-sqlite Requires: qt5-plugin-sqldriver-sqlite
%description %description
...@@ -23,7 +24,6 @@ Requires: qt5-plugin-sqldriver-sqlite ...@@ -23,7 +24,6 @@ Requires: qt5-plugin-sqldriver-sqlite
Summary: Unit tests for qtcontacts-sqlite-qt5 Summary: Unit tests for qtcontacts-sqlite-qt5
Group: System/Libraries Group: System/Libraries
BuildRequires: pkgconfig(Qt5Test) BuildRequires: pkgconfig(Qt5Test)
Requires: blts-tools
Requires: %{name} = %{version}-%{release} Requires: %{name} = %{version}-%{release}
%description tests %description tests
...@@ -32,6 +32,7 @@ This package contains unit tests for the qtcontacts-sqlite-qt5 library. ...@@ -32,6 +32,7 @@ This package contains unit tests for the qtcontacts-sqlite-qt5 library.
%files tests %files tests
%defattr(-,root,root,-) %defattr(-,root,root,-)
/opt/tests/qtcontacts-sqlite-qt5/* /opt/tests/qtcontacts-sqlite-qt5/*
%{_libdir}/qtcontacts-sqlite-qt5/libtestdlgg.so
%package extensions %package extensions
Summary: QtContacts extension headers for qtcontacts-sqlite-qt5 Summary: QtContacts extension headers for qtcontacts-sqlite-qt5
...@@ -51,7 +52,7 @@ This package contains extension headers for the qtcontacts-sqlite-qt5 library. ...@@ -51,7 +52,7 @@ This package contains extension headers for the qtcontacts-sqlite-qt5 library.
%setup -q -n %{name}-%{version} %setup -q -n %{name}-%{version}
%build %build
%qmake5 %qmake5 "VERSION=%{version}"
make %{?_smp_mflags} make %{?_smp_mflags}
%install %install
......
...@@ -142,7 +142,8 @@ static QVariant dateValue(const QVariant &columnValue) ...@@ -142,7 +142,8 @@ static QVariant dateValue(const QVariant &columnValue)
static const FieldInfo displayLabelFields[] = static const FieldInfo displayLabelFields[] =
{ {
{ QContactDisplayLabel::FieldLabel, "displayLabel", LocalizedField } { QContactDisplayLabel::FieldLabel, "displayLabel", LocalizedField },
{ QContactDisplayLabel__FieldLabelGroup, "displayLabelGroup", LocalizedField }
}; };
static const FieldInfo nameFields[] = static const FieldInfo nameFields[] =
...@@ -1410,7 +1411,10 @@ static QString buildOrderBy(const QContactSortOrder &order, QStringList *joins, ...@@ -1410,7 +1411,10 @@ static QString buildOrderBy(const QContactSortOrder &order, QStringList *joins,
return QString(); return QString();
} }
QString sortExpression(QStringLiteral("%1.%2").arg(detail.joinToSort ? detail.table : QStringLiteral("Contacts")).arg(field.column)); const bool isDisplayLabelGroup = detail.detailType == QContactDisplayLabel::Type && field.field == QContactDisplayLabel__FieldLabelGroup;
QString sortExpression(QStringLiteral("%1.%2")
.arg(detail.joinToSort ? detail.table : QStringLiteral("Contacts"))
.arg(isDisplayLabelGroup ? QStringLiteral("DisplayLabelGroupSortOrder") : field.column));
bool sortBlanks = true; bool sortBlanks = true;
bool collate = true; bool collate = true;
bool localized = field.fieldType == LocalizedField; bool localized = field.fieldType == LocalizedField;
...@@ -1457,7 +1461,7 @@ static QString buildOrderBy(const QContactSortOrder &order, QStringList *joins, ...@@ -1457,7 +1461,7 @@ static QString buildOrderBy(const QContactSortOrder &order, QStringList *joins,
result.append(sortExpression); result.append(sortExpression);
if (collate) { if (!isDisplayLabelGroup && collate) {
if (localized && useLocale) { if (localized && useLocale) {
result.append(QLatin1String(" COLLATE localeCollation")); result.append(QLatin1String(" COLLATE localeCollation"));
} else { } else {
...@@ -1935,7 +1939,30 @@ QContactManager::Error ContactReader::queryContacts( ...@@ -1935,7 +1939,30 @@ QContactManager::Error ContactReader::queryContacts(
QContactManager::Error err = QContactManager::NoError; QContactManager::Error err = QContactManager::NoError;
const QString idsQueryStatement(QString::fromLatin1( const QString idsQueryStatement(QString::fromLatin1(
"SELECT Contacts.* " "SELECT " // order and content can change due to schema upgrades, so list manually.
"Contacts.contactId, "
"Contacts.displayLabel, "
"Contacts.displayLabelGroup, "
"Contacts.firstName, "
"Contacts.lowerFirstName, "
"Contacts.lastName, "
"Contacts.lowerLastName, "
"Contacts.middleName, "
"Contacts.prefix, "
"Contacts.suffix, "
"Contacts.customLabel, "
"Contacts.syncTarget, "
"Contacts.created, "
"Contacts.modified, "
"Contacts.gender, "
"Contacts.isFavorite, "
"Contacts.hasPhoneNumber, "
"Contacts.hasEmailAddress, "
"Contacts.hasOnlineAccount, "
"Contacts.isOnline, "
"Contacts.isDeactivated, "
"Contacts.isIncidental, "
"Contacts.type "
"FROM temp.%1 " "FROM temp.%1 "
"CROSS JOIN Contacts ON temp.%1.contactId = Contacts.contactId " // Cross join ensures we scan the temp table first "CROSS JOIN Contacts ON temp.%1.contactId = Contacts.contactId " // Cross join ensures we scan the temp table first
"ORDER BY temp.%1.rowId ASC").arg(tableName)); "ORDER BY temp.%1.rowId ASC").arg(tableName));
...@@ -2117,22 +2144,22 @@ QContactManager::Error ContactReader::queryContacts( ...@@ -2117,22 +2144,22 @@ QContactManager::Error ContactReader::queryContacts(
contact.setId(id); contact.setId(id);
QString persistedDL = contactQuery.value(1).toString(); QString persistedDL = contactQuery.value(1).toString();
if (!persistedDL.isEmpty()) QString displayLabelGroup = contactQuery.value(2).toString();
ContactsEngine::setContactDisplayLabel(&contact, persistedDL); ContactsEngine::setContactDisplayLabel(&contact, persistedDL, displayLabelGroup);
QContactName name; QContactName name;
setValue(&name, QContactName::FieldFirstName , contactQuery.value(2)); setValue(&name, QContactName::FieldFirstName , contactQuery.value(3));
// ignore lowerFirstName // ignore lowerFirstName
setValue(&name, QContactName::FieldLastName , contactQuery.value(4)); setValue(&name, QContactName::FieldLastName , contactQuery.value(5));
// ignore lowerLastName // ignore lowerLastName
setValue(&name, QContactName::FieldMiddleName , contactQuery.value(6)); setValue(&name, QContactName::FieldMiddleName , contactQuery.value(7));
setValue(&name, QContactName::FieldPrefix , contactQuery.value(7)); setValue(&name, QContactName::FieldPrefix , contactQuery.value(8));
setValue(&name, QContactName::FieldSuffix , contactQuery.value(8)); setValue(&name, QContactName::FieldSuffix , contactQuery.value(9));
setValue(&name, QContactName__FieldCustomLabel, contactQuery.value(9)); setValue(&name, QContactName__FieldCustomLabel, contactQuery.value(10));
if (!name.isEmpty()) if (!name.isEmpty())
contact.saveDetail(&name); contact.saveDetail(&name);
const QString syncTarget(contactQuery.value(10).toString()); const QString syncTarget(contactQuery.value(11).toString());
QContactSyncTarget starget; QContactSyncTarget starget;
setValue(&starget, QContactSyncTarget::FieldSyncTarget, syncTarget); setValue(&starget, QContactSyncTarget::FieldSyncTarget, syncTarget);
...@@ -2140,27 +2167,27 @@ QContactManager::Error ContactReader::queryContacts( ...@@ -2140,27 +2167,27 @@ QContactManager::Error ContactReader::queryContacts(
contact.saveDetail(&starget); contact.saveDetail(&starget);
QContactTimestamp timestamp; QContactTimestamp timestamp;
setValue(&timestamp, QContactTimestamp::FieldCreationTimestamp , ContactsDatabase::fromDateTimeString(contactQuery.value(11).toString())); setValue(&timestamp, QContactTimestamp::FieldCreationTimestamp , ContactsDatabase::fromDateTimeString(contactQuery.value(12).toString()));
setValue(&timestamp, QContactTimestamp::FieldModificationTimestamp, ContactsDatabase::fromDateTimeString(contactQuery.value(12).toString())); setValue(&timestamp, QContactTimestamp::FieldModificationTimestamp, ContactsDatabase::fromDateTimeString(contactQuery.value(13).toString()));
QContactGender gender; QContactGender gender;
// Gender is an enum in qtpim // Gender is an enum in qtpim
QString genderText = contactQuery.value(13).toString(); QString genderText = contactQuery.value(14).toString();
gender.setGender(static_cast<QContactGender::GenderField>(genderText.toInt())); gender.setGender(static_cast<QContactGender::GenderField>(genderText.toInt()));
contact.saveDetail(&gender); contact.saveDetail(&gender);
QContactFavorite favorite; QContactFavorite favorite;
setValue(&favorite, QContactFavorite::FieldFavorite, contactQuery.value(14).toBool()); setValue(&favorite, QContactFavorite::FieldFavorite, contactQuery.value(15).toBool());
if (!favorite.isEmpty()) if (!favorite.isEmpty())
contact.saveDetail(&favorite); contact.saveDetail(&favorite);
QContactStatusFlags flags; QContactStatusFlags flags;
flags.setFlag(QContactStatusFlags::HasPhoneNumber, contactQuery.value(15).toBool()); flags.setFlag(QContactStatusFlags::HasPhoneNumber, contactQuery.value(16).toBool());
flags.setFlag(QContactStatusFlags::HasEmailAddress, contactQuery.value(16).toBool()); flags.setFlag(QContactStatusFlags::HasEmailAddress, contactQuery.value(17).toBool());
flags.setFlag(QContactStatusFlags::HasOnlineAccount, contactQuery.value(17).toBool()); flags.setFlag(QContactStatusFlags::HasOnlineAccount, contactQuery.value(18).toBool());
flags.setFlag(QContactStatusFlags::IsOnline, contactQuery.value(18).toBool()); flags.setFlag(QContactStatusFlags::IsOnline, contactQuery.value(19).toBool());
flags.setFlag(QContactStatusFlags::IsDeactivated, contactQuery.value(19).toBool()); flags.setFlag(QContactStatusFlags::IsDeactivated, contactQuery.value(20).toBool());
flags.setFlag(QContactStatusFlags::IsIncidental, contactQuery.value(20).toBool()); flags.setFlag(QContactStatusFlags::IsIncidental, contactQuery.value(21).toBool());
if (flags.testFlag(QContactStatusFlags::IsDeactivated)) { if (flags.testFlag(QContactStatusFlags::IsDeactivated)) {
QContactDeactivated deactivated; QContactDeactivated deactivated;
...@@ -2171,7 +2198,7 @@ QContactManager::Error ContactReader::queryContacts( ...@@ -2171,7 +2198,7 @@ QContactManager::Error ContactReader::queryContacts(
contact.saveDetail(&incidental); contact.saveDetail(&incidental);
} }
int contactType = contactQuery.value(21).toInt(); int contactType = contactQuery.value(22).toInt();
QContactType typeDetail = contact.detail<QContactType>(); QContactType typeDetail = contact.detail<QContactType>();
typeDetail.setType(static_cast<QContactType::TypeValues>(contactType)); typeDetail.setType(static_cast<QContactType::TypeValues>(contactType));
contact.saveDetail(&typeDetail); contact.saveDetail(&typeDetail);
......
This diff is collapsed.
...@@ -34,6 +34,11 @@ ...@@ -34,6 +34,11 @@
#include "semaphore_p.h" #include "semaphore_p.h"
#include "contactstransientstore.h" #include "contactstransientstore.h"
#include "../extensions/displaylabelgroupgenerator.h"
#ifdef HAS_MLITE
#include <mgconfitem.h>
#endif
#include <QHash> #include <QHash>
#include <QMutex> #include <QMutex>
...@@ -42,7 +47,11 @@ ...@@ -42,7 +47,11 @@
#include <QSqlError> #include <QSqlError>
#include <QSqlQuery> #include <QSqlQuery>
#include <QVariantList> #include <QVariantList>
#include <QVector>
#include <QContact>
class ContactsEngine;
class ContactsDatabase class ContactsDatabase
{ {
public: public:
...@@ -101,7 +110,7 @@ public: ...@@ -101,7 +110,7 @@ public:
void reportError(const char *text) const; void reportError(const char *text) const;
}; };
ContactsDatabase(); ContactsDatabase(ContactsEngine *engine);
~ContactsDatabase(); ~ContactsDatabase();
QMutex *accessMutex() const; QMutex *accessMutex() const;
...@@ -148,6 +157,12 @@ public: ...@@ -148,6 +157,12 @@ public:
bool removeTransientDetails(quint32 contactId); bool removeTransientDetails(quint32 contactId);
bool removeTransientDetails(const QList<quint32> &contactIds); bool removeTransientDetails(const QList<quint32> &contactIds);
void regenerateDisplayLabelGroups();
QString displayLabelGroupPreferredProperty() const;
QString determineDisplayLabelGroup(const QContact &c);
QStringList displayLabelGroups() const;
int displayLabelGroupSortValue(const QString &group) const;
static bool execute(QSqlQuery &query); static bool execute(QSqlQuery &query);
static bool executeBatch(QSqlQuery &query, QSqlQuery::BatchExecutionMode mode = QSqlQuery::ValuesAsRows); static bool executeBatch(QSqlQuery &query, QSqlQuery::BatchExecutionMode mode = QSqlQuery::ValuesAsRows);
...@@ -163,6 +178,7 @@ public: ...@@ -163,6 +178,7 @@ public:
static QDateTime fromDateTimeString(const QString &s); static QDateTime fromDateTimeString(const QString &s);
private: private:
ContactsEngine *m_engine;
QSqlDatabase m_database; QSqlDatabase m_database;
ContactsTransientStore m_transientStore; ContactsTransientStore m_transientStore;
QMutex m_mutex; QMutex m_mutex;
...@@ -170,6 +186,12 @@ private: ...@@ -170,6 +186,12 @@ private:
bool m_nonprivileged; bool m_nonprivileged;
QString m_localeName; QString m_localeName;
QHash<QString, QSqlQuery> m_preparedQueries; QHash<QString, QSqlQuery> m_preparedQueries;
QVector<QtContactsSqliteExtensions::DisplayLabelGroupGenerator*> m_dlgGenerators;
QScopedPointer<QtContactsSqliteExtensions::DisplayLabelGroupGenerator> m_defaultGenerator;
QMap<QString, int> m_knownDisplayLabelGroupsSortValues;
#ifdef HAS_MLITE
MGConfItem m_groupPropertyConf;
#endif // HAS_MLITE
}; };
#endif #endif
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "qtcontacts-extensions.h" #include "qtcontacts-extensions.h"
#include "qtcontacts-extensions_impl.h" #include "qtcontacts-extensions_impl.h"
#include "displaylabelgroupgenerator.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QMutex> #include <QMutex>
...@@ -68,13 +69,13 @@ class Job ...@@ -68,13 +69,13 @@ class Job
{ {
public: public:
struct WriterProxy { struct WriterProxy {
const ContactsEngine &engine; ContactsEngine &engine;
ContactsDatabase &database; ContactsDatabase &database;
ContactNotifier &notifier; ContactNotifier &notifier;
ContactReader &reader; ContactReader &reader;
mutable ContactWriter *writer; mutable ContactWriter *writer;
WriterProxy(const ContactsEngine &e, ContactsDatabase &db, ContactNotifier &n, ContactReader &r) WriterProxy(ContactsEngine &e, ContactsDatabase &db, ContactNotifier &n, ContactReader &r)
: engine(e), database(db), notifier(n), reader(r), writer(0) : engine(e), database(db), notifier(n), reader(r), writer(0)
{ {
} }
...@@ -517,6 +518,7 @@ public: ...@@ -517,6 +518,7 @@ public:
JobThread(ContactsEngine *engine, const QString &databaseUuid, bool nonprivileged, bool autoTest) JobThread(ContactsEngine *engine, const QString &databaseUuid, bool nonprivileged, bool autoTest)
: m_currentJob(0) : m_currentJob(0)
, m_engine(engine) , m_engine(engine)
, m_database(engine)
, m_databaseUuid(databaseUuid) , m_databaseUuid(databaseUuid)
, m_updatePending(false) , m_updatePending(false)
, m_running(false) , m_running(false)
...@@ -1173,16 +1175,19 @@ QList<QContactType::TypeValues> ContactsEngine::supportedContactTypes() const ...@@ -1173,16 +1175,19 @@ QList<QContactType::TypeValues> ContactsEngine::supportedContactTypes() const
return QList<QContactType::TypeValues>() << QContactType::TypeContact; return QList<QContactType::TypeValues>() << QContactType::TypeContact;
} }
void ContactsEngine::regenerateDisplayLabel(QContact &contact) const void ContactsEngine::regenerateDisplayLabel(QContact &contact)
{ {
QContactManager::Error displayLabelError = QContactManager::NoError; QContactManager::Error displayLabelError = QContactManager::NoError;
QString label = synthesizedDisplayLabel(contact, &displayLabelError); const QString label = synthesizedDisplayLabel(contact, &displayLabelError);
if (displayLabelError != QContactManager::NoError) { if (displayLabelError != QContactManager::NoError) {
QTCONTACTS_SQLITE_DEBUG(QString::fromLatin1("Unable to regenerate displayLabel for contact: %1").arg(ContactId::toString(contact))); QTCONTACTS_SQLITE_DEBUG(QString::fromLatin1("Unable to regenerate displayLabel for contact: %1").arg(ContactId::toString(contact)));
return; return;
} }
setContactDisplayLabel(&contact, label); QContact tempContact(contact);
setContactDisplayLabel(&tempContact, label, QString());
const QString group = m_database ? m_database->determineDisplayLabelGroup(tempContact) : QString();
setContactDisplayLabel(&contact, label, group);
} }
bool ContactsEngine::fetchSyncContacts(const QString &syncTarget, const QDateTime &lastSync, const QList<QContactId> &exportedIds, bool ContactsEngine::fetchSyncContacts(const QString &syncTarget, const QDateTime &lastSync, const QList<QContactId> &exportedIds,
...@@ -1282,11 +1287,29 @@ bool ContactsEngine::removeOOB(const QString &scope) ...@@ -1282,11 +1287,29 @@ bool ContactsEngine::removeOOB(const QString &scope)
return writer()->removeOOB(scope, QStringList()); return writer()->removeOOB(scope, QStringList());
} }
bool ContactsEngine::setContactDisplayLabel(QContact *contact, const QString &label) QStringList ContactsEngine::displayLabelGroups()
{
return database().displayLabelGroups();
}
bool ContactsEngine::setContactDisplayLabel(QContact *contact, const QString &label, const QString &group)
{ {
QContactDisplayLabel detail(contact->detail<QContactDisplayLabel>()); QContactDisplayLabel detail(contact->detail<QContactDisplayLabel>());
detail.setLabel(label); bool needSave = false;
return contact->saveDetail(&detail); if (!label.trimmed().isEmpty()) {
detail.setLabel(label);
needSave = true;
}
if (!group.trimmed().isEmpty()) {
detail.setValue(QContactDisplayLabel__FieldLabelGroup, group);
needSave = true;
}
if (needSave) {
return contact->saveDetail(&detail);
}
return true;
} }
QString ContactsEngine::normalizedPhoneNumber(const QString &input) QString ContactsEngine::normalizedPhoneNumber(const QString &input)
...@@ -1390,6 +1413,11 @@ void ContactsEngine::_q_syncContactsChanged(const QStringList &syncTargets) ...@@ -1390,6 +1413,11 @@ void ContactsEngine::_q_syncContactsChanged(const QStringList &syncTargets)
emit syncContactsChanged(syncTargets); emit syncContactsChanged(syncTargets);
} }
void ContactsEngine::_q_displayLabelGroupsChanged()
{
emit displayLabelGroupsChanged(displayLabelGroups());
}
void ContactsEngine::_q_contactsRemoved(const QVector<quint32> &contactIds) void ContactsEngine::_q_contactsRemoved(const QVector<quint32> &contactIds)
{ {
emit contactsRemoved(idList(contactIds)); emit contactsRemoved(idList(contactIds));
...@@ -1416,7 +1444,7 @@ ContactsDatabase &ContactsEngine::database() ...@@ -1416,7 +1444,7 @@ ContactsDatabase &ContactsEngine::database()
QString dbId(QStringLiteral("qtcontacts-sqlite%1-%2")); QString dbId(QStringLiteral("qtcontacts-sqlite%1-%2"));
dbId = dbId.arg(m_autoTest ? QStringLiteral("-test") : QString()).arg(databaseUuid()); dbId = dbId.arg(m_autoTest ? QStringLiteral("-test") : QString()).arg(databaseUuid());
m_database.reset(new ContactsDatabase); m_database.reset(new ContactsDatabase(this));
if (!m_database->open(dbId, m_nonprivileged, m_autoTest, true)) { if (!m_database->open(dbId, m_nonprivileged, m_autoTest, true)) {
QTCONTACTS_SQLITE_WARNING(QString::fromLatin1("Unable to open synchronous engine database connection")); QTCONTACTS_SQLITE_WARNING(QString::fromLatin1("Unable to open synchronous engine database connection"));
} }
......
...@@ -132,7 +132,7 @@ public: ...@@ -132,7 +132,7 @@ public:
bool isRelationshipTypeSupported(const QString &relationshipType, QContactType::TypeValues contactType) const override; bool isRelationshipTypeSupported(const QString &relationshipType, QContactType::TypeValues contactType) const override;
QList<QContactType::TypeValues> supportedContactTypes() const override; QList<QContactType::TypeValues> supportedContactTypes() const override;
void regenerateDisplayLabel(QContact &contact) const; void regenerateDisplayLabel(QContact &contact);
bool fetchSyncContacts(const QString &syncTarget, const QDateTime &lastSync, const QList<QContactId> &exportedIds, bool fetchSyncContacts(const QString &syncTarget, const QDateTime &lastSync, const QList<QContactId> &exportedIds,
QList<QContact> *syncContacts, QList<QContact> *addedContacts, QList<QContactId> *deletedContactIds, QList<QContact> *syncContacts, QList<QContact> *addedContacts, QList<QContactId> *deletedContactIds,
...@@ -159,12 +159,14 @@ public: ...@@ -159,12 +159,14 @@ public:
bool removeOOB(const QString &scope, const QStringList &keys); bool removeOOB(const QString &scope, const QStringList &keys);
bool removeOOB(const QString &scope); bool removeOOB(const QString &scope);
static bool setContactDisplayLabel(QContact *contact, const QString &label); static bool setContactDisplayLabel(QContact *contact, const QString &label, const QString &group);
static QString normalizedPhoneNumber(const QString &input); static QString normalizedPhoneNumber(const QString &input);
QString synthesizedDisplayLabel(const QContact &contact, QContactManager::Error *error) const; QString synthesizedDisplayLabel(const QContact &contact, QContactManager::Error *error) const;
QStringList displayLabelGroups() override;
private slots: private slots:
void _q_contactsChanged(const QVector<quint32> &contactIds); void _q_contactsChanged(const QVector<quint32> &contactIds);
void _q_contactsPresenceChanged(const QVector<quint32> &contactIds); void _q_contactsPresenceChanged(const QVector<quint32> &contactIds);
...@@ -174,6 +176,7 @@ private slots: ...@@ -174,6 +176,7 @@ private slots:
void _q_selfContactIdChanged(quint32,quint32); void _q_selfContactIdChanged(quint32,quint32);
void _q_relationshipsAdded(const QVector<quint32> &contactIds); void _q_relationshipsAdded(const QVector<quint32> &contactIds);
void _q_relationshipsRemoved(const QVector<quint32> &contactIds); void _q_relationshipsRemoved(const QVector<quint32> &contactIds);
void _q_displayLabelGroupsChanged();
private: private:
QString databaseUuid(); QString databaseUuid();
......
...@@ -139,7 +139,7 @@ static const QString matchEmailAddressesTable(QString::fromLatin1("matchEmailAdd ...@@ -139,7 +139,7 @@ static const QString matchEmailAddressesTable(QString::fromLatin1("matchEmailAdd
static const QString matchPhoneNumbersTable(QString::fromLatin1("matchPhoneNumbers")); static const QString matchPhoneNumbersTable(QString::fromLatin1("matchPhoneNumbers"));
static const QString matchOnlineAccountsTable(QString::fromLatin1("matchOnlineAccounts")); static const QString matchOnlineAccountsTable(QString::fromLatin1("matchOnlineAccounts"));
ContactWriter::ContactWriter(const ContactsEngine &engine, ContactsDatabase &database, ContactNotifier *notifier, ContactReader *reader) ContactWriter::ContactWriter(ContactsEngine &engine, ContactsDatabase &database, ContactNotifier *notifier, ContactReader *reader)
: m_engine(engine) : m_engine(engine)
, m_database(database) , m_database(database)
, m_notifier(notifier) , m_notifier(notifier)
...@@ -5541,6 +5541,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac ...@@ -5541,6 +5541,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
const QString insertContact(QStringLiteral( const QString insertContact(QStringLiteral(
" INSERT INTO Contacts (" " INSERT INTO Contacts ("
" displayLabel," " displayLabel,"
" displayLabelGroup,"
" displayLabelGroupSortOrder,"
" firstName," " firstName,"
" lowerFirstName," " lowerFirstName,"
" lastName," " lastName,"
...@@ -5562,6 +5564,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac ...@@ -5562,6 +5564,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
" isIncidental)" " isIncidental)"
" VALUES (" " VALUES ("
" :displayLabel," " :displayLabel,"
" :displayLabelGroup,"
" :displayLabelGroupSortOrder,"
" :firstName," " :firstName,"
" :lowerFirstName," " :lowerFirstName,"
" :lastName," " :lastName,"
...@@ -5585,6 +5589,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac ...@@ -5585,6 +5589,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
const QString updateContact(QStringLiteral( const QString updateContact(QStringLiteral(
" UPDATE Contacts SET" " UPDATE Contacts SET"
" displayLabel = :displayLabel," " displayLabel = :displayLabel,"
" displayLabelGroup = :displayLabelGroup,"
" displayLabelGroupSortOrder = :displayLabelGroupSortOrder,"
" firstName = :firstName," " firstName = :firstName,"
" lowerFirstName = :lowerFirstName," " lowerFirstName = :lowerFirstName,"
" lastName = :lastName," " lastName = :lastName,"
...@@ -5610,34 +5616,39 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac ...@@ -5610,34 +5616,39 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
ContactsDatabase::Query query(m_database.prepare(update ? updateContact : insertContact)); ContactsDatabase::Query query(m_database.prepare(update ? updateContact : insertContact));
QContactDisplayLabel label = contact.detail<QContactDisplayLabel>();
query.bindValue(0, label.label().trimmed());
const QContactName name = contact.detail<QContactName>(); const QContactName name = contact.detail<QContactName>();
const QString firstName(name.value<QString>(QContactName::FieldFirstName).trimmed()); const QString firstName(name.value<QString>(QContactName::FieldFirstName).trimmed());
const QString lastName(name.value<QString>(QContactName::FieldLastName).trimmed()); const QString lastName(name.value<QString>(QContactName::FieldLastName).trimmed());
query.bindValue(1, firstName); QContactDisplayLabel label = contact.detail<QContactDisplayLabel>();
query.bindValue(2, firstName.toLower()); const QString displayLabel = label.label().trimmed();
query.bindValue(3, lastName); query.bindValue(0, displayLabel);
query.bindValue(4, lastName.toLower()); const QString displayLabelGroup = m_database.determineDisplayLabelGroup(contact);
query.bindValue(5, name.value<QString>(QContactName::FieldMiddleName).trimmed()); query.bindValue(1, displayLabelGroup);
query.bindValue(6, name.value<QString>(QContactName::FieldPrefix).trimmed()); const int displayLabelGroupSortOrder = m_database.displayLabelGroupSortValue(displayLabelGroup);
query.bindValue(7, name.value<QString>(QContactName::FieldSuffix).trimmed()); query.bindValue(2, displayLabelGroupSortOrder);
query.bindValue(8, name.value<QString>(QContactName__FieldCustomLabel).trimmed());
query.bindValue(3, firstName);
query.bindValue(4, firstName.toLower());
query.bindValue(5, lastName);
query.bindValue(6, lastName.toLower());
query.bindValue(7, name.value<QString>(QContactName::FieldMiddleName).trimmed());
query.bindValue(8, name.value<QString>(QContactName::FieldPrefix).trimmed());
query.bindValue(9, name.value<QString>(QContactName::FieldSuffix).trimmed());
query.bindValue(10, name.value<QString>(QContactName__FieldCustomLabel).trimmed());
const QString syncTarget(contact.detail<QContactSyncTarget>().syncTarget()); const QString syncTarget(contact.detail<QContactSyncTarget>().syncTarget());
query.bindValue(9, syncTarget); query.bindValue(11, syncTarget);
const QContactTimestamp timestamp = contact.detail<QContactTimestamp>(); const QContactTimestamp timestamp = contact.detail<QContactTimestamp>();
query.bindValue(10, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldCreationTimestamp).toUTC())); query.bindValue(12, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldCreationTimestamp).toUTC()));
query.bindValue(11, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldModificationTimestamp).toUTC())); query.bindValue(13, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldModificationTimestamp).toUTC()));
const QContactGender gender = contact.detail<QContactGender>(); const QContactGender gender = contact.detail<QContactGender>();
query.bindValue(12, QString::number(static_cast<int>(gender.gender()))); query.bindValue(14, QString::number(static_cast<int>(gender.gender())));
const QContactFavorite favorite = contact.detail<QContactFavorite>(); const QContactFavorite favorite = contact.detail<QContactFavorite>();
query.bindValue(13, favorite.isFavorite()); query.bindValue(15, favorite.isFavorite());
// Does this contact contain the information needed to update hasPhoneNumber? // Does this contact contain the information needed to update hasPhoneNumber?
bool hasPhoneNumberKnown = definitionMask.isEmpty() || detailListContains<QContactPhoneNumber>(definitionMask); bool hasPhoneNumberKnown = definitionMask.isEmpty() || detailListContains<QContactPhoneNumber>(definitionMask);
...@@ -5672,26 +5683,26 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac ...@@ -5672,26 +5683,26 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
} }
if (update) { if (update) {
query.bindValue(14, hasPhoneNumberKnown); query.bindValue(16, hasPhoneNumberKnown);
query.bindValue(15, hasPhoneNumber); query.bindValue(17, hasPhoneNumber);
query.bindValue(16, hasEmailAddressKnown); query.bindValue(18, hasEmailAddressKnown);
query.bindValue(17, hasEmailAddress); query.bindValue(19, hasEmailAddress);
query.bindValue(18, hasOnlineAccountKnown); query.bindValue(20, hasOnlineAccountKnown);
query.bindValue(19, hasOnlineAccount); query.bindValue(21, hasOnlineAccount);
query.bindValue(20, isOnlineKnown); query.bindValue(22, isOnlineKnown);
query.bindValue(21, isOnline); query.bindValue(23, isOnline);
query.bindValue(22, isDeactivatedKnown); query.bindValue(24, isDeactivatedKnown);
query.bindValue(23, isDeactivated); query.bindValue(25, isDeactivated);
query.bindValue(24, contactId); query.bindValue(26, contactId);
} else { } else {
query.bindValue(14, hasPhoneNumber); query.bindValue(16, hasPhoneNumber);
query.bindValue(15, hasEmailAddress); query.bindValue(17, hasEmailAddress);
query.bindValue(16, hasOnlineAccount); query.bindValue(18, hasOnlineAccount);
query.bindValue(17, isOnline); query.bindValue(19, isOnline);
query.bindValue(18, isDeactivated); query.bindValue(20, isDeactivated);
// Incidental state only applies to creation // Incidental state only applies to creation
query.bindValue(19, !contact.details<QContactIncidental>().isEmpty()); query.bindValue(21, !contact.details<QContactIncidental>().isEmpty());
} }
return query; return query;
......