aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp16
-rw-r--r--lib/connection.h28
2 files changed, 31 insertions, 13 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index fa358e17..d75d8e56 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -133,6 +133,10 @@ class Connection::Private
packAndSendAccountData(
makeEvent<EventT>(std::forward<ContentT>(content)));
}
+ QString topLevelStatePath() const
+ {
+ return q->stateCacheDir().filePath("state.json");
+ }
};
Connection::Connection(const QUrl& server, QObject* parent)
@@ -1232,7 +1236,8 @@ void Connection::saveRoomState(Room* r) const
if (!d->cacheState)
return;
- QFile outRoomFile { stateCachePath() % SyncData::fileNameForRoom(r->id()) };
+ QFile outRoomFile {
+ stateCacheDir().filePath(SyncData::fileNameForRoom(r->id())) };
if (outRoomFile.open(QFile::WriteOnly))
{
QJsonDocument json { r->toJson() };
@@ -1253,7 +1258,7 @@ void Connection::saveState() const
QElapsedTimer et; et.start();
- QFile outFile { stateCachePath() % "state.json" };
+ QFile outFile { d->topLevelStatePath() };
if (!outFile.open(QFile::WriteOnly))
{
qCWarning(MAIN) << "Error opening" << outFile.fileName()
@@ -1313,7 +1318,7 @@ void Connection::loadState()
QElapsedTimer et; et.start();
- SyncData sync { stateCachePath() % "state.json" };
+ SyncData sync { d->topLevelStatePath() };
if (sync.nextBatch().isEmpty()) // No token means no cache by definition
return;
@@ -1331,6 +1336,11 @@ void Connection::loadState()
QString Connection::stateCachePath() const
{
+ return stateCacheDir().path() % '/';
+}
+
+QDir Connection::stateCacheDir() const
+{
auto safeUserId = userId();
safeUserId.replace(':', '_');
return cacheLocation(safeUserId);
diff --git a/lib/connection.h b/lib/connection.h
index 42e678ff..2ff27ea6 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -26,6 +26,7 @@
#include <QtCore/QObject>
#include <QtCore/QUrl>
#include <QtCore/QSize>
+#include <QtCore/QDir>
#include <functional>
#include <memory>
@@ -305,8 +306,8 @@ namespace QMatrixClient
* Call this before first sync to load from previously saved file.
*
* \param fromFile A local path to read the state from. Uses QUrl
- * to be QML-friendly. Empty parameter means using a path
- * defined by stateCachePath().
+ * to be QML-friendly. Empty parameter means saving to the directory
+ * defined by stateCachePath() / stateCacheDir().
*/
Q_INVOKABLE void loadState();
/**
@@ -315,23 +316,30 @@ namespace QMatrixClient
* loadState() on a next run of the client.
*
* \param toFile A local path to save the state to. Uses QUrl to be
- * QML-friendly. Empty parameter means using a path defined by
- * stateCachePath().
+ * QML-friendly. Empty parameter means saving to the directory
+ * defined by stateCachePath() / stateCacheDir().
*/
Q_INVOKABLE void saveState() const;
/// This method saves the current state of a single room.
void saveRoomState(Room* r) const;
+ /// Get the default directory path to save the room state to
+ /** \sa stateCacheDir */
+ Q_INVOKABLE QString stateCachePath() const;
+
+ /// Get the default directory to save the room state to
/**
- * The default path to store the cached room state, defined as
- * follows:
+ * This function returns the default directory to store the cached
+ * room state, defined as follows:
+ * \code
* QStandardPaths::writeableLocation(QStandardPaths::CacheLocation) + _safeUserId + "_state.json"
- * where `_safeUserId` is userId() with `:` (colon) replaced with
- * `_` (underscore)
- * /see loadState(), saveState()
+ * \endcode
+ * where `_safeUserId` is userId() with `:` (colon) replaced by
+ * `_` (underscore), as colons are reserved characters on Windows.
+ * \sa loadState, saveState, stateCachePath
*/
- Q_INVOKABLE QString stateCachePath() const;
+ QDir stateCacheDir() const;
bool cacheState() const;
void setCacheState(bool newValue);