SteamGridDB for manually added games
This commit is contained in:
@@ -221,7 +221,8 @@ template PreferencesWindow : Adw.PreferencesWindow {
|
||||
title: _("Behavior");
|
||||
|
||||
Adw.ActionRow {
|
||||
title: _("Download Images on Import");
|
||||
title: _("Download Images Automatically");
|
||||
subtitle: _("Download images when adding or importing games");
|
||||
|
||||
Switch sgdb_download_switch {
|
||||
valign: center;
|
||||
|
||||
@@ -156,9 +156,6 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
self.win.update_games([game_id])
|
||||
|
||||
if self.win.stack.get_visible_child() == self.win.overview:
|
||||
self.win.show_overview(None, self.win.active_game_id)
|
||||
|
||||
def on_hide_game_action(self, _widget, _callback=None, game_id=None):
|
||||
if not game_id:
|
||||
game_id = self.win.active_game_id
|
||||
|
||||
@@ -27,6 +27,7 @@ from gi.repository import Adw, GdkPixbuf, Gio, GLib, GObject, Gtk
|
||||
from .create_dialog import create_dialog
|
||||
from .save_cover import save_cover
|
||||
from .save_game import save_game
|
||||
from .steamgriddb import SGDBSave
|
||||
|
||||
|
||||
def create_details_window(parent_widget, game_id=None):
|
||||
@@ -267,13 +268,18 @@ def create_details_window(parent_widget, game_id=None):
|
||||
)
|
||||
return
|
||||
|
||||
if pixbuf:
|
||||
save_cover(parent_widget, game_id, None, pixbuf)
|
||||
|
||||
values["name"] = final_name
|
||||
values["developer"] = final_developer or None
|
||||
values["executable"] = final_executable_split
|
||||
|
||||
if pixbuf:
|
||||
save_cover(parent_widget, game_id, None, pixbuf)
|
||||
elif (
|
||||
game_id not in parent_widget.games
|
||||
or parent_widget.games[game_id].pixbuf == parent_widget.placeholder_pixbuf
|
||||
):
|
||||
SGDBSave(parent_widget, {(game_id, values["name"])})
|
||||
|
||||
path = parent_widget.data_dir / "cartridges" / "games" / f"{game_id}.json"
|
||||
|
||||
if path.exists():
|
||||
@@ -284,8 +290,6 @@ def create_details_window(parent_widget, game_id=None):
|
||||
save_game(parent_widget, values)
|
||||
|
||||
parent_widget.update_games([game_id])
|
||||
if parent_widget.stack.get_visible_child() == parent_widget.overview:
|
||||
parent_widget.show_overview(None, game_id)
|
||||
window.close()
|
||||
parent_widget.show_overview(None, game_id)
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class Importer:
|
||||
self.queue = len(self.games)
|
||||
self.import_statuspage.set_title(_("Importing Covers…"))
|
||||
self.update_progressbar()
|
||||
SGDBSave(self, self.games)
|
||||
SGDBSave(self.parent_widget, self.games, self)
|
||||
else:
|
||||
self.done()
|
||||
|
||||
|
||||
@@ -4,13 +4,16 @@ import requests
|
||||
from gi.repository import Gio
|
||||
from steamgrid import SteamGridDB, http
|
||||
|
||||
from .create_dialog import create_dialog
|
||||
from .save_cover import save_cover
|
||||
|
||||
|
||||
class SGDBSave:
|
||||
def __init__(self, importer, games):
|
||||
def __init__(self, parent_widget, games, importer=None):
|
||||
self.parent_widget = parent_widget
|
||||
self.sgdb = SteamGridDB(self.parent_widget.schema.get_string("sgdb-key"))
|
||||
self.importer = importer
|
||||
self.sgdb = SteamGridDB(importer.parent_widget.schema.get_string("sgdb-key"))
|
||||
self.exception = None
|
||||
|
||||
# Wrap the function in another one as Gio.Task.run_in_thread does not allow for passing args
|
||||
def create_func(game):
|
||||
@@ -26,10 +29,10 @@ class SGDBSave:
|
||||
Gio.Task.new(None, None, self.task_done).run_in_thread(create_func(game))
|
||||
|
||||
def update_cover(self, task, game):
|
||||
if self.importer.parent_widget.schema.get_boolean("sgdb-prefer") or (
|
||||
self.importer.parent_widget.schema.get_boolean("sgdb-import")
|
||||
and self.importer.parent_widget.games[game[0]].pixbuf
|
||||
== self.importer.parent_widget.placeholder_pixbuf
|
||||
if self.parent_widget.schema.get_boolean("sgdb-prefer") or (
|
||||
self.parent_widget.schema.get_boolean("sgdb-import")
|
||||
and self.parent_widget.games[game[0]].pixbuf
|
||||
== self.parent_widget.placeholder_pixbuf
|
||||
):
|
||||
try:
|
||||
search_result = self.sgdb.search_game(game[1])
|
||||
@@ -37,7 +40,7 @@ class SGDBSave:
|
||||
task.return_value(game[0])
|
||||
return
|
||||
except http.HTTPException as exception:
|
||||
self.importer.sgdb_exception = str(exception)
|
||||
self.exception = str(exception)
|
||||
task.return_value(game[0])
|
||||
return
|
||||
|
||||
@@ -58,12 +61,28 @@ class SGDBSave:
|
||||
return
|
||||
|
||||
Path(tmp_file.get_path()).write_bytes(response.content)
|
||||
save_cover(self.importer.parent_widget, game[0], tmp_file.get_path())
|
||||
save_cover(self.parent_widget, game[0], tmp_file.get_path())
|
||||
|
||||
task.return_value(game[0])
|
||||
|
||||
def task_done(self, _task, result):
|
||||
game_id = result.propagate_value()[1]
|
||||
self.importer.parent_widget.update_games([game_id])
|
||||
self.importer.queue -= 1
|
||||
self.importer.done()
|
||||
self.parent_widget.update_games([game_id])
|
||||
if self.importer:
|
||||
self.importer.queue -= 1
|
||||
self.importer.done()
|
||||
self.importer.sgdb_exception = self.exception
|
||||
elif self.exception:
|
||||
create_dialog(
|
||||
self.parent_widget,
|
||||
_("Couldn't Connect to SteamGridDB"),
|
||||
self.exception,
|
||||
"open_preferences",
|
||||
_("Preferences"),
|
||||
).connect("response", self.response)
|
||||
|
||||
def response(self, _widget, response):
|
||||
if response == "open_preferences":
|
||||
self.parent_widget.get_application().on_preferences_action(
|
||||
None, page_name="sgdb"
|
||||
)
|
||||
|
||||
@@ -173,6 +173,9 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
else:
|
||||
self.hidden_library_bin.set_child(self.hidden_scrolledwindow)
|
||||
|
||||
if self.stack.get_visible_child() == self.overview:
|
||||
self.show_overview(None, self.active_game_id)
|
||||
|
||||
self.library.invalidate_filter()
|
||||
self.hidden_library.invalidate_filter()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user