diff options
author | Roman Plášil <me@rplasil.name> | 2017-08-18 14:29:06 +0800 |
---|---|---|
committer | Roman Plášil <me@rplasil.name> | 2017-08-18 14:29:06 +0800 |
commit | f3d893150f3991db2aed7a890d6156a576ae2e42 (patch) | |
tree | d080ca364cdd94a609aa11afe44e8c18554621da /connection.cpp | |
parent | 6ae8e3d78b5c4a75ca7d5ca88af730071047d148 (diff) | |
download | libquotient-f3d893150f3991db2aed7a890d6156a576ae2e42.tar.gz libquotient-f3d893150f3991db2aed7a890d6156a576ae2e42.zip |
Fix compilation for Qt 5.2.1
Diffstat (limited to 'connection.cpp')
-rw-r--r-- | connection.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/connection.cpp b/connection.cpp index 7650b4dd..4d76f7cd 100644 --- a/connection.cpp +++ b/connection.cpp @@ -59,6 +59,7 @@ class Connection::Private QString userId; SyncJob* syncJob; + QString stateSaveFile; }; Connection::Connection(const QUrl& server, QObject* parent) @@ -175,7 +176,6 @@ void Connection::sync(int timeout) void Connection::onSyncSuccess(SyncData &data) { d->data->setLastEvent(data.nextBatch()); - qInfo() << "last event " << d->data->lastEvent(); for( auto&& roomData: data.takeRoomData() ) { if ( auto* r = provideRoom(roomData.roomId) ) @@ -330,7 +330,11 @@ QByteArray Connection::generateTxnId() } QString Connection::getStateSaveFile() const { - return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/state.json"; + return d->stateSaveFile; +} + +void Connection::setStateSaveFile(const QString &path) { + d->stateSaveFile = path; } void Connection::saveState() { @@ -342,21 +346,25 @@ void Connection::saveState() { rooms[i->id()] = roomObj; } - QJsonObject rootObj{ - {"next_batch", QJsonValue(d->data->lastEvent())}, - {"presence", QJsonValue(QJsonObject())}, - {"rooms", QJsonValue({ - qMakePair(QString("leave"), QJsonValue(QJsonObject())), - qMakePair(QString("join"), QJsonValue(rooms)), - qMakePair(QString("invite"), QJsonValue(QJsonObject())) - })} - }; + QJsonObject roomObj; + roomObj["leave"] = QJsonObject(); + roomObj["join"] = rooms; + roomObj["invite"] = QJsonObject(); + + QJsonObject rootObj; + rootObj["next_batch"] = d->data->lastEvent(); + rootObj["presence"] = QJsonObject(); + rootObj["rooms"] = roomObj; + QJsonDocument doc { rootObj }; QByteArray data = doc.toJson(); - QFile outfile { getStateSaveFile() }; + QString filepath = getStateSaveFile(); + if (filepath.isEmpty()) return; + + QFile outfile { filepath }; outfile.open(QFile::WriteOnly); - qInfo() << "Writing state to file=" << outfile.fileName(); + qCDebug(MAIN) << "Writing state to file=" << outfile.fileName(); outfile.write(data.data(), data.size()); } |