From 6d0ae67c9df225e32959500afbcffe7f51cace5e Mon Sep 17 00:00:00 2001 From: jenli669 Date: Fri, 28 Jun 2019 22:17:27 +0200 Subject: [PATCH 1/9] refactor(widget): remove Widget singleton in ContentDialog --- src/widget/contentdialog.cpp | 10 +++++----- src/widget/contentdialog.h | 11 ++++++----- src/widget/widget.cpp | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index e451e72d3..e054a7f88 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -37,10 +37,10 @@ #include "src/model/status.h" #include "src/persistence/settings.h" #include "src/widget/contentlayout.h" -#include "src/widget/friendwidget.h" -#include "src/widget/groupwidget.h" #include "src/widget/form/chatform.h" #include "src/widget/friendlistlayout.h" +#include "src/widget/friendwidget.h" +#include "src/widget/groupwidget.h" #include "src/widget/style.h" #include "src/widget/tool/adjustingscrollarea.h" #include "src/widget/translator.h" @@ -141,7 +141,7 @@ ContentDialog::~ContentDialog() Translator::unregister(this); } -void ContentDialog::closeEvent(QCloseEvent *event) +void ContentDialog::closeEvent(QCloseEvent* event) { emit willClose(); event->accept(); @@ -499,7 +499,7 @@ void ContentDialog::dropEvent(QDropEvent* event) return; } - Widget::getInstance()->addFriendDialog(contact, this); + emit addFriendDialog(contact, this); ensureSplitterVisible(); } else if (group) { assert(event->mimeData()->hasFormat("groupId")); @@ -509,7 +509,7 @@ void ContentDialog::dropEvent(QDropEvent* event) return; } - Widget::getInstance()->addGroupDialog(contact, this); + emit addGroupDialog(contact, this); ensureSplitterVisible(); } } diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 48e6e2801..b6604564e 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -20,12 +20,12 @@ #ifndef CONTENTDIALOG_H #define CONTENTDIALOG_H -#include "src/model/dialogs/idialogs.h" -#include "src/widget/genericchatitemlayout.h" -#include "src/widget/tool/activatedialog.h" -#include "src/model/status.h" #include "src/core/groupid.h" #include "src/core/toxpk.h" +#include "src/model/dialogs/idialogs.h" +#include "src/model/status.h" +#include "src/widget/genericchatitemlayout.h" +#include "src/widget/tool/activatedialog.h" #include @@ -79,6 +79,8 @@ public: signals: void friendDialogShown(const Friend* f); void groupDialogShown(Group* g); + void addFriendDialog(Friend* frnd, ContentDialog* contentDialog); + void addGroupDialog(Group* group, ContentDialog* contentDialog); void activated(); void willClose(); @@ -116,7 +118,6 @@ private: void focusCommon(const ContactId& id, QHash list); private: - QList layouts; QSplitter* splitter; FriendListLayout* friendLayout; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index e57c50d7d..e10886248 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1820,6 +1820,8 @@ ContentDialog* Widget::createContentDialog() const 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); #ifdef Q_OS_MAC Nexus& n = Nexus::getInstance(); From e57693fa8f2d8b806282ed519984ad36637b9cf0 Mon Sep 17 00:00:00 2001 From: jenli669 Date: Fri, 28 Jun 2019 22:23:13 +0200 Subject: [PATCH 2/9] refactor(widget): stop using getInstance in Widget --- src/widget/widget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index e10886248..a5a095be9 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -2158,7 +2158,7 @@ void Widget::onEmptyGroupCreated(uint32_t groupnumber, const GroupId& groupId, c } if (title.isEmpty()) { // Only rename group if groups are visible. - if (Widget::getInstance()->groupsVisible()) { + if (groupsVisible()) { groupWidgets[groupId]->editName(); } } else { From c28b2604cdea32fc8d9dcab64b7dda9db12326c1 Mon Sep 17 00:00:00 2001 From: jenli669 Date: Fri, 28 Jun 2019 22:34:16 +0200 Subject: [PATCH 3/9] refactor(widget): remove Widget singleton access from GeneralForm --- src/widget/form/settings/generalform.cpp | 5 ++--- src/widget/form/settings/generalform.h | 2 ++ src/widget/form/settingswidget.cpp | 4 +++- src/widget/form/settingswidget.h | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index c4aa13af4..f4623fe5e 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -152,8 +152,7 @@ GeneralForm::GeneralForm(SettingsWidget* myParent) #ifndef QTOX_PLATFORM_EXT - bodyUI->autoAwayLabel->setEnabled( - false); // these don't seem to change the appearance of the widgets, + bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets, bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable #endif @@ -203,7 +202,7 @@ void GeneralForm::on_closeToTray_stateChanged() void GeneralForm::on_lightTrayIcon_stateChanged() { Settings::getInstance().setLightTrayIcon(bodyUI->lightTrayIcon->isChecked()); - Widget::getInstance()->updateIcons(); + emit updateIcons(); } void GeneralForm::on_minimizeToTray_stateChanged() diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index ca3a3033f..7cf1d7de2 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -38,6 +38,8 @@ public: { return tr("General"); } +signals: + void updateIcons(); private slots: void on_transComboBox_currentIndexChanged(int index); diff --git a/src/widget/form/settingswidget.cpp b/src/widget/form/settingswidget.cpp index 0d8a9c34d..8bef3cc86 100644 --- a/src/widget/form/settingswidget.cpp +++ b/src/widget/form/settingswidget.cpp @@ -41,7 +41,7 @@ #include -SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, QWidget* parent) +SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Widget* parent) : QWidget(parent, Qt::Window) { CoreAV* coreAV = Core::getInstance()->getAv(); @@ -58,6 +58,8 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Q bodyLayout->addWidget(settingsWidgets.get()); std::unique_ptr gfrm(new GeneralForm(this)); + connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons); + std::unique_ptr uifrm(new UserInterfaceForm(this)); std::unique_ptr pfrm(new PrivacyForm()); AVForm* rawAvfrm = new AVForm(audio, coreAV, camera, audioSettings, videoSettings); diff --git a/src/widget/form/settingswidget.h b/src/widget/form/settingswidget.h index 89b4b7d2e..968ea7134 100644 --- a/src/widget/form/settingswidget.h +++ b/src/widget/form/settingswidget.h @@ -37,12 +37,13 @@ class QLabel; class QTabWidget; class ContentLayout; class UpdateCheck; +class Widget; class SettingsWidget : public QWidget { Q_OBJECT public: - SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, QWidget* parent = nullptr); + SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Widget* parent = nullptr); ~SettingsWidget(); bool isShown() const; From 09f37a97f9efc6f87f3df7b070f527665842bbbb Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 09:06:47 +0200 Subject: [PATCH 4/9] refactor(widget): make searchWidget always use signals --- src/widget/circlewidget.cpp | 6 +++--- src/widget/circlewidget.h | 1 + src/widget/contentdialog.cpp | 1 + src/widget/contentdialog.h | 1 + src/widget/friendlistwidget.cpp | 14 +++++++------- src/widget/friendlistwidget.h | 2 ++ src/widget/friendwidget.cpp | 23 ++++++++++++----------- src/widget/friendwidget.h | 2 ++ src/widget/widget.cpp | 19 +++++++++++++++++-- src/widget/widget.h | 4 +++- 10 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index 74090561f..a7108b8f9 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -33,8 +33,8 @@ #include "widget.h" #include "tool/croppinglabel.h" -#include "src/model/friend.h" #include "src/friendlist.h" +#include "src/model/friend.h" #include "src/persistence/settings.h" #include "src/widget/form/chatform.h" @@ -142,7 +142,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) void CircleWidget::dragEnterEvent(QDragEnterEvent* event) { - if(!event->mimeData()->hasFormat("toxPk")) { + if (!event->mimeData()->hasFormat("toxPk")) { return; } ToxPk toxPk(event->mimeData()->data("toxPk")); @@ -186,7 +186,7 @@ void CircleWidget::dropEvent(QDropEvent* event) if (circleWidget != nullptr) { circleWidget->updateStatus(); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } setContainerAttribute(Qt::WA_UnderMouse, false); diff --git a/src/widget/circlewidget.h b/src/widget/circlewidget.h index d9b4b42c4..2d6dd7abf 100644 --- a/src/widget/circlewidget.h +++ b/src/widget/circlewidget.h @@ -34,6 +34,7 @@ public: signals: void renameRequested(CircleWidget* circleWidget, const QString& newName); + void searchCircle(CircleWidget& circletWidget); protected: void contextMenuEvent(QContextMenuEvent* event) final override; diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index e054a7f88..2476390df 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -153,6 +153,7 @@ FriendWidget* ContentDialog::addFriend(std::shared_ptr chatroom, auto frnd = chatroom->getFriend(); auto friendPk = frnd->getPublicKey(); auto friendWidget = new FriendWidget(chatroom, compact); + emit connectFriendWidget(*friendWidget); contactWidgets[friendPk] = friendWidget; friendLayout->addFriendWidget(friendWidget, frnd->getStatus()); contactChatForms[friendPk] = form; diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index b6604564e..a2aa0a145 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -83,6 +83,7 @@ signals: void addGroupDialog(Group* group, ContentDialog* contentDialog); void activated(); void willClose(); + void connectFriendWidget(FriendWidget& friendWidget); public slots: void reorderLayouts(bool newGroupOnTop); diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index ff1b78099..129678b56 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -294,8 +294,7 @@ void FriendListWidget::addGroupWidget(GroupWidget* widget) { groupLayout.addSortedWidget(widget); Group* g = widget->getGroup(); - connect(g, &Group::titleChanged, - [=](const QString& author, const QString& name) { + connect(g, &Group::titleChanged, [=](const QString& author, const QString& name) { Q_UNUSED(author); renameGroupWidget(widget, name); }); @@ -330,7 +329,7 @@ void FriendListWidget::removeFriendWidget(FriendWidget* w) CircleWidget* circleWidget = CircleWidget::getFromID(id); if (circleWidget != nullptr) { circleWidget->removeFriendWidget(w, contact->getStatus()); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } } } @@ -354,10 +353,10 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget) circleWidget->setExpanded(true); if (circleOriginal != nullptr) - Widget::getInstance()->searchCircle(circleOriginal); + emit searchCircle(*circleOriginal); } - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); if (window()->isActiveWindow()) circleWidget->editName(); @@ -420,7 +419,7 @@ void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget) if (circleWidget != nullptr) { circleWidget->removeFriendWidget(friendWidget, status); circleWidget->addFriendWidget(friendWidget, status); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } else { listLayout->removeFriendWidget(friendWidget, status); listLayout->addFriendWidget(friendWidget, status); @@ -575,7 +574,7 @@ void FriendListWidget::dragEnterEvent(QDragEnterEvent* event) if (!event->mimeData()->hasFormat("toxPk")) { return; } - ToxPk toxPk(event->mimeData()->data("toxPk"));; + ToxPk toxPk(event->mimeData()->data("toxPk")); Friend* frnd = FriendList::findFriend(toxPk); if (frnd) event->acceptProposedAction(); @@ -673,6 +672,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id) assert(circleLayout != nullptr); CircleWidget* circleWidget = new CircleWidget(this, id); + emit connectCircleWidget(*circleWidget); circleLayout->addSortedWidget(circleWidget); connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged); connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget); diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index 7bb3158f4..cb6f66777 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -65,6 +65,8 @@ public: signals: void onCompactChanged(bool compact); + void connectCircleWidget(CircleWidget& circleWidget); + void searchCircle(CircleWidget& circleWidget); public slots: void renameGroupWidget(GroupWidget* groupWidget, const QString& newName); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index f8cd15706..1f3cd71aa 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -72,7 +72,8 @@ FriendWidget::FriendWidget(std::shared_ptr chatroom, bool compac connect(nameLabel, &CroppingLabel::editFinished, frnd, &Friend::setAlias); // update on changes of the displayed name connect(frnd, &Friend::displayedNameChanged, nameLabel, &CroppingLabel::setText); - connect(frnd, &Friend::displayedNameChanged, this, [this](const QString /* &newName */){emit friendWidgetRenamed(this);}); + connect(frnd, &Friend::displayedNameChanged, this, + [this](const QString /* &newName */) { emit friendWidgetRenamed(this); }); connect(chatroom.get(), &FriendChatroom::activeChanged, this, &FriendWidget::setActive); statusMessageLabel->setTextFormat(Qt::PlainText); } @@ -125,9 +126,7 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event) for (const auto group : chatroom->getGroups()) { const auto groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(group.name)); - connect(groupAction, &QAction::triggered, [=]() { - chatroom->inviteFriend(group.group); - }); + connect(groupAction, &QAction::triggered, [=]() { chatroom->inviteFriend(group.group); }); } const auto circleId = chatroom->getCircleId(); @@ -242,7 +241,7 @@ void FriendWidget::removeFromCircle() if (circleWidget != nullptr) { circleWidget->updateStatus(); - Widget::getInstance()->searchCircle(circleWidget); + emit searchCircle(*circleWidget); } } @@ -258,7 +257,7 @@ void FriendWidget::moveToCircle(int newCircleId) if (newCircleWidget) { newCircleWidget->addFriendWidget(this, frnd->getStatus()); newCircleWidget->setExpanded(true); - Widget::getInstance()->searchCircle(newCircleWidget); + emit searchCircle(*newCircleWidget); s.savePersonal(); } else { s.setFriendCircleID(pk, newCircleId); @@ -266,7 +265,7 @@ void FriendWidget::moveToCircle(int newCircleId) if (oldCircleWidget) { oldCircleWidget->updateStatus(); - Widget::getInstance()->searchCircle(oldCircleWidget); + emit searchCircle(*oldCircleWidget); } } @@ -274,8 +273,10 @@ void FriendWidget::changeAutoAccept(bool enable) { if (enable) { const auto oldDir = chatroom->getAutoAcceptDir(); - const auto newDir = QFileDialog::getExistingDirectory( - Q_NULLPTR, tr("Choose an auto accept directory", "popup title"), oldDir); + const auto newDir = + QFileDialog::getExistingDirectory(Q_NULLPTR, + tr("Choose an auto accept directory", "popup title"), + oldDir); chatroom->setAutoAcceptDir(newDir); } else { chatroom->disableAutoAccept(); @@ -305,8 +306,8 @@ void FriendWidget::setActive(bool active) { GenericChatroomWidget::setActive(active); if (isDefaultAvatar) { - const auto uri = active ? QStringLiteral(":img/contact_dark.svg") - : QStringLiteral(":img/contact.svg"); + const auto uri = + active ? QStringLiteral(":img/contact_dark.svg") : QStringLiteral(":img/contact.svg"); avatar->setPixmap(QPixmap{uri}); } } diff --git a/src/widget/friendwidget.h b/src/widget/friendwidget.h index 779f8df7f..d637fdbcd 100644 --- a/src/widget/friendwidget.h +++ b/src/widget/friendwidget.h @@ -28,6 +28,7 @@ class FriendChatroom; class QPixmap; class MaskablePixmapWidget; +class CircleWidget; class FriendWidget : public GenericChatroomWidget { @@ -53,6 +54,7 @@ signals: void contextMenuCalled(QContextMenuEvent* event); void friendHistoryRemoved(); void friendWidgetRenamed(FriendWidget* friendWidget); + void searchCircle(CircleWidget& circleWidget); public slots: void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index a5a095be9..0e64e04c7 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -249,6 +249,9 @@ void Widget::init() ui->searchContactFilterBox->setMenu(filterMenu); contactListWidget = new FriendListWidget(this, settings.getGroupchatPosition()); + connect(contactListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle); + connect(contactListWidget, &FriendListWidget::connectCircleWidget, this, + &Widget::connectCircleWidget); ui->friendList->setWidget(contactListWidget); ui->friendList->setLayoutDirection(Qt::RightToLeft); ui->friendList->setContextMenuPolicy(Qt::CustomContextMenu); @@ -1141,6 +1144,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) std::shared_ptr chatroom(rawChatroom); const auto compact = settings.getCompactLayout(); auto widget = new FriendWidget(chatroom, compact); + connectFriendWidget(*widget); auto history = Nexus::getProfile()->getHistory(); auto messageProcessor = MessageProcessor(sharedMessageProcessorParams); @@ -1822,6 +1826,7 @@ ContentDialog* Widget::createContentDialog() const &ContentDialog::reorderLayouts); 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(); @@ -2540,11 +2545,11 @@ Widget::FilterCriteria Widget::getFilterCriteria() const return FilterCriteria::All; } -void Widget::searchCircle(CircleWidget* circleWidget) +void Widget::searchCircle(CircleWidget& circleWidget) { FilterCriteria filter = getFilterCriteria(); QString text = ui->searchContactText->text(); - circleWidget->search(text, true, filterOnline(filter), filterOffline(filter)); + circleWidget.search(text, true, filterOnline(filter), filterOffline(filter)); } bool Widget::groupsVisible() const @@ -2692,3 +2697,13 @@ void Widget::refreshPeerListsLocal(const QString& username) g->updateUsername(core->getSelfPublicKey(), username); } } + +void Widget::connectCircleWidget(CircleWidget& circleWidget) +{ + connect(&circleWidget, &CircleWidget::searchCircle, this, &Widget::searchCircle); +} + +void Widget::connectFriendWidget(FriendWidget& friendWidget) +{ + connect(&friendWidget, &FriendWidget::searchCircle, this, &Widget::searchCircle); +} diff --git a/src/widget/widget.h b/src/widget/widget.h index 7b3b41a45..7da4cdb1a 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -145,7 +145,6 @@ public: void reloadTheme(); static inline QIcon prepareIcon(QString path, int w = 0, int h = 0); - void searchCircle(CircleWidget* circleWidget); bool groupsVisible() const; void resetIcon(); @@ -241,6 +240,9 @@ private slots: void dispatchFile(ToxFile file); void dispatchFileWithBool(ToxFile file, bool); void dispatchFileSendFailed(uint32_t friendId, const QString& fileName); + void connectCircleWidget(CircleWidget& circleWidget); + void connectFriendWidget(FriendWidget& friendWidget); + void searchCircle(CircleWidget& circleWidget); private: // QMainWindow overrides From cff845ffa724b7cbfd6792b5f4b60bdb5339d0ca Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 09:14:23 +0200 Subject: [PATCH 5/9] refactor(widget): make AboutFriendForm use FriendWidget as parent --- src/widget/friendwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 1f3cd71aa..53fbb354e 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -287,7 +287,7 @@ void FriendWidget::showDetails() const auto frnd = chatroom->getFriend(); const auto iabout = new AboutFriend(frnd, &Settings::getInstance()); std::unique_ptr about = std::unique_ptr(iabout); - const auto aboutUser = new AboutFriendForm(std::move(about), Widget::getInstance()); + const auto aboutUser = new AboutFriendForm(std::move(about), this); connect(aboutUser, &AboutFriendForm::histroyRemoved, this, &FriendWidget::friendHistoryRemoved); aboutUser->show(); } From 20979744c91808061c5bf2290f94e684da50b91e Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 09:49:29 +0200 Subject: [PATCH 6/9] refactor(chatform): make ChatForm use signals for updateFriendActivity --- src/widget/form/chatform.cpp | 65 +++++++++++++++++------------------- src/widget/form/chatform.h | 4 ++- src/widget/friendwidget.cpp | 2 +- src/widget/friendwidget.h | 1 + src/widget/widget.cpp | 12 ++++--- src/widget/widget.h | 2 +- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 6c9303a70..f3cb6fcaa 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -74,34 +74,33 @@ static constexpr int TYPING_NOTIFICATION_DURATION = 3000; const QString ChatForm::ACTION_PREFIX = QStringLiteral("/me "); -namespace +namespace { +QString secondsToDHMS(quint32 duration) { - QString secondsToDHMS(quint32 duration) - { - QString res; - QString cD = ChatForm::tr("Call duration: "); - quint32 seconds = duration % 60; - duration /= 60; - quint32 minutes = duration % 60; - duration /= 60; - quint32 hours = duration % 24; - quint32 days = duration / 24; + QString res; + QString cD = ChatForm::tr("Call duration: "); + quint32 seconds = duration % 60; + duration /= 60; + quint32 minutes = duration % 60; + duration /= 60; + quint32 hours = duration % 24; + quint32 days = duration / 24; - // I assume no one will ever have call longer than a month - if (days) { - return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds); - } - - if (hours) { - return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds); - } - - if (minutes) { - return cD + res.sprintf("%02dm %02ds", minutes, seconds); - } - - return cD + res.sprintf("%02ds", seconds); + // I assume no one will ever have call longer than a month + if (days) { + return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds); } + + if (hours) { + return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds); + } + + if (minutes) { + return cD + res.sprintf("%02dm %02ds", minutes, seconds); + } + + return cD + res.sprintf("%02ds", seconds); +} } // namespace ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& messageDispatcher) @@ -155,9 +154,8 @@ ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& me connect(headWidget, &ChatFormHeader::videoCallTriggered, this, &ChatForm::onVideoCallTriggered); connect(headWidget, &ChatFormHeader::micMuteToggle, this, &ChatForm::onMicMuteToggle); connect(headWidget, &ChatFormHeader::volMuteToggle, this, &ChatForm::onVolMuteToggle); - - connect(sendButton, &QPushButton::pressed, this, &ChatForm::updateFriendActivity); - connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::updateFriendActivity); + connect(sendButton, &QPushButton::pressed, this, &ChatForm::callUpdateFriendActivity); + connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::callUpdateFriendActivity); connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged); connect(msgEdit, &ChatTextEdit::pasteImage, this, &ChatForm::sendImage); connect(statusMessageLabel, &CroppingLabel::customContextMenuRequested, this, @@ -201,10 +199,9 @@ void ChatForm::setStatusMessage(const QString& newMessage) statusMessageLabel->setToolTip(Qt::convertFromPlainText(newMessage, Qt::WhiteSpaceNormal)); } -void ChatForm::updateFriendActivity() +void ChatForm::callUpdateFriendActivity() { - // TODO: Remove Widget::getInstance() - Widget::getInstance()->updateFriendActivity(f); + emit updateFriendActivity(*f); } void ChatForm::updateFriendActivityForFile(const ToxFile& file) @@ -212,9 +209,7 @@ void ChatForm::updateFriendActivityForFile(const ToxFile& file) if (file.friendId != f->getId()) { return; } - - // TODO: Remove Widget::getInstance() - Widget::getInstance()->updateFriendActivity(f); + emit updateFriendActivity(*f); } void ChatForm::onFileNameChanged(const ToxPk& friendPk) @@ -351,7 +346,7 @@ void ChatForm::showOutgoingCall(bool video) addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()), ChatMessage::INFO, QDateTime::currentDateTime()); emit outgoingNotification(); - Widget::getInstance()->updateFriendActivity(f); + emit updateFriendActivity(*f); } void ChatForm::onAnswerCallTriggered(bool video) diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 3161596bd..57a68d7be 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -65,6 +65,7 @@ signals: void endCallNotification(); void rejectCall(uint32_t friendId); void acceptCall(uint32_t friendId); + void updateFriendActivity(Friend& frnd); public slots: void onAvInvite(uint32_t friendId, bool video); @@ -75,7 +76,6 @@ public slots: void clearChatArea(); private slots: - void updateFriendActivity(); void updateFriendActivityForFile(const ToxFile& file); void onAttachClicked() override; void onScreenshotClicked() override; @@ -97,6 +97,8 @@ private slots: void doScreenshot(); void onCopyStatusMessage(); + void callUpdateFriendActivity(); + private: void updateMuteMicButton(); void updateMuteVolButton(); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 53fbb354e..7d4d79590 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -326,7 +326,7 @@ void FriendWidget::updateStatusLight() circleWidget->setExpanded(true); } - Widget::getInstance()->updateFriendActivity(frnd); + emit updateFriendActivity(*frnd); } statusPic.setMargin(event ? 1 : 3); diff --git a/src/widget/friendwidget.h b/src/widget/friendwidget.h index d637fdbcd..ce5847a64 100644 --- a/src/widget/friendwidget.h +++ b/src/widget/friendwidget.h @@ -55,6 +55,7 @@ signals: void friendHistoryRemoved(); void friendWidgetRenamed(FriendWidget* friendWidget); void searchCircle(CircleWidget& circleWidget); + void updateFriendActivity(Friend& frnd); public slots: void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 0e64e04c7..d0274fa38 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1157,6 +1157,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk) std::make_shared(*newfriend, history, *core, Settings::getInstance(), *friendMessageDispatcher); auto friendForm = new ChatForm(newfriend, *chatHistory, *friendMessageDispatcher); + connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity); friendMessageDispatchers[friendPk] = friendMessageDispatcher; friendChatLogs[friendPk] = chatHistory; @@ -1704,14 +1705,14 @@ void Widget::onFileReceiveRequested(const ToxFile& file) true, true); } -void Widget::updateFriendActivity(const Friend* frnd) +void Widget::updateFriendActivity(const Friend& frnd) { - const ToxPk& pk = frnd->getPublicKey(); + const ToxPk& pk = frnd.getPublicKey(); const auto oldTime = settings.getFriendActivity(pk); const auto newTime = QDateTime::currentDateTime(); settings.setFriendActivity(pk, newTime); - FriendWidget* widget = friendWidgets[frnd->getPublicKey()]; - contactListWidget->moveWidget(widget, frnd->getStatus()); + FriendWidget* widget = friendWidgets[frnd.getPublicKey()]; + contactListWidget->moveWidget(widget, frnd.getStatus()); contactListWidget->updateActivityTime(oldTime); // update old category widget } @@ -1928,7 +1929,7 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo) const uint32_t friendId = inviteInfo.getFriendId(); const ToxPk& friendPk = FriendList::id2Key(friendId); const Friend* f = FriendList::findFriend(friendPk); - updateFriendActivity(f); + updateFriendActivity(*f); const uint8_t confType = inviteInfo.getType(); if (confType == TOX_CONFERENCE_TYPE_TEXT || confType == TOX_CONFERENCE_TYPE_AV) { @@ -2706,4 +2707,5 @@ void Widget::connectCircleWidget(CircleWidget& circleWidget) void Widget::connectFriendWidget(FriendWidget& friendWidget) { connect(&friendWidget, &FriendWidget::searchCircle, this, &Widget::searchCircle); + connect(&friendWidget, &FriendWidget::updateFriendActivity, this, &Widget::updateFriendActivity); } diff --git a/src/widget/widget.h b/src/widget/widget.h index 7da4cdb1a..8077ba20d 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -174,7 +174,6 @@ public slots: void onReceiptReceived(int friendId, ReceiptNum receipt); void onFriendRequestReceived(const ToxPk& friendPk, const QString& message); void onFileReceiveRequested(const ToxFile& file); - void updateFriendActivity(const Friend* frnd); void onEmptyGroupCreated(uint32_t groupnumber, const GroupId& groupId, const QString& title); void onGroupJoined(int groupNum, const GroupId& groupId); void onGroupInviteReceived(const GroupInvite& inviteInfo); @@ -243,6 +242,7 @@ private slots: void connectCircleWidget(CircleWidget& circleWidget); void connectFriendWidget(FriendWidget& friendWidget); void searchCircle(CircleWidget& circleWidget); + void updateFriendActivity(const Friend& frnd); private: // QMainWindow overrides From adab063a49fad4298c24ae0f1ed075b440cf2545 Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 09:53:58 +0200 Subject: [PATCH 7/9] refactor(widget): make PrivacyForm use signals for clearAllReceipts() --- src/widget/form/settings/privacyform.cpp | 2 +- src/widget/form/settings/privacyform.h | 3 +++ src/widget/form/settingswidget.cpp | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index a569e3c78..5d0ed9445 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -59,7 +59,7 @@ void PrivacyForm::on_cbKeepHistory_stateChanged() { Settings::getInstance().setEnableLogging(bodyUI->cbKeepHistory->isChecked()); if (!bodyUI->cbKeepHistory->isChecked()) { - Widget::getInstance()->clearAllReceipts(); + emit clearAllReceipts(); QMessageBox::StandardButton dialogDelHistory; dialogDelHistory = QMessageBox::question(nullptr, tr("Confirmation"), diff --git a/src/widget/form/settings/privacyform.h b/src/widget/form/settings/privacyform.h index 0d84983e8..1110ef630 100644 --- a/src/widget/form/settings/privacyform.h +++ b/src/widget/form/settings/privacyform.h @@ -37,6 +37,9 @@ public: return tr("Privacy"); } +signals: + void clearAllReceipts(); + private slots: void on_cbKeepHistory_stateChanged(); void on_cbTypingNotification_stateChanged(); diff --git a/src/widget/form/settingswidget.cpp b/src/widget/form/settingswidget.cpp index 8bef3cc86..352c4b2d1 100644 --- a/src/widget/form/settingswidget.cpp +++ b/src/widget/form/settingswidget.cpp @@ -62,6 +62,8 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, W std::unique_ptr uifrm(new UserInterfaceForm(this)); std::unique_ptr pfrm(new PrivacyForm()); + connect(pfrm.get(), &PrivacyForm::clearAllReceipts, parent, &Widget::clearAllReceipts); + AVForm* rawAvfrm = new AVForm(audio, coreAV, camera, audioSettings, videoSettings); std::unique_ptr avfrm(rawAvfrm); std::unique_ptr expfrm(new AdvancedForm()); From 7fca93bde9cf3092deae6142474c0524f4db3705 Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 12:53:49 +0200 Subject: [PATCH 8/9] refactor(circlewidget): link CircleWidget ContentDialogs using signals --- src/widget/circlewidget.cpp | 4 ++-- src/widget/circlewidget.h | 3 +++ src/widget/contentdialogmanager.cpp | 30 +++++++++++++++------------- src/widget/contentdialogmanager.h | 19 ++++++++++-------- src/widget/widget.cpp | 31 +++++++++++++++++------------ src/widget/widget.h | 1 + 6 files changed, 51 insertions(+), 37 deletions(-) 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 From 105f9ec4013ee5e5c96b261507b1e658dc49bdfb Mon Sep 17 00:00:00 2001 From: jenli669 Date: Sat, 29 Jun 2019 13:14:38 +0200 Subject: [PATCH 9/9] refactor(widget): remove Widget::getInstance --- src/nexus.cpp | 9 +++++---- src/widget/tool/callconfirmwidget.cpp | 17 +++++++---------- src/widget/widget.cpp | 17 ----------------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/nexus.cpp b/src/nexus.cpp index bb7a60ac7..ff3f76f79 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -34,8 +34,8 @@ #include #include #include -#include #include +#include #ifdef Q_OS_MAC #include @@ -169,7 +169,7 @@ int Nexus::showLogin(const QString& profileName) return returnval; } -void Nexus::bootstrapWithProfile(Profile *p) +void Nexus::bootstrapWithProfile(Profile* p) { // kriby: This is a hack until a proper controller is written @@ -222,7 +222,7 @@ void Nexus::showMainGUI() assert(profile); // Create GUI - widget = Widget::getInstance(audioControl.get()); + widget = new Widget(*audioControl); // Start GUI widget->init(); @@ -309,7 +309,8 @@ void Nexus::onLoadProfile(const QString& name, const QString& pass) * Changes the loaded profile and notifies listeners. * @param p */ -void Nexus::setProfile(Profile* p) { +void Nexus::setProfile(Profile* p) +{ if (!p) { emit profileLoadFailed(); // Warnings are issued during respective createNew/load calls diff --git a/src/widget/tool/callconfirmwidget.cpp b/src/widget/tool/callconfirmwidget.cpp index cf5322c9a..19db6b861 100644 --- a/src/widget/tool/callconfirmwidget.cpp +++ b/src/widget/tool/callconfirmwidget.cpp @@ -22,6 +22,7 @@ #include "src/widget/style.h" #include "src/widget/widget.h" #include +#include #include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include /** @@ -76,12 +76,12 @@ CallConfirmWidget::CallConfirmWidget(const QWidget* anchor) // Note: At the moment this may not work properly. For languages written // from right to left, there is no translation for the phrase "Incoming call...". // In this situation, the phrase "Incoming call..." looks as "...oming call..." - Qt::TextElideMode elideMode = (QGuiApplication::layoutDirection() == Qt::LeftToRight) - ? Qt::ElideRight : Qt::ElideLeft; + Qt::TextElideMode elideMode = + (QGuiApplication::layoutDirection() == Qt::LeftToRight) ? Qt::ElideRight : Qt::ElideLeft; int marginSize = 12; QFontMetrics fontMetrics(callLabel->font()); - QString elidedText = fontMetrics.elidedText(callLabel->text(), elideMode, - rectW - marginSize * 2 - 4); + QString elidedText = + fontMetrics.elidedText(callLabel->text(), elideMode, rectW - marginSize * 2 - 4); callLabel->setText(elidedText); QDialogButtonBox* buttonBox = new QDialogButtonBox(Qt::Horizontal, this); @@ -154,14 +154,11 @@ void CallConfirmWidget::paintEvent(QPaintEvent*) void CallConfirmWidget::showEvent(QShowEvent*) { + // Kriby: Legacy comment, is this still true? // If someone does show() from Widget or lower, the event will reach us // because it's our parent, and we could show up in the wrong form. // So check here if our friend's form is actually the active one. - // if (!Widget::getInstance()->isFriendWidgetCurActiveWidget(&f)) - { - // QWidget::hide(); - // return; - } + reposition(); update(); } diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 195dfba70..75d2fd142 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -601,23 +601,6 @@ Widget::~Widget() instance = nullptr; } -/** - * @param audio Only used for initialization from Nexus, to pass IAudioControl - * @brief Returns the singleton instance. - */ -Widget* Widget::getInstance(IAudioControl* audio) -{ - if (!instance) { - // Passing audio via pointer here is a hack - // to allow for default paramters. - // once Widget::getInstance is removed it won't be neccessary - assert(audio != nullptr); - instance = new Widget(*audio); - } - - return instance; -} - /** * @brief Switches to the About settings page. */