2014-11-03 01:36:27 +08:00
|
|
|
#include "src/corestructs.h"
|
|
|
|
#include "src/core.h"
|
2014-11-06 22:12:10 +08:00
|
|
|
#include <tox/tox.h>
|
2014-09-11 21:44:34 +08:00
|
|
|
#include <QFile>
|
2014-11-06 22:12:10 +08:00
|
|
|
#include <QRegularExpression>
|
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
#define TOX_HEX_ID_LENGTH 2*TOX_ADDRESS_SIZE
|
2014-09-11 21:44:34 +08:00
|
|
|
|
2015-04-20 05:12:44 +08:00
|
|
|
ToxFile::ToxFile(uint32_t FileNum, uint32_t FriendId, QByteArray FileName, QString FilePath, FileDirection Direction)
|
2014-09-11 21:44:34 +08:00
|
|
|
: fileNum(FileNum), friendId(FriendId), fileName{FileName}, filePath{FilePath}, file{new QFile(filePath)},
|
|
|
|
bytesSent{0}, filesize{0}, status{STOPPED}, direction{Direction}, sendTimer{nullptr}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-11-17 23:05:14 +08:00
|
|
|
bool ToxFile::operator==(const ToxFile &other) const
|
|
|
|
{
|
2014-11-18 03:08:55 +08:00
|
|
|
return (fileNum == other.fileNum) && (friendId == other.friendId) && (direction == other.direction);
|
2014-11-17 23:05:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxFile::operator!=(const ToxFile &other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:44:34 +08:00
|
|
|
void ToxFile::setFilePath(QString path)
|
|
|
|
{
|
|
|
|
filePath=path;
|
|
|
|
file->setFileName(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxFile::open(bool write)
|
|
|
|
{
|
|
|
|
return write ? file->open(QIODevice::ReadWrite) : file->open(QIODevice::ReadOnly);
|
|
|
|
}
|
2014-11-03 01:36:27 +08:00
|
|
|
|
2015-01-30 04:23:33 +08:00
|
|
|
ToxID::ToxID(const ToxID& other)
|
|
|
|
{
|
|
|
|
publicKey = other.publicKey;
|
|
|
|
noSpam = other.noSpam;
|
|
|
|
checkSum = other.checkSum;
|
|
|
|
}
|
|
|
|
|
2014-11-03 01:36:27 +08:00
|
|
|
QString ToxID::toString() const
|
|
|
|
{
|
|
|
|
return publicKey + noSpam + checkSum;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToxID ToxID::fromString(QString id)
|
|
|
|
{
|
|
|
|
ToxID toxID;
|
|
|
|
toxID.publicKey = id.left(TOX_ID_PUBLIC_KEY_LENGTH);
|
|
|
|
toxID.noSpam = id.mid(TOX_ID_PUBLIC_KEY_LENGTH, TOX_ID_NO_SPAM_LENGTH);
|
2014-11-12 00:35:45 +08:00
|
|
|
toxID.checkSum = id.mid(TOX_ID_PUBLIC_KEY_LENGTH + TOX_ID_NO_SPAM_LENGTH, TOX_ID_CHECKSUM_LENGTH);
|
2014-11-03 01:36:27 +08:00
|
|
|
return toxID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ToxID::operator==(const ToxID& other) const
|
|
|
|
{
|
|
|
|
return publicKey == other.publicKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxID::operator!=(const ToxID& other) const
|
|
|
|
{
|
|
|
|
return publicKey != other.publicKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ToxID::isMine() const
|
|
|
|
{
|
|
|
|
return *this == Core::getInstance()->getSelfId();
|
|
|
|
}
|
2014-11-06 22:12:10 +08:00
|
|
|
|
2014-11-16 19:40:44 +08:00
|
|
|
void ToxID::clear()
|
|
|
|
{
|
|
|
|
publicKey.clear();
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:12:10 +08:00
|
|
|
bool ToxID::isToxId(const QString& value)
|
|
|
|
{
|
|
|
|
const QRegularExpression hexRegExp("^[A-Fa-f0-9]+$");
|
2015-04-20 05:12:44 +08:00
|
|
|
return value.length() == TOX_HEX_ID_LENGTH && value.contains(hexRegExp);
|
2014-11-06 22:12:10 +08:00
|
|
|
}
|