File indexing completed on 2024-05-19 05:00:55

0001 /*
0002     This file is part of the KDE project.
0003 
0004     SPDX-FileCopyrightText: 2023 Stefano Crocco <stefano.crocco@alice.it>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #include "tabsoptions.h"
0010 
0011 #include "ui_tabsoptions.h"
0012 
0013 #include <KConfigGroup>
0014 #include <QDBusMessage>
0015 #include <QDBusConnection>
0016 
0017 TabsOptions::TabsOptions(QObject* parent, const KPluginMetaData& md, const QVariantList& args) : KCModule(parent, md),
0018     m_ui(new Ui::TabsOptions)
0019 {
0020     Q_UNUSED(args);
0021     m_config = KSharedConfig::openConfig(QStringLiteral("konquerorrc"), KConfig::NoGlobals);
0022     m_ui->setupUi(this->widget());
0023     connect(m_ui->m_pShowMMBInTabs, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0024     connect(m_ui->m_pDynamicTabbarHide, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0025     connect(m_ui->m_pNewTabsInBackground, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0026     connect(m_ui->m_pOpenAfterCurrentPage, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0027     connect(m_ui->m_pTabConfirm, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0028     connect(m_ui->m_pTabCloseActivatePrevious, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0029     connect(m_ui->m_pPermanentCloseButton, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0030     connect(m_ui->m_pKonquerorTabforExternalURL, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0031     connect(m_ui->m_pPopupsWithinTabs, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0032     connect(m_ui->m_pMiddleClickClose, &QAbstractButton::toggled, this, [this](bool){setNeedsSave(true);});
0033     connect(m_ui->tabbarPosition, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int){setNeedsSave(true);});
0034 }
0035 
0036 TabsOptions::~TabsOptions() noexcept
0037 {
0038 }
0039 
0040 void TabsOptions::defaults()
0041 {
0042     bool old = m_config->readDefaults();
0043     m_config->setReadDefaults(true);
0044     load();
0045     m_config->setReadDefaults(old);
0046 
0047 #if QT_VERSION_MAJOR > 5
0048     setRepresentsDefaults(true);
0049 #endif
0050 }
0051 
0052 void TabsOptions::load()
0053 {
0054     //TODO KF6: move these settings to a Tabs group
0055     KConfigGroup cg = m_config->group("FMSettings");
0056     m_ui->m_pShowMMBInTabs->setChecked(cg.readEntry("MMBOpensTab", true));
0057     m_ui->m_pDynamicTabbarHide->setChecked(!(cg.readEntry("AlwaysTabbedMode", false)));
0058     m_ui->m_pNewTabsInBackground->setChecked(!(cg.readEntry("NewTabsInFront", false)));
0059     m_ui->m_pOpenAfterCurrentPage->setChecked(cg.readEntry("OpenAfterCurrentPage", false));
0060     m_ui->m_pPermanentCloseButton->setChecked(cg.readEntry("PermanentCloseButton", true));
0061     m_ui->m_pKonquerorTabforExternalURL->setChecked(cg.readEntry("KonquerorTabforExternalURL", false));
0062     m_ui->m_pPopupsWithinTabs->setChecked(cg.readEntry("PopupsWithinTabs", false));
0063     m_ui->m_pTabCloseActivatePrevious->setChecked(cg.readEntry("TabCloseActivatePrevious", false));
0064     m_ui->m_pMiddleClickClose->setChecked(cg.readEntry("MouseMiddleClickClosesTab", false));
0065     m_ui->tabbarPosition->setCurrentIndex(cg.readEntry("TabBarPosition", 0));
0066 
0067     cg = KConfigGroup(m_config, "Notification Messages");
0068     m_ui->m_pTabConfirm->setChecked(!cg.hasKey("MultipleTabConfirm"));
0069     KCModule::load();
0070 }
0071 
0072 void TabsOptions::save()
0073 {
0074     //TODO KF6: move these settings to a Tabs group
0075     KConfigGroup cg(m_config, "FMSettings");
0076     cg.writeEntry("MMBOpensTab", m_ui->m_pShowMMBInTabs->isChecked());
0077     cg.writeEntry("AlwaysTabbedMode", !(m_ui->m_pDynamicTabbarHide->isChecked()));
0078 
0079     cg.writeEntry("NewTabsInFront", !(m_ui->m_pNewTabsInBackground->isChecked()));
0080     cg.writeEntry("OpenAfterCurrentPage", m_ui->m_pOpenAfterCurrentPage->isChecked());
0081     cg.writeEntry("PermanentCloseButton", m_ui->m_pPermanentCloseButton->isChecked());
0082     cg.writeEntry("KonquerorTabforExternalURL", m_ui->m_pKonquerorTabforExternalURL->isChecked());
0083     cg.writeEntry("PopupsWithinTabs", m_ui->m_pPopupsWithinTabs->isChecked());
0084     cg.writeEntry("TabCloseActivatePrevious", m_ui->m_pTabCloseActivatePrevious->isChecked());
0085     cg.writeEntry("MouseMiddleClickClosesTab", m_ui->m_pMiddleClickClose->isChecked());
0086     cg.writeEntry("TabBarPosition", m_ui->tabbarPosition->currentIndex());
0087     cg.sync();
0088     // It only matters whether the key is present, its value has no meaning
0089     cg = KConfigGroup(m_config, "Notification Messages");
0090     if (m_ui->m_pTabConfirm->isChecked()) {
0091         cg.deleteEntry("MultipleTabConfirm");
0092     } else {
0093         cg.writeEntry("MultipleTabConfirm", true);
0094     }
0095     // Send signal to all konqueror instances
0096     QDBusMessage message =
0097         QDBusMessage::createSignal(QStringLiteral("/KonqMain"), QStringLiteral("org.kde.Konqueror.Main"), QStringLiteral("reparseConfiguration"));
0098     QDBusConnection::sessionBus().send(message);
0099 
0100     KCModule::save();
0101 }
0102 
0103 
0104