diff --git a/src/core.cpp b/src/core.cpp index 4a2ad0279..b3eec8ad3 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -269,6 +269,7 @@ void Core::start() tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); + tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); tox_callback_file_send_request(tox, onFileSendRequestCallback, this); tox_callback_file_control(tox, onFileControlCallback, this); @@ -518,6 +519,16 @@ void Core::onGroupNamelistChange(Tox*, int groupnumber, int peernumber, uint8_t emit static_cast(core)->groupNamelistChanged(groupnumber, peernumber, change); } +void Core::onGroupTitleChange(Tox*, int groupnumber, int peernumber, const uint8_t* title, uint8_t len, void* _core) +{ + qDebug() << "Core: group" << groupnumber << "title changed by" << peernumber; + Core* core = static_cast(_core); + QString author; + if (peernumber >= 0 && !tox_group_peernumber_is_ours(core->tox, groupnumber, peernumber)) + author = core->getGroupPeerName(groupnumber, peernumber); + emit core->groupTitleChanged(groupnumber, author, CString::toString(title, len)); +} + void Core::onFileSendRequestCallback(Tox*, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename, uint16_t filename_length, void *core) { @@ -816,6 +827,14 @@ void Core::sendGroupAction(int groupId, const QString& message) } } +void Core::changeGroupTitle(int groupId, const QString& title) +{ + CString cTitle(title); + int err = tox_group_set_title(tox, groupId, cTitle.data(), cTitle.size()); + if (!err) + emit groupTitleChanged(groupId, "", title); +} + void Core::sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize) { QMutexLocker mlocker(&fileSendMutex); diff --git a/src/core.h b/src/core.h index e65710c26..738c0a431 100644 --- a/src/core.h +++ b/src/core.h @@ -95,10 +95,11 @@ public slots: void setStatusMessage(const QString& message); void setAvatar(uint8_t format, const QByteArray& data); - int sendMessage(int friendId, const QString& message); + int sendMessage(int friendId, const QString& message); void sendGroupMessage(int groupId, const QString& message); void sendGroupAction(int groupId, const QString& message); - int sendAction(int friendId, const QString& action); + void changeGroupTitle(int groupId, const QString& title); + int sendAction(int friendId, const QString& action); void sendTyping(int friendId, bool typing); void sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize); @@ -157,6 +158,7 @@ signals: void groupInviteReceived(int friendnumber, uint8_t type, QByteArray publicKey); void groupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction); void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change); + void groupTitleChanged(int groupnumber, const QString& author, const QString& title); void usernameSet(const QString& username); void statusMessageSet(const QString& message); @@ -166,6 +168,7 @@ signals: void messageSentResult(int friendId, const QString& message, int messageId); void groupSentResult(int groupId, const QString& message, int result); + void actionSentResult(int friendId, const QString& action, int success); void receiptRecieved(int friedId, int receipt); @@ -221,6 +224,7 @@ private: static void onGroupInvite(Tox *tox, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length,void *userdata); static void onGroupMessage(Tox *tox, int groupnumber, int friendgroupnumber, const uint8_t * message, uint16_t length, void *userdata); static void onGroupNamelistChange(Tox *tox, int groupnumber, int peernumber, uint8_t change, void *userdata); + static void onGroupTitleChange(Tox*, int groupnumber, int peernumber, const uint8_t* title, uint8_t len, void* _core); static void onFileSendRequestCallback(Tox *tox, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *filename, uint16_t filename_length, void *userdata); static void onFileControlCallback(Tox *tox, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, diff --git a/src/group.cpp b/src/group.cpp index 37160fef0..7f517ab41 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -69,3 +69,9 @@ void Group::updatePeer(int peerId, QString name) widget->onUserListChanged(); chatForm->onUserListChanged(); } + +void Group::setName(const QString& name) +{ + widget->setName(name); + chatForm->setName(name); +} diff --git a/src/group.h b/src/group.h index 56c3bebb0..86790b61c 100644 --- a/src/group.h +++ b/src/group.h @@ -35,6 +35,7 @@ public: void addPeer(int peerId, QString name); void removePeer(int peerId); void updatePeer(int peerId, QString newName); + void setName(const QString& name); public: int groupId; diff --git a/src/widget/form/groupchatform.cpp b/src/widget/form/groupchatform.cpp index 28e295f98..0731cf278 100644 --- a/src/widget/form/groupchatform.cpp +++ b/src/widget/form/groupchatform.cpp @@ -52,6 +52,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup) } nameLabel->setText(group->widget->getName()); + nameLabel->setEditable(true); nusersLabel->setFont(Style::getFont(Style::Medium)); nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size())); @@ -80,6 +81,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup) connect(callButton, &QPushButton::clicked, this, &GroupChatForm::onCallClicked); connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle())); connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle())); + connect(nameLabel, &CroppingLabel::textChanged, this, [=](QString s, QString) {emit groupTitleChanged(group->groupId, s);} ); setAcceptDrops(true); } diff --git a/src/widget/form/groupchatform.h b/src/widget/form/groupchatform.h index d89c82730..221b1ceae 100644 --- a/src/widget/form/groupchatform.h +++ b/src/widget/form/groupchatform.h @@ -35,6 +35,9 @@ public: void keyPressEvent(QKeyEvent* ev); void keyReleaseEvent(QKeyEvent* ev); +signals: + void groupTitleChanged(int groupnum, const QString& name); + private slots: void onSendTriggered(); void onMicMuteToggle(); diff --git a/src/widget/groupwidget.cpp b/src/widget/groupwidget.cpp index 3e9f149f0..dd52cce94 100644 --- a/src/widget/groupwidget.cpp +++ b/src/widget/groupwidget.cpp @@ -137,3 +137,8 @@ void GroupWidget::keyReleaseEvent(QKeyEvent* ev) if (g) g->chatForm->keyReleaseEvent(ev); } + +void GroupWidget::setName(const QString& name) +{ + nameLabel->setText(name); +} diff --git a/src/widget/groupwidget.h b/src/widget/groupwidget.h index eeb14dae0..53cba6ac8 100644 --- a/src/widget/groupwidget.h +++ b/src/widget/groupwidget.h @@ -32,6 +32,7 @@ public: void updateStatusLight(); void setChatForm(Ui::MainWindow &); void resetEventFlags(); + void setName(const QString& name); signals: void groupWidgetClicked(GroupWidget* widget); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index e4c9fb91c..d951682f1 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -222,6 +222,7 @@ void Widget::init() connect(core, &Core::groupInviteReceived, this, &Widget::onGroupInviteReceived); connect(core, &Core::groupMessageReceived, this, &Widget::onGroupMessageReceived); connect(core, &Core::groupNamelistChanged, this, &Widget::onGroupNamelistChanged); + connect(core, &Core::groupTitleChanged, this, &Widget::onGroupTitleChanged); connect(core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated); connect(core, &Core::avInvite, this, &Widget::playRingtone); connect(core, &Core::blockingClearContacts, this, &Widget::clearContactsList, Qt::BlockingQueuedConnection); @@ -847,7 +848,7 @@ void Widget::removeFriend(Friend* f, bool fake) FriendList::removeFriend(f->getFriendID(), fake); core->removeFriend(f->getFriendID(), fake); delete f; - if (ui->mainHead->layout()->isEmpty()) // tux3: this should have covered the case of the bug you "fixed" 5 lines above + if (ui->mainHead->layout()->isEmpty()) onAddClicked(); contactListWidget->hide(); @@ -951,6 +952,17 @@ void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Cha g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber)); } +void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const QString& title) +{ + Group* g = GroupList::findGroup(groupnumber); + if (!g) + return; + + g->setName(title); + if (!author.isEmpty()) + g->chatForm->addSystemInfoMessage(tr("%1 has set the title to %2").arg(author, title), "silver", QDateTime::currentDateTime()); +} + void Widget::removeGroup(Group* g, bool fake) { g->widget->setAsInactiveChatroom(); @@ -999,6 +1011,7 @@ Group *Widget::createGroup(int groupId) connect(newgroup->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newgroup->chatForm, SLOT(focusInput())); connect(newgroup->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendGroupMessage(int,QString))); connect(newgroup->chatForm, SIGNAL(sendAction(int,QString)), core, SLOT(sendGroupAction(int,QString))); + connect(newgroup->chatForm, &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle); return newgroup; } @@ -1171,4 +1184,4 @@ void Widget::clearAllReceipts() { f->getChatForm()->clearReciepts(); } -} +} \ No newline at end of file diff --git a/src/widget/widget.h b/src/widget/widget.h index 1131da49a..09a6814a6 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -115,6 +115,7 @@ private slots: void onGroupInviteReceived(int32_t friendId, uint8_t type, QByteArray invite); void onGroupMessageReceived(int groupnumber, const QString& message, const QString& author, bool isAction); void onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t change); + void onGroupTitleChanged(int groupnumber, const QString& author, const QString& title); void removeFriend(int friendId); void copyFriendIdToClipboard(int friendId); void removeGroup(int groupId);