Implement base classes for application components

PR #17219.
This commit is contained in:
Vladimir Golovnev
2022-06-25 15:46:55 +03:00
committed by GitHub
parent 41a38428fc
commit f8a304abdc
28 changed files with 256 additions and 69 deletions

View File

@@ -37,8 +37,9 @@
#include "apierror.h"
APIController::APIController(QObject *parent)
: QObject {parent}
APIController::APIController(IApplication *app, QObject *parent)
: QObject(parent)
, ApplicationComponent(app)
{
}

View File

@@ -32,18 +32,20 @@
#include <QObject>
#include <QVariant>
#include "base/applicationcomponent.h"
class QString;
using DataMap = QHash<QString, QByteArray>;
using StringMap = QHash<QString, QString>;
class APIController : public QObject
class APIController : public QObject, public ApplicationComponent
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(APIController)
public:
explicit APIController(QObject *parent = nullptr);
explicit APIController(IApplication *app, QObject *parent = nullptr);
QVariant run(const QString &action, const StringMap &params, const DataMap &data = {});

View File

@@ -294,7 +294,7 @@ void AppController::preferencesAction()
// Advanced settings
// qBitorrent preferences
// Physical memory (RAM) usage limit
data[u"memory_working_set_limit"_qs] = dynamic_cast<IApplication *>(QCoreApplication::instance())->memoryWorkingSetLimit();
data[u"memory_working_set_limit"_qs] = app()->memoryWorkingSetLimit();
// Current network interface
data[u"current_network_interface"_qs] = session->networkInterface();
// Current network interface address
@@ -758,7 +758,7 @@ void AppController::setPreferencesAction()
// qBittorrent preferences
// Physical memory (RAM) usage limit
if (hasKey(u"memory_working_set_limit"_qs))
dynamic_cast<IApplication *>(QCoreApplication::instance())->setMemoryWorkingSetLimit(it.value().toInt());
app()->setMemoryWorkingSetLimit(it.value().toInt());
// Current network interface
if (hasKey(u"current_network_interface"_qs))
{

View File

@@ -37,8 +37,8 @@
#include "apierror.h"
#include "isessionmanager.h"
AuthController::AuthController(ISessionManager *sessionManager, QObject *parent)
: APIController {parent}
AuthController::AuthController(ISessionManager *sessionManager, IApplication *app, QObject *parent)
: APIController(app, parent)
, m_sessionManager {sessionManager}
{
}

View File

@@ -43,7 +43,7 @@ class AuthController : public APIController
Q_DISABLE_COPY_MOVE(AuthController)
public:
explicit AuthController(ISessionManager *sessionManager, QObject *parent = nullptr);
explicit AuthController(ISessionManager *sessionManager, IApplication *app, QObject *parent = nullptr);
private slots:
void loginAction();

View File

@@ -366,8 +366,8 @@ namespace
}
}
SyncController::SyncController(QObject *parent)
: APIController(parent)
SyncController::SyncController(IApplication *app, QObject *parent)
: APIController(app, parent)
{
m_freeDiskSpaceThread = new QThread(this);
m_freeDiskSpaceChecker = new FreeDiskSpaceChecker();

View File

@@ -45,7 +45,7 @@ class SyncController : public APIController
public:
using APIController::APIController;
explicit SyncController(QObject *parent = nullptr);
explicit SyncController(IApplication *app, QObject *parent = nullptr);
~SyncController() override;
private slots: