Add basic support for system icons and custom icons
This commit is contained in:
parent
d09af19d3f
commit
d575ab0b2b
@ -3,6 +3,7 @@
|
||||
* Copyright 2013, Jonas Kvinge <jonas@strawbs.net>
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2017-2019, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* 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 <QDir>
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QIcon>
|
||||
#include <QSize>
|
||||
#include <QtDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
|
||||
#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<int> 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;
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2017-2019, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* 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
|
||||
|
@ -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()) {
|
||||
|
@ -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();
|
||||
|
||||
|
@ -222,6 +222,13 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkbox_system_icons">
|
||||
<property name="text">
|
||||
<string>Use system theme icons</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
Loading…
x
Reference in New Issue
Block a user