Skip to content

Commit

Permalink
Image cache changes
Browse files Browse the repository at this point in the history
Vertical game images support


Former-commit-id: a785155
  • Loading branch information
tkashkin committed Sep 28, 2019
1 parent 6de5317 commit 1b1de28
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 72 deletions.
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ option('runtime', type: 'string', value: '')
option('use_libunity', type: 'boolean', value: false)

option('use_overlayfs', type: 'boolean', value: true)

option('use_images_memcache', type: 'boolean', value: true)
17 changes: 9 additions & 8 deletions src/data/Game.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ namespace GameHub.Data

public string description { get; protected set; }

public string icon { get; set; }
public string image { get; set; }
public string? icon { get; set; }
public string? image { get; set; }
public string? image_vertical { get; set; }

public string? info { get; protected set; }
public string? info_detailed { get; protected set; }
Expand Down Expand Up @@ -455,11 +456,13 @@ namespace GameHub.Data
{
public const string BASE = "base";

public Game game { get; construct; }
public Game game { get; construct; }

public string id { get; construct; }
public string name { get; construct; }
public bool enabled { get; set; }
public string id { get; construct; }
public string name { get; construct; }
public bool enabled { get; set; }

public File? directory;

public bool removable
{
Expand All @@ -476,8 +479,6 @@ namespace GameHub.Data
}
}

public File? directory;

public Overlay(Game game, string id=BASE, string? name=null, bool enabled=true)
{
Object(game: game, id: id, name: name ?? (id == BASE ? game.name : id));
Expand Down
4 changes: 2 additions & 2 deletions src/data/Runnable.vala
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ namespace GameHub.Data
n.set_icon(new ThemedIcon("dialog-warning"));
if(game != null)
{
var icon = ImageCache.local_file(game.icon, "icon");
var icon = ImageCache.local_file(game.icon, @"games/$(game.source.id)/$(game.id)/icons/");
if(icon != null && icon.query_exists())
{
n.set_icon(new FileIcon(icon));
Expand Down Expand Up @@ -617,7 +617,7 @@ namespace GameHub.Data
n.set_icon(new ThemedIcon("dialog-warning"));
if(game != null)
{
var icon = ImageCache.local_file(game.icon, "icon");
var icon = ImageCache.local_file(game.icon, @"games/$(game.source.id)/$(game.id)/icons/");
if(icon != null && icon.query_exists())
{
n.set_icon(new FileIcon(icon));
Expand Down
2 changes: 1 addition & 1 deletion src/data/db/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace GameHub.Data.DB
{
public class Database
{
public const int VERSION = 8;
public const int VERSION = 9;
public static Table[] TABLES;

public static Database instance;
Expand Down
12 changes: 10 additions & 2 deletions src/data/db/tables/Games.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace GameHub.Data.DB.Tables
public static Table.Field LAST_LAUNCH;
public static Table.Field PLAYTIME_SOURCE;
public static Table.Field PLAYTIME_TRACKED;
public static Table.Field IMAGE_VERTICAL;

public Games()
{
Expand All @@ -75,6 +76,7 @@ namespace GameHub.Data.DB.Tables
LAST_LAUNCH = f(14);
PLAYTIME_SOURCE = f(15);
PLAYTIME_TRACKED = f(16);
IMAGE_VERTICAL = f(17);
}

public override void migrate(Sqlite.Database db, int version)
Expand Down Expand Up @@ -113,6 +115,10 @@ namespace GameHub.Data.DB.Tables
db.exec("ALTER TABLE `games` ADD `playtime_source` integer not null default 0");
db.exec("ALTER TABLE `games` ADD `playtime_tracked` integer not null default 0");
break;

case 8:
db.exec("ALTER TABLE `games` ADD `image_vertical` string");
break;
}
}
}
Expand Down Expand Up @@ -150,8 +156,9 @@ namespace GameHub.Data.DB.Tables
`arguments`,
`last_launch`,
`playtime_source`,
`playtime_tracked`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", -1, out s);
`playtime_tracked`,
`image_vertical`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", -1, out s);

if(res != Sqlite.OK)
{
Expand Down Expand Up @@ -190,6 +197,7 @@ namespace GameHub.Data.DB.Tables
LAST_LAUNCH.bind_int64(s, game.last_launch);
PLAYTIME_SOURCE.bind_int64(s, game.playtime_source);
PLAYTIME_TRACKED.bind_int64(s, game.playtime_tracked);
IMAGE_VERTICAL.bind(s, game.image_vertical);

res = s.step();

Expand Down
10 changes: 8 additions & 2 deletions src/data/db/tables/IGDBData.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ namespace GameHub.Data.DB.Tables

public static Table.Field GAME;
public static Table.Field DATA;
public static Table.Field INDEX;

public IGDBData()
{
instance = this;

GAME = f(0);
DATA = f(1);
GAME = f(0);
DATA = f(1);
INDEX = f(2);
}

public override void migrate(Sqlite.Database db, int version)
Expand All @@ -54,6 +56,10 @@ namespace GameHub.Data.DB.Tables
`data` string,
PRIMARY KEY(`game`))");
break;

case 8:
db.exec("ALTER TABLE `igdb_data` ADD `index` integer not null default 0");
break;
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/data/providers/images/SteamGridDB.vala
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,18 @@ namespace GameHub.Data.Providers.Images

public enum Style
{
ALTERNATE, BLURRED, MATERIAL, NO_LOGO;
ALTERNATE, BLURRED, MATERIAL, NO_LOGO, WHITE_LOGO;

public string name()
{
switch(this)
{
case Style.ALTERNATE: return C_("imagesource_steamgriddb_image_style", "Alternate");
case Style.BLURRED: return C_("imagesource_steamgriddb_image_style", "Blurred");
case Style.ALTERNATE: return C_("imagesource_steamgriddb_image_style", "Alternate");
case Style.BLURRED: return C_("imagesource_steamgriddb_image_style", "Blurred");
// TRANSLATORS: Flat / Material Design image style. Probably should not be translated
case Style.MATERIAL: return C_("imagesource_steamgriddb_image_style", "Material");
case Style.NO_LOGO: return C_("imagesource_steamgriddb_image_style", "No logo");
case Style.MATERIAL: return C_("imagesource_steamgriddb_image_style", "Material");
case Style.NO_LOGO: return C_("imagesource_steamgriddb_image_style", "No logo");
case Style.WHITE_LOGO: return C_("imagesource_steamgriddb_image_style", "White logo");
}
assert_not_reached();
}
Expand All @@ -192,10 +193,11 @@ namespace GameHub.Data.Providers.Images
{
switch(style)
{
case "alternate": return Style.ALTERNATE;
case "blurred": return Style.BLURRED;
case "material": return Style.MATERIAL;
case "no_logo": return Style.NO_LOGO;
case "alternate": return Style.ALTERNATE;
case "blurred": return Style.BLURRED;
case "material": return Style.MATERIAL;
case "no_logo": return Style.NO_LOGO;
case "white_logo": return Style.WHITE_LOGO;
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace GameHub.Data.Sources.GOG
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);
playtime_source = Tables.Games.PLAYTIME_SOURCE.get_int64(s);
playtime_tracked = Tables.Games.PLAYTIME_TRACKED.get_int64(s);
image_vertical = Tables.Games.IMAGE_VERTICAL.get(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down
3 changes: 2 additions & 1 deletion src/data/sources/humble/HumbleGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace GameHub.Data.Sources.Humble
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);
playtime_source = Tables.Games.PLAYTIME_SOURCE.get_int64(s);
playtime_tracked = Tables.Games.PLAYTIME_TRACKED.get_int64(s);
image_vertical = Tables.Games.IMAGE_VERTICAL.get(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down Expand Up @@ -334,7 +335,7 @@ namespace GameHub.Data.Sources.Humble
NotificationPriority.HIGH,
n => {
n.set_icon(new ThemedIcon("dialog-warning"));
var cached_icon = ImageCache.local_file(icon, "icon");
var cached_icon = ImageCache.local_file(icon, @"$(source.id)/$(id)/icons/");
if(cached_icon != null && cached_icon.query_exists())
{
n.set_icon(new FileIcon(cached_icon));
Expand Down
2 changes: 1 addition & 1 deletion src/data/sources/steam/Steam.vala
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ namespace GameHub.Data.Sources.Steam

if(game.image != null)
{
var cached = ImageCache.local_file(game.image, "image");
var cached = ImageCache.local_file(game.image, @"games/$(game.source.id)/$(game.id)/images/");
game_node.add_node(new BinaryVDF.StringNode.node("icon", cached.get_path()));
}

Expand Down
24 changes: 17 additions & 7 deletions src/data/sources/steam/SteamGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ namespace GameHub.Data.Sources.Steam

id = json_obj.get_int_member("appid").to_string();
name = json_obj.get_string_member("name");

var icon_hash = json_obj.get_string_member("img_icon_url");

icon = @"http://media.steampowered.com/steamcommunity/public/images/apps/$(id)/$(icon_hash).jpg";
image = @"http://cdn.akamai.steamstatic.com/steam/apps/$(id)/header.jpg";
image_vertical = @"http://cdn.akamai.steamstatic.com/steam/apps/$(id)/library_600x900_2x.jpg";

info = Json.to_string(json_node, false);

Expand All @@ -60,8 +63,6 @@ namespace GameHub.Data.Sources.Steam
name = Tables.Games.NAME.get(s);
info = Tables.Games.INFO.get(s);
info_detailed = Tables.Games.INFO_DETAILED.get(s);
icon = Tables.Games.ICON.get(s);
image = Tables.Games.IMAGE.get(s);
info = Tables.Games.INFO.get(s);
info_detailed = Tables.Games.INFO_DETAILED.get(s);
compat_tool = Tables.Games.COMPAT_TOOL.get(s);
Expand All @@ -71,6 +72,20 @@ namespace GameHub.Data.Sources.Steam
playtime_source = Tables.Games.PLAYTIME_SOURCE.get_int64(s);
playtime_tracked = Tables.Games.PLAYTIME_TRACKED.get_int64(s);

icon = Tables.Games.ICON.get(s);
image = Tables.Games.IMAGE.get(s);
image_vertical = Tables.Games.IMAGE_VERTICAL.get(s);

if(image == null || image == "")
{
image = @"http://cdn.akamai.steamstatic.com/steam/apps/$(id)/header.jpg";
}

if(image_vertical == null || image_vertical == "")
{
image_vertical = @"http://cdn.akamai.steamstatic.com/steam/apps/$(id)/library_600x900_2x.jpg";
}

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
foreach(var pl in pls)
Expand Down Expand Up @@ -111,11 +126,6 @@ namespace GameHub.Data.Sources.Steam

update_status();

if(image == null || image == "")
{
image = @"http://cdn.akamai.steamstatic.com/steam/apps/$(id)/header.jpg";
}

if((info != null && info.length > 0))
{
var i = Parser.parse_json(info).get_object();
Expand Down
1 change: 1 addition & 0 deletions src/data/sources/user/UserGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace GameHub.Data.Sources.User
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);
playtime_source = Tables.Games.PLAYTIME_SOURCE.get_int64(s);
playtime_tracked = Tables.Games.PLAYTIME_TRACKED.get_int64(s);
image_vertical = Tables.Games.IMAGE_VERTICAL.get(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down
5 changes: 3 additions & 2 deletions src/ui/dialogs/CompatRunDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ namespace GameHub.UI.Dialogs

content.add(opts_list);

if(game is Game && (game as Game).icon != null)
if(game is Game && ((Game) game).icon != null)
{
var g = (Game) game;
var icon = new AutoSizeImage();
icon.valign = Align.START;
icon.set_constraint(48, 48, 1);
icon.set_size_request(48, 48);
title_label.margin_start = 8;
compat_tool_picker.margin_start = 4;
icon.load((game as Game).icon, "icon");
icon.load(g.icon, null, @"$(g.source.id)/$(g.id)/icons/");
hbox.add(icon);
}

Expand Down
5 changes: 3 additions & 2 deletions src/ui/dialogs/CorruptedInstallerDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ namespace GameHub.UI.Dialogs
message_label.get_style_context().add_class("category-label");
content.add(message_label);

if(game is Game && (game as Game).icon != null)
if(game is Game && ((Game) game).icon != null)
{
var g = (Game) game;
var icon = new AutoSizeImage();
icon.valign = Align.START;
icon.set_constraint(48, 48, 1);
icon.set_size_request(48, 48);
icon.load((game as Game).icon, "icon");
icon.load(g.icon, null, @"$(g.source.id)/$(g.id)/icons/");
hbox.add(icon);
}

Expand Down
8 changes: 4 additions & 4 deletions src/ui/dialogs/GamePropertiesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ namespace GameHub.UI.Dialogs

properties_box.add(icon_entry);

image_view.load(game.image, "image");
icon_view.load(game.icon, "icon");
image_view.load(game.image, game.image_vertical, @"games/$(game.source.id)/$(game.id)/images/");
icon_view.load(game.icon, null, @"games/$(game.source.id)/$(game.id)/icons/");

var space = new Box(Orientation.VERTICAL, 0);
space.vexpand = true;
Expand Down Expand Up @@ -269,7 +269,7 @@ namespace GameHub.UI.Dialogs
}
else
{
image_view.load(url, "image");
image_view.load(url, null, @"games/$(game.source.id)/$(game.id)/images/");
}
}

Expand All @@ -283,7 +283,7 @@ namespace GameHub.UI.Dialogs
}
else
{
icon_view.load(url, "icon");
icon_view.load(url, null, @"games/$(game.source.id)/$(game.id)/icons/");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/InstallDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace GameHub.UI.Dialogs
icon.valign = Align.START;
icon.set_constraint(48, 48, 1);
icon.set_size_request(48, 48);
icon.load(game.icon, "icon");
icon.load(game.icon, null, @"games/$(game.source.id)/$(game.id)/icons/");
hbox.add(icon);
title_label.margin_start = title_label.margin_end = 8;
subtitle_label.margin_start = subtitle_label.margin_end = 8;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GameDetailsView/GameDetailsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ namespace GameHub.UI.Views.GameDetailsView
});
set_visible_widgets(game.status);

icon.load(game.icon, "icon");
icon.load(game.icon, null, @"games/$(game.source.id)/$(game.id)/icons/");
no_icon_indicator.visible = game.icon == null || icon.source == null;

if(content_scrolled.parent == stack)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GameDetailsView/blocks/Achievements.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace GameHub.UI.Views.GameDetailsView.Blocks
image.tooltip_markup += "\n" + """<span weight="600" size="smaller">%s</span>""".printf(_("Global percentage: %g%%").printf(achievement.global_percentage));
}

image.load(achievement.image, @"achievement_$(game.source.id)_$(game.id)");
image.load(achievement.image, null, @"games/$(game.source.id)/$(game.id)/achievements/$(achievement.id)/");
achievements_box.add(image);
}
achievements_box.show_all();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/GameDetailsView/blocks/Artwork.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ namespace GameHub.UI.Views.GameDetailsView.Blocks

var images_download_popover = new ImagesDownloadPopover(game, images_download_btn);

image_view.load(game.image, "image");
image_view.load(game.image, game.image_vertical, @"games/$(game.source.id)/$(game.id)/images/");
game.notify["image"].connect(() => {
image_view.load(game.image, "image");
image_view.load(game.image, game.image_vertical, @"games/$(game.source.id)/$(game.id)/images/");
});

Settings.UI.Appearance.instance.notify["grid-card-width"].connect(update_image_constraints);
Expand Down
Loading

0 comments on commit 1b1de28

Please sign in to comment.