From eafb3caff163d70accc92dd652c773024cfda47a Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Thu, 19 Sep 2024 09:18:00 +0800 Subject: [PATCH] fix: the tips of unable to open file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix the tips of unable to open file. Log: fix the tips of unable to open file. Bug: https://pms.uniontech.com/bug-view-271335.html v20 BUG 分支合一到v25主线 Task: https://pms.uniontech.com/task-view-383477.html --- src/service/filehander.cpp | 48 ++++++++++++++++++++++++++++++- src/service/filehander.h | 4 +++ translations/deepin-draw_zh_CN.ts | 5 ++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/service/filehander.cpp b/src/service/filehander.cpp index fba204e93..635288b2d 100644 --- a/src/service/filehander.cpp +++ b/src/service/filehander.cpp @@ -676,6 +676,47 @@ QString FileHander::toLegalFile(const QString &filePath) return result; } +bool FileHander::pathControl(const QString &sPath) +{ + if (sPath.isEmpty()) return false; + + QStringList tmpLocation; + tmpLocation << QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + tmpLocation << QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + if (tmpLocation.empty()) { + qWarning() << "Failed to get standard locations"; + return false; + } + + QDBusMessage reply; + QDBusInterface iface("com.deepin.FileArmor1", "/com/deepin/FileArmor1", "com.deepin.FileArmor1", QDBusConnection::systemBus()); + if (!iface.isValid()) { + qWarning() << "Failed to connect to D-Bus interface"; + return false; + } + + for (const QString &location : tmpLocation) { + if (sPath.startsWith(location)) { + qDebug() << "Check location:" << location; + reply = iface.call("GetApps", location); + break; + } + } + + if (reply.type() == QDBusMessage::ReplyMessage) { + QList lValue = reply.arguments().takeFirst().toStringList(); + qDebug() << "App list:" << lValue; + QString strApp = QStandardPaths::findExecutable("deepin-draw"); + // 此路径对画板进行了权限禁用 + if (!strApp.isEmpty() && lValue.contains(strApp)) { + qWarning() << "Permission denied for app:" << strApp; + return true; + } + } + + return false; +} + PageContext *FileHander::loadDdf(const QString &file) { qDebug() << "Loading DDF file:" << file; @@ -738,9 +779,14 @@ QImage FileHander::loadImage(const QString &file) if (checkFileBeforeLoad(file, false)) { auto legalPath = toLegalFile(file); QImage img = loadImage_helper(legalPath, this); - if (img.isNull()) { + if (pathControl(legalPath)){ + qWarning() << "Failed to load image: No permissions"; + d_pri()->setError(EFileNotExist, tr("No permissions to open it")); + return QImage(); + } else if (img.isNull()) { qWarning() << "Failed to load image, file may be damaged"; d_pri()->setError(EDamagedImageFile, tr("Damaged file, unable to open it")); + return QImage(); } #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // 应用颜色空间转换,解决CMYK等格式的颜色显示问题 (仅Qt6) diff --git a/src/service/filehander.h b/src/service/filehander.h index 6f79c1554..e9a02e6f9 100644 --- a/src/service/filehander.h +++ b/src/service/filehander.h @@ -43,6 +43,10 @@ class FileHander: public QObject static bool isLegalFile(const QString &file); static QString toLegalFile(const QString &file); + /** + * @brief pathControl 返回输入sPath文件是否被读写权限管控 + */ + static bool pathControl(const QString &sPath); PageContext *loadDdf(const QString &file); bool saveToDdf(PageContext *context, const QString &file = ""); diff --git a/translations/deepin-draw_zh_CN.ts b/translations/deepin-draw_zh_CN.ts index 18aed1a97..4e9a98817 100644 --- a/translations/deepin-draw_zh_CN.ts +++ b/translations/deepin-draw_zh_CN.ts @@ -543,6 +543,11 @@ Saving... 正在保存... + + + No permissions to open it + 没有权限打开 + Damaged file, unable to open it