diff --git a/src/dbusinterface.cpp b/src/dbusinterface.cpp index 4e24354ab..15016d2e0 100644 --- a/src/dbusinterface.cpp +++ b/src/dbusinterface.cpp @@ -1,73 +1,73 @@ /* * Copyright 2015 Ashish Bansal * * 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 */ #include "dbusinterface.h" #include "global.h" #include "dolphin_generalsettings.h" #include #include #include #include #include DBusInterface::DBusInterface() : QObject() { QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/freedesktop/FileManager1"), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); QDBusConnection::sessionBus().interface()->registerService(QStringLiteral("org.freedesktop.FileManager1"), QDBusConnectionInterface::QueueService); } void DBusInterface::ShowFolders(const QStringList& uriList, const QString& startUpId) { Q_UNUSED(startUpId); const QList urls = Dolphin::validateUris(uriList); if (urls.isEmpty()) { return; } const auto serviceName = QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); if(!Dolphin::attachToExistingInstance(urls, false, GeneralSettings::splitView(), serviceName)) { Dolphin::openNewWindow(urls); } } void DBusInterface::ShowItems(const QStringList& uriList, const QString& startUpId) { Q_UNUSED(startUpId); const QList urls = Dolphin::validateUris(uriList); if (urls.isEmpty()) { return; } const auto serviceName = QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid()); if(!Dolphin::attachToExistingInstance(urls, true, GeneralSettings::splitView(), serviceName)) { - Dolphin::openNewWindow(urls); + Dolphin::openNewWindow(urls, nullptr, Dolphin::OpenNewWindowFlag::Select); }; } void DBusInterface::ShowItemProperties(const QStringList& uriList, const QString& startUpId) { Q_UNUSED(startUpId); const QList urls = Dolphin::validateUris(uriList); if (!urls.isEmpty()) { KPropertiesDialog::showDialog(urls); } } diff --git a/src/global.cpp b/src/global.cpp index 42044c97d..4547faced 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -1,145 +1,145 @@ /* * Copyright 2015 Ashish Bansal * * 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 */ #include "global.h" #include "dolphin_generalsettings.h" #include "dolphindebug.h" #include #include #include #include #include #include QList Dolphin::validateUris(const QStringList& uriList) { const QString currentDir = QDir::currentPath(); QList urls; foreach (const QString& str, uriList) { const QUrl url = QUrl::fromUserInput(str, currentDir, QUrl::AssumeLocalFile); if (url.isValid()) { urls.append(url); } else { qCWarning(DolphinDebug) << "Invalid URL: " << str; } } return urls; } QUrl Dolphin::homeUrl() { return QUrl::fromUserInput(GeneralSettings::homeUrl(), QString(), QUrl::AssumeLocalFile); } void Dolphin::openNewWindow(const QList &urls, QWidget *window, const OpenNewWindowFlags &flags) { QString command = QStringLiteral("dolphin --new-window"); if (flags.testFlag(OpenNewWindowFlag::Select)) { command.append(QLatin1String(" --select")); } if (!urls.isEmpty()) { command.append(QLatin1String(" %U")); } KRun::run( command, urls, window, QApplication::applicationDisplayName(), QApplication::windowIcon().name() ); } bool Dolphin::attachToExistingInstance(const QList& inputUrls, bool openFiles, bool splitView, const QString& preferredService) { // TODO: once Wayland clients can raise or activate themselves remove check from conditional - if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty()) { + if (KWindowSystem::isPlatformWayland() || inputUrls.isEmpty() || !GeneralSettings::openExternallyCalledFolderInNewTab()) { return false; } const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames().value(); // Don't match the service without trailing "-" (unique instance) const QString pattern = QStringLiteral("org.kde.dolphin-"); // Don't match the pid without leading "-" const QString myPid = QStringLiteral("-") + QString::number(QCoreApplication::applicationPid()); QVector, QStringList>> dolphinServices; if (!preferredService.isEmpty()) { QSharedPointer preferred( new QDBusInterface(preferredService, QStringLiteral("/dolphin/Dolphin_1"), QStringLiteral("org.kde.dolphin.MainWindow")) ); if (preferred->isValid()) { dolphinServices.append(qMakePair(preferred, QStringList() )); } } // find all dolphin instances for (const QString& service : services) { if (service.startsWith(pattern) && !service.endsWith(myPid)) { // Check if instance can handle our URLs QSharedPointer instance( new QDBusInterface(service, QStringLiteral("/dolphin/Dolphin_1"), QStringLiteral("org.kde.dolphin.MainWindow")) ); if (!instance->isValid() || instance->lastError().isValid()) { continue; } dolphinServices.append(qMakePair(instance, QStringList())); } } if (dolphinServices.isEmpty()) { return false; } QStringList newUrls; // check to see if any instances already have any of the given URLs open const auto urls = QUrl::toStringList(inputUrls); for (const QString& url : urls) { bool urlFound = false; for (auto& service: dolphinServices) { QDBusReply isUrlOpen = service.first->call(QStringLiteral("isUrlOpen"), url); if (isUrlOpen.isValid() && isUrlOpen.value()) { service.second.append(url); urlFound = true; break; } } if (!urlFound) { newUrls.append(url); } } dolphinServices.front().second << newUrls; for (const auto& service: dolphinServices) { if (!service.second.isEmpty()) { service.first->call(openFiles ? QStringLiteral("openFiles") : QStringLiteral("openDirectories"), service.second, splitView); service.first->call(QStringLiteral("activateWindow")); } } return true; } diff --git a/src/settings/dolphin_generalsettings.kcfg b/src/settings/dolphin_generalsettings.kcfg index 5a6bba06b..5a7bb1a01 100644 --- a/src/settings/dolphin_generalsettings.kcfg +++ b/src/settings/dolphin_generalsettings.kcfg @@ -1,123 +1,127 @@ QDir QUrl KCompletion false KCompletion::CompletionPopup false false + + + true + 0 false QUrl::fromLocalFile(QDir::homePath()).toDisplayString(QUrl::PreferLocalFile) false false true false true true true true false true false false false true true true true 0 diff --git a/src/settings/startup/startupsettingspage.cpp b/src/settings/startup/startupsettingspage.cpp index 23d8731d4..d7d5fba4c 100644 --- a/src/settings/startup/startupsettingspage.cpp +++ b/src/settings/startup/startupsettingspage.cpp @@ -1,186 +1,191 @@ /*************************************************************************** * Copyright (C) 2008 by Peter Penz * * * * 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 * ***************************************************************************/ #include "startupsettingspage.h" #include "dolphin_generalsettings.h" #include "dolphinmainwindow.h" #include "dolphinviewcontainer.h" #include "global.h" #include #include #include #include #include #include #include #include #include StartupSettingsPage::StartupSettingsPage(const QUrl& url, QWidget* parent) : SettingsPageBase(parent), m_url(url), m_homeUrl(nullptr), m_splitView(nullptr), m_editableUrl(nullptr), m_showFullPath(nullptr), m_filterBar(nullptr), - m_showFullPathInTitlebar(nullptr) + m_showFullPathInTitlebar(nullptr), + m_openExternallyCalledFolderInNewTab(nullptr) { QFormLayout* topLayout = new QFormLayout(this); // create 'Home URL' editor QHBoxLayout* homeUrlBoxLayout = new QHBoxLayout(); homeUrlBoxLayout->setContentsMargins(0, 0, 0, 0); m_homeUrl = new QLineEdit(); m_homeUrl->setClearButtonEnabled(true); homeUrlBoxLayout->addWidget(m_homeUrl); QPushButton* selectHomeUrlButton = new QPushButton(QIcon::fromTheme(QStringLiteral("folder-open")), QString()); homeUrlBoxLayout->addWidget(selectHomeUrlButton); #ifndef QT_NO_ACCESSIBILITY selectHomeUrlButton->setAccessibleName(i18nc("@action:button", "Select Home Location")); #endif connect(selectHomeUrlButton, &QPushButton::clicked, this, &StartupSettingsPage::selectHomeUrl); QHBoxLayout* buttonBoxLayout = new QHBoxLayout(); buttonBoxLayout->setContentsMargins(0, 0, 0, 0); QPushButton* useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location")); buttonBoxLayout->addWidget(useCurrentButton); connect(useCurrentButton, &QPushButton::clicked, this, &StartupSettingsPage::useCurrentLocation); QPushButton* useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location")); buttonBoxLayout->addWidget(useDefaultButton); connect(useDefaultButton, &QPushButton::clicked, this, &StartupSettingsPage::useDefaultLocation); QVBoxLayout* homeBoxLayout = new QVBoxLayout(); homeBoxLayout->setContentsMargins(0, 0, 0, 0); homeBoxLayout->addLayout(homeUrlBoxLayout); homeBoxLayout->addLayout(buttonBoxLayout); topLayout->addRow(i18nc("@label:textbox", "Start in:"), homeBoxLayout); topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed)); // create 'Split view', 'Show full path', 'Editable location' and 'Filter bar' checkboxes m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode")); topLayout->addRow(i18nc("@label:checkbox", "Window options:"), m_splitView); m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar")); topLayout->addRow(QString(), m_editableUrl); m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar")); topLayout->addRow(QString(), m_showFullPath); m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Show filter bar")); topLayout->addRow(QString(), m_filterBar); m_showFullPathInTitlebar = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path in title bar")); topLayout->addRow(QString(), m_showFullPathInTitlebar); + m_openExternallyCalledFolderInNewTab = new QCheckBox(i18nc("@option:check Startup Settings", "Open new folders in tabs")); + topLayout->addRow(QString(), m_openExternallyCalledFolderInNewTab); loadSettings(); connect(m_homeUrl, &QLineEdit::textChanged, this, &StartupSettingsPage::slotSettingsChanged); connect(m_splitView, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); connect(m_editableUrl, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); connect(m_filterBar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); connect(m_showFullPathInTitlebar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); + connect(m_openExternallyCalledFolderInNewTab, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); } StartupSettingsPage::~StartupSettingsPage() { } 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)); } else { KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied.")); } settings->setSplitView(m_splitView->isChecked()); settings->setEditableUrl(m_editableUrl->isChecked()); settings->setShowFullPath(m_showFullPath->isChecked()); settings->setFilterBar(m_filterBar->isChecked()); settings->setShowFullPathInTitlebar(m_showFullPathInTitlebar->isChecked()); - + settings->setOpenExternallyCalledFolderInNewTab(m_openExternallyCalledFolderInNewTab->isChecked()); settings->save(); } void StartupSettingsPage::restoreDefaults() { GeneralSettings* settings = GeneralSettings::self(); settings->useDefaults(true); loadSettings(); settings->useDefaults(false); } void StartupSettingsPage::slotSettingsChanged() { // Provide a hint that the startup settings have been changed. This allows the views // to apply the startup settings only if they have been explicitly changed by the user // (see bug #254947). GeneralSettings::setModifiedStartupSettings(true); emit changed(); } void StartupSettingsPage::selectHomeUrl() { const QUrl homeUrl(QUrl::fromUserInput(m_homeUrl->text(), QString(), QUrl::AssumeLocalFile)); QUrl url = QFileDialog::getExistingDirectoryUrl(this, QString(), homeUrl); if (!url.isEmpty()) { m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); slotSettingsChanged(); } } void StartupSettingsPage::useCurrentLocation() { m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile)); } void StartupSettingsPage::useDefaultLocation() { m_homeUrl->setText(QDir::homePath()); } void StartupSettingsPage::loadSettings() { const QUrl url(Dolphin::homeUrl()); m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); m_splitView->setChecked(GeneralSettings::splitView()); m_editableUrl->setChecked(GeneralSettings::editableUrl()); m_showFullPath->setChecked(GeneralSettings::showFullPath()); m_filterBar->setChecked(GeneralSettings::filterBar()); m_showFullPathInTitlebar->setChecked(GeneralSettings::showFullPathInTitlebar()); + m_openExternallyCalledFolderInNewTab->setChecked(GeneralSettings::openExternallyCalledFolderInNewTab()); } diff --git a/src/settings/startup/startupsettingspage.h b/src/settings/startup/startupsettingspage.h index e06b65697..a5e0b236f 100644 --- a/src/settings/startup/startupsettingspage.h +++ b/src/settings/startup/startupsettingspage.h @@ -1,69 +1,70 @@ /*************************************************************************** * Copyright (C) 2008 by Peter Penz * * * * 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 * ***************************************************************************/ #ifndef STARTUPSETTINGSPAGE_H #define STARTUPSETTINGSPAGE_H #include "settings/settingspagebase.h" #include class QLineEdit; class QCheckBox; /** * @brief Page for the 'Startup' settings of the Dolphin settings dialog. * * The startup settings allow to set the home URL and to configure the * state of the view mode, split mode and the filter bar when starting Dolphin. */ class StartupSettingsPage : public SettingsPageBase { Q_OBJECT public: StartupSettingsPage(const QUrl& url, QWidget* parent); ~StartupSettingsPage() override; /** @see SettingsPageBase::applySettings() */ void applySettings() override; /** @see SettingsPageBase::restoreDefaults() */ void restoreDefaults() override; private slots: void slotSettingsChanged(); void selectHomeUrl(); void useCurrentLocation(); void useDefaultLocation(); private: void loadSettings(); private: QUrl m_url; QLineEdit* m_homeUrl; QCheckBox* m_splitView; QCheckBox* m_editableUrl; QCheckBox* m_showFullPath; QCheckBox* m_filterBar; QCheckBox* m_showFullPathInTitlebar; + QCheckBox* m_openExternallyCalledFolderInNewTab; }; #endif