diff --git a/src/core/core.cpp b/src/core/core.cpp index 2d70c9e70..92509d53d 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -44,6 +44,26 @@ const QString Core::TOX_EXT = ".tox"; #define ASSERT_CORE_THREAD assert(QThread::currentThread() == coreThread.get()) +namespace { + bool LogConferenceTitleError(TOX_ERR_CONFERENCE_TITLE error) + { + switch(error) + { + case TOX_ERR_CONFERENCE_TITLE_OK: + break; + case TOX_ERR_CONFERENCE_TITLE_CONFERENCE_NOT_FOUND: + qWarning() << "Conference title not found"; + break; + case TOX_ERR_CONFERENCE_TITLE_INVALID_LENGTH: + qWarning() << "Invalid conference title length"; + break; + case TOX_ERR_CONFERENCE_TITLE_FAIL_SEND: + qWarning() << "Failed to send title packet"; + } + return error; + } +} // namespace + Core::Core(QThread* coreThread) : tox(nullptr) , av(nullptr) @@ -451,8 +471,7 @@ void Core::onGroupInvite(Tox* tox, uint32_t friendId, Tox_Conference_Type type, const uint8_t* cookie, size_t length, void* vCore) { Core* core = static_cast(vCore); - // static_cast is used twice to replace using unsafe reinterpret_cast - const QByteArray data(static_cast(static_cast(cookie)), length); + const QByteArray data(reinterpret_cast(cookie), length); const GroupInvite inviteInfo(friendId, type, data); switch (type) { case TOX_CONFERENCE_TYPE_TEXT: @@ -1025,7 +1044,18 @@ void Core::loadGroups() tox_conference_get_chatlist(tox.get(), groupIds); for(size_t i = 0; i < groupCount; ++i) { - emit emptyGroupCreated(static_cast(groupIds[i])); + TOX_ERR_CONFERENCE_TITLE error; + size_t titleSize = tox_conference_get_title_size(tox.get(), groupIds[i], &error); + if (LogConferenceTitleError(error)) { + continue; + } + + QByteArray name(titleSize, Qt::Uninitialized); + if (!tox_conference_get_title(tox.get(), groupIds[i], reinterpret_cast(name.data()), &error)) + if (LogConferenceTitleError(error)) { + continue; + } + emit emptyGroupCreated(static_cast(groupIds[i]), ToxString(name).getQString()); } delete[] groupIds; @@ -1114,7 +1144,7 @@ QString Core::getGroupPeerName(int groupId, int peerId) const } QByteArray name(length, Qt::Uninitialized); - uint8_t* namePtr = static_cast(static_cast(name.data())); + uint8_t* namePtr = reinterpret_cast(name.data()); bool success = tox_conference_peer_get_name(tox.get(), groupId, peerId, namePtr, &error); if (!parsePeerQueryError(error) || !success) { qWarning() << "getGroupPeerName: Unknown error"; @@ -1179,7 +1209,7 @@ QStringList Core::getGroupPeerNames(int groupId) const } QByteArray name(length, Qt::Uninitialized); - uint8_t* namePtr = static_cast(static_cast(name.data())); + uint8_t* namePtr = reinterpret_cast(name.data()); bool ok = tox_conference_peer_get_name(tox.get(), groupId, i, namePtr, &error); if (ok && parsePeerQueryError(error)) { names.append(ToxString(name).getQString()); @@ -1267,7 +1297,7 @@ uint32_t Core::joinGroupchat(const GroupInvite& inviteInfo) const const uint32_t friendId = inviteInfo.getFriendId(); const uint8_t confType = inviteInfo.getType(); const QByteArray invite = inviteInfo.getInvite(); - const uint8_t* const cookie = static_cast(static_cast(invite.data())); + const uint8_t* const cookie = reinterpret_cast(invite.data()); const size_t cookieLength = invite.length(); switch (confType) { case TOX_CONFERENCE_TYPE_TEXT: { diff --git a/src/core/core.h b/src/core/core.h index 1799c288a..67bd2ccf8 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -190,7 +190,7 @@ signals: void friendRemoved(uint32_t friendId); void friendLastSeenChanged(uint32_t friendId, const QDateTime& dateTime); - void emptyGroupCreated(int groupnumber); + void emptyGroupCreated(int groupnumber, const QString& title = QString()); void groupInviteReceived(const GroupInvite& inviteInfo); void groupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction); void groupNamelistChanged(int groupnumber, int peernumber, uint8_t change); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 459403759..719b65c76 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1907,16 +1907,19 @@ Group* Widget::createGroup(int groupId) return newgroup; } -void Widget::onEmptyGroupCreated(int groupId) +void Widget::onEmptyGroupCreated(int groupId, const QString& title) { Group* group = createGroup(groupId); if (!group) { return; } - - // Only rename group if groups are visible. - if (Widget::getInstance()->groupsVisible()) { - groupWidgets[groupId]->editName(); + if (title.isEmpty()) { + // Only rename group if groups are visible. + if (Widget::getInstance()->groupsVisible()) { + groupWidgets[groupId]->editName(); + } + } else { + group->setTitle(QString(), title); } } diff --git a/src/widget/widget.h b/src/widget/widget.h index 8db6c6611..06d5877bc 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -167,7 +167,7 @@ public slots: void updateFriendActivity(const Friend* frnd); void onMessageSendResult(uint32_t friendId, const QString& message, int messageId); void onReceiptRecieved(int friendId, int receipt); - void onEmptyGroupCreated(int groupId); + void onEmptyGroupCreated(int groupId, const QString& title); void onGroupInviteReceived(const GroupInvite& inviteInfo); void onGroupInviteAccepted(const GroupInvite& inviteInfo); void onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction);