]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow non-local startup location
authorDerek Christ <christ.derek@gmail.com>
Mon, 21 Dec 2020 12:08:12 +0000 (13:08 +0100)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 21 Dec 2020 21:28:50 +0000 (21:28 +0000)
Only local directories were supported to be set as the starting location
of Dolphin. This commit fixes this by using an KIO::StatJob to determine
if the path is actually pointing to a directory or a file regardless if
it is a local or a remote path.

Additionaly a hard-coded exception for urls with the scheme "timeline"
was removed because with the new fix it is now obsolete.

BUG: 428885

src/settings/startup/startupsettingspage.cpp
src/settings/startup/startupsettingspage.h

index 6c3f6bdadf9328149d918c43e3ed8a57447f0bdb..a7fcec4fa3320f818a0e7e1711d316b038941719 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <KLocalizedString>
 #include <KMessageBox>
+#include <KProtocolManager>
 
 #include <QButtonGroup>
 #include <QCheckBox>
@@ -138,11 +139,17 @@ void StartupSettingsPage::applySettings()
     GeneralSettings* settings = GeneralSettings::self();
 
     const QUrl url(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile));
-    KFileItem fileItem(url);
-    if ((url.isValid() && fileItem.isDir()) || (url.scheme() == QLatin1String("timeline"))) {
-        settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile));
+    if (url.isValid() && KProtocolManager::supportsListing(url)) {
+        KIO::StatJob* job = KIO::statDetails(url, KIO::StatJob::SourceSide, KIO::StatDetail::StatBasic, KIO::JobFlag::HideProgressInfo);
+        connect(job, &KJob::result, this, [this, settings, url](KJob* job) {
+            if (job->error() == 0 && qobject_cast<KIO::StatJob*>(job)->statResult().isDir()) {
+                settings->setHomeUrl(url.toDisplayString(QUrl::PreferLocalFile));
+            } else {
+                showSetDefaultDirectoryError();
+            }
+        });
     } else {
-        KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
+        showSetDefaultDirectoryError();
     }
 
     // Remove saved state if "remember open tabs" has been turned off
@@ -222,3 +229,8 @@ void StartupSettingsPage::loadSettings()
     m_showFullPathInTitlebar->setChecked(GeneralSettings::showFullPathInTitlebar());
     m_openExternallyCalledFolderInNewTab->setChecked(GeneralSettings::openExternallyCalledFolderInNewTab());
 }
+
+void StartupSettingsPage::showSetDefaultDirectoryError()
+{
+    KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied."));
+}
index ff3ffcb12916096d1814ff9d91f17cae3bfdeb02..1090e0822be4ddba2bcefc4cbcebf978faae2dba 100644 (file)
@@ -43,6 +43,7 @@ private slots:
 
 private:
     void loadSettings();
+    void showSetDefaultDirectoryError();
 
 private:
     QUrl m_url;