[gnome-games] love: Add LoveIcon



commit b80fa763c390f21d8b6c6e0ba5e9eec2a63778ec
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed May 11 19:11:42 2016 +0200

    love: Add LoveIcon
    
    This will be used in subsequent commits to represent LÖVE games icons.
    
    Fixes #290

 plugins/love/src/Makefile.am    |    1 +
 plugins/love/src/love-icon.vala |   52 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/plugins/love/src/Makefile.am b/plugins/love/src/Makefile.am
index dc6a346..bc6a9fd 100644
--- a/plugins/love/src/Makefile.am
+++ b/plugins/love/src/Makefile.am
@@ -8,6 +8,7 @@ libgames_love_plugin_la_DEPENDENCIES = \
 libgames_love_plugin_la_SOURCES = \
        love-error.vala \
        love-game.vala \
+       love-icon.vala \
        love-package.vala \
        love-plugin.vala \
        $(NULL)
diff --git a/plugins/love/src/love-icon.vala b/plugins/love/src/love-icon.vala
new file mode 100644
index 0000000..b7ae688
--- /dev/null
+++ b/plugins/love/src/love-icon.vala
@@ -0,0 +1,52 @@
+// This file is part of GNOME Games. License: GPLv3
+
+private class Games.LoveIcon : Object, Icon {
+       private static GLib.Icon? love_icon;
+
+       private LovePackage package;
+       private bool already_parsed;
+       private Gdk.Pixbuf pixbuf;
+
+       public LoveIcon (LovePackage package) {
+               this.package = package;
+               already_parsed = false;
+       }
+
+       static construct {
+               try {
+                       love_icon = GLib.Icon.new_for_string ("love");
+               }
+               catch (Error e) {
+                       warning ("%s\n", e.message);
+               }
+       }
+
+       public GLib.Icon? get_icon () {
+               if (pixbuf != null)
+                       return pixbuf;
+
+               if (already_parsed)
+                       return love_icon;
+
+               already_parsed = true;
+
+               var icon_path = package.get_config ("icon");
+               if (icon_path == null)
+                       return null;
+
+               var stream = package.get_file_input_stream (icon_path);
+               if (stream == null)
+                       return null;
+
+               try {
+                       pixbuf = new Gdk.Pixbuf.from_stream (stream);
+               }
+               catch (Error e) {
+                       warning (e.message);
+               }
+               if (pixbuf != null)
+                       return pixbuf;
+
+               return love_icon;
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]