Browse Source

Provide interface for Application class

PR #16864.
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
a2b85ba1fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/app/application.cpp
  2. 126
      src/app/application.h
  3. 1
      src/base/CMakeLists.txt
  4. 1
      src/base/base.pri
  5. 65
      src/base/interfaces/iapplication.h
  6. 1
      src/gui/CMakeLists.txt
  7. 10
      src/gui/advancedsettings.cpp
  8. 1
      src/gui/gui.pri
  9. 43
      src/gui/interfaces/iguiapplication.h
  10. 6
      src/gui/optionsdialog.cpp

14
src/app/application.cpp

@ -29,8 +29,6 @@ @@ -29,8 +29,6 @@
#include "application.h"
#include <QtGlobal>
#include <algorithm>
#ifdef DISABLE_GUI
@ -82,7 +80,6 @@ @@ -82,7 +80,6 @@
#include "base/torrentfileswatcher.h"
#include "base/utils/compare.h"
#include "base/utils/fs.h"
#include "base/path.h"
#include "base/utils/misc.h"
#include "base/version.h"
#include "applicationinstancemanager.h"
@ -90,10 +87,10 @@ @@ -90,10 +87,10 @@
#ifndef DISABLE_GUI
#include "gui/addnewtorrentdialog.h"
#include "gui/uithememanager.h"
#include "gui/utils.h"
#include "gui/mainwindow.h"
#include "gui/shutdownconfirmdialog.h"
#include "gui/uithememanager.h"
#include "gui/utils.h"
#endif // DISABLE_GUI
#ifndef DISABLE_WEBUI
@ -121,12 +118,8 @@ namespace @@ -121,12 +118,8 @@ namespace
Application::Application(int &argc, char **argv)
: BaseApplication(argc, argv)
, m_running(false)
, m_shutdownAct(ShutdownDialogAction::Exit)
, m_commandLineArgs(parseCommandLine(this->arguments()))
#ifdef Q_OS_WIN
, m_storeMemoryWorkingSetLimit(SETTINGS_KEY(u"MemoryWorkingSetLimit"_qs))
#endif
, m_storeFileLoggerEnabled(FILELOGGER_SETTINGS_KEY(u"Enabled"_qs))
, m_storeFileLoggerBackup(FILELOGGER_SETTINGS_KEY(u"Backup"_qs))
, m_storeFileLoggerDeleteOld(FILELOGGER_SETTINGS_KEY(u"DeleteOld"_qs))
@ -134,6 +127,9 @@ Application::Application(int &argc, char **argv) @@ -134,6 +127,9 @@ Application::Application(int &argc, char **argv)
, m_storeFileLoggerAge(FILELOGGER_SETTINGS_KEY(u"Age"_qs))
, m_storeFileLoggerAgeType(FILELOGGER_SETTINGS_KEY(u"AgeType"_qs))
, m_storeFileLoggerPath(FILELOGGER_SETTINGS_KEY(u"Path"_qs))
#ifdef Q_OS_WIN
, m_storeMemoryWorkingSetLimit(SETTINGS_KEY(u"MemoryWorkingSetLimit"_qs))
#endif
{
qRegisterMetaType<Log::Msg>("Log::Msg");
qRegisterMetaType<Log::Peer>("Log::Peer");

126
src/app/application.h

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2022 Mike Tzou (Chocobo1)
* Copyright (C) 2015, 2019 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez
*
@ -29,31 +30,24 @@ @@ -29,31 +30,24 @@
#pragma once
#include <QtGlobal>
#include <QCoreApplication>
#include <QPointer>
#include <QStringList>
#include <QTranslator>
#ifndef DISABLE_GUI
#include <QApplication>
using BaseApplication = QApplication;
class MainWindow;
#ifdef Q_OS_WIN
class QSessionManager;
#endif // Q_OS_WIN
#else
#include <QCoreApplication>
using BaseApplication = QCoreApplication;
#endif // DISABLE_GUI
#endif
#include "base/interfaces/iapplication.h"
#include "base/path.h"
#include "base/settingvalue.h"
#include "base/types.h"
#include "cmdoptions.h"
#ifndef DISABLE_WEBUI
class WebUI;
#ifndef DISABLE_GUI
#include "gui/interfaces/iguiapplication.h"
#endif
class ApplicationInstanceManager;
@ -70,7 +64,25 @@ namespace RSS @@ -70,7 +64,25 @@ namespace RSS
class AutoDownloader;
}
class Application final : public BaseApplication
#ifndef DISABLE_GUI
class MainWindow;
using BaseApplication = QApplication;
using BaseIApplication = IGUIApplication;
#ifdef Q_OS_WIN
class QSessionManager;
#endif
#else // DISABLE_GUI
using BaseApplication = QCoreApplication;
using BaseIApplication = IApplication;
#endif // DISABLE_GUI
#ifndef DISABLE_WEBUI
class WebUI;
#endif
class Application final : public BaseApplication, public BaseIApplication
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(Application)
@ -79,42 +91,35 @@ public: @@ -79,42 +91,35 @@ public:
Application(int &argc, char **argv);
~Application() override;
bool isRunning();
int exec(const QStringList &params);
bool sendParams(const QStringList &params);
#ifndef DISABLE_GUI
QPointer<MainWindow> mainWindow();
#endif
bool isRunning();
bool sendParams(const QStringList &params);
const QBtCommandLineParameters &commandLineArgs() const;
// FileLogger properties
bool isFileLoggerEnabled() const override;
void setFileLoggerEnabled(bool value) override;
Path fileLoggerPath() const override;
void setFileLoggerPath(const Path &path) override;
bool isFileLoggerBackup() const override;
void setFileLoggerBackup(bool value) override;
bool isFileLoggerDeleteOld() const override;
void setFileLoggerDeleteOld(bool value) override;
int fileLoggerMaxSize() const override;
void setFileLoggerMaxSize(int bytes) override;
int fileLoggerAge() const override;
void setFileLoggerAge(int value) override;
int fileLoggerAgeType() const override;
void setFileLoggerAgeType(int value) override;
#ifdef Q_OS_WIN
int memoryWorkingSetLimit() const;
void setMemoryWorkingSetLimit(int size);
int memoryWorkingSetLimit() const override;
void setMemoryWorkingSetLimit(int size) override;
#endif
// FileLogger properties
bool isFileLoggerEnabled() const;
void setFileLoggerEnabled(bool value);
Path fileLoggerPath() const;
void setFileLoggerPath(const Path &path);
bool isFileLoggerBackup() const;
void setFileLoggerBackup(bool value);
bool isFileLoggerDeleteOld() const;
void setFileLoggerDeleteOld(bool value);
int fileLoggerMaxSize() const;
void setFileLoggerMaxSize(int bytes);
int fileLoggerAge() const;
void setFileLoggerAge(int value);
int fileLoggerAgeType() const;
void setFileLoggerAgeType(int value);
protected:
#ifndef DISABLE_GUI
#ifdef Q_OS_MACOS
bool event(QEvent *) override;
#endif
QPointer<MainWindow> mainWindow() override;
#endif
private slots:
@ -122,32 +127,31 @@ private slots: @@ -122,32 +127,31 @@ private slots:
void torrentFinished(BitTorrent::Torrent *const torrent);
void allTorrentsFinished();
void cleanup();
#if (!defined(DISABLE_GUI) && defined(Q_OS_WIN))
void shutdownCleanup(QSessionManager &manager);
#endif
private:
#ifdef Q_OS_WIN
void applyMemoryWorkingSetLimit();
#endif
void initializeTranslation();
void processParams(const QStringList &params);
void runExternalProgram(const BitTorrent::Torrent *torrent) const;
void sendNotificationEmail(const BitTorrent::Torrent *torrent);
ApplicationInstanceManager *m_instanceManager = nullptr;
bool m_running;
ShutdownDialogAction m_shutdownAct;
QBtCommandLineParameters m_commandLineArgs;
#ifdef Q_OS_WIN
void applyMemoryWorkingSetLimit();
#endif
#ifndef DISABLE_GUI
QPointer<MainWindow> m_window;
#ifdef Q_OS_MACOS
bool event(QEvent *) override;
#endif
#ifndef DISABLE_WEBUI
WebUI *m_webui = nullptr;
#endif
ApplicationInstanceManager *m_instanceManager = nullptr;
bool m_running = false;
ShutdownDialogAction m_shutdownAct;
QBtCommandLineParameters m_commandLineArgs;
// FileLog
QPointer<FileLogger> m_fileLogger;
@ -155,9 +159,6 @@ private: @@ -155,9 +159,6 @@ private:
QTranslator m_translator;
QStringList m_paramsQueue;
#ifdef Q_OS_WIN
SettingValue<int> m_storeMemoryWorkingSetLimit;
#endif
SettingValue<bool> m_storeFileLoggerEnabled;
SettingValue<bool> m_storeFileLoggerBackup;
SettingValue<bool> m_storeFileLoggerDeleteOld;
@ -165,4 +166,15 @@ private: @@ -165,4 +166,15 @@ private:
SettingValue<int> m_storeFileLoggerAge;
SettingValue<int> m_storeFileLoggerAgeType;
SettingValue<Path> m_storeFileLoggerPath;
#ifdef Q_OS_WIN
SettingValue<int> m_storeMemoryWorkingSetLimit;
#endif
#ifndef DISABLE_GUI
QPointer<MainWindow> m_window;
#endif
#ifndef DISABLE_WEBUI
WebUI *m_webui = nullptr;
#endif
};

1
src/base/CMakeLists.txt

@ -51,6 +51,7 @@ add_library(qbt_base STATIC @@ -51,6 +51,7 @@ add_library(qbt_base STATIC
http/types.h
iconprovider.h
indexrange.h
interfaces/iapplication.h
interfaces/istringable.h
logger.h
net/dnsupdater.h

1
src/base/base.pri

@ -50,6 +50,7 @@ HEADERS += \ @@ -50,6 +50,7 @@ HEADERS += \
$$PWD/http/types.h \
$$PWD/iconprovider.h \
$$PWD/indexrange.h \
$$PWD/interfaces/iapplication.h \
$$PWD/interfaces/istringable.h \
$$PWD/logger.h \
$$PWD/net/dnsupdater.h \

65
src/base/interfaces/iapplication.h

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2022 Mike Tzou (Chocobo1)
* Copyright (C) 2015, 2019 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include <QtGlobal>
class QString;
class Path;
struct QBtCommandLineParameters;
class IApplication
{
public:
virtual ~IApplication() = default;
// FileLogger properties
virtual bool isFileLoggerEnabled() const = 0;
virtual void setFileLoggerEnabled(bool value) = 0;
virtual Path fileLoggerPath() const = 0;
virtual void setFileLoggerPath(const Path &path) = 0;
virtual bool isFileLoggerBackup() const = 0;
virtual void setFileLoggerBackup(bool value) = 0;
virtual bool isFileLoggerDeleteOld() const = 0;
virtual void setFileLoggerDeleteOld(bool value) = 0;
virtual int fileLoggerMaxSize() const = 0;
virtual void setFileLoggerMaxSize(int bytes) = 0;
virtual int fileLoggerAge() const = 0;
virtual void setFileLoggerAge(int value) = 0;
virtual int fileLoggerAgeType() const = 0;
virtual void setFileLoggerAgeType(int value) = 0;
#ifdef Q_OS_WIN
virtual int memoryWorkingSetLimit() const = 0;
virtual void setMemoryWorkingSetLimit(int size) = 0;
#endif
};

1
src/gui/CMakeLists.txt

@ -50,6 +50,7 @@ add_library(qbt_gui STATIC @@ -50,6 +50,7 @@ add_library(qbt_gui STATIC
fspathedit.h
fspathedit_p.h
hidabletabwidget.h
interfaces/iguiapplication.h
ipsubnetwhitelistoptionsdialog.h
lineedit.h
log/logfiltermodel.h

10
src/gui/advancedsettings.cpp

@ -39,9 +39,9 @@ @@ -39,9 +39,9 @@
#include "base/global.h"
#include "base/preferences.h"
#include "base/unicodestrings.h"
#include "app/application.h"
#include "gui/addnewtorrentdialog.h"
#include "gui/mainwindow.h"
#include "interfaces/iguiapplication.h"
namespace
{
@ -200,7 +200,7 @@ void AdvancedSettings::saveAdvancedSettings() @@ -200,7 +200,7 @@ void AdvancedSettings::saveAdvancedSettings()
}
session->setOSMemoryPriority(prio);
static_cast<Application *>(QCoreApplication::instance())->setMemoryWorkingSetLimit(m_spinBoxMemoryWorkingSetLimit.value());
dynamic_cast<IApplication *>(QCoreApplication::instance())->setMemoryWorkingSetLimit(m_spinBoxMemoryWorkingSetLimit.value());
#endif
// Async IO threads
session->setAsyncIOThreads(m_spinBoxAsyncIOThreads.value());
@ -292,7 +292,7 @@ void AdvancedSettings::saveAdvancedSettings() @@ -292,7 +292,7 @@ void AdvancedSettings::saveAdvancedSettings()
// Stop tracker timeout
session->setStopTrackerTimeout(m_spinBoxStopTrackerTimeout.value());
// Program notification
MainWindow *const mainWindow = static_cast<Application*>(QCoreApplication::instance())->mainWindow();
MainWindow *mainWindow = dynamic_cast<IGUIApplication *>(QCoreApplication::instance())->mainWindow();
mainWindow->setNotificationsEnabled(m_checkBoxProgramNotifications.isChecked());
mainWindow->setTorrentAddedNotificationsEnabled(m_checkBoxTorrentAddedNotifications.isChecked());
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
@ -449,7 +449,7 @@ void AdvancedSettings::loadAdvancedSettings() @@ -449,7 +449,7 @@ void AdvancedSettings::loadAdvancedSettings()
m_spinBoxMemoryWorkingSetLimit.setMinimum(1);
m_spinBoxMemoryWorkingSetLimit.setMaximum(std::numeric_limits<int>::max());
m_spinBoxMemoryWorkingSetLimit.setSuffix(tr(" MiB"));
m_spinBoxMemoryWorkingSetLimit.setValue(static_cast<Application *>(QCoreApplication::instance())->memoryWorkingSetLimit());
m_spinBoxMemoryWorkingSetLimit.setValue(dynamic_cast<IApplication *>(QCoreApplication::instance())->memoryWorkingSetLimit());
addRow(MEMORY_WORKING_SET_LIMIT, (tr("Physical memory (RAM) usage limit")
+ u' ' + makeLink(u"https://wikipedia.org/wiki/Working_set", u"(?)"))
@ -694,7 +694,7 @@ void AdvancedSettings::loadAdvancedSettings() @@ -694,7 +694,7 @@ void AdvancedSettings::loadAdvancedSettings()
, &m_spinBoxStopTrackerTimeout);
// Program notifications
const MainWindow *const mainWindow = static_cast<Application*>(QCoreApplication::instance())->mainWindow();
const MainWindow *mainWindow = dynamic_cast<IGUIApplication *>(QCoreApplication::instance())->mainWindow();
m_checkBoxProgramNotifications.setChecked(mainWindow->isNotificationsEnabled());
addRow(PROGRAM_NOTIFICATIONS, tr("Display notifications"), &m_checkBoxProgramNotifications);
// Torrent added notifications

1
src/gui/gui.pri

@ -17,6 +17,7 @@ HEADERS += \ @@ -17,6 +17,7 @@ HEADERS += \
$$PWD/fspathedit.h \
$$PWD/fspathedit_p.h \
$$PWD/hidabletabwidget.h \
$$PWD/interfaces/iguiapplication.h \
$$PWD/ipsubnetwhitelistoptionsdialog.h \
$$PWD/lineedit.h \
$$PWD/log/logfiltermodel.h \

43
src/gui/interfaces/iguiapplication.h

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2022 Mike Tzou (Chocobo1)
* Copyright (C) 2015, 2019 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include "base/interfaces/iapplication.h"
class MainWindow;
class IGUIApplication : public IApplication
{
public:
virtual ~IGUIApplication() = default;
virtual QPointer<MainWindow> mainWindow() = 0;
};

6
src/gui/optionsdialog.cpp

@ -61,8 +61,8 @@ @@ -61,8 +61,8 @@
#include "base/utils/random.h"
#include "addnewtorrentdialog.h"
#include "advancedsettings.h"
#include "app/application.h"
#include "banlistoptionsdialog.h"
#include "interfaces/iguiapplication.h"
#include "ipsubnetwhitelistoptionsdialog.h"
#include "rss/automatedrssdownloader.h"
#include "ui_optionsdialog.h"
@ -719,7 +719,7 @@ void OptionsDialog::saveOptions() @@ -719,7 +719,7 @@ void OptionsDialog::saveOptions()
#endif
session->setPerformanceWarningEnabled(m_ui->checkBoxPerformanceWarning->isChecked());
auto *const app = static_cast<Application *>(QCoreApplication::instance());
auto *app = dynamic_cast<IApplication *>(QCoreApplication::instance());
app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024);
@ -969,7 +969,7 @@ void OptionsDialog::loadOptions() @@ -969,7 +969,7 @@ void OptionsDialog::loadOptions()
#endif
m_ui->checkBoxPerformanceWarning->setChecked(session->isPerformanceWarningEnabled());
const Application *const app = static_cast<Application*>(QCoreApplication::instance());
const auto *app = dynamic_cast<IApplication *>(QCoreApplication::instance());
m_ui->checkFileLog->setChecked(app->isFileLoggerEnabled());
m_ui->textFileLogPath->setSelectedPath(app->fileLoggerPath());
const bool fileLogBackup = app->isFileLoggerBackup();

Loading…
Cancel
Save