Browse Source

refactor(files): change ToxFile's fileName to QString

reviewable/pr5354/r12
Anthony Bilinski 7 years ago
parent
commit
84362244da
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 10
      src/core/corefile.cpp
  2. 2
      src/core/toxfile.cpp
  3. 4
      src/core/toxfile.h
  4. 14
      src/persistence/history.cpp
  5. 4
      src/persistence/history.h

10
src/core/corefile.cpp

@ -108,7 +108,6 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d @@ -108,7 +108,6 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d
ToxFile file{fileNum, friendId, "", "", ToxFile::SENDING};
file.filesize = filesize;
file.fileName = QByteArray((char*)avatarHash, TOX_HASH_LENGTH);
file.fileKind = TOX_FILE_KIND_AVATAR;
file.avatarData = data;
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
@ -121,19 +120,18 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString filename, QString @@ -121,19 +120,18 @@ void CoreFile::sendFile(Core* core, uint32_t friendId, QString filename, QString
long long filesize)
{
QMutexLocker mlocker(&fileSendMutex);
QByteArray fileName = filename.toUtf8();
ToxString fileName(filename);
TOX_ERR_FILE_SEND sendErr;
uint32_t fileNum = tox_file_send(core->tox.get(), friendId, TOX_FILE_KIND_DATA, filesize,
nullptr, (uint8_t*)fileName.data(), fileName.size(), &sendErr);
nullptr, fileName.data(), fileName.size(), &sendErr);
if (sendErr != TOX_ERR_FILE_SEND_OK) {
qWarning() << "sendFile: Can't create the Tox file sender (" << sendErr << ")";
emit core->fileSendFailed(friendId, filename);
emit core->fileSendFailed(friendId, fileName.getQString());
return;
}
qDebug() << QString("sendFile: Created file sender %1 with friend %2").arg(fileNum).arg(friendId);
ToxFile file{fileNum, friendId, fileName, filePath, ToxFile::SENDING};
ToxFile file{fileNum, friendId, fileName.getQString(), filePath, ToxFile::SENDING};
file.filesize = filesize;
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
tox_file_get_file_id(core->tox.get(), friendId, fileNum, (uint8_t*)file.resumeFileId.data(),

2
src/core/toxfile.cpp

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
/**
* @brief ToxFile constructor
*/
ToxFile::ToxFile(uint32_t fileNum, uint32_t friendId, QByteArray filename, QString filePath,
ToxFile::ToxFile(uint32_t fileNum, uint32_t friendId, QString filename, QString filePath,
FileDirection Direction)
: fileKind{TOX_FILE_KIND_DATA}
, fileNum(fileNum)

4
src/core/toxfile.h

@ -31,7 +31,7 @@ struct ToxFile @@ -31,7 +31,7 @@ struct ToxFile
};
ToxFile() = default;
ToxFile(uint32_t FileNum, uint32_t FriendId, QByteArray FileName, QString filePath,
ToxFile(uint32_t FileNum, uint32_t FriendId, QString FileName, QString filePath,
FileDirection Direction);
bool operator==(const ToxFile& other) const;
@ -43,7 +43,7 @@ struct ToxFile @@ -43,7 +43,7 @@ struct ToxFile
uint8_t fileKind;
uint32_t fileNum;
uint32_t friendId;
QByteArray fileName;
QString fileName;
QString filePath;
std::shared_ptr<QFile> file;
quint64 bytesSent;

14
src/persistence/history.cpp

@ -287,7 +287,7 @@ void History::onFileInsertionReady(FileDbInsertionData data) @@ -287,7 +287,7 @@ void History::onFileInsertionReady(FileDbInsertionData data)
.arg(data.size)
.arg(static_cast<int>(data.direction))
.arg(ToxFile::CANCELED),
{data.fileId.toUtf8(), data.filePath.toUtf8(), data.fileName, QByteArray()},
{data.fileId.toUtf8(), data.filePath.toUtf8(), data.fileName.toUtf8(), QByteArray()},
[weakThis, fileId](int64_t id) {
auto pThis = weakThis.lock();
if (pThis) {
@ -338,7 +338,7 @@ RawDatabase::Query History::generateFileFinished(int64_t id, bool success, const @@ -338,7 +338,7 @@ RawDatabase::Query History::generateFileFinished(int64_t id, bool success, const
}
void History::addNewFileMessage(const QString& friendPk, const QString& fileId,
const QByteArray& fileName, const QString& filePath, int64_t size,
const QString& fileName, const QString& filePath, int64_t size,
const QString& sender, const QDateTime& time, QString const& dispName)
{
// This is an incredibly far from an optimal way of implementing this,
@ -644,16 +644,14 @@ QList<History::HistMessage> History::getChatHistory(const QString& friendPk, con @@ -644,16 +644,14 @@ QList<History::HistMessage> History::getChatHistory(const QString& friendPk, con
auto display_name = QString::fromUtf8(row[4].toByteArray().replace('\0', ""));
auto sender_key = row[5].toString();
if (row[7].isNull()) {
messages += {id, isOfflineMessage, timestamp, friend_key,
display_name, sender_key, row[6].toString()};
messages +=
{id, isOfflineMessage, timestamp, friend_key, display_name, sender_key, row[6].toString()};
} else {
ToxFile file;
file.fileKind = TOX_FILE_KIND_DATA;
file.resumeFileId = row[7].toString().toUtf8();
file.filePath = QString::fromUtf8(row[8].toByteArray().replace('\0', ""));
file.fileName =
QString::fromUtf8(row[9].toByteArray())
.toUtf8(); // for some reason the path has to be utf8 parsed even though it went in as a straight array
file.filePath = row[8].toString();
file.fileName = row[9].toString();
file.filesize = row[10].toLongLong();
file.direction = static_cast<ToxFile::FileDirection>(row[11].toLongLong());
file.status = static_cast<ToxFile::FileStatus>(row[12].toInt());

4
src/persistence/history.h

@ -98,7 +98,7 @@ struct FileDbInsertionData @@ -98,7 +98,7 @@ struct FileDbInsertionData
int64_t historyId;
QString friendPk;
QString fileId;
QByteArray fileName;
QString fileName;
QString filePath;
int64_t size;
int direction;
@ -164,7 +164,7 @@ public: @@ -164,7 +164,7 @@ public:
const std::function<void(int64_t)>& insertIdCallback = {});
void addNewFileMessage(const QString& friendPk, const QString& fileId,
const QByteArray& fileName, const QString& filePath, int64_t size,
const QString& fileName, const QString& filePath, int64_t size,
const QString& sender, const QDateTime& time, QString const& dispName);
void setFileFinished(const QString& fileId, bool success, const QString& filePath, const QByteArray& fileHash);

Loading…
Cancel
Save