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)
BuildRequires: pkgconfig(Qt5Sql)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Contacts)
BuildRequires: pkgconfig(mlite5)
Requires: qt5-plugin-sqldriver-sqlite
%description
......@@ -23,7 +24,6 @@ Requires: qt5-plugin-sqldriver-sqlite
Summary: Unit tests for qtcontacts-sqlite-qt5
Group: System/Libraries
BuildRequires: pkgconfig(Qt5Test)
Requires: blts-tools
Requires: %{name} = %{version}-%{release}
%description tests
......@@ -32,6 +32,7 @@ This package contains unit tests for the qtcontacts-sqlite-qt5 library.
%files tests
%defattr(-,root,root,-)
/opt/tests/qtcontacts-sqlite-qt5/*
%{_libdir}/qtcontacts-sqlite-qt5/libtestdlgg.so
%package extensions
Summary: QtContacts extension headers for qtcontacts-sqlite-qt5
......@@ -51,7 +52,7 @@ This package contains extension headers for the qtcontacts-sqlite-qt5 library.
%setup -q -n %{name}-%{version}
%build
%qmake5
%qmake5 "VERSION=%{version}"
make %{?_smp_mflags}
%install
......
......@@ -142,7 +142,8 @@ static QVariant dateValue(const QVariant &columnValue)
static const FieldInfo displayLabelFields[] =
{
{ QContactDisplayLabel::FieldLabel, "displayLabel", LocalizedField }
{ QContactDisplayLabel::FieldLabel, "displayLabel", LocalizedField },
{ QContactDisplayLabel__FieldLabelGroup, "displayLabelGroup", LocalizedField }
};
static const FieldInfo nameFields[] =
......@@ -1410,7 +1411,10 @@ static QString buildOrderBy(const QContactSortOrder &order, QStringList *joins,
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 collate = true;
bool localized = field.fieldType == LocalizedField;
......@@ -1457,7 +1461,7 @@ static QString buildOrderBy(const QContactSortOrder &order, QStringList *joins,
result.append(sortExpression);
if (collate) {
if (!isDisplayLabelGroup && collate) {
if (localized && useLocale) {
result.append(QLatin1String(" COLLATE localeCollation"));
} else {
......@@ -1935,7 +1939,30 @@ QContactManager::Error ContactReader::queryContacts(
QContactManager::Error err = QContactManager::NoError;
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 "
"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));
......@@ -2117,22 +2144,22 @@ QContactManager::Error ContactReader::queryContacts(
contact.setId(id);
QString persistedDL = contactQuery.value(1).toString();
if (!persistedDL.isEmpty())
ContactsEngine::setContactDisplayLabel(&contact, persistedDL);
QString displayLabelGroup = contactQuery.value(2).toString();
ContactsEngine::setContactDisplayLabel(&contact, persistedDL, displayLabelGroup);
QContactName name;
setValue(&name, QContactName::FieldFirstName , contactQuery.value(2));
setValue(&name, QContactName::FieldFirstName , contactQuery.value(3));
// ignore lowerFirstName
setValue(&name, QContactName::FieldLastName , contactQuery.value(4));
setValue(&name, QContactName::FieldLastName , contactQuery.value(5));
// ignore lowerLastName
setValue(&name, QContactName::FieldMiddleName , contactQuery.value(6));
setValue(&name, QContactName::FieldPrefix , contactQuery.value(7));
setValue(&name, QContactName::FieldSuffix , contactQuery.value(8));
setValue(&name, QContactName__FieldCustomLabel, contactQuery.value(9));
setValue(&name, QContactName::FieldMiddleName , contactQuery.value(7));
setValue(&name, QContactName::FieldPrefix , contactQuery.value(8));
setValue(&name, QContactName::FieldSuffix , contactQuery.value(9));
setValue(&name, QContactName__FieldCustomLabel, contactQuery.value(10));
if (!name.isEmpty())
contact.saveDetail(&name);
const QString syncTarget(contactQuery.value(10).toString());
const QString syncTarget(contactQuery.value(11).toString());
QContactSyncTarget starget;
setValue(&starget, QContactSyncTarget::FieldSyncTarget, syncTarget);
......@@ -2140,27 +2167,27 @@ QContactManager::Error ContactReader::queryContacts(
contact.saveDetail(&starget);
QContactTimestamp timestamp;
setValue(&timestamp, QContactTimestamp::FieldCreationTimestamp , ContactsDatabase::fromDateTimeString(contactQuery.value(11).toString()));
setValue(&timestamp, QContactTimestamp::FieldModificationTimestamp, ContactsDatabase::fromDateTimeString(contactQuery.value(12).toString()));
setValue(&timestamp, QContactTimestamp::FieldCreationTimestamp , ContactsDatabase::fromDateTimeString(contactQuery.value(12).toString()));
setValue(&timestamp, QContactTimestamp::FieldModificationTimestamp, ContactsDatabase::fromDateTimeString(contactQuery.value(13).toString()));
QContactGender gender;
// 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()));
contact.saveDetail(&gender);
QContactFavorite favorite;
setValue(&favorite, QContactFavorite::FieldFavorite, contactQuery.value(14).toBool());
setValue(&favorite, QContactFavorite::FieldFavorite, contactQuery.value(15).toBool());
if (!favorite.isEmpty())
contact.saveDetail(&favorite);
QContactStatusFlags flags;
flags.setFlag(QContactStatusFlags::HasPhoneNumber, contactQuery.value(15).toBool());
flags.setFlag(QContactStatusFlags::HasEmailAddress, contactQuery.value(16).toBool());
flags.setFlag(QContactStatusFlags::HasOnlineAccount, contactQuery.value(17).toBool());
flags.setFlag(QContactStatusFlags::IsOnline, contactQuery.value(18).toBool());
flags.setFlag(QContactStatusFlags::IsDeactivated, contactQuery.value(19).toBool());
flags.setFlag(QContactStatusFlags::IsIncidental, contactQuery.value(20).toBool());
flags.setFlag(QContactStatusFlags::HasPhoneNumber, contactQuery.value(16).toBool());
flags.setFlag(QContactStatusFlags::HasEmailAddress, contactQuery.value(17).toBool());
flags.setFlag(QContactStatusFlags::HasOnlineAccount, contactQuery.value(18).toBool());
flags.setFlag(QContactStatusFlags::IsOnline, contactQuery.value(19).toBool());
flags.setFlag(QContactStatusFlags::IsDeactivated, contactQuery.value(20).toBool());
flags.setFlag(QContactStatusFlags::IsIncidental, contactQuery.value(21).toBool());
if (flags.testFlag(QContactStatusFlags::IsDeactivated)) {
QContactDeactivated deactivated;
......@@ -2171,7 +2198,7 @@ QContactManager::Error ContactReader::queryContacts(
contact.saveDetail(&incidental);
}
int contactType = contactQuery.value(21).toInt();
int contactType = contactQuery.value(22).toInt();
QContactType typeDetail = contact.detail<QContactType>();
typeDetail.setType(static_cast<QContactType::TypeValues>(contactType));
contact.saveDetail(&typeDetail);
......
This diff is collapsed.
......@@ -34,6 +34,11 @@
#include "semaphore_p.h"
#include "contactstransientstore.h"
#include "../extensions/displaylabelgroupgenerator.h"
#ifdef HAS_MLITE
#include <mgconfitem.h>
#endif
#include <QHash>
#include <QMutex>
......@@ -42,7 +47,11 @@
#include <QSqlError>
#include <QSqlQuery>
#include <QVariantList>
#include <QVector>
#include <QContact>
class ContactsEngine;
class ContactsDatabase
{
public:
......@@ -101,7 +110,7 @@ public:
void reportError(const char *text) const;
};
ContactsDatabase();
ContactsDatabase(ContactsEngine *engine);
~ContactsDatabase();
QMutex *accessMutex() const;
......@@ -148,6 +157,12 @@ public:
bool removeTransientDetails(quint32 contactId);
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 executeBatch(QSqlQuery &query, QSqlQuery::BatchExecutionMode mode = QSqlQuery::ValuesAsRows);
......@@ -163,6 +178,7 @@ public:
static QDateTime fromDateTimeString(const QString &s);
private:
ContactsEngine *m_engine;
QSqlDatabase m_database;
ContactsTransientStore m_transientStore;
QMutex m_mutex;
......@@ -170,6 +186,12 @@ private:
bool m_nonprivileged;
QString m_localeName;
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
......@@ -39,6 +39,7 @@
#include "qtcontacts-extensions.h"
#include "qtcontacts-extensions_impl.h"
#include "displaylabelgroupgenerator.h"
#include <QCoreApplication>
#include <QMutex>
......@@ -68,13 +69,13 @@ class Job
{
public:
struct WriterProxy {
const ContactsEngine &engine;
ContactsEngine &engine;
ContactsDatabase &database;
ContactNotifier &notifier;
ContactReader &reader;
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)
{
}
......@@ -517,6 +518,7 @@ public:
JobThread(ContactsEngine *engine, const QString &databaseUuid, bool nonprivileged, bool autoTest)
: m_currentJob(0)
, m_engine(engine)
, m_database(engine)
, m_databaseUuid(databaseUuid)
, m_updatePending(false)
, m_running(false)
......@@ -1173,16 +1175,19 @@ QList<QContactType::TypeValues> ContactsEngine::supportedContactTypes() const
return QList<QContactType::TypeValues>() << QContactType::TypeContact;
}
void ContactsEngine::regenerateDisplayLabel(QContact &contact) const
void ContactsEngine::regenerateDisplayLabel(QContact &contact)
{
QContactManager::Error displayLabelError = QContactManager::NoError;
QString label = synthesizedDisplayLabel(contact, &displayLabelError);
const QString label = synthesizedDisplayLabel(contact, &displayLabelError);
if (displayLabelError != QContactManager::NoError) {
QTCONTACTS_SQLITE_DEBUG(QString::fromLatin1("Unable to regenerate displayLabel for contact: %1").arg(ContactId::toString(contact)));
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,
......@@ -1282,11 +1287,29 @@ bool ContactsEngine::removeOOB(const QString &scope)
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>());
detail.setLabel(label);
return contact->saveDetail(&detail);
bool needSave = false;
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)
......@@ -1390,6 +1413,11 @@ void ContactsEngine::_q_syncContactsChanged(const QStringList &syncTargets)
emit syncContactsChanged(syncTargets);
}
void ContactsEngine::_q_displayLabelGroupsChanged()
{
emit displayLabelGroupsChanged(displayLabelGroups());
}
void ContactsEngine::_q_contactsRemoved(const QVector<quint32> &contactIds)
{
emit contactsRemoved(idList(contactIds));
......@@ -1416,7 +1444,7 @@ ContactsDatabase &ContactsEngine::database()
QString dbId(QStringLiteral("qtcontacts-sqlite%1-%2"));
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)) {
QTCONTACTS_SQLITE_WARNING(QString::fromLatin1("Unable to open synchronous engine database connection"));
}
......
......@@ -132,7 +132,7 @@ public:
bool isRelationshipTypeSupported(const QString &relationshipType, QContactType::TypeValues contactType) 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,
QList<QContact> *syncContacts, QList<QContact> *addedContacts, QList<QContactId> *deletedContactIds,
......@@ -159,12 +159,14 @@ public:
bool removeOOB(const QString &scope, const QStringList &keys);
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);
QString synthesizedDisplayLabel(const QContact &contact, QContactManager::Error *error) const;
QStringList displayLabelGroups() override;
private slots:
void _q_contactsChanged(const QVector<quint32> &contactIds);
void _q_contactsPresenceChanged(const QVector<quint32> &contactIds);
......@@ -174,6 +176,7 @@ private slots:
void _q_selfContactIdChanged(quint32,quint32);
void _q_relationshipsAdded(const QVector<quint32> &contactIds);
void _q_relationshipsRemoved(const QVector<quint32> &contactIds);
void _q_displayLabelGroupsChanged();
private:
QString databaseUuid();
......
......@@ -139,7 +139,7 @@ static const QString matchEmailAddressesTable(QString::fromLatin1("matchEmailAdd
static const QString matchPhoneNumbersTable(QString::fromLatin1("matchPhoneNumbers"));
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_database(database)
, m_notifier(notifier)
......@@ -5541,6 +5541,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
const QString insertContact(QStringLiteral(
" INSERT INTO Contacts ("
" displayLabel,"
" displayLabelGroup,"
" displayLabelGroupSortOrder,"
" firstName,"
" lowerFirstName,"
" lastName,"
......@@ -5562,6 +5564,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
" isIncidental)"
" VALUES ("
" :displayLabel,"
" :displayLabelGroup,"
" :displayLabelGroupSortOrder,"
" :firstName,"
" :lowerFirstName,"
" :lastName,"
......@@ -5585,6 +5589,8 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
const QString updateContact(QStringLiteral(
" UPDATE Contacts SET"
" displayLabel = :displayLabel,"
" displayLabelGroup = :displayLabelGroup,"
" displayLabelGroupSortOrder = :displayLabelGroupSortOrder,"
" firstName = :firstName,"
" lowerFirstName = :lowerFirstName,"
" lastName = :lastName,"
......@@ -5610,34 +5616,39 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
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 QString firstName(name.value<QString>(QContactName::FieldFirstName).trimmed());
const QString lastName(name.value<QString>(QContactName::FieldLastName).trimmed());
query.bindValue(1, firstName);
query.bindValue(2, firstName.toLower());
query.bindValue(3, lastName);
query.bindValue(4, lastName.toLower());
query.bindValue(5, name.value<QString>(QContactName::FieldMiddleName).trimmed());
query.bindValue(6, name.value<QString>(QContactName::FieldPrefix).trimmed());
query.bindValue(7, name.value<QString>(QContactName::FieldSuffix).trimmed());
query.bindValue(8, name.value<QString>(QContactName__FieldCustomLabel).trimmed());
QContactDisplayLabel label = contact.detail<QContactDisplayLabel>();
const QString displayLabel = label.label().trimmed();
query.bindValue(0, displayLabel);
const QString displayLabelGroup = m_database.determineDisplayLabelGroup(contact);
query.bindValue(1, displayLabelGroup);
const int displayLabelGroupSortOrder = m_database.displayLabelGroupSortValue(displayLabelGroup);
query.bindValue(2, displayLabelGroupSortOrder);
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());
query.bindValue(9, syncTarget);
query.bindValue(11, syncTarget);
const QContactTimestamp timestamp = contact.detail<QContactTimestamp>();
query.bindValue(10, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldCreationTimestamp).toUTC()));
query.bindValue(11, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldModificationTimestamp).toUTC()));
query.bindValue(12, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldCreationTimestamp).toUTC()));
query.bindValue(13, ContactsDatabase::dateTimeString(timestamp.value<QDateTime>(QContactTimestamp::FieldModificationTimestamp).toUTC()));
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>();
query.bindValue(13, favorite.isFavorite());
query.bindValue(15, favorite.isFavorite());
// Does this contact contain the information needed to update hasPhoneNumber?
bool hasPhoneNumberKnown = definitionMask.isEmpty() || detailListContains<QContactPhoneNumber>(definitionMask);
......@@ -5672,26 +5683,26 @@ ContactsDatabase::Query ContactWriter::bindContactDetails(const QContact &contac
}
if (update) {
query.bindValue(14, hasPhoneNumberKnown);
query.bindValue(15, hasPhoneNumber);
query.bindValue(16, hasEmailAddressKnown);
query.bindValue(17, hasEmailAddress);
query.bindValue(18, hasOnlineAccountKnown);
query.bindValue(19, hasOnlineAccount);
query.bindValue(20, isOnlineKnown);
query.bindValue(21, isOnline);
query.bindValue(22, isDeactivatedKnown);
query.bindValue(23, isDeactivated);
query.bindValue(24, contactId);
query.bindValue(16, hasPhoneNumberKnown);
query.bindValue(17, hasPhoneNumber);
query.bindValue(18, hasEmailAddressKnown);
query.bindValue(19, hasEmailAddress);
query.bindValue(20, hasOnlineAccountKnown);
query.bindValue(21, hasOnlineAccount);
query.bindValue(22, isOnlineKnown);
query.bindValue(23, isOnline);
query.bindValue(24, isDeactivatedKnown);
query.bindValue(25, isDeactivated);
query.bindValue(26, contactId);
} else {
query.bindValue(14, hasPhoneNumber);
query.bindValue(15, hasEmailAddress);
query.bindValue(16, hasOnlineAccount);
query.bindValue(17, isOnline);
query.bindValue(18, isDeactivated);
query.bindValue(16, hasPhoneNumber);
query.bindValue(17, hasEmailAddress);
query.bindValue(18, hasOnlineAccount);
query.bindValue(19, isOnline);
query.bindValue(20, isDeactivated);
// Incidental state only applies to creation
query.bindValue(19, !contact.details<QContactIncidental>().isEmpty());
query.bindValue(21, !contact.details<QContactIncidental>().isEmpty());
}
return query;
......
......@@ -72,7 +72,7 @@ class ContactWriter
public:
typedef QList<QContactDetail::DetailType> DetailList;
ContactWriter(const ContactsEngine &engine, ContactsDatabase &database, ContactNotifier *notifier, ContactReader *reader);
ContactWriter(ContactsEngine &engine, ContactsDatabase &database, ContactNotifier *notifier, ContactReader *reader);
~ContactWriter();
QContactManager::Error save(
......@@ -167,7 +167,7 @@ private:
template <typename T> bool removeCommonDetails(quint32 contactId, QContactManager::Error *error);
const ContactsEngine &m_engine;
ContactsEngine &m_engine;
ContactsDatabase &m_database;
ContactNotifier *m_notifier;
ContactReader *m_reader;
......
/*
* Copyright (C) 2019 Jolla Ltd. <chris.adams@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."
*/
#include "defaultdlggenerator.h"
/*
This display label group generator provides the
default (fallback) group generation semantics, and should
be the last generator used (i.e. if no other generator
is valid in the current locale).
The semantics it implements are as follows:
1) if the preferred name field data is empty,
it falls back to display label data to generate the
group.
2) if the first character of the preferred data
is a digit (0..9) then the group is '#'.
3) if the first character of the preferred data
is within 'A'..'Z' it returns that character.
(TODO: perform a unidecode transliteration first.)
4) otherwise, the group is '?'
For example, if the preferred detail is
QContactName::Type and the preferred field is
QContactName::FieldLastName, and the client passes
in a contact with name "John Smith", then the first
letter of the last name (in this case, 'S') will be
returned as the group.
*/
DefaultDlgGenerator::DefaultDlgGenerator(QObject *parent)
: QObject(parent)
{
}
QString DefaultDlgGenerator::name() const
{
return QStringLiteral("default");
}
int DefaultDlgGenerator::priority() const
{
return 0;
}
bool DefaultDlgGenerator::validForLocale(const QLocale &) const
{
return true; // this default plugin is the fallback, and always valid.
}
QStringList DefaultDlgGenerator::displayLabelGroups() const
{
static QStringList groups {
QStringLiteral("A"),
QStringLiteral("B"),
QStringLiteral("C"),
QStringLiteral("D"),
QStringLiteral("E"),
QStringLiteral("F"),
QStringLiteral("G"),
QStringLiteral("H"),
QStringLiteral("I"),
QStringLiteral("J"),
QStringLiteral("K"),
QStringLiteral("L"),
QStringLiteral("M"),
QStringLiteral("N"),
QStringLiteral("O"),
QStringLiteral("P"),
QStringLiteral("Q"),
QStringLiteral("R"),
QStringLiteral("S"),
QStringLiteral("T"),
QStringLiteral("U"),
QStringLiteral("V"),
QStringLiteral("W"),
QStringLiteral("X"),
QStringLiteral("Y"),
QStringLiteral("Z"),
QStringLiteral("#"),
QStringLiteral("?")
};
return groups;
}
QString DefaultDlgGenerator::displayLabelGroup(const QString &data) const
{
QString group;
if (!data.isEmpty()) {
QChar upperChar = data.at(0).toUpper();
ushort val = upperChar.unicode();
if (val >= 'A' && val <= 'Z') {
group = QString(upperChar);
} else if (data.at(0).isDigit()) {
group = QStringLiteral("#");
}
}
if (group.isEmpty()) {
// unknown group. put in "other" group '?'
group = QStringLiteral("?");
}
return group;
}
/*
* Copyright (C) 2019 Jolla Ltd. <chris.adams@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 DEFAULTDLGGENERATOR_H
#define DEFAULTDLGGENERATOR_H
#include <QObject>
#include <displaylabelgroupgenerator.h>