summaryrefslogtreecommitdiff
path: root/src/images/icon.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-24 19:58:27 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-07-24 19:58:27 +0200
commit309d161f6d464fcea2de200bb3cb5a7cb784b6d3 (patch)
treea0d5ea02bfb3765191f2596aa8a7404f6b3a819c /src/images/icon.vala
parent45a3d7f0e2783d9898f017772583d31c1c9e0f03 (diff)
New upstream version 0.7.1upstream/0.7.1
Diffstat (limited to 'src/images/icon.vala')
-rw-r--r--src/images/icon.vala63
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 "";
}
}