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

group title support

This commit is contained in:
dubslow 2014-11-05 18:22:50 -06:00 committed by Tux3 / Mlkj / !Lev.uXFMLA
parent 3bc6909c96
commit 71c34b9d69
10 changed files with 59 additions and 4 deletions

View File

@ -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*>(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*>(_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);

View File

@ -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,

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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();

View File

@ -137,3 +137,8 @@ void GroupWidget::keyReleaseEvent(QKeyEvent* ev)
if (g)
g->chatForm->keyReleaseEvent(ev);
}
void GroupWidget::setName(const QString& name)
{
nameLabel->setText(name);
}

View File

@ -32,6 +32,7 @@ public:
void updateStatusLight();
void setChatForm(Ui::MainWindow &);
void resetEventFlags();
void setName(const QString& name);
signals:
void groupWidgetClicked(GroupWidget* widget);

View File

@ -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();
}
}
}

View File

@ -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);