aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-04-13 20:32:08 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-04-13 20:33:00 +0900
commit139a6743a4e7a3b2e380d4f3e8f43558bc3164fa (patch)
tree7bf5321a78d731299d68973316a1843c0d238f85
parentbf1dc1484ad5aefd5b86f7f79f23f5d6fc9b940a (diff)
downloadlibquotient-139a6743a4e7a3b2e380d4f3e8f43558bc3164fa.tar.gz
libquotient-139a6743a4e7a3b2e380d4f3e8f43558bc3164fa.zip
Support Qt 5.4
That is until ubports move to xenial.
-rw-r--r--CMakeLists.txt2
-rw-r--r--lib/connection.cpp8
-rw-r--r--lib/connection.h6
-rw-r--r--lib/room.cpp8
-rw-r--r--lib/room.h6
5 files changed, 19 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dae8b287..93cb16fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,7 +40,7 @@ foreach (FLAG all "" pedantic extra error=return-type no-unused-parameter no-gnu
endif ()
endforeach ()
-find_package(Qt5 5.5.1 REQUIRED Network Gui)
+find_package(Qt5 5.4.1 REQUIRED Network Gui)
get_filename_component(Qt5_Prefix "${Qt5_DIR}/../../../.." ABSOLUTE)
message( STATUS )
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 600ab396..241fa43d 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -84,7 +84,7 @@ class Connection::Private
QVector<QString> roomIdsToForget;
QMap<QString, User*> userMap;
DirectChatsMap directChats;
- QHash<QString, QVariantHash> accountData;
+ QHash<QString, AccountDataMap> accountData;
QString userId;
SyncJob* syncJob = nullptr;
@@ -336,7 +336,7 @@ void Connection::onSyncSuccess(SyncData &&data) {
continue;
}
d->accountData[accountEvent->jsonType()] =
- accountEvent->contentJson().toVariantHash();
+ fromJson<AccountDataMap>(accountEvent->contentJson());
emit accountDataChanged(accountEvent->jsonType());
}
}
@@ -657,7 +657,7 @@ bool Connection::hasAccountData(const QString& type) const
return d->accountData.contains(type);
}
-QVariantHash Connection::accountData(const QString& type) const
+Connection::AccountDataMap Connection::accountData(const QString& type) const
{
return d->accountData.value(type);
}
@@ -909,7 +909,7 @@ void Connection::saveState(const QUrl &toFile) const
for (auto it = d->accountData.begin(); it != d->accountData.end(); ++it)
accountDataEvents.append(QJsonObject {
{"type", it.key()},
- {"content", QJsonObject::fromVariantHash(it.value())}
+ {"content", QMatrixClient::toJson(it.value())}
});
rootObj.insert("account_data",
QJsonObject {{ QStringLiteral("events"), accountDataEvents }});
diff --git a/lib/connection.h b/lib/connection.h
index be414931..839371ef 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -66,6 +66,10 @@ namespace QMatrixClient
using DirectChatsMap = QMultiHash<const User*, QString>;
+ using AccountDataMap = std::conditional_t<
+ QT_VERSION >= QT_VERSION_CHECK(5, 5, 0),
+ QVariantHash, QVariantMap>;
+
enum RoomVisibility { PublishRoom, UnpublishRoom }; // FIXME: Should go inside CreateRoomJob
explicit Connection(QObject* parent = nullptr);
@@ -88,7 +92,7 @@ namespace QMatrixClient
* stored on the server. Direct chats map cannot be retrieved
* using this method _yet_; use directChats() instead.
*/
- QVariantHash accountData(const QString& type) const;
+ AccountDataMap accountData(const QString& type) const;
/** Get all Invited and Joined rooms grouped by tag
* \return a hashmap from tag name to a vector of room pointers,
diff --git a/lib/room.cpp b/lib/room.cpp
index edbc9266..42d63574 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -109,7 +109,7 @@ class Room::Private
QHash<const User*, QString> lastReadEventIds;
QString serverReadMarker;
TagsMap tags;
- QHash<QString, QVariantHash> accountData;
+ QHash<QString, AccountDataMap> accountData;
QString prevBatch;
QPointer<RoomMessagesJob> roomMessagesJob;
@@ -637,7 +637,7 @@ bool Room::hasAccountData(const QString& type) const
return d->accountData.contains(type);
}
-QVariantHash Room::accountData(const QString& type) const
+Room::AccountDataMap Room::accountData(const QString& type) const
{
return d->accountData.value(type);
}
@@ -1653,7 +1653,7 @@ void Room::processAccountDataEvent(EventPtr event)
}
default:
d->accountData[event->jsonType()] =
- event->contentJson().toVariantHash();
+ fromJson<AccountDataMap>(event->contentJson());
emit accountDataChanged(event->jsonType());
}
}
@@ -1816,7 +1816,7 @@ QJsonObject Room::Private::toJson() const
{
for (auto it = accountData.begin(); it != accountData.end(); ++it)
appendEvent(accountDataEvents, it.key(),
- QJsonObject::fromVariantHash(it.value()));
+ QMatrixClient::toJson(it.value()));
}
result.insert("account_data", QJsonObject {{ "events", accountDataEvents }});
diff --git a/lib/room.h b/lib/room.h
index 39dee8f5..86a7b245 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -123,6 +123,10 @@ namespace QMatrixClient
using rev_iter_t = Timeline::const_reverse_iterator;
using timeline_iter_t = Timeline::const_iterator;
+ using AccountDataMap = std::conditional_t<
+ QT_VERSION >= QT_VERSION_CHECK(5, 5, 0),
+ QVariantHash, QVariantMap>;
+
Room(Connection* connection, QString id, JoinState initialJoinState);
~Room() override;
@@ -269,7 +273,7 @@ namespace QMatrixClient
* stored on the server. Tags and read markers cannot be retrieved
* using this method _yet_.
*/
- QVariantHash accountData(const QString& type) const;
+ AccountDataMap accountData(const QString& type) const;
QStringList tagNames() const;
TagsMap tags() const;