[gnome-games/wip/exalm/collection: 158/158] cover: Use Gdk.Pixbuf instead of GLib.Icon



commit 1f7cc3c51fdd012d597519ee3380681ef71d8585
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Jun 9 22:01:13 2019 +0500

    cover: Use Gdk.Pixbuf instead of GLib.Icon

 plugins/steam/src/steam-cover.vala | 27 ++++++++++++++++-----------
 src/core/cover.vala                |  2 +-
 src/dummy/dummy-cover.vala         |  2 +-
 src/grilo/grilo-cover.vala         | 21 ++++++++++-----------
 src/ui/game-thumbnail.vala         | 16 ++--------------
 src/utils/composite-cover.vala     |  2 +-
 src/utils/local-cover.vala         | 16 ++++++++++------
 7 files changed, 41 insertions(+), 45 deletions(-)
---
diff --git a/plugins/steam/src/steam-cover.vala b/plugins/steam/src/steam-cover.vala
index 517db2a8..f897a4a4 100644
--- a/plugins/steam/src/steam-cover.vala
+++ b/plugins/steam/src/steam-cover.vala
@@ -2,7 +2,7 @@
 
 public class Games.SteamCover : Object, Cover {
        private string game_id;
-       private GLib.Icon icon;
+       private Gdk.Pixbuf? pixbuf;
        private bool resolving;
 
        public SteamCover (string game_id) {
@@ -10,16 +10,22 @@ public class Games.SteamCover : Object, Cover {
                resolving = false;
        }
 
-       public GLib.Icon? get_cover () {
+       public Gdk.Pixbuf? get_cover () {
                if (resolving)
-                       return icon;
+                       return pixbuf;
 
-               if (icon != null)
-                       return icon;
+               if (pixbuf != null)
+                       return pixbuf;
 
-               load_cover ();
-               if (icon != null)
-                       return icon;
+               try {
+                       load_cover ();
+               }
+               catch (Error e) {
+                       warning (e.message);
+               }
+
+               if (pixbuf != null)
+                       return pixbuf;
 
                resolving = true;
 
@@ -60,14 +66,13 @@ public class Games.SteamCover : Object, Cover {
                });
        }
 
-       private void load_cover () {
+       private void load_cover () throws Error {
                var cover_path = get_cover_path ();
 
                if (!FileUtils.test (cover_path, FileTest.EXISTS))
                        return;
 
-               var file = File.new_for_path (cover_path);
-               icon = new FileIcon (file);
+               pixbuf = new Gdk.Pixbuf.from_file (cover_path);
 
                changed ();
        }
diff --git a/src/core/cover.vala b/src/core/cover.vala
index b2434b05..7261d974 100644
--- a/src/core/cover.vala
+++ b/src/core/cover.vala
@@ -3,5 +3,5 @@
 public interface Games.Cover : Object {
        public signal void changed ();
 
-       public abstract GLib.Icon? get_cover ();
+       public abstract Gdk.Pixbuf? get_cover ();
 }
diff --git a/src/dummy/dummy-cover.vala b/src/dummy/dummy-cover.vala
index f8252b7f..1938bdc0 100644
--- a/src/dummy/dummy-cover.vala
+++ b/src/dummy/dummy-cover.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 public class Games.DummyCover : Object, Cover {
-       public GLib.Icon? get_cover () {
+       public Gdk.Pixbuf? get_cover () {
                return null;
        }
 }
diff --git a/src/grilo/grilo-cover.vala b/src/grilo/grilo-cover.vala
index 5736237e..3a511b52 100644
--- a/src/grilo/grilo-cover.vala
+++ b/src/grilo/grilo-cover.vala
@@ -3,7 +3,7 @@
 public class Games.GriloCover : Object, Cover {
        private GriloMedia media;
        private Uid uid;
-       private GLib.Icon icon;
+       private Gdk.Pixbuf pixbuf;
        private bool resolving;
        private string cover_path;
 
@@ -14,12 +14,12 @@ public class Games.GriloCover : Object, Cover {
                resolving = false;
        }
 
-       public GLib.Icon? get_cover () {
+       public Gdk.Pixbuf? get_cover () {
                if (resolving)
-                       return icon;
+                       return pixbuf;
 
-               if (icon != null)
-                       return icon;
+               if (pixbuf != null)
+                       return pixbuf;
 
                try {
                        load_cover ();
@@ -27,17 +27,17 @@ public class Games.GriloCover : Object, Cover {
                catch (Error e) {
                        warning (e.message);
 
-                       return icon;
+                       return pixbuf;
                }
 
-               if (icon != null)
-                       return icon;
+               if (pixbuf != null)
+                       return pixbuf;
 
                resolving = true;
 
                media.try_resolve_media ();
 
-               return icon;
+               return pixbuf;
        }
 
        private void on_media_resolved () {
@@ -106,8 +106,7 @@ public class Games.GriloCover : Object, Cover {
                if (!FileUtils.test (cover_path, FileTest.EXISTS))
                        return;
 
-               var file = File.new_for_path (cover_path);
-               icon = new FileIcon (file);
+               pixbuf = new Gdk.Pixbuf.from_file (cover_path);
 
                changed ();
        }
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 3e3db343..2d753c0c 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -222,21 +222,9 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
                if (cover_cache != null)
                        return cover_cache;
 
-               var g_icon = cover.get_cover ();
-               if (g_icon == null)
-                       return null;
-
-               var theme = Gtk.IconTheme.get_default ();
-               var lookup_flags = Gtk.IconLookupFlags.FORCE_SIZE | Gtk.IconLookupFlags.FORCE_REGULAR;
-               var icon_info = theme.lookup_by_gicon (g_icon, (int) size, lookup_flags);
+               cover_cache = cover.get_cover ();
 
-               try {
-                       cover_cache = icon_info.load_icon ();
-                       save_cover_cache_to_disk (size);
-               }
-               catch (Error e) {
-                       warning (@"Couldn’t load the icon: $(e.message)\n");
-               }
+               save_cover_cache_to_disk (size);
 
                return cover_cache;
        }
diff --git a/src/utils/composite-cover.vala b/src/utils/composite-cover.vala
index 3cca1c8a..a3e2a045 100644
--- a/src/utils/composite-cover.vala
+++ b/src/utils/composite-cover.vala
@@ -9,7 +9,7 @@ public class Games.CompositeCover : Object, Cover {
                        cover.changed.connect (on_cover_changed);
        }
 
-       public GLib.Icon? get_cover () {
+       public Gdk.Pixbuf? get_cover () {
                foreach (var cover in covers) {
                        var result_cover = cover.get_cover ();
                        if (result_cover != null)
diff --git a/src/utils/local-cover.vala b/src/utils/local-cover.vala
index 1190be58..02407f21 100644
--- a/src/utils/local-cover.vala
+++ b/src/utils/local-cover.vala
@@ -3,15 +3,15 @@
 public class Games.LocalCover : Object, Cover {
        private Uri uri;
        private bool resolved;
-       private GLib.Icon? icon;
+       private Gdk.Pixbuf? pixbuf;
 
        public LocalCover (Uri uri) {
                this.uri = uri;
        }
 
-       public GLib.Icon? get_cover () {
+       public Gdk.Pixbuf? get_cover () {
                if (resolved)
-                       return icon;
+                       return pixbuf;
 
                resolved = true;
 
@@ -28,10 +28,14 @@ public class Games.LocalCover : Object, Cover {
                if (cover_path == null)
                        return null;
 
-               var file = File.new_for_path (cover_path);
-               icon = new FileIcon (file);
+               try {
+                       pixbuf = new Gdk.Pixbuf.from_file (cover_path);
+               }
+               catch (Error e) {
+                       warning (e.message);
+               }
 
-               return icon;
+               return pixbuf;
        }
 
        private string? get_cover_path () throws Error {


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