aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp19
-rw-r--r--connection.h15
2 files changed, 10 insertions, 24 deletions
diff --git a/connection.cpp b/connection.cpp
index 89da47cd..97594e7d 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -61,7 +61,6 @@ class Connection::Private
QString userId;
SyncJob* syncJob;
- QUrl stateSaveFile;
};
Connection::Connection(const QUrl& server, QObject* parent)
@@ -331,17 +330,7 @@ QByteArray Connection::generateTxnId()
return d->data->generateTxnId();
}
-QUrl Connection::getStateSaveFile() const {
- return d->stateSaveFile;
-}
-
-void Connection::setStateSaveFile(const QUrl &path) {
- d->stateSaveFile = path;
-}
-
-void Connection::saveState() {
- if (getStateSaveFile().isEmpty()) return;
-
+void Connection::saveState(const QUrl &toFile) {
QJsonObject rooms;
for (auto i : this->roomMap()) {
@@ -363,7 +352,7 @@ void Connection::saveState() {
QJsonDocument doc { rootObj };
QByteArray data = doc.toJson();
- QFileInfo stateFile { getStateSaveFile().toLocalFile() };
+ QFileInfo stateFile { toFile.toLocalFile() };
QFile outfile { stateFile.absoluteFilePath() };
if (!stateFile.dir().exists()) stateFile.dir().mkpath(".");
@@ -376,8 +365,8 @@ void Connection::saveState() {
}
}
-void Connection::loadState() {
- QFile file { getStateSaveFile().toLocalFile() };
+void Connection::loadState(const QUrl &fromFile) {
+ QFile file { fromFile.toLocalFile() };
if (!file.exists()) return;
file.open(QFile::ReadOnly);
QByteArray data = file.readAll();
diff --git a/connection.h b/connection.h
index 5a5ce3ac..0265d92f 100644
--- a/connection.h
+++ b/connection.h
@@ -39,7 +39,6 @@ namespace QMatrixClient
class Connection: public QObject {
Q_OBJECT
- Q_PROPERTY(QUrl stateSaveFile READ getStateSaveFile WRITE setStateSaveFile)
public:
explicit Connection(const QUrl& server, QObject* parent = nullptr);
Connection();
@@ -85,9 +84,12 @@ namespace QMatrixClient
Q_INVOKABLE SyncJob* syncJob() const;
Q_INVOKABLE int millisToReconnect() const;
- /** call this before first sync */
- Q_INVOKABLE void loadState();
- Q_INVOKABLE void saveState();
+ /**
+ * Call this before first sync to load from previously saved file.
+ * Uses QUrl to be QML-friendly.
+ */
+ Q_INVOKABLE void loadState(const QUrl &fromFile);
+ Q_INVOKABLE void saveState(const QUrl &toFile);
template <typename JobT, typename... JobArgTs>
JobT* callApi(JobArgTs... jobArgs) const
@@ -145,11 +147,6 @@ namespace QMatrixClient
*/
virtual Room* createRoom(const QString& roomId);
- /**
- * Returns the path to file for saving state (rooms, presence, ...)
- */
- QUrl getStateSaveFile() const;
- void setStateSaveFile(const QUrl &path);
/**
* Completes loading sync data.