fun:文件校验功能添加(未结束)。
This commit is contained in:
@@ -106,8 +106,11 @@ void LoadingDialog::moveToCenter(QWidget* pParent)
|
||||
*/
|
||||
void LoadingDialog::cancelBtnClicked()
|
||||
{
|
||||
emit cancelWaiting();
|
||||
this->done(USER_CANCEL);
|
||||
if (isShow_) {
|
||||
isShow_ = false;
|
||||
emit cancelWaiting();
|
||||
this->done(USER_CANCEL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,6 +132,12 @@ void LoadingDialog::paintEvent(QPaintEvent* event)
|
||||
QWidget::paintEvent(event);
|
||||
}
|
||||
|
||||
int LoadingDialog::exec()
|
||||
{
|
||||
isShow_ = true;
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
LoadingDialog::~LoadingDialog()
|
||||
{
|
||||
delete m_pLoadingMovie;
|
||||
|
||||
@@ -23,16 +23,19 @@ public:
|
||||
// 移动到指定窗口中间显示
|
||||
void moveToCenter(QWidget* pParent);
|
||||
|
||||
public:
|
||||
int exec() override;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
void initUi();
|
||||
|
||||
|
||||
Q_SIGNALS:
|
||||
void cancelWaiting();
|
||||
|
||||
private slots:
|
||||
public slots:
|
||||
void cancelBtnClicked();
|
||||
|
||||
private:
|
||||
@@ -40,6 +43,7 @@ private:
|
||||
QLabel* m_pMovieLabel;
|
||||
QMovie* m_pLoadingMovie;
|
||||
QLabel* m_pTipsLabel;
|
||||
bool isShow_{};
|
||||
QPushButton* m_pCancelBtn;
|
||||
};
|
||||
#endif // LOADINGDIALOG_H
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Transform.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "ui_Transform.h"
|
||||
@@ -146,3 +147,105 @@ void TransForm::closeEvent(QCloseEvent* event)
|
||||
exis_ = true;
|
||||
QDialog::closeEvent(event);
|
||||
}
|
||||
|
||||
CheckCondition::CheckCondition(QObject* parent) : QThread(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void CheckCondition::SetClientCore(ClientCore* clientCore)
|
||||
{
|
||||
clientCore_ = clientCore;
|
||||
}
|
||||
|
||||
void CheckCondition::SetTasks(const QVector<TransTask>& tasks)
|
||||
{
|
||||
tasks_ = tasks;
|
||||
}
|
||||
|
||||
void CheckCondition::recvFrame(QSharedPointer<FrameBuffer> frame)
|
||||
{
|
||||
InfoMsg info = infoUnpack<InfoMsg>(frame->data);
|
||||
if (info.command == STRMSG_ANSWER_CHECK_FILE_EXIST) {
|
||||
remoteNotExits_ = info.list;
|
||||
qInfo() << tr("检查结束,远端不存在的文件数:") << remoteNotExits_.size();
|
||||
msg_ = info.command;
|
||||
return;
|
||||
}
|
||||
msg_ = tr("收到未知信息,认为判断失败:") + info.command;
|
||||
qInfo() << msg_;
|
||||
}
|
||||
|
||||
void CheckCondition::interrupCheck()
|
||||
{
|
||||
if (!isAlreadyInter_) {
|
||||
isAlreadyInter_ = true;
|
||||
qWarning() << tr("中断文件校验......");
|
||||
emit sigCheckOver();
|
||||
}
|
||||
}
|
||||
|
||||
void CheckCondition::run()
|
||||
{
|
||||
qInfo() << tr("开始文件校验......");
|
||||
|
||||
resultMsgMap_.clear();
|
||||
checkRet_.clear();
|
||||
isRun_ = true;
|
||||
msg_.clear();
|
||||
isAlreadyInter_ = false;
|
||||
|
||||
// 先检查本地文件是否存在
|
||||
for (const auto& task : tasks_) {
|
||||
if (task.isUpload && !Util::FileExist(task.localPath)) {
|
||||
resultMsgMap_[CCR_CHECK_LOCAL_NOT_EXIT].push_back(task.localPath);
|
||||
if (!checkRet_.contains(CCR_CHECK_LOCAL_NOT_EXIT)) {
|
||||
checkRet_.push_back(CCR_CHECK_LOCAL_NOT_EXIT);
|
||||
}
|
||||
}
|
||||
if (!task.isUpload && Util::FileExist(task.localPath)) {
|
||||
resultMsgMap_[CCR_CHECK_LOCAL_EXIT].push_back(task.localPath);
|
||||
if (!checkRet_.contains(CCR_CHECK_LOCAL_EXIT)) {
|
||||
checkRet_.push_back(CCR_CHECK_LOCAL_EXIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 再检查远程文件是否存在
|
||||
InfoMsg msg;
|
||||
msg.command = STRMSG_REQUEST_CHECK_FILE_EXIST;
|
||||
for (const auto& task : tasks_) {
|
||||
msg.list.push_back(task.remotePath);
|
||||
}
|
||||
|
||||
auto f = clientCore_->GetBuffer(msg, FBT_MSGINFO_ASK, clientCore_->GetRemoteID());
|
||||
if (!ClientCore::syncInvoke(clientCore_, f)) {
|
||||
auto errMsg = tr("检查远程文件存在性数据发送失败。");
|
||||
if (!checkRet_.contains(CCR_CHECK_FAILED)) {
|
||||
checkRet_.push_back(CCR_CHECK_FAILED);
|
||||
resultMsgMap_[CCR_CHECK_FAILED].push_back(errMsg);
|
||||
}
|
||||
emit sigCheckOver();
|
||||
qCritical() << errMsg;
|
||||
return;
|
||||
}
|
||||
while (isRun_) {
|
||||
QThread::msleep(10);
|
||||
if (msg_.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (msg_ != STRMSG_ANSWER_CHECK_FILE_EXIST) {
|
||||
if (!checkRet_.contains(CCR_CHECK_FAILED)) {
|
||||
checkRet_.push_back(CCR_CHECK_FAILED);
|
||||
resultMsgMap_[CCR_CHECK_FAILED].push_back(msg_);
|
||||
}
|
||||
} else {
|
||||
if (!checkRet_.contains(CCR_CHECK_PASSED)) {
|
||||
checkRet_.push_back(CCR_CHECK_PASSED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
isAlreadyInter_ = true;
|
||||
emit sigCheckOver();
|
||||
qInfo() << tr("文件校验结束......");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QDialog>
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Ui {
|
||||
class TransForm;
|
||||
@@ -33,7 +34,7 @@ signals:
|
||||
void sigTaskNum(const QString& data);
|
||||
|
||||
private:
|
||||
void setProgress(double val);
|
||||
void setProgress(double val);
|
||||
void handleFailed();
|
||||
void handleDone();
|
||||
void handleUI(const TransTask& task);
|
||||
@@ -41,12 +42,12 @@ private:
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
private:
|
||||
bool exis_{ false };
|
||||
bool exis_{false};
|
||||
TranFromTh* workTh_{};
|
||||
qint32 curTaskNum_{ 0 };
|
||||
qint32 curTaskNum_{0};
|
||||
QVector<TransTask> tasks_;
|
||||
FileTrans* fileTrans_{};
|
||||
ClientCore* clientCore_{};
|
||||
@@ -61,6 +62,7 @@ public:
|
||||
explicit TranFromTh(TransForm* tf, QObject* parent = nullptr) : QThread(parent), tf_(tf)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void run() override
|
||||
{
|
||||
@@ -73,4 +75,47 @@ private:
|
||||
TransForm* tf_;
|
||||
};
|
||||
|
||||
#endif // TRANSFORM_H
|
||||
enum CondCheckResult {
|
||||
CCR_NO_CHECK = 0,
|
||||
CCR_CHECK_PASSED,
|
||||
CCR_CHECK_FAILED,
|
||||
CCR_CHECK_INTERRUPT,
|
||||
CCR_CHECK_LOCAL_EXIT,
|
||||
CCR_CHECK_REMOTE_EXIT,
|
||||
CCR_CHECK_LOCAL_NOT_EXIT,
|
||||
CCR_CHECK_REMOTE_NOT_EXIT
|
||||
};
|
||||
|
||||
class CheckCondition : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CheckCondition(QObject* parent = nullptr);
|
||||
|
||||
public:
|
||||
void SetClientCore(ClientCore* clientCore);
|
||||
void SetTasks(const QVector<TransTask>& tasks);
|
||||
|
||||
Q_SIGNALS:
|
||||
void sigCheckOver();
|
||||
|
||||
public Q_SLOTS:
|
||||
void interrupCheck();
|
||||
void recvFrame(QSharedPointer<FrameBuffer> frame);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
QString msg_;
|
||||
bool isRun_;
|
||||
bool isAlreadyInter_;
|
||||
QVector<TransTask> tasks_;
|
||||
ClientCore* clientCore_{};
|
||||
QVector<QString> remoteNotExits_;
|
||||
QVector<CondCheckResult> checkRet_;
|
||||
std::unordered_map<CondCheckResult, QVector<QString>> resultMsgMap_;
|
||||
};
|
||||
|
||||
#endif // TRANSFORM_H
|
||||
Reference in New Issue
Block a user