diff options
| author | Gleb Kasachou <[email protected]> | 2025-07-28 18:19:47 +0300 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2025-07-30 07:57:20 +0000 |
| commit | 80156ef3f57bab877574ad2932fbeca42eee05a0 (patch) | |
| tree | 54bbd5f83ae8c3fa7df248f083e7ff7ee3c073f1 /src | |
| parent | 3186f0428888447a783d014afaaa0b44b68ebaba (diff) | |
Add a check before offering to create folder
This commit adds a function that checks if a folder can be created at
the url entered in the location bar. This prevents offering to create
folders in locations where the user does not have write permissions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dolphinviewcontainer.cpp | 17 | ||||
| -rw-r--r-- | src/dolphinviewcontainer.h | 6 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 49615d185..5e8b26293 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -957,6 +957,21 @@ void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel) m_view->setZoomLevel(zoomLevel); } +bool DolphinViewContainer::isFolderCreatable(QUrl url) +{ + while (url.isValid()) { + url = url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); + QFileInfo info(url.toLocalFile()); + if (info.exists()) { + return info.isWritable(); + } + if (info.isSymLink()) { + return false; + } + } + return false; +} + void DolphinViewContainer::slotErrorMessageFromView(const QString &message, const int kioErrorCode) { if (kioErrorCode == KIO::ERR_CANNOT_ENTER_DIRECTORY && m_view->url().scheme() == QStringLiteral("file") @@ -975,7 +990,7 @@ void DolphinViewContainer::slotErrorMessageFromView(const QString &message, cons } showMessage(i18nc("@info", "Authorization required to enter this folder."), KMessageWidget::Error, {m_authorizeToEnterFolderAction}); return; - } else if (kioErrorCode == KIO::ERR_DOES_NOT_EXIST && m_view->url().isLocalFile()) { + } else if (kioErrorCode == KIO::ERR_DOES_NOT_EXIST && m_view->url().isLocalFile() && isFolderCreatable(m_view->url())) { if (!m_createFolderAction) { m_createFolderAction = new QAction(this); m_createFolderAction->setText(i18nc("@action", "Create missing folder")); diff --git a/src/dolphinviewcontainer.h b/src/dolphinviewcontainer.h index 419b9f5b1..4acccdd81 100644 --- a/src/dolphinviewcontainer.h +++ b/src/dolphinviewcontainer.h @@ -460,6 +460,12 @@ private: */ QRect preferredSmallStatusBarGeometry(); + /** + * Check if a folder can be created at url. + * This method supports only local URLs. + */ + bool isFolderCreatable(QUrl url); + protected: bool eventFilter(QObject *object, QEvent *event) override; |
