core,ui: Add FileManager::cacheLocation() helper

This commit is contained in:
Oleg Shparber 2018-01-21 01:55:20 +02:00
parent 26da8bef6e
commit 18de7a1b5d
3 changed files with 20 additions and 12 deletions

View File

@ -22,9 +22,13 @@
#include "filemanager.h"
#include <QCoreApplication>
#include <QDateTime>
#include <QDir>
#include <QFileInfo>
#include <QFutureWatcher>
#include <QLoggingCategory>
#include <QStandardPaths>
#include <QtConcurrent>
@ -35,6 +39,9 @@ static Q_LOGGING_CATEGORY(log, "zeal.core.filemanager")
FileManager::FileManager(QObject *parent)
: QObject(parent)
{
// Ensure that cache location exists.
// TODO: Check for errors.
QDir().mkpath(cacheLocation());
}
bool FileManager::removeRecursively(const QString &path)
@ -74,3 +81,12 @@ bool FileManager::removeRecursively(const QString &path)
return true;
}
QString FileManager::cacheLocation()
{
#ifndef PORTABLE_BUILD
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
#else
const QDir cacheDir(QCoreApplication::applicationDirPath() + QLatin1String("/cache"));
#endif
}

View File

@ -30,12 +30,13 @@ namespace Core {
class FileManager : public QObject
{
Q_OBJECT
public:
typedef unsigned int JobId;
explicit FileManager(QObject *parent = nullptr);
bool removeRecursively(const QString &path);
static QString cacheLocation();
};
} // namespace Core

View File

@ -43,7 +43,6 @@
#include <QMessageBox>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QStandardPaths>
#include <QTemporaryFile>
#include <QUrl>
@ -865,13 +864,5 @@ int DocsetsDialog::percent(qint64 fraction, qint64 total)
QString DocsetsDialog::cacheLocation(const QString &fileName)
{
#ifndef PORTABLE_BUILD
const QDir cacheDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
#else
const QDir cacheDir(QCoreApplication::applicationDirPath() + QLatin1String("/cache"));
#endif
// TODO: Report error
QDir().mkpath(cacheDir.path());
return cacheDir.filePath(fileName);
return QDir(Core::FileManager::cacheLocation()).filePath(fileName);
}