From 309d161f6d464fcea2de200bb3cb5a7cb784b6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 24 Jul 2017 19:58:27 +0200 Subject: New upstream version 0.7.1 --- src/images/icon.vala | 63 +++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) (limited to 'src/images/icon.vala') diff --git a/src/images/icon.vala b/src/images/icon.vala index 176e187..7933e81 100644 --- a/src/images/icon.vala +++ b/src/images/icon.vala @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// Copyright (c) 2011-2016 by Simon Schneegans +// Copyright (c) 2011-2017 by Simon Schneegans // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -74,61 +74,44 @@ public class Icon : Image { return base.width(); } - ///////////////////////////////////////////////////////////////////// - /// Returns the icon name for a given GLib.Icon. - ///////////////////////////////////////////////////////////////////// - - public static string get_icon_name(GLib.Icon? icon) { - if (icon != null) { - var icon_names = icon.to_string().split(" "); - - foreach (var icon_name in icon_names) { - if (Gtk.IconTheme.get_default().has_icon(icon_name)) { - return icon_name; - } - } - } - - return ""; - } - ///////////////////////////////////////////////////////////////////// /// Returns the filename for a given system icon. ///////////////////////////////////////////////////////////////////// public static string get_icon_file(string icon_name, int size) { - string result = ""; - if (icon_name.contains("/")) { var file = GLib.File.new_for_path(icon_name); - if(file.query_exists()) + if(file.query_exists()) { return icon_name; - - warning("Icon \"" + icon_name + "\" not found! Using default icon..."); + } } - var icon_theme = Gtk.IconTheme.get_default(); var file = icon_theme.lookup_icon(icon_name, size, 0); - if (file != null) result = file.get_filename(); - - if (result == "") { - warning("Icon \"" + icon_name + "\" not found! Using default icon..."); - - string[] default_icons = {"application-default-icon", "stock_unknown"}; - foreach (var icon in default_icons) { - file = icon_theme.lookup_icon(icon, size, 0); - if (file != null) { - result = file.get_filename(); - break; - } + if (file != null) { + return file.get_filename(); + } + + try { + file = icon_theme.lookup_by_gicon(GLib.Icon.new_for_string(icon_name), size, 0); + if (file != null) { + return file.get_filename(); } + } catch(GLib.Error e) {} + + warning("Icon \"" + icon_name + "\" not found! Using default icon..."); - if (result == "") - warning("No default icon found! Will be ugly..."); + string[] default_icons = {"image-missing", "application-default-icon"}; + foreach (var icon in default_icons) { + file = icon_theme.lookup_icon(icon, size, 0); + if (file != null) { + return file.get_filename(); + } } - return result; + warning("No default icon found! Will be ugly..."); + + return ""; } } -- cgit v1.2.3