Skip to content

Commit

Permalink
fix: [dragdrophelper] Files cannot be dragged to a USB drive, but can…
Browse files Browse the repository at this point in the history
… be copied and cut

Modify the values of canrename and canmovecopy in file information, and add judgments for copyaction and canmovecopy

Log: Files cannot be dragged to a USB drive, but can be copied and cut
Bug: https://pms.uniontech.com/bug-view-275437.html
  • Loading branch information
liyigang1 authored and deepin-bot[bot] committed Oct 10, 2024
1 parent 91bd906 commit f0071dd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/dfm-base/interfaces/fileinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class FileInfo : public AbstractFileInfo, public QEnableSharedFromThis<FileInfo>
kCanTrash = 1, // 可以移动到回收站
kCanRename = 2, // 可以重命名
kCanRedirectionFileUrl = 3, // 可以重定向
kCanMoveOrCopy = 4, // 可以移动或者拷贝
kCanMoveOrCopy = 4, // 可以拷贝,可以移动使用kCanRename去判断
kCanDrop = 5, // 可以Drop
kCanDrag = 6, // 可以drag
kCanDragCompress = 7, // 可以压缩
Expand Down
14 changes: 13 additions & 1 deletion src/dfm-base/file/local/asyncfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ bool AsyncFileInfo::canAttributes(const CanableInfoType type) const
if (FileUtils::isGphotoFile(url))
return false;
return true;
case FileCanType::kCanMoveOrCopy:
// file can not read or dir can not execte,will can not copy
if (!d->asyncAttribute(FileInfo::FileInfoAttributeID::kAccessCanRead).toBool() ||
(d->asyncAttribute(FileInfo::FileInfoAttributeID::kStandardIsDir).toBool() &&
!d->asyncAttribute(FileInfo::FileInfoAttributeID::kAccessCanExecute).toBool()))
return false;
return FileInfo::canAttributes(type);
default:
return FileInfo::canAttributes(type);
}
Expand Down Expand Up @@ -951,8 +958,13 @@ bool AsyncFileInfoPrivate::canRename() const

bool canRename = false;
canRename = SysInfoUtils::isRootUser();
if (!canRename)
if (!canRename) {
// dir can not write, will can not rename
if (this->attribute(DFileInfo::AttributeID::kStandardIsDir).toBool() &&
!this->attribute(DFileInfo::AttributeID::kAccessCanWrite).toBool())
return false;
return this->attribute(DFileInfo::AttributeID::kAccessCanRename).toBool();
}

return canRename;
}
Expand Down
15 changes: 14 additions & 1 deletion src/dfm-base/file/local/syncfileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ bool SyncFileInfo::canAttributes(const CanableInfoType type) const
if (FileUtils::isGphotoFile(url))
return false;
return true;
case FileCanType::kCanMoveOrCopy:
// file can not read or dir can not execte
if (!d->attribute(DFileInfo::AttributeID::kAccessCanRead).toBool() ||
(d->attribute(DFileInfo::AttributeID::kStandardIsDir).toBool() &&
!d->attribute(DFileInfo::AttributeID::kAccessCanExecute).toBool()))
return false;
return FileInfo::canAttributes(type);
default:
return FileInfo::canAttributes(type);
}
Expand Down Expand Up @@ -960,8 +967,14 @@ bool SyncFileInfoPrivate::canRename() const

bool canRename = false;
canRename = SysInfoUtils::isRootUser();
if (!canRename)
if (!canRename) {
// dir can not write, can not rename
if (this->attribute(DFileInfo::AttributeID::kStandardIsDir).toBool() &&
!this->attribute(DFileInfo::AttributeID::kAccessCanWrite).toBool())
return false;

return this->attribute(DFileInfo::AttributeID::kAccessCanRename).toBool();
}

return canRename;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ Qt::DropAction SideBarView::canDropMimeData(SideBarItem *item, const QMimeData *
return Qt::IgnoreAction;
}
//部分文件不能复制或剪切,需要在拖拽时忽略
if (!fileInfo->canAttributes(CanableInfoType::kCanMoveOrCopy)) {
if (!fileInfo->canAttributes(CanableInfoType::kCanMoveOrCopy) &&
!fileInfo->canAttributes(CanableInfoType::kCanRename)) {
return Qt::IgnoreAction;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ bool DragDropHelper::dragEnter(QDragEnterEvent *event)

for (const QUrl &url : currentDragUrls) {
auto info = InfoFactory::create<FileInfo>(url);
if (!info || !info->canAttributes(CanableInfoType::kCanMoveOrCopy)) {
if (!info || (!info->canAttributes(CanableInfoType::kCanMoveOrCopy)
&& !info->canAttributes(CanableInfoType::kCanRename))) {
event->ignore();
return true;
}
Expand Down Expand Up @@ -134,14 +135,12 @@ bool DragDropHelper::dragMove(QDragMoveEvent *event)
return true;
}

// target is not local device, origin is dir and can not write, prohibit drop
// copy action must origin file can copy
const QUrl &targetUrl = hoverFileInfo->urlOf(UrlInfoType::kUrl);
if (!hoverFileInfo->extendAttributes(ExtInfoType::kFileLocalDevice).toBool()) {
if (!info->isAttributes(OptInfoType::kIsWritable)) {
view->setViewSelectState(false);
event->ignore();
return true;
}
if (event->dropAction() == Qt::DropAction::CopyAction && !info->canAttributes(CanableInfoType::kCanMoveOrCopy)) {
view->setViewSelectState(false);
event->ignore();
return true;
}

if (UniversalUtils::urlEquals(targetUrl, url)) {
Expand Down

0 comments on commit f0071dd

Please sign in to comment.