mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(core): replace CString with ToxString
This commit is contained in:
parent
1f0467bb1b
commit
25c279c320
|
@ -22,6 +22,7 @@
|
|||
#include "corefile.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/core/cstring.h"
|
||||
#include "src/core/toxstring.h"
|
||||
#include "src/net/avatarbroadcaster.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
|
@ -421,7 +422,7 @@ void Core::onFriendRequest(Tox* /* tox*/, const uint8_t* cFriendPk, const uint8_
|
|||
{
|
||||
ToxPk friendPk(cFriendPk);
|
||||
emit static_cast<Core*>(core)->friendRequestReceived(friendPk,
|
||||
CString::toString(cMessage, cMessageSize));
|
||||
ToxString(cMessage, cMessageSize).getQString());
|
||||
}
|
||||
|
||||
void Core::onFriendMessage(Tox* /* tox*/, uint32_t friendId, TOX_MESSAGE_TYPE type,
|
||||
|
@ -429,14 +430,14 @@ void Core::onFriendMessage(Tox* /* tox*/, uint32_t friendId, TOX_MESSAGE_TYPE ty
|
|||
{
|
||||
bool isAction = (type == TOX_MESSAGE_TYPE_ACTION);
|
||||
emit static_cast<Core*>(core)->friendMessageReceived(friendId,
|
||||
CString::toString(cMessage, cMessageSize),
|
||||
ToxString(cMessage, cMessageSize).getQString(),
|
||||
isAction);
|
||||
}
|
||||
|
||||
void Core::onFriendNameChange(Tox* /* tox*/, uint32_t friendId, const uint8_t* cName,
|
||||
size_t cNameSize, void* core)
|
||||
{
|
||||
emit static_cast<Core*>(core)->friendUsernameChanged(friendId, CString::toString(cName, cNameSize));
|
||||
emit static_cast<Core*>(core)->friendUsernameChanged(friendId, ToxString(cName, cNameSize).getQString());
|
||||
}
|
||||
|
||||
void Core::onFriendTypingChange(Tox* /* tox*/, uint32_t friendId, bool isTyping, void* core)
|
||||
|
@ -448,7 +449,7 @@ void Core::onStatusMessageChanged(Tox* /* tox*/, uint32_t friendId, const uint8_
|
|||
size_t cMessageSize, void* core)
|
||||
{
|
||||
emit static_cast<Core*>(core)->friendStatusMessageChanged(friendId,
|
||||
CString::toString(cMessage, cMessageSize));
|
||||
ToxString(cMessage, cMessageSize).getQString());
|
||||
}
|
||||
|
||||
void Core::onUserStatusChanged(Tox* /* tox*/, uint32_t friendId, TOX_USER_STATUS userstatus, void* core)
|
||||
|
@ -504,9 +505,8 @@ void Core::onGroupMessage(Tox*, uint32_t groupId, uint32_t peerId, TOX_MESSAGE_T
|
|||
const uint8_t* cMessage, size_t length, void* vCore)
|
||||
{
|
||||
Core* core = static_cast<Core*>(vCore);
|
||||
QString message = CString::toString(cMessage, length);
|
||||
bool isAction = type == TOX_MESSAGE_TYPE_ACTION;
|
||||
emit core->groupMessageReceived(groupId, peerId, message, isAction);
|
||||
emit core->groupMessageReceived(groupId, peerId, ToxString(cMessage, length).getQString(), isAction);
|
||||
}
|
||||
|
||||
void Core::onGroupNamelistChange(Tox*, uint32_t groupId, uint32_t peerId,
|
||||
|
@ -525,8 +525,7 @@ void Core::onGroupTitleChange(Tox*, uint32_t groupId, uint32_t peerId, const uin
|
|||
{
|
||||
Core* core = static_cast<Core*>(vCore);
|
||||
QString author = core->getGroupPeerName(groupId, peerId);
|
||||
QString title = CString::toString(cTitle, length);
|
||||
emit core->groupTitleChanged(groupId, author, title);
|
||||
emit core->groupTitleChanged(groupId, author, ToxString(cTitle, length).getQString());
|
||||
}
|
||||
|
||||
void Core::onReadReceiptCallback(Tox*, uint32_t friendId, uint32_t receipt, void* core)
|
||||
|
@ -560,7 +559,7 @@ void Core::requestFriendship(const ToxId& friendAddress, const QString& message)
|
|||
} else if (hasFriendWithPublicKey(friendPk)) {
|
||||
emit failedToAddFriend(friendPk, tr("Friend is already added"));
|
||||
} else {
|
||||
CString cMessage(message);
|
||||
ToxString cMessage(message);
|
||||
|
||||
uint32_t friendId =
|
||||
tox_friend_add(tox, friendAddress.getBytes(), cMessage.data(), cMessage.size(), nullptr);
|
||||
|
@ -595,7 +594,7 @@ void Core::requestFriendship(const ToxId& friendAddress, const QString& message)
|
|||
int Core::sendMessage(uint32_t friendId, const QString& message)
|
||||
{
|
||||
QMutexLocker ml(&messageSendMutex);
|
||||
CString cMessage(message);
|
||||
ToxString cMessage(message);
|
||||
int receipt = tox_friend_send_message(tox, friendId, TOX_MESSAGE_TYPE_NORMAL, cMessage.data(),
|
||||
cMessage.size(), nullptr);
|
||||
emit messageSentResult(friendId, message, receipt);
|
||||
|
@ -605,7 +604,7 @@ int Core::sendMessage(uint32_t friendId, const QString& message)
|
|||
int Core::sendAction(uint32_t friendId, const QString& action)
|
||||
{
|
||||
QMutexLocker ml(&messageSendMutex);
|
||||
CString cMessage(action);
|
||||
ToxString cMessage(action);
|
||||
int receipt = tox_friend_send_message(tox, friendId, TOX_MESSAGE_TYPE_ACTION, cMessage.data(),
|
||||
cMessage.size(), nullptr);
|
||||
emit messageSentResult(friendId, action, receipt);
|
||||
|
@ -621,9 +620,10 @@ void Core::sendTyping(uint32_t friendId, bool typing)
|
|||
|
||||
void Core::sendGroupMessageWithType(int groupId, const QString& message, TOX_MESSAGE_TYPE type)
|
||||
{
|
||||
QList<CString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
|
||||
QList<QString> cMessages = splitMessage(message, MAX_GROUP_MESSAGE_LEN);
|
||||
|
||||
for (auto& cMsg : cMessages) {
|
||||
for (auto& part : cMessages) {
|
||||
ToxString cMsg(part);
|
||||
TOX_ERR_CONFERENCE_SEND_MESSAGE error;
|
||||
bool success =
|
||||
tox_conference_send_message(tox, groupId, type, cMsg.data(), cMsg.size(), &error);
|
||||
|
@ -665,7 +665,7 @@ void Core::sendGroupAction(int groupId, const QString& message)
|
|||
|
||||
void Core::changeGroupTitle(int groupId, const QString& title)
|
||||
{
|
||||
CString cTitle(title);
|
||||
ToxString cTitle(title);
|
||||
TOX_ERR_CONFERENCE_TITLE error;
|
||||
bool success = tox_conference_set_title(tox, groupId, cTitle.data(), cTitle.size(), &error);
|
||||
|
||||
|
@ -778,7 +778,7 @@ QString Core::getUsername() const
|
|||
int size = tox_self_get_name_size(tox);
|
||||
uint8_t* name = new uint8_t[size];
|
||||
tox_self_get_name(tox, name);
|
||||
sname = CString::toString(name, size);
|
||||
sname = ToxString(name, size).getQString();
|
||||
delete[] name;
|
||||
return sname;
|
||||
}
|
||||
|
@ -788,7 +788,7 @@ void Core::setUsername(const QString& username)
|
|||
if (username == getUsername())
|
||||
return;
|
||||
|
||||
CString cUsername(username);
|
||||
ToxString cUsername(username);
|
||||
|
||||
if (!tox_self_set_name(tox, cUsername.data(), cUsername.size(), nullptr)) {
|
||||
emit failedToSetUsername(username);
|
||||
|
@ -856,7 +856,7 @@ QString Core::getStatusMessage() const
|
|||
size_t size = tox_self_get_status_message_size(tox);
|
||||
uint8_t* name = new uint8_t[size];
|
||||
tox_self_get_status_message(tox, name);
|
||||
sname = CString::toString(name, size);
|
||||
sname = ToxString(name, size).getQString();
|
||||
delete[] name;
|
||||
return sname;
|
||||
}
|
||||
|
@ -874,7 +874,7 @@ void Core::setStatusMessage(const QString& message)
|
|||
if (message == getStatusMessage())
|
||||
return;
|
||||
|
||||
CString cMessage(message);
|
||||
ToxString cMessage(message);
|
||||
|
||||
if (!tox_self_set_status_message(tox, cMessage.data(), cMessage.size(), nullptr)) {
|
||||
emit failedToSetStatusMessage(message);
|
||||
|
@ -954,7 +954,7 @@ void Core::loadFriends()
|
|||
if (nameSize && nameSize != SIZE_MAX) {
|
||||
uint8_t* name = new uint8_t[nameSize];
|
||||
if (tox_friend_get_name(tox, ids[i], name, nullptr))
|
||||
emit friendUsernameChanged(ids[i], CString::toString(name, nameSize));
|
||||
emit friendUsernameChanged(ids[i], ToxString(name, nameSize).getQString());
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
|
@ -963,8 +963,8 @@ void Core::loadFriends()
|
|||
if (statusMessageSize != SIZE_MAX) {
|
||||
uint8_t* statusMessage = new uint8_t[statusMessageSize];
|
||||
if (tox_friend_get_status_message(tox, ids[i], statusMessage, nullptr)) {
|
||||
emit friendStatusMessageChanged(ids[i], CString::toString(statusMessage,
|
||||
statusMessageSize));
|
||||
emit friendStatusMessageChanged(ids[i], ToxString(statusMessage,
|
||||
statusMessageSize).getQString());
|
||||
}
|
||||
delete[] statusMessage;
|
||||
}
|
||||
|
@ -1050,7 +1050,7 @@ QString Core::getGroupPeerName(int groupId, int peerId) const
|
|||
return QString{};
|
||||
}
|
||||
|
||||
return CString::toString(nameArray, length);
|
||||
return ToxString(nameArray, length).getQString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1106,7 +1106,7 @@ QList<QString> Core::getGroupPeerNames(int groupId) const
|
|||
lengths[i] = tox_conference_peer_get_name_size(tox, groupId, i, &error);
|
||||
bool ok = tox_conference_peer_get_name(tox, groupId, i, namesArray[i], &error);
|
||||
if (parsePeerQueryError(error) && ok) {
|
||||
names.push_back(CString::toString(namesArray[i], lengths[i]));
|
||||
names.push_back(ToxString(namesArray[i], lengths[i]).getQString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1292,14 +1292,14 @@ QString Core::getFriendUsername(uint32_t friendnumber) const
|
|||
}
|
||||
uint8_t* name = new uint8_t[namesize];
|
||||
tox_friend_get_name(tox, friendnumber, name, nullptr);
|
||||
QString sname = CString::toString(name, namesize);
|
||||
ToxString sname(name, namesize);
|
||||
delete[] name;
|
||||
return sname;
|
||||
return sname.getQString();
|
||||
}
|
||||
|
||||
QList<CString> Core::splitMessage(const QString& message, int maxLen)
|
||||
QList<QString> Core::splitMessage(const QString& message, int maxLen)
|
||||
{
|
||||
QList<CString> splittedMsgs;
|
||||
QList<QString> splittedMsgs;
|
||||
QByteArray ba_message(message.toUtf8());
|
||||
|
||||
while (ba_message.size() > maxLen) {
|
||||
|
@ -1314,11 +1314,11 @@ QList<CString> Core::splitMessage(const QString& message, int maxLen)
|
|||
splitPos--;
|
||||
}
|
||||
|
||||
splittedMsgs.push_back(CString(ba_message.left(splitPos + 1)));
|
||||
splittedMsgs.push_back(QString(ba_message.left(splitPos + 1)));
|
||||
ba_message = ba_message.mid(splitPos + 1);
|
||||
}
|
||||
|
||||
splittedMsgs.push_back(CString(ba_message));
|
||||
splittedMsgs.push_back(QString(ba_message));
|
||||
|
||||
return splittedMsgs;
|
||||
}
|
||||
|
@ -1343,7 +1343,7 @@ QString Core::getPeerName(const ToxPk& id) const
|
|||
return name;
|
||||
}
|
||||
|
||||
name = CString::toString(cname, nameSize);
|
||||
name = ToxString(cname, nameSize).getQString();
|
||||
delete[] cname;
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ template <typename T>
|
|||
class QList;
|
||||
class QTimer;
|
||||
class QString;
|
||||
class CString;
|
||||
struct ToxAV;
|
||||
class CoreAV;
|
||||
struct vpx_image;
|
||||
|
@ -54,7 +53,7 @@ public:
|
|||
static const QString TOX_EXT;
|
||||
static const QString CONFIG_FILE_NAME;
|
||||
static QString sanitize(QString name);
|
||||
static QList<CString> splitMessage(const QString& message, int maxLen);
|
||||
static QList<QString> splitMessage(const QString& message, int maxLen);
|
||||
|
||||
static QByteArray getSaltFromFile(QString filename);
|
||||
|
||||
|
|
|
@ -1010,23 +1010,22 @@ void ChatForm::SendMessageStr(QString msg)
|
|||
msg.remove(0, ACTION_PREFIX.length());
|
||||
}
|
||||
|
||||
QList<CString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
||||
QList<QString> splittedMsg = Core::splitMessage(msg, TOX_MAX_MESSAGE_LENGTH);
|
||||
QDateTime timestamp = QDateTime::currentDateTime();
|
||||
|
||||
for (CString& c_msg : splittedMsg) {
|
||||
QString qt_msg = CString::toString(c_msg.data(), c_msg.size());
|
||||
QString qt_msg_hist = qt_msg;
|
||||
for (QString& part : splittedMsg) {
|
||||
QString historyPart = part;
|
||||
if (isAction) {
|
||||
qt_msg_hist = ACTION_PREFIX + qt_msg;
|
||||
historyPart = ACTION_PREFIX + part;
|
||||
}
|
||||
|
||||
bool status = !Settings::getInstance().getFauxOfflineMessaging();
|
||||
|
||||
ChatMessage::Ptr ma = addSelfMessage(qt_msg, isAction, timestamp, false);
|
||||
ChatMessage::Ptr ma = addSelfMessage(part, isAction, timestamp, false);
|
||||
|
||||
Core* core = Core::getInstance();
|
||||
uint32_t friendId = f->getFriendId();
|
||||
int rec = isAction ? core->sendAction(friendId, qt_msg) : core->sendMessage(friendId, qt_msg);
|
||||
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
|
||||
|
||||
Profile* profile = Nexus::getProfile();
|
||||
if (profile->isHistoryEnabled()) {
|
||||
|
@ -1034,7 +1033,7 @@ void ChatForm::SendMessageStr(QString msg)
|
|||
QString selfPk = Core::getInstance()->getSelfId().toString();
|
||||
QString pk = f->getPublicKey().toString();
|
||||
QString name = Core::getInstance()->getUsername();
|
||||
profile->getHistory()->addNewMessage(pk, qt_msg_hist, selfPk, timestamp, status, name,
|
||||
profile->getHistory()->addNewMessage(pk, historyPart, selfPk, timestamp, status, name,
|
||||
[offMsgEngine, rec, ma](int64_t id) {
|
||||
offMsgEngine->registerReceipt(rec, id, ma);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user