qa: Avoid deprecation warnings for QList/QSet conversions
[quassel.git] / src / qtui / settingspages / appearancesettingspage.cpp
index 6bb0b26..55d2acf 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2016 by the Quassel Project                        *
+ *   Copyright (C) 2005-2019 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 
 #include "appearancesettingspage.h"
 
+#include <QCheckBox>
+#include <QDir>
+#include <QFile>
+#include <QFileDialog>
+#include <QStyleFactory>
+
 #include "buffersettings.h"
 #include "qtui.h"
 #include "qtuisettings.h"
 #include "qtuistyle.h"
 
-#include <QCheckBox>
-#include <QFileDialog>
-#include <QStyleFactory>
-#include <QFile>
-#include <QDir>
-
-AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
+AppearanceSettingsPage::AppearanceSettingsPage(QWidget* parent)
     : SettingsPage(tr("Interface"), QString(), parent)
 {
     ui.setupUi(this);
@@ -40,50 +40,55 @@ AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
     ui.useSystemTrayIcon->hide();
 #endif
 
+    // If no system icon theme is given, showing the override option makes no sense.
+    // Also don't mention a "fallback".
+    if (QtUi::instance()->systemIconTheme().isEmpty()) {
+        ui.iconThemeLabel->setText(tr("Icon theme:"));
+        ui.overrideSystemIconTheme->hide();
+    }
+
     initAutoWidgets();
     initStyleComboBox();
     initLanguageComboBox();
     initIconThemeComboBox();
 
-    foreach(QComboBox *comboBox, findChildren<QComboBox *>()) {
-        connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
+    foreach (QComboBox* comboBox, findChildren<QComboBox*>()) {
+        connect(comboBox, &QComboBox::currentTextChanged, this, &AppearanceSettingsPage::widgetHasChanged);
     }
-    foreach(QCheckBox *checkBox, findChildren<QCheckBox *>()) {
-        connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
+    foreach (QCheckBox* checkBox, findChildren<QCheckBox*>()) {
+        connect(checkBox, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
     }
 
-    connect(ui.chooseStyleSheet, SIGNAL(clicked()), SLOT(chooseStyleSheet()));
+    connect(ui.chooseStyleSheet, &QAbstractButton::clicked, this, &AppearanceSettingsPage::chooseStyleSheet);
 
-    connect(ui.userNoticesInDefaultBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.userNoticesInStatusBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.userNoticesInCurrentBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
+    connect(ui.userNoticesInDefaultBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
+    connect(ui.userNoticesInStatusBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
+    connect(ui.userNoticesInCurrentBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
 
-    connect(ui.serverNoticesInDefaultBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.serverNoticesInStatusBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.serverNoticesInCurrentBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
+    connect(ui.serverNoticesInDefaultBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
+    connect(ui.serverNoticesInStatusBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
+    connect(ui.serverNoticesInCurrentBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
 
-    connect(ui.errorMsgsInDefaultBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.errorMsgsInStatusBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-    connect(ui.errorMsgsInCurrentBuffer, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
+    connect(ui.errorMsgsInDefaultBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
+    connect(ui.errorMsgsInStatusBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
+    connect(ui.errorMsgsInCurrentBuffer, &QAbstractButton::clicked, this, &AppearanceSettingsPage::widgetHasChanged);
 }
 
-
 void AppearanceSettingsPage::initStyleComboBox()
 {
     QStringList styleList = QStyleFactory::keys();
     ui.styleComboBox->addItem(tr("<System Default>"));
-    foreach(QString style, styleList) {
+    foreach (QString style, styleList) {
         ui.styleComboBox->addItem(style);
     }
 }
 
-
 void AppearanceSettingsPage::initLanguageComboBox()
 {
     QDir i18nDir(Quassel::translationDirPath(), "*.qm");
 
     QRegExp rx("(qt_)?([a-zA-Z_]+)\\.qm");
-    foreach(QString translationFile, i18nDir.entryList()) {
+    foreach (QString translationFile, i18nDir.entryList()) {
         if (!rx.exactMatch(translationFile))
             continue;
         if (!rx.cap(1).isEmpty())
@@ -91,30 +96,20 @@ void AppearanceSettingsPage::initLanguageComboBox()
         QLocale locale(rx.cap(2));
         _locales[QLocale::languageToString(locale.language())] = locale;
     }
-    foreach(QString language, _locales.keys()) {
+    foreach (QString language, _locales.keys()) {
         ui.languageComboBox->addItem(language);
     }
 }
 
 void AppearanceSettingsPage::initIconThemeComboBox()
 {
-    // TODO Replace by runtime detection
-#if defined WITH_OXYGEN || defined WITH_BREEZE || defined WITH_BREEZE_DARK
-# if defined WITH_BREEZE
-    ui.iconthemeComboBox->addItem(tr("Breeze Light"), QVariant("breeze"));
-# endif
-# if defined WITH_BREEZE_DARK
-    ui.iconthemeComboBox->addItem(tr("Breeze Dark"), QVariant("breezedark"));
-# endif
-# if defined WITH_OXYGEN
-    ui.iconthemeComboBox->addItem(tr("Oxygen"), QVariant("oxygen"));
-# endif
-#else
-    ui.iconthemeLabel->hide();
-    ui.iconthemeComboBox->hide();
-#endif
-}
+    auto availableThemes = QtUi::instance()->availableIconThemes();
 
+    ui.iconThemeComboBox->addItem(tr("Automatic"), QString{});
+    for (auto&& p : QtUi::instance()->availableIconThemes()) {
+        ui.iconThemeComboBox->addItem(p.second, p.first);
+    }
+}
 
 void AppearanceSettingsPage::defaults()
 {
@@ -125,7 +120,6 @@ void AppearanceSettingsPage::defaults()
     widgetHasChanged();
 }
 
-
 void AppearanceSettingsPage::load()
 {
     QtUiSettings uiSettings;
@@ -144,7 +138,7 @@ void AppearanceSettingsPage::load()
     QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
     if (locale == QLocale::system())
         ui.languageComboBox->setCurrentIndex(1);
-    else if (locale.language() == QLocale::C) // we use C for "untranslated"
+    else if (locale.language() == QLocale::C)  // we use C for "untranslated"
         ui.languageComboBox->setCurrentIndex(0);
     else
         ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
@@ -152,12 +146,15 @@ void AppearanceSettingsPage::load()
     Quassel::loadTranslation(selectedLocale());
 
     // IconTheme
-    QString icontheme = uiSettings.value("IconTheme", QVariant("")).toString();
-    if (icontheme == "")
-        ui.iconthemeComboBox->setCurrentIndex(0);
-    else
-        ui.iconthemeComboBox->setCurrentIndex(ui.iconthemeComboBox->findData(icontheme));
-    ui.iconthemeComboBox->setProperty("storedValue", ui.iconthemeComboBox->currentIndex());
+    QString icontheme = UiStyleSettings{}.value("Icons/FallbackTheme", QString{}).toString();
+    if (icontheme.isEmpty()) {
+        ui.iconThemeComboBox->setCurrentIndex(0);
+    }
+    else {
+        auto idx = ui.iconThemeComboBox->findData(icontheme);
+        ui.iconThemeComboBox->setCurrentIndex(idx > 0 ? idx : 0);
+    }
+    ui.iconThemeComboBox->setProperty("storedValue", ui.iconThemeComboBox->currentIndex());
 
     // bufferSettings:
     BufferSettings bufferSettings;
@@ -180,10 +177,10 @@ void AppearanceSettingsPage::load()
     setChangedState(false);
 }
 
-
 void AppearanceSettingsPage::save()
 {
     QtUiSettings uiSettings;
+    UiStyleSettings styleSettings;
 
     if (ui.styleComboBox->currentIndex() < 1) {
         uiSettings.setValue("Style", QString(""));
@@ -195,25 +192,28 @@ void AppearanceSettingsPage::save()
     ui.styleComboBox->setProperty("storedValue", ui.styleComboBox->currentIndex());
 
     if (ui.languageComboBox->currentIndex() == 1) {
-        uiSettings.remove("Locale"); // force the default (QLocale::system())
+        uiSettings.remove("Locale");  // force the default (QLocale::system())
     }
     else {
         uiSettings.setValue("Locale", selectedLocale());
     }
     ui.languageComboBox->setProperty("storedValue", ui.languageComboBox->currentIndex());
 
-    if (selectedIconTheme()=="") {
-        uiSettings.remove("IconTheme");
+    bool needsIconThemeRefresh = ui.iconThemeComboBox->currentIndex() != ui.iconThemeComboBox->property("storedValue").toInt()
+                                 || ui.overrideSystemIconTheme->isChecked() != ui.overrideSystemIconTheme->property("storedValue").toBool();
+
+    auto iconTheme = selectedIconTheme();
+    if (iconTheme.isEmpty()) {
+        styleSettings.remove("Icons/FallbackTheme");
     }
     else {
-        uiSettings.setValue("IconTheme", selectedIconTheme());
-        QIcon::setThemeName(selectedIconTheme());
+        styleSettings.setValue("Icons/FallbackTheme", iconTheme);
     }
-    ui.iconthemeComboBox->setProperty("storedValue", ui.iconthemeComboBox->currentIndex());
+    ui.iconThemeComboBox->setProperty("storedValue", ui.iconThemeComboBox->currentIndex());
 
-    bool needsStyleReload =
-        ui.useCustomStyleSheet->isChecked() != ui.useCustomStyleSheet->property("storedValue").toBool()
-        || (ui.useCustomStyleSheet->isChecked() && ui.customStyleSheetPath->text() != ui.customStyleSheetPath->property("storedValue").toString());
+    bool needsStyleReload = ui.useCustomStyleSheet->isChecked() != ui.useCustomStyleSheet->property("storedValue").toBool()
+                            || (ui.useCustomStyleSheet->isChecked()
+                                && ui.customStyleSheetPath->text() != ui.customStyleSheetPath->property("storedValue").toString());
 
     BufferSettings bufferSettings;
     int redirectTarget = 0;
@@ -247,9 +247,10 @@ void AppearanceSettingsPage::save()
     setChangedState(false);
     if (needsStyleReload)
         QtUi::style()->reload();
+    if (needsIconThemeRefresh)
+        QtUi::instance()->refreshIconTheme();
 }
 
-
 QLocale AppearanceSettingsPage::selectedLocale() const
 {
     QLocale locale;
@@ -266,7 +267,7 @@ QLocale AppearanceSettingsPage::selectedLocale() const
 
 QString AppearanceSettingsPage::selectedIconTheme() const
 {
-    return ui.iconthemeComboBox->itemData(ui.iconthemeComboBox->currentIndex()).toString();
+    return ui.iconThemeComboBox->itemData(ui.iconThemeComboBox->currentIndex()).toString();
 }
 
 void AppearanceSettingsPage::chooseStyleSheet()
@@ -282,30 +283,40 @@ void AppearanceSettingsPage::chooseStyleSheet()
         ui.customStyleSheetPath->setText(name);
 }
 
-
 void AppearanceSettingsPage::widgetHasChanged()
 {
     setChangedState(testHasChanged());
 }
 
-
 bool AppearanceSettingsPage::testHasChanged()
 {
-    if (ui.styleComboBox->currentIndex() != ui.styleComboBox->property("storedValue").toInt()) return true;
-    if (ui.languageComboBox->currentIndex() != ui.languageComboBox->property("storedValue").toInt()) return true;
-    if (ui.iconthemeComboBox->currentIndex() != ui.iconthemeComboBox->property("storedValue").toInt()) return true;
-
-    if (SettingsPage::hasChanged(ui.userNoticesInStatusBuffer)) return true;
-    if (SettingsPage::hasChanged(ui.userNoticesInDefaultBuffer)) return true;
-    if (SettingsPage::hasChanged(ui.userNoticesInCurrentBuffer)) return true;
-
-    if (SettingsPage::hasChanged(ui.serverNoticesInStatusBuffer)) return true;
-    if (SettingsPage::hasChanged(ui.serverNoticesInDefaultBuffer)) return true;
-    if (SettingsPage::hasChanged(ui.serverNoticesInCurrentBuffer)) return true;
-
-    if (SettingsPage::hasChanged(ui.errorMsgsInStatusBuffer)) return true;
-    if (SettingsPage::hasChanged(ui.errorMsgsInDefaultBuffer)) return true;
-    if (SettingsPage::hasChanged(ui.errorMsgsInCurrentBuffer)) return true;
+    if (ui.styleComboBox->currentIndex() != ui.styleComboBox->property("storedValue").toInt())
+        return true;
+    if (ui.languageComboBox->currentIndex() != ui.languageComboBox->property("storedValue").toInt())
+        return true;
+    if (ui.iconThemeComboBox->currentIndex() != ui.iconThemeComboBox->property("storedValue").toInt())
+        return true;
+
+    if (SettingsPage::hasChanged(ui.userNoticesInStatusBuffer))
+        return true;
+    if (SettingsPage::hasChanged(ui.userNoticesInDefaultBuffer))
+        return true;
+    if (SettingsPage::hasChanged(ui.userNoticesInCurrentBuffer))
+        return true;
+
+    if (SettingsPage::hasChanged(ui.serverNoticesInStatusBuffer))
+        return true;
+    if (SettingsPage::hasChanged(ui.serverNoticesInDefaultBuffer))
+        return true;
+    if (SettingsPage::hasChanged(ui.serverNoticesInCurrentBuffer))
+        return true;
+
+    if (SettingsPage::hasChanged(ui.errorMsgsInStatusBuffer))
+        return true;
+    if (SettingsPage::hasChanged(ui.errorMsgsInDefaultBuffer))
+        return true;
+    if (SettingsPage::hasChanged(ui.errorMsgsInCurrentBuffer))
+        return true;
 
     return false;
 }