X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fappearancesettingspage.cpp;h=91e32a010cc0ebc8cf1c2b30ba63dcdd2fd1a078;hp=14c79240033d97e469fdd4346dc40711bfcda28a;hb=dcac65fc4beeb1167de8ebec5cc54608fc314fd3;hpb=109e990662d25b98e5d5a159c4cad7c93e56b2fe diff --git a/src/qtui/settingspages/appearancesettingspage.cpp b/src/qtui/settingspages/appearancesettingspage.cpp index 14c79240..91e32a01 100644 --- a/src/qtui/settingspages/appearancesettingspage.cpp +++ b/src/qtui/settingspages/appearancesettingspage.cpp @@ -1,18 +1,18 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Appearance Public License as published by * + * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Appearance Public License for more details. * + * GNU General Public License for more details. * * * - * You should have received a copy of the GNU Appearance Public License * + * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * @@ -20,29 +20,54 @@ #include "appearancesettingspage.h" +#include "buffersettings.h" +#include "chatviewsettings.h" #include "qtui.h" -#include "uisettings.h" +#include "qtuisettings.h" +#include "util.h" +#include #include AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent) - : SettingsPage(tr("Appearance"), tr("General"), parent) { + : SettingsPage(tr("Appearance"), QString(), parent) +{ ui.setupUi(this); initStyleComboBox(); + initLanguageComboBox(); - connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); +#ifndef HAVE_WEBKIT + ui.showWebPreview->hide(); + ui.showWebPreview->setEnabled(false); +#endif + + foreach(QComboBox *comboBox, findChildren()) { + connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); + } + foreach(QCheckBox *checkBox, findChildren()) { + connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); + } } void AppearanceSettingsPage::initStyleComboBox() { QStringList styleList = QStyleFactory::keys(); - ui.styleComboBox->addItem(""); + ui.styleComboBox->addItem(tr("")); foreach(QString style, styleList) { ui.styleComboBox->addItem(style); } } -bool AppearanceSettingsPage::hasDefaults() const { - return true; +void AppearanceSettingsPage::initLanguageComboBox() { + QDir i18nDir(Quassel::translationDirPath(), "quassel_*.qm"); + + foreach(QString translationFile, i18nDir.entryList()) { + QString localeName(translationFile.mid(8)); + localeName.chop(3); + QLocale locale(localeName); + _locales << locale; + ui.languageComboBox->addItem(QLocale::languageToString(locale.language())); + } + } void AppearanceSettingsPage::defaults() { @@ -52,8 +77,9 @@ void AppearanceSettingsPage::defaults() { } void AppearanceSettingsPage::load() { - UiSettings uiSettings; + QtUiSettings uiSettings; + // Gui Style settings["Style"] = uiSettings.value("Style", QString("")); if(settings["Style"].toString() == "") { ui.styleComboBox->setCurrentIndex(0); @@ -62,11 +88,27 @@ void AppearanceSettingsPage::load() { QApplication::setStyle(settings["Style"].toString()); } + // Language + QLocale locale = uiSettings.value("Locale", QLocale::system()).value(); + if(locale == QLocale::system()) + ui.languageComboBox->setCurrentIndex(0); + else if(locale.language() == QLocale::C) + ui.languageComboBox->setCurrentIndex(1); + else + ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly)); + Quassel::loadTranslation(selectedLocale()); + + ChatViewSettings chatViewSettings; + SettingsPage::load(ui.showWebPreview, chatViewSettings.showWebPreview()); + + BufferSettings bufferSettings; + SettingsPage::load(ui.showUserStateIcons, bufferSettings.showUserStateIcons()); + setChangedState(false); } void AppearanceSettingsPage::save() { - UiSettings uiSettings; + QtUiSettings uiSettings; if(ui.styleComboBox->currentIndex() < 1) { uiSettings.setValue("Style", QString("")); @@ -74,17 +116,45 @@ void AppearanceSettingsPage::save() { uiSettings.setValue("Style", ui.styleComboBox->currentText()); } + if(ui.languageComboBox->currentIndex() == 0) { + uiSettings.remove("Locale"); // force the default (QLocale::system()) + } else { + uiSettings.setValue("Locale", selectedLocale()); + } + + ChatViewSettings chatViewSettings; + chatViewSettings.enableWebPreview(ui.showWebPreview->isChecked()); + + BufferSettings bufferSettings; + bufferSettings.enableUserStateIcons(ui.showUserStateIcons->isChecked()); + load(); setChangedState(false); } +QLocale AppearanceSettingsPage::selectedLocale() const { + QLocale locale; + int index = ui.languageComboBox->currentIndex(); + if(index == 0) + locale = QLocale::system(); + else if(index == 1) + locale = QLocale::c(); + else if(index > 1) + locale = _locales[index - 2]; + + return locale; +} + void AppearanceSettingsPage::widgetHasChanged() { - bool changed = testHasChanged(); - if(changed != hasChanged()) setChangedState(changed); + setChangedState(testHasChanged()); } bool AppearanceSettingsPage::testHasChanged() { if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true; + if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation()) + + if(SettingsPage::hasChanged(ui.showWebPreview)) return true; + if(SettingsPage::hasChanged(ui.showUserStateIcons)) return true; return false; }