Commit 1f7cc3c5 authored by Alexander Mikhaylenko's avatar Alexander Mikhaylenko

cover: Use Gdk.Pixbuf instead of GLib.Icon

parent bc1555a6
Pipeline #105412 passed with stages
in 19 minutes and 44 seconds
......@@ -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 ();
}
......
......@@ -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 ();
}
// 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;
}
}
......@@ -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 ();
}
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment