summaryrefslogtreecommitdiff
path: root/src/images
diff options
context:
space:
mode:
authorJörg Frings-Fürst <jff@merkur>2014-07-23 11:40:08 +0200
committerJörg Frings-Fürst <jff@merkur>2014-07-23 11:40:08 +0200
commit6edfb34cb3eee958e392a433ae9ac4f240279d09 (patch)
treed33f9e9032809dba2ccb1b8c9ccc928507c38cf6 /src/images
parent1f6f24308e96040962794c5a9ffd81597b5e072a (diff)
Imported Upstream version 0.5.5upstream/0.5.5
Diffstat (limited to 'src/images')
-rw-r--r--src/images/icon.vala25
-rw-r--r--src/images/image.vala10
2 files changed, 22 insertions, 13 deletions
diff --git a/src/images/icon.vala b/src/images/icon.vala
index 42be41f..6dfb53b 100644
--- a/src/images/icon.vala
+++ b/src/images/icon.vala
@@ -56,11 +56,11 @@ public class Icon : Image {
/////////////////////////////////////////////////////////////////////
public Icon(string icon_name, int size) {
- var cached = this.cache.get("%s@%u".printf(icon_name, size));
+ var cached = Icon.cache.get("%s@%u".printf(icon_name, size));
if (cached == null) {
- this.load_file_at_size(this.get_icon_file(icon_name, size), size, size);
- this.cache.set("%s@%u".printf(icon_name, size), this.surface);
+ this.load_file_at_size(Icon.get_icon_file(icon_name, size), size, size);
+ Icon.cache.set("%s@%u".printf(icon_name, size), this.surface);
} else {
this.surface = cached;
}
@@ -105,7 +105,6 @@ public class Icon : Image {
return icon_name;
warning("Icon \"" + icon_name + "\" not found! Using default icon...");
- icon_name = "stock_unknown";
}
@@ -115,14 +114,20 @@ public class Icon : Image {
if (result == "") {
warning("Icon \"" + icon_name + "\" not found! Using default icon...");
- icon_name = "stock_unknown";
- file = icon_theme.lookup_icon(icon_name, size, 0);
- if (file != null) result = file.get_filename();
- }
- if (result == "")
- warning("Icon \"" + icon_name + "\" not found! Will be ugly...");
+ 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 (result == "")
+ warning("No default icon found! Will be ugly...");
+ }
+
return result;
}
}
diff --git a/src/images/image.vala b/src/images/image.vala
index 1d9674b..197523b 100644
--- a/src/images/image.vala
+++ b/src/images/image.vala
@@ -134,6 +134,7 @@ public class Image : GLib.Object {
warning("Failed to load " + filename + "!");
this.surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height);
}
+
} catch (GLib.Error e) {
message("Error loading image file: %s", e.message);
this.surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height);
@@ -167,8 +168,11 @@ public class Image : GLib.Object {
/////////////////////////////////////////////////////////////////////
public Gdk.Pixbuf to_pixbuf() {
- var pixbuf = new Gdk.Pixbuf.from_data(surface.get_data(), Gdk.Colorspace.RGB, true, 8,
- width(), height(), surface.get_stride(), null);
+ if (this.surface == null || this.surface.get_data().length <= 0)
+ return new Gdk.Pixbuf(Gdk.Colorspace.RGB, true, 8, 1, 1);
+
+ var pixbuf = new Gdk.Pixbuf.from_data(this.surface.get_data(), Gdk.Colorspace.RGB, true, 8,
+ width(), height(), this.surface.get_stride(), null);
pixbuf = pixbuf.copy();
@@ -180,7 +184,7 @@ public class Image : GLib.Object {
*(p + i) = *(p + i + 2);
*(p + i + 2) = tmp;
}
-
+
return pixbuf;
}