fix: down remote file error.
This commit is contained in:
@@ -139,6 +139,10 @@ void ClientCore::UseFrame(QSharedPointer<FrameBuffer> frame)
|
|||||||
emit sigTransFailed(frame);
|
emit sigTransFailed(frame);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case FBT_CLI_FILE_INFO: {
|
||||||
|
emit sigFileInfo(frame);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
qCritical() << QString("unknown frame type: %1").arg(frame->type);
|
qCritical() << QString("unknown frame type: %1").arg(frame->type);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ signals:
|
|||||||
void sigCanDown(QSharedPointer<FrameBuffer> frame);
|
void sigCanDown(QSharedPointer<FrameBuffer> frame);
|
||||||
void sigFileBuffer(QSharedPointer<FrameBuffer> frame);
|
void sigFileBuffer(QSharedPointer<FrameBuffer> frame);
|
||||||
void sigTransFailed(QSharedPointer<FrameBuffer> frame);
|
void sigTransFailed(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void sigFileInfo(QSharedPointer<FrameBuffer> frame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onReadyRead();
|
void onReadyRead();
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ void FileTrans::ReqDownFile(const TransTask& task)
|
|||||||
info.toPath = task.localPath;
|
info.toPath = task.localPath;
|
||||||
info.fromPath = task.remotePath;
|
info.fromPath = task.remotePath;
|
||||||
|
|
||||||
|
downTask_->task = task;
|
||||||
|
downTask_->totalSize = 0;
|
||||||
downTask_->file.setFileName(Util::Get2FilePath(task.remotePath, task.localPath));
|
downTask_->file.setFileName(Util::Get2FilePath(task.remotePath, task.localPath));
|
||||||
if (!downTask_->file.open(QIODevice::WriteOnly)) {
|
if (!downTask_->file.open(QIODevice::WriteOnly)) {
|
||||||
qCritical() << QString(tr("open file [%1] failed.")).arg(downTask_->file.fileName());
|
qCritical() << QString(tr("open file [%1] failed.")).arg(downTask_->file.fileName());
|
||||||
@@ -73,29 +75,38 @@ void FileTrans::ReqDownFile(const TransTask& task)
|
|||||||
auto frame = clientCore_->GetBuffer(info, FBT_CLI_REQ_DOWN, task.remoteId);
|
auto frame = clientCore_->GetBuffer(info, FBT_CLI_REQ_DOWN, task.remoteId);
|
||||||
if (!ClientCore::asyncInvoke(clientCore_, [this, frame]() { return clientCore_->Send(frame); })) {
|
if (!ClientCore::asyncInvoke(clientCore_, [this, frame]() { return clientCore_->Send(frame); })) {
|
||||||
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
|
qCritical() << QString(tr("send req send failed: %1")).arg(info.msg);
|
||||||
sendTask_->state = TaskState::STATE_NONE;
|
downTask_->state = TaskState::STATE_NONE;
|
||||||
sendTask_->file.close();
|
downTask_->file.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sendTask_->state = TaskState::STATE_RUNNING;
|
downTask_->state = TaskState::STATE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint32 FileTrans::GetSendProgress()
|
qint32 FileTrans::GetSendProgress()
|
||||||
{
|
{
|
||||||
|
if (sendTask_->state == TaskState::STATE_FINISH) {
|
||||||
|
downTask_->state == TaskState::STATE_NONE;
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
if (sendTask_->state != TaskState::STATE_RUNNING) {
|
if (sendTask_->state != TaskState::STATE_RUNNING) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double per = (sendTask_->tranSize * 100.0) / sendTask_->totalSize;
|
double per = (sendTask_->tranSize * 100.0) / sendTask_->totalSize;
|
||||||
return per;
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint32 FileTrans::GetDownProgress()
|
qint32 FileTrans::GetDownProgress()
|
||||||
{
|
{
|
||||||
|
if (downTask_->state == TaskState::STATE_FINISH) {
|
||||||
|
downTask_->state == TaskState::STATE_NONE;
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
if (downTask_->state != TaskState::STATE_RUNNING) {
|
if (downTask_->state != TaskState::STATE_RUNNING) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (downTask_->totalSize == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
double per = (downTask_->tranSize * 100.0) / downTask_->totalSize;
|
double per = (downTask_->tranSize * 100.0) / downTask_->totalSize;
|
||||||
return per;
|
return per;
|
||||||
}
|
}
|
||||||
@@ -110,6 +121,7 @@ void FileTrans::RegisterSignal()
|
|||||||
connect(clientCore_, &ClientCore::sigCanotDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanotDown(frame); });
|
connect(clientCore_, &ClientCore::sigCanotDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanotDown(frame); });
|
||||||
connect(clientCore_, &ClientCore::sigCanDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanDown(frame); });
|
connect(clientCore_, &ClientCore::sigCanDown, this, [this](QSharedPointer<FrameBuffer> frame) { fbtCanDown(frame); });
|
||||||
connect(clientCore_, &ClientCore::sigFileBuffer, this, [this](QSharedPointer<FrameBuffer> frame) { fbtFileBuffer(frame); });
|
connect(clientCore_, &ClientCore::sigFileBuffer, this, [this](QSharedPointer<FrameBuffer> frame) { fbtFileBuffer(frame); });
|
||||||
|
connect(clientCore_, &ClientCore::sigFileInfo, this, [this](QSharedPointer<FrameBuffer> frame) { fbtFileInfo(frame); });
|
||||||
connect(clientCore_, &ClientCore::sigTransFailed, this, [this](QSharedPointer<FrameBuffer> frame) { fbtTransFailed(frame); });
|
connect(clientCore_, &ClientCore::sigTransFailed, this, [this](QSharedPointer<FrameBuffer> frame) { fbtTransFailed(frame); });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +186,25 @@ void FileTrans::fbtReqDown(QSharedPointer<FrameBuffer> frame)
|
|||||||
qCritical() << QString(tr("open file failed: %1")).arg(info.fromPath);
|
qCritical() << QString(tr("open file failed: %1")).arg(info.fromPath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileInfo fileInfo(info.fromPath);
|
||||||
|
if (fileInfo.exists()) {
|
||||||
|
qint64 size = fileInfo.size();
|
||||||
|
info.permissions = static_cast<quint32>(fileInfo.permissions());
|
||||||
|
info.size = size;
|
||||||
|
} else {
|
||||||
|
qCritical() << QString(tr("File [%1] not exit.")).arg(info.fromPath);
|
||||||
|
doTask->file.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reply fileinfo
|
||||||
|
auto f = clientCore_->GetBuffer(info, FBT_CLI_FILE_INFO, frame->fid);
|
||||||
|
if (!ClientCore::asyncInvoke(clientCore_, [this, f]() { return clientCore_->Send(f); })) {
|
||||||
|
qCritical() << QString(tr("send file %1 info failed.")).arg(info.fromPath);
|
||||||
|
doTask->file.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
doTask->task.isUpload = true;
|
doTask->task.isUpload = true;
|
||||||
doTask->task.localPath = info.fromPath;
|
doTask->task.localPath = info.fromPath;
|
||||||
doTask->task.remoteId = frame->fid;
|
doTask->task.remoteId = frame->fid;
|
||||||
@@ -230,6 +261,15 @@ void FileTrans::fbtFileBuffer(QSharedPointer<FrameBuffer> frame)
|
|||||||
downTask_->tranSize += ws;
|
downTask_->tranSize += ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileTrans::fbtFileInfo(QSharedPointer<FrameBuffer> frame)
|
||||||
|
{
|
||||||
|
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
||||||
|
qInfo() << QString(tr("prepare downfile's size is:%1, perm:%2")).arg(info.size, info.permissions);
|
||||||
|
downTask_->totalSize = info.size;
|
||||||
|
downTask_->tranSize = 0;
|
||||||
|
downTask_->permission = info.permissions;
|
||||||
|
}
|
||||||
|
|
||||||
void FileTrans::fbtCanotSend(QSharedPointer<FrameBuffer> frame)
|
void FileTrans::fbtCanotSend(QSharedPointer<FrameBuffer> frame)
|
||||||
{
|
{
|
||||||
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ private:
|
|||||||
void fbtCanDown(QSharedPointer<FrameBuffer> frame);
|
void fbtCanDown(QSharedPointer<FrameBuffer> frame);
|
||||||
void fbtCanotDown(QSharedPointer<FrameBuffer> frame);
|
void fbtCanotDown(QSharedPointer<FrameBuffer> frame);
|
||||||
void fbtFileBuffer(QSharedPointer<FrameBuffer> frame);
|
void fbtFileBuffer(QSharedPointer<FrameBuffer> frame);
|
||||||
|
void fbtFileInfo(QSharedPointer<FrameBuffer> frame);
|
||||||
void fbtCanotSend(QSharedPointer<FrameBuffer> frame);
|
void fbtCanotSend(QSharedPointer<FrameBuffer> frame);
|
||||||
void fbtCanSend(QSharedPointer<FrameBuffer> frame);
|
void fbtCanSend(QSharedPointer<FrameBuffer> frame);
|
||||||
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
|
void fbtTransFailed(QSharedPointer<FrameBuffer> frame);
|
||||||
|
|||||||
@@ -23,18 +23,20 @@ FileManager::~FileManager()
|
|||||||
|
|
||||||
void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clientCore)
|
void FileManager::SetModeStr(const QString& modeStr, int type, ClientCore* clientCore)
|
||||||
{
|
{
|
||||||
|
cliCore_ = clientCore;
|
||||||
|
|
||||||
ui->lbMode->setText(modeStr);
|
ui->lbMode->setText(modeStr);
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
fileHelper_ = std::make_shared<LocalFile>();
|
fileHelper_ = std::make_shared<LocalFile>();
|
||||||
} else {
|
} else {
|
||||||
cliCore_ = clientCore;
|
|
||||||
auto remotePtr = std::make_shared<RemoteFile>();
|
auto remotePtr = std::make_shared<RemoteFile>();
|
||||||
remotePtr->setClientCore(clientCore);
|
remotePtr->setClientCore(clientCore);
|
||||||
ui->tableWidget->setIsRemote(true);
|
ui->tableWidget->setIsRemote(true);
|
||||||
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
|
||||||
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
|
|
||||||
fileHelper_ = remotePtr;
|
fileHelper_ = remotePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui->tableWidget->setOwnIDCall([this]() { return cliCore_->GetOwnID(); });
|
||||||
|
ui->tableWidget->setRemoteIDCall([this]() { return cliCore_->GetRemoteID(); });
|
||||||
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
|
ui->tableWidget->setBasePathCall([this]() { return curRoot_; });
|
||||||
|
|
||||||
connect(fileHelper_.get(), &DirFileHelper::sigHome, this, &FileManager::ShowPath);
|
connect(fileHelper_.get(), &DirFileHelper::sigHome, this, &FileManager::ShowPath);
|
||||||
|
|||||||
@@ -7,10 +7,17 @@
|
|||||||
|
|
||||||
CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent)
|
CpTableWidget::CpTableWidget(QWidget* parent) : QTableWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CpTableWidget::~CpTableWidget()
|
CpTableWidget::~CpTableWidget()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CpTableWidget::dropEvent(QDropEvent* event)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
void CpTableWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ public:
|
|||||||
~CpTableWidget() override;
|
~CpTableWidget() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void dropEvent(QDropEvent* event) override;
|
||||||
void dragEnterEvent(QDragEnterEvent* event);
|
void dragEnterEvent(QDragEnterEvent* event);
|
||||||
|
|
||||||
protected:
|
|
||||||
QPoint startPos_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CP_TABLEWIDET_H
|
#endif // CP_TABLEWIDET_H
|
||||||
|
|||||||
@@ -8,10 +8,18 @@ TransForm::TransForm(QWidget* parent) : QDialog(parent), ui(new Ui::TransForm)
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
setWindowTitle(tr("TransProgress"));
|
||||||
|
ui->edFrom->setReadOnly(true);
|
||||||
|
ui->edTo->setReadOnly(true);
|
||||||
|
ui->pedFrom->setReadOnly(true);
|
||||||
|
ui->pedTo->setReadOnly(true);
|
||||||
|
ui->edTask->setReadOnly(true);
|
||||||
|
|
||||||
connect(this, &TransForm::sigProgress, this, &TransForm::setProgress);
|
connect(this, &TransForm::sigProgress, this, &TransForm::setProgress);
|
||||||
connect(this, &TransForm::sigDone, this, &TransForm::handleDone);
|
connect(this, &TransForm::sigDone, this, &TransForm::handleDone);
|
||||||
connect(this, &TransForm::sigFailed, this, &TransForm::handleFailed);
|
connect(this, &TransForm::sigFailed, this, &TransForm::handleFailed);
|
||||||
connect(this, &TransForm::sigSetUi, this, &TransForm::handleUI);
|
connect(this, &TransForm::sigSetUi, this, &TransForm::handleUI);
|
||||||
|
connect(this, &TransForm::sigTaskNum, this, &TransForm::showNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransForm::~TransForm()
|
TransForm::~TransForm()
|
||||||
@@ -35,7 +43,13 @@ void TransForm::SetTasks(const QVector<TransTask>& tasks)
|
|||||||
|
|
||||||
void TransForm::startTask()
|
void TransForm::startTask()
|
||||||
{
|
{
|
||||||
|
qInfo() << "TransForm::startTask enter....";
|
||||||
|
curTaskNum_ = 0;
|
||||||
for (auto& task : tasks_) {
|
for (auto& task : tasks_) {
|
||||||
|
|
||||||
|
QString str = QString(tr("%1/%2")).arg(curTaskNum_).arg(tasks_.size());
|
||||||
|
emit sigTaskNum(str);
|
||||||
|
|
||||||
emit sigSetUi(task);
|
emit sigSetUi(task);
|
||||||
if (task.isUpload) {
|
if (task.isUpload) {
|
||||||
fileTrans_->ReqSendFile(task);
|
fileTrans_->ReqSendFile(task);
|
||||||
@@ -74,9 +88,13 @@ void TransForm::startTask()
|
|||||||
QThread::msleep(10);
|
QThread::msleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
++curTaskNum_;
|
||||||
|
|
||||||
|
str = QString(tr("%1/%2")).arg(curTaskNum_).arg(tasks_.size());
|
||||||
|
emit sigTaskNum(str);
|
||||||
}
|
}
|
||||||
tasks_.clear();
|
tasks_.clear();
|
||||||
qDebug() << "TransForm::startTask exit....";
|
qInfo() << "TransForm::startTask exit....";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransForm::setProgress(double val)
|
void TransForm::setProgress(double val)
|
||||||
@@ -109,11 +127,16 @@ void TransForm::handleUI(const TransTask& task)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TransForm::showNum(const QString& data)
|
||||||
|
{
|
||||||
|
ui->edTask->setText(data);
|
||||||
|
}
|
||||||
|
|
||||||
void TransForm::showEvent(QShowEvent* event)
|
void TransForm::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
QDialog::showEvent(event);
|
QDialog::showEvent(event);
|
||||||
workTh_ = new TranFromTh(this, this);
|
workTh_ = new TranFromTh(this, this);
|
||||||
//fileTrans_->moveToThread(workTh_);
|
// fileTrans_->moveToThread(workTh_);
|
||||||
connect(workTh_, &QThread::finished, workTh_, &QObject::deleteLater);
|
connect(workTh_, &QThread::finished, workTh_, &QObject::deleteLater);
|
||||||
workTh_->start();
|
workTh_->start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,14 @@ signals:
|
|||||||
void sigFailed();
|
void sigFailed();
|
||||||
void sigDone();
|
void sigDone();
|
||||||
void sigSetUi(const TransTask& task);
|
void sigSetUi(const TransTask& task);
|
||||||
|
void sigTaskNum(const QString& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setProgress(double val);
|
void setProgress(double val);
|
||||||
void handleFailed();
|
void handleFailed();
|
||||||
void handleDone();
|
void handleDone();
|
||||||
void handleUI(const TransTask& task);
|
void handleUI(const TransTask& task);
|
||||||
|
void showNum(const QString& data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent* event) override;
|
void showEvent(QShowEvent* event) override;
|
||||||
@@ -44,6 +46,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
bool exis_{ false };
|
bool exis_{ false };
|
||||||
TranFromTh* workTh_{};
|
TranFromTh* workTh_{};
|
||||||
|
qint32 curTaskNum_{ 0 };
|
||||||
QVector<TransTask> tasks_;
|
QVector<TransTask> tasks_;
|
||||||
FileTrans* fileTrans_{};
|
FileTrans* fileTrans_{};
|
||||||
ClientCore* clientCore_{};
|
ClientCore* clientCore_{};
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ void frelayGUI::InitControl()
|
|||||||
localFile_ = new FileManager(this);
|
localFile_ = new FileManager(this);
|
||||||
remoteFile_ = new FileManager(this);
|
remoteFile_ = new FileManager(this);
|
||||||
|
|
||||||
localFile_->SetModeStr(tr("Local:"));
|
localFile_->SetModeStr(tr("Local:"), 0, clientCore_);
|
||||||
localFile_->SetOtherSideCall([this]() { return remoteFile_->GetCurRoot(); });
|
localFile_->SetOtherSideCall([this]() { return remoteFile_->GetCurRoot(); });
|
||||||
remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_);
|
remoteFile_->SetModeStr(tr("Remote:"), 1, clientCore_);
|
||||||
remoteFile_->SetOtherSideCall([this]() { return localFile_->GetCurRoot(); });
|
remoteFile_->SetOtherSideCall([this]() { return localFile_->GetCurRoot(); });
|
||||||
@@ -90,9 +90,9 @@ void frelayGUI::ControlMsgHander(QtMsgType type, const QMessageLogContext& conte
|
|||||||
{
|
{
|
||||||
Q_UNUSED(context);
|
Q_UNUSED(context);
|
||||||
|
|
||||||
if (!qApp || !qobject_cast<frelayGUI*>(qApp->activeWindow())) {
|
//if (!qApp || !qobject_cast<frelayGUI*>(qApp->activeWindow())) {
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ enum FrameBufferType : uint16_t {
|
|||||||
FBT_CLI_CANOT_DOWN,
|
FBT_CLI_CANOT_DOWN,
|
||||||
FBT_CLI_FILE_BUFFER,
|
FBT_CLI_FILE_BUFFER,
|
||||||
FBT_CLI_TRANS_DONE,
|
FBT_CLI_TRANS_DONE,
|
||||||
FBT_CLI_TRANS_FAILED
|
FBT_CLI_TRANS_FAILED,
|
||||||
|
FBT_CLI_FILE_INFO
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FrameBuffer {
|
struct FrameBuffer {
|
||||||
|
|||||||
Reference in New Issue
Block a user