Commit 9e96435a authored by Adrien Plazas's avatar Adrien Plazas

steam: Add SteamCover

Allow to download Steam games' header and use it as their cover.
parent bf4426cf
......@@ -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 \
......
// 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 ();
}
}
......@@ -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);
......
......@@ -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 ();
......
......@@ -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 ();
......
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