mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(Nexus): Remove Nexus::getCore
It relies on singleton state, instead just pass core to classes that need it.
This commit is contained in:
parent
2d6cc25405
commit
c6ee8d0654
|
@ -278,19 +278,6 @@ void Nexus::destroyInstance()
|
||||||
nexus = nullptr;
|
nexus = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get core instance.
|
|
||||||
* @return nullptr if not started, core instance otherwise.
|
|
||||||
*/
|
|
||||||
Core* Nexus::getCore()
|
|
||||||
{
|
|
||||||
Nexus& nexus_ = getInstance();
|
|
||||||
if (!nexus_.profile)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
return &nexus_.profile->getCore();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get current user profile.
|
* @brief Get current user profile.
|
||||||
* @return nullptr if not started, profile otherwise.
|
* @return nullptr if not started, profile otherwise.
|
||||||
|
|
|
@ -56,7 +56,6 @@ public:
|
||||||
void setParser(QCommandLineParser* parser_);
|
void setParser(QCommandLineParser* parser_);
|
||||||
static Nexus& getInstance();
|
static Nexus& getInstance();
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
static Core* getCore();
|
|
||||||
static Profile* getProfile();
|
static Profile* getProfile();
|
||||||
static Widget* getDesktopGUI();
|
static Widget* getDesktopGUI();
|
||||||
static CameraSource& getCameraSource();
|
static CameraSource& getCameraSource();
|
||||||
|
|
|
@ -62,11 +62,12 @@ namespace
|
||||||
*/
|
*/
|
||||||
|
|
||||||
AddFriendForm::AddFriendForm(ToxId ownId_, Settings& settings_, Style& style_,
|
AddFriendForm::AddFriendForm(ToxId ownId_, Settings& settings_, Style& style_,
|
||||||
IMessageBoxManager& messageBoxManager_)
|
IMessageBoxManager& messageBoxManager_, Core& core_)
|
||||||
: ownId{ownId_}
|
: ownId{ownId_}
|
||||||
, settings{settings_}
|
, settings{settings_}
|
||||||
, style{style_}
|
, style{style_}
|
||||||
, messageBoxManager{messageBoxManager_}
|
, messageBoxManager{messageBoxManager_}
|
||||||
|
, core{core_}
|
||||||
{
|
{
|
||||||
tabWidget = new QTabWidget();
|
tabWidget = new QTabWidget();
|
||||||
main = new QWidget(tabWidget);
|
main = new QWidget(tabWidget);
|
||||||
|
@ -112,7 +113,7 @@ AddFriendForm::AddFriendForm(ToxId ownId_, Settings& settings_, Style& style_,
|
||||||
connect(&sendButton, &QPushButton::clicked, this, &AddFriendForm::onSendTriggered);
|
connect(&sendButton, &QPushButton::clicked, this, &AddFriendForm::onSendTriggered);
|
||||||
connect(&importSendButton, &QPushButton::clicked, this, &AddFriendForm::onImportSendClicked);
|
connect(&importSendButton, &QPushButton::clicked, this, &AddFriendForm::onImportSendClicked);
|
||||||
connect(&importFileButton, &QPushButton::clicked, this, &AddFriendForm::onImportOpenClicked);
|
connect(&importFileButton, &QPushButton::clicked, this, &AddFriendForm::onImportOpenClicked);
|
||||||
connect(Nexus::getCore(), &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
|
connect(&core, &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
|
||||||
|
|
||||||
// accessibility stuff
|
// accessibility stuff
|
||||||
toxIdLabel.setAccessibleDescription(
|
toxIdLabel.setAccessibleDescription(
|
||||||
|
|
|
@ -36,6 +36,7 @@ class ContentLayout;
|
||||||
class Settings;
|
class Settings;
|
||||||
class Style;
|
class Style;
|
||||||
class IMessageBoxManager;
|
class IMessageBoxManager;
|
||||||
|
class Core;
|
||||||
|
|
||||||
class AddFriendForm : public QObject
|
class AddFriendForm : public QObject
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
AddFriendForm(ToxId ownId_, Settings& settings, Style& style,
|
AddFriendForm(ToxId ownId_, Settings& settings, Style& style,
|
||||||
IMessageBoxManager& messageBoxManager);
|
IMessageBoxManager& messageBoxManager, Core& core);
|
||||||
AddFriendForm(const AddFriendForm&) = delete;
|
AddFriendForm(const AddFriendForm&) = delete;
|
||||||
AddFriendForm& operator=(const AddFriendForm&) = delete;
|
AddFriendForm& operator=(const AddFriendForm&) = delete;
|
||||||
~AddFriendForm();
|
~AddFriendForm();
|
||||||
|
@ -120,4 +121,5 @@ private:
|
||||||
Settings& settings;
|
Settings& settings;
|
||||||
Style& style;
|
Style& style;
|
||||||
IMessageBoxManager& messageBoxManager;
|
IMessageBoxManager& messageBoxManager;
|
||||||
|
Core& core;
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,13 +45,14 @@
|
||||||
* @brief This form contains all group invites you received
|
* @brief This form contains all group invites you received
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GroupInviteForm::GroupInviteForm(Settings& settings_)
|
GroupInviteForm::GroupInviteForm(Settings& settings_, Core& core_)
|
||||||
: headWidget(new QWidget(this))
|
: headWidget(new QWidget(this))
|
||||||
, headLabel(new QLabel(this))
|
, headLabel(new QLabel(this))
|
||||||
, createButton(new QPushButton(this))
|
, createButton(new QPushButton(this))
|
||||||
, inviteBox(new QGroupBox(this))
|
, inviteBox(new QGroupBox(this))
|
||||||
, scroll(new QScrollArea(this))
|
, scroll(new QScrollArea(this))
|
||||||
, settings{settings_}
|
, settings{settings_}
|
||||||
|
, core{core_}
|
||||||
{
|
{
|
||||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||||
connect(createButton, &QPushButton::clicked,
|
connect(createButton, &QPushButton::clicked,
|
||||||
|
@ -124,7 +125,8 @@ bool GroupInviteForm::addGroupInvite(const GroupInvite& inviteInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupInviteWidget* widget = new GroupInviteWidget(this, inviteInfo, settings);
|
GroupInviteWidget* widget = new GroupInviteWidget(this, inviteInfo, settings,
|
||||||
|
core);
|
||||||
scroll->widget()->layout()->addWidget(widget);
|
scroll->widget()->layout()->addWidget(widget);
|
||||||
invites.append(widget);
|
invites.append(widget);
|
||||||
connect(widget, &GroupInviteWidget::accepted, [this] (const GroupInvite& inviteInfo_) {
|
connect(widget, &GroupInviteWidget::accepted, [this] (const GroupInvite& inviteInfo_) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ class QPushButton;
|
||||||
class QScrollArea;
|
class QScrollArea;
|
||||||
class QSignalMapper;
|
class QSignalMapper;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
class Core;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
@ -40,7 +41,7 @@ class GroupInviteForm : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GroupInviteForm(Settings& settings);
|
GroupInviteForm(Settings& settings, Core& core);
|
||||||
~GroupInviteForm();
|
~GroupInviteForm();
|
||||||
|
|
||||||
void show(ContentLayout* contentLayout);
|
void show(ContentLayout* contentLayout);
|
||||||
|
@ -67,4 +68,5 @@ private:
|
||||||
QList<GroupInviteWidget*> invites;
|
QList<GroupInviteWidget*> invites;
|
||||||
QScrollArea* scroll;
|
QScrollArea* scroll;
|
||||||
Settings& settings;
|
Settings& settings;
|
||||||
|
Core& core;
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,7 +35,8 @@
|
||||||
* and provides buttons to accept/reject it
|
* and provides buttons to accept/reject it
|
||||||
*/
|
*/
|
||||||
|
|
||||||
GroupInviteWidget::GroupInviteWidget(QWidget* parent, const GroupInvite& invite, Settings& settings_)
|
GroupInviteWidget::GroupInviteWidget(QWidget* parent, const GroupInvite& invite,
|
||||||
|
Settings& settings_, Core& core_)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, acceptButton(new QPushButton(this))
|
, acceptButton(new QPushButton(this))
|
||||||
, rejectButton(new QPushButton(this))
|
, rejectButton(new QPushButton(this))
|
||||||
|
@ -43,6 +44,7 @@ GroupInviteWidget::GroupInviteWidget(QWidget* parent, const GroupInvite& invite,
|
||||||
, widgetLayout(new QHBoxLayout(this))
|
, widgetLayout(new QHBoxLayout(this))
|
||||||
, inviteInfo(invite)
|
, inviteInfo(invite)
|
||||||
, settings{settings_}
|
, settings{settings_}
|
||||||
|
, core{core_}
|
||||||
{
|
{
|
||||||
connect(acceptButton, &QPushButton::clicked, [=]() { emit accepted(inviteInfo); });
|
connect(acceptButton, &QPushButton::clicked, [=]() { emit accepted(inviteInfo); });
|
||||||
connect(rejectButton, &QPushButton::clicked, [=]() { emit rejected(inviteInfo); });
|
connect(rejectButton, &QPushButton::clicked, [=]() { emit rejected(inviteInfo); });
|
||||||
|
@ -58,7 +60,7 @@ GroupInviteWidget::GroupInviteWidget(QWidget* parent, const GroupInvite& invite,
|
||||||
*/
|
*/
|
||||||
void GroupInviteWidget::retranslateUi()
|
void GroupInviteWidget::retranslateUi()
|
||||||
{
|
{
|
||||||
QString name = Nexus::getCore()->getFriendUsername(inviteInfo.getFriendId());
|
QString name = core.getFriendUsername(inviteInfo.getFriendId());
|
||||||
QDateTime inviteDate = inviteInfo.getInviteDate();
|
QDateTime inviteDate = inviteInfo.getInviteDate();
|
||||||
QString date = inviteDate.toString(settings.getDateFormat());
|
QString date = inviteDate.toString(settings.getDateFormat());
|
||||||
QString time = inviteDate.toString(settings.getTimestampFormat());
|
QString time = inviteDate.toString(settings.getTimestampFormat());
|
||||||
|
|
|
@ -28,12 +28,14 @@ class CroppingLabel;
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
class Core;
|
||||||
|
|
||||||
class GroupInviteWidget : public QWidget
|
class GroupInviteWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
GroupInviteWidget(QWidget* parent, const GroupInvite& invite, Settings& settings);
|
GroupInviteWidget(QWidget* parent, const GroupInvite& invite, Settings& settings,
|
||||||
|
Core& core);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
const GroupInvite getInviteInfo() const;
|
const GroupInvite getInviteInfo() const;
|
||||||
|
|
||||||
|
@ -48,4 +50,5 @@ private:
|
||||||
QHBoxLayout* widgetLayout;
|
QHBoxLayout* widgetLayout;
|
||||||
GroupInvite inviteInfo;
|
GroupInvite inviteInfo;
|
||||||
Settings& settings;
|
Settings& settings;
|
||||||
|
Core& core;
|
||||||
};
|
};
|
||||||
|
|
|
@ -295,8 +295,9 @@ void Widget::init()
|
||||||
|
|
||||||
CoreFile* coreFile = core->getCoreFile();
|
CoreFile* coreFile = core->getCoreFile();
|
||||||
filesForm = new FilesForm(*coreFile, settings, style, messageBoxManager);
|
filesForm = new FilesForm(*coreFile, settings, style, messageBoxManager);
|
||||||
addFriendForm = new AddFriendForm(core->getSelfId(), settings, style, messageBoxManager);
|
addFriendForm = new AddFriendForm(core->getSelfId(), settings, style,
|
||||||
groupInviteForm = new GroupInviteForm(settings);
|
messageBoxManager, *core);
|
||||||
|
groupInviteForm = new GroupInviteForm(settings, *core);
|
||||||
|
|
||||||
#if UPDATE_CHECK_ENABLED
|
#if UPDATE_CHECK_ENABLED
|
||||||
updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(settings));
|
updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(settings));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user