File indexing completed on 2024-12-01 04:36:38

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "configuresettingsdialog.h"
0008 #include "configureaccountwidget.h"
0009 #include "configurefontwidget.h"
0010 #include "configuregeneralwidget.h"
0011 #include "configurespellcheckingwidget.h"
0012 #include <KConfigGroup>
0013 #include <KLocalizedString>
0014 #include <KSharedConfig>
0015 #include <KWindowConfig>
0016 #include <QDialogButtonBox>
0017 #include <QIcon>
0018 #include <QPushButton>
0019 #include <QWindow>
0020 
0021 #include "config-ruqola.h"
0022 
0023 #if HAVE_TEXT_TRANSLATOR
0024 #include <TextTranslator/TranslatorConfigureListsWidget>
0025 #endif
0026 
0027 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0028 #include "configureautocorrectionwidget.h"
0029 #endif
0030 
0031 #if HAVE_TEXT_TO_SPEECH
0032 #include "configureaccessibilitywidget.h"
0033 #endif
0034 
0035 #if HAVE_KUSERFEEDBACK
0036 #include "configureuserfeedbackwidget.h"
0037 #endif
0038 
0039 namespace
0040 {
0041 const char myConfigGroupName[] = "ConfigureSettingsDialog";
0042 }
0043 ConfigureSettingsDialog::ConfigureSettingsDialog(QWidget *parent)
0044     : KPageDialog(parent)
0045     , mConfigureAccountWidget(new ConfigureAccountWidget(this))
0046     , mConfigureSpellCheckingWidget(new ConfigureSpellCheckingWidget(this))
0047     , mConfigureGeneralWidget(new ConfigureGeneralWidget(this))
0048     , mConfigureFontWidget(new ConfigureFontWidget(this))
0049 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0050     , mConfigureAutoCorrectionWidget(new ConfigureAutoCorrectionWidget(this))
0051 #endif
0052 #if HAVE_KUSERFEEDBACK
0053     , mConfigureUserFeedBackWidget(new ConfigureUserFeedbackWidget(this))
0054 #endif
0055 #if HAVE_TEXT_TRANSLATOR
0056     , mConfigureTranslateWidget(new TextTranslator::TranslatorConfigureListsWidget(this))
0057 #endif
0058 #if HAVE_TEXT_TO_SPEECH
0059     , mConfigureTextToSpeechWidget(new ConfigureAccessibilityWidget(this))
0060 #endif
0061 {
0062     setWindowTitle(i18nc("@title:window", "Configure Ruqola"));
0063     setFaceType(KPageDialog::List);
0064 
0065     buttonBox()->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0066 
0067     const QString generalPageName = i18nc("@title Preferences page name", "General");
0068     mConfigureGeneralWidgetPage = new KPageWidgetItem(mConfigureGeneralWidget, generalPageName);
0069     mConfigureGeneralWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("ruqola")));
0070     addPage(mConfigureGeneralWidgetPage);
0071 
0072     const QString accountPageName = i18nc("@title Preferences page name", "Account");
0073     mConfigureAccountWidgetPage = new KPageWidgetItem(mConfigureAccountWidget, accountPageName);
0074     mConfigureAccountWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("network-workgroup")));
0075     addPage(mConfigureAccountWidgetPage);
0076 
0077     const QString fontPageName = i18nc("@title Preferences page name", "Font");
0078     mConfigureFontWidgetPage = new KPageWidgetItem(mConfigureFontWidget, fontPageName);
0079     mConfigureFontWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-font")));
0080     addPage(mConfigureFontWidgetPage);
0081 
0082 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0083     const QString autoCorrectionPageName = i18nc("@title AutoCorrection page name", "AutoCorrection");
0084     mConfigureAutoCorrectionWidgetPage = new KPageWidgetItem(mConfigureAutoCorrectionWidget, autoCorrectionPageName);
0085     // TODO add icon mConfigureAutoCorrectionWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("font")));
0086     addPage(mConfigureAutoCorrectionWidgetPage);
0087 #endif
0088 
0089     const QString spellCheckingPageName = i18nc("@title Preferences page name", "Spell Checking");
0090     mConfigureSpellCheckingWidgetPage = new KPageWidgetItem(mConfigureSpellCheckingWidget, spellCheckingPageName);
0091     mConfigureSpellCheckingWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("tools-check-spelling")));
0092     addPage(mConfigureSpellCheckingWidgetPage);
0093 
0094 #if HAVE_TEXT_TRANSLATOR
0095     const QString translatePageName = i18nc("@title Preferences page name", "Translate");
0096     mConfigureTranslateWidgetPage = new KPageWidgetItem(mConfigureTranslateWidget, translatePageName);
0097     mConfigureTranslateWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("network-workgroup")));
0098     addPage(mConfigureTranslateWidgetPage);
0099 #endif
0100 
0101 #if HAVE_KUSERFEEDBACK
0102     const QString userFeedBackPageName = i18nc("@title Preferences page name", "User Feedback");
0103     mConfigureUserFeedBackWidgetPage = new KPageWidgetItem(mConfigureUserFeedBackWidget, userFeedBackPageName);
0104     mConfigureUserFeedBackWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("preferences-other")));
0105     addPage(mConfigureUserFeedBackWidgetPage);
0106 #endif
0107 
0108 #if HAVE_TEXT_TO_SPEECH
0109     const QString textToSpeechPageName = i18nc("@title Preferences page name", "Accessibility");
0110     mConfigureTextToSpeechWidgetPage = new KPageWidgetItem(mConfigureTextToSpeechWidget, textToSpeechPageName);
0111     mConfigureTextToSpeechWidgetPage->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-accessibility")));
0112     addPage(mConfigureTextToSpeechWidgetPage);
0113 #endif
0114 
0115     connect(buttonBox()->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &ConfigureSettingsDialog::slotAccepted);
0116     connect(buttonBox()->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &ConfigureSettingsDialog::reject);
0117     readConfig();
0118     load();
0119 }
0120 
0121 ConfigureSettingsDialog::~ConfigureSettingsDialog()
0122 {
0123     writeConfig();
0124 }
0125 
0126 void ConfigureSettingsDialog::readConfig()
0127 {
0128     create(); // ensure a window is created
0129     windowHandle()->resize(QSize(800, 600));
0130     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigGroupName));
0131     KWindowConfig::restoreWindowSize(windowHandle(), group);
0132     resize(windowHandle()->size()); // workaround for QTBUG-40584
0133 }
0134 
0135 void ConfigureSettingsDialog::writeConfig()
0136 {
0137     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myConfigGroupName));
0138     KWindowConfig::saveWindowSize(windowHandle(), group);
0139 }
0140 
0141 void ConfigureSettingsDialog::slotAccepted()
0142 {
0143     mConfigureAccountWidget->save();
0144     mConfigureSpellCheckingWidget->save();
0145 #if HAVE_KUSERFEEDBACK
0146     mConfigureUserFeedBackWidget->save();
0147 #endif
0148     mConfigureGeneralWidget->save();
0149     mConfigureFontWidget->save();
0150 #if HAVE_TEXT_TRANSLATOR
0151     mConfigureTranslateWidget->save();
0152 #endif
0153 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0154     mConfigureAutoCorrectionWidget->save();
0155 #endif
0156 #if HAVE_TEXT_TO_SPEECH
0157     mConfigureTextToSpeechWidget->save();
0158 #endif
0159 }
0160 
0161 void ConfigureSettingsDialog::load()
0162 {
0163     mConfigureAccountWidget->load();
0164     mConfigureSpellCheckingWidget->load();
0165 #if HAVE_KUSERFEEDBACK
0166     mConfigureUserFeedBackWidget->load();
0167 #endif
0168     mConfigureGeneralWidget->load();
0169     mConfigureFontWidget->load();
0170 #if HAVE_TEXT_TRANSLATOR
0171     mConfigureTranslateWidget->load();
0172 #endif
0173 #if HAVE_TEXT_AUTOCORRECTION_WIDGETS
0174     mConfigureAutoCorrectionWidget->load();
0175 #endif
0176 #if HAVE_TEXT_TO_SPEECH
0177     mConfigureTextToSpeechWidget->load();
0178 #endif
0179 }
0180 
0181 #include "moc_configuresettingsdialog.cpp"