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

refactor: remove getInstance from ContentDialog

This UI element probably should never depend on Core, but this is to fix
for a later time.
This commit is contained in:
sudden6 2020-05-24 21:38:47 +02:00
parent 19f4a6c4e0
commit 445340a0e9
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
7 changed files with 21 additions and 13 deletions

View File

@ -40,9 +40,10 @@
QHash<int, CircleWidget*> CircleWidget::circleList;
CircleWidget::CircleWidget(FriendListWidget* parent, int id)
CircleWidget::CircleWidget(const Core &_core, FriendListWidget* parent, int id)
: CategoryWidget(parent)
, id(id)
, core{_core}
{
setName(Settings::getInstance().getCircleName(id), false);
circleList[id] = this;
@ -113,7 +114,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
circleList.remove(replacedCircle);
} else if (selectedItem == openAction) {
ContentDialog* dialog = new ContentDialog();
ContentDialog* dialog = new ContentDialog(core);
emit newContentDialog(*dialog);
for (int i = 0; i < friendOnlineLayout()->count(); ++i) {
QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget();

View File

@ -22,12 +22,13 @@
#include "categorywidget.h"
class ContentDialog;
class Core;
class CircleWidget final : public CategoryWidget
{
Q_OBJECT
public:
explicit CircleWidget(FriendListWidget* parent, int id);
explicit CircleWidget(const Core& _core, FriendListWidget* parent, int id);
~CircleWidget();
void editName();
@ -52,4 +53,6 @@ private:
static QHash<int, CircleWidget*> circleList;
int id;
const Core& core;
};

View File

@ -51,7 +51,7 @@ static const int minHeight = 220;
static const QSize minSize(minHeight, minWidget);
static const QSize defaultSize(720, 400);
ContentDialog::ContentDialog(QWidget* parent)
ContentDialog::ContentDialog(const Core &core, QWidget* parent)
: ActivateDialog(parent, Qt::Window)
, splitter{new QSplitter(this)}
, friendLayout{new FriendListLayout(this)}
@ -124,7 +124,7 @@ ContentDialog::ContentDialog(QWidget* parent)
SplitterRestorer restorer(splitter);
restorer.restore(s.getDialogSplitterState(), size());
username = Core::getInstance()->getUsername();
username = core.getUsername();
setAcceptDrops(true);

View File

@ -32,6 +32,7 @@ template <typename K, typename V>
class QHash;
class ContentLayout;
class Core;
class Friend;
class FriendChatroom;
class FriendListLayout;
@ -48,7 +49,7 @@ class ContentDialog : public ActivateDialog, public IDialogs
{
Q_OBJECT
public:
explicit ContentDialog(QWidget* parent = nullptr);
explicit ContentDialog(const Core& core, QWidget* parent = nullptr);
~ContentDialog() override;
FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);

View File

@ -97,9 +97,10 @@ qint64 timeUntilTomorrow()
return now.msecsTo(tomorrow);
}
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
FriendListWidget::FriendListWidget(const Core &_core, Widget* parent, bool groupsOnTop)
: QWidget(parent)
, groupsOnTop(groupsOnTop)
, core{_core}
{
listLayout = new FriendListLayout();
setLayout(listLayout);
@ -671,7 +672,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
assert(circleLayout != nullptr);
CircleWidget* circleWidget = new CircleWidget(this, id);
CircleWidget* circleWidget = new CircleWidget(core, this, id);
emit connectCircleWidget(*circleWidget);
circleLayout->addSortedWidget(circleWidget);
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);

View File

@ -42,7 +42,7 @@ class FriendListWidget : public QWidget
Q_OBJECT
public:
using SortingMode = Settings::FriendListSortingMode;
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
explicit FriendListWidget(const Core& _core, Widget* parent, bool groupsOnTop = true);
~FriendListWidget();
void setMode(SortingMode mode);
SortingMode getMode() const;
@ -95,4 +95,6 @@ private:
GenericChatItemLayout groupLayout;
QVBoxLayout* activityLayout = nullptr;
QTimer* dayTimer;
const Core& core;
};

View File

@ -247,7 +247,9 @@ void Widget::init()
ui->searchContactFilterBox->setMenu(filterMenu);
contactListWidget = new FriendListWidget(this, settings.getGroupchatPosition());
core = &profile.getCore();
contactListWidget = new FriendListWidget(*core, this, settings.getGroupchatPosition());
connect(contactListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle);
connect(contactListWidget, &FriendListWidget::connectCircleWidget, this,
&Widget::connectCircleWidget);
@ -278,8 +280,6 @@ void Widget::init()
addFriendForm = new AddFriendForm(core->getSelfId());
groupInviteForm = new GroupInviteForm;
core = &profile.getCore();
#if UPDATE_CHECK_ENABLED
updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(settings));
connect(updateCheck.get(), &UpdateCheck::updateAvailable, this, &Widget::onUpdateAvailable);
@ -1803,7 +1803,7 @@ void Widget::onUpdateAvailable()
ContentDialog* Widget::createContentDialog() const
{
ContentDialog* contentDialog = new ContentDialog();
ContentDialog* contentDialog = new ContentDialog(*core);
registerContentDialog(*contentDialog);
return contentDialog;