From c18a591b484db451eb084ec4f1f17057813800df Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 12 Jun 2021 20:51:17 +0200 Subject: Adjust to new moc/QMetaType requirements See https://www.qt.io/blog/whats-new-in-qmetatype-qvariant#qmetatype-knows-your-properties-and-methods-types --- lib/connection.cpp | 3 +++ lib/room.cpp | 3 +++ 2 files changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/connection.cpp b/lib/connection.cpp index 55067bb7..b3006084 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -14,6 +14,9 @@ #include "settings.h" #include "user.h" +// NB: since Qt 6, moc_connection.cpp needs Room and User fully defined +#include "moc_connection.cpp" + #include "csapi/account-data.h" #include "csapi/capabilities.h" #include "csapi/joining.h" diff --git a/lib/room.cpp b/lib/room.cpp index fadcea17..abaf50b7 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -16,6 +16,9 @@ #include "syncdata.h" #include "user.h" +// NB: since Qt 6, moc_room.cpp needs User fully defined +#include "moc_room.cpp" + #include "csapi/account-data.h" #include "csapi/banning.h" #include "csapi/inviting.h" -- cgit v1.2.3 From ff171e91877048f132955abaa617a26c63632bdf Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 12 Jun 2021 20:56:41 +0200 Subject: connection.cpp: erase_if -> remove_if erase_if is now also provided by Qt; doing pretty much the same thing, the Qt implementation only returns the number of removed entries instead of returning a collection of them, however. Worth admitting at this point that the function in connection.cpp has never had the semantics of STL's erase_if() and doesn't quite have the semantics of remove_if() either; but at least it's closer to remove_if(). --- lib/connection.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/connection.cpp b/lib/connection.cpp index b3006084..e076957a 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -58,7 +58,7 @@ using namespace Quotient; // This is very much Qt-specific; STL iterators don't have key() and value() template -HashT erase_if(HashT& hashMap, Pred pred) +HashT remove_if(HashT& hashMap, Pred pred) { HashT removals; for (auto it = hashMap.begin(); it != hashMap.end();) { @@ -668,16 +668,16 @@ void Connection::Private::consumeAccountData(Events&& accountDataEvents) // https://github.com/quotient-im/libQuotient/wiki/Handling-direct-chat-events const auto& usersToDCs = dce.usersToDirectChats(); DirectChatsMap remoteRemovals = - erase_if(directChats, [&usersToDCs, this](auto it) { + remove_if(directChats, [&usersToDCs, this](auto it) { return !( usersToDCs.contains(it.key()->id(), it.value()) || dcLocalAdditions.contains(it.key(), it.value())); }); - erase_if(directChatUsers, [&remoteRemovals](auto it) { + remove_if(directChatUsers, [&remoteRemovals](auto it) { return remoteRemovals.contains(it.value(), it.key()); }); // Remove from dcLocalRemovals what the server already has. - erase_if(dcLocalRemovals, [&remoteRemovals](auto it) { + remove_if(dcLocalRemovals, [&remoteRemovals](auto it) { return remoteRemovals.contains(it.key(), it.value()); }); if (MAIN().isDebugEnabled()) @@ -705,7 +705,7 @@ void Connection::Private::consumeAccountData(Events&& accountDataEvents) << "Couldn't get a user object for" << it.key(); } // Remove from dcLocalAdditions what the server already has. - erase_if(dcLocalAdditions, [&remoteAdditions](auto it) { + remove_if(dcLocalAdditions, [&remoteAdditions](auto it) { return remoteAdditions.contains(it.key(), it.value()); }); if (!remoteAdditions.isEmpty() || !remoteRemovals.isEmpty()) @@ -1388,7 +1388,7 @@ void Connection::removeFromDirectChats(const QString& roomId, User* user) removals.insert(user, roomId); d->dcLocalRemovals.insert(user, roomId); } else { - removals = erase_if(d->directChats, + removals = remove_if(d->directChats, [&roomId](auto it) { return it.value() == roomId; }); d->directChatUsers.remove(roomId); d->dcLocalRemovals += removals; -- cgit v1.2.3 From 84d6295f859ee600d7aa3860767030bdc78914ba Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 12 Jun 2021 20:57:54 +0200 Subject: uri.cpp, room.*: Get rid of QStringRefs --- lib/room.cpp | 8 ++++++-- lib/room.h | 2 +- lib/uri.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/room.cpp b/lib/room.cpp index abaf50b7..c314fc72 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -2962,12 +2962,16 @@ bool MemberSorter::operator()(User* u1, User* u2) const return operator()(u1, room->disambiguatedMemberName(u2->id())); } -bool MemberSorter::operator()(User* u1, const QString& u2name) const +bool MemberSorter::operator()(User* u1, QStringView u2name) const { auto n1 = room->disambiguatedMemberName(u1->id()); if (n1.startsWith('@')) n1.remove(0, 1); - auto n2 = u2name.midRef(u2name.startsWith('@') ? 1 : 0); + const auto n2 = u2name.mid(u2name.startsWith('@') ? 1 : 0) +#if QT_VERSION_MAJOR < 6 + .toString() // Qt 5 doesn't have QStringView::localeAwareCompare +#endif + ; return n1.localeAwareCompare(n2) < 0; } diff --git a/lib/room.h b/lib/room.h index a8275ce9..26d0121e 100644 --- a/lib/room.h +++ b/lib/room.h @@ -754,7 +754,7 @@ public: explicit MemberSorter(const Room* r) : room(r) {} bool operator()(User* u1, User* u2) const; - bool operator()(User* u1, const QString& u2name) const; + bool operator()(User* u1, QStringView u2name) const; template typename ContT::size_type lowerBoundIndex(const ContT& c, const ValT& v) const diff --git a/lib/uri.cpp b/lib/uri.cpp index 291bfcae..d8624796 100644 --- a/lib/uri.cpp +++ b/lib/uri.cpp @@ -70,7 +70,7 @@ static QString pathSegment(const QUrl& url, int which) encodedPath(url).section('/', which, which).toUtf8()); } -static auto decodeFragmentPart(const QStringRef& part) +static auto decodeFragmentPart(QStringView part) { return QUrl::fromPercentEncoding(part.toLatin1()).toUtf8(); } @@ -98,7 +98,7 @@ Uri::Uri(QUrl url) : QUrl(std::move(url)) if (scheme() == "matrix") { // Check sanity as per https://github.com/matrix-org/matrix-doc/pull/2312 const auto& urlPath = encodedPath(*this); - const auto& splitPath = urlPath.splitRef('/'); + const auto& splitPath = urlPath.split('/'); switch (splitPath.size()) { case 2: break; @@ -128,9 +128,9 @@ Uri::Uri(QUrl url) : QUrl(std::move(url)) // so force QUrl to decode everything. auto f = fragment(QUrl::EncodeUnicode); if (auto&& m = MatrixToUrlRE.match(f); m.hasMatch()) - *this = Uri { decodeFragmentPart(m.capturedRef("main")), - decodeFragmentPart(m.capturedRef("sec")), - decodeFragmentPart(m.capturedRef("query")) }; + *this = Uri { decodeFragmentPart(m.capturedView(u"main")), + decodeFragmentPart(m.capturedView(u"sec")), + decodeFragmentPart(m.capturedView(u"query")) }; } } -- cgit v1.2.3 From 620c2fe55b327e555477ed29bd670ddc6b9023d1 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 12 Jun 2021 21:01:38 +0200 Subject: Make RequestData compile again This fixes reliance on QIODevice being magically available for std::unique_ptr<> by indirect inclusion. Since Qt 6 this inclusion no more happens, time to #include explicitly. --- lib/jobs/requestdata.cpp | 5 +++++ lib/jobs/requestdata.h | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/jobs/requestdata.cpp b/lib/jobs/requestdata.cpp index 047e2920..2c001ccc 100644 --- a/lib/jobs/requestdata.cpp +++ b/lib/jobs/requestdata.cpp @@ -3,6 +3,7 @@ #include "requestdata.h" +#include #include #include #include @@ -31,4 +32,8 @@ RequestData::RequestData(const QJsonObject& jo) : _source(fromJson(jo)) {} RequestData::RequestData(const QJsonArray& ja) : _source(fromJson(ja)) {} +RequestData::RequestData(QIODevice* source) + : _source(std::unique_ptr(source)) +{} + RequestData::~RequestData() = default; diff --git a/lib/jobs/requestdata.h b/lib/jobs/requestdata.h index 4958e0f9..21657631 100644 --- a/lib/jobs/requestdata.h +++ b/lib/jobs/requestdata.h @@ -24,8 +24,7 @@ public: RequestData(const QByteArray& a = {}); RequestData(const QJsonObject& jo); RequestData(const QJsonArray& ja); - RequestData(QIODevice* source) : _source(std::unique_ptr(source)) - {} + RequestData(QIODevice* source); RequestData(RequestData&&) = default; RequestData& operator=(RequestData&&) = default; ~RequestData(); -- cgit v1.2.3 From 67ea5b45701e6bd5bf244039dc60a134d67a4cab Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 13 Jun 2021 14:08:52 +0200 Subject: Disable the piece depending on Qt Multimedia for Qt 6 Waiting for the Multimedia arrival in Qt 6.2. --- lib/events/roommessageevent.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index 31c0fd9e..3f6e475d 100644 --- a/lib/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp @@ -10,7 +10,9 @@ #include #include #include -#include +#if QT_VERSION_MAJOR < 6 +# include +#endif using namespace Quotient; using namespace EventContent; @@ -149,7 +151,11 @@ TypedBase* contentFromFile(const QFileInfo& file, bool asGenericFile) // done by starting to play the file. Left for a future implementation. if (mimeTypeName.startsWith("video/")) return new VideoContent(localUrl, file.size(), mimeType, +#if QT_VERSION_MAJOR < 6 QMediaResource(localUrl).resolution(), +#else + {}, +#endif file.fileName()); if (mimeTypeName.startsWith("audio/")) -- cgit v1.2.3 From b8a78fe7a2370697eea4517ab000130fe1180715 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 13 Jun 2021 14:10:47 +0200 Subject: Exclude code no more needed with Qt6 --- lib/converters.h | 4 +++- lib/settings.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/converters.h b/lib/converters.h index e07b6ee4..af6c0192 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -221,14 +221,16 @@ template struct JsonConverter> : public JsonArrayConverter> {}; +#if QT_VERSION_MAJOR < 6 // QVector is an alias of QList in Qt6 but not in Qt 5 template struct JsonConverter> : public JsonArrayConverter> {}; +#endif template struct JsonConverter> : public JsonArrayConverter> {}; template <> -struct JsonConverter : public JsonConverter> { +struct JsonConverter : public JsonArrayConverter { static auto dump(const QStringList& sl) { return QJsonArray::fromStringList(sl); diff --git a/lib/settings.cpp b/lib/settings.cpp index 703f4320..1d36db27 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -21,7 +21,9 @@ void Settings::setLegacyNames(const QString& organizationName, Settings::Settings(QObject* parent) : QSettings(parent) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) setIniCodec("UTF-8"); +#endif } void Settings::setValue(const QString& key, const QVariant& value) -- cgit v1.2.3 From beb3a135a336dca654d967b88ea06a7457fbbec1 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 12 Jun 2021 22:31:25 +0200 Subject: EncryptionEvent: fix "too perfect forwarding" Now that QMetaType introspects into types, it reveals hidden problems (which is very nice of it). --- lib/events/encryptionevent.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h index f9bbab12..65ee4187 100644 --- a/lib/events/encryptionevent.h +++ b/lib/events/encryptionevent.h @@ -40,6 +40,7 @@ public: // default value : StateEvent(typeId(), obj) {} + EncryptionEvent(EncryptionEvent&&) = delete; template EncryptionEvent(ArgTs&&... contentArgs) : StateEvent(typeId(), matrixTypeId(), QString(), -- cgit v1.2.3 From faf0122db53e4d010ec1f9f00f40feedd6786e71 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sat, 12 Jun 2021 22:43:33 +0200 Subject: Uri: Fix ambiguity around QChar constructors QChar now accepts more types for construction, and that unraveled concatenation of a Type/SecondaryType character with a QString. To fix it, give the compiler a hint by casting to the enum's underlying type (which also nicely documents that we _actually_ switch from enum to character type). --- lib/uri.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/uri.cpp b/lib/uri.cpp index d8624796..c8843dda 100644 --- a/lib/uri.cpp +++ b/lib/uri.cpp @@ -186,14 +186,18 @@ QString Uri::primaryId() const if (primaryType_ == Empty || primaryType_ == Invalid) return {}; - const auto& idStem = pathSegment(*this, 1); - return idStem.isEmpty() ? idStem : primaryType_ + idStem; + auto idStem = pathSegment(*this, 1); + if (!idStem.isEmpty()) + idStem.push_front(char(primaryType_)); + return idStem; } QString Uri::secondaryId() const { - const auto& idStem = pathSegment(*this, 3); - return idStem.isEmpty() ? idStem : secondaryType() + idStem; + auto idStem = pathSegment(*this, 3); + if (!idStem.isEmpty()) + idStem.push_front(char(secondaryType())); + return idStem; } static const auto ActionKey = QStringLiteral("action"); -- cgit v1.2.3 From 55845602abf09bc5ccee2032a21b95b245d3cedd Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 13 Jun 2021 14:23:46 +0200 Subject: BaseJob: FollowRedirectsAttribute -> RedirectPolicyAttribute The latter obsoleted the former since Qt 5.9, actually. --- lib/jobs/basejob.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 48c2996d..c27c6a89 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -288,7 +288,8 @@ void BaseJob::Private::sendRequest() req.setRawHeader("Authorization", QByteArray("Bearer ") + connection->accessToken()); req.setAttribute(QNetworkRequest::BackgroundRequestAttribute, inBackground); - req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); + req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, + QNetworkRequest::NoLessSafeRedirectPolicy); req.setMaximumRedirectsAllowed(10); req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); req.setAttribute( -- cgit v1.2.3