mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
feat(core): Extend and deduplicate Tox_Err_File_Send error parsing
This commit is contained in:
parent
350fa9b462
commit
aff5663351
|
@ -26,11 +26,16 @@
|
||||||
#include "src/model/status.h"
|
#include "src/model/status.h"
|
||||||
#include "src/model/toxclientstandards.h"
|
#include "src/model/toxclientstandards.h"
|
||||||
#include "util/compatiblerecursivemutex.h"
|
#include "util/compatiblerecursivemutex.h"
|
||||||
|
#include "util/toxcoreerrorparser.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
|
#include <tox/tox.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -109,26 +114,7 @@ void CoreFile::sendAvatarFile(uint32_t friendId, const QByteArray& data)
|
||||||
Tox_Err_File_Send error;
|
Tox_Err_File_Send error;
|
||||||
const uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_AVATAR, filesize,
|
const uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_AVATAR, filesize,
|
||||||
file_id, file_name, nameLength, &error);
|
file_id, file_name, nameLength, &error);
|
||||||
|
if (!PARSE_ERR(error)) {
|
||||||
switch (error) {
|
|
||||||
case TOX_ERR_FILE_SEND_OK:
|
|
||||||
break;
|
|
||||||
case TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED:
|
|
||||||
qCritical() << "Friend not connected";
|
|
||||||
return;
|
|
||||||
case TOX_ERR_FILE_SEND_FRIEND_NOT_FOUND:
|
|
||||||
qCritical() << "Friend not found";
|
|
||||||
return;
|
|
||||||
case TOX_ERR_FILE_SEND_NAME_TOO_LONG:
|
|
||||||
qCritical() << "Name too long";
|
|
||||||
return;
|
|
||||||
case TOX_ERR_FILE_SEND_NULL:
|
|
||||||
qCritical() << "Send null";
|
|
||||||
return;
|
|
||||||
case TOX_ERR_FILE_SEND_TOO_MANY:
|
|
||||||
qCritical() << "Too many outgoing transfers";
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,8 +136,8 @@ void CoreFile::sendFile(uint32_t friendId, QString filename, QString filePath,
|
||||||
Tox_Err_File_Send sendErr;
|
Tox_Err_File_Send sendErr;
|
||||||
uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_DATA, filesize,
|
uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_DATA, filesize,
|
||||||
nullptr, 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 << ")";
|
if (!PARSE_ERR(sendErr)) {
|
||||||
emit fileSendFailed(friendId, fileName.getQString());
|
emit fileSendFailed(friendId, fileName.getQString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,4 +50,6 @@ namespace ToxcoreErrorParser {
|
||||||
bool parseErr(Tox_Err_Set_Typing error, int line);
|
bool parseErr(Tox_Err_Set_Typing error, int line);
|
||||||
bool parseErr(Tox_Err_Conference_Delete error, int line);
|
bool parseErr(Tox_Err_Conference_Delete error, int line);
|
||||||
bool parseErr(Tox_Err_Get_Port error, int line);
|
bool parseErr(Tox_Err_Get_Port error, int line);
|
||||||
|
bool parseErr(Tox_Err_File_Send error, int line);
|
||||||
|
|
||||||
} // namespace ToxcoreErrorParser
|
} // namespace ToxcoreErrorParser
|
||||||
|
|
|
@ -412,3 +412,33 @@ bool ToxcoreErrorParser::parseErr(Tox_Err_Get_Port error, int line)
|
||||||
qCritical() << line << "Unknown Tox_Err_Get_Port error code:" << error;
|
qCritical() << line << "Unknown Tox_Err_Get_Port error code:" << error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Send error, int line)
|
||||||
|
{
|
||||||
|
switch (error) {
|
||||||
|
case TOX_ERR_FILE_SEND_OK:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_SEND_NULL:
|
||||||
|
qCritical() << line << ": One of the arguments to the function was NULL when it was not expected.";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_SEND_FRIEND_NOT_FOUND:
|
||||||
|
qCritical() << line << ": The friend_number passed did not designate a valid friend.";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED:
|
||||||
|
qCritical() << line << ": This client is currently not connected to the friend.";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_SEND_NAME_TOO_LONG:
|
||||||
|
qCritical() << line << ": Filename length exceeded TOX_MAX_FILENAME_LENGTH bytes.";
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TOX_ERR_FILE_SEND_TOO_MANY:
|
||||||
|
qCritical() << line << ": Too many ongoing transfers.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
qCritical() << line << "Unknown Tox_Err_File_Send error code:" << error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user