]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Apply 2 suggestion(s) to 1 file(s)
[dolphin.git] / src / dolphinviewcontainer.cpp
index 6d08c47c7d03990f4fed2c4e06b9d2887fb03fd4..726e0d12912268e5efd873100e1532ff1808ea0e 100644 (file)
@@ -27,6 +27,7 @@
 #include <KFileItemActions>
 #include <KFilePlacesModel>
 #include <KIO/JobUiDelegateFactory>
+#include <KIO/MkpathJob>
 #include <KIO/OpenUrlJob>
 #include <KLocalizedString>
 #include <KMessageWidget>
@@ -76,6 +77,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
     , m_searchModeEnabled(false)
     , m_adminBar{nullptr}
     , m_authorizeToEnterFolderAction{nullptr}
+    , m_createFolderAction(nullptr)
     , m_messageWidget(nullptr)
     , m_selectionModeTopBar{nullptr}
     , m_view(nullptr)
@@ -522,6 +524,11 @@ void DolphinViewContainer::showMessage(const QString &message, KMessageWidget::M
 #endif
 }
 
+void DolphinViewContainer::showProgress(const QString &currentlyRunningTaskTitle, int progressPercent)
+{
+    m_statusBar->showProgress(currentlyRunningTaskTitle, progressPercent, DolphinStatusBar::CancelLoading::Disallowed);
+}
+
 void DolphinViewContainer::readSettings()
 {
     // The startup settings should (only) get applied if they have been
@@ -950,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")
@@ -968,6 +991,27 @@ 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() && isFolderCreatable(m_view->url())) {
+        if (!m_createFolderAction) {
+            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);
+                connect(job, &KJob::result, this, [this](KJob *job) {
+                    if (job->error()) {
+                        showErrorMessage(job->errorString());
+                    } else {
+                        m_view->reload();
+                        m_messageWidget->animatedHide();
+                    }
+                });
+            });
+        }
+        showMessage(message, KMessageWidget::Error, {m_createFolderAction});
+        return;
     }
     Q_EMIT showErrorMessage(message);
 }
@@ -1089,11 +1133,9 @@ bool DolphinViewContainer::eventFilter(QObject *object, QEvent *event)
 
 QRect DolphinViewContainer::preferredSmallStatusBarGeometry()
 {
-    // Adjust to clipping, we need to add 1 due to how QRects coordinates work.
-    int clipAdjustment = m_statusBar->clippingAmount() + 1;
-    // Add offset depending if horizontal scrollbar or filterbar is visible.
-    const int yPos = m_view->geometry().bottom() - m_view->horizontalScrollBarHeight() - m_statusBar->minimumHeight() + clipAdjustment;
-    QRect statusBarRect = rect().adjusted(-clipAdjustment, yPos, 0, 0);
+    // Add offset depending if horizontal scrollbar or filterbar is visible, we need to add 1 due to how QRect coordinates work.
+    const int yPos = m_view->geometry().bottom() - m_view->horizontalScrollBarHeight() - m_statusBar->minimumHeight() + 1;
+    QRect statusBarRect = rect().adjusted(0, yPos, 0, 0);
     return statusBarRect;
 }