1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(group): Store title name in Group

This commit is contained in:
Diadlo 2017-08-05 10:21:51 +03:00
parent aaf1029667
commit 7429614188
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
3 changed files with 14 additions and 9 deletions

View File

@ -28,8 +28,11 @@
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
Group::Group(int groupId, QString name, bool isAvGroupchat) static const int MAX_GROUP_TITLE_LENGTH = 128;
: groupId(groupId)
Group::Group(int groupId, const QString& name, bool isAvGroupchat)
: title{name}
, groupId(groupId)
, nPeers{0} , nPeers{0}
, avGroupchat{isAvGroupchat} , avGroupchat{isAvGroupchat}
{ {
@ -70,12 +73,15 @@ void Group::updatePeer(int peerId, QString name)
void Group::setName(const QString& name) void Group::setName(const QString& name)
{ {
emit titleChanged(groupId, name); if (!name.isEmpty() && title != name) {
title = name.left(MAX_GROUP_TITLE_LENGTH);
emit titleChanged(groupId, title);
}
} }
QString Group::getName() const QString Group::getName() const
{ {
return widget->getName(); return title;
} }
QString Group::getDisplayedName() const QString Group::getDisplayedName() const

View File

@ -36,7 +36,7 @@ class Group : public Contact
{ {
Q_OBJECT Q_OBJECT
public: public:
Group(int GroupId, QString Name, bool IsAvGroupchat); Group(int groupId, const QString& name, bool isAvGroupchat);
~Group() override; ~Group() override;
bool isAvGroupchat() const; bool isAvGroupchat() const;
@ -67,6 +67,7 @@ signals:
void userListChanged(uint32_t groupId, const QMap<QByteArray, QString>& toxids); void userListChanged(uint32_t groupId, const QMap<QByteArray, QString>& toxids);
private: private:
QString title;
GroupWidget* widget; GroupWidget* widget;
GroupChatForm* chatForm; GroupChatForm* chatForm;
QStringList peers; QStringList peers;

View File

@ -63,10 +63,8 @@ GroupWidget::~GroupWidget()
void GroupWidget::setTitle(const QString& newName) void GroupWidget::setTitle(const QString& newName)
{ {
if (!newName.isEmpty()) { Group* g = GroupList::findGroup(groupId);
Group* g = GroupList::findGroup(groupId); g->setName(newName);
g->setName(newName);
}
} }
void GroupWidget::contextMenuEvent(QContextMenuEvent* event) void GroupWidget::contextMenuEvent(QContextMenuEvent* event)