diff --git a/src/app/application.cpp b/src/app/application.cpp index 60fbefb41..ee000292a 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -174,7 +174,8 @@ void Application::setFileLoggerEnabled(bool value) QString Application::fileLoggerPath() const { - return settings()->loadValue(KEY_FILELOGGER_PATH, QVariant(Utils::Fs::QDesktopServicesDataLocation() + LOG_FOLDER)).toString(); + return settings()->loadValue(KEY_FILELOGGER_PATH, + QVariant(specialFolderLocation(SpecialFolder::Data) + LOG_FOLDER)).toString(); } void Application::setFileLoggerPath(const QString &value) diff --git a/src/app/upgrade.h b/src/app/upgrade.h index e23eade51..40c720f4d 100644 --- a/src/app/upgrade.h +++ b/src/app/upgrade.h @@ -148,7 +148,7 @@ bool upgrade(bool ask = true) // Upgrade preferences Preferences::instance()->upgrade(); - QString backupFolderPath = Utils::Fs::expandPathAbs(Utils::Fs::QDesktopServicesDataLocation() + "BT_backup"); + QString backupFolderPath = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + "BT_backup"); QDir backupFolderDir(backupFolderPath); // **************************************************************************************** diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 2497ef2a6..c94683956 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -66,6 +66,7 @@ #include #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")); diff --git a/src/base/net/geoipmanager.cpp b/src/base/net/geoipmanager.cpp index 990c2f48c..19c74455d 100644 --- a/src/base/net/geoipmanager.cpp +++ b/src/base/net/geoipmanager.cpp @@ -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)); diff --git a/src/base/profile.h b/src/base/profile.h index 5ea304ab9..72fed6eb2 100644 --- a/src/base/profile.h +++ b/src/base/profile.h @@ -77,4 +77,10 @@ private: QScopedPointer m_impl; static Profile *m_instance; }; + +inline QString specialFolderLocation(SpecialFolder folder) +{ + return Profile::instance().location(folder); +} + #endif // QBT_PROFILE_H diff --git a/src/base/searchengine.cpp b/src/base/searchengine.cpp index 88e922c7e..df86e2312 100644 --- a/src/base/searchengine.cpp +++ b/src/base/searchengine.cpp @@ -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()); diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index e0d1298b2..eca53876d 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -50,8 +50,6 @@ #include #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/"; diff --git a/src/base/utils/fs.h b/src/base/utils/fs.h index 3ee9fec5a..56320c1dc 100644 --- a/src/base/utils/fs.h +++ b/src/base/utils/fs.h @@ -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(); } } diff --git a/src/gui/rss/htmlbrowser.cpp b/src/gui/rss/htmlbrowser.cpp index 82ea75821..e378b0405 100644 --- a/src/gui/rss/htmlbrowser.cpp +++ b/src/gui/rss/htmlbrowser.cpp @@ -10,14 +10,14 @@ #include #include -#include "base/utils/fs.h" +#include "base/profile.h" HtmlBrowser::HtmlBrowser(QWidget* parent) : QTextBrowser(parent) { m_netManager = new QNetworkAccessManager(this); m_diskCache = new QNetworkDiskCache(this); - m_diskCache->setCacheDirectory(QDir::cleanPath(Utils::Fs::cacheLocation() + "/rss")); + m_diskCache->setCacheDirectory(QDir::cleanPath(specialFolderLocation(SpecialFolder::Cache) + "/rss")); m_diskCache->setMaximumCacheSize(50 * 1024 * 1024); qDebug() << "HtmlBrowser cache path:" << m_diskCache->cacheDirectory() << " max size:" << m_diskCache->maximumCacheSize() / 1024 / 1024 << "MB"; m_netManager->setCache(m_diskCache);