mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
94f9a6d431
46
core.cpp
46
core.cpp
|
@ -34,6 +34,7 @@
|
|||
#include <QTimer>
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
|
||||
const QString Core::CONFIG_FILE_NAME = "data";
|
||||
QList<ToxFile> Core::fileSendQueue;
|
||||
|
@ -473,10 +474,13 @@ void Core::requestFriendship(const QString& friendAddress, const QString& messag
|
|||
|
||||
void Core::sendMessage(int friendId, const QString& message)
|
||||
{
|
||||
CString cMessage(message);
|
||||
QList<CString> cMessages = splitMessage(message);
|
||||
|
||||
int messageId = tox_send_message(tox, friendId, cMessage.data(), cMessage.size());
|
||||
emit messageSentResult(friendId, message, messageId);
|
||||
for (auto &cMsg :cMessages)
|
||||
{
|
||||
int messageId = tox_send_message(tox, friendId, cMsg.data(), cMsg.size());
|
||||
emit messageSentResult(friendId, message, messageId);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::sendAction(int friendId, const QString &action)
|
||||
|
@ -495,9 +499,12 @@ void Core::sendTyping(int friendId, bool typing)
|
|||
|
||||
void Core::sendGroupMessage(int groupId, const QString& message)
|
||||
{
|
||||
CString cMessage(message);
|
||||
QList<CString> cMessages = splitMessage(message);
|
||||
|
||||
tox_group_message_send(tox, groupId, cMessage.data(), cMessage.size());
|
||||
for (auto &cMsg :cMessages)
|
||||
{
|
||||
tox_group_message_send(tox, groupId, cMsg.data(), cMsg.size());
|
||||
}
|
||||
}
|
||||
|
||||
void Core::sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize)
|
||||
|
@ -1159,3 +1166,32 @@ QString Core::getFriendAddress(int friendNumber) const
|
|||
|
||||
return id;
|
||||
}
|
||||
|
||||
QList<CString> Core::splitMessage(const QString &message)
|
||||
{
|
||||
QList<CString> splittedMsgs;
|
||||
QByteArray ba_message(message.toUtf8());
|
||||
|
||||
while (ba_message.size() > TOX_MAX_MESSAGE_LENGTH)
|
||||
{
|
||||
int splitPos = ba_message.lastIndexOf(' ', TOX_MAX_MESSAGE_LENGTH - 1);
|
||||
if (splitPos <= 0)
|
||||
{
|
||||
splitPos = TOX_MAX_MESSAGE_LENGTH;
|
||||
if (ba_message[splitPos] & 0x80)
|
||||
{
|
||||
do {
|
||||
splitPos--;
|
||||
} while (!(ba_message[splitPos] & 0x40));
|
||||
}
|
||||
splitPos--;
|
||||
}
|
||||
|
||||
splittedMsgs.push_back(CString(ba_message.left(splitPos + 1)));
|
||||
ba_message = ba_message.mid(splitPos + 1);
|
||||
}
|
||||
|
||||
splittedMsgs.push_back(CString(ba_message));
|
||||
|
||||
return splittedMsgs;
|
||||
}
|
||||
|
|
3
core.h
3
core.h
|
@ -28,6 +28,7 @@ template <typename T> class QList;
|
|||
class Camera;
|
||||
class QTimer;
|
||||
class QString;
|
||||
class CString;
|
||||
|
||||
class Core : public QObject
|
||||
{
|
||||
|
@ -210,6 +211,8 @@ private:
|
|||
|
||||
void checkLastOnline(int friendId);
|
||||
|
||||
QList<CString> splitMessage(const QString &message);
|
||||
|
||||
private slots:
|
||||
void onFileTransferFinished(ToxFile file);
|
||||
|
||||
|
|
19
cstring.cpp
19
cstring.cpp
|
@ -17,10 +17,23 @@
|
|||
#include "cstring.h"
|
||||
#include <QString>
|
||||
|
||||
CString::CString(const QString& string)
|
||||
CString::CString(const QString& string) :
|
||||
CString(string.toUtf8())
|
||||
{
|
||||
cString = new uint8_t[string.length() * MAX_SIZE_OF_UTF8_ENCODED_CHARACTER]();
|
||||
cStringSize = fromString(string, cString);
|
||||
}
|
||||
|
||||
CString::CString(const QByteArray& ba_string)
|
||||
{
|
||||
cString = new uint8_t[ba_string.size()]();
|
||||
cStringSize = ba_string.size();
|
||||
memcpy(cString, reinterpret_cast<const uint8_t*>(ba_string.data()), cStringSize);
|
||||
}
|
||||
|
||||
CString::CString(const CString &cstr)
|
||||
{
|
||||
cStringSize = cstr.cStringSize;
|
||||
cString = new uint8_t[cStringSize]();
|
||||
memcpy(cString, cstr.cString, cStringSize);
|
||||
}
|
||||
|
||||
CString::~CString()
|
||||
|
|
Loading…
Reference in New Issue
Block a user