mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(group): use displayedNameChanged signal
This commit is contained in:
parent
3f00e85486
commit
0d74134dc1
|
@ -35,6 +35,9 @@ public:
|
|||
|
||||
virtual void setEventFlag(bool flag) = 0;
|
||||
virtual bool getEventFlag() const = 0;
|
||||
|
||||
signals:
|
||||
void displayedNameChanged(const QString& newName);
|
||||
};
|
||||
|
||||
#endif // CONTACT_H
|
||||
|
|
|
@ -52,7 +52,6 @@ public:
|
|||
Status getStatus() const;
|
||||
|
||||
signals:
|
||||
void displayedNameChanged(const QString& newName);
|
||||
void nameChanged(uint32_t friendId, const QString& name);
|
||||
void aliasChanged(uint32_t friendId, QString alias);
|
||||
void statusChanged(uint32_t friendId, Status status);
|
||||
|
|
|
@ -24,9 +24,7 @@
|
|||
#include "src/persistence/settings.h"
|
||||
#include "src/widget/form/groupchatform.h"
|
||||
#include "src/widget/groupwidget.h"
|
||||
#include "src/widget/gui.h"
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
||||
static const int MAX_GROUP_TITLE_LENGTH = 128;
|
||||
|
||||
|
@ -64,17 +62,21 @@ void Group::updatePeer(int peerId, QString name)
|
|||
|
||||
void Group::setName(const QString& newTitle)
|
||||
{
|
||||
if (!newTitle.isEmpty() && title != newTitle) {
|
||||
title = newTitle.left(MAX_GROUP_TITLE_LENGTH);
|
||||
const QString shortTitle = newTitle.left(MAX_GROUP_TITLE_LENGTH);
|
||||
if (!shortTitle.isEmpty() && title != shortTitle) {
|
||||
title = shortTitle;
|
||||
emit displayedNameChanged(title);
|
||||
emit titleChangedByUser(groupId, title);
|
||||
emit titleChanged(groupId, selfName, title);
|
||||
}
|
||||
}
|
||||
|
||||
void Group::onTitleChanged(const QString& author, const QString& newTitle)
|
||||
void Group::setTitle(const QString& author, const QString& newTitle)
|
||||
{
|
||||
if (!newTitle.isEmpty() && title != newTitle) {
|
||||
title = newTitle.left(MAX_GROUP_TITLE_LENGTH);
|
||||
const QString shortTitle = newTitle.left(MAX_GROUP_TITLE_LENGTH);
|
||||
if (!shortTitle.isEmpty() && title != shortTitle) {
|
||||
title = shortTitle;
|
||||
emit displayedNameChanged(title);
|
||||
emit titleChanged(groupId, author, title);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
|
||||
#define RETRY_PEER_INFO_INTERVAL 500
|
||||
|
||||
class Friend;
|
||||
class GroupChatForm;
|
||||
class ToxPk;
|
||||
|
||||
class Group : public Contact
|
||||
|
@ -52,7 +50,7 @@ public:
|
|||
|
||||
void updatePeer(int peerId, QString newName);
|
||||
void setName(const QString& newTitle) override;
|
||||
void onTitleChanged(const QString& author, const QString& newTitle);
|
||||
void setTitle(const QString& author, const QString& newTitle);
|
||||
QString getName() const;
|
||||
QString getDisplayedName() const override;
|
||||
|
||||
|
|
|
@ -118,7 +118,8 @@ QString secondsToDHMS(quint32 duration)
|
|||
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend, History* history)
|
||||
: f(chatFriend)
|
||||
: GenericChatForm(chatFriend)
|
||||
, f(chatFriend)
|
||||
, history{history}
|
||||
, isTyping{false}
|
||||
, lastCallIsVideo{false}
|
||||
|
@ -194,8 +195,6 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
|
|||
});
|
||||
|
||||
// reflect name changes in the header
|
||||
// TODO(sudden6): check if this creates a cycle when the alias is changed
|
||||
connect(f, &Friend::displayedNameChanged, this, &ChatForm::setName);
|
||||
connect(headWidget, &ChatFormHeader::nameChanged, this, [=](const QString& newName) {
|
||||
f->setAlias(newName);
|
||||
});
|
||||
|
|
|
@ -129,7 +129,7 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
|
|||
|
||||
}
|
||||
|
||||
GenericChatForm::GenericChatForm(QWidget* parent)
|
||||
GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent)
|
||||
: QWidget(parent, Qt::Window)
|
||||
, audioInputFlag(false)
|
||||
, audioOutputFlag(false)
|
||||
|
@ -242,6 +242,9 @@ GenericChatForm::GenericChatForm(QWidget* parent)
|
|||
retranslateUi();
|
||||
Translator::registerHandler(std::bind(&GenericChatForm::retranslateUi, this), this);
|
||||
|
||||
// update header on name/title change
|
||||
connect(contact, &Contact::displayedNameChanged, this, &GenericChatForm::setName);
|
||||
|
||||
netcam = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
class ChatFormHeader;
|
||||
class ChatLog;
|
||||
class ChatTextEdit;
|
||||
class Contact;
|
||||
class ContentLayout;
|
||||
class CroppingLabel;
|
||||
class FlyoutOverlayWidget;
|
||||
|
@ -57,7 +58,7 @@ class GenericChatForm : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GenericChatForm(QWidget* parent = nullptr);
|
||||
explicit GenericChatForm(const Contact* contact, QWidget* parent = nullptr);
|
||||
~GenericChatForm() override;
|
||||
|
||||
void setName(const QString& newName);
|
||||
|
|
|
@ -73,7 +73,8 @@ QString editName(const QString& name)
|
|||
*/
|
||||
|
||||
GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
: group(chatGroup)
|
||||
: GenericChatForm (chatGroup)
|
||||
, group(chatGroup)
|
||||
, inCall(false)
|
||||
{
|
||||
nusersLabel = new QLabel();
|
||||
|
@ -114,9 +115,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
|||
connect(headWidget, &ChatFormHeader::callTriggered, this, &GroupChatForm::onCallClicked);
|
||||
connect(headWidget, &ChatFormHeader::micMuteToggle, this, &GroupChatForm::onMicMuteToggle);
|
||||
connect(headWidget, &ChatFormHeader::volMuteToggle, this, &GroupChatForm::onVolMuteToggle);
|
||||
connect(headWidget, &ChatFormHeader::nameChanged, this, [=](const QString& newName) {
|
||||
chatGroup->setName(newName);
|
||||
});
|
||||
connect(headWidget, &ChatFormHeader::nameChanged, chatGroup, &Group::setName);
|
||||
connect(group, &Group::userListChanged, this, &GroupChatForm::onUserListChanged);
|
||||
connect(group, &Group::titleChanged, this, &GroupChatForm::onTitleChanged);
|
||||
connect(&Settings::getInstance(), &Settings::blackListChanged, this, &GroupChatForm::updateUserNames);
|
||||
|
@ -182,7 +181,6 @@ void GroupChatForm::onUserListChanged()
|
|||
void GroupChatForm::onTitleChanged(uint32_t groupId, const QString& author, const QString& title)
|
||||
{
|
||||
Q_UNUSED(groupId);
|
||||
setName(title);
|
||||
if (author.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -385,7 +385,6 @@ void FriendListWidget::searchChatrooms(const QString& searchString, bool hideOnl
|
|||
void FriendListWidget::renameGroupWidget(GroupWidget* groupWidget, const QString& newName)
|
||||
{
|
||||
groupLayout.removeSortedWidget(groupWidget);
|
||||
groupWidget->setName(newName);
|
||||
groupLayout.addSortedWidget(groupWidget);
|
||||
}
|
||||
|
||||
|
|
|
@ -1823,7 +1823,7 @@ void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const Q
|
|||
GUI::setWindowTitle(title);
|
||||
}
|
||||
|
||||
g->onTitleChanged(author, title);
|
||||
g->setTitle(author, title);
|
||||
FilterCriteria filter = getFilterCriteria();
|
||||
widget->searchName(ui->searchContactText->text(), filterGroups(filter));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user