You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
2.3 KiB
57 lines
2.3 KiB
/* Последовательные операции над выбранными файлами/деревьями. Контекст неизменен; |
|
* локальный обход выполняется в worker, сеть — через bridge. Отмена ждёт завершения |
|
* текущего файлового I/O до finished. Временный каталог экспорта удаляется при ошибке. */ |
|
#pragma once |
|
#include <QObject> |
|
#include <QList> |
|
#include <QSet> |
|
#include <QThreadPool> |
|
#include <QStringList> |
|
#include <QByteArray> |
|
#include <atomic> |
|
#include <functional> |
|
#include <cstdint> |
|
struct mf_message; |
|
|
|
struct MemberFileEntry { |
|
QString remote, local; |
|
QByteArray version; |
|
bool directory = false, verify = false; |
|
quint64 cursor = 0; |
|
}; |
|
|
|
class MemberFileBatch : public QObject { |
|
public: |
|
enum Mode { Upload, Download, Remove }; |
|
MemberFileBatch(quint64 group, quint64 server, quint64 owner, Mode mode, QObject* parent); |
|
~MemberFileBatch() override; |
|
void upload(const QStringList& sources, const QString& destination); |
|
void start(const QList<MemberFileEntry>& entries, const QString& destination = {}, bool temporary = false); |
|
bool response(const mf_message& message); |
|
bool transfer(const uint8_t* data, int length); |
|
void cancel(); |
|
std::function<void(const QString&, int)> progress; |
|
std::function<void(bool, const QString&, const QStringList&)> finished; |
|
// Возвращает QMessageBox::Yes/No/YesToAll/NoToAll/Cancel; конфликт разных типов нельзя заменить. |
|
std::function<int(const QString&, bool)> conflict; |
|
private: |
|
void next(); |
|
void request(uint8_t command); |
|
void copyFile(const QByteArray& version); |
|
void advance(bool skipped = false); |
|
void finish(const QString& error = {}); |
|
bool replace(bool sameType); |
|
void cancelRequest(quint64 id); |
|
const quint64 m_group, m_server, m_owner; |
|
const Mode m_mode; |
|
QList<MemberFileEntry> m_queue, m_verify, m_remove; |
|
QSet<QString> m_seen; |
|
QStringList m_roots; |
|
QString m_temporary; |
|
QThreadPool m_pool; |
|
std::atomic_bool m_cancelled{false}; |
|
bool m_work = false, m_finished = false, m_scanning = false; |
|
quint64 m_request = 0, m_transfer = 0; |
|
uint8_t m_command = 0; |
|
int m_done = 0, m_skipped = 0, m_policy = 0; |
|
};
|
|
|