From 5c450d527a306fdece5c44d9d2fdebdc05fee3a6 Mon Sep 17 00:00:00 2001 From: kate Date: Mon, 17 Jan 2022 03:08:30 +0800 Subject: [PATCH] fix: xdg folders rename --- dialogs/filepropertiesdialog.cpp | 3 ++- helper/fm.cpp | 16 ++++++++++++++++ helper/fm.h | 1 + model/foldermodel.cpp | 10 ++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dialogs/filepropertiesdialog.cpp b/dialogs/filepropertiesdialog.cpp index dce72cc..cdf3db4 100644 --- a/dialogs/filepropertiesdialog.cpp +++ b/dialogs/filepropertiesdialog.cpp @@ -19,6 +19,7 @@ #include "filepropertiesdialog.h" #include "../desktopiconprovider.h" +#include "../helper/fm.h" #include #include @@ -97,7 +98,7 @@ void FilePropertiesDialog::accept(const QString &text) if (fileName() != newFileName) { QUrl newUrl; - if (!location().isEmpty()) { + if (!location().isEmpty() && !Fm::isFixedFolder(m_items.first().url())) { newUrl = location(); newUrl.setPath(concatPaths(newUrl.path(), newFileName)); newUrl.setScheme(item.url().scheme()); diff --git a/helper/fm.cpp b/helper/fm.cpp index 493e328..d222764 100644 --- a/helper/fm.cpp +++ b/helper/fm.cpp @@ -19,6 +19,9 @@ #include "fm.h" #include +#include +#include + #include Fm::Fm(QObject *parent) : QObject(parent) @@ -36,3 +39,16 @@ void Fm::emptyTrash() KIO::Job *job = KIO::emptyTrash(); job->start(); } + +bool Fm::isFixedFolder(const QUrl &folderUrl) +{ + const QString folder = folderUrl.toLocalFile(); + + return folder == QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first() || + folder == QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first() || + folder == QStandardPaths::standardLocations(QStandardPaths::MusicLocation).first() || + folder == QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).first() || + folder == QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first() || + folder == QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first() || + folder == QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first(); +} diff --git a/helper/fm.h b/helper/fm.h index d32e2ed..7da7049 100644 --- a/helper/fm.h +++ b/helper/fm.h @@ -31,6 +31,7 @@ public: Q_INVOKABLE QString rootPath(); Q_INVOKABLE static void emptyTrash(); + static bool isFixedFolder(const QUrl &folderUrl); }; #endif // FM_H diff --git a/model/foldermodel.cpp b/model/foldermodel.cpp index 7ec2889..fd060a3 100644 --- a/model/foldermodel.cpp +++ b/model/foldermodel.cpp @@ -33,6 +33,7 @@ #include "../helper/datehelper.h" #include "../helper/filelauncher.h" +#include "../helper/fm.h" #include "../cio/cfilesizejob.h" @@ -86,7 +87,6 @@ static bool isDropBetweenSharedViews(const QList &urls, const QUrl &folder return true; } - FolderModel::FolderModel(QObject *parent) : QSortFilterProxyModel(parent) , m_dirWatch(nullptr) @@ -1231,6 +1231,12 @@ void FolderModel::drop(QQuickItem *target, QObject *dropEvent, int row) if (!isDropBetweenSharedViews(mimeData->urls(), dropTargetFolderUrl)) { KIO::Job *job = KIO::move(mimeData->urls(), dropTargetUrl, KIO::HideProgressInfo); job->start(); + + // Add select + for (QUrl url : mimeData->urls()) { + m_needSelectUrls.append(QUrl::fromLocalFile(QString("%1/%2").arg(rootItem().url().toLocalFile()) + .arg(url.fileName()))); + } } } @@ -1920,7 +1926,7 @@ void FolderModel::updateActions() if (QAction *rename = m_actionCollection.action(QStringLiteral("rename"))) { rename->setEnabled(itemProperties.supportsMoving()); - rename->setVisible(!isTrash); + rename->setVisible(!isTrash && !Fm::isFixedFolder(items.first().url())); } if (QAction *trash = m_actionCollection.action("trash")) {