diff --git a/src/core/iconloader.cpp b/src/core/iconloader.cpp index 3d8ce965..fa663f10 100644 --- a/src/core/iconloader.cpp +++ b/src/core/iconloader.cpp @@ -3,6 +3,7 @@ * Copyright 2013, Jonas Kvinge * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2017-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,28 +22,64 @@ #include "config.h" +#include #include #include #include #include #include -#include +#include +#include #include "core/logging.h" +#include "settings/appearancesettingspage.h" #include "iconloader.h" +bool IconLoader::system_icons_ = false; +bool IconLoader::custom_icons_ = false; + +void IconLoader::Init() { + + QSettings s; + s.beginGroup(AppearanceSettingsPage::kSettingsGroup); + system_icons_ = s.value("system_icons", false).toBool(); + s.endGroup(); + + QDir dir; + if (dir.exists(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/icons")) { + custom_icons_ = true; + } + +} + QIcon IconLoader::Load(const QString &name, const int size) { QIcon ret; + if (name.isEmpty()) { + qLog(Error) << "Icon name is empty!"; + return ret; + } + QList sizes; sizes.clear(); if (size == 0) { sizes << 22 << 32 << 48 << 64; } else sizes << size; - if (name.isEmpty()) { - qLog(Error) << "Icon name is empty!"; - return ret; + if (system_icons_) { + ret = QIcon::fromTheme(name); + if (!ret.isNull()) return ret; + qLog(Warning) << "Couldn't load icon" << name << "from system theme icons."; + } + + if (custom_icons_) { + QString custom_icon_path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/icons/%1x%2/%3.png"; + for (int s : sizes) { + QString filename(custom_icon_path.arg(s).arg(s).arg(name)); + if (QFile::exists(filename)) ret.addFile(filename, QSize(s, s)); + } + if (!ret.isNull()) return ret; + qLog(Warning) << "Couldn't load icon" << name << "from custom icons."; } const QString path(":/icons/%1x%2/%3.png"); @@ -51,13 +88,6 @@ QIcon IconLoader::Load(const QString &name, const int size) { if (QFile::exists(filename)) ret.addFile(filename, QSize(s, s)); } - // Load icon from system theme only if it hasn't been found - if (ret.isNull()) { - ret = QIcon::fromTheme(name); - if (!ret.isNull()) return ret; - qLog(Warning) << "Couldn't load icon" << name; - } - return ret; } diff --git a/src/core/iconloader.h b/src/core/iconloader.h index c1ad9f50..87bd680a 100644 --- a/src/core/iconloader.h +++ b/src/core/iconloader.h @@ -2,6 +2,7 @@ * Strawberry Music Player * This file was part of Clementine. * Copyright 2010, David Sansome + * Copyright 2017-2019, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,10 +28,12 @@ class IconLoader { public: + static void Init(); static QIcon Load(const QString &name, const int size = 0); -private: + private: IconLoader() {} + static bool system_icons_; + static bool custom_icons_; }; -#endif // ICONLOADER_H - +#endif // ICONLOADER_H diff --git a/src/main.cpp b/src/main.cpp index f8044f82..1fee07ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -223,6 +223,8 @@ int main(int argc, char* argv[]) { QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true); #endif + IconLoader::Init(); + #ifdef HAVE_TRANSLATIONS QString override_language = options.language(); if (override_language.isEmpty()) { diff --git a/src/settings/appearancesettingspage.cpp b/src/settings/appearancesettingspage.cpp index caa2c9a8..1eed999e 100644 --- a/src/settings/appearancesettingspage.cpp +++ b/src/settings/appearancesettingspage.cpp @@ -124,6 +124,7 @@ void AppearanceSettingsPage::Load() { ui_->background_image_filename->setText(playlist_view_background_image_filename_); ui_->blur_slider->setValue(s.value("blur_radius", PlaylistView::kDefaultBlurRadius).toInt()); ui_->opacity_slider->setValue(s.value("opacity_level", PlaylistView::kDefaultOpacityLevel).toInt()); + ui_->checkbox_system_icons->setChecked(s.value("system_icons", false).toBool()); s.endGroup(); @@ -161,6 +162,7 @@ void AppearanceSettingsPage::Save() { s.setValue(PlaylistView::kSettingBackgroundImageType, playlist_view_background_image_type_); s.setValue("blur_radius", ui_->blur_slider->value()); s.setValue("opacity_level", ui_->opacity_slider->value()); + s.setValue("system_icons", ui_->checkbox_system_icons->isChecked()); s.endGroup(); diff --git a/src/settings/appearancesettingspage.ui b/src/settings/appearancesettingspage.ui index d40a8435..6b29d9f3 100644 --- a/src/settings/appearancesettingspage.ui +++ b/src/settings/appearancesettingspage.ui @@ -222,6 +222,13 @@ + + + + Use system theme icons + + +