diff --git a/debian/control b/debian/control index b5942e4bfc..b40dcecd37 100644 --- a/debian/control +++ b/debian/control @@ -76,7 +76,7 @@ Depends: libqt6sql6-sqlite, qt6-translations-l10n, libimageeditor6 | hello -Conflicts: dde-workspace (<< 2.90.5), dde-file-manager-oem +Conflicts: dde-workspace (<< 2.90.5), dde-file-manager-oem, dde-desktop-plugins Replaces: dde-file-manager-oem, dde-file-manager (<< 6.0.1), dde-desktop-plugins Recommends: qt5dxcb-plugin, deepin-screensaver, dcc-wallpapersetting-plugin Description: deepin desktop-environment - desktop module @@ -109,6 +109,11 @@ Replaces: dde-file-manager-oem, dde-desktop (<< 6.0.1), dde-file-manager-plugins, dde-file-manager-daemon-plugins, dde-file-manager-common-plugins +Conflicts: dde-file-manager-preview, + dde-file-manager-preview-plugins, + dde-file-manager-plugins, + dde-file-manager-daemon-plugins, + dde-file-manager-common-plugins Recommends: dde-qt5integration, avfs, samba, deepin-anything-server Description: File manager front end File manager front-end of Deepin OS @@ -127,6 +132,7 @@ Multi-Arch: same Description: DDE File Manager core librarys This package contains the shared libraries. Replaces: dfmplugin-disk-encrypt +Conflicts: dfmplugin-disk-encrypt Package: dde-disk-mount-plugin Architecture: any diff --git a/src/dfm-base/base/device/deviceutils.cpp b/src/dfm-base/base/device/deviceutils.cpp index d2dc77e507..1dcd81f6a8 100644 --- a/src/dfm-base/base/device/deviceutils.cpp +++ b/src/dfm-base/base/device/deviceutils.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -75,7 +76,7 @@ QUrl DeviceUtils::getSambaFileUriFromNative(const QUrl &url) if (!url.isValid()) return QUrl(); - if (!DeviceUtils::isSamba(url)) + if (!ProtocolUtils::isSMBFile(url)) return url; QUrl smbUrl; @@ -93,7 +94,7 @@ QUrl DeviceUtils::getSambaFileUriFromNative(const QUrl &url) // /root/.gvfs/smb-share...../helloworld.txt // /media/user/smbmounts/smb-share...../helloworld.txt // ======> helloworld.txt - static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*/|^/root/.gvfs/[^/]*/|^/media/.*/smbmounts/[^/]*/)"); + static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*/|^/root/.gvfs/[^/]*/|^/(?:run/)?media/.*/smbmounts/[^/]*/)"); QString fileName = fullPath.remove(prefix); fileName.chop(1); // remove last '/'. @@ -270,44 +271,12 @@ bool DeviceUtils::isPWUserspaceOpticalDiscDev(const QString &dev) return isPWOpticalDiscDev(dev); } -bool DeviceUtils::isSamba(const QUrl &url) -{ - if (url.scheme() == Global::Scheme::kSmb) - return true; - static const QString smbMatch { "(^/run/user/\\d+/gvfs/smb|^/root/\\.gvfs/smb|^/media/[\\s\\S]*/smbmounts)" }; // TODO(xust) /media/$USER/smbmounts might be changed in the future.} - return hasMatch(url.path(), smbMatch); -} - -bool DeviceUtils::isFtp(const QUrl &url) -{ - static const QString smbMatch { "(^/run/user/\\d+/gvfs/s?ftp|^/root/\\.gvfs/s?ftp)" }; - return hasMatch(url.path(), smbMatch); -} - -bool DeviceUtils::isSftp(const QUrl &url) -{ - static const QString smbMatch { "(^/run/user/\\d+/gvfs/sftp|^/root/\\.gvfs/sftp)" }; - return hasMatch(url.path(), smbMatch); -} - -bool DeviceUtils::isMtpFile(const QUrl &url) -{ - if (!url.isValid()) - return false; - - const QString &path = url.toLocalFile(); - static const QString gvfsMatch { R"(^/run/user/\d+/gvfs/mtp:host|^/root/.gvfs/mtp:host)" }; - QRegularExpression re { gvfsMatch }; - QRegularExpressionMatch match { re.match(path) }; - return match.hasMatch(); -} - bool DeviceUtils::supportDfmioCopyDevice(const QUrl &url) { if (!url.isValid()) return false; - return !isMtpFile(url); + return !ProtocolUtils::isMTPFile(url); } bool DeviceUtils::supportSetPermissionsDevice(const QUrl &url) @@ -315,17 +284,12 @@ bool DeviceUtils::supportSetPermissionsDevice(const QUrl &url) if (!url.isValid()) return false; - return !isMtpFile(url); -} - -bool DeviceUtils::isExternalBlock(const QUrl &url) -{ - return DeviceProxyManager::instance()->isFileOfExternalBlockMounts(url.path()); + return !ProtocolUtils::isMTPFile(url); } QUrl DeviceUtils::parseNetSourceUrl(const QUrl &target) { - if (!isSamba(target) && !isFtp(target)) + if (!ProtocolUtils::isSMBFile(target) && !ProtocolUtils::isFTPFile(target)) return {}; QString host, port; @@ -334,7 +298,7 @@ QUrl DeviceUtils::parseNetSourceUrl(const QUrl &target) return {}; QString protocol, share; - if (isSamba(target)) { + if (ProtocolUtils::isSMBFile(target)) { protocol = "smb"; static const QRegularExpression regxSmb(R"(,share=([^,/]*))"); auto match = regxSmb.match(target.path()); @@ -343,10 +307,10 @@ QUrl DeviceUtils::parseNetSourceUrl(const QUrl &target) else return {}; } else { - protocol = isSftp(target) ? "sftp" : "ftp"; + protocol = ProtocolUtils::isSFTPFile(target) ? "sftp" : "ftp"; } - static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*|^/media/.*/smbmounts/[^/]*)"); + static const QRegularExpression prefix(R"(^/run/user/.*/gvfs/[^/]*|^/(?:run/)?media/.*/smbmounts/[^/]*)"); QString dirPath = target.path(); dirPath.remove(prefix); dirPath.prepend(share); @@ -411,11 +375,12 @@ QString DeviceUtils::nameOfSystemDisk(const QVariantMap &datas) QString mountPoint = clearInfo.value(kMountPoint, datas.value(kMountPoint)).toString(); QString label = clearInfo.value(kIdLabel, datas.value(kIdLabel)).toString(); qlonglong size = datas.value(kSizeTotal).toLongLong(); + bool canPowerOff = datas.value(kCanPowerOff).toBool(); // get system disk name if there is no alias if (mountPoint == "/") return QObject::tr("System Disk"); - if (!mountPoint.startsWith("/media/") && !mountPoint.isEmpty()) { + if (!canPowerOff && !mountPoint.isEmpty()) { if (label.startsWith("_dde_data")) return QObject::tr("Data Disk"); if (label.startsWith("_dde_")) @@ -605,19 +570,6 @@ bool DeviceUtils::isMountPointOfDlnfs(const QString &path) }); } -bool DeviceUtils::isLowSpeedDevice(const QUrl &url) -{ - if (!url.isValid()) - return false; - - const QString &path = url.toLocalFile(); - static const QString lowSpeedMountpoint { "(^/run/user/\\d+/gvfs/|^/root/.gvfs/|^/media/[\\s\\S]*/smbmounts)" }; - // TODO(xust) /media/$USER/smbmounts might be changed in the future. - QRegularExpression re { lowSpeedMountpoint }; - QRegularExpressionMatch match { re.match(path) }; - return match.hasMatch(); -} - /*! * \brief DeviceUtils::getLongestMountRootPath: get the mount root of a file `filePath` * return `/home/` for `/home/helloworld.txt`, eg. @@ -677,7 +629,7 @@ qint64 DeviceUtils::deviceBytesFree(const QUrl &url) bool DeviceUtils::isUnmountSamba(const QUrl &url) { - if (!isSamba(url)) + if (!ProtocolUtils::isSMBFile(url)) return false; return !DevProxyMng->isFileOfProtocolMounts(url.path()); diff --git a/src/dfm-base/base/device/deviceutils.h b/src/dfm-base/base/device/deviceutils.h index 53bdaabf56..9e844e9d35 100644 --- a/src/dfm-base/base/device/deviceutils.h +++ b/src/dfm-base/base/device/deviceutils.h @@ -48,13 +48,8 @@ class DeviceUtils static bool isPWOpticalDiscDev(const QString &dev); static bool isPWUserspaceOpticalDiscDev(const QString &dev); - static bool isSamba(const QUrl &url); - static bool isFtp(const QUrl &url); - static bool isSftp(const QUrl &url); - static bool isMtpFile(const QUrl &url); static bool supportDfmioCopyDevice(const QUrl &url); static bool supportSetPermissionsDevice(const QUrl &url); - static bool isExternalBlock(const QUrl &url); static QUrl parseNetSourceUrl(const QUrl &target); static bool parseSmbInfo(const QString &smbPath, QString &host, QString &share, QString *port = nullptr); @@ -73,7 +68,6 @@ class DeviceUtils static bool isSubpathOfDlnfs(const QString &path); static bool isMountPointOfDlnfs(const QString &path); - static bool isLowSpeedDevice(const QUrl &url); static QString getLongestMountRootPath(const QString &filePath); diff --git a/src/dfm-base/base/device/private/devicehelper.cpp b/src/dfm-base/base/device/private/devicehelper.cpp index 04cf3a4e45..147f640b16 100644 --- a/src/dfm-base/base/device/private/devicehelper.cpp +++ b/src/dfm-base/base/device/private/devicehelper.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -375,7 +376,7 @@ void DeviceHelper::readOpticalInfo(QVariantMap &datas) bool DeviceHelper::checkNetworkConnection(const QString &id) { QUrl url(id); - if (!(DeviceUtils::isSamba(url) || DeviceUtils::isSftp(url) || DeviceUtils::isFtp(url))) + if (!(ProtocolUtils::isSMBFile(url) || ProtocolUtils::isSFTPFile(url) || ProtocolUtils::isFTPFile(url))) return true; QString host, port; @@ -414,7 +415,7 @@ QVariantMap DeviceHelper::makeFakeProtocolInfo(const QString &id) fakeInfo[DeviceProperty::kDeviceIcon] = "folder-remote"; fakeInfo["fake"] = true; - if (DeviceUtils::isSamba(QUrl(path))) { + if (ProtocolUtils::isSMBFile(QUrl(path))) { QString host, share; if (DeviceUtils::parseSmbInfo(path, host, share)) fakeInfo[DeviceProperty::kDisplayName] = QObject::tr("%1 on %2").arg(share).arg(host); diff --git a/src/dfm-base/base/schemefactory.cpp b/src/dfm-base/base/schemefactory.cpp index 9e3c37bb4d..c553b250fa 100644 --- a/src/dfm-base/base/schemefactory.cpp +++ b/src/dfm-base/base/schemefactory.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include -#include +#include namespace dfmbase { @@ -19,7 +19,7 @@ QString InfoFactory::scheme(const QUrl &url) if (scheme != Global::Scheme::kFile) return scheme; - if (!FileUtils::isLocalDevice(url)) + if (!ProtocolUtils::isLocalFile(url)) return Global::Scheme::kAsyncFile; dfmio::DFileInfo dinfo(url); @@ -27,7 +27,7 @@ QString InfoFactory::scheme(const QUrl &url) return scheme; auto targetPath = dinfo.attribute(dfmio::DFileInfo::AttributeID::kStandardSymlinkTarget).toString(); - if (!targetPath.isEmpty() && !FileUtils::isLocalDevice(QUrl::fromLocalFile(targetPath))) + if (!targetPath.isEmpty() && !ProtocolUtils::isLocalFile(QUrl::fromLocalFile(targetPath))) scheme = Global::Scheme::kAsyncFile; return scheme; diff --git a/src/dfm-base/file/local/asyncfileinfo.cpp b/src/dfm-base/file/local/asyncfileinfo.cpp index a2ffc2ef78..57acebaa8b 100644 --- a/src/dfm-base/file/local/asyncfileinfo.cpp +++ b/src/dfm-base/file/local/asyncfileinfo.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -130,10 +131,10 @@ QString AsyncFileInfo::nameOf(const NameInfoType type) const return FileInfo::nameOf(type); } /*! - * \brief 获取文件路径,默认是文件全路径,此接口不会实现异步,全部使用Qurl去 - * 处理或者字符串处理,这都比较快 - * \param FileNameInfoType - */ + * \brief 获取文件路径,默认是文件全路径,此接口不会实现异步,全部使用Qurl去 + * 处理或者字符串处理,这都比较快 + * \param FileNameInfoType + */ QString AsyncFileInfo::pathOf(const PathInfoType type) const { switch (type) { @@ -168,7 +169,7 @@ QUrl AsyncFileInfo::urlOf(const UrlInfoType type) const switch (type) { case FileUrlInfoType::kRedirectedFileUrl: return d->redirectedFileUrl(); - case FileUrlInfoType::kOriginalUrl:{ + case FileUrlInfoType::kOriginalUrl: { auto originalUri = d->asyncAttribute(FileInfo::FileInfoAttributeID::kOriginalUri); if (originalUri.isValid()) return QUrl(originalUri.toString()); @@ -218,7 +219,7 @@ bool AsyncFileInfo::canAttributes(const CanableInfoType type) const case FileCanType::kCanRename: return d->asyncAttribute(FileInfo::FileInfoAttributeID::kAccessCanRename).toBool(); case FileCanType::kCanHidden: - if (FileUtils::isGphotoFile(url)) + if (ProtocolUtils::isGphotoFile(url)) return false; return true; default: @@ -715,7 +716,7 @@ QIcon AsyncFileInfoPrivate::defaultIcon() QString AsyncFileInfoPrivate::fileName() const { QString fileName = this->attribute(DFileInfo::AttributeID::kStandardName).toString(); - if (fileName == R"(/)" && FileUtils::isGvfsFile(q->fileUrl())) + if (fileName == R"(/)" && ProtocolUtils::isRemoteFile(q->fileUrl())) fileName = this->attribute(DFileInfo::AttributeID::kIdFilesystem).toString(); return fileName; } @@ -761,7 +762,7 @@ QString AsyncFileInfoPrivate::iconName() const if (!list.isEmpty()) iconNameValue = list.first(); } - if (!FileUtils::isGvfsFile(q->fileUrl()) && iconNameValue.isEmpty()) + if (!ProtocolUtils::isRemoteFile(q->fileUrl()) && iconNameValue.isEmpty()) iconNameValue = q->fileMimeType().iconName(); if (iconNameValue.isEmpty() && q->isAttributes(OptInfoType::kIsDir)) iconNameValue = "folder"; @@ -772,7 +773,7 @@ QString AsyncFileInfoPrivate::mimeTypeName() const { // At present, there is no dfmio library code. For temporary repair // local file use the method on v20 to obtain mimeType - if (FileUtils::isGvfsFile(q->fileUrl())) { + if (ProtocolUtils::isRemoteFile(q->fileUrl())) { return asyncAttribute(FileInfo::FileInfoAttributeID::kStandardContentType).toString(); } return q->fileMimeType().name(); @@ -795,7 +796,7 @@ QString AsyncFileInfoPrivate::fileDisplayName() const QString fileDisplayName = this->attribute(DFileInfo::AttributeID::kStandardDisplayName, &ok).toString(); if (fileDisplayName.isEmpty() || !ok) fileDisplayName = q->fileUrl().fileName(); - if (fileDisplayName == R"(/)" && FileUtils::isGvfsFile(q->fileUrl())) + if (fileDisplayName == R"(/)" && ProtocolUtils::isRemoteFile(q->fileUrl())) fileDisplayName = this->attribute(DFileInfo::AttributeID::kIdFilesystem).toString(); return fileDisplayName; @@ -890,7 +891,7 @@ bool AsyncFileInfoPrivate::isExecutable() const if (!success) { qCDebug(logDFMBase) << "cannot obtain the property kAccessCanExecute of" << q->fileUrl(); - if (FileUtils::isGvfsFile(q->fileUrl())) { + if (ProtocolUtils::isRemoteFile(q->fileUrl())) { qCDebug(logDFMBase) << "trying to get isExecutable by judging whether the dir can be iterated" << q->fileUrl(); struct dirent *next { nullptr }; DIR *dirp = opendir(filePath().toUtf8().constData()); @@ -1104,7 +1105,7 @@ int AsyncFileInfoPrivate::cacheAllAttributes(const QString &attributes) auto symlink = symLinkTarget(); if (attribute(DFileInfo::AttributeID::kStandardIsSymlink).toBool() && !symlink.isEmpty() - && !FileUtils::isLocalDevice(QUrl::fromLocalFile(symlink))) { + && !ProtocolUtils::isLocalFile(QUrl::fromLocalFile(symlink))) { FileInfoPointer info = InfoFactory::create(QUrl::fromLocalFile(symlink)); auto asyncInfo = info.dynamicCast(); if (asyncInfo) { diff --git a/src/dfm-base/file/local/localdiriterator.cpp b/src/dfm-base/file/local/localdiriterator.cpp index 877f84b6c1..7f942d0096 100644 --- a/src/dfm-base/file/local/localdiriterator.cpp +++ b/src/dfm-base/file/local/localdiriterator.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -62,7 +63,7 @@ FileInfoPointer LocalDirIteratorPrivate::fileInfo(const QSharedPointerattribute(dfmio::DFileInfo::AttributeID::kStandardSymlinkTarget).toString(); - if (FileUtils::isLocalDevice(url) && (targetPath.isEmpty() || FileUtils::isLocalDevice(QUrl::fromLocalFile(targetPath)))) { + if (ProtocolUtils::isLocalFile(url) && (targetPath.isEmpty() || ProtocolUtils::isLocalFile(QUrl::fromLocalFile(targetPath)))) { info = QSharedPointer(new SyncFileInfo(url)); } else { info = QSharedPointer(new AsyncFileInfo(url, dfmInfo)); @@ -72,7 +73,7 @@ FileInfoPointer LocalDirIteratorPrivate::fileInfo(const QSharedPointerproperty("QueryAttributes").toString().isEmpty() - && q->property("QueryAttributes").toString() != "*") { + && q->property("QueryAttributes").toString() != "*") { info->setExtendedAttributes(ExtInfoType::kFileNeedUpdate, true); info->setExtendedAttributes(ExtInfoType::kFileNeedTransInfo, true); } @@ -212,7 +213,7 @@ void LocalDirIterator::cacheBlockIOAttribute() const QUrl &rootUrl = this->url(); const QUrl &url = DFMIO::DFMUtils::buildFilePath(rootUrl.toString().toStdString().c_str(), ".hidden", nullptr); d->hideFileList = DFMIO::DFMUtils::hideListFromUrl(url); - d->isLocalDevice = FileUtils::isLocalDevice(rootUrl); + d->isLocalDevice = ProtocolUtils::isLocalFile(rootUrl); d->isCdRomDevice = FileUtils::isCdRomDevice(rootUrl); } @@ -266,7 +267,7 @@ bool LocalDirIterator::oneByOne() if (info) return !info->extendAttributes(ExtInfoType::kFileLocalDevice).toBool() || !d->dfmioDirIterator; - return !FileUtils::isLocalDevice(url()) || !d->dfmioDirIterator; + return !ProtocolUtils::isLocalFile(url()) || !d->dfmioDirIterator; } bool LocalDirIterator::initIterator() diff --git a/src/dfm-base/file/local/localfilehandler.cpp b/src/dfm-base/file/local/localfilehandler.cpp index 775cfb19ca..6b422c3a19 100644 --- a/src/dfm-base/file/local/localfilehandler.cpp +++ b/src/dfm-base/file/local/localfilehandler.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -178,7 +179,7 @@ bool LocalFileHandler::renameFile(const QUrl &url, const QUrl &newUrl, const boo } // check device, use set displayname if device is mtp - if (Q_UNLIKELY(FileUtils::isMtpFile(newUrl))) { + if (Q_UNLIKELY(ProtocolUtils::isMTPFile(newUrl))) { const QUrl &fromParentUrl = UrlRoute::urlParent(url); const QUrl &toParentUrl = UrlRoute::urlParent(newUrl); if (fromParentUrl == toParentUrl) { @@ -723,7 +724,7 @@ bool LocalFileHandlerPrivate::isInvalidSymlinkFile(const QUrl &url) return true; const QString &path { info->pathOf(PathInfoType::kAbsoluteFilePath) }; - if (!DFMIO::DFile(path).exists() && !DeviceUtils::isSamba(url)) + if (!DFMIO::DFile(path).exists() && !ProtocolUtils::isSMBFile(url)) return true; return false; @@ -1106,7 +1107,7 @@ bool LocalFileHandlerPrivate::doOpenFiles(const QList &urls, const QString if (openResult || openMount || openCmd) return true; - if (DeviceUtils::isSamba(transUrls[0])) + if (ProtocolUtils::isSMBFile(transUrls[0])) return false; QStringList paths; diff --git a/src/dfm-base/file/local/syncfileinfo.cpp b/src/dfm-base/file/local/syncfileinfo.cpp index 732c49e003..fa830716eb 100644 --- a/src/dfm-base/file/local/syncfileinfo.cpp +++ b/src/dfm-base/file/local/syncfileinfo.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -236,7 +237,7 @@ bool SyncFileInfo::canAttributes(const CanableInfoType type) const case FileCanType::kCanRename: return d->canRename(); case FileCanType::kCanHidden: - if (FileUtils::isGphotoFile(url)) + if (ProtocolUtils::isGphotoFile(url)) return false; return true; default: @@ -724,7 +725,7 @@ void SyncFileInfoPrivate::updateMediaInfo(const DFileInfo::MediaType type, const QString SyncFileInfoPrivate::fileName() const { QString fileName = this->attribute(DFileInfo::AttributeID::kStandardName).toString(); - if (fileName == R"(/)" && FileUtils::isGvfsFile(q->fileUrl())) + if (fileName == R"(/)" && ProtocolUtils::isRemoteFile(q->fileUrl())) fileName = this->attribute(DFileInfo::AttributeID::kIdFilesystem).toString(); return fileName; } @@ -773,7 +774,7 @@ QString SyncFileInfoPrivate::iconName() const iconNameValue = *iter; } - if (!FileUtils::isGvfsFile(q->fileUrl()) && iconNameValue.isEmpty()) + if (!ProtocolUtils::isRemoteFile(q->fileUrl()) && iconNameValue.isEmpty()) iconNameValue = q->fileMimeType().iconName(); return iconNameValue; @@ -783,7 +784,7 @@ QString SyncFileInfoPrivate::mimeTypeName() const { // At present, there is no dfmio library code. For temporary repair // local file use the method on v20 to obtain mimeType - if (FileUtils::isGvfsFile(q->fileUrl())) { + if (ProtocolUtils::isRemoteFile(q->fileUrl())) { return this->attribute(DFileInfo::AttributeID::kStandardContentType).toString(); } return q->fileMimeType().name(); @@ -804,7 +805,7 @@ QString SyncFileInfoPrivate::fileDisplayName() const } QString fileDisplayName = this->attribute(DFileInfo::AttributeID::kStandardDisplayName).toString(); - if (fileDisplayName == R"(/)" && FileUtils::isGvfsFile(q->fileUrl())) + if (fileDisplayName == R"(/)" && ProtocolUtils::isRemoteFile(q->fileUrl())) fileDisplayName = this->attribute(DFileInfo::AttributeID::kIdFilesystem).toString(); return fileDisplayName; @@ -899,7 +900,7 @@ bool SyncFileInfoPrivate::isExecutable() const if (!success) { qCWarning(logDFMBase) << "cannot obtain the property kAccessCanExecute of" << q->fileUrl(); - if (FileUtils::isGvfsFile(q->fileUrl())) { + if (ProtocolUtils::isRemoteFile(q->fileUrl())) { qCDebug(logDFMBase) << "trying to get isExecutable by judging whether the dir can be iterated" << q->fileUrl(); struct dirent *next { nullptr }; DIR *dirp = opendir(filePath().toUtf8().constData()); diff --git a/src/dfm-base/mimetype/dmimedatabase.cpp b/src/dfm-base/mimetype/dmimedatabase.cpp index 8e35ad4df1..a6f07eb15a 100644 --- a/src/dfm-base/mimetype/dmimedatabase.cpp +++ b/src/dfm-base/mimetype/dmimedatabase.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -71,7 +72,7 @@ QMimeType DMimeDatabase::mimeTypeForFile(const FileInfoPointer &fileInfo, QMimeD } } - if (isMatchExtension || DeviceUtils::isLowSpeedDevice(QUrl::fromLocalFile(path))) { + if (isMatchExtension || ProtocolUtils::isRemoteFile(QUrl::fromLocalFile(path))) { result = QMimeDatabase::mimeTypeForFile(fileInfo->pathOf(PathInfoType::kFilePath), QMimeDatabase::MatchExtension); } else { result = QMimeDatabase::mimeTypeForFile(fileInfo->pathOf(PathInfoType::kFilePath), mode); @@ -147,7 +148,7 @@ QMimeType DMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, QMimeDatabas isMatchExtension = blackList.contains(filePath); } } - if (isMatchExtension || DeviceUtils::isLowSpeedDevice(QUrl::fromLocalFile(path))) { + if (isMatchExtension || ProtocolUtils::isRemoteFile(QUrl::fromLocalFile(path))) { result = QMimeDatabase::mimeTypeForFile(fileInfo, QMimeDatabase::MatchExtension); } else { result = QMimeDatabase::mimeTypeForFile(fileInfo, mode); diff --git a/src/dfm-base/qrc/configure/dde-file-manager.default.json b/src/dfm-base/qrc/configure/dde-file-manager.default.json index 20251c1f7a..cf8e3823e1 100644 --- a/src/dfm-base/qrc/configure/dde-file-manager.default.json +++ b/src/dfm-base/qrc/configure/dde-file-manager.default.json @@ -39,7 +39,8 @@ "WhiteList":[ "/media", "/home", - "/run/media" + "/run/media", + "/var/home" ], "BlackList": [ "~/.local/share/Trash" diff --git a/src/dfm-base/utils/fileinfohelper.cpp b/src/dfm-base/utils/fileinfohelper.cpp index 1fdb1547dc..71497d52b2 100644 --- a/src/dfm-base/utils/fileinfohelper.cpp +++ b/src/dfm-base/utils/fileinfohelper.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -145,9 +145,9 @@ void FileInfoHelper::handleFileRefresh(QSharedPointer dfileInfo) Q_UNUSED(data); if (!success) { FileInfoHelper::instance().checkInfoRefresh(asyncInfo); - if (DeviceUtils::isSamba(asyncInfo->fileUrl()) - && asyncInfo->errorCodeFromDfmio() == DFMIOErrorCode::DFM_IO_ERROR_HOST_IS_DOWN - && !NetworkUtils::instance()->checkFtpOrSmbBusy(asyncInfo->fileUrl())) { + if (ProtocolUtils::isSMBFile(asyncInfo->fileUrl()) + && asyncInfo->errorCodeFromDfmio() == DFMIOErrorCode::DFM_IO_ERROR_HOST_IS_DOWN + && !NetworkUtils::instance()->checkFtpOrSmbBusy(asyncInfo->fileUrl())) { emit this->smbSeverMayModifyPassword(asyncInfo->fileUrl()); } return; diff --git a/src/dfm-base/utils/fileutils.cpp b/src/dfm-base/utils/fileutils.cpp index 8bf1066fbf..0b79b7f120 100644 --- a/src/dfm-base/utils/fileutils.cpp +++ b/src/dfm-base/utils/fileutils.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -160,43 +161,6 @@ int FileUtils::supportedMaxLength(const QString &fileSystem) return datas.value(fileSystem.toLower(), 11); } -bool FileUtils::isGvfsFile(const QUrl &url) -{ - if (!url.isValid()) - return false; - - const QString &path = url.toLocalFile(); - static const QString gvfsMatch { "(^/run/user/\\d+/gvfs/|^/root/.gvfs/|^/media/[\\s\\S]*/smbmounts)" }; - // TODO(xust) /media/$USER/smbmounts might be changed in the future. - QRegularExpression re { gvfsMatch }; - QRegularExpressionMatch match { re.match(path) }; - return match.hasMatch(); -} - -bool FileUtils::isMtpFile(const QUrl &url) -{ - if (!url.isValid()) - return false; - - const QString &path = url.toLocalFile(); - static const QString gvfsMatch { R"(^/run/user/\d+/gvfs/mtp:host|^/root/.gvfs/mtp:host)" }; - QRegularExpression re { gvfsMatch }; - QRegularExpressionMatch match { re.match(path) }; - return match.hasMatch(); -} - -bool FileUtils::isGphotoFile(const QUrl &url) -{ - if (!url.isValid()) - return false; - - const QString &path = url.toLocalFile(); - static const QString gvfsMatch { R"(^/run/user/\d+/gvfs/gphoto2:host|^/root/.gvfs/gphoto2:host)" }; - QRegularExpression re { gvfsMatch }; - QRegularExpressionMatch match { re.match(path) }; - return match.hasMatch(); -} - QString FileUtils::preprocessingFileName(QString name) { // eg: [\\:*\"?<>|\r\n] @@ -378,21 +342,6 @@ bool FileUtils::isSameFile(const QString &path1, const QString &path2) return false; } -bool FileUtils::isLocalDevice(const QUrl &url) -{ - //return !DFMIO::DFMUtils::fileIsRemovable(url) && !isGvfsFile(url); - if (isGvfsFile(url)) - return false; - - if (DeviceUtils::isExternalBlock(url)) - return false; - - if (DevProxyMng->isFileOfProtocolMounts(url.path())) - return false; - - return true; -} - bool FileUtils::isCdRomDevice(const QUrl &url) { return DFMIO::DFMUtils::devicePathFromUrl(url).startsWith("/dev/sr"); @@ -1013,16 +962,16 @@ bool FileUtils::containsCopyingFileUrl(const QUrl &url) return copyingUrl.contains(url); } -// TODO: remot it! +// TODO: remove it! void FileUtils::notifyFileChangeManual(DFMGLOBAL_NAMESPACE::FileNotifyType type, const QUrl &url) { if (!url.isValid()) return; auto isRemoteMount = [=](const QUrl &url) -> bool { - if (DeviceUtils::isSamba(url)) + if (ProtocolUtils::isSMBFile(url)) return true; - if (DeviceUtils::isFtp(url)) + if (ProtocolUtils::isFTPFile(url)) return true; return false; diff --git a/src/dfm-base/utils/fileutils.h b/src/dfm-base/utils/fileutils.h index 625c39bd46..07cc56f970 100644 --- a/src/dfm-base/utils/fileutils.h +++ b/src/dfm-base/utils/fileutils.h @@ -27,9 +27,6 @@ class FileUtils public: static QString formatSize(qint64 num, bool withUnitVisible = true, int precision = 1, int forceUnit = -1, QStringList unitList = QStringList()); static int supportedMaxLength(const QString &fileSystem); - static bool isGvfsFile(const QUrl &url); - static bool isMtpFile(const QUrl &url); - static bool isGphotoFile(const QUrl &url); static QString preprocessingFileName(QString name); static bool processLength(const QString &srcText, int srcPos, int maxLen, bool useCharCount, QString &dstText, int &dstPos); static bool isContainProhibitPath(const QList &urls); @@ -46,7 +43,6 @@ class FileUtils static bool isSameFile(const QUrl &url1, const QUrl &url2, const Global::CreateFileInfoType infoCache = Global::CreateFileInfoType::kCreateFileInfoAuto); static bool isSameFile(const QString &path1, const QString &path2); - static bool isLocalDevice(const QUrl &url); static bool isCdRomDevice(const QUrl &url); static bool trashIsEmpty(); static QUrl trashRootUrl(); diff --git a/src/dfm-base/utils/networkutils.cpp b/src/dfm-base/utils/networkutils.cpp index 6229fba5f0..8d9f950891 100644 --- a/src/dfm-base/utils/networkutils.cpp +++ b/src/dfm-base/utils/networkutils.cpp @@ -99,7 +99,7 @@ bool NetworkUtils::parseIp(const QString &mpt, QString &ip, QString &port) { QString s(mpt); static QRegularExpression gvfsPref { "(^/run/user/\\d+/gvfs/|^/root/\\.gvfs/)" }; - static QRegularExpression cifsMptPref { "^/media/[\\s\\S]*/smbmounts/" }; // TODO(xust) smb mount point may be changed. + static QRegularExpression cifsMptPref { "^/(?:run/)?media/[\\s\\S]*/smbmounts/" }; if (s.contains(gvfsPref)) { s.remove(gvfsPref); diff --git a/src/dfm-base/utils/protocolutils.cpp b/src/dfm-base/utils/protocolutils.cpp new file mode 100644 index 0000000000..ee1257a24f --- /dev/null +++ b/src/dfm-base/utils/protocolutils.cpp @@ -0,0 +1,92 @@ +// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later +#include "protocolutils.h" + +#include +#include + +DFMBASE_BEGIN_NAMESPACE + +namespace ProtocolUtils { + +static bool hasMatch(const QString &txt, const QString &rex) +{ + QRegularExpression re(rex); + QRegularExpressionMatch match = re.match(txt); + return match.hasMatch(); +} + +bool isRemoteFile(const QUrl &url) +{ + if (!url.isValid()) + return false; + + // TODO(xust) smbmounts path might be changed in the future. + static const QString gvfsMatch { R"((^/run/user/\d+/gvfs/|^/root/.gvfs/|^/(?:run/)?media/[\s\S]*/smbmounts))" }; + return hasMatch(url.toLocalFile(), gvfsMatch); +} + +bool isMTPFile(const QUrl &url) +{ + if (!url.isValid()) + return false; + + static const QString gvfsMatch { R"(^/run/user/\d+/gvfs/mtp:host|^/root/.gvfs/mtp:host)" }; + return hasMatch(url.toLocalFile(), gvfsMatch); +} + +bool isGphotoFile(const QUrl &url) +{ + if (!url.isValid()) + return false; + + static const QString gvfsMatch { R"(^/run/user/\d+/gvfs/gphoto2:host|^/root/.gvfs/gphoto2:host)" }; + return hasMatch(url.toLocalFile(), gvfsMatch); +} + +bool isFTPFile(const QUrl &url) +{ + if (!url.isValid()) + return false; + + static const QString smbMatch { R"((^/run/user/\d+/gvfs/s?ftp|^/root/.gvfs/s?ftp))" }; + return hasMatch(url.path(), smbMatch); +} + +bool isSFTPFile(const QUrl &url) +{ + if (!url.isValid()) + return false; + + static const QString smbMatch { R"((^/run/user/\d+/gvfs/sftp|^/root/.gvfs/sftp))" }; + return hasMatch(url.path(), smbMatch); +} + +bool isSMBFile(const QUrl &url) +{ + if (!url.isValid()) + return false; + if (url.scheme() == Global::Scheme::kSmb) + return true; + // TODO(xust) smbmounts path might be changed in the future. + static const QString smbMatch { R"((^/run/user/\d+/gvfs/smb|^/root/.gvfs/smb|^/(?:run/)?media/[\s\S]*/smbmounts))" }; + return hasMatch(url.path(), smbMatch); +} + +bool isLocalFile(const QUrl &url) +{ + if (!url.isLocalFile()) + return false; + if (isRemoteFile(url)) + return false; + if (DevProxyMng->isFileOfExternalBlockMounts(url.path())) + return false; + if (DevProxyMng->isFileOfProtocolMounts(url.path())) + return false; + + return true; +} + +} // namespace ProtocolUtils + +DFMBASE_END_NAMESPACE diff --git a/src/dfm-base/utils/protocolutils.h b/src/dfm-base/utils/protocolutils.h new file mode 100644 index 0000000000..4585706d1e --- /dev/null +++ b/src/dfm-base/utils/protocolutils.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later +#ifndef PROTOCOLUTILS_H +#define PROTOCOLUTILS_H + +#include + +DFMBASE_BEGIN_NAMESPACE + +namespace ProtocolUtils { +bool isLocalFile(const QUrl &url); +bool isRemoteFile(const QUrl &url); +bool isMTPFile(const QUrl &url); +bool isGphotoFile(const QUrl &url); +bool isFTPFile(const QUrl &url); +bool isSFTPFile(const QUrl &url); +bool isSMBFile(const QUrl &url); +} // namespace ProtocolUtils + +DFMBASE_END_NAMESPACE + +#endif // PROTOCOLUTILS_H diff --git a/src/dfm-base/utils/systempathutil.h b/src/dfm-base/utils/systempathutil.h index ecf2a6cb88..665791fdc2 100644 --- a/src/dfm-base/utils/systempathutil.h +++ b/src/dfm-base/utils/systempathutil.h @@ -29,9 +29,7 @@ class SystemPathUtil final : public QObject QString systemPathIconNameByPath(QString path); bool isSystemPath(QString path) const; bool checkContainsSystemPath(const QList &urlList); - - // 将URL列表转换为规范路径,保持符号链接的原始路径 - static QList canonicalUrlList(const QList &urls); + QList canonicalUrlList(const QList &urls); private: explicit SystemPathUtil(QObject *parent = nullptr); diff --git a/src/dfm-base/utils/thumbnail/thumbnailhelper.cpp b/src/dfm-base/utils/thumbnail/thumbnailhelper.cpp index c8d8bdefa3..350b2b3f3b 100644 --- a/src/dfm-base/utils/thumbnail/thumbnailhelper.cpp +++ b/src/dfm-base/utils/thumbnail/thumbnailhelper.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include @@ -138,16 +139,17 @@ QString ThumbnailHelper::saveThumbnail(const QUrl &url, const QImage &img, Thumb makePath(thumbnailPath); - QMetaObject::invokeMethod(QCoreApplication::instance(), [img, thumbnailFilePath, fileUrl, fileModify]() { - Q_ASSERT(QThread::currentThread() == qApp->thread()); - QImage tmpImg = img; - tmpImg.setText(QT_STRINGIFY(Thumb::URL), fileUrl); - tmpImg.setText(QT_STRINGIFY(Thumb::MTime), QString::number(fileModify)); - if (!tmpImg.save(thumbnailFilePath, Q_NULLPTR, 50)) { - qCWarning(logDFMBase) << "thumbnail: save failed." << fileUrl; - } - }, - Qt::QueuedConnection); + QMetaObject::invokeMethod( + QCoreApplication::instance(), [img, thumbnailFilePath, fileUrl, fileModify]() { + Q_ASSERT(QThread::currentThread() == qApp->thread()); + QImage tmpImg = img; + tmpImg.setText(QT_STRINGIFY(Thumb::URL), fileUrl); + tmpImg.setText(QT_STRINGIFY(Thumb::MTime), QString::number(fileModify)); + if (!tmpImg.save(thumbnailFilePath, Q_NULLPTR, 50)) { + qCWarning(logDFMBase) << "thumbnail: save failed." << fileUrl; + } + }, + Qt::QueuedConnection); return thumbnailFilePath; } @@ -236,7 +238,7 @@ bool ThumbnailHelper::checkThumbEnable(const QUrl &url) } bool enable { true }; - if (FileUtils::isMtpFile(fileUrl)) { // 是否是mtpfile + if (ProtocolUtils::isMTPFile(fileUrl)) { // 是否是mtpfile enable = DConfigManager::instance()->value("org.deepin.dde.file-manager.preview", "mtpThumbnailEnable", true).toBool(); } else if (DevProxyMng->isFileOfProtocolMounts(fileUrl.path())) { // 是否是协议设备 enable = Application::instance()->genericAttribute(Application::kShowThunmbnailInRemote).toBool(); diff --git a/src/plugins/common/dfmplugin-bookmark/bookmarkcallback.cpp b/src/plugins/common/dfmplugin-bookmark/bookmarkcallback.cpp index 02764d15b0..5063e4a579 100644 --- a/src/plugins/common/dfmplugin-bookmark/bookmarkcallback.cpp +++ b/src/plugins/common/dfmplugin-bookmark/bookmarkcallback.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -86,7 +87,7 @@ void BookmarkCallBack::cdBookMarkUrlCallBack(quint64 windowId, const QUrl &url) if (!bookmarkMap.contains(url)) { fmCritical() << "boormark:" - << "not find the book mark!"; + << "not find the book mark!"; return; } @@ -99,7 +100,7 @@ void BookmarkCallBack::cdBookMarkUrlCallBack(quint64 windowId, const QUrl &url) if (dfmio::DFile(url).exists()) { BookMarkEventCaller::sendOpenBookMarkInWindow(windowId, url); return; - } else if (DeviceUtils::isSamba(url) || DeviceUtils::isFtp(url)) { + } else if (ProtocolUtils::isSMBFile(url) || ProtocolUtils::isFTPFile(url)) { auto srcUrl = DeviceUtils::parseNetSourceUrl(url); fmInfo() << "bookmark of net file:" << url << "got souce url:" << srcUrl; if (srcUrl.isValid()) { diff --git a/src/plugins/common/dfmplugin-burn/dialogs/dumpisooptdialog.cpp b/src/plugins/common/dfmplugin-burn/dialogs/dumpisooptdialog.cpp index c4aa851cbc..cc8124e76a 100644 --- a/src/plugins/common/dfmplugin-burn/dialogs/dumpisooptdialog.cpp +++ b/src/plugins/common/dfmplugin-burn/dialogs/dumpisooptdialog.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -167,7 +168,7 @@ void DumpISOOptDialog::onPathChanged(const QString &path) { const QUrl &url { UrlRoute::fromUserInput(path) }; if (url.isEmpty() || !url.isValid() || !dfmbase::FileUtils::isLocalFile(url) - || DeviceUtils::isLowSpeedDevice(url) || DeviceUtils::isSamba(url)) { + || ProtocolUtils::isRemoteFile(url) || ProtocolUtils::isSMBFile(url)) { fmWarning() << "Path:" << path << "is prohibited"; createImgBtn->setEnabled(false); return; diff --git a/src/plugins/common/dfmplugin-emblem/utils/emblemhelper.cpp b/src/plugins/common/dfmplugin-emblem/utils/emblemhelper.cpp index 87de46acd0..35e49e66ea 100644 --- a/src/plugins/common/dfmplugin-emblem/utils/emblemhelper.cpp +++ b/src/plugins/common/dfmplugin-emblem/utils/emblemhelper.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -269,13 +270,13 @@ void EmblemHelper::pending(const FileInfoPointer &info) bool EmblemHelper::isExtEmblemProhibited(const FileInfoPointer &info, const QUrl &url) { // SMB mounted by cifs (v6), so mountpoint is native path - if (FileUtils::isGvfsFile(url)) + if (ProtocolUtils::isRemoteFile(url)) return true; // In the block device, all file extension emblem icons are displayed by default, // When configuring emblem icons display, all file extension corners are displayed in the block device // When emblem icons hiding is configured, all file extension corners are hidden in the block device - if ((info ? !info->extendAttributes(ExtInfoType::kFileLocalDevice).toBool() : !FileUtils::isLocalDevice(url))) { + if ((info ? !info->extendAttributes(ExtInfoType::kFileLocalDevice).toBool() : !ProtocolUtils::isLocalFile(url))) { bool enable { DConfigManager::instance()->value("org.deepin.dde.file-manager.emblem", "blockExtEnable", true).toBool() }; if (enable) return false; diff --git a/src/plugins/common/dfmplugin-fileoperations/fileoperations/copyfiles/docopyfilesworker.cpp b/src/plugins/common/dfmplugin-fileoperations/fileoperations/copyfiles/docopyfilesworker.cpp index 2f3c0a9b11..44e35d3de9 100644 --- a/src/plugins/common/dfmplugin-fileoperations/fileoperations/copyfiles/docopyfilesworker.cpp +++ b/src/plugins/common/dfmplugin-fileoperations/fileoperations/copyfiles/docopyfilesworker.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -51,7 +52,7 @@ bool DoCopyFilesWorker::doWork() determineCountProcessType(); // 检查磁盘空间 - if (!checkTotalDiskSpaceAvailable(sourceUrls.isEmpty() ? QUrl() : sourceUrls.first(), targetOrgUrl, nullptr)){ + if (!checkTotalDiskSpaceAvailable(sourceUrls.isEmpty() ? QUrl() : sourceUrls.first(), targetOrgUrl, nullptr)) { endWork(); return false; } @@ -121,7 +122,7 @@ bool DoCopyFilesWorker::initArgs() if (targetInfo->attribute(DFileInfo::AttributeID::kStandardIsSymlink).toBool()) targetOrgUrl = QUrl::fromLocalFile(targetInfo->attribute(DFileInfo::AttributeID::kStandardSymlinkTarget).toString()); - workData->needSyncEveryRW = FileUtils::isGvfsFile(targetUrl); + workData->needSyncEveryRW = ProtocolUtils::isRemoteFile(targetUrl); if (!workData->needSyncEveryRW) { const QString &fsType = DFMIO::DFMUtils::fsTypeFromUrl(targetUrl); workData->isFsTypeVfat = fsType.contains("vfat"); diff --git a/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/docopyfileworker.cpp b/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/docopyfileworker.cpp index ef1a9c672f..361c5deb03 100644 --- a/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/docopyfileworker.cpp +++ b/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/docopyfileworker.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -185,8 +186,8 @@ int DoCopyFileWorker::openFileBySys(const DFileInfoPointer &fromInfo, const DFil if (fd < 0) { auto lastError = strerror(errno); fmWarning() << "file open error, url from: " << fromInfo->uri() - << " url to: " << toInfo->uri() << " open flag: " << flags - << " open url : " << openUrl << " error msg: " << lastError; + << " url to: " << toInfo->uri() << " open flag: " << flags + << " open url : " << openUrl << " error msg: " << lastError; action = doHandleErrorAndWait(fromInfo->uri(), toInfo->uri(), AbstractJobHandler::JobErrorType::kOpenError, !isSource, lastError); @@ -226,7 +227,7 @@ DoCopyFileWorker::NextDo DoCopyFileWorker::doCopyFilePractically(const DFileInfo setTargetPermissions(fromInfo->uri(), toInfo->uri()); workData->zeroOrlinkOrDirWriteSize += FileUtils::getMemoryPageSize(); FileUtils::notifyFileChangeManual(DFMBASE_NAMESPACE::Global::FileNotifyType::kFileAdded, toInfo->uri()); - if (workData->exBlockSyncEveryWrite || DeviceUtils::isSamba(toInfo->uri())) + if (workData->exBlockSyncEveryWrite || ProtocolUtils::isSMBFile(toInfo->uri())) syncBlockFile(toInfo); return NextDo::kDoCopyNext; } @@ -235,7 +236,7 @@ DoCopyFileWorker::NextDo DoCopyFileWorker::doCopyFilePractically(const DFileInfo return NextDo::kDoCopyErrorAddCancel; // 循环读取和写入文件,拷贝 int toFd = -1; - auto toIsSmb = DeviceUtils::isSamba(toInfo->uri()); + auto toIsSmb = ProtocolUtils::isSMBFile(toInfo->uri()); if (workData->exBlockSyncEveryWrite || toIsSmb) toFd = open(toInfo->uri().path().toUtf8().toStdString().data(), O_RDONLY); qint64 blockSize = fromSize > kMaxBufferLength ? kMaxBufferLength : fromSize; @@ -275,7 +276,7 @@ DoCopyFileWorker::NextDo DoCopyFileWorker::doCopyFilePractically(const DFileInfo data = nullptr; // 执行同步策略 - if ((workData->exBlockSyncEveryWrite || toIsSmb) && toFd > 0) + if ((workData->exBlockSyncEveryWrite || toIsSmb) && toFd > 0) syncfs(toFd); if (toFd > 0) @@ -331,12 +332,12 @@ DoCopyFileWorker::NextDo DoCopyFileWorker::doCopyFileByRange(const DFileInfoPoin setTargetPermissions(fromInfo->uri(), toInfo->uri()); workData->zeroOrlinkOrDirWriteSize += FileUtils::getMemoryPageSize(); FileUtils::notifyFileChangeManual(DFMBASE_NAMESPACE::Global::FileNotifyType::kFileAdded, toInfo->uri()); - if (workData->exBlockSyncEveryWrite || DeviceUtils::isSamba(toInfo->uri())) + if (workData->exBlockSyncEveryWrite || ProtocolUtils::isSMBFile(toInfo->uri())) syncfs(targetFd); return NextDo::kDoCopyNext; } // 循环读取和写入文件,拷贝 - auto toIsSmb = DeviceUtils::isSamba(toInfo->uri()); + auto toIsSmb = ProtocolUtils::isSMBFile(toInfo->uri()); size_t blockSize = static_cast(fromSize > kMaxBufferLength ? kMaxBufferLength : fromSize); off_t offset_in = 0; off_t offset_out = 0; @@ -352,7 +353,7 @@ DoCopyFileWorker::NextDo DoCopyFileWorker::doCopyFileByRange(const DFileInfoPoin if (result < 0) { auto lastError = strerror(errno); fmWarning() << "copy file range error, url from: " << fromInfo->uri() - << " url to: " << toInfo->uri() << " error msg: " << lastError; + << " url to: " << toInfo->uri() << " error msg: " << lastError; action = doHandleErrorAndWait(fromInfo->uri(), toInfo->uri(), AbstractJobHandler::JobErrorType::kWriteError, false, lastError); @@ -364,13 +365,13 @@ DoCopyFileWorker::NextDo DoCopyFileWorker::doCopyFileByRange(const DFileInfoPoin } while (action == AbstractJobHandler::SupportAction::kRetryAction && !isStopped()); checkRetry(); if (!actionOperating(action, fromSize - offset_out, skip)) - return NextDo::kDoCopyErrorAddCancel; + return NextDo::kDoCopyErrorAddCancel; // 执行同步策略 if (workData->exBlockSyncEveryWrite || toIsSmb) syncfs(targetFd); } while (offset_out != fromSize); // 执行同步策略 - if (workData->exBlockSyncEveryWrite || toIsSmb) + if (workData->exBlockSyncEveryWrite || toIsSmb) syncfs(targetFd); // 对文件加权 setTargetPermissions(fromInfo->uri(), toInfo->uri()); diff --git a/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/fileoperatebaseworker.cpp b/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/fileoperatebaseworker.cpp index bc93c702ef..24d1917a1f 100644 --- a/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/fileoperatebaseworker.cpp +++ b/src/plugins/common/dfmplugin-fileoperations/fileoperations/fileoperationutils/fileoperatebaseworker.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -108,7 +109,7 @@ void FileOperateBaseWorker::setTargetPermissions(const QUrl &fromUrl, const QUrl QFileDevice::Permissions permissions = fromInfo->permissions(); QString path = fromInfo->urlOf(UrlInfoType::kUrl).path(); // 权限为0000时,源文件已经被删除,无需修改新建的文件的权限为0000 - if (permissions != 0000 && !FileUtils::isMtpFile(toInfo->urlOf(UrlInfoType::kUrl))) + if (permissions != 0000 && !ProtocolUtils::isMTPFile(toInfo->urlOf(UrlInfoType::kUrl))) localFileHandler->setPermissions(toInfo->urlOf(UrlInfoType::kUrl), permissions); } @@ -680,7 +681,7 @@ bool FileOperateBaseWorker::checkAndCopyDir(const DFileInfoPointer &fromInfo, co auto fileUrl = toInfo->uri(); if (localFileHandler->errorCode() == DFMIOErrorCode::DFM_IO_ERROR_FAILED && fileUrl.path().toLocal8Bit().size() > 255 - && FileUtils::isMtpFile(fileUrl)) + && ProtocolUtils::isMTPFile(fileUrl)) errstr = tr("The file name or the path is too long!"); action = doHandleErrorAndWait(fromInfo->uri(), toInfo->uri(), @@ -757,7 +758,7 @@ bool FileOperateBaseWorker::checkAndCopyDir(const DFileInfoPointer &fromInfo, co dirinfo->permission = permissions; dirPermissonList.appendByLock(dirinfo); } else { - if (permissions && !FileUtils::isMtpFile(toInfo->uri())) + if (permissions && !ProtocolUtils::isMTPFile(toInfo->uri())) localFileHandler->setPermissions(toInfo->uri(), permissions); } @@ -788,8 +789,8 @@ void FileOperateBaseWorker::initCopyWay() threadCount = FileUtils::getCpuProcessCount() >= 8 ? FileUtils::getCpuProcessCount() : 8; } - if (DeviceUtils::isSamba(targetUrl) - || DeviceUtils::isFtp(targetUrl) + if (ProtocolUtils::isSMBFile(targetUrl) + || ProtocolUtils::isFTPFile(targetUrl) || workData->jobFlags.testFlag(AbstractJobHandler::JobFlag::kCountProgressCustomize)) countWriteType = CountWriteSizeType::kCustomizeType; diff --git a/src/plugins/common/dfmplugin-fileoperations/fileoperationsevent/trashfileeventreceiver.cpp b/src/plugins/common/dfmplugin-fileoperations/fileoperationsevent/trashfileeventreceiver.cpp index cc81b40cab..975b68d13a 100644 --- a/src/plugins/common/dfmplugin-fileoperations/fileoperationsevent/trashfileeventreceiver.cpp +++ b/src/plugins/common/dfmplugin-fileoperations/fileoperationsevent/trashfileeventreceiver.cpp @@ -73,7 +73,7 @@ JobHandlePointer TrashFileEventReceiver::doMoveToTrash(const quint64 windowId, c } // gio can only handle canonical file paths - QList processedSources = SystemPathUtil::canonicalUrlList(sources); + QList processedSources = SystemPathUtil::instance()->canonicalUrlList(sources); const QUrl &sourceFirst = processedSources.first(); JobHandlePointer handle = nullptr; bool nullDirDelete = false; diff --git a/src/plugins/common/dfmplugin-menu/menuscene/fileoperatormenuscene.cpp b/src/plugins/common/dfmplugin-menu/menuscene/fileoperatormenuscene.cpp index 7b9a41ffd7..a6818a5023 100644 --- a/src/plugins/common/dfmplugin-menu/menuscene/fileoperatormenuscene.cpp +++ b/src/plugins/common/dfmplugin-menu/menuscene/fileoperatormenuscene.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -187,7 +188,7 @@ void FileOperatorMenuScene::updateState(QMenu *parent) // set as wallpaper if (auto setWallpaper = d->predicateAction.value(ActionID::kSetAsWallpaper)) { auto focusUrl = d->focusFileInfo->urlOf(UrlInfoType::kUrl); - if (FileUtils::isMtpFile(focusUrl) || FileUtils::isGvfsFile(focusUrl)) + if (ProtocolUtils::isMTPFile(focusUrl) || ProtocolUtils::isRemoteFile(focusUrl)) setWallpaper->setDisabled(true); } diff --git a/src/plugins/common/dfmplugin-menu/menuscene/opendirmenuscene.cpp b/src/plugins/common/dfmplugin-menu/menuscene/opendirmenuscene.cpp index 7ce7a85013..b0d456d559 100644 --- a/src/plugins/common/dfmplugin-menu/menuscene/opendirmenuscene.cpp +++ b/src/plugins/common/dfmplugin-menu/menuscene/opendirmenuscene.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -190,7 +191,7 @@ void OpenDirMenuScene::openAsAdminAction(QMenu *parent) if (SysInfoUtils::isRootUser() || SysInfoUtils::isServerSys()) return; - if (FileUtils::isGvfsFile(d->currentDir)) { // gvfs mounts and new smb mounts + if (ProtocolUtils::isRemoteFile(d->currentDir)) { // gvfs mounts and new smb mounts fmDebug() << "openAsAdmin is not added cause GVFS file: " << d->currentDir; return; } diff --git a/src/plugins/common/dfmplugin-menu/oemmenuscene/oemmenu.cpp b/src/plugins/common/dfmplugin-menu/oemmenuscene/oemmenu.cpp index 587a2a538e..27a21ccbfe 100644 --- a/src/plugins/common/dfmplugin-menu/oemmenuscene/oemmenu.cpp +++ b/src/plugins/common/dfmplugin-menu/oemmenuscene/oemmenu.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -413,7 +414,7 @@ void OemMenu::loadDesktopFile() menuTypes.removeAll(""); if (menuTypes.isEmpty()) { fmDebug() << "[OEM Menu Support] Entry will probably not be shown due to empty or have no valid" - << kMenuTypeKey << " and " << kMenuTypeAliasKey << "key in the desktop file."; + << kMenuTypeKey << " and " << kMenuTypeAliasKey << "key in the desktop file."; fmDebug() << "[OEM Menu Support] Details:" << fileInfo.filePath() << "with entry name" << entry.localizedValue(kNameKey, kLocaleKey, kDesktopEntryGroup); continue; } @@ -525,7 +526,7 @@ QList OemMenu::normalActions(const QList &files, bool onDesktop } // compression is not supported on FTP - if (action->text() == QObject::tr("Compress") && DeviceUtils::isFtp(file)) { + if (action->text() == QObject::tr("Compress") && ProtocolUtils::isFTPFile(file)) { it = actions.erase(it); continue; } @@ -619,7 +620,7 @@ QList OemMenu::focusNormalActions(const QUrl &foucs, const QListtext() == QObject::tr("Compress") && DeviceUtils::isFtp(foucs)) { + if (action->text() == QObject::tr("Compress") && ProtocolUtils::isFTPFile(foucs)) { it = actions.erase(it); continue; } @@ -650,7 +651,7 @@ QList OemMenu::focusNormalActions(const QUrl &foucs, const QList #include #include +#include #include @@ -41,12 +42,12 @@ bool isHiddenExtMenu(const QUrl &dirUrl) hidden = true; // hidden by `dfm.menu.protocoldev.enable` - if (!enableProtocolDev && FileUtils::isGvfsFile(dirUrl)) + if (!enableProtocolDev && ProtocolUtils::isRemoteFile(dirUrl)) hidden = true; // hidden by `dfm.menu.blockdev.enable` // NOTE: SMB mounted by cifs that mount point is local but it's a protocol device - if (!enableBlockDev && DFMIO::DFMUtils::fileIsRemovable(dirUrl) && !FileUtils::isGvfsFile(dirUrl)) + if (!enableBlockDev && DFMIO::DFMUtils::fileIsRemovable(dirUrl) && !ProtocolUtils::isRemoteFile(dirUrl)) hidden = true; return hidden; diff --git a/src/plugins/common/dfmplugin-tag/utils/tagmanager.cpp b/src/plugins/common/dfmplugin-tag/utils/tagmanager.cpp index 8da8aac794..cc39767177 100644 --- a/src/plugins/common/dfmplugin-tag/utils/tagmanager.cpp +++ b/src/plugins/common/dfmplugin-tag/utils/tagmanager.cpp @@ -17,12 +17,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include @@ -528,7 +528,7 @@ bool TagManager::localFileCanTagFilter(const FileInfoPointer &info) const return desktopInfo->canTag(); } - if (DeviceUtils::isSamba(url)) + if (ProtocolUtils::isSMBFile(url)) return false; return !SystemPathUtil::instance()->isSystemPath(filePath); diff --git a/src/plugins/common/dfmplugin-utils/appendcompress/appendcompresshelper.cpp b/src/plugins/common/dfmplugin-utils/appendcompress/appendcompresshelper.cpp index e3e6dd2298..94290ac9fb 100644 --- a/src/plugins/common/dfmplugin-utils/appendcompress/appendcompresshelper.cpp +++ b/src/plugins/common/dfmplugin-utils/appendcompress/appendcompresshelper.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -85,7 +86,7 @@ bool AppendCompressHelper::canAppendCompress(const QList &fromUrls, const if (toFilePath.isEmpty()) return false; - if (DeviceUtils::isFtp(fromUrls.at(0)) || DeviceUtils::isFtp(toUrl)) + if (ProtocolUtils::isFTPFile(fromUrls.at(0)) || ProtocolUtils::isFTPFile(toUrl)) return false; if (dpfHookSequence->run("dfmplugin_utils", "hook_AppendCompress_Prohibit", fromUrls, toUrl)) { diff --git a/src/plugins/daemon/daemon-recentdaemon/recentiterateworker.cpp b/src/plugins/daemon/daemon-recentdaemon/recentiterateworker.cpp index 0cad2947cc..9f804eac4d 100644 --- a/src/plugins/daemon/daemon-recentdaemon/recentiterateworker.cpp +++ b/src/plugins/daemon/daemon-recentdaemon/recentiterateworker.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -75,7 +76,7 @@ void RecentIterateWorker::processBookmarkElement(QXmlStreamReader &reader, QStri const QUrl url(location); if (!url.isLocalFile()) return; - if (DeviceUtils::isLowSpeedDevice(url)) + if (ProtocolUtils::isRemoteFile(url)) return; QFileInfo info(url.toLocalFile()); diff --git a/src/plugins/filemanager/dfmplugin-computer/controller/computercontroller.cpp b/src/plugins/filemanager/dfmplugin-computer/controller/computercontroller.cpp index 2ff38cd0e4..ea51881384 100644 --- a/src/plugins/filemanager/dfmplugin-computer/controller/computercontroller.cpp +++ b/src/plugins/filemanager/dfmplugin-computer/controller/computercontroller.cpp @@ -23,6 +23,8 @@ #include #include #include +#include + #include #include @@ -64,7 +66,7 @@ void ComputerController::onOpenItem(quint64 winId, const QUrl &url) if (target.isValid()) { if (isOptical) target = ComputerUtils::makeBurnUrl(ComputerUtils::getBlockDevIdByUrl(url)); - if (DeviceUtils::isSamba(target) || DeviceUtils::isFtp(target)) + if (ProtocolUtils::isSMBFile(target) || ProtocolUtils::isFTPFile(target)) handleNetworkCdCall(winId, info); else ComputerEventCaller::cdTo(winId, target); @@ -560,7 +562,7 @@ void ComputerController::actLogoutAndForgetPasswd(DFMEntryFileInfoPointer info) QString uri(id); if (id.startsWith(DFMBASE_NAMESPACE::Global::Scheme::kSmb)) { uri = id; - } else if (DeviceUtils::isSamba(id)) { + } else if (ProtocolUtils::isSMBFile(id)) { QString host, share; bool ok = DeviceUtils::parseSmbInfo(id, host, share); if (!ok) { diff --git a/src/plugins/filemanager/dfmplugin-computer/events/computereventreceiver.cpp b/src/plugins/filemanager/dfmplugin-computer/events/computereventreceiver.cpp index 2505b4d74b..c682458b56 100644 --- a/src/plugins/filemanager/dfmplugin-computer/events/computereventreceiver.cpp +++ b/src/plugins/filemanager/dfmplugin-computer/events/computereventreceiver.cpp @@ -96,7 +96,6 @@ void ComputerEventReceiver::dirAccessPrehandler(quint64, const QUrl &url, std::f // fmInfo() << "not file scheme, ignore prehandle" << url; break; } - // only handle mounts by udisks if (!path.startsWith("/media/")) { // fmInfo() << "not udisks mount path, ignore prehandle" << url; @@ -180,7 +179,7 @@ bool ComputerEventReceiver::parseCifsMountCrumb(const QUrl &url, QListpush_back(rootNode); - static const QRegularExpression kCifsDevId(R"(^/media/.*/smbmounts/[^/]*)"); + static const QRegularExpression kCifsDevId(R"(^/(?:run/)?media/.*/smbmounts/[^/]*)"); match = kCifsDevId.match(filePath); if (!match.hasMatch()) return true; diff --git a/src/plugins/filemanager/dfmplugin-computer/fileentity/protocolentryfileentity.cpp b/src/plugins/filemanager/dfmplugin-computer/fileentity/protocolentryfileentity.cpp index 20a93d700e..838d5eac51 100644 --- a/src/plugins/filemanager/dfmplugin-computer/fileentity/protocolentryfileentity.cpp +++ b/src/plugins/filemanager/dfmplugin-computer/fileentity/protocolentryfileentity.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -93,7 +94,7 @@ DFMBASE_NAMESPACE::AbstractEntryFileEntity::EntryOrder ProtocolEntryFileEntity:: return DFMBASE_NAMESPACE::AbstractEntryFileEntity::EntryOrder::kOrderFtp; if (id.startsWith(DFMBASE_NAMESPACE::Global::Scheme::kSmb) - || DFMBASE_NAMESPACE::DeviceUtils::isSamba(QUrl(id))) + || DFMBASE_NAMESPACE::ProtocolUtils::isSMBFile(QUrl(id))) return DFMBASE_NAMESPACE::AbstractEntryFileEntity::EntryOrder::kOrderSmb; if (id.startsWith(DFMBASE_NAMESPACE::Global::Scheme::kMtp)) @@ -129,7 +130,7 @@ QUrl ProtocolEntryFileEntity::targetUrl() const return target; target.setScheme(DFMBASE_NAMESPACE::Global::Scheme::kFile); target.setPath(mpt); - if (DFMBASE_NAMESPACE::DeviceUtils::isSamba(target)) + if (DFMBASE_NAMESPACE::ProtocolUtils::isSMBFile(target)) return DFMBASE_NAMESPACE::DeviceUtils::getSambaFileUriFromNative(target); return target; } diff --git a/src/plugins/filemanager/dfmplugin-computer/menu/computermenuscene.cpp b/src/plugins/filemanager/dfmplugin-computer/menu/computermenuscene.cpp index 6524233b06..02d4fab363 100644 --- a/src/plugins/filemanager/dfmplugin-computer/menu/computermenuscene.cpp +++ b/src/plugins/filemanager/dfmplugin-computer/menu/computermenuscene.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "plugins/common/dfmplugin-menu/menu_eventinterface_helper.h" @@ -159,7 +160,7 @@ void ComputerMenuScene::updateState(QMenu *parent) keeped << kUnmount; auto id = d->info->extraProperty(DeviceProperty::kId).toString(); - if (id.contains(QRegularExpression("^smb|^ftp|^sftp|^dav")) || DeviceUtils::isSamba(QUrl(id))) + if (id.contains(QRegularExpression("^smb|^ftp|^sftp|^dav")) || ProtocolUtils::isSMBFile(QUrl(id))) keeped << kLogoutAndForget; } break; diff --git a/src/plugins/filemanager/dfmplugin-computer/utils/computerutils.cpp b/src/plugins/filemanager/dfmplugin-computer/utils/computerutils.cpp index 0d902d279f..b52fcc7cb3 100644 --- a/src/plugins/filemanager/dfmplugin-computer/utils/computerutils.cpp +++ b/src/plugins/filemanager/dfmplugin-computer/utils/computerutils.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -178,7 +179,7 @@ QMutex ComputerUtils::mtxForCheckGvfs; QWaitCondition ComputerUtils::condForCheckGvfs; bool ComputerUtils::checkGvfsMountExist(const QUrl &url, int timeout) { - if (!FileUtils::isGvfsFile(url)) + if (!ProtocolUtils::isRemoteFile(url)) return true; setCursorState(true); diff --git a/src/plugins/filemanager/dfmplugin-optical/events/opticaleventreceiver.cpp b/src/plugins/filemanager/dfmplugin-optical/events/opticaleventreceiver.cpp index a91f7d7ef8..50dd39388f 100644 --- a/src/plugins/filemanager/dfmplugin-optical/events/opticaleventreceiver.cpp +++ b/src/plugins/filemanager/dfmplugin-optical/events/opticaleventreceiver.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include @@ -25,7 +26,7 @@ OpticalEventReceiver &OpticalEventReceiver::instance() bool OpticalEventReceiver::handleDeleteFilesShortcut(quint64, const QList &urls, const QUrl &rootUrl) { - if (!rootUrl.toLocalFile().startsWith("/media")) + if (!DevProxyMng->isFileFromOptical(rootUrl.toLocalFile())) return false; auto iter = std::find_if(urls.cbegin(), urls.cend(), [](const QUrl &url) { @@ -68,9 +69,7 @@ bool OpticalEventReceiver::handleMoveToTrashShortcut(quint64 winId, const QList< { Q_UNUSED(winId); - // 树形结构中,如果在根目录展开进行操作将导致 BUG,但是这是一个corner case, - // 考虑到性能问题这里直接简单判断 - if (!rootUrl.toLocalFile().startsWith("/media")) + if (!DevProxyMng->isFileFromOptical(rootUrl.toLocalFile())) return false; if (isContainPWSubDirFile(urls)) @@ -83,7 +82,7 @@ bool OpticalEventReceiver::handleCutFilesShortcut(quint64 winId, const QListisFileFromOptical(rootUrl.toLocalFile())) return false; // 仅 PW 光盘根目录支持 @@ -99,7 +98,7 @@ bool OpticalEventReceiver::handlePasteFilesShortcut(quint64 winId, const QListisFileFromOptical(path)) return false; QString dev { DeviceUtils::getMountInfo(path, false) }; diff --git a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp index a8f29b0c3c..3c209572e3 100644 --- a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp +++ b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/fulltext/fulltextsearcher.cpp @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -162,18 +161,19 @@ bool FullTextSearcherPrivate::doSearch(const QString &path, const QString &keywo QString FullTextSearcherPrivate::dealKeyword(const QString &keyword) { - static QRegExp cnReg("^[\u4e00-\u9fa5]"); - static QRegExp enReg("^[A-Za-z]+$"); - static QRegExp numReg("^[0-9]$"); + QRegularExpression cnReg("^[\u4e00-\u9fa5]"); + QRegularExpression enReg("^[A-Za-z]+$"); + QRegularExpression numReg("^[0-9]$"); WordType oldType = kCn, currType = kCn; QString newStr; for (auto c : keyword) { - if (cnReg.exactMatch(c)) { + QString charStr(c); + if (cnReg.match(charStr).hasMatch()) { currType = kCn; - } else if (enReg.exactMatch(c)) { + } else if (enReg.match(charStr).hasMatch()) { currType = kEn; - } else if (numReg.exactMatch(c)) { + } else if (numReg.match(charStr).hasMatch()) { currType = kDigit; } else { // 特殊符号均当作空格处理 diff --git a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/iterator/iteratorsearcher.cpp b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/iterator/iteratorsearcher.cpp index 154216d01a..377c7a5b5b 100644 --- a/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/iterator/iteratorsearcher.cpp +++ b/src/plugins/filemanager/dfmplugin-search/searchmanager/searcher/iterator/iteratorsearcher.cpp @@ -86,10 +86,10 @@ void IteratorSearcher::doSearch() // 仅在过滤目录下进行搜索时,过滤目录下的内容才能被检索 if (dfmbase::FileUtils::isLocalFile(url)) { - QRegExp reg(kFilterFolders); + QRegularExpression reg(kFilterFolders); const auto &searchRootPath = searchUrl.toLocalFile(); const auto &filePath = url.toLocalFile(); - if (!reg.exactMatch(searchRootPath) && reg.exactMatch(filePath)) + if (!reg.match(searchRootPath).hasMatch() && reg.match(filePath).hasMatch()) continue; } diff --git a/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/protocoldevicedisplaymanager.cpp b/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/protocoldevicedisplaymanager.cpp index ca4f968cf0..57a49e1f18 100644 --- a/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/protocoldevicedisplaymanager.cpp +++ b/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/protocoldevicedisplaymanager.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -107,7 +108,7 @@ bool ProtocolDeviceDisplayManager::hookItemsFilter(QList *entryUrls) void ProtocolDeviceDisplayManager::onDevMounted(const QString &id, const QString &) { - if (!DeviceUtils::isSamba(QUrl(id))) + if (!ProtocolUtils::isSMBFile(QUrl(id))) return; if (!isShowOfflineItem()) @@ -124,7 +125,7 @@ void ProtocolDeviceDisplayManager::onDevMounted(const QString &id, const QString void ProtocolDeviceDisplayManager::onDevUnmounted(const QString &id) { - if (!DeviceUtils::isSamba(QUrl(id))) + if (!ProtocolUtils::isSMBFile(QUrl(id))) return; if (displayMode() == SmbDisplayMode::kSeperate && isShowOfflineItem()) { @@ -271,7 +272,7 @@ bool ProtocolDeviceDisplayManagerPrivate::isSupportVEntry(const QUrl &entryUrl) { if (!showOffline && displayMode == kSeperate) return false; - if (!DeviceUtils::isSamba(entryUrl.path())) + if (!ProtocolUtils::isSMBFile(entryUrl.path())) return false; if (!entryUrl.path().endsWith(kComputerProtocolSuffix)) return false; @@ -282,7 +283,7 @@ bool ProtocolDeviceDisplayManagerPrivate::isSupportVEntry(const QString &devId) { if (!showOffline && displayMode == kSeperate) return false; - if (!DeviceUtils::isSamba(devId)) + if (!ProtocolUtils::isSMBFile(devId)) return false; return true; } diff --git a/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/utilities/protocoldisplayutilities.cpp b/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/utilities/protocoldisplayutilities.cpp index f9723e05db..a96410952f 100644 --- a/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/utilities/protocoldisplayutilities.cpp +++ b/src/plugins/filemanager/dfmplugin-smbbrowser/displaycontrol/utilities/protocoldisplayutilities.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -167,7 +168,7 @@ QStringList protocol_display_utilities::getMountedSmb() auto protoDevs = DevProxyMng->getAllProtocolIds(); for (int i = protoDevs.count() - 1; i >= 0; i--) { QUrl dev(protoDevs.at(i)); - if (!DeviceUtils::isSamba(dev)) { + if (!ProtocolUtils::isSMBFile(dev)) { protoDevs.removeAt(i); continue; } @@ -206,7 +207,7 @@ QString protocol_display_utilities::getStandardSmbPath(const QUrl &entryUrl) QString protocol_display_utilities::getStandardSmbPath(const QString &devId) { QString id = QUrl::fromPercentEncoding(devId.toLocal8Bit()); - static const QRegularExpression kCifsSmbPrefix(R"(^file:///media/.*/smbmounts/)"); + static const QRegularExpression kCifsSmbPrefix(R"(^file:///(?:run/)?media/.*/smbmounts/)"); if (!id.startsWith(Global::Scheme::kFile) || !id.contains(kCifsSmbPrefix)) return id; diff --git a/src/plugins/filemanager/dfmplugin-smbbrowser/events/smbbrowsereventreceiver.cpp b/src/plugins/filemanager/dfmplugin-smbbrowser/events/smbbrowsereventreceiver.cpp index 8b01284a98..9b08147725 100644 --- a/src/plugins/filemanager/dfmplugin-smbbrowser/events/smbbrowsereventreceiver.cpp +++ b/src/plugins/filemanager/dfmplugin-smbbrowser/events/smbbrowsereventreceiver.cpp @@ -110,7 +110,7 @@ bool SmbBrowserEventReceiver::getOriginalUri(const QUrl &in, QUrl *out) QString path = in.path(); // is cifs - static const QRegularExpression kCifsPrefix { R"(^/media/[^/]*/smbmounts/smb-share:[^/]*)" }; + static const QRegularExpression kCifsPrefix { R"(^/(?:run/)?media/[^/]*/smbmounts/smb-share:[^/]*)" }; if (path.contains(kCifsPrefix)) { QString host, share, port; if (!DeviceUtils::parseSmbInfo(path, host, share, &port)) diff --git a/src/plugins/filemanager/dfmplugin-titlebar/utils/historystack.cpp b/src/plugins/filemanager/dfmplugin-titlebar/utils/historystack.cpp index 94e0c57290..5a81c62346 100644 --- a/src/plugins/filemanager/dfmplugin-titlebar/utils/historystack.cpp +++ b/src/plugins/filemanager/dfmplugin-titlebar/utils/historystack.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -211,8 +212,8 @@ bool HistoryStack::needCheckExist(const QUrl &url) bool HistoryStack::checkPathIsExist(const QUrl &url) { - if (FileUtils::isGvfsFile(url) && NetworkUtils::instance()->checkFtpOrSmbBusy(url)) { - return false; + if (ProtocolUtils::isRemoteFile(url) && NetworkUtils::instance()->checkFtpOrSmbBusy(url)) { + return false; } else { auto info = InfoFactory::create(url); return info && info->exists(); diff --git a/src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp b/src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp index d346295c18..72b43db537 100644 --- a/src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp +++ b/src/plugins/filemanager/dfmplugin-titlebar/views/urlpushbutton.cpp @@ -10,7 +10,7 @@ #include "utils/crumbmanager.h" #include -#include +#include #include #include @@ -280,7 +280,7 @@ void UrlPushButton::setCrumbDatas(const QList &datas, bool stacked) } else { const CrumbData &data = datas.first(); // 本地文件显示下拉选项 - d->subDirVisible = (FileUtils::isLocalDevice(data.url) && CrumbManager::instance()->isRegisted(data.url.scheme())); + d->subDirVisible = (ProtocolUtils::isLocalFile(data.url) && CrumbManager::instance()->isRegisted(data.url.scheme())); if (data.iconName.isEmpty()) { setText(data.displayText); } else { diff --git a/src/plugins/filemanager/dfmplugin-workspace/models/fileviewmodel.cpp b/src/plugins/filemanager/dfmplugin-workspace/models/fileviewmodel.cpp index 21c88fdd2f..8ef6e72cf6 100644 --- a/src/plugins/filemanager/dfmplugin-workspace/models/fileviewmodel.cpp +++ b/src/plugins/filemanager/dfmplugin-workspace/models/fileviewmodel.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -814,7 +815,7 @@ void FileViewModel::onDConfigChanged(const QString &config, const QString &key) if (config != DConfigInfo::kConfName) return; - if (DConfigInfo::kMtpThumbnailKey == key && FileUtils::isMtpFile(rootUrl())) + if (DConfigInfo::kMtpThumbnailKey == key && ProtocolUtils::isMTPFile(rootUrl())) Q_EMIT requestClearThumbnail(); } diff --git a/src/plugins/filemanager/dfmplugin-workspace/utils/filedatamanager.cpp b/src/plugins/filemanager/dfmplugin-workspace/utils/filedatamanager.cpp index f897dd934f..4dd5e3187b 100644 --- a/src/plugins/filemanager/dfmplugin-workspace/utils/filedatamanager.cpp +++ b/src/plugins/filemanager/dfmplugin-workspace/utils/filedatamanager.cpp @@ -7,7 +7,7 @@ #include "models/fileitemdata.h" #include "events/workspaceeventcaller.h" -#include +#include #include #include #include @@ -188,7 +188,7 @@ bool FileDataManager::checkNeedCache(const QUrl &url) return true; // mounted dir should cache files in FileDataManager - if ((!FileUtils::isLocalDevice(url))) + if ((!ProtocolUtils::isLocalFile(url))) return true; return false; diff --git a/src/plugins/filemanager/dfmplugin-workspace/utils/filesortworker.cpp b/src/plugins/filemanager/dfmplugin-workspace/utils/filesortworker.cpp index 058efe6c2f..788e87bf19 100644 --- a/src/plugins/filemanager/dfmplugin-workspace/utils/filesortworker.cpp +++ b/src/plugins/filemanager/dfmplugin-workspace/utils/filesortworker.cpp @@ -810,26 +810,15 @@ void FileSortWorker::checkNameFilters(const FileItemDataPointer itemData) if (!itemData || itemData->data(Global::ItemRoles::kItemFileIsDirRole).toBool() || nameFilters.isEmpty()) return; -#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) - QRegExp re("", Qt::CaseInsensitive, QRegExp::Wildcard); + QRegularExpression re("", QRegularExpression::CaseInsensitiveOption); for (int i = 0; i < nameFilters.size(); ++i) { - re.setPattern(nameFilters.at(i)); - if (re.exactMatch(itemData->data(kItemNameRole).toString())) { + QString pattern = QRegularExpression::wildcardToRegularExpression(nameFilters.at(i)); + re.setPattern(pattern); + if (re.match(itemData->data(kItemNameRole).toString()).hasMatch()) { itemData->setAvailableState(true); return; } } -#else - for (const QString &filter : nameFilters) { - // 使用 QRegularExpression::wildcardToRegularExpression 转换通配符为正则表达式 - QRegularExpression re(QRegularExpression::wildcardToRegularExpression(filter), QRegularExpression::CaseInsensitiveOption); - QRegularExpressionMatch match = re.match(itemData->data(kItemNameRole).toString()); - if (match.hasMatch()) { - itemData->setAvailableState(true); - return; - } - } -#endif itemData->setAvailableState(false); } @@ -1529,7 +1518,8 @@ bool FileSortWorker::checkFilters(const SortInfoPointer &sortInfo, const bool by if (item && !nameFilters.isEmpty() && !item->data(Global::ItemRoles::kItemFileIsDirRole).toBool()) { QRegularExpression re("", QRegularExpression::CaseInsensitiveOption); for (int i = 0; i < nameFilters.size(); ++i) { - re.setPattern(nameFilters.at(i)); + QString pattern = QRegularExpression::wildcardToRegularExpression(nameFilters.at(i)); + re.setPattern(pattern); if (re.match(item->data(kItemNameRole).toString()).hasMatch()) { item->setAvailableState(true); } diff --git a/src/plugins/filemanager/dfmplugin-workspace/views/fileview.cpp b/src/plugins/filemanager/dfmplugin-workspace/views/fileview.cpp index 7750af03fb..0d827089aa 100644 --- a/src/plugins/filemanager/dfmplugin-workspace/views/fileview.cpp +++ b/src/plugins/filemanager/dfmplugin-workspace/views/fileview.cpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #ifdef DTKWIDGET_CLASS_DSizeMode # include @@ -2105,7 +2105,7 @@ void FileView::initializeConnect() Qt::DirectConnection); } connect(&FileInfoHelper::instance(), &FileInfoHelper::smbSeverMayModifyPassword, this, [this](const QUrl &url) { - if (DeviceUtils::isSamba(rootUrl()) && url.path().startsWith(rootUrl().path())) { + if (ProtocolUtils::isSMBFile(rootUrl()) && url.path().startsWith(rootUrl().path())) { fmInfo() << rootUrl() << url << "smb server may modify password"; if (d->isShowSmbMountError) return; diff --git a/src/plugins/filemanager/dfmplugin-workspace/views/private/renamebar_p.h b/src/plugins/filemanager/dfmplugin-workspace/views/private/renamebar_p.h index 9380f36544..ac3c1bae2b 100644 --- a/src/plugins/filemanager/dfmplugin-workspace/views/private/renamebar_p.h +++ b/src/plugins/filemanager/dfmplugin-workspace/views/private/renamebar_p.h @@ -22,7 +22,6 @@ class QComboBox; class QStackedWidget; class QLineEdit; class QFrame; -class QRegExpValidator; class QPushButton; QT_END_NAMESPACE