Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复ftp共享目录图片打开显示空白 #146

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions libimageviewer/viewpanel/scen/imagegraphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

#include <DGuiApplicationHelper>
#include <DApplicationHelper>
#include <QNetworkAccessManager>
#include <QNetworkReply>

#ifndef QT_NO_OPENGL
//#include <QGLWidget>
Expand Down Expand Up @@ -78,6 +80,31 @@ QVariantList cachePixmap(const QString &path)
if (QFileInfo(path).exists() && p.isNull()) {
//判定为损坏图片
// p = utils::image::getDamagePixmap(DApplicationHelper::instance()->themeType() == DApplicationHelper::LightType);
if(path.contains("ftp:host=")) {//前面失败后再处理ftp图片
QFileInfo info(path);
if(info.size() <= 1024*1024*1024) {//小于1Mftp文件做下载本地处理
QNetworkAccessManager manager;
QTemporaryFile tmpfile;
QEventLoop loop;

QObject::connect(&manager, &QNetworkAccessManager::finished, [&](QNetworkReply *reply){
if (tmpfile.open()) {
tmpfile.write(reply->readAll()); // 写入到目标文件
tmpfile.flush();
loop.quit();
}
});
int nIdex = path.indexOf("ftp:host=");
QString urlAddr = path.mid(nIdex).replace("ftp:host=", "ftp://");
QNetworkRequest request(urlAddr);
manager.get(request);
loop.exec();
QString strNewFile = tmpfile.fileName();
LibUnionImage_NameSpace::loadStaticImageFromFile(strNewFile, tImg, errMsg);
p = QPixmap::fromImage(tImg);
tmpfile.close();
}
}
qDebug() << errMsg;
}
QVariantList vl;
Expand Down
Loading