Skip to content

Commit

Permalink
fix: the tips of unable to open file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
add-uos committed Sep 20, 2024
1 parent 8c16a8c commit 87d3aa5
Show file tree
Hide file tree
Showing 4 changed files with 571 additions and 545 deletions.
34 changes: 33 additions & 1 deletion src/service/filehander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,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)
{
d_pri()->unsetError();
Expand Down Expand Up @@ -636,7 +666,9 @@ 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)){
d_pri()->setError(EFileNotExist, tr("No permissions to open it"));
} else if (img.isNull()) {
d_pri()->setError(EDamagedImageFile, tr("Damaged file, unable to open it"));
}
img = img.convertToFormat(QImage::Format_ARGB32);
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
Loading

0 comments on commit 87d3aa5

Please sign in to comment.