diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index a7108b8f9..74bd0426a 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -113,8 +113,8 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) circleList.remove(replacedCircle); } else if (selectedItem == openAction) { - ContentDialog* dialog = Widget::getInstance()->createContentDialog(); - + ContentDialog* dialog = new ContentDialog(); + emit newContentDialog(*dialog); for (int i = 0; i < friendOnlineLayout()->count(); ++i) { QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget(); FriendWidget* const friendWidget = qobject_cast(widget); diff --git a/src/widget/circlewidget.h b/src/widget/circlewidget.h index 2d6dd7abf..0c77d0f9b 100644 --- a/src/widget/circlewidget.h +++ b/src/widget/circlewidget.h @@ -22,6 +22,8 @@ #include "categorywidget.h" +class ContentDialog; + class CircleWidget final : public CategoryWidget { Q_OBJECT @@ -35,6 +37,7 @@ public: signals: void renameRequested(CircleWidget* circleWidget, const QString& newName); void searchCircle(CircleWidget& circletWidget); + void newContentDialog(ContentDialog& contentDialog); protected: void contextMenuEvent(QContextMenuEvent* event) final override; diff --git a/src/widget/contentdialogmanager.cpp b/src/widget/contentdialogmanager.cpp index 75b9042fa..c6546767c 100644 --- a/src/widget/contentdialogmanager.cpp +++ b/src/widget/contentdialogmanager.cpp @@ -19,17 +19,16 @@ #include "contentdialogmanager.h" -#include "src/widget/friendwidget.h" -#include "src/widget/groupwidget.h" #include "src/friendlist.h" #include "src/grouplist.h" #include "src/model/friend.h" #include "src/model/group.h" +#include "src/widget/friendwidget.h" +#include "src/widget/groupwidget.h" #include -namespace -{ +namespace { void removeDialog(ContentDialog* dialog, QHash& dialogs) { for (auto it = dialogs.begin(); it != dialogs.end();) { @@ -40,7 +39,7 @@ void removeDialog(ContentDialog* dialog, QHash } } } -} +} // namespace ContentDialogManager* ContentDialogManager::instance; @@ -60,7 +59,8 @@ bool ContentDialogManager::contactWidgetExists(const ContactId& contactId) } FriendWidget* ContentDialogManager::addFriendToDialog(ContentDialog* dialog, - std::shared_ptr chatroom, GenericChatForm* form) + std::shared_ptr chatroom, + GenericChatForm* form) { auto friendWidget = dialog->addFriend(chatroom, form); const auto friendPk = friendWidget->getFriend()->getPublicKey(); @@ -75,7 +75,8 @@ FriendWidget* ContentDialogManager::addFriendToDialog(ContentDialog* dialog, } GroupWidget* ContentDialogManager::addGroupToDialog(ContentDialog* dialog, - std::shared_ptr chatroom, GenericChatForm* form) + std::shared_ptr chatroom, + GenericChatForm* form) { auto groupWidget = dialog->addGroup(chatroom, form); const auto& groupId = groupWidget->getGroup()->getPersistentId(); @@ -103,7 +104,8 @@ void ContentDialogManager::focusContact(const ContactId& contactId) * @param list List with dialogs * @return ContentDialog if found, nullptr otherwise */ -ContentDialog* ContentDialogManager::focusDialog(const ContactId& id, const QHash& list) +ContentDialog* ContentDialogManager::focusDialog(const ContactId& id, + const QHash& list) { auto iter = list.find(id); if (iter == list.end()) { @@ -178,11 +180,11 @@ ContentDialogManager* ContentDialogManager::getInstance() return instance; } -void ContentDialogManager::addContentDialog(ContentDialog* dialog) +void ContentDialogManager::addContentDialog(ContentDialog& dialog) { - currentDialog = dialog; - connect(dialog, &ContentDialog::willClose, this, &ContentDialogManager::onDialogClose); - connect(dialog, &ContentDialog::activated, this, &ContentDialogManager::onDialogActivate); + currentDialog = &dialog; + connect(&dialog, &ContentDialog::willClose, this, &ContentDialogManager::onDialogClose); + connect(&dialog, &ContentDialog::activated, this, &ContentDialogManager::onDialogActivate); } void ContentDialogManager::onDialogActivate() @@ -203,10 +205,10 @@ void ContentDialogManager::onDialogClose() IDialogs* ContentDialogManager::getFriendDialogs(const ToxPk& friendPk) const { - return getFriendDialog(friendPk); + return getFriendDialog(friendPk); } IDialogs* ContentDialogManager::getGroupDialogs(const GroupId& groupId) const { - return getGroupDialog(groupId); + return getGroupDialog(groupId); } diff --git a/src/widget/contentdialogmanager.h b/src/widget/contentdialogmanager.h index d4e45ed00..564093393 100644 --- a/src/widget/contentdialogmanager.h +++ b/src/widget/contentdialogmanager.h @@ -20,11 +20,11 @@ #ifndef _CONTENT_DIALOG_MANAGER_H_ #define _CONTENT_DIALOG_MANAGER_H_ -#include "src/core/contactid.h" -#include "src/core/toxpk.h" -#include "src/core/groupid.h" -#include "src/model/dialogs/idialogsmanager.h" #include "contentdialog.h" +#include "src/core/contactid.h" +#include "src/core/groupid.h" +#include "src/core/toxpk.h" +#include "src/model/dialogs/idialogsmanager.h" #include @@ -47,10 +47,12 @@ public: IDialogs* getFriendDialogs(const ToxPk& friendPk) const; IDialogs* getGroupDialogs(const GroupId& groupId) const; - FriendWidget* addFriendToDialog(ContentDialog* dialog, std::shared_ptr chatroom, GenericChatForm* form); - GroupWidget* addGroupToDialog(ContentDialog* dialog, std::shared_ptr chatroom, GenericChatForm* form); + FriendWidget* addFriendToDialog(ContentDialog* dialog, std::shared_ptr chatroom, + GenericChatForm* form); + GroupWidget* addGroupToDialog(ContentDialog* dialog, std::shared_ptr chatroom, + GenericChatForm* form); - void addContentDialog(ContentDialog* dialog); + void addContentDialog(ContentDialog& dialog); static ContentDialogManager* getInstance(); @@ -59,7 +61,8 @@ private slots: void onDialogActivate(); private: - ContentDialog* focusDialog(const ContactId& id, const QHash& list); + ContentDialog* focusDialog(const ContactId& id, + const QHash& list); ContentDialog* currentDialog = nullptr; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index d0274fa38..195dfba70 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1818,26 +1818,30 @@ void Widget::onUpdateAvailable(QString /*latestVersion*/, QUrl /*link*/) ContentDialog* Widget::createContentDialog() const { ContentDialog* contentDialog = new ContentDialog(); - ContentDialogManager::getInstance()->addContentDialog(contentDialog); - connect(contentDialog, &ContentDialog::friendDialogShown, this, &Widget::onFriendDialogShown); - connect(contentDialog, &ContentDialog::groupDialogShown, this, &Widget::onGroupDialogShown); - connect(core, &Core::usernameSet, contentDialog, &ContentDialog::setUsername); - connect(&settings, &Settings::groupchatPositionChanged, contentDialog, + registerContentDialog(*contentDialog); + return contentDialog; +} + +void Widget::registerContentDialog(ContentDialog& contentDialog) const +{ + ContentDialogManager::getInstance()->addContentDialog(contentDialog); + connect(&contentDialog, &ContentDialog::friendDialogShown, this, &Widget::onFriendDialogShown); + connect(&contentDialog, &ContentDialog::groupDialogShown, this, &Widget::onGroupDialogShown); + connect(core, &Core::usernameSet, &contentDialog, &ContentDialog::setUsername); + connect(&settings, &Settings::groupchatPositionChanged, &contentDialog, &ContentDialog::reorderLayouts); - connect(contentDialog, &ContentDialog::addFriendDialog, this, &Widget::addFriendDialog); - connect(contentDialog, &ContentDialog::addGroupDialog, this, &Widget::addGroupDialog); - connect(contentDialog, &ContentDialog::connectFriendWidget, this, &Widget::connectFriendWidget); + connect(&contentDialog, &ContentDialog::addFriendDialog, this, &Widget::addFriendDialog); + connect(&contentDialog, &ContentDialog::addGroupDialog, this, &Widget::addGroupDialog); + connect(&contentDialog, &ContentDialog::connectFriendWidget, this, &Widget::connectFriendWidget); #ifdef Q_OS_MAC Nexus& n = Nexus::getInstance(); - connect(contentDialog, &ContentDialog::destroyed, &n, &Nexus::updateWindowsClosed); - connect(contentDialog, &ContentDialog::windowStateChanged, &n, &Nexus::onWindowStateChanged); - connect(contentDialog->windowHandle(), &QWindow::windowTitleChanged, &n, &Nexus::updateWindows); + connect(&contentDialog, &ContentDialog::destroyed, &n, &Nexus::updateWindowsClosed); + connect(&contentDialog, &ContentDialog::windowStateChanged, &n, &Nexus::onWindowStateChanged); + connect(contentDialog.windowHandle(), &QWindow::windowTitleChanged, &n, &Nexus::updateWindows); n.updateWindows(); #endif - - return contentDialog; } ContentLayout* Widget::createContentDialog(DialogType type) const @@ -2702,6 +2706,7 @@ void Widget::refreshPeerListsLocal(const QString& username) void Widget::connectCircleWidget(CircleWidget& circleWidget) { connect(&circleWidget, &CircleWidget::searchCircle, this, &Widget::searchCircle); + connect(&circleWidget, &CircleWidget::newContentDialog, this, &Widget::registerContentDialog); } void Widget::connectFriendWidget(FriendWidget& friendWidget) diff --git a/src/widget/widget.h b/src/widget/widget.h index 8077ba20d..8cf769bf8 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -243,6 +243,7 @@ private slots: void connectFriendWidget(FriendWidget& friendWidget); void searchCircle(CircleWidget& circleWidget); void updateFriendActivity(const Friend& frnd); + void registerContentDialog(ContentDialog& contentDialog) const; private: // QMainWindow overrides