[gnome-games] steam: Add SteamCover



commit 9e96435adbe47a87ae15dcd7ffff7da0e3d95fc3
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue May 24 15:41:14 2016 +0200

    steam: Add SteamCover
    
    Allow to download Steam games' header and use it as their cover.

 plugins/steam/src/Makefile.am            |    1 +
 plugins/steam/src/steam-cover.vala       |   70 ++++++++++++++++++++++++++++++
 plugins/steam/src/steam-game-source.vala |    2 +-
 src/ui/application.vala                  |    6 +-
 src/ui/game-thumbnail.vala               |   13 +++--
 5 files changed, 83 insertions(+), 9 deletions(-)
---
diff --git a/plugins/steam/src/Makefile.am b/plugins/steam/src/Makefile.am
index 3f916be..b4c9147 100644
--- a/plugins/steam/src/Makefile.am
+++ b/plugins/steam/src/Makefile.am
@@ -6,6 +6,7 @@ libgames_steam_plugin_la_DEPENDENCIES = \
        $(NULL)
 
 libgames_steam_plugin_la_SOURCES = \
+       steam-cover.vala \
        steam-error.vala \
        steam-game-source.vala \
        steam-icon.vala \
diff --git a/plugins/steam/src/steam-cover.vala b/plugins/steam/src/steam-cover.vala
new file mode 100644
index 0000000..91586f4
--- /dev/null
+++ b/plugins/steam/src/steam-cover.vala
@@ -0,0 +1,70 @@
+// This file is part of GNOME Games. License: GPLv3
+
+public class Games.SteamCover : Object, Cover {
+       private string game_id;
+       private GLib.Icon icon;
+       private bool resolving;
+
+       public SteamCover (string game_id) {
+               this.game_id = game_id;
+               resolving = false;
+       }
+
+       public GLib.Icon? get_cover () {
+               if (resolving)
+                       return icon;
+
+               if (icon != null)
+                       return icon;
+
+               load_cover ();
+               if (icon != null)
+                       return icon;
+
+               resolving = true;
+
+               var uri = @"http://cdn.akamai.steamstatic.com/steam/apps/$game_id/header.jpg";;
+               fetch_cover.begin (uri);
+
+               return null;
+       }
+
+       private string get_cover_path () {
+               var dir = Application.get_covers_dir ();
+
+               return @"$dir/steam-$game_id.jpg";
+       }
+
+       private async void fetch_cover (string uri) {
+               var dir = Application.get_covers_dir ();
+               Application.try_make_dir (dir);
+
+               var cover_path = get_cover_path ();
+
+               var src = File.new_for_uri (uri);
+               var dst = File.new_for_path (cover_path);
+
+               try {
+                       yield src.copy_async (dst, FileCopyFlags.OVERWRITE);
+               }
+               catch (Error e) {
+                       warning (e.message);
+
+                       return;
+               }
+
+               load_cover ();
+       }
+
+       private void load_cover () {
+               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);
+
+               changed ();
+       }
+}
diff --git a/plugins/steam/src/steam-game-source.vala b/plugins/steam/src/steam-game-source.vala
index 53a030e..0d7b0f7 100644
--- a/plugins/steam/src/steam-game-source.vala
+++ b/plugins/steam/src/steam-game-source.vala
@@ -91,7 +91,7 @@ private class Games.SteamGameSource : Object, GameSource {
 
                var title = new SteamTitle (registry);
                var icon = new SteamIcon (game_id);
-               var cover = new DummyCover ();
+               var cover = new SteamCover (game_id);
                string[] args = { "steam", @"steam://rungameid/" + game_id };
                var runner = new CommandRunner (args, false);
 
diff --git a/src/ui/application.vala b/src/ui/application.vala
index e5bf86f..7b99e86 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -2,7 +2,7 @@
 
 private extern const string VERSION;
 
-private class Games.Application : Gtk.Application {
+public class Games.Application : Gtk.Application {
        private ListStore collection;
 
        private Tracker.Sparql.Connection? _connection;
@@ -24,7 +24,7 @@ private class Games.Application : Gtk.Application {
 
        private ApplicationWindow window;
 
-       public Application () {
+       internal Application () {
                Object (application_id: "org.gnome.Games",
                        flags: ApplicationFlags.FLAGS_NONE);
        }
@@ -117,7 +117,7 @@ private class Games.Application : Gtk.Application {
                window.show ();
        }
 
-       public async void load_game_list () {
+       internal async void load_game_list () {
                GameSource[] sources = {};
 
                var register = PluginRegister.get_register ();
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 14c8fe4..64aacf7 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -6,11 +6,11 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
        private const Gtk.CornerType[] bottom_corners = { Gtk.CornerType.BOTTOM_LEFT, 
Gtk.CornerType.BOTTOM_RIGHT };
 
        private const double ICON_SCALE = 0.75;
-       private const double COVER_MARGIN = 3;
+       private const double COVER_MARGIN = 0;
        private const double FRAME_RADIUS = 2;
        private const int EMBLEM_PADDING = 8;
 
-       public int center_emblem_size { set; get; default = 16; }
+       public int center_emblem_size { set; get; default = 32; }
        public int secondary_emblem_size { set; get; default = 8; }
 
        private Icon _icon;
@@ -122,9 +122,12 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
                double offset_x = (context.width - width) / 2.0;
                double offset_y = (context.height - height) / 2.0;
 
-               context.style.render_background (context.cr, offset_x, offset_y, width, height);
+               context.cr.set_source_rgb (0, 0, 0);
+               rounded_rectangle (context.cr, 0.5, 0.5, context.width - 1, context.height - 1, FRAME_RADIUS);
+               context.cr.fill ();
                draw_pixbuf (context, pixbuf);
-               context.style.render_frame (context.cr, offset_x, offset_y, width, height);
+               draw_border (context);
+//             context.style.render_frame (context.cr, offset_x, offset_y, width, height);
 
                return true;
        }
@@ -211,7 +214,7 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
                Cairo.ImageSurface mask = new Cairo.ImageSurface (Cairo.Format.A8, context.width, 
context.height);
 
                Cairo.Context cr = new Cairo.Context (mask);
-               cr.set_source_rgb (0, 0, 0);
+               cr.set_source_rgba (0, 0, 0, 0.9);
                rounded_rectangle (cr, 0.5, 0.5, context.width - 1, context.height - 1, FRAME_RADIUS);
                cr.fill ();
 


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