File indexing completed on 2024-05-05 05:00:15

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2023 Stefano Crocco <stefano.crocco@alice.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "configdialog.h"
0008 
0009 #include <KCModule>
0010 
0011 #include <QTabWidget>
0012 
0013 using namespace Konq;
0014 
0015 Konq::ConfigDialog::ConfigDialog(QWidget* parent) : KCMultiDialog(parent)
0016 {
0017     setObjectName(QStringLiteral("configureDialog"));
0018     setFaceType(KPageDialog::Tree);
0019 
0020     QMap<Module, QString> modules {
0021         {GeneralModule, "konqueror_kcms/khtml_general"},
0022         {PerformanceModule, "konqueror_kcms/kcm_performance"},
0023         {TabsModule, "konqueror_kcms/khtml_tabs"},
0024         {BookmarksModule, "konqueror_kcms/kcm_bookmarks"},
0025         {KonqModule, "konqueror_kcms/kcm_konq"},
0026         {DolphinGeneralModule, "dolphin/kcms/kcm_dolphingeneral"},
0027 #if QT_VERSION_MAJOR < 6
0028         {DolphinNavigationModule, "dolphin/kcms/kcm_dolphinnavigation"},
0029 #endif
0030         {DolphinViewModesModule, "dolphin/kcms/kcm_dolphinviewmodes"},
0031         {TrashModule, "kcm_trash"},
0032         {FileTypesModule, "plasma/kcms/systemsettings_qwidgets/kcm_filetypes"},
0033         {HtmlBehaviorModule, "konqueror_kcms/khtml_behavior"},
0034         {HtmlAppearanceModule, "konqueror_kcms/khtml_appearance"},
0035         {AdBlockModule, "konqueror_kcms/khtml_filter"},
0036         {HtmlCacheModule, "konqueror_kcms/khtml_cache"},
0037 #if QT_VERSION_MAJOR < 6
0038         {WebShortcutsModule, "kcm_webshortcuts"},
0039         {ProxyModule, "kcm_proxy"},
0040 #else
0041         {WebShortcutsModule, "plasma/kcms/systemsettings_qwidgets/kcm_webshortcuts"},
0042         {ProxyModule, "plasma/kcms/systemsettings_qwidgets/kcm_proxy"},
0043 #endif
0044         {HistoryModule, "konqueror_kcms/kcm_history"},
0045         {CookiesModule, "konqueror_kcms/khtml_cookies"},
0046         {JavaModule, "konqueror_kcms/khtml_java_js"},
0047         {UserAgentModule, "konqueror_kcms/khtml_useragent"}
0048     };
0049 
0050 #ifdef Q_OS_WIN
0051     modules.remove(PerformanceModule);
0052 #endif
0053     for (auto modIt = modules.constBegin(); modIt != modules.constEnd(); ++modIt) {
0054         KPluginMetaData md(modIt.value());
0055         //In KF6, the web shortcuts and the proxy KCMs are provided by kio-extras, which Konqueror doesn't require,
0056         //so avoid displaying an invalid entry if they can't be loaded for any reason
0057         if (!md.isValid() && (modIt.key() == WebShortcutsModule || modIt.key() == ProxyModule)) {
0058             continue;
0059         }
0060         KPageWidgetItem *it = addModule(md);
0061         //Attempt to remove the Behavior tab from the Dolphin general module, as it only applies to dolphin
0062         if (modIt.key() == DolphinGeneralModule) {
0063             fixDolphinGeneralPage(it);
0064         }
0065         m_pages[modIt.key()] = it;
0066     }
0067 }
0068 
0069 Konq::ConfigDialog::~ConfigDialog() noexcept
0070 {
0071 }
0072 
0073 void Konq::ConfigDialog::fixDolphinGeneralPage(KPageWidgetItem *it)
0074 {
0075     QTabWidget *tw = it->widget()->findChild<QTabWidget*>();
0076     if(tw && tw->count() > 0) {
0077         tw->removeTab(0);
0078     }
0079 }
0080 
0081 QSize Konq::ConfigDialog::computeSizeHint() const
0082 {
0083     QSize size{KCMultiDialog::sizeHint()};
0084     for (auto it = m_pages.constBegin(); it != m_pages.constEnd(); ++it) {
0085         QSize s = it.value()->widget()->sizeHint();
0086         if (size.width() < s.width()) {
0087             size.setWidth(s.width());
0088         }
0089         if (size.height() < s.height()) {
0090             size.setHeight(s.height());
0091         }
0092     }
0093     return size;
0094 }
0095 
0096 QSize Konq::ConfigDialog::sizeHint() const
0097 {
0098     if (!m_sizeHint.isValid()) {
0099         m_sizeHint = computeSizeHint();
0100     }
0101     return m_sizeHint;
0102 }
0103 
0104 void Konq::ConfigDialog::setCurrentPage(Module module)
0105 {
0106     KPageWidgetItem *page = m_pages.value(module);
0107     if (page) {
0108         KCMultiDialog::setCurrentPage(page);
0109     }
0110 }