2015-06-06 09:40:08 +08:00
|
|
|
/*
|
2018-04-13 04:02:28 +08:00
|
|
|
Copyright © 2015-2018 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2015-04-24 08:32:09 +08:00
|
|
|
#ifndef COREFILE_H
|
|
|
|
#define COREFILE_H
|
|
|
|
|
|
|
|
#include <tox/tox.h>
|
|
|
|
|
2017-10-27 20:02:43 +08:00
|
|
|
#include "toxfile.h"
|
2019-03-05 06:17:29 +08:00
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/core/toxpk.h"
|
2019-04-22 15:54:15 +08:00
|
|
|
#include "src/model/status.h"
|
2015-04-24 21:31:30 +08:00
|
|
|
|
|
|
|
#include <QHash>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QMutex>
|
2019-03-05 06:17:29 +08:00
|
|
|
#include <QObject>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QString>
|
2015-04-24 21:31:30 +08:00
|
|
|
|
2019-04-22 15:54:15 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
|
2015-04-24 08:32:09 +08:00
|
|
|
struct Tox;
|
2019-03-05 06:17:29 +08:00
|
|
|
class CoreFile;
|
2015-04-24 08:32:09 +08:00
|
|
|
|
2019-03-05 06:17:29 +08:00
|
|
|
using CoreFilePtr = std::unique_ptr<CoreFile>;
|
2015-04-24 21:31:30 +08:00
|
|
|
|
2019-03-05 06:17:29 +08:00
|
|
|
class CoreFile : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-06-28 03:32:28 +08:00
|
|
|
|
|
|
|
public:
|
2019-03-05 06:17:29 +08:00
|
|
|
void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept);
|
|
|
|
static CoreFilePtr makeCoreFile(Core* core, Tox* tox, QMutex& coreLoopLock);
|
2018-06-30 18:10:46 +08:00
|
|
|
|
2019-03-05 06:17:29 +08:00
|
|
|
void sendFile(uint32_t friendId, QString filename, QString filePath,
|
|
|
|
long long filesize);
|
|
|
|
void sendAvatarFile(uint32_t friendId, const QByteArray& data);
|
|
|
|
void pauseResumeFile(uint32_t friendId, uint32_t fileId);
|
|
|
|
void cancelFileSend(uint32_t friendId, uint32_t fileId);
|
|
|
|
|
|
|
|
void cancelFileRecv(uint32_t friendId, uint32_t fileId);
|
|
|
|
void rejectFileRecvRequest(uint32_t friendId, uint32_t fileId);
|
|
|
|
void acceptFileRecvRequest(uint32_t friendId, uint32_t fileId, QString path);
|
|
|
|
|
|
|
|
unsigned corefileIterationInterval();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void fileSendStarted(ToxFile file);
|
|
|
|
void fileReceiveRequested(ToxFile file);
|
|
|
|
void fileTransferAccepted(ToxFile file);
|
|
|
|
void fileTransferCancelled(ToxFile file);
|
|
|
|
void fileTransferFinished(ToxFile file);
|
|
|
|
void fileUploadFinished(const QString& path);
|
|
|
|
void fileDownloadFinished(const QString& path);
|
|
|
|
void fileTransferPaused(ToxFile file);
|
|
|
|
void fileTransferInfo(ToxFile file);
|
|
|
|
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
|
|
|
|
void fileTransferBrokenUnbroken(ToxFile file, bool broken);
|
|
|
|
void fileNameChanged(const ToxPk& friendPk);
|
|
|
|
void fileSendFailed(uint32_t friendId, const QString& fname);
|
2015-04-24 08:32:09 +08:00
|
|
|
|
2015-04-24 21:31:30 +08:00
|
|
|
private:
|
2019-03-05 06:17:29 +08:00
|
|
|
CoreFile(Tox* core, QMutex& coreLoopLock);
|
|
|
|
|
|
|
|
ToxFile* findFile(uint32_t friendId, uint32_t fileId);
|
|
|
|
void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file);
|
|
|
|
void removeFile(uint32_t friendId, uint32_t fileId);
|
2016-10-19 04:57:58 +08:00
|
|
|
static constexpr uint64_t getFriendKey(uint32_t friendId, uint32_t fileId)
|
|
|
|
{
|
|
|
|
return (static_cast<std::uint64_t>(friendId) << 32) + fileId;
|
|
|
|
}
|
2015-04-24 21:31:30 +08:00
|
|
|
|
2019-03-05 06:17:29 +08:00
|
|
|
static void connectCallbacks(Tox& tox);
|
|
|
|
static void onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint32_t kind,
|
2017-02-26 19:52:45 +08:00
|
|
|
uint64_t filesize, const uint8_t* fname, size_t fnameLen,
|
|
|
|
void* vCore);
|
|
|
|
static void onFileControlCallback(Tox* tox, uint32_t friendId, uint32_t fileId,
|
2019-03-05 06:17:29 +08:00
|
|
|
Tox_File_Control control, void* vCore);
|
2017-02-26 19:52:45 +08:00
|
|
|
static void onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint64_t pos,
|
2019-03-05 06:17:29 +08:00
|
|
|
size_t length, void* vCore);
|
2017-02-26 19:52:45 +08:00
|
|
|
static void onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fileId, uint64_t position,
|
|
|
|
const uint8_t* data, size_t length, void* vCore);
|
2015-04-24 21:31:30 +08:00
|
|
|
|
2018-05-01 03:29:36 +08:00
|
|
|
static QString getCleanFileName(QString filename);
|
2019-03-05 06:17:29 +08:00
|
|
|
|
|
|
|
private slots:
|
2019-04-22 15:54:15 +08:00
|
|
|
void onConnectionStatusChanged(uint32_t friendId, Status::Status state);
|
2019-03-05 06:17:29 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
QHash<uint64_t, ToxFile> fileMap;
|
|
|
|
Tox* tox;
|
|
|
|
QMutex* coreLoopLock = nullptr;
|
2015-04-24 08:32:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COREFILE_H
|