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"
24 #include "qtuisettings.h"
25 #include "qtuistyle.h"
28 #include <QFileDialog>
29 #include <QStyleFactory>
31 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
32 : SettingsPage(tr("Interface"), QString(), parent)
37 initLanguageComboBox();
39 foreach(QComboBox *comboBox, findChildren<QComboBox *>()) {
40 connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
42 foreach(QCheckBox *checkBox, findChildren<QCheckBox *>()) {
43 connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
46 connect(ui.chooseStyleSheet, SIGNAL(clicked()), SLOT(chooseStyleSheet()));
49 void AppearanceSettingsPage::initStyleComboBox() {
50 QStringList styleList = QStyleFactory::keys();
51 ui.styleComboBox->addItem(tr("<System Default>"));
52 foreach(QString style, styleList) {
53 ui.styleComboBox->addItem(style);
57 void AppearanceSettingsPage::initLanguageComboBox() {
58 QDir i18nDir(Quassel::translationDirPath(), "quassel_*.qm");
60 foreach(QString translationFile, i18nDir.entryList()) {
61 QString localeName(translationFile.mid(8));
63 QLocale locale(localeName);
65 ui.languageComboBox->addItem(QLocale::languageToString(locale.language()));
69 void AppearanceSettingsPage::defaults() {
70 ui.styleComboBox->setCurrentIndex(0);
72 SettingsPage::defaults();
76 void AppearanceSettingsPage::load() {
77 QtUiSettings uiSettings;
80 QString style = uiSettings.value("Style", QString("")).toString();
82 ui.styleComboBox->setCurrentIndex(0);
84 ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(style, Qt::MatchExactly));
85 QApplication::setStyle(style);
87 ui.styleComboBox->setProperty("storedValue", ui.styleComboBox->currentIndex());
90 QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
91 if(locale == QLocale::system())
92 ui.languageComboBox->setCurrentIndex(0);
93 else if(locale.language() == QLocale::C)
94 ui.languageComboBox->setCurrentIndex(1);
96 ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
97 ui.languageComboBox->setProperty("storedValue", ui.languageComboBox->currentIndex());
98 Quassel::loadTranslation(selectedLocale());
100 SettingsPage::load();
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 bool needsStyleReload =
120 ui.useCustomStyleSheet->isChecked() != ui.useCustomStyleSheet->property("storedValue").toBool()
121 || (ui.useCustomStyleSheet->isChecked() && ui.customStyleSheetPath->text() != ui.customStyleSheetPath->property("storedValue").toString());
123 SettingsPage::save();
124 setChangedState(false);
126 QtUi::style()->reload();
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::chooseStyleSheet() {
143 QString name = QFileDialog::getOpenFileName(this, tr("Please choose a stylesheet file"), QString(), "*.qss");
145 ui.customStyleSheetPath->setText(name);
148 void AppearanceSettingsPage::widgetHasChanged() {
149 setChangedState(testHasChanged());
152 bool AppearanceSettingsPage::testHasChanged() {
153 if(ui.styleComboBox->currentIndex() != ui.styleComboBox->property("storedValue").toInt()) return true;
155 if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())