Simpler iconloader::Load() logic (#5706)

This fixes a bug when clementine uses an icon from the system, even though it exists in it the *data* folder.

For example: the icons at the top of *playlistlistview.ui*, and at the top of *fileview.ui*
This commit is contained in:
Elias Lattash 2017-05-08 12:07:59 +01:00 committed by John Maguire
parent 61e6fc7815
commit f854bc5deb
1 changed files with 29 additions and 36 deletions

View File

@ -46,43 +46,7 @@ QIcon IconLoader::Load(const QString& name, const IconType& icontype) {
// Set the icon load location based on IConType
switch (icontype) {
case Base: case Provider:
break;
case Lastfm: case Other: {
// lastfm icons location
const QString custom_fm_other_icon_location = custom_icon_path_
+ icon_sub_path_.at(icontype);
if (QDir(custom_fm_other_icon_location).exists()) {
// Try to load icons from the custom icon location initially
const QString locate_file(
custom_fm_other_icon_location + "/" + name + ".png");
if (QFile::exists(locate_file)) ret.addFile(locate_file);
if (!ret.isNull()) return ret;
}
#if QT_VERSION >= 0x040600
// Then try to load it from the system theme
ret = QIcon::fromTheme(name);
if (!ret.isNull()) return ret;
#endif
// Otherwise use our fallback theme
const QString path_file(":" + icon_sub_path_.at(icontype)
+ "/" + name + ".png");
if (QFile::exists(path_file)) ret.addFile(path_file);
if (ret.isNull()) qLog(Warning) << "Couldn't load icon" << name;
return ret;
}
default:
// Should never be reached
qLog(Warning) << "Couldn't recognize IconType" << name;
return ret;
}
case Base: case Provider: {
const QString custom_icon_location = custom_icon_path_
+ icon_sub_path_.at(icontype);
if (QDir(custom_icon_location).exists()) {
@ -97,12 +61,6 @@ QIcon IconLoader::Load(const QString& name, const IconType& icontype) {
if (!ret.isNull()) return ret;
}
#if QT_VERSION >= 0x040600
// Then try to load it from the system theme
ret = QIcon::fromTheme(name);
if (!ret.isNull()) return ret;
#endif
// Otherwise use our fallback theme
const QString path(":" + icon_sub_path_.at(icontype) + "/%1x%2/%3.png");
for (int size : sizes_) {
@ -110,7 +68,42 @@ QIcon IconLoader::Load(const QString& name, const IconType& icontype) {
if (QFile::exists(filename)) ret.addFile(filename, QSize(size, size));
}
}
case Lastfm: case Other: {
// lastfm icons location
const QString custom_fm_other_icon_location = custom_icon_path_
+ icon_sub_path_.at(icontype);
if (QDir(custom_fm_other_icon_location).exists()) {
// Try to load icons from the custom icon location initially
const QString locate_file(
custom_fm_other_icon_location + "/" + name + ".png");
if (QFile::exists(locate_file)) ret.addFile(locate_file);
if (!ret.isNull()) return ret;
}
// Otherwise use our fallback theme
const QString path_file(":" + icon_sub_path_.at(icontype)
+ "/" + name + ".png");
if (QFile::exists(path_file)) ret.addFile(path_file);
if (ret.isNull()) qLog(Warning) << "Couldn't load icon" << name;
}
default:
// Should never be reached
qLog(Warning) << "Couldn't recognize IconType" << name;
}
// Load icon from system theme only if it hasn't been found
if (ret.isNull()) {
#if QT_VERSION >= 0x040600
ret = QIcon::fromTheme(name);
if (!ret.isNull()) return ret;
#endif
}
else qLog(Warning) << "Couldn't load icon" << name;
return ret;
}