Browse Source

refactor: Remove 'FriendWidget::setChatForm'

reviewable/pr4942/r2
Diadlo 8 years ago
parent
commit
61e0dff8a4
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
  1. 9
      src/widget/circlewidget.cpp
  2. 14
      src/widget/contentdialog.cpp
  3. 4
      src/widget/contentdialog.h
  4. 8
      src/widget/friendwidget.cpp
  5. 1
      src/widget/friendwidget.h
  6. 1
      src/widget/genericchatroomwidget.h
  7. 2
      src/widget/groupwidget.h
  8. 13
      src/widget/widget.cpp

9
src/widget/circlewidget.cpp

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include "src/model/friend.h"
#include "src/friendlist.h"
#include "src/persistence/settings.h"
#include "src/widget/form/chatform.h"
QHash<int, CircleWidget*> CircleWidget::circleList;
@ -119,8 +120,9 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) @@ -119,8 +120,9 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
qobject_cast<FriendWidget*>(friendOnlineLayout()->itemAt(i)->widget());
if (friendWidget != nullptr) {
const Friend* f = friendWidget->getFriend();
dialog->addFriend(f);
const Friend* const f = friendWidget->getFriend();
ChatForm* const form = f->getChatForm();
dialog->addFriend(f, form);
}
}
for (int i = 0; i < friendOfflineLayout()->count(); ++i) {
@ -129,7 +131,8 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event) @@ -129,7 +131,8 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
if (friendWidget != nullptr) {
const Friend* f = friendWidget->getFriend();
dialog->addFriend(f);
ChatForm* const form = f->getChatForm();
dialog->addFriend(f, form);
}
}

14
src/widget/contentdialog.cpp

@ -159,12 +159,13 @@ ContentDialog::~ContentDialog() @@ -159,12 +159,13 @@ ContentDialog::~ContentDialog()
Translator::unregister(this);
}
FriendWidget* ContentDialog::addFriend(const Friend* frnd)
FriendWidget* ContentDialog::addFriend(const Friend* frnd, GenericChatForm* form)
{
bool compact = Settings::getInstance().getCompactLayout();
uint32_t friendId = frnd->getId();
FriendWidget* friendWidget = new FriendWidget(frnd, compact);
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
friendChatForms[friendId] = form;
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
@ -716,11 +717,18 @@ void ContentDialog::activate(GenericChatroomWidget* widget) @@ -716,11 +717,18 @@ void ContentDialog::activate(GenericChatroomWidget* widget)
activeChatroomWidget = widget;
widget->setChatForm(contentLayout);
const FriendWidget* const friendWidget = qobject_cast<FriendWidget*>(widget);
if (friendWidget) {
uint32_t friendId = friendWidget->getFriend()->getId();
friendChatForms[friendId]->show(contentLayout);
} else {
GroupWidget* const groupWidget = qobject_cast<GroupWidget*>(widget);
groupWidget->setChatForm(contentLayout);
}
widget->setAsActiveChatroom();
widget->resetEventFlags();
widget->updateStatusLight();
updateTitleAndStatusIcon();
}

4
src/widget/contentdialog.h

@ -34,6 +34,7 @@ class QSplitter; @@ -34,6 +34,7 @@ class QSplitter;
class QVBoxLayout;
class ContentDialog;
class ContentLayout;
class GenericChatForm;
class GenericChatroomWidget;
class FriendWidget;
class GroupWidget;
@ -50,7 +51,7 @@ public: @@ -50,7 +51,7 @@ public:
explicit ContentDialog(QWidget* parent = nullptr);
~ContentDialog() override;
FriendWidget* addFriend(const Friend* f);
FriendWidget* addFriend(const Friend* f, GenericChatForm* form);
GroupWidget* addGroup(int groupId, const QString& name);
void removeFriend(int friendId);
void removeGroup(int groupId);
@ -132,6 +133,7 @@ private: @@ -132,6 +133,7 @@ private:
static ContentDialog* currentDialog;
static QHash<int, ContactInfo> friendList;
static QHash<int, ContactInfo> groupList;
QHash<int, GenericChatForm*> friendChatForms;
};
#endif // CONTENTDIALOG_H

8
src/widget/friendwidget.cpp

@ -359,14 +359,6 @@ void FriendWidget::search(const QString& searchString, bool hide) @@ -359,14 +359,6 @@ void FriendWidget::search(const QString& searchString, bool hide)
}
}
void FriendWidget::setChatForm(ContentLayout* contentLayout)
{
ChatForm* form = frnd->getChatForm();
if (form) {
form->show(contentLayout);
}
}
void FriendWidget::resetEventFlags()
{
// Hack to avoid edit const Friend. TODO: Repalce on emit

1
src/widget/friendwidget.h

@ -32,7 +32,6 @@ public: @@ -32,7 +32,6 @@ public:
void setAsActiveChatroom() override final;
void setAsInactiveChatroom() override final;
void updateStatusLight() override final;
void setChatForm(ContentLayout* contentLayout) override final;
void resetEventFlags() override final;
QString getStatusString() const override final;
const Friend* getFriend() const override final;

1
src/widget/genericchatroomwidget.h

@ -39,7 +39,6 @@ public: @@ -39,7 +39,6 @@ public:
virtual void setAsActiveChatroom() = 0;
virtual void setAsInactiveChatroom() = 0;
virtual void updateStatusLight() = 0;
virtual void setChatForm(ContentLayout* contentLayout) = 0;
virtual void resetEventFlags() = 0;
virtual QString getStatusString() const = 0;
virtual const Friend* getFriend() const

2
src/widget/groupwidget.h

@ -31,10 +31,10 @@ public: @@ -31,10 +31,10 @@ public:
void setAsInactiveChatroom() final override;
void setAsActiveChatroom() final override;
void updateStatusLight() final override;
void setChatForm(ContentLayout* contentLayout) final override;
void resetEventFlags() final override;
QString getStatusString() const final override;
Group* getGroup() const final override;
void setChatForm(ContentLayout* contentLayout);
void setName(const QString& name);
void editName();

13
src/widget/widget.cpp

@ -1185,7 +1185,8 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow) @@ -1185,7 +1185,8 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
if (frnd) {
chatForms[frnd->getId()]->show(contentLayout);
} else {
widget->setChatForm(contentLayout);
GroupWidget* const groupWidget = qobject_cast<GroupWidget*>(widget);
groupWidget->setChatForm(contentLayout);
}
widget->setAsActiveChatroom();
setWindowTitle(widget->getTitle());
@ -1226,15 +1227,17 @@ void Widget::onReceiptRecieved(int friendId, int receipt) @@ -1226,15 +1227,17 @@ void Widget::onReceiptRecieved(int friendId, int receipt)
void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
{
ContentDialog* contentDialog = ContentDialog::getFriendDialog(frnd->getId());
uint32_t friendId = frnd->getId();
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
bool isSeparate = Settings::getInstance().getSeparateWindow();
FriendWidget* widget = friendWidgets[frnd->getId()];
FriendWidget* widget = friendWidgets[friendId];
bool isCurrent = activeChatroomWidget == widget;
if (!contentDialog && !isSeparate && isCurrent) {
onAddClicked();
}
FriendWidget* friendWidget = dialog->addFriend(frnd);
ChatForm* form = chatForms[friendId];
FriendWidget* friendWidget = dialog->addFriend(frnd, form);
friendWidget->setStatusMsg(widget->getStatusMsg());
@ -1267,7 +1270,7 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog) @@ -1267,7 +1270,7 @@ void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
QPixmap avatar = Nexus::getProfile()->loadAvatar(frnd->getPublicKey());
if (!avatar.isNull()) {
friendWidget->onAvatarChange(frnd->getId(), avatar);
friendWidget->onAvatarChange(friendId, avatar);
}
}

Loading…
Cancel
Save