File indexing completed on 2024-12-22 05:01:02
0001 /* 0002 * kmail: KDE mail client 0003 * SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 // configuredialog_p.cpp: classes internal to ConfigureDialog 0007 // see configuredialog.cpp for details. 0008 0009 // my header: 0010 #include "configuredialog_p.h" 0011 0012 // other KMail headers: 0013 #include "settings/kmailsettings.h" 0014 0015 // other KDE headers: 0016 #include <QTabWidget> 0017 0018 // Qt headers: 0019 #include <QShowEvent> 0020 #include <QVBoxLayout> 0021 0022 // Other headers: 0023 0024 ConfigModuleWithTabs::ConfigModuleWithTabs(QObject *parent, const KPluginMetaData &data) 0025 : ConfigModule(parent, data) 0026 , mTabWidget(new QTabWidget(widget())) 0027 { 0028 auto vlay = new QVBoxLayout(widget()); 0029 vlay->setContentsMargins({}); 0030 vlay->addWidget(mTabWidget); 0031 mTabWidget->setDocumentMode(true); 0032 } 0033 0034 void ConfigModuleWithTabs::addTab(ConfigModuleTab *tab, const QString &title) 0035 { 0036 mTabWidget->addTab(tab, title); 0037 connect(tab, &ConfigModuleTab::changed, this, [this](bool state) { 0038 setNeedsSave(state); 0039 }); 0040 } 0041 0042 void ConfigModuleWithTabs::load() 0043 { 0044 const int numberOfTab = mTabWidget->count(); 0045 for (int i = 0; i < numberOfTab; ++i) { 0046 auto tab = qobject_cast<ConfigModuleTab *>(mTabWidget->widget(i)); 0047 if (tab) { 0048 tab->load(); 0049 } 0050 } 0051 KCModule::load(); 0052 mWasInitialized = true; 0053 } 0054 0055 void ConfigModuleWithTabs::save() 0056 { 0057 if (mWasInitialized) { 0058 KCModule::save(); 0059 const int numberOfTab = mTabWidget->count(); 0060 for (int i = 0; i < numberOfTab; ++i) { 0061 auto tab = qobject_cast<ConfigModuleTab *>(mTabWidget->widget(i)); 0062 if (tab) { 0063 tab->save(); 0064 } 0065 } 0066 } 0067 } 0068 0069 void ConfigModuleWithTabs::defaults() 0070 { 0071 auto tab = qobject_cast<ConfigModuleTab *>(mTabWidget->currentWidget()); 0072 if (tab) { 0073 tab->defaults(); 0074 } 0075 KCModule::defaults(); 0076 } 0077 0078 void ConfigModuleTab::load() 0079 { 0080 mEmitChanges = false; 0081 doLoadFromGlobalSettings(); 0082 doLoadOther(); 0083 mEmitChanges = true; 0084 } 0085 0086 void ConfigModuleTab::defaults() 0087 { 0088 // reset settings which are available via GlobalSettings to their defaults 0089 // (stolen from KConfigDialogManager::updateWidgetsDefault()) 0090 const bool bUseDefaults = KMailSettings::self()->useDefaults(true); 0091 doLoadFromGlobalSettings(); 0092 KMailSettings::self()->useDefaults(bUseDefaults); 0093 // reset other settings to default values 0094 doResetToDefaultsOther(); 0095 } 0096 0097 void ConfigModuleTab::slotEmitChanged() 0098 { 0099 if (mEmitChanges) { 0100 Q_EMIT changed(true); 0101 } 0102 } 0103 0104 #include "moc_configuredialog_p.cpp"