Add basic support for system icons and custom icons
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
* Copyright 2013, Jonas Kvinge <jonas@strawbs.net>
|
* Copyright 2013, Jonas Kvinge <jonas@strawbs.net>
|
||||||
* This file was part of Clementine.
|
* This file was part of Clementine.
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
* 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
|
* Strawberry is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,28 +22,64 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QtDebug>
|
#include <QStandardPaths>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
#include "settings/appearancesettingspage.h"
|
||||||
#include "iconloader.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 IconLoader::Load(const QString &name, const int size) {
|
||||||
|
|
||||||
QIcon ret;
|
QIcon ret;
|
||||||
|
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
qLog(Error) << "Icon name is empty!";
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
QList<int> sizes;
|
QList<int> sizes;
|
||||||
sizes.clear();
|
sizes.clear();
|
||||||
if (size == 0) { sizes << 22 << 32 << 48 << 64; }
|
if (size == 0) { sizes << 22 << 32 << 48 << 64; }
|
||||||
else sizes << size;
|
else sizes << size;
|
||||||
|
|
||||||
if (name.isEmpty()) {
|
if (system_icons_) {
|
||||||
qLog(Error) << "Icon name is empty!";
|
ret = QIcon::fromTheme(name);
|
||||||
return ret;
|
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");
|
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));
|
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;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
* Strawberry Music Player
|
* Strawberry Music Player
|
||||||
* This file was part of Clementine.
|
* This file was part of Clementine.
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
* 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
|
* Strawberry is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,10 +28,12 @@
|
|||||||
|
|
||||||
class IconLoader {
|
class IconLoader {
|
||||||
public:
|
public:
|
||||||
|
static void Init();
|
||||||
static QIcon Load(const QString &name, const int size = 0);
|
static QIcon Load(const QString &name, const int size = 0);
|
||||||
private:
|
private:
|
||||||
IconLoader() {}
|
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);
|
QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
IconLoader::Init();
|
||||||
|
|
||||||
#ifdef HAVE_TRANSLATIONS
|
#ifdef HAVE_TRANSLATIONS
|
||||||
QString override_language = options.language();
|
QString override_language = options.language();
|
||||||
if (override_language.isEmpty()) {
|
if (override_language.isEmpty()) {
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ void AppearanceSettingsPage::Load() {
|
|||||||
ui_->background_image_filename->setText(playlist_view_background_image_filename_);
|
ui_->background_image_filename->setText(playlist_view_background_image_filename_);
|
||||||
ui_->blur_slider->setValue(s.value("blur_radius", PlaylistView::kDefaultBlurRadius).toInt());
|
ui_->blur_slider->setValue(s.value("blur_radius", PlaylistView::kDefaultBlurRadius).toInt());
|
||||||
ui_->opacity_slider->setValue(s.value("opacity_level", PlaylistView::kDefaultOpacityLevel).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();
|
s.endGroup();
|
||||||
|
|
||||||
@@ -161,6 +162,7 @@ void AppearanceSettingsPage::Save() {
|
|||||||
s.setValue(PlaylistView::kSettingBackgroundImageType, playlist_view_background_image_type_);
|
s.setValue(PlaylistView::kSettingBackgroundImageType, playlist_view_background_image_type_);
|
||||||
s.setValue("blur_radius", ui_->blur_slider->value());
|
s.setValue("blur_radius", ui_->blur_slider->value());
|
||||||
s.setValue("opacity_level", ui_->opacity_slider->value());
|
s.setValue("opacity_level", ui_->opacity_slider->value());
|
||||||
|
s.setValue("system_icons", ui_->checkbox_system_icons->isChecked());
|
||||||
|
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
|
|||||||
@@ -222,6 +222,13 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkbox_system_icons">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use system theme icons</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
Reference in New Issue
Block a user