mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Preparation for new file transfer
This commit is contained in:
parent
fa9529ecae
commit
ae1ce8ec88
24
core.cpp
24
core.cpp
|
@ -239,8 +239,10 @@ void Core::onFileSendRequestCallback(Tox*, int32_t friendnumber, uint8_t filenum
|
||||||
{
|
{
|
||||||
qDebug() << QString("Core: Received file request %1 with friend %2").arg(filenumber).arg(friendnumber);
|
qDebug() << QString("Core: Received file request %1 with friend %2").arg(filenumber).arg(friendnumber);
|
||||||
|
|
||||||
fileRecvQueue.append(ToxFile(filenumber, friendnumber, QByteArray(), filesize,
|
ToxFile file{filenumber, friendnumber,
|
||||||
CString::toString(filename,filename_length).toUtf8(), ToxFile::RECEIVING));
|
CString::toString(filename,filename_length).toUtf8(), "", ToxFile::RECEIVING};
|
||||||
|
file.filesize = filesize;
|
||||||
|
fileRecvQueue.append(file);
|
||||||
emit static_cast<Core*>(core)->fileReceiveRequested(fileRecvQueue.last());
|
emit static_cast<Core*>(core)->fileReceiveRequested(fileRecvQueue.last());
|
||||||
}
|
}
|
||||||
void Core::onFileControlCallback(Tox*, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
|
void Core::onFileControlCallback(Tox*, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
|
||||||
|
@ -330,7 +332,7 @@ void Core::onFileDataCallback(Tox*, int32_t friendnumber, uint8_t filenumber, co
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file->fileData.append((char*)data,length);
|
file->file->write((char*)data,length);
|
||||||
file->bytesSent += length;
|
file->bytesSent += length;
|
||||||
//qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->fileData.size()).arg(file->filesize);
|
//qDebug() << QString("Core::onFileDataCallback: received %1/%2 bytes").arg(file->fileData.size()).arg(file->filesize);
|
||||||
emit static_cast<Core*>(core)->fileTransferInfo(file->friendId, file->fileNum,
|
emit static_cast<Core*>(core)->fileTransferInfo(file->friendId, file->fileNum,
|
||||||
|
@ -392,10 +394,10 @@ void Core::sendGroupMessage(int groupId, const QString& message)
|
||||||
tox_group_message_send(tox, groupId, cMessage.data(), cMessage.size());
|
tox_group_message_send(tox, groupId, cMessage.data(), cMessage.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::sendFile(int32_t friendId, QString Filename, QByteArray data)
|
void Core::sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize)
|
||||||
{
|
{
|
||||||
QByteArray fileName = Filename.toUtf8();
|
QByteArray fileName = Filename.toUtf8();
|
||||||
int fileNum = tox_new_file_sender(tox, friendId, data.size(), (uint8_t*)fileName.data(), fileName.size());
|
int fileNum = tox_new_file_sender(tox, friendId, filesize, (uint8_t*)fileName.data(), fileName.size());
|
||||||
if (fileNum == -1)
|
if (fileNum == -1)
|
||||||
{
|
{
|
||||||
qWarning() << "Core::sendFile: Can't create the Tox file sender";
|
qWarning() << "Core::sendFile: Can't create the Tox file sender";
|
||||||
|
@ -403,7 +405,9 @@ void Core::sendFile(int32_t friendId, QString Filename, QByteArray data)
|
||||||
}
|
}
|
||||||
qDebug() << QString("Core::sendFile: Created file sender %1 with friend %2").arg(fileNum).arg(friendId);
|
qDebug() << QString("Core::sendFile: Created file sender %1 with friend %2").arg(fileNum).arg(friendId);
|
||||||
|
|
||||||
fileSendQueue.append(ToxFile(fileNum, friendId, data, data.size(), fileName, ToxFile::SENDING));
|
ToxFile file{fileNum, friendId, fileName, FilePath, ToxFile::SENDING};
|
||||||
|
file.filesize = filesize;
|
||||||
|
fileSendQueue.append(file);
|
||||||
|
|
||||||
emit fileSendStarted(fileSendQueue.last());
|
emit fileSendStarted(fileSendQueue.last());
|
||||||
}
|
}
|
||||||
|
@ -910,7 +914,7 @@ void Core::removeFileFromQueue(bool sendQueue, int friendId, int fileId)
|
||||||
|
|
||||||
void Core::sendAllFileData(Core *core, ToxFile* file)
|
void Core::sendAllFileData(Core *core, ToxFile* file)
|
||||||
{
|
{
|
||||||
while (file->bytesSent < file->fileData.size())
|
while (file->bytesSent < file->filesize)
|
||||||
{
|
{
|
||||||
if (file->status == ToxFile::PAUSED)
|
if (file->status == ToxFile::PAUSED)
|
||||||
{
|
{
|
||||||
|
@ -924,7 +928,7 @@ void Core::sendAllFileData(Core *core, ToxFile* file)
|
||||||
}
|
}
|
||||||
emit core->fileTransferInfo(file->friendId, file->fileNum, file->filesize, file->bytesSent, ToxFile::SENDING);
|
emit core->fileTransferInfo(file->friendId, file->fileNum, file->filesize, file->bytesSent, ToxFile::SENDING);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
int chunkSize = tox_file_data_size(core->tox, file->friendId);
|
long long chunkSize = tox_file_data_size(core->tox, file->friendId);
|
||||||
if (chunkSize == -1)
|
if (chunkSize == -1)
|
||||||
{
|
{
|
||||||
qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send");
|
qWarning("Core::fileHeartbeat: Error getting preffered chunk size, aborting file send");
|
||||||
|
@ -934,8 +938,8 @@ void Core::sendAllFileData(Core *core, ToxFile* file)
|
||||||
removeFileFromQueue(true, file->friendId, file->fileNum);
|
removeFileFromQueue(true, file->friendId, file->fileNum);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chunkSize = std::min(chunkSize, file->fileData.size());
|
chunkSize = std::min(chunkSize, file->filesize);
|
||||||
QByteArray toSend = file->fileData.mid(file->bytesSent, chunkSize);
|
QByteArray toSend = file->file->read(chunkSize);
|
||||||
if (tox_file_send_data(core->tox, file->friendId, file->fileNum, (uint8_t*)toSend.data(), toSend.size()) == -1)
|
if (tox_file_send_data(core->tox, file->friendId, file->fileNum, (uint8_t*)toSend.data(), toSend.size()) == -1)
|
||||||
{
|
{
|
||||||
//qWarning("Core::fileHeartbeat: Error sending data chunk");
|
//qWarning("Core::fileHeartbeat: Error sending data chunk");
|
||||||
|
|
15
core.h
15
core.h
|
@ -27,6 +27,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
|
@ -73,14 +74,18 @@ struct ToxFile
|
||||||
};
|
};
|
||||||
|
|
||||||
ToxFile()=default;
|
ToxFile()=default;
|
||||||
ToxFile(int FileNum, int FriendId, QByteArray FileData, long long Filesize, QByteArray FileName, FileDirection Direction)
|
ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePath, FileDirection Direction)
|
||||||
: fileNum(FileNum), friendId(FriendId), fileData{FileData}, fileName{FileName},
|
: fileNum(FileNum), friendId(FriendId), fileName{FileName}, filePath{FilePath}, file{new QFile(filePath)},
|
||||||
bytesSent{0}, filesize(Filesize), status{STOPPED}, direction{Direction} {}
|
bytesSent{0}, filesize{0}, status{STOPPED}, direction{Direction} {}
|
||||||
|
~ToxFile(){file->close(); delete file;}
|
||||||
|
void setFilePath(QString path) {filePath=path; file->setFileName(path);}
|
||||||
|
bool open(bool write) {return write?file->open(QIODevice::WriteOnly):file->open(QIODevice::ReadOnly);}
|
||||||
|
|
||||||
int fileNum;
|
int fileNum;
|
||||||
int friendId;
|
int friendId;
|
||||||
QByteArray fileData;
|
|
||||||
QByteArray fileName;
|
QByteArray fileName;
|
||||||
|
QString filePath;
|
||||||
|
QFile* file;
|
||||||
long long bytesSent;
|
long long bytesSent;
|
||||||
long long filesize;
|
long long filesize;
|
||||||
FileStatus status;
|
FileStatus status;
|
||||||
|
@ -147,7 +152,7 @@ public slots:
|
||||||
void sendAction(int friendId, const QString& action);
|
void sendAction(int friendId, const QString& action);
|
||||||
void sendTyping(int friendId, bool typing);
|
void sendTyping(int friendId, bool typing);
|
||||||
|
|
||||||
void sendFile(int32_t friendId, QString Filename, QByteArray data);
|
void sendFile(int32_t friendId, QString Filename, QString FilePath, long long filesize);
|
||||||
void cancelFileSend(int friendId, int fileNum);
|
void cancelFileSend(int friendId, int fileNum);
|
||||||
void cancelFileRecv(int friendId, int fileNum);
|
void cancelFileRecv(int friendId, int fileNum);
|
||||||
void rejectFileRecvRequest(int friendId, int fileNum);
|
void rejectFileRecvRequest(int friendId, int fileNum);
|
||||||
|
|
|
@ -93,7 +93,7 @@ FileTransfertWidget::FileTransfertWidget(ToxFile File)
|
||||||
connect(bottomright, SIGNAL(clicked()), this, SLOT(pauseResumeSend()));
|
connect(bottomright, SIGNAL(clicked()), this, SLOT(pauseResumeSend()));
|
||||||
|
|
||||||
QPixmap preview;
|
QPixmap preview;
|
||||||
if (preview.loadFromData(File.fileData))
|
if (preview.loadFromData(File.file->readAll()))
|
||||||
{
|
{
|
||||||
preview = preview.scaledToHeight(40);
|
preview = preview.scaledToHeight(40);
|
||||||
pic->setPixmap(preview);
|
pic->setPixmap(preview);
|
||||||
|
@ -234,14 +234,8 @@ void FileTransfertWidget::onFileTransferFinished(ToxFile File)
|
||||||
|
|
||||||
if (File.direction == ToxFile::RECEIVING)
|
if (File.direction == ToxFile::RECEIVING)
|
||||||
{
|
{
|
||||||
QFile saveFile(savePath);
|
|
||||||
if (!saveFile.open(QIODevice::WriteOnly))
|
|
||||||
return;
|
|
||||||
saveFile.write(File.fileData);
|
|
||||||
saveFile.close();
|
|
||||||
|
|
||||||
QPixmap preview;
|
QPixmap preview;
|
||||||
if (preview.loadFromData(File.fileData))
|
if (preview.loadFromData(File.file->readAll()))
|
||||||
{
|
{
|
||||||
preview = preview.scaledToHeight(40);
|
preview = preview.scaledToHeight(40);
|
||||||
pic->setPixmap(preview);
|
pic->setPixmap(preview);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user