File indexing completed on 2024-09-08 03:28:24
0001 /* 0002 This file is part of Kiten, a KDE Japanese Reference Tool... 0003 SPDX-FileCopyrightText: 2001 Jason Katz-Brown <jason@katzbrown.com> 0004 SPDX-FileCopyrightText: 2005 Paul Temple <paul.temple@gmx.net> 0005 SPDX-FileCopyrightText: 2006 Joseph Kerian <jkerian@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "configuredialog.h" 0011 0012 #include <KLocalizedString> 0013 0014 #include <QString> 0015 #include <QStringList> 0016 #include <QTabWidget> 0017 #include <QWidget> 0018 0019 #include "kitenconfig.h" 0020 0021 // Generated from UI files 0022 #include "ui_configfont.h" 0023 #include "ui_configsearching.h" 0024 0025 // Our template for managing individual dict type's settings 0026 #include "dictionarypreferencedialog.h" 0027 // The dictionary file selector widget 0028 #include "configdictionaryselector.h" 0029 // The sorting selection widget 0030 #include "configsortingpage.h" 0031 // To get the list of dictionary Types and to interface with dictType objects 0032 #include "dictionarymanager.h" 0033 0034 ConfigureDialog::ConfigureDialog(QWidget *parent, KitenConfigSkeleton *config) 0035 : KConfigDialog(parent, QStringLiteral("Settings"), config) 0036 { 0037 // TODO: Figure out why these pages are unmanaged... is this needed? 0038 addPage(makeDictionaryFileSelectionPage(nullptr, config), i18n("Dictionaries"), QStringLiteral("help-contents")); 0039 0040 QWidget *widget; 0041 widget = new QWidget(); 0042 Ui::ConfigSearching cs; 0043 cs.setupUi(widget); 0044 addPage(widget, i18n("Searching"), QStringLiteral("edit-find")); 0045 0046 widget = new QWidget(); 0047 Ui::ConfigFont cf; 0048 cf.setupUi(widget); 0049 addPage(widget, i18n("Font"), QStringLiteral("preferences-desktop-font")); 0050 0051 addPage(makeDictionaryPreferencesPage(nullptr, config), 0052 i18nc("@title:group the settings for the dictionary display", "Display"), 0053 QStringLiteral("format-indent-more")); 0054 addPage(makeSortingPage(nullptr, config), i18n("Results Sorting"), QStringLiteral("format-indent-more")); 0055 0056 setHelp(QString(), QStringLiteral("kiten")); 0057 0058 connect(this, &KConfigDialog::widgetModified, this, &ConfigureDialog::updateConfiguration); 0059 } 0060 0061 void ConfigureDialog::updateConfiguration() 0062 { 0063 Q_EMIT settingsChanged(QString()); 0064 } 0065 0066 QWidget *ConfigureDialog::makeDictionaryFileSelectionPage(QWidget *parent, KitenConfigSkeleton *config) 0067 { 0068 auto tabWidget = new QTabWidget(parent); 0069 tabWidget->setDocumentMode(true); 0070 0071 for (const QString &dict : config->dictionary_list()) { 0072 QWidget *newTab = new ConfigDictionarySelector(dict, tabWidget, config); 0073 if (newTab) { 0074 connect(newTab, SIGNAL(widgetChanged()), this, SIGNAL(widgetModified())); 0075 connect(this, SIGNAL(updateWidgetsSignal()), newTab, SLOT(updateWidgets())); 0076 connect(this, SIGNAL(updateWidgetsDefaultSignal()), newTab, SLOT(updateWidgetsDefault())); 0077 connect(this, SIGNAL(updateSettingsSignal()), newTab, SLOT(updateSettings())); 0078 tabWidget->addTab(newTab, dict); 0079 } 0080 } 0081 0082 return tabWidget; 0083 } 0084 0085 QWidget *ConfigureDialog::makeDictionaryPreferencesPage(QWidget *parent, KitenConfigSkeleton *config) 0086 { 0087 const QStringList dictTypes = DictionaryManager::listDictFileTypes(); 0088 const QMap<QString, DictionaryPreferenceDialog *> dialogList = DictionaryManager::generatePreferenceDialogs(config, parent); 0089 0090 auto tabWidget = new QTabWidget(parent); 0091 tabWidget->setDocumentMode(true); 0092 0093 for (DictionaryPreferenceDialog *dialog : dialogList) { 0094 connect(this, &ConfigureDialog::updateWidgetsSignal, dialog, &DictionaryPreferenceDialog::updateWidgets); 0095 connect(this, &ConfigureDialog::updateWidgetsDefaultSignal, dialog, &DictionaryPreferenceDialog::updateWidgetsDefault); 0096 connect(this, &ConfigureDialog::updateSettingsSignal, dialog, &DictionaryPreferenceDialog::updateSettings); 0097 0098 tabWidget->addTab(dialog, dialog->name()); 0099 } 0100 0101 return tabWidget; 0102 } 0103 0104 QWidget *ConfigureDialog::makeSortingPage(QWidget *parent, KitenConfigSkeleton *config) 0105 { 0106 auto newPage = new ConfigSortingPage(parent, config); 0107 0108 connect(newPage, &ConfigSortingPage::widgetChanged, this, &KConfigDialog::widgetModified); 0109 0110 connect(this, &ConfigureDialog::updateWidgetsSignal, newPage, &ConfigSortingPage::updateWidgets); 0111 connect(this, &ConfigureDialog::updateWidgetsDefaultSignal, newPage, &ConfigSortingPage::updateWidgetsDefault); 0112 connect(this, &ConfigureDialog::updateSettingsSignal, newPage, &ConfigSortingPage::updateSettings); 0113 0114 return newPage; 0115 } 0116 0117 void ConfigureDialog::updateWidgets() 0118 { 0119 Q_EMIT updateWidgetsSignal(); 0120 } 0121 0122 void ConfigureDialog::updateWidgetsDefault() 0123 { 0124 Q_EMIT updateWidgetsDefaultSignal(); 0125 } 0126 0127 void ConfigureDialog::updateSettings() 0128 { 0129 Q_EMIT updateSettingsSignal(); 0130 } 0131 0132 bool ConfigureDialog::isDefault() 0133 { 0134 return false; 0135 // Always show the defaults button.... perhaps make a workaround later 0136 } 0137 0138 #include "moc_configuredialog.cpp"