sni: Prefer system icons over pixmap
This commit is contained in:
parent
fc9a390977
commit
f437bf96e3
|
@ -318,20 +318,42 @@ void Item::updateImage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Pixbuf> Item::getIconPixbuf() {
|
Glib::RefPtr<Gdk::Pixbuf> Item::getIconPixbuf() {
|
||||||
try {
|
|
||||||
if (icon_pixmap) {
|
if (!icon_name.empty()) {
|
||||||
return icon_pixmap;
|
|
||||||
}
|
try {
|
||||||
if (!icon_name.empty()) {
|
|
||||||
std::ifstream temp(icon_name);
|
std::ifstream temp(icon_name);
|
||||||
if (temp.is_open()) {
|
if (temp.is_open()) {
|
||||||
return Gdk::Pixbuf::create_from_file(icon_name);
|
return Gdk::Pixbuf::create_from_file(icon_name);
|
||||||
}
|
}
|
||||||
return getIconByName(icon_name, getScaledIconSize());
|
} catch (Glib::Error& e) {
|
||||||
|
// Ignore because we want to also try different methods of getting an icon.
|
||||||
|
//
|
||||||
|
// But a warning is logged, as the file apparently exists, but there was
|
||||||
|
// a failure in creating a pixbuf out of it.
|
||||||
|
|
||||||
|
spdlog::warn("Item '{}': {}", id, static_cast<std::string>(e.what()));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Will throw if it can not find an icon.
|
||||||
|
return getIconByName(icon_name, getScaledIconSize());
|
||||||
|
} catch (Glib::Error& e) {
|
||||||
|
spdlog::info("Item '{}': {}", id, static_cast<std::string>(e.what()));
|
||||||
}
|
}
|
||||||
} catch (Glib::Error& e) {
|
|
||||||
spdlog::error("Item '{}': {}", id, static_cast<std::string>(e.what()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the pixmap only if an icon for the given name could not be found.
|
||||||
|
if (icon_pixmap) {
|
||||||
|
return icon_pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (icon_name.empty()) {
|
||||||
|
spdlog::error("Item '{}': No icon name or pixmap given.", id, icon_name);
|
||||||
|
} else {
|
||||||
|
spdlog::error("Item '{}': Could not find an icon named '{}' and no pixmap given.", id, icon_name);
|
||||||
|
}
|
||||||
|
|
||||||
return getIconByName("image-missing", getScaledIconSize());
|
return getIconByName("image-missing", getScaledIconSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue