1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
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"
23 #include "buffersettings.h"
24 #include "chatviewsettings.h"
26 #include "qtuisettings.h"
30 #include <QStyleFactory>
32 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
33 : SettingsPage(tr("Appearance"), tr("General"), parent) {
36 initLanguageComboBox();
38 foreach(QComboBox *comboBox, findChildren<QComboBox *>()) {
39 connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
41 foreach(QCheckBox *checkBox, findChildren<QCheckBox *>()) {
42 connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
46 void AppearanceSettingsPage::initStyleComboBox() {
47 QStringList styleList = QStyleFactory::keys();
48 ui.styleComboBox->addItem(tr("<System Default>"));
49 foreach(QString style, styleList) {
50 ui.styleComboBox->addItem(style);
54 void AppearanceSettingsPage::initLanguageComboBox() {
55 QDir i18nDir(":/i18n", "quassel_*.qm");
57 foreach(QString translationFile, i18nDir.entryList()) {
58 QString localeName(translationFile.mid(8));
60 QLocale locale(localeName);
62 ui.languageComboBox->addItem(QLocale::languageToString(locale.language()));
67 void AppearanceSettingsPage::defaults() {
68 ui.styleComboBox->setCurrentIndex(0);
73 void AppearanceSettingsPage::load() {
74 QtUiSettings uiSettings;
77 settings["Style"] = uiSettings.value("Style", QString(""));
78 if(settings["Style"].toString() == "") {
79 ui.styleComboBox->setCurrentIndex(0);
81 ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(settings["Style"].toString(), Qt::MatchExactly));
82 QApplication::setStyle(settings["Style"].toString());
86 QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
87 if(locale == QLocale::system())
88 ui.languageComboBox->setCurrentIndex(0);
89 else if(locale.language() == QLocale::C)
90 ui.languageComboBox->setCurrentIndex(1);
92 ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
93 Quassel::loadTranslation(selectedLocale());
95 ChatViewSettings chatViewSettings;
96 SettingsPage::load(ui.showWebPreview, chatViewSettings.showWebPreview());
98 BufferSettings bufferSettings;
99 SettingsPage::load(ui.showUserStateIcons, bufferSettings.showUserStateIcons());
101 setChangedState(false);
104 void AppearanceSettingsPage::save() {
105 QtUiSettings uiSettings;
107 if(ui.styleComboBox->currentIndex() < 1) {
108 uiSettings.setValue("Style", QString(""));
110 uiSettings.setValue("Style", ui.styleComboBox->currentText());
113 if(ui.languageComboBox->currentIndex() == 0) {
114 uiSettings.remove("Locale"); // force the default (QLocale::system())
116 uiSettings.setValue("Locale", selectedLocale());
119 ChatViewSettings chatViewSettings;
120 chatViewSettings.enableWebPreview(ui.showWebPreview->isChecked());
122 BufferSettings bufferSettings;
123 bufferSettings.enableUserStateIcons(ui.showUserStateIcons->isChecked());
126 setChangedState(false);
129 QLocale AppearanceSettingsPage::selectedLocale() const {
131 int index = ui.languageComboBox->currentIndex();
133 locale = QLocale::system();
135 locale = QLocale::c();
137 locale = _locales[index - 2];
142 void AppearanceSettingsPage::widgetHasChanged() {
143 setChangedState(testHasChanged());
146 bool AppearanceSettingsPage::testHasChanged() {
147 if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
148 if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())
150 if(SettingsPage::hasChanged(ui.showWebPreview)) return true;
151 if(SettingsPage::hasChanged(ui.showUserStateIcons)) return true;