diff --git a/src/service/filehander.cpp b/src/service/filehander.cpp index fba204e9..6ef651f6 100644 --- a/src/service/filehander.cpp +++ b/src/service/filehander.cpp @@ -676,6 +676,36 @@ QString FileHander::toLegalFile(const QString &filePath) return result; } +bool FileHander::pathControl(const QString &sPath) +{ + QDBusMessage reply; + QDBusInterface iface("com.deepin.FileArmor1", "/com/deepin/FileArmor1", "com.deepin.FileArmor1", QDBusConnection::systemBus()); + if (iface.isValid()) { + QStringList tmpDocLocation = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + if (tmpDocLocation.size() > 0) { + QString docPath = tmpDocLocation.first(); + if (sPath.startsWith(docPath)) { + reply = iface.call("GetApps", docPath); + } + } + QStringList tmpPicLocation = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + if (tmpPicLocation.size() > 0) { + QString picPath = tmpPicLocation.first(); + if (sPath.startsWith(picPath)) { + reply = iface.call("GetApps", picPath); + } + } + } + if (reply.type() == QDBusMessage::ReplyMessage) { + QList lValue = reply.arguments().takeFirst().toStringList(); + QString strApp = QStandardPaths::findExecutable("deepin-draw"); + if (lValue.contains(strApp)) { + return true; + } + } + return false; +} + PageContext *FileHander::loadDdf(const QString &file) { qDebug() << "Loading DDF file:" << file; @@ -738,7 +768,10 @@ 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")); + } else if (img.isNull()) { qWarning() << "Failed to load image, file may be damaged"; d_pri()->setError(EDamagedImageFile, tr("Damaged file, unable to open it")); } diff --git a/src/service/filehander.h b/src/service/filehander.h index 6f79c155..e9a02e6f 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 18aed1a9..4e9a9881 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