Finalize Flatpak source

This commit is contained in:
kramo
2023-06-30 23:49:48 +02:00
parent 8efb1c6c5e
commit 721a46c5b8
6 changed files with 94 additions and 16 deletions

View File

@@ -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;
}
}
}
}
}

View File

@@ -28,6 +28,9 @@
<key name="lutris-import-steam" type="b">
<default>false</default>
</key>
<key name="lutris-import-flatpak" type="b">
<default>false</default>
</key>
<key name="heroic" type="b">
<default>true</default>
</key>
@@ -62,11 +65,14 @@
<default>"~/.config/legendary/"</default>
</key>
<key name="flatpak" type="b">
<default>false</default>
<default>true</default>
</key>
<key name="flatpak-location" type="s">
<default>"/var/lib/flatpak/exports"</default>
</key>
<key name="flatpak-import-launchers" type="b">
<default>false</default>
</key>
<key name="sgdb-key" type="s">
<default>""</default>
</key>

View File

@@ -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

View File

@@ -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)

View File

@@ -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",

View File

@@ -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))