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)
37 initLanguageComboBox();
40 ui.showWebPreview->hide();
41 ui.showWebPreview->setEnabled(false);
44 foreach(QComboBox *comboBox, findChildren<QComboBox *>()) {
45 connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
47 foreach(QCheckBox *checkBox, findChildren<QCheckBox *>()) {
48 connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
52 void AppearanceSettingsPage::initStyleComboBox() {
53 QStringList styleList = QStyleFactory::keys();
54 ui.styleComboBox->addItem(tr("<System Default>"));
55 foreach(QString style, styleList) {
56 ui.styleComboBox->addItem(style);
60 void AppearanceSettingsPage::initLanguageComboBox() {
61 QDir i18nDir(Quassel::translationDirPath(), "quassel_*.qm");
63 foreach(QString translationFile, i18nDir.entryList()) {
64 QString localeName(translationFile.mid(8));
66 QLocale locale(localeName);
68 ui.languageComboBox->addItem(QLocale::languageToString(locale.language()));
73 void AppearanceSettingsPage::defaults() {
74 ui.styleComboBox->setCurrentIndex(0);
79 void AppearanceSettingsPage::load() {
80 QtUiSettings uiSettings;
83 settings["Style"] = uiSettings.value("Style", QString(""));
84 if(settings["Style"].toString() == "") {
85 ui.styleComboBox->setCurrentIndex(0);
87 ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(settings["Style"].toString(), Qt::MatchExactly));
88 QApplication::setStyle(settings["Style"].toString());
92 QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
93 if(locale == QLocale::system())
94 ui.languageComboBox->setCurrentIndex(0);
95 else if(locale.language() == QLocale::C)
96 ui.languageComboBox->setCurrentIndex(1);
98 ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
99 Quassel::loadTranslation(selectedLocale());
101 ChatViewSettings chatViewSettings;
102 SettingsPage::load(ui.showWebPreview, chatViewSettings.showWebPreview());
104 BufferSettings bufferSettings;
105 SettingsPage::load(ui.showUserStateIcons, bufferSettings.showUserStateIcons());
107 setChangedState(false);
110 void AppearanceSettingsPage::save() {
111 QtUiSettings uiSettings;
113 if(ui.styleComboBox->currentIndex() < 1) {
114 uiSettings.setValue("Style", QString(""));
116 uiSettings.setValue("Style", ui.styleComboBox->currentText());
119 if(ui.languageComboBox->currentIndex() == 0) {
120 uiSettings.remove("Locale"); // force the default (QLocale::system())
122 uiSettings.setValue("Locale", selectedLocale());
125 ChatViewSettings chatViewSettings;
126 chatViewSettings.enableWebPreview(ui.showWebPreview->isChecked());
128 BufferSettings bufferSettings;
129 bufferSettings.enableUserStateIcons(ui.showUserStateIcons->isChecked());
132 setChangedState(false);
135 QLocale AppearanceSettingsPage::selectedLocale() const {
137 int index = ui.languageComboBox->currentIndex();
139 locale = QLocale::system();
141 locale = QLocale::c();
143 locale = _locales[index - 2];
148 void AppearanceSettingsPage::widgetHasChanged() {
149 setChangedState(testHasChanged());
152 bool AppearanceSettingsPage::testHasChanged() {
153 if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
154 if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())
156 if(SettingsPage::hasChanged(ui.showWebPreview)) return true;
157 if(SettingsPage::hasChanged(ui.showUserStateIcons)) return true;