diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-07-24 19:58:27 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-07-24 19:58:27 +0200 |
commit | 5ad5531baa3ab7729427caf821fde6a6856da34e (patch) | |
tree | 016644484b3c5814879a0e910394e9b064d2b2d2 /src/images/icon.vala | |
parent | 394ad3b32f9f79775bcac4c6cc2a4dfa74586800 (diff) | |
parent | 309d161f6d464fcea2de200bb3cb5a7cb784b6d3 (diff) |
Updated version 0.7.1 from 'upstream/0.7.1'
with Debian dir 55ec79e844cfb79babaf0535d64bfdb9bd5b22f7
Diffstat (limited to 'src/images/icon.vala')
-rw-r--r-- | src/images/icon.vala | 63 |
1 files changed, 23 insertions, 40 deletions
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 @@ -75,60 +75,43 @@ public class Icon : Image { } ///////////////////////////////////////////////////////////////////// - /// 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 ""; } } |