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