diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index 74bd0426a..2bb1fc7e9 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -40,9 +40,10 @@ QHash 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(); diff --git a/src/widget/circlewidget.h b/src/widget/circlewidget.h index 10f08100c..30673879b 100644 --- a/src/widget/circlewidget.h +++ b/src/widget/circlewidget.h @@ -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 circleList; int id; + + const Core& core; }; diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index bf9f92f0c..2a4bffc42 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -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); diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index a0d9836b4..519f85f6a 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -32,6 +32,7 @@ template 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 chatroom, GenericChatForm* form); diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index 5cd9c897f..8cd927499 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -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); diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index b7d313920..98f59f79d 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -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; }; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index a6f86a6cd..115f52d83 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -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(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;