Skip to content
Closed
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion src/service/filehander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString> 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;
Expand Down Expand Up @@ -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"));
}
Expand Down
4 changes: 4 additions & 0 deletions src/service/filehander.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "");
Expand Down
5 changes: 5 additions & 0 deletions translations/deepin-draw_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@
<source>Saving...</source>
<translation>正在保存...</translation>
</message>
<message>
<location filename="../src/service/filehander.cpp" line="650"/>
<source>No permissions to open it</source>
<translation>没有权限打开</translation>
</message>
<message>
<location filename="../src/service/filehander.cpp" line="651"/>
<source>Damaged file, unable to open it</source>
Expand Down