From 47b9d8dbc6455ea0c62450a14650caf62f00df90 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 28 Aug 2019 15:00:14 +0800 Subject: [PATCH 1/2] Clean up Application class constructor --- src/app/application.cpp | 25 ++++++++++--------------- src/app/application.h | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 3f7c177b9..9be3fb167 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -122,20 +122,22 @@ Application::Application(const QString &id, int &argc, char **argv) , m_running(false) , m_shutdownAct(ShutdownDialogAction::Exit) , m_commandLineArgs(parseCommandLine(this->arguments())) -#ifndef DISABLE_WEBUI - , m_webui(nullptr) -#endif { qRegisterMetaType("Log::Msg"); setApplicationName("qBittorrent"); setOrganizationDomain("qbittorrent.org"); +#if !defined(DISABLE_GUI) + setDesktopFileName("org.qbittorrent.qBittorrent"); + setAttribute(Qt::AA_UseHighDpiPixmaps, true); // opt-in to the high DPI pixmap support + setQuitOnLastWindowClosed(false); +#endif + validateCommandLineParameters(); const QString profileDir = m_commandLineArgs.portableMode ? QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(DEFAULT_PORTABLE_MODE_PROFILE_DIR) : m_commandLineArgs.profileDir; - Profile::initialize(profileDir, m_commandLineArgs.configurationName, m_commandLineArgs.relativeFastresumePaths || m_commandLineArgs.portableMode); @@ -143,24 +145,17 @@ Application::Application(const QString &id, int &argc, char **argv) SettingsStorage::initInstance(); Preferences::initInstance(); - if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value - Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort); - initializeTranslation(); -#if !defined(DISABLE_GUI) - setAttribute(Qt::AA_UseHighDpiPixmaps, true); // opt-in to the high DPI pixmap support - setQuitOnLastWindowClosed(false); - setDesktopFileName("org.qbittorrent.qBittorrent"); -#endif + if (m_commandLineArgs.webUiPort > 0) // it will be -1 when user did not set any value + Preferences::instance()->setWebUiPort(m_commandLineArgs.webUiPort); + connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup); + connect(m_instanceManager, &ApplicationInstanceManager::messageReceived, this, &Application::processMessage); #if defined(Q_OS_WIN) && !defined(DISABLE_GUI) connect(this, &QGuiApplication::commitDataRequest, this, &Application::shutdownCleanup, Qt::DirectConnection); #endif - connect(m_instanceManager, &ApplicationInstanceManager::messageReceived, this, &Application::processMessage); - connect(this, &QCoreApplication::aboutToQuit, this, &Application::cleanup); - if (isFileLoggerEnabled()) m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast(fileLoggerAgeType())); diff --git a/src/app/application.h b/src/app/application.h index 95771f6bd..50470da9c 100644 --- a/src/app/application.h +++ b/src/app/application.h @@ -130,7 +130,7 @@ private: #endif #ifndef DISABLE_WEBUI - WebUI *m_webui; + WebUI *m_webui = nullptr; #endif // FileLog From 7e0daf1663dc99639c2cd8847a51901d44e05439 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 28 Aug 2019 15:07:18 +0800 Subject: [PATCH 2/2] Setup pixmap cache in a proper place There is no need to reset the cache limit to previous value as QPixmapCache is an application wide cache. Also raise the cache size to 64MB. --- src/app/application.cpp | 25 +++++++++++++++++-------- src/gui/torrentcontentmodel.cpp | 18 ------------------ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/src/app/application.cpp b/src/app/application.cpp index 9be3fb167..2b2a3f2d9 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -33,6 +33,10 @@ #include +#ifdef DISABLE_GUI +#include +#endif + #ifdef Q_OS_WIN #include #include @@ -47,6 +51,7 @@ #ifndef DISABLE_GUI #include +#include #ifdef Q_OS_WIN #include #include @@ -54,14 +59,7 @@ #ifdef Q_OS_MAC #include #endif // Q_OS_MAC -#include "addnewtorrentdialog.h" -#include "gui/uithememanager.h" -#include "gui/utils.h" -#include "mainwindow.h" -#include "shutdownconfirmdialog.h" -#else // DISABLE_GUI -#include -#endif // DISABLE_GUI +#endif #include "base/bittorrent/session.h" #include "base/bittorrent/torrenthandle.h" @@ -85,6 +83,14 @@ #include "applicationinstancemanager.h" #include "filelogger.h" +#ifndef DISABLE_GUI +#include "addnewtorrentdialog.h" +#include "gui/uithememanager.h" +#include "gui/utils.h" +#include "mainwindow.h" +#include "shutdownconfirmdialog.h" +#endif // DISABLE_GUI + #ifndef DISABLE_WEBUI #include "webui/webui.h" #endif @@ -114,6 +120,8 @@ namespace const int MIN_FILELOG_SIZE = 1024; // 1KiB const int MAX_FILELOG_SIZE = 1000 * 1024 * 1024; // 1000MiB const int DEFAULT_FILELOG_SIZE = 65 * 1024; // 65KiB + + const int PIXMAP_CACHE_SIZE = 64 * 1024 * 1024; // 64MiB } Application::Application(const QString &id, int &argc, char **argv) @@ -131,6 +139,7 @@ Application::Application(const QString &id, int &argc, char **argv) setDesktopFileName("org.qbittorrent.qBittorrent"); setAttribute(Qt::AA_UseHighDpiPixmaps, true); // opt-in to the high DPI pixmap support setQuitOnLastWindowClosed(false); + QPixmapCache::setCacheLimit(PIXMAP_CACHE_SIZE); #endif validateCommandLineParameters(); diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index 9b4eff3dc..c36af066b 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -77,24 +77,6 @@ namespace }; #ifdef QBT_PIXMAP_CACHE_FOR_FILE_ICONS - struct Q_DECL_UNUSED PixmapCacheSetup - { - static const int PixmapCacheForIconsSize = 2 * 1024 * 1024; // 2 MiB for file icons - - PixmapCacheSetup() - { - QPixmapCache::setCacheLimit(QPixmapCache::cacheLimit() + PixmapCacheForIconsSize); - } - - ~PixmapCacheSetup() - { - Q_ASSERT(QPixmapCache::cacheLimit() > PixmapCacheForIconsSize); - QPixmapCache::setCacheLimit(QPixmapCache::cacheLimit() - PixmapCacheForIconsSize); - } - }; - - PixmapCacheSetup pixmapCacheSetup; - class CachingFileIconProvider : public UnifiedFileIconProvider { public: