From 721a46c5b812908f4946ff13b5a27b2703179617 Mon Sep 17 00:00:00 2001
From: kramo <93832451+kra-mo@users.noreply.github.com>
Date: Fri, 30 Jun 2023 23:49:48 +0200
Subject: [PATCH] Finalize Flatpak source
---
data/gtk/preferences.blp | 20 ++++++++-
data/hu.kramo.Cartridges.gschema.xml.in | 8 +++-
src/importer/sources/flatpak_source.py | 21 +++++++++-
src/importer/sources/lutris_source.py | 6 ++-
src/preferences.py | 4 ++
src/store/managers/local_cover_manager.py | 51 ++++++++++++++++++-----
6 files changed, 94 insertions(+), 16 deletions(-)
diff --git a/data/gtk/preferences.blp b/data/gtk/preferences.blp
index 98c4341..6fc3da1 100644
--- a/data/gtk/preferences.blp
+++ b/data/gtk/preferences.blp
@@ -132,6 +132,15 @@ template $PreferencesWindow : Adw.PreferencesWindow {
valign: center;
}
}
+
+ Adw.ActionRow {
+ title: _("Import Flatpak Games");
+ activatable-widget: lutris_import_flatpak_switch;
+
+ Switch lutris_import_flatpak_switch {
+ valign: center;
+ }
+ }
}
Adw.ExpanderRow heroic_expander_row {
@@ -218,7 +227,7 @@ template $PreferencesWindow : Adw.PreferencesWindow {
}
Adw.ExpanderRow flatpak_expander_row {
- title: _("Flatpak Games");
+ title: _("Flatpak");
show-enable-switch: true;
Adw.ActionRow flatpak_data_action_row {
@@ -229,6 +238,15 @@ template $PreferencesWindow : Adw.PreferencesWindow {
valign: center;
}
}
+
+ Adw.ActionRow flatpak_import_launchers_row {
+ title: _("Import Game Launchers");
+ activatable-widget: flatpak_import_launchers_switch;
+
+ Switch flatpak_import_launchers_switch {
+ valign: center;
+ }
+ }
}
}
}
diff --git a/data/hu.kramo.Cartridges.gschema.xml.in b/data/hu.kramo.Cartridges.gschema.xml.in
index 507ceae..038a465 100644
--- a/data/hu.kramo.Cartridges.gschema.xml.in
+++ b/data/hu.kramo.Cartridges.gschema.xml.in
@@ -28,6 +28,9 @@
false
+
+ false
+
true
@@ -62,11 +65,14 @@
"~/.config/legendary/"
- false
+ true
"/var/lib/flatpak/exports"
+
+ false
+
""
diff --git a/src/importer/sources/flatpak_source.py b/src/importer/sources/flatpak_source.py
index 779caaf..0609dae 100644
--- a/src/importer/sources/flatpak_source.py
+++ b/src/importer/sources/flatpak_source.py
@@ -47,7 +47,24 @@ class FlatpakSourceIterator(SourceIterator):
check=True,
)
flatpak_ids = process.stdout.split("\n")
- flatpak_ids.remove("hu.kramo.Cartridges")
+
+ to_remove = (
+ {"hu.kramo.Cartridges"}
+ if shared.schema.get_boolean("flatpak-import-launchers")
+ else {
+ "hu.kramo.Cartridges",
+ "com.valvesoftware.Steam",
+ "net.lutris.Lutris",
+ "com.heroicgameslauncher.hgl",
+ "com.usebottles.Bottles",
+ "io.itch.itch",
+ }
+ )
+
+ for item in to_remove:
+ if item in flatpak_ids:
+ flatpak_ids.remove(item)
+
except subprocess.CalledProcessError:
return
@@ -88,7 +105,7 @@ class FlatpakSourceIterator(SourceIterator):
additional_data = {}
if icon_name := desktop_values["Icon"]:
if icon_path := IconTheme.getIconPath(icon_name, 512):
- additional_data = {"local_image_path": Path(icon_path)}
+ additional_data = {"local_icon_path": Path(icon_path)}
else:
pass
diff --git a/src/importer/sources/lutris_source.py b/src/importer/sources/lutris_source.py
index 36f28c1..f9a384e 100644
--- a/src/importer/sources/lutris_source.py
+++ b/src/importer/sources/lutris_source.py
@@ -48,9 +48,13 @@ class LutrisSourceIterator(SourceIterator):
AND configPath IS NOT NULL
AND installed
AND (runner IS NOT "steam" OR :import_steam)
+ AND (runner IS NOT "flatpak" OR :import_flatpak)
;
"""
- params = {"import_steam": shared.schema.get_boolean("lutris-import-steam")}
+ params = {
+ "import_steam": shared.schema.get_boolean("lutris-import-steam"),
+ "import_flatpak": shared.schema.get_boolean("lutris-import-flatpak"),
+ }
db_path = copy_db(self.source.data_location["pga.db"])
connection = connect(db_path)
cursor = connection.execute(request, params)
diff --git a/src/preferences.py b/src/preferences.py
index 7a807d6..72ed609 100644
--- a/src/preferences.py
+++ b/src/preferences.py
@@ -60,6 +60,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
lutris_cache_action_row = Gtk.Template.Child()
lutris_cache_file_chooser_button = Gtk.Template.Child()
lutris_import_steam_switch = Gtk.Template.Child()
+ lutris_import_flatpak_switch = Gtk.Template.Child()
heroic_expander_row = Gtk.Template.Child()
heroic_config_action_row = Gtk.Template.Child()
@@ -83,6 +84,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
flatpak_expander_row = Gtk.Template.Child()
flatpak_data_action_row = Gtk.Template.Child()
flatpak_config_file_chooser_button = Gtk.Template.Child()
+ flatpak_import_launchers_switch = Gtk.Template.Child()
sgdb_key_group = Gtk.Template.Child()
sgdb_key_entry_row = Gtk.Template.Child()
@@ -174,9 +176,11 @@ class PreferencesWindow(Adw.PreferencesWindow):
"cover-launches-game",
"high-quality-images",
"lutris-import-steam",
+ "lutris-import-flatpak",
"heroic-import-epic",
"heroic-import-gog",
"heroic-import-sideload",
+ "flatpak-import-launchers",
"sgdb",
"sgdb-prefer",
"sgdb-animated",
diff --git a/src/store/managers/local_cover_manager.py b/src/store/managers/local_cover_manager.py
index 9aa8703..8f621e6 100644
--- a/src/store/managers/local_cover_manager.py
+++ b/src/store/managers/local_cover_manager.py
@@ -1,6 +1,7 @@
# local_cover_manager.py
#
# Copyright 2023 Geoffrey Coulaud
+# Copyright 2023 kramo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,12 +18,13 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
-from pathlib import Path
+from gi.repository import GdkPixbuf
+from src import shared
from src.game import Game
from src.store.managers.manager import Manager
from src.store.managers.steam_api_manager import SteamAPIManager
-from src.utils.save_cover import save_cover, resize_cover
+from src.utils.save_cover import resize_cover, save_cover
class LocalCoverManager(Manager):
@@ -31,12 +33,39 @@ class LocalCoverManager(Manager):
run_after = (SteamAPIManager,)
def manager_logic(self, game: Game, additional_data: dict) -> None:
- # Ensure that the cover path is in the additional data
- try:
- image_path: Path = additional_data["local_image_path"]
- except KeyError:
- return
- if not image_path.is_file():
- return
- # Save the image
- save_cover(game.game_id, resize_cover(image_path))
+ if image_path := additional_data.get("local_image_path"):
+ if not image_path.is_file():
+ return
+ save_cover(game.game_id, resize_cover(image_path))
+ elif icon_path := additional_data.get("local_icon_path"):
+ cover_width, cover_height = shared.image_size
+
+ dest_width = cover_width * 0.7
+ dest_height = cover_width * 0.7
+
+ dest_x = cover_width * 0.15
+ dest_y = (cover_height - dest_height) / 2
+
+ image = GdkPixbuf.Pixbuf.new_from_file(str(icon_path)).scale_simple(
+ dest_width, dest_height, GdkPixbuf.InterpType.BILINEAR
+ )
+
+ cover = image.scale_simple(
+ 1, 2, GdkPixbuf.InterpType.BILINEAR
+ ).scale_simple(cover_width, cover_height, GdkPixbuf.InterpType.BILINEAR)
+
+ image.composite(
+ cover,
+ dest_x,
+ dest_y,
+ dest_width,
+ dest_height,
+ dest_x,
+ dest_y,
+ 1,
+ 1,
+ GdkPixbuf.InterpType.BILINEAR,
+ 255,
+ )
+
+ save_cover(game.game_id, resize_cover(pixbuf=cover))