Skip to content

Commit

Permalink
fix: Filter image format not support wallpaper
Browse files Browse the repository at this point in the history
缓存图片后缀和格式保持相同, 提高压缩率
部分图片格式不支持,新增格式判断函数和看图一致

Log: 过滤不支持设置为壁纸的图片格式
Bug: https://pms.uniontech.com/bug-view-247311.html
Influence: SetWallpaper
  • Loading branch information
rb-union committed Mar 20, 2024
1 parent 05aaa33 commit 9f3447a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/album/controller/wallpapersetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool WallpaperSetter::setBackground(const QString &pictureFilePath)
QString errMsg;
QFileInfo info(pictureFilePath);
QString tempWallPaperpath;
tempWallPaperpath = WALLPAPER_PATH + info.baseName() + ".png";
tempWallPaperpath = WALLPAPER_PATH + info.baseName() + ".jpg";
QFileInfo tempInfo(tempWallPaperpath);
if (!UnionImage_NameSpace::loadStaticImageFromFile(pictureFilePath, tImg, errMsg)) {
return false;
Expand All @@ -57,7 +57,7 @@ bool WallpaperSetter::setBackground(const QString &pictureFilePath)
}

// 后端壁纸设置接口不接收超过32MB的图片:调整压缩格式从PNG到JPG,以降低缓存文件占用
if (!tImg.save(tempWallPaperpath, "JPG", 100)) {
if (!tImg.save(tempWallPaperpath, "JPG")) {
return false;
}
if (!tempInfo.exists()) {
Expand Down
2 changes: 1 addition & 1 deletion src/album/thumbnail/thumbnaillistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ void ThumbnailListView::updateMenuContents()

if ((1 == paths.length() || QFileInfo(paths[0]).suffix().contains("gif"))) {
DBImgInfo data = selectedIndexes().at(0).data(Qt::DisplayRole).value<DBImgInfo>();
if (data.itemType == ItemTypePic && QFileInfo(paths[0]).isReadable()) {
if (data.itemType == ItemTypePic && QFileInfo(paths[0]).isReadable() && utils::base::isSupportWallpaper(paths[0])) {
m_MenuActionMap.value(tr("Set as wallpaper"))->setVisible(true);
} else {
m_MenuActionMap.value(tr("Set as wallpaper"))->setVisible(false);
Expand Down
14 changes: 14 additions & 0 deletions src/album/utils/baseutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,20 @@ bool isSupportClassify(const QString &path)
return bRet;
}

/**
@return 图片 \a path 是否支持设置为壁纸,同步看图代码
*/
bool isSupportWallpaper(const QString &path)
{
QMimeDatabase db;
QMimeType mt = db.mimeTypeForFile(path, QMimeDatabase::MatchDefault);
return mt.name().startsWith("image")
&& !mt.name().endsWith("svg+xml")
&& !mt.name().endsWith("raf")
&& !mt.name().endsWith("crw")
&& !mt.name().endsWith("x-portable-anymap");
}

} // namespace base

} // namespace utils
2 changes: 2 additions & 0 deletions src/album/utils/baseutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ QImage cheatScaled(const QImage &srcImg, int size, int side);
QImage getThumbnailFromImage(const QImage &srcImg, int size);
//判断图片路径是否支持图片分类
bool isSupportClassify(const QString &path);
//判断图片是否支持设置壁纸
bool isSupportWallpaper(const QString &path);
} // namespace base

} // namespace utils
Expand Down

0 comments on commit 9f3447a

Please sign in to comment.