[gnome-games] core: Replace Game 'icon' prop by get_icon() method
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] core: Replace Game 'icon' prop by get_icon() method
- Date: Wed, 11 May 2016 23:01:54 +0000 (UTC)
commit 4cf18a4caaa8123a63884d09ef94e0e001fb0f7c
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed May 11 17:48:14 2016 +0200
core: Replace Game 'icon' prop by get_icon() method
Make games able to return Games icon providers rather than naked GLib
icons.
Fixes # 289
plugins/desktop/src/desktop-game.vala | 8 +++---
plugins/love/src/love-game.vala | 22 +++++-----------
plugins/mame/src/mame-game.vala | 8 +++---
plugins/sega-saturn/src/sega-saturn-game.vala | 8 +++---
plugins/steam/src/steam-game.vala | 33 ++----------------------
src/core/game.vala | 2 +-
src/dummy/dummy-game.vala | 8 +++---
src/ui/game-icon-view.vala | 2 +-
src/ui/game-thumbnail.vala | 21 ++++++++-------
src/utils/generic-game.vala | 13 +++-------
10 files changed, 43 insertions(+), 82 deletions(-)
---
diff --git a/plugins/desktop/src/desktop-game.vala b/plugins/desktop/src/desktop-game.vala
index 47defa1..2ae4bb6 100644
--- a/plugins/desktop/src/desktop-game.vala
+++ b/plugins/desktop/src/desktop-game.vala
@@ -5,10 +5,6 @@ private class Games.DesktopGame: Object, Game {
get { return app_info.get_name (); }
}
- public GLib.Icon? icon {
- get { return app_info.get_icon (); }
- }
-
private DesktopAppInfo app_info;
public DesktopGame (string uri) {
@@ -18,6 +14,10 @@ private class Games.DesktopGame: Object, Game {
app_info = new DesktopAppInfo.from_filename (path);
}
+ public Icon get_icon () {
+ return new DesktopIcon (app_info);
+ }
+
public Runner get_runner () throws Error {
string[] args;
try {
diff --git a/plugins/love/src/love-game.vala b/plugins/love/src/love-game.vala
index 2e51f1d..6b3e833 100644
--- a/plugins/love/src/love-game.vala
+++ b/plugins/love/src/love-game.vala
@@ -6,22 +6,8 @@ private class Games.LoveGame : Object, Game {
get { return _name; }
}
- public GLib.Icon? icon {
- get { return love_icon; }
- }
-
- private static GLib.Icon? love_icon;
-
private string path;
-
- static construct {
- try {
- love_icon = GLib.Icon.new_for_string ("love");
- }
- catch (Error e) {
- warning ("%s\n", e.message);
- }
- }
+ private LoveIcon icon;
public LoveGame (string uri) throws Error {
var package = new LovePackage (uri);
@@ -40,6 +26,12 @@ private class Games.LoveGame : Object, Game {
name = name.split ("(")[0];
_name = name.strip ();
}
+
+ icon = new LoveIcon (package);
+ }
+
+ public Icon get_icon () {
+ return icon;
}
public Runner get_runner () throws Error {
diff --git a/plugins/mame/src/mame-game.vala b/plugins/mame/src/mame-game.vala
index 3552e40..1c3523d 100644
--- a/plugins/mame/src/mame-game.vala
+++ b/plugins/mame/src/mame-game.vala
@@ -22,10 +22,6 @@ private class Games.MameGame : Object, Game {
get { return _name; }
}
- public GLib.Icon? icon {
- get { return null; }
- }
-
private string uri;
public MameGame (string uri) throws Error {
@@ -45,6 +41,10 @@ private class Games.MameGame : Object, Game {
_name = _name.strip ();
}
+ public Icon get_icon () {
+ return new DummyIcon ();
+ }
+
public Runner get_runner () throws Error {
return new RetroRunner (MODULE_BASENAME, uri, uid, SUPPORTS_SNAPSHOTTING);
}
diff --git a/plugins/sega-saturn/src/sega-saturn-game.vala b/plugins/sega-saturn/src/sega-saturn-game.vala
index 80ecfd9..c9e575e 100644
--- a/plugins/sega-saturn/src/sega-saturn-game.vala
+++ b/plugins/sega-saturn/src/sega-saturn-game.vala
@@ -21,10 +21,6 @@ private class Games.SegaSaturnGame : Object, Game {
get { return _name; }
}
- public GLib.Icon? icon {
- get { return null; }
- }
-
private string uri;
private SegaSaturnHeader header;
@@ -43,6 +39,10 @@ private class Games.SegaSaturnGame : Object, Game {
_name = name.strip ();
}
+ public Icon get_icon () {
+ return new DummyIcon ();
+ }
+
public Runner get_runner () throws Error {
return new RetroRunner (MODULE_BASENAME, uri, uid, SUPPORTS_SNAPSHOTTING);
}
diff --git a/plugins/steam/src/steam-game.vala b/plugins/steam/src/steam-game.vala
index ef4e8eb..e8c1a46 100644
--- a/plugins/steam/src/steam-game.vala
+++ b/plugins/steam/src/steam-game.vala
@@ -1,29 +1,13 @@
// This file is part of GNOME Games. License: GPLv3
private class Games.SteamGame : Object, Game {
- private static GLib.Icon? steam_icon;
-
private string _name;
public string name {
get { return _name; }
}
- private GLib.Icon? _icon;
- public GLib.Icon? icon {
- get { return _icon != null ? _icon : steam_icon; }
- }
-
private string game_id;
- static construct {
- try {
- steam_icon = GLib.Icon.new_for_string ("steam");
- }
- catch (Error e) {
- warning ("%s\n", e.message);
- }
- }
-
public SteamGame (string appmanifest_path) throws Error {
var registry = new SteamRegistry (appmanifest_path);
game_id = registry.get_data ({"AppState", "appid"});
@@ -38,26 +22,15 @@ private class Games.SteamGame : Object, Game {
if (name == null)
throw new SteamGameError.NO_NAME (@"Couldn't get name from manifest
'$appmanifest_path'");
+ }
- try {
- var icon_name = "steam_icon_" + game_id;
- if (check_icon_exists (icon_name))
- _icon = GLib.Icon.new_for_string (icon_name);
- }
- catch (Error e) {
- warning ("%s\n", e.message);
- }
+ public Icon get_icon () {
+ return new SteamIcon (game_id);
}
public Runner get_runner () throws Error {
return new SteamRunner (game_id);
}
-
- private bool check_icon_exists (string icon_name) {
- var theme = Gtk.IconTheme.get_default ();
-
- return theme.has_icon (icon_name);
- }
}
errordomain Games.SteamGameError {
diff --git a/src/core/game.vala b/src/core/game.vala
index 156b1e4..1a0d895 100644
--- a/src/core/game.vala
+++ b/src/core/game.vala
@@ -2,7 +2,7 @@
public interface Games.Game : Object {
public abstract string name { get; }
- public abstract GLib.Icon? icon { get; }
+ public abstract Icon get_icon ();
public abstract Runner get_runner () throws Error;
}
diff --git a/src/dummy/dummy-game.vala b/src/dummy/dummy-game.vala
index 5df939e..009569c 100644
--- a/src/dummy/dummy-game.vala
+++ b/src/dummy/dummy-game.vala
@@ -6,10 +6,6 @@ private class Games.DummyGame : Object, Game {
get { return _name; }
}
- public GLib.Icon? icon {
- get { return null; }
- }
-
public DummyGame (string name) {
_name = name;
}
@@ -22,6 +18,10 @@ private class Games.DummyGame : Object, Game {
_name = name.strip ();
}
+ public Icon get_icon () {
+ return new DummyIcon ();
+ }
+
public Runner get_runner () throws Error {
return new DummyRunner ();
}
diff --git a/src/ui/game-icon-view.vala b/src/ui/game-icon-view.vala
index 6b6ec23..a2b3b90 100644
--- a/src/ui/game-icon-view.vala
+++ b/src/ui/game-icon-view.vala
@@ -11,7 +11,7 @@ private class Games.GameIconView : Gtk.Box {
_game = value;
- thumbnail.game = game;
+ thumbnail.icon = game.get_icon ();
title.label = game.name;
queue_draw ();
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 38894c2..ac7f534 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -12,14 +12,14 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
public int center_emblem_size { set; get; default = 16; }
public int secondary_emblem_size { set; get; default = 8; }
- private Game _game;
- public Game game {
- get { return _game; }
+ private Icon _icon;
+ public Icon icon {
+ get { return _icon; }
set {
- if (_game == value)
+ if (_icon == value)
return;
- _game = value;
+ _icon = value;
queue_draw ();
}
@@ -46,7 +46,7 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
cr, window, style, state, width, height
};
- if (game == null)
+ if (icon == null)
return false;
var drawn = false;
@@ -61,10 +61,11 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
}
public bool draw_icon (DrawingContext context) {
- if (game.icon == null)
+ var g_icon = icon.get_icon ();
+ if (g_icon == null)
return false;
- var pixbuf = get_scaled_icon (context, game.icon, ICON_SCALE);
+ var pixbuf = get_scaled_icon (context, g_icon, ICON_SCALE);
if (pixbuf == null)
return false;
@@ -112,13 +113,13 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
var theme = Gtk.IconTheme.get_default ();
var lookup_flags = Gtk.IconLookupFlags.FORCE_SIZE | Gtk.IconLookupFlags.FORCE_REGULAR;
var size = int.min (context.width, context.height) * scale;
- var icon_info = theme.lookup_by_gicon (game.icon, (int) size, lookup_flags);
+ var icon_info = theme.lookup_by_gicon (icon, (int) size, lookup_flags);
try {
return icon_info.load_icon ();
}
catch (Error e) {
- warning (@"Couldn't load the icon for '$(game.name): $(e.message)\n");
+ warning (@"Couldn't load the icon: $(e.message)\n");
return null;
}
}
diff --git a/src/utils/generic-game.vala b/src/utils/generic-game.vala
index 82a79da..43172db 100644
--- a/src/utils/generic-game.vala
+++ b/src/utils/generic-game.vala
@@ -18,15 +18,6 @@ public class Games.GenericGame : Object, Game {
}
}
- private GLib.Icon? _icon;
- public GLib.Icon? icon {
- get {
- _icon = game_cover.get_cover ();
-
- return _icon;
- }
- }
-
private Title game_title;
private Icon game_icon;
private Cover game_cover;
@@ -39,6 +30,10 @@ public class Games.GenericGame : Object, Game {
game_runner = runner;
}
+ public Icon get_icon () {
+ return game_icon;
+ }
+
public Runner get_runner () throws Error {
return game_runner;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]