┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkseli Lahtinen <[email protected]>2024-08-30 10:54:56 +0000
committerAkseli Lahtinen <[email protected]>2024-08-30 10:54:56 +0000
commitfc3a6594cc2572da95e7c889793363c3ecdc4635 (patch)
tree0af86291cc66d84234f7b8b2c2b6b156c34bde68
parentd66414f9df71b7861d7550f53fe7987effe25008 (diff)
settings: Fix the Use Current Location button
During the Dolphin settings revamp (https://invent.kde.org/system/dolphin/-/commit/489b56b68bb29e81337e115c490eea4403001b71?) this QUrl had been forgot to add back so that the FoldersTabsSettingsPage knows what is the current url. This change checks for the main window of dolphin, then gets the URL of it whenever useCurrentLocation is called. However, when this is used as KCM, the button is not created, since there it doesn't make sense. BUG:491753
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/settings/interface/folderstabssettingspage.cpp19
2 files changed, 20 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bbf882a8a..ce5b54613 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -526,6 +526,7 @@ if(NOT WIN32)
# The settings are still accessible from the hamburger menu
add_library(kcm_dolphinviewmodes MODULE)
add_library(kcm_dolphingeneral MODULE)
+ target_compile_definitions(kcm_dolphingeneral PUBLIC IS_KCM)
target_sources(kcm_dolphinviewmodes PRIVATE
settings/kcm/kcmdolphinviewmodes.cpp
diff --git a/src/settings/interface/folderstabssettingspage.cpp b/src/settings/interface/folderstabssettingspage.cpp
index 6fad3d1c2..0212f624c 100644
--- a/src/settings/interface/folderstabssettingspage.cpp
+++ b/src/settings/interface/folderstabssettingspage.cpp
@@ -13,6 +13,9 @@
#include <KMessageBox>
#include <KProtocolManager>
+#ifndef IS_KCM
+#include <QApplication>
+#endif
#include <QButtonGroup>
#include <QCheckBox>
#include <QFileDialog>
@@ -71,9 +74,11 @@ FoldersTabsSettingsPage::FoldersTabsSettingsPage(QWidget *parent)
QHBoxLayout *buttonBoxLayout = new QHBoxLayout(m_buttonBoxLayoutContainer);
buttonBoxLayout->setContentsMargins(0, 0, 0, 0);
+#ifndef IS_KCM
QPushButton *useCurrentButton = new QPushButton(i18nc("@action:button", "Use Current Location"));
buttonBoxLayout->addWidget(useCurrentButton);
connect(useCurrentButton, &QPushButton::clicked, this, &FoldersTabsSettingsPage::useCurrentLocation);
+#endif
QPushButton *useDefaultButton = new QPushButton(i18nc("@action:button", "Use Default Location"));
buttonBoxLayout->addWidget(useDefaultButton);
connect(useDefaultButton, &QPushButton::clicked, this, &FoldersTabsSettingsPage::useDefaultLocation);
@@ -241,6 +246,20 @@ void FoldersTabsSettingsPage::selectHomeUrl()
void FoldersTabsSettingsPage::useCurrentLocation()
{
+#ifndef IS_KCM
+ DolphinMainWindow *mainWindow = nullptr;
+ const auto topLevelWidgets = QApplication::allWidgets();
+ for (const auto widget : topLevelWidgets) {
+ if (qobject_cast<DolphinMainWindow *>(widget)) {
+ mainWindow = static_cast<DolphinMainWindow *>(widget);
+ break;
+ }
+ }
+
+ if (mainWindow) {
+ m_url = mainWindow->activeViewContainer()->url();
+ }
+#endif
m_homeUrl->setText(m_url.toDisplayString(QUrl::PreferLocalFile));
}