File indexing completed on 2024-05-12 17:18:54

0001 /*
0002  * SPDX-FileCopyrightText: 2023 Dimosthenis Krallis <dimosthenis.krallis@outlook.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "statusandlocationbarssettingspage.h"
0008 #include "dolphinmainwindow.h"
0009 #include "dolphinviewcontainer.h"
0010 #include "settings/interface/folderstabssettingspage.h"
0011 
0012 #include <KLocalizedString>
0013 
0014 #include <QCheckBox>
0015 #include <QFormLayout>
0016 
0017 #include <QRadioButton>
0018 #include <QSpacerItem>
0019 
0020 StatusAndLocationBarsSettingsPage::StatusAndLocationBarsSettingsPage(QWidget *parent, FoldersTabsSettingsPage *foldersPage)
0021     : SettingsPageBase(parent)
0022     , m_editableUrl(nullptr)
0023     , m_showFullPath(nullptr)
0024     , m_showStatusBar(nullptr)
0025     , m_showZoomSlider(nullptr)
0026     , m_showSpaceInfo(nullptr)
0027 {
0028     // We need to update some urls at the Folders & Tabs tab. We get that from foldersPage and set it on a private attribute
0029     // foldersTabsPage. That way, we can modify the necessary stuff from here. Specifically, any changes on locationUpdateInitialViewOptions()
0030     // which is a copy of updateInitialViewOptions() on Folders & Tabs.
0031     foldersTabsPage = foldersPage;
0032 
0033     QFormLayout *topLayout = new QFormLayout(this);
0034 
0035     // Status bar
0036     m_showStatusBar = new QCheckBox(i18nc("@option:check", "Show status bar"), this);
0037     m_showZoomSlider = new QCheckBox(i18nc("@option:check", "Show zoom slider"), this);
0038     m_showSpaceInfo = new QCheckBox(i18nc("@option:check", "Show space information"), this);
0039 
0040     topLayout->addRow(i18nc("@title:group", "Status Bar: "), m_showStatusBar);
0041     topLayout->addRow(QString(), m_showZoomSlider);
0042     topLayout->addRow(QString(), m_showSpaceInfo);
0043 
0044     topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
0045 
0046     // Location bar
0047     m_editableUrl = new QCheckBox(i18nc("@option:check Startup Settings", "Make location bar editable"));
0048     topLayout->addRow(i18n("Location bar:"), m_editableUrl);
0049 
0050     m_showFullPath = new QCheckBox(i18nc("@option:check Startup Settings", "Show full path inside location bar"));
0051     topLayout->addRow(QString(), m_showFullPath);
0052 
0053     loadSettings();
0054 
0055     locationUpdateInitialViewOptions();
0056 
0057     connect(m_editableUrl, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged);
0058     connect(m_showFullPath, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged);
0059 
0060     connect(m_showStatusBar, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::changed);
0061     connect(m_showStatusBar, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::onShowStatusBarToggled);
0062     connect(m_showZoomSlider, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::changed);
0063     connect(m_showSpaceInfo, &QCheckBox::toggled, this, &StatusAndLocationBarsSettingsPage::changed);
0064 }
0065 
0066 StatusAndLocationBarsSettingsPage::~StatusAndLocationBarsSettingsPage()
0067 {
0068 }
0069 
0070 void StatusAndLocationBarsSettingsPage::applySettings()
0071 {
0072     GeneralSettings *settings = GeneralSettings::self();
0073 
0074     settings->setEditableUrl(m_editableUrl->isChecked());
0075     settings->setShowFullPath(m_showFullPath->isChecked());
0076 
0077     settings->setShowStatusBar(m_showStatusBar->isChecked());
0078     settings->setShowZoomSlider(m_showZoomSlider->isChecked());
0079     settings->setShowSpaceInfo(m_showSpaceInfo->isChecked());
0080 
0081     settings->save();
0082 }
0083 
0084 void StatusAndLocationBarsSettingsPage::onShowStatusBarToggled()
0085 {
0086     const bool checked = m_showStatusBar->isChecked();
0087     m_showZoomSlider->setEnabled(checked);
0088     m_showSpaceInfo->setEnabled(checked);
0089 }
0090 
0091 void StatusAndLocationBarsSettingsPage::restoreDefaults()
0092 {
0093     GeneralSettings *settings = GeneralSettings::self();
0094     settings->useDefaults(true);
0095     loadSettings();
0096     settings->useDefaults(false);
0097 }
0098 
0099 void StatusAndLocationBarsSettingsPage::locationSlotSettingsChanged()
0100 {
0101     // Provide a hint that the startup settings have been changed. This allows the views
0102     // to apply the startup settings only if they have been explicitly changed by the user
0103     // (see bug #254947).
0104     GeneralSettings::setModifiedStartupSettings(true);
0105 
0106     // Enable and disable home URL controls appropriately
0107     locationUpdateInitialViewOptions();
0108     Q_EMIT changed();
0109 }
0110 
0111 void StatusAndLocationBarsSettingsPage::locationUpdateInitialViewOptions()
0112 {
0113     foldersTabsPage->m_homeUrlBoxLayoutContainer->setEnabled(foldersTabsPage->m_homeUrlRadioButton->isChecked());
0114     foldersTabsPage->m_buttonBoxLayoutContainer->setEnabled(foldersTabsPage->m_homeUrlRadioButton->isChecked());
0115 }
0116 
0117 void StatusAndLocationBarsSettingsPage::loadSettings()
0118 {
0119     m_editableUrl->setChecked(GeneralSettings::editableUrl());
0120     m_showFullPath->setChecked(GeneralSettings::showFullPath());
0121     m_showStatusBar->setChecked(GeneralSettings::showStatusBar());
0122     m_showZoomSlider->setChecked(GeneralSettings::showZoomSlider());
0123     m_showSpaceInfo->setChecked(GeneralSettings::showSpaceInfo());
0124 
0125     onShowStatusBarToggled();
0126 }
0127 
0128 #include "moc_statusandlocationbarssettingspage.cpp"