diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-22 09:31:10 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-11-22 16:53:57 +0900 |
commit | 7f6dec0676123629d2cdf9da7640c1e17566ed3d (patch) | |
tree | f404d3e572651146c7f30aa2cb2ab1d8f696d494 | |
parent | f9dccac588f2aa1c809018c0c5eb606a1470d2c5 (diff) | |
download | libquotient-7f6dec0676123629d2cdf9da7640c1e17566ed3d.tar.gz libquotient-7f6dec0676123629d2cdf9da7640c1e17566ed3d.zip |
Generalise and expose cacheLocation()
-rw-r--r-- | lib/avatar.cpp | 12 | ||||
-rw-r--r-- | lib/util.cpp | 14 | ||||
-rw-r--r-- | lib/util.h | 6 |
3 files changed, 21 insertions, 11 deletions
diff --git a/lib/avatar.cpp b/lib/avatar.cpp index b8e1096d..c0ef3cba 100644 --- a/lib/avatar.cpp +++ b/lib/avatar.cpp @@ -190,18 +190,8 @@ bool Avatar::Private::checkUrl(const QUrl& url) const return _imageSource != Banned; } -QString cacheLocation() { - const auto cachePath = - QStandardPaths::writableLocation(QStandardPaths::CacheLocation) - + "/avatar/"; - QDir dir; - if (!dir.exists(cachePath)) - dir.mkpath(cachePath); - return cachePath; -} - QString Avatar::Private::localFile() const { - static const auto cachePath = cacheLocation(); + static const auto cachePath = cacheLocation("avatars"); return cachePath % _url.authority() % '_' % _url.fileName() % ".png"; } diff --git a/lib/util.cpp b/lib/util.cpp index 1773fcfe..5266af1e 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -19,6 +19,9 @@ #include "util.h" #include <QtCore/QRegularExpression> +#include <QtCore/QStandardPaths> +#include <QtCore/QDir> +#include <QtCore/QStringBuilder> static const auto RegExpOptions = QRegularExpression::CaseInsensitiveOption @@ -61,3 +64,14 @@ QString QMatrixClient::prettyPrint(const QString& plainText) linkifyUrls(pt); return pt; } + +QString QMatrixClient::cacheLocation(const QString& dirName) +{ + const auto cachePath = + QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + % '/' % dirName % '/'; + QDir dir; + if (!dir.exists(cachePath)) + dir.mkpath(cachePath); + return cachePath; +} @@ -240,5 +240,11 @@ namespace QMatrixClient * This includes HTML escaping of <,>,",& and URLs linkification. */ QString prettyPrint(const QString& plainText); + + /** Return a path to cache directory after making sure that it exists + * The returned path has a trailing slash, clients don't need to append it. + * \param dir path to cache directory relative to the standard cache path + */ + QString cacheLocation(const QString& dirName); } // namespace QMatrixClient |