diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -186,6 +186,21 @@ toolBar()->installEventFilter(middleClickEventFilter); setupWhatsThis(); + + // Restore window state if the setting is turned on and there are no + // other Dolphin windows open + if (GeneralSettings::rememberOpenedTabs()) { + // Check for existing Dolphin windows in a separate nested if() to + // save a DBus call if the user isn't using the feature + // FIXME: Calling Dolphin::dolphinInstanceData() here is slooooooooow + if (Dolphin::dolphinInstanceData(QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid())).isEmpty()) { + // Wait for the initialization ending + QTimer::singleShot(0, [this]() { + KConfigGroup windowState{KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "WindowState"}; + readProperties(windowState); + }); + } + } } DolphinMainWindow::~DolphinMainWindow() @@ -534,6 +549,11 @@ } } + if (GeneralSettings::rememberOpenedTabs()) { + KConfigGroup windowState{KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "WindowState"}; + saveProperties(windowState); + } + GeneralSettings::setVersion(CurrentDolphinVersion); GeneralSettings::self()->save(); diff --git a/src/global.h b/src/global.h --- a/src/global.h +++ b/src/global.h @@ -20,6 +20,8 @@ #ifndef GLOBAL_H #define GLOBAL_H +#include +#include #include #include @@ -48,6 +50,12 @@ */ bool attachToExistingInstance(const QList& inputUrls, bool openFiles, bool splitView, const QString& preferredService = QString()); + /** + * Returns a QVector with full data about all currently-running GUI-capable + * Dolphin instances + */ + QVector, QStringList>> dolphinInstanceData(const QString& preferredService); + /** * TODO: Move this somewhere global to all KDE apps, not just Dolphin */ diff --git a/src/global.cpp b/src/global.cpp --- a/src/global.cpp +++ b/src/global.cpp @@ -77,6 +77,42 @@ return false; } + QVector, QStringList>> dolphinServices = dolphinInstanceData(preferredService); + 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; +} + +QVector, QStringList>> Dolphin::dolphinInstanceData(const QString& preferredService) +{ QVector, QStringList>> dolphinServices; if (!preferredService.isEmpty()) { QSharedPointer preferred( @@ -110,34 +146,7 @@ } if (dolphinServices.isEmpty()) { - return false; + return QVector, QStringList>>(); } - - 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; + return dolphinServices; } diff --git a/src/settings/dolphin_generalsettings.kcfg b/src/settings/dolphin_generalsettings.kcfg --- a/src/settings/dolphin_generalsettings.kcfg +++ b/src/settings/dolphin_generalsettings.kcfg @@ -42,6 +42,10 @@ QUrl::fromLocalFile(QDir::homePath()).toDisplayString(QUrl::PreferLocalFile) + + + false + false diff --git a/src/settings/startup/startupsettingspage.h b/src/settings/startup/startupsettingspage.h --- a/src/settings/startup/startupsettingspage.h +++ b/src/settings/startup/startupsettingspage.h @@ -59,6 +59,7 @@ QUrl m_url; QLineEdit* m_homeUrl; + QCheckBox* m_rememberOpenedTabs; QCheckBox* m_splitView; QCheckBox* m_editableUrl; QCheckBox* m_showFullPath; diff --git a/src/settings/startup/startupsettingspage.cpp b/src/settings/startup/startupsettingspage.cpp --- a/src/settings/startup/startupsettingspage.cpp +++ b/src/settings/startup/startupsettingspage.cpp @@ -84,36 +84,38 @@ homeBoxLayout->addLayout(homeUrlBoxLayout); homeBoxLayout->addLayout(buttonBoxLayout); - topLayout->addRow(i18nc("@label:textbox", "Start in:"), homeBoxLayout); + topLayout->addRow(i18nc("@label:textbox", "For new windows, show:"), homeBoxLayout); + + m_splitView = new QCheckBox(i18nc("@option:check Startup Settings", "Split view mode")); + topLayout->addRow(QString(), m_splitView); + m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Editable location bar")); + topLayout->addRow(QString(), m_editableUrl); + m_filterBar = new QCheckBox(i18nc("@option:check Startup Settings", "Filter bar")); + topLayout->addRow(QString(), m_filterBar); 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_rememberOpenedTabs = new QCheckBox(i18nc("@option:check Startup Settings", "Remember open folders and tabs")); + topLayout->addRow(i18nc("@label:checkbox", "General settings:"), m_rememberOpenedTabs); + m_openExternallyCalledFolderInNewTab = new QCheckBox(i18nc("@option:check Startup Settings", "Open new folders in tabs")); + topLayout->addRow(QString(), m_openExternallyCalledFolderInNewTab); 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_rememberOpenedTabs, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); connect(m_openExternallyCalledFolderInNewTab, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); + connect(m_showFullPath, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); + connect(m_showFullPathInTitlebar, &QCheckBox::toggled, this, &StartupSettingsPage::slotSettingsChanged); } StartupSettingsPage::~StartupSettingsPage() @@ -132,6 +134,7 @@ KMessageBox::error(this, i18nc("@info", "The location for the home folder is invalid or does not exist, it will not be applied.")); } + settings->setRememberOpenedTabs(m_rememberOpenedTabs->isChecked()); settings->setSplitView(m_splitView->isChecked()); settings->setEditableUrl(m_editableUrl->isChecked()); settings->setShowFullPath(m_showFullPath->isChecked()); @@ -182,6 +185,7 @@ { const QUrl url(Dolphin::homeUrl()); m_homeUrl->setText(url.toDisplayString(QUrl::PreferLocalFile)); + m_rememberOpenedTabs->setChecked(GeneralSettings::rememberOpenedTabs()); m_splitView->setChecked(GeneralSettings::splitView()); m_editableUrl->setChecked(GeneralSettings::editableUrl()); m_showFullPath->setChecked(GeneralSettings::showFullPath());