1 /***************************************************************************
2 * Copyright (C) 2005 by Joshua Keel <joshuakeel@gmail.com> *
3 * (C) 2007-2014 by Jeremy Whiting <jpwhiting@kde.org> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20
21 #include "mainsettings.h"
22
23 #include <KConfig>
24 #include <KConfigDialog>
25 #include <KLocalizedString>
26 #include <KMessageBox>
27
28 #include <QPushButton>
29 #include <QStandardPaths>
30 #include <QLoggingCategory>
31
32 #include <sharedkvtmlfiles.h>
33 #include "kanagramsettings.h"
34 #include "kanagramgame.h"
35
Q_DECLARE_LOGGING_CATEGORY(KANAGRAM)36 Q_DECLARE_LOGGING_CATEGORY(KANAGRAM)
37
38 MainSettings::MainSettings(QWidget *parent) : QWidget(parent)
39 {
40 setupUi( this );
41
42 slotToggleAdvancedSettings();
43 populateLanguageBox();
44 connect(scoringPointCheckbox, &QCheckBox::toggled, this, &MainSettings::slotToggleAdvancedSettings);
45
46 //the language code/name
47 QLocale languageLocale(KanagramSettings::dataLanguage());
48
49 // select the current language
50 languageComboBox->setCurrentIndex(languageComboBox->findText(languageLocale.nativeLanguageName()));
51
52 // Connect after we set the current language from settings.
53 connect(languageComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainSettings::widgetModified);
54
55 #ifndef HAVE_SPEECH
56 kcfg_enablePronunciation->hide();
57 #endif
58 }
59
~MainSettings()60 MainSettings::~MainSettings()
61 {
62 }
63
slotToggleAdvancedSettings()64 void MainSettings::slotToggleAdvancedSettings()
65 {
66 bool enable = scoringPointCheckbox->isChecked();
67 textCorrectAnswer->setVisible(enable);
68 kcfg_correctAnswerScore->setVisible(enable);
69 textIncorrectAnswer->setVisible(enable);
70 kcfg_incorrectAnswerScore->setVisible(enable);
71 textRevealAnswer->setVisible(enable);
72 kcfg_revealAnswerScore->setVisible(enable);
73 textSkippedWord->setVisible(enable);
74 kcfg_skippedWordScore->setVisible(enable);
75 }
76
populateLanguageBox()77 void MainSettings::populateLanguageBox()
78 {
79 QStringList languages = SharedKvtmlFiles::languages();
80
81 //the language code/name
82 for (int i = 0; i < languages.count(); ++i)
83 {
84 QLocale languageLocale(languages[i]);
85
86 // get the language name
87 QString languageName = languageLocale.nativeLanguageName();
88 if (languageName.isEmpty() || languageName == QLatin1Char('C'))
89 {
90 languageName = i18nc("@item:inlistbox no language for that locale", "None");
91 }
92 languageComboBox->addItem(languageName, languages[i]);
93 }
94 }
95
saveLanguage()96 bool MainSettings::saveLanguage()
97 {
98 int index = languageComboBox->currentIndex();
99 QString language = languageComboBox->itemData(index).toString();
100 qCDebug(KANAGRAM) << "Writing new default language: " << language;
101 if (KanagramSettings::dataLanguage() != language) {
102 KanagramSettings::setDataLanguage(language);
103 KanagramSettings::self()->save();
104 return true;
105 }
106 return false;
107 }
108