Option to refetch SGDB covers - fixes #192
This commit is contained in:
@@ -290,5 +290,18 @@ template $PreferencesWindow : Adw.PreferencesWindow {
|
|||||||
title: _("Prefer Animated Images");
|
title: _("Prefer Animated Images");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Adw.PreferencesGroup {
|
||||||
|
Adw.ActionRow {
|
||||||
|
title: _("Redownload Covers");
|
||||||
|
subtitle: _("Fetch covers for games already in your library");
|
||||||
|
sensitive: bind sgdb_switch.active;
|
||||||
|
|
||||||
|
Button sgdb_fetch_button {
|
||||||
|
label: _("Download");
|
||||||
|
valign: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class DetailsWindow(Adw.Window):
|
|||||||
# Get a cover from SGDB if none is present
|
# Get a cover from SGDB if none is present
|
||||||
if not self.game_cover.get_texture():
|
if not self.game_cover.get_texture():
|
||||||
self.game.set_loading(1)
|
self.game.set_loading(1)
|
||||||
sgdb_manager: SGDBManager = shared.store.managers[SGDBManager]
|
sgdb_manager = shared.store.managers[SGDBManager]
|
||||||
sgdb_manager.reset_cancellable()
|
sgdb_manager.reset_cancellable()
|
||||||
sgdb_manager.process_game(self.game, {}, self.update_cover_callback)
|
sgdb_manager.process_game(self.game, {}, self.update_cover_callback)
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ from typing import Any, Callable, Optional
|
|||||||
from gi.repository import Adw, Gio, GLib, Gtk
|
from gi.repository import Adw, Gio, GLib, Gtk
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
|
from src.errors.friendly_error import FriendlyError
|
||||||
from src.game import Game
|
from src.game import Game
|
||||||
from src.importer.sources.bottles_source import BottlesSource
|
from src.importer.sources.bottles_source import BottlesSource
|
||||||
from src.importer.sources.flatpak_source import FlatpakSource
|
from src.importer.sources.flatpak_source import FlatpakSource
|
||||||
@@ -37,6 +38,7 @@ from src.importer.sources.lutris_source import LutrisSource
|
|||||||
from src.importer.sources.retroarch_source import RetroarchSource
|
from src.importer.sources.retroarch_source import RetroarchSource
|
||||||
from src.importer.sources.source import Source
|
from src.importer.sources.source import Source
|
||||||
from src.importer.sources.steam_source import SteamSource
|
from src.importer.sources.steam_source import SteamSource
|
||||||
|
from src.store.managers.sgdb_manager import SGDBManager
|
||||||
from src.utils.create_dialog import create_dialog
|
from src.utils.create_dialog import create_dialog
|
||||||
|
|
||||||
|
|
||||||
@@ -104,6 +106,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
sgdb_switch = Gtk.Template.Child()
|
sgdb_switch = Gtk.Template.Child()
|
||||||
sgdb_prefer_switch = Gtk.Template.Child()
|
sgdb_prefer_switch = Gtk.Template.Child()
|
||||||
sgdb_animated_switch = Gtk.Template.Child()
|
sgdb_animated_switch = Gtk.Template.Child()
|
||||||
|
sgdb_fetch_button = Gtk.Template.Child()
|
||||||
|
|
||||||
danger_zone_group = Gtk.Template.Child()
|
danger_zone_group = Gtk.Template.Child()
|
||||||
reset_action_row = Gtk.Template.Child()
|
reset_action_row = Gtk.Template.Child()
|
||||||
@@ -172,6 +175,41 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def redownload_sgdb(*_args) -> None:
|
||||||
|
counter = 0
|
||||||
|
games_len = shared.store.__len__() - 1 # IDK why it returns one more
|
||||||
|
sgdb_manager = shared.store.managers[SGDBManager]
|
||||||
|
sgdb_manager.reset_cancellable()
|
||||||
|
|
||||||
|
self.add_toast(download_toast := Adw.Toast.new(_("Downloading covers…")))
|
||||||
|
|
||||||
|
def update_cover_callback(manager: SGDBManager) -> None:
|
||||||
|
nonlocal counter
|
||||||
|
nonlocal games_len
|
||||||
|
nonlocal download_toast
|
||||||
|
|
||||||
|
counter += 1
|
||||||
|
if counter != games_len:
|
||||||
|
return
|
||||||
|
|
||||||
|
for error in manager.collect_errors():
|
||||||
|
if isinstance(error, FriendlyError):
|
||||||
|
create_dialog(self, error.title, error.subtitle)
|
||||||
|
break
|
||||||
|
|
||||||
|
for game in shared.store:
|
||||||
|
game.update()
|
||||||
|
|
||||||
|
toast = Adw.Toast.new(_("Covers updated"))
|
||||||
|
toast.set_priority(Adw.ToastPriority.HIGH)
|
||||||
|
download_toast.dismiss()
|
||||||
|
self.add_toast(toast)
|
||||||
|
|
||||||
|
for game in shared.store:
|
||||||
|
sgdb_manager.process_game(game, {}, update_cover_callback)
|
||||||
|
|
||||||
|
self.sgdb_fetch_button.connect("clicked", redownload_sgdb)
|
||||||
|
|
||||||
# Switches
|
# Switches
|
||||||
self.bind_switches(
|
self.bind_switches(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user