]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/settings/startup/startupsettingspage.cpp
Allow non-local startup location
[dolphin.git] / src / settings / startup / startupsettingspage.cpp
index eb149574659dfb82f9cf2cebe49c7330cd0fb254..a7fcec4fa3320f818a0e7e1711d316b038941719 100644 (file)
@@ -1,21 +1,8 @@
-/***************************************************************************
- *   Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2008 Peter Penz <peter.penz19@gmail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "startupsettingspage.h"
 
@@ -26,6 +13,7 @@
 
 #include <KLocalizedString>
 #include <KMessageBox>
+#include <KProtocolManager>
 
 #include <QButtonGroup>
 #include <QCheckBox>
@@ -151,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
@@ -193,7 +187,7 @@ void StartupSettingsPage::slotSettingsChanged()
 
     // Enable and disable home URL controls appropriately
     updateInitialViewOptions();
-    emit changed();
+    Q_EMIT changed();
 }
 
 void StartupSettingsPage::updateInitialViewOptions()
@@ -235,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."));
+}