1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(Nexus): Remove Nexus::getDesktopGUI

Remove ProfileImporter's dependence on Widget, on path towards removing
Nexus singleton.
This commit is contained in:
Anthony Bilinski 2022-03-28 17:37:24 -07:00
parent d2fe222b89
commit 665a6c4e3d
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
8 changed files with 32 additions and 25 deletions

View File

@ -166,7 +166,6 @@ AppManager::AppManager(int argc, char** argv)
, messageBoxManager(new MessageBoxManager(nullptr))
, settings(new Settings(*messageBoxManager))
, ipc(new IPC(settings->getCurrentProfileId()))
, toxSave(new ToxSave(*settings, *ipc))
{
}
@ -392,15 +391,14 @@ int AppManager::run()
if (ipc->isAttached()) {
// Start to accept Inter-process communication
ipc->registerEventHandler("uri", &toxURIEventHandler, uriDialog.get());
ipc->registerEventHandler(ToxSave::eventHandlerKey, &ToxSave::toxSaveEventHandler, toxSave.get());
nexus.registerActivate();
nexus.registerIpcHandlers();
}
// Event was not handled by already running instance therefore we handle it ourselves
if (eventType == "uri") {
uriDialog->handleToxURI(firstParam);
} else if (eventType == ToxSave::eventHandlerKey) {
toxSave->handleToxSave(firstParam);
nexus.handleToxSave(firstParam);
}
connect(qapp.get(), &QApplication::aboutToQuit, this, &AppManager::cleanup);

View File

@ -25,7 +25,6 @@
class MessageBoxManager;
class Settings;
class ToxSave;
class IPC;
class QApplication;
class ToxURIDialog;
@ -47,6 +46,5 @@ private:
std::unique_ptr<MessageBoxManager> messageBoxManager;
std::unique_ptr<Settings> settings;
std::unique_ptr<IPC> ipc;
std::unique_ptr<ToxSave> toxSave;
std::unique_ptr<ToxURIDialog> uriDialog;
};

View File

@ -331,15 +331,6 @@ void Nexus::setParser(QCommandLineParser* parser_)
parser = parser_;
}
/**
* @brief Get desktop GUI widget.
* @return nullptr if not started, desktop widget otherwise.
*/
Widget* Nexus::getDesktopGUI()
{
return getInstance().widget;
}
CameraSource& Nexus::getCameraSource()
{
return *getInstance().cameraSource;
@ -355,9 +346,15 @@ void Nexus::setIpc(IPC* ipc_)
ipc = ipc_;
}
void Nexus::registerActivate()
void Nexus::registerIpcHandlers()
{
widget->registerActivate();
widget->registerIpcHandlers();
}
bool Nexus::handleToxSave(const QString& path)
{
assert(widget);
return widget->handleToxSave(path);
}
#ifdef Q_OS_MAC

View File

@ -59,10 +59,9 @@ public:
static Nexus& getInstance();
static void destroyInstance();
Profile* getProfile();
static Widget* getDesktopGUI();
static CameraSource& getCameraSource();
void registerActivate();
void registerIpcHandlers();
bool handleToxSave(const QString& path);
#ifdef Q_OS_MAC
public:

View File

@ -28,9 +28,10 @@
const QString ToxSave::eventHandlerKey = QStringLiteral("save");
ToxSave::ToxSave(Settings& settings_, IPC& ipc_)
ToxSave::ToxSave(Settings& settings_, IPC& ipc_, QWidget* parent_)
: settings{settings_}
, ipc{ipc_}
, parent{parent_}
{}
ToxSave::~ToxSave()
@ -58,6 +59,6 @@ bool ToxSave::toxSaveEventHandler(const QByteArray& eventData, void* userData)
*/
bool ToxSave::handleToxSave(const QString& path)
{
ProfileImporter importer(settings, Nexus::getDesktopGUI());
ProfileImporter importer(settings, parent);
return importer.importProfile(path);
}

View File

@ -24,12 +24,13 @@ class QByteArray;
class Settings;
class IPC;
class QString;
class QWidget;
class ToxSave
{
public:
const static QString eventHandlerKey;
ToxSave(Settings& settings, IPC& ipc);
ToxSave(Settings& settings, IPC& ipc, QWidget* parent);
~ToxSave();
bool handleToxSave(const QString& path);
static bool toxSaveEventHandler(const QByteArray& eventData, void* userData);
@ -37,4 +38,5 @@ public:
private:
Settings& settings;
IPC& ipc;
QWidget* parent;
};

View File

@ -81,6 +81,7 @@
#include "src/widget/tool/messageboxmanager.h"
#include "tool/removechatdialog.h"
#include "src/persistence/smileypack.h"
#include "src/persistence/toxsave.h"
#include "src/ipc.h"
namespace {
@ -99,6 +100,7 @@ bool tryRemoveFile(const QString& filepath)
}
const QString activateHandlerKey("activate");
const QString saveHandlerKey("save");
} // namespace
@ -162,6 +164,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou
, groupList(new GroupList())
, contentDialogManager(new ContentDialogManager(*friendList))
, ipc{ipc_}
, toxSave(new ToxSave{settings, ipc, this})
{
installEventFilter(this);
QString locale = settings.getTranslation();
@ -2757,7 +2760,13 @@ void Widget::formatWindowTitle(const QString& content)
}
}
void Widget::registerActivate()
void Widget::registerIpcHandlers()
{
ipc.registerEventHandler(activateHandlerKey, &toxActivateEventHandler, this);
ipc.registerEventHandler(saveHandlerKey, &ToxSave::toxSaveEventHandler, toxSave.get());
}
bool Widget::handleToxSave(const QString& path)
{
return toxSave->handleToxSave(path);
}

View File

@ -91,6 +91,7 @@ class ContentDialogManager;
class FriendList;
class GroupList;
class IPC;
class ToxSave;
class Widget final : public QMainWindow
{
@ -154,8 +155,9 @@ public:
bool groupsVisible() const;
void resetIcon();
void registerActivate();
void registerIpcHandlers();
static bool toxActivateEventHandler(const QByteArray& data, void* userData);
bool handleToxSave(const QString& path);
public slots:
void reloadTheme();
@ -400,4 +402,5 @@ private:
std::unique_ptr<GroupList> groupList;
std::unique_ptr<ContentDialogManager> contentDialogManager;
IPC& ipc;
std::unique_ptr<ToxSave> toxSave;
};