Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow build with qt6 #10

Merged
merged 1 commit into from Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.pri
@@ -1,3 +1,3 @@
CONFIG += link_pkgconfig

PKGCONFIG += Qt5Contacts Qt5Versit qtcontacts-sqlite-qt5-extensions
PKGCONFIG += Qt$${QT_MAJOR_VERSION}Contacts Qt$${QT_MAJOR_VERSION}Versit qtcontacts-sqlite-qt$${QT_MAJOR_VERSION}-extensions
8 changes: 4 additions & 4 deletions lib/lib.pri
Expand Up @@ -3,21 +3,21 @@ include(../config.pri)
CONFIG += qt hide_symbols
CONFIG += link_pkgconfig

packagesExist(mlite5) {
PKGCONFIG += mlite5
packagesExist(mlite$${QT_MAJOR_VERSION}) {
PKGCONFIG += mlite$${QT_MAJOR_VERSION}
DEFINES += HAS_MLITE
} else {
warning("mlite not available. Some functionality may not work as expected.")
}
PKGCONFIG += mlocale5 mce
PKGCONFIG += mlocale$${QT_MAJOR_VERSION} mce
LIBS += -lphonenumber


# We need access to QtContacts private headers
QT += contacts-private

# We need the moc output for ContactManagerEngine from sqlite-extensions
extensionsIncludePath = $$system(pkg-config --cflags-only-I qtcontacts-sqlite-qt5-extensions)
extensionsIncludePath = $$system(pkg-config --cflags-only-I qtcontacts-sqlite-qt$${QT_MAJOR_VERSION}-extensions)
VPATH += $$replace(extensionsIncludePath, -I, )
HEADERS += \
contactmanagerengine.h \
Expand Down
5 changes: 3 additions & 2 deletions lib/lib.pro
Expand Up @@ -3,7 +3,7 @@ include(lib.pri)
TEMPLATE = lib

# 'contacts' is too generic for the target name - use 'contactcache'
TARGET = contactcache-qt5
TARGET = contactcache-qt$${QT_MAJOR_VERSION}
target.path = $$[QT_INSTALL_LIBS]
INSTALLS += target

Expand All @@ -12,6 +12,7 @@ DEFINES += CONTACTCACHE_BUILD
CONFIG += create_pc create_prl no_install_prl

QT -= gui
QT += core

develheaders.path = /usr/include/$$TARGET
develheaders.files = $$PUBLIC_HEADERS
Expand All @@ -21,7 +22,7 @@ QMAKE_PKGCONFIG_DESCRIPTION = Sailfish OS contact cache library
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$develheaders.path
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5Contacts Qt5Versit qtcontacts-sqlite-qt5-extensions
QMAKE_PKGCONFIG_REQUIRES = Qt$${QT_MAJOR_VERSION}Core Qt$${QT_MAJOR_VERSION}Contacts Qt$${QT_MAJOR_VERSION}Versit qtcontacts-sqlite-qt$${QT_MAJOR_VERSION}-extensions
QMAKE_PKGCONFIG_VERSION = $$VERSION

INSTALLS += develheaders
17 changes: 17 additions & 0 deletions lib/seasidecache.cpp
Expand Up @@ -1243,7 +1243,11 @@ void SeasideCache::decomposeDisplayLabel(const QString &formattedDisplayLabel, Q

// Try to parse the structure from the formatted name
// TODO: Use MBreakIterator for localized splitting
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringList tokens(formattedDisplayLabel.split(QChar::fromLatin1(' '), Qt::SkipEmptyParts));
#else
QStringList tokens(formattedDisplayLabel.split(QChar::fromLatin1(' '), QString::SkipEmptyParts));
#endif
if (tokens.count() >= 2) {
QString format;
if (tokens.count() == 2) {
Expand Down Expand Up @@ -1863,7 +1867,11 @@ void SeasideCache::startRequest(bool *idleProcessing)
} else {
// Fetch the constituent information (even if they're already in the
// cache, because we don't update non-aggregates on change notifications)
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
m_fetchByIdRequest.setIds(m_constituentIds.values());
#else
m_fetchByIdRequest.setIds(m_constituentIds.toList());
#endif
m_fetchByIdRequest.start();

m_fetchByIdProcessedCount = 0;
Expand Down Expand Up @@ -2523,7 +2531,11 @@ void SeasideCache::contactsAvailable()
if (contacts.isEmpty())
return;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QSet<QContactDetail::DetailType> queryDetailTypes = QSet<QContactDetail::DetailType>(detailTypesHint(fetchHint).begin(), detailTypesHint(fetchHint).end());
#else
QSet<QContactDetail::DetailType> queryDetailTypes = detailTypesHint(fetchHint).toSet();
#endif

if (request == &m_fetchRequest && m_populating) {
Q_ASSERT(m_populateProgress > Unpopulated && m_populateProgress < Populated);
Expand Down Expand Up @@ -3050,7 +3062,12 @@ void SeasideCache::addressRequestStateChanged(QContactAbstractRequest::State sta

// results are complete, so record them in the cache
QContactFetchRequest *request = static_cast<QContactFetchRequest *>(sender());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QSet<QContactDetail::DetailType> queryDetailTypes = QSet<QContactDetail::DetailType>(detailTypesHint(request->fetchHint()).begin()
, detailTypesHint(request->fetchHint()).end());
#else
QSet<QContactDetail::DetailType> queryDetailTypes = detailTypesHint(request->fetchHint()).toSet();
#endif
applyContactUpdates(request->contacts(), queryDetailTypes);

// now figure out which address was being resolved and resolve it
Expand Down
8 changes: 8 additions & 0 deletions lib/seasidepropertyhandler.cpp
Expand Up @@ -156,7 +156,11 @@ void processOnlineAccount(const QVersitProperty &property, bool *alreadyProcesse
const QString detail(property.variantValue().toString());

// The format is: URI/path/display-name/icon-path/service-provider/service-provider-display-name
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QStringList details(detail.split(QLatin1Char(';'), Qt::KeepEmptyParts));
#else
const QStringList details(detail.split(QLatin1Char(';'), QString::KeepEmptyParts));
#endif
if (details.count() == 6) {
QContactOnlineAccount qcoa;

Expand All @@ -171,7 +175,11 @@ void processOnlineAccount(const QVersitProperty &property, bool *alreadyProcesse
updatedDetails->append(qcoa);

// Since it is a demo account, give it a random presence state
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const int state = (rand() % 4);
#else
const int state = (qrand() % 4);
#endif
QContactPresence presence;
presence.setPresenceState(state == 3 ? QContactPresence::PresenceBusy : (state == 2 ? QContactPresence::PresenceAway : QContactPresence::PresenceAvailable));
presence.setLinkedDetailUris(QStringList() << qcoa.detailUri());
Expand Down
2 changes: 2 additions & 0 deletions src/plugin.cpp
Expand Up @@ -93,7 +93,9 @@ class Q_DECL_EXPORT NemoContactsPlugin : public QQmlExtensionPlugin
qmlRegisterType<SeasideFilteredModel>(uri, 1, 0, "PeopleModel");
qmlRegisterType<SeasideAddressBookModel>(uri, 1, 0, "AddressBookModel");
qmlRegisterType<SeasideDisplayLabelGroupModel>(uri, 1, 0, "PeopleDisplayLabelGroupModel");
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qmlRegisterType<SeasidePersonAttached>();
#endif
qmlRegisterType<SeasidePerson>(uri, 1, 0, "Person");
qmlRegisterType<SeasideVCardModel>(uri, 1, 0, "PeopleVCardModel");
qmlRegisterType<SeasideConstituentModel>(uri, 1, 0, "ConstituentModel");
Expand Down
11 changes: 9 additions & 2 deletions src/seasideconstituentmodel.h
Expand Up @@ -35,7 +35,12 @@
#include "seasidesimplecontactmodel.h"

class SeasidePerson;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#ifndef DECLARE_SEASIDE_PERSON
#define DECLARE_SEASIDE_PERSON
Q_DECLARE_OPAQUE_POINTER(SeasidePerson)
#endif
#endif
QTCONTACTS_USE_NAMESPACE

class SeasideConstituentModel : public SeasideSimpleContactModel
Expand Down Expand Up @@ -65,5 +70,7 @@ class SeasideConstituentModel : public SeasideSimpleContactModel
SeasidePerson *m_person = nullptr;
SeasideCache::CacheItem *m_cacheItem = nullptr;
};

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Q_MOC_INCLUDE("seasideperson.h")
#endif
#endif
11 changes: 9 additions & 2 deletions src/seasidefilteredmodel.cpp
Expand Up @@ -491,10 +491,13 @@ struct FilterData : public SeasideCache::ItemListener

static const QChar *cbegin(const QString &s) { return s.cbegin(); }
static const QChar *cend(const QString &s) { return s.cend(); }

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
static const QChar *cbegin(const QStringView &r) { return r.data(); }
static const QChar *cend(const QStringView &r) { return r.data() + r.size(); }
#else
static const QChar *cbegin(const QStringRef &r) { return r.data(); }
static const QChar *cend(const QStringRef &r) { return r.data() + r.size(); }

#endif
template<typename KeyType>
static bool partialMatch(const KeyType &key, const QChar * const vbegin, const QChar * const vend)
{
Expand Down Expand Up @@ -559,7 +562,11 @@ struct FilterData : public SeasideCache::ItemListener
const QChar initialChar(*vbegin);
int index = -1;
while ((index = token.indexOf(initialChar, index + 1)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (partialMatch(QStringView(token).mid(index), vbegin, vend)) {
#else
if (partialMatch(token.midRef(index), vbegin, vend)) {
#endif
return true;
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/seasidemergecandidatemodel.h
Expand Up @@ -35,7 +35,12 @@
#include "seasidesimplecontactmodel.h"

class SeasidePerson;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#ifndef DECLARE_SEASIDE_PERSON
#define DECLARE_SEASIDE_PERSON
Q_DECLARE_OPAQUE_POINTER(SeasidePerson)
#endif
#endif
QTCONTACTS_USE_NAMESPACE

class SeasideMergeCandidateModel : public SeasideSimpleContactModel
Expand Down Expand Up @@ -65,5 +70,7 @@ class SeasideMergeCandidateModel : public SeasideSimpleContactModel
SeasidePerson *m_person = nullptr;
SeasideCache::CacheItem *m_cacheItem = nullptr;
};

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Q_MOC_INCLUDE("seasideperson.h")
#endif
#endif
9 changes: 8 additions & 1 deletion src/seasideperson.cpp
Expand Up @@ -463,7 +463,11 @@ QString SeasidePerson::department() const
void SeasidePerson::setDepartment(const QString &department)
{
QStringList dept;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
foreach (const QString &field, department.split(QChar::fromLatin1(';'), Qt::SkipEmptyParts)) {
#else
foreach (const QString &field, department.split(QChar::fromLatin1(';'), QString::SkipEmptyParts)) {
#endif
dept.append(field.trimmed());
}

Expand Down Expand Up @@ -2306,8 +2310,11 @@ QStringList SeasidePerson::avatarUrlsExcluding(const QStringList &excludeMetadat

urls.insert(avatar.imageUrl().toString());
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return urls.values();
#else
return urls.toList();
#endif
}

/*!
Expand Down
5 changes: 5 additions & 0 deletions src/seasidesimplecontactmodel.cpp
Expand Up @@ -133,8 +133,13 @@ void SeasideSimpleContactModel::updateOrReset(const QList<int> &newContactIds)
currentContactIds.append(contactInfo.cacheItem->iid);
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QSet<int> currentIdSet = QSet<int>(currentContactIds.begin(), currentContactIds.end());
const QSet<int> newIdSet = QSet<int>(newContactIds.begin(), newContactIds.end());
#else
const QSet<int> currentIdSet = currentContactIds.toSet();
const QSet<int> newIdSet = newContactIds.toSet();
#endif

if (currentIdSet == newIdSet) {
return;
Expand Down
3 changes: 2 additions & 1 deletion src/seasidevcardmodel.cpp
Expand Up @@ -257,12 +257,13 @@ void SeasideVCardModel::readContacts()
if (vcf.open(QIODevice::ReadOnly)) {
// TODO: thread
QVersitReader reader(&vcf);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (!mDefaultCodec.isEmpty()) {
QTextCodec *codec = QTextCodec::codecForName(mDefaultCodec.toLatin1());
rainemak marked this conversation as resolved.
Show resolved Hide resolved
if (codec)
reader.setDefaultCodec(codec);
}
#endif

reader.startReading();
reader.waitForFinished();
Expand Down
8 changes: 4 additions & 4 deletions src/src.pro
Expand Up @@ -9,17 +9,17 @@ CONFIG += qt plugin hide_symbols
QT = \
core \
qml
PKGCONFIG += mlocale5 accounts-qt5
PKGCONFIG += mlocale$${QT_MAJOR_VERSION} accounts-qt$${QT_MAJOR_VERSION}

packagesExist(mlite5) {
PKGCONFIG += mlite5
packagesExist(mlite$${QT_MAJOR_VERSION}) {
PKGCONFIG += mlite$${QT_MAJOR_VERSION}
DEFINES += HAS_MLITE
} else {
warning("mlite not available. Some functionality may not work as expected.")
}

INCLUDEPATH += ../lib
LIBS += -L../lib -lcontactcache-qt5
LIBS += -L../lib -lcontactcache-qt$${QT_MAJOR_VERSION}

target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
INSTALLS += target
Expand Down
2 changes: 1 addition & 1 deletion tests/basename.pri
@@ -1 +1 @@
BASENAME=nemo-qml-plugins-qt5
BASENAME=nemo-qml-plugins-qt$${QT_MAJOR_VERSION}
2 changes: 1 addition & 1 deletion tests/common.pri
Expand Up @@ -9,7 +9,7 @@ QT += testlib qml
SRCDIR = $$PWD/../src/
INCLUDEPATH += $$SRCDIR $$PWD/../lib/
DEPENDPATH += $$INCLUDEPATH
LIBS += -L$$PWD/../lib -lcontactcache-qt5
LIBS += -L$$PWD/../lib -L../../lib -lcontactcache-qt$${QT_MAJOR_VERSION}

target.path = /opt/tests/$${BASENAME}/contacts
INSTALLS += target
@@ -1,6 +1,6 @@
include(../common.pri)

PKGCONFIG += mlocale5
PKGCONFIG += mlocale$${QT_MAJOR_VERSION}

CONFIG += c++11

Expand Down
17 changes: 17 additions & 0 deletions tests/tst_seasideperson/tst_seasideperson.cpp
Expand Up @@ -678,7 +678,11 @@ void tst_SeasidePerson::birthday()
QCOMPARE(spy.count(), 2);
QCOMPARE(person->birthday(), QDateTime());
QCOMPARE(person->property("birthday").toDateTime(), person->birthday());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
person->setBirthday(QDateTime(QDate::fromString("05/01/1980", "dd/MM/yyyy").startOfDay()));
#else
person->setBirthday(QDateTime(QDate::fromString("05/01/1980", "dd/MM/yyyy")));
#endif
QCOMPARE(spy.count(), 3);
QCOMPARE(person->birthday(), QDateTime::fromString("05/01/1980 12:00:00.000", "dd/MM/yyyy hh:mm:ss.zzz"));
QCOMPARE(person->property("birthday").toDateTime(), person->birthday());
Expand Down Expand Up @@ -1084,7 +1088,11 @@ void tst_SeasidePerson::removeDuplicatePhoneNumbers()
const QVariantMap detail(item.value<QVariantMap>());
resultList.append(detail.value(phoneDetailNumber).toString());
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QCOMPARE(QSet<QString>(resultList.begin(), resultList.end()), expectedSet);
#else
QCOMPARE(resultList.toSet(), expectedSet);
#endif
}
}

Expand Down Expand Up @@ -1132,7 +1140,12 @@ void tst_SeasidePerson::removeDuplicateOnlineAccounts()
const QString path(detail.value(accountDetailPath).toString());
resultList.append(qMakePair(uri, path));
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QSet<QPair<QString, QString> > resultSet = QSet<QPair<QString, QString> > (resultList.begin(), resultList.end());
QCOMPARE(resultSet, expected);
#else
QCOMPARE(resultList.toSet(), expected);
#endif
}
}

Expand Down Expand Up @@ -1175,7 +1188,11 @@ void tst_SeasidePerson::removeDuplicateEmailAddresses()
const QString addr(detail.value(emailDetailAddress).toString().trimmed().toLower());
resultList.append(addr);
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QCOMPARE(QSet<QString>(resultList.begin(), resultList.end()), expected);
#else
QCOMPARE(resultList.toSet(), expected);
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/common.pri
Expand Up @@ -5,4 +5,4 @@ CONFIG -= app_bundle

INCLUDEPATH += $$PWD/../src/ $$PWD/../lib/
DEPENDPATH += $$INCLUDEPATH
LIBS += -L$$PWD/../lib -lcontactcache-qt5
LIBS += -L$$PWD/../lib -L../../lib -lcontactcache-qt$${QT_MAJOR_VERSION}