Replace wrappers in base/utils/fs.h with Profile::SpecialFolders::location()

This commit is contained in:
Eugene Shalygin
2016-05-11 13:25:29 +02:00
parent 44b6cb28f6
commit 0bf7fa15c1
9 changed files with 20 additions and 43 deletions

View File

@@ -66,6 +66,7 @@
#include <libtorrent/torrent_info.hpp>
#include "base/logger.h"
#include "base/profile.h"
#include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#include "base/net/portforwarder.h"
@@ -132,7 +133,7 @@ namespace
return tmp;
}
QString normalizeSavePath(QString path, const QString &defaultPath = Utils::Fs::QDesktopServicesDownloadLocation())
QString normalizeSavePath(QString path, const QString &defaultPath = specialFolderLocation(SpecialFolder::Downloads))
{
path = path.trimmed();
if (path.isEmpty())
@@ -266,7 +267,7 @@ Session::Session(QObject *parent)
, m_isProxyPeerConnectionsEnabled(BITTORRENT_SESSION_KEY("ProxyPeerConnections"), false)
, m_storedCategories(BITTORRENT_SESSION_KEY("Categories"))
, m_maxRatioAction(BITTORRENT_SESSION_KEY("MaxRatioAction"), Pause)
, m_defaultSavePath(BITTORRENT_SESSION_KEY("DefaultSavePath"), Utils::Fs::QDesktopServicesDownloadLocation(), normalizePath)
, m_defaultSavePath(BITTORRENT_SESSION_KEY("DefaultSavePath"), specialFolderLocation(SpecialFolder::Downloads), normalizePath)
, m_tempPath(BITTORRENT_SESSION_KEY("TempPath"), defaultSavePath() + "temp/", normalizePath)
, m_isSubcategoriesEnabled(BITTORRENT_SESSION_KEY("SubcategoriesEnabled"), false)
, m_isTempPathEnabled(BITTORRENT_SESSION_KEY("TempPathEnabled"), false)
@@ -3003,7 +3004,7 @@ bool Session::hasPerTorrentRatioLimit() const
void Session::initResumeFolder()
{
m_resumeFolderPath = Utils::Fs::expandPathAbs(Utils::Fs::QDesktopServicesDataLocation() + RESUME_FOLDER);
m_resumeFolderPath = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + RESUME_FOLDER);
QDir resumeFolderDir(m_resumeFolderPath);
if (resumeFolderDir.exists() || resumeFolderDir.mkpath(resumeFolderDir.absolutePath())) {
m_resumeFolderLock.setFileName(resumeFolderDir.absoluteFilePath("session.lock"));

View File

@@ -35,6 +35,7 @@
#include "base/logger.h"
#include "base/preferences.h"
#include "base/profile.h"
#include "base/utils/fs.h"
#include "base/utils/gzip.h"
#include "downloadmanager.h"
@@ -94,7 +95,7 @@ void GeoIPManager::loadDatabase()
}
QString filepath = Utils::Fs::expandPathAbs(
QString("%1%2/%3").arg(Utils::Fs::QDesktopServicesDataLocation())
QString("%1%2/%3").arg(specialFolderLocation(SpecialFolder::Data))
.arg(GEOIP_FOLDER).arg(GEOIP_FILENAME));
QString error;
@@ -431,7 +432,7 @@ void GeoIPManager::downloadFinished(const QString &url, QByteArray data)
.arg(m_geoIPDatabase->type()).arg(m_geoIPDatabase->buildEpoch().toString()),
Log::INFO);
QString targetPath = Utils::Fs::expandPathAbs(
Utils::Fs::QDesktopServicesDataLocation() + GEOIP_FOLDER);
specialFolderLocation(SpecialFolder::Data) + GEOIP_FOLDER);
if (!QDir(targetPath).exists())
QDir().mkpath(targetPath);
QFile targetFile(QString("%1/%2").arg(targetPath).arg(GEOIP_FILENAME));

View File

@@ -77,4 +77,10 @@ private:
QScopedPointer<Private::Profile> m_impl;
static Profile *m_instance;
};
inline QString specialFolderLocation(SpecialFolder folder)
{
return Profile::instance().location(folder);
}
#endif // QBT_PROFILE_H

View File

@@ -37,6 +37,7 @@
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/preferences.h"
#include "base/profile.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h"
#include "searchengine.h"
@@ -325,7 +326,7 @@ QString SearchEngine::engineLocation()
QString folder = "nova";
if (Utils::Misc::pythonVersion() >= 3)
folder = "nova3";
const QString location = Utils::Fs::expandPathAbs(Utils::Fs::QDesktopServicesDataLocation() + folder);
const QString location = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + folder);
QDir locationDir(location);
if (!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());

View File

@@ -50,8 +50,6 @@
#include <Windows.h>
#endif
#include "base/profile.h"
/**
* Converts a path to a string suitable for display.
* This function makes sure the directory separator used is consistent
@@ -317,30 +315,6 @@ QString Utils::Fs::expandPathAbs(const QString& path)
return ret;
}
QString Utils::Fs::QDesktopServicesDataLocation()
{
return Profile::instance().location(SpecialFolder::Data);
}
QString Utils::Fs::QDesktopServicesCacheLocation()
{
return Profile::instance().location(SpecialFolder::Cache);
}
QString Utils::Fs::QDesktopServicesDownloadLocation()
{
return Profile::instance().location(SpecialFolder::Downloads);
}
QString Utils::Fs::cacheLocation()
{
QString location = expandPathAbs(QDesktopServicesCacheLocation());
QDir locationDir(location);
if (!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
QString Utils::Fs::tempPath()
{
static const QString path = QDir::tempPath() + "/.qBittorrent/";

View File

@@ -60,13 +60,6 @@ namespace Utils
bool forceRemove(const QString& file_path);
void removeDirRecursive(const QString& dirName);
/* Ported from Qt4 to drop dependency on QtGui */
QString QDesktopServicesDataLocation();
QString QDesktopServicesCacheLocation();
QString QDesktopServicesDownloadLocation();
/* End of Qt4 code */
QString cacheLocation();
QString tempPath();
}
}