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:
parent
d2fe222b89
commit
665a6c4e3d
|
@ -166,7 +166,6 @@ AppManager::AppManager(int argc, char** argv)
|
||||||
, messageBoxManager(new MessageBoxManager(nullptr))
|
, messageBoxManager(new MessageBoxManager(nullptr))
|
||||||
, settings(new Settings(*messageBoxManager))
|
, settings(new Settings(*messageBoxManager))
|
||||||
, ipc(new IPC(settings->getCurrentProfileId()))
|
, ipc(new IPC(settings->getCurrentProfileId()))
|
||||||
, toxSave(new ToxSave(*settings, *ipc))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,15 +391,14 @@ int AppManager::run()
|
||||||
if (ipc->isAttached()) {
|
if (ipc->isAttached()) {
|
||||||
// Start to accept Inter-process communication
|
// Start to accept Inter-process communication
|
||||||
ipc->registerEventHandler("uri", &toxURIEventHandler, uriDialog.get());
|
ipc->registerEventHandler("uri", &toxURIEventHandler, uriDialog.get());
|
||||||
ipc->registerEventHandler(ToxSave::eventHandlerKey, &ToxSave::toxSaveEventHandler, toxSave.get());
|
nexus.registerIpcHandlers();
|
||||||
nexus.registerActivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event was not handled by already running instance therefore we handle it ourselves
|
// Event was not handled by already running instance therefore we handle it ourselves
|
||||||
if (eventType == "uri") {
|
if (eventType == "uri") {
|
||||||
uriDialog->handleToxURI(firstParam);
|
uriDialog->handleToxURI(firstParam);
|
||||||
} else if (eventType == ToxSave::eventHandlerKey) {
|
} else if (eventType == ToxSave::eventHandlerKey) {
|
||||||
toxSave->handleToxSave(firstParam);
|
nexus.handleToxSave(firstParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(qapp.get(), &QApplication::aboutToQuit, this, &AppManager::cleanup);
|
connect(qapp.get(), &QApplication::aboutToQuit, this, &AppManager::cleanup);
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
|
|
||||||
class MessageBoxManager;
|
class MessageBoxManager;
|
||||||
class Settings;
|
class Settings;
|
||||||
class ToxSave;
|
|
||||||
class IPC;
|
class IPC;
|
||||||
class QApplication;
|
class QApplication;
|
||||||
class ToxURIDialog;
|
class ToxURIDialog;
|
||||||
|
@ -47,6 +46,5 @@ private:
|
||||||
std::unique_ptr<MessageBoxManager> messageBoxManager;
|
std::unique_ptr<MessageBoxManager> messageBoxManager;
|
||||||
std::unique_ptr<Settings> settings;
|
std::unique_ptr<Settings> settings;
|
||||||
std::unique_ptr<IPC> ipc;
|
std::unique_ptr<IPC> ipc;
|
||||||
std::unique_ptr<ToxSave> toxSave;
|
|
||||||
std::unique_ptr<ToxURIDialog> uriDialog;
|
std::unique_ptr<ToxURIDialog> uriDialog;
|
||||||
};
|
};
|
||||||
|
|
|
@ -331,15 +331,6 @@ void Nexus::setParser(QCommandLineParser* parser_)
|
||||||
parser = 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()
|
CameraSource& Nexus::getCameraSource()
|
||||||
{
|
{
|
||||||
return *getInstance().cameraSource;
|
return *getInstance().cameraSource;
|
||||||
|
@ -355,9 +346,15 @@ void Nexus::setIpc(IPC* ipc_)
|
||||||
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
|
#ifdef Q_OS_MAC
|
||||||
|
|
|
@ -59,10 +59,9 @@ public:
|
||||||
static Nexus& getInstance();
|
static Nexus& getInstance();
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
Profile* getProfile();
|
Profile* getProfile();
|
||||||
static Widget* getDesktopGUI();
|
|
||||||
static CameraSource& getCameraSource();
|
static CameraSource& getCameraSource();
|
||||||
void registerActivate();
|
void registerIpcHandlers();
|
||||||
|
bool handleToxSave(const QString& path);
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
const QString ToxSave::eventHandlerKey = QStringLiteral("save");
|
const QString ToxSave::eventHandlerKey = QStringLiteral("save");
|
||||||
|
|
||||||
ToxSave::ToxSave(Settings& settings_, IPC& ipc_)
|
ToxSave::ToxSave(Settings& settings_, IPC& ipc_, QWidget* parent_)
|
||||||
: settings{settings_}
|
: settings{settings_}
|
||||||
, ipc{ipc_}
|
, ipc{ipc_}
|
||||||
|
, parent{parent_}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ToxSave::~ToxSave()
|
ToxSave::~ToxSave()
|
||||||
|
@ -58,6 +59,6 @@ bool ToxSave::toxSaveEventHandler(const QByteArray& eventData, void* userData)
|
||||||
*/
|
*/
|
||||||
bool ToxSave::handleToxSave(const QString& path)
|
bool ToxSave::handleToxSave(const QString& path)
|
||||||
{
|
{
|
||||||
ProfileImporter importer(settings, Nexus::getDesktopGUI());
|
ProfileImporter importer(settings, parent);
|
||||||
return importer.importProfile(path);
|
return importer.importProfile(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,12 +24,13 @@ class QByteArray;
|
||||||
class Settings;
|
class Settings;
|
||||||
class IPC;
|
class IPC;
|
||||||
class QString;
|
class QString;
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
class ToxSave
|
class ToxSave
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const static QString eventHandlerKey;
|
const static QString eventHandlerKey;
|
||||||
ToxSave(Settings& settings, IPC& ipc);
|
ToxSave(Settings& settings, IPC& ipc, QWidget* parent);
|
||||||
~ToxSave();
|
~ToxSave();
|
||||||
bool handleToxSave(const QString& path);
|
bool handleToxSave(const QString& path);
|
||||||
static bool toxSaveEventHandler(const QByteArray& eventData, void* userData);
|
static bool toxSaveEventHandler(const QByteArray& eventData, void* userData);
|
||||||
|
@ -37,4 +38,5 @@ public:
|
||||||
private:
|
private:
|
||||||
Settings& settings;
|
Settings& settings;
|
||||||
IPC& ipc;
|
IPC& ipc;
|
||||||
|
QWidget* parent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
#include "src/widget/tool/messageboxmanager.h"
|
#include "src/widget/tool/messageboxmanager.h"
|
||||||
#include "tool/removechatdialog.h"
|
#include "tool/removechatdialog.h"
|
||||||
#include "src/persistence/smileypack.h"
|
#include "src/persistence/smileypack.h"
|
||||||
|
#include "src/persistence/toxsave.h"
|
||||||
#include "src/ipc.h"
|
#include "src/ipc.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -99,6 +100,7 @@ bool tryRemoveFile(const QString& filepath)
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString activateHandlerKey("activate");
|
const QString activateHandlerKey("activate");
|
||||||
|
const QString saveHandlerKey("save");
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -162,6 +164,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou
|
||||||
, groupList(new GroupList())
|
, groupList(new GroupList())
|
||||||
, contentDialogManager(new ContentDialogManager(*friendList))
|
, contentDialogManager(new ContentDialogManager(*friendList))
|
||||||
, ipc{ipc_}
|
, ipc{ipc_}
|
||||||
|
, toxSave(new ToxSave{settings, ipc, this})
|
||||||
{
|
{
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
QString locale = settings.getTranslation();
|
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(activateHandlerKey, &toxActivateEventHandler, this);
|
||||||
|
ipc.registerEventHandler(saveHandlerKey, &ToxSave::toxSaveEventHandler, toxSave.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Widget::handleToxSave(const QString& path)
|
||||||
|
{
|
||||||
|
return toxSave->handleToxSave(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ class ContentDialogManager;
|
||||||
class FriendList;
|
class FriendList;
|
||||||
class GroupList;
|
class GroupList;
|
||||||
class IPC;
|
class IPC;
|
||||||
|
class ToxSave;
|
||||||
|
|
||||||
class Widget final : public QMainWindow
|
class Widget final : public QMainWindow
|
||||||
{
|
{
|
||||||
|
@ -154,8 +155,9 @@ public:
|
||||||
bool groupsVisible() const;
|
bool groupsVisible() const;
|
||||||
|
|
||||||
void resetIcon();
|
void resetIcon();
|
||||||
void registerActivate();
|
void registerIpcHandlers();
|
||||||
static bool toxActivateEventHandler(const QByteArray& data, void* userData);
|
static bool toxActivateEventHandler(const QByteArray& data, void* userData);
|
||||||
|
bool handleToxSave(const QString& path);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void reloadTheme();
|
void reloadTheme();
|
||||||
|
@ -400,4 +402,5 @@ private:
|
||||||
std::unique_ptr<GroupList> groupList;
|
std::unique_ptr<GroupList> groupList;
|
||||||
std::unique_ptr<ContentDialogManager> contentDialogManager;
|
std::unique_ptr<ContentDialogManager> contentDialogManager;
|
||||||
IPC& ipc;
|
IPC& ipc;
|
||||||
|
std::unique_ptr<ToxSave> toxSave;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user