mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-23 14:26:12 +03:00
core,ui: Add FileManager::cacheLocation() helper
This commit is contained in:
parent
26da8bef6e
commit
18de7a1b5d
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user