]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
GIT_SILENT Sync po/docbooks with svn
[dolphin.git] / src / dolphinviewcontainer.cpp
index 49615d185b568666cad3180476161b531867c444..1b87911673a528f0fd30ac7e83dc4ba878b97e17 100644 (file)
@@ -957,6 +957,22 @@ void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel)
     m_view->setZoomLevel(zoomLevel);
 }
 
+bool DolphinViewContainer::isTopMostParentFolderWritable(QUrl url)
+{
+    Q_ASSERT(url.isLocalFile());
+    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")
@@ -980,7 +996,6 @@ void DolphinViewContainer::slotErrorMessageFromView(const QString &message, cons
             m_createFolderAction = new QAction(this);
             m_createFolderAction->setText(i18nc("@action", "Create missing folder"));
             m_createFolderAction->setIcon(QIcon::fromTheme(QStringLiteral("folder-new")));
-            m_createFolderAction->setToolTip(i18nc("@info:tooltip", "Create the folder at this path and open it"));
             connect(m_createFolderAction, &QAction::triggered, this, [this](bool) {
                 KIO::MkpathJob *job = KIO::mkpath(m_view->url());
                 KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Mkpath, {}, m_view->url(), job);
@@ -994,6 +1009,13 @@ void DolphinViewContainer::slotErrorMessageFromView(const QString &message, cons
                 });
             });
         }
+        if (isTopMostParentFolderWritable(m_view->url())) {
+            m_createFolderAction->setEnabled(true);
+            m_createFolderAction->setToolTip(i18nc("@info:tooltip", "Create the folder at this path and open it"));
+        } else {
+            m_createFolderAction->setEnabled(false);
+            m_createFolderAction->setToolTip(i18nc("@info:tooltip", "You do not have permission to create the folder"));
+        }
         showMessage(message, KMessageWidget::Error, {m_createFolderAction});
         return;
     }