1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
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. *
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. *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "appearancesettingspage.h"
24 #include "qtuisettings.h"
28 #include <QStyleFactory>
30 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
31 : SettingsPage(tr("Appearance"), tr("General"), parent) {
34 initLanguageComboBox();
36 connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
37 connect(ui.languageComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
40 void AppearanceSettingsPage::initStyleComboBox() {
41 QStringList styleList = QStyleFactory::keys();
42 ui.styleComboBox->addItem(tr("<System Default>"));
43 foreach(QString style, styleList) {
44 ui.styleComboBox->addItem(style);
48 void AppearanceSettingsPage::initLanguageComboBox() {
49 QDir i18nDir(":/i18n", "quassel_*.qm");
51 foreach(QString translationFile, i18nDir.entryList()) {
52 QString localeName(translationFile.mid(8));
54 QLocale locale(localeName);
56 ui.languageComboBox->addItem(QLocale::languageToString(locale.language()));
61 void AppearanceSettingsPage::defaults() {
62 ui.styleComboBox->setCurrentIndex(0);
67 void AppearanceSettingsPage::load() {
68 QtUiSettings uiSettings;
70 settings["Style"] = uiSettings.value("Style", QString(""));
71 if(settings["Style"].toString() == "") {
72 ui.styleComboBox->setCurrentIndex(0);
74 ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(settings["Style"].toString(), Qt::MatchExactly));
75 QApplication::setStyle(settings["Style"].toString());
78 QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
79 if(locale == QLocale::system())
80 ui.languageComboBox->setCurrentIndex(0);
81 else if(locale.language() == QLocale::C)
82 ui.languageComboBox->setCurrentIndex(1);
84 ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
85 loadTranslation(selectedLocale());
87 setChangedState(false);
90 void AppearanceSettingsPage::save() {
91 QtUiSettings uiSettings;
93 if(ui.styleComboBox->currentIndex() < 1) {
94 uiSettings.setValue("Style", QString(""));
96 uiSettings.setValue("Style", ui.styleComboBox->currentText());
99 if(ui.languageComboBox->currentIndex() == 0) {
100 uiSettings.remove("Locale"); // force the default (QLocale::system())
102 uiSettings.setValue("Locale", selectedLocale());
106 setChangedState(false);
109 QLocale AppearanceSettingsPage::selectedLocale() const {
111 int index = ui.languageComboBox->currentIndex();
113 locale = QLocale::system();
115 locale = QLocale::c();
117 locale = _locales[index - 2];
122 void AppearanceSettingsPage::widgetHasChanged() {
123 setChangedState(testHasChanged());
126 bool AppearanceSettingsPage::testHasChanged() {
127 if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
128 if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())