🐞 fix(文件传输): 优化下载文件逻辑

添加文件全部下载完成处理,防止传入的从手机获取的文件大小错误导致进度未完成
This commit is contained in:
huheng@kylinos.cn 2023-04-26 16:45:37 +08:00
parent 902d74b0ed
commit 4c431d4ca6
1 changed files with 40 additions and 37 deletions

View File

@ -270,6 +270,10 @@ void FtpManager::ftpCommandFinished(int commandId, bool error)
delete file;
file = nullptr;
m_downFiles.remove(commandId);
if (m_downFiles.isEmpty() && !m_isFree) {
m_isFree = true;
Q_EMIT sigUpdateTransferProgress(0, 0);
}
return;
}
@ -319,8 +323,8 @@ void FtpManager::ftpCommandFinished(int commandId, bool error)
Q_EMIT sigCurrentDirectoryList(m_currentAllFiles);
} else {
QString downloadPath = m_taskDownload.value(0);
qInfo() << "CommandFinished: Successfully obtained the list under "
+ m_taskDownloadMap.value(downloadPath).currentPath + " directory!";
qInfo() << "CommandFinished: Successfully obtained the list under " +
m_taskDownloadMap.value(downloadPath).currentPath + " directory!";
QList<FileInfo> currentDownloadFiles;
QStringList dirPathList;
if (m_taskDownloadMap.value(downloadPath).fileList.isEmpty()) {
@ -458,33 +462,33 @@ void FtpManager::ftpCommandStarted(int commandId)
void FtpManager::ftpStateChanged(int state)
{
switch (state) {
case QFtp::Unconnected: {
qInfo() << "StateChanged: Unconnected.";
connectFtp();
break;
}
case QFtp::HostLookup: {
qInfo() << "StateChanged: Host name lookup in progress.";
break;
}
case QFtp::Connecting: {
qInfo() << "StateChanged: Attempting to connect to host.";
break;
}
case QFtp::Connected: {
qInfo() << "StateChanged: The connection with the host has been realized.";
break;
}
case QFtp::LoggedIn: {
qInfo() << "StateChanged: Connection and user login have been realized.";
break;
}
case QFtp::Closing: {
qInfo() << "StateChanged: Connection closing.";
break;
}
default:
break;
case QFtp::Unconnected: {
qInfo() << "StateChanged: Unconnected.";
connectFtp();
break;
}
case QFtp::HostLookup: {
qInfo() << "StateChanged: Host name lookup in progress.";
break;
}
case QFtp::Connecting: {
qInfo() << "StateChanged: Attempting to connect to host.";
break;
}
case QFtp::Connected: {
qInfo() << "StateChanged: The connection with the host has been realized.";
break;
}
case QFtp::LoggedIn: {
qInfo() << "StateChanged: Connection and user login have been realized.";
break;
}
case QFtp::Closing: {
qInfo() << "StateChanged: Connection closing.";
break;
}
default:
break;
}
}
@ -564,7 +568,7 @@ void FtpManager::initFtp()
void FtpManager::handleUploadDir(QString dirPath, QString uploadPath)
{
QDir dir(dirPath); // QDir的路径一定要是全路径相对路径会有错误
QDir dir(dirPath); // QDir的路径一定要是全路径相对路径会有错误
if (!dir.exists()) {
qCritical() << dirPath << "Folder does not exist!";
@ -791,7 +795,6 @@ void FtpManager::clearErrorFiles()
}
}
void FtpManager::connectFtp()
{
if (m_reconnectNum >= RECONNECT_MAX_NUM) {
@ -830,12 +833,12 @@ void FtpManager::connectFtp()
void FtpManager::setTransferMode(int mode)
{
switch (mode) {
case QFtp::Active:
m_ftp->setTransferMode(QFtp::Active);
break;
case QFtp::Passive:
m_ftp->setTransferMode(QFtp::Passive);
break;
case QFtp::Active:
m_ftp->setTransferMode(QFtp::Active);
break;
case QFtp::Passive:
m_ftp->setTransferMode(QFtp::Passive);
break;
}
}