Skip to content

Commit 9cf18a9

Browse files
add-uoslichaofan2008
authored andcommitted
fix: the tips of unable to open file
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
1 parent 27ae242 commit 9cf18a9

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/service/filehander.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,44 @@ QString FileHander::toLegalFile(const QString &filePath)
676676
return result;
677677
}
678678

679+
bool FileHander::pathControl(const QString &sPath)
680+
{
681+
static QStringList tmpDocLocation = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
682+
static QStringList tmpPicLocation = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
683+
684+
QDBusMessage reply;
685+
QDBusInterface iface("com.deepin.FileArmor1", "/com/deepin/FileArmor1", "com.deepin.FileArmor1", QDBusConnection::systemBus());
686+
if (!iface.isValid()) {
687+
qWarning() << "Failed to connect to D-Bus interface";
688+
return false;
689+
}
690+
691+
if (tmpDocLocation.size() > 0) {
692+
QString docPath = tmpDocLocation.first();
693+
if (sPath.startsWith(docPath)) {
694+
reply = iface.call("GetApps", docPath);
695+
} else {
696+
if (tmpPicLocation.size() > 0) {
697+
QString picPath = tmpPicLocation.first();
698+
if (sPath.startsWith(picPath)) {
699+
reply = iface.call("GetApps", picPath);
700+
}
701+
}
702+
}
703+
}
704+
705+
if (reply.type() == QDBusMessage::ReplyMessage) {
706+
QList<QString> lValue = reply.arguments().takeFirst().toStringList();
707+
QString strApp = QStandardPaths::findExecutable("deepin-draw");
708+
// 此路径对画板进行了权限禁用
709+
if (lValue.contains(strApp)) {
710+
return true;
711+
}
712+
}
713+
714+
return false;
715+
}
716+
679717
PageContext *FileHander::loadDdf(const QString &file)
680718
{
681719
qDebug() << "Loading DDF file:" << file;
@@ -738,9 +776,14 @@ QImage FileHander::loadImage(const QString &file)
738776
if (checkFileBeforeLoad(file, false)) {
739777
auto legalPath = toLegalFile(file);
740778
QImage img = loadImage_helper(legalPath, this);
741-
if (img.isNull()) {
779+
if (pathControl(legalPath)){
780+
qWarning() << "Failed to load image: No permissions";
781+
d_pri()->setError(EFileNotExist, tr("No permissions to open it"));
782+
return QImage();
783+
} else if (img.isNull()) {
742784
qWarning() << "Failed to load image, file may be damaged";
743785
d_pri()->setError(EDamagedImageFile, tr("Damaged file, unable to open it"));
786+
return QImage();
744787
}
745788
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
746789
// 应用颜色空间转换,解决CMYK等格式的颜色显示问题 (仅Qt6)

src/service/filehander.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class FileHander: public QObject
4343

4444
static bool isLegalFile(const QString &file);
4545
static QString toLegalFile(const QString &file);
46+
/**
47+
* @brief pathControl 返回输入sPath文件是否被读写权限管控
48+
*/
49+
static bool pathControl(const QString &sPath);
4650

4751
PageContext *loadDdf(const QString &file);
4852
bool saveToDdf(PageContext *context, const QString &file = "");

translations/deepin-draw_zh_CN.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@
543543
<source>Saving...</source>
544544
<translation>正在保存...</translation>
545545
</message>
546+
<message>
547+
<location filename="../src/service/filehander.cpp" line="650"/>
548+
<source>No permissions to open it</source>
549+
<translation>没有权限打开</translation>
550+
</message>
546551
<message>
547552
<location filename="../src/service/filehander.cpp" line="651"/>
548553
<source>Damaged file, unable to open it</source>

0 commit comments

Comments
 (0)