Get rid of game-removed signal, screw mypy

This commit is contained in:
Mathieu Comandon 2024-02-18 03:19:09 -08:00
parent ad82a5c778
commit 62afeeb2ad
6 changed files with 16 additions and 24 deletions

View file

@ -62,7 +62,6 @@ class Game(GObject.Object):
"game-started": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-stop": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-stopped": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-removed": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-updated": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-install": (GObject.SIGNAL_RUN_FIRST, None, ()),
"game-install-update": (GObject.SIGNAL_RUN_FIRST, None, ()),
@ -351,12 +350,11 @@ class Game(GObject.Object):
disable_compositing()
self.compositor_disabled = True
def uninstall(self, delete_files: bool = False, no_signal: bool = False) -> None:
def uninstall(self, delete_files: bool = False) -> None:
"""Uninstall a game, but do not remove it from the library.
Params:
delete_files (bool): Delete the game files
no_signal (bool): Don't emit game-removed signal
"""
sql.db_update(settings.DB_PATH, "games", {"installed": 0, "runner": ""}, {"id": self.id})
if self.config:
@ -375,16 +373,12 @@ class Game(GObject.Object):
log_buffer = LOG_BUFFERS[self.id]
log_buffer.delete(log_buffer.get_start_iter(), log_buffer.get_end_iter())
if not no_signal:
self.emit("game-removed")
def delete(self, no_signal: bool = False) -> None:
def delete(self) -> None:
"""Delete a game from the library; must be uninstalled first."""
if self.is_installed:
raise RuntimeError(_("Uninstall the game before deleting"))
games_db.delete_game(self.id)
if not no_signal:
self.emit("game-removed")
self._id = None
def set_platform_from_runner(self):

View file

@ -18,7 +18,7 @@ from lutris.gui.config.edit_game import EditGameConfigDialog
from lutris.gui.config.edit_game_categories import EditGameCategoriesDialog
from lutris.gui.dialogs import InputDialog
from lutris.gui.dialogs.log import LogWindow
from lutris.gui.dialogs.uninstall_game import UninstallMultipleGamesDialog
from lutris.gui.dialogs.uninstall_dialog import UninstallDialog
from lutris.gui.widgets.utils import open_uri
from lutris.services.lutris import download_lutris_media
from lutris.util import xdgshortcuts
@ -96,7 +96,7 @@ class BaseGameActions:
"""Callback that present the uninstall dialog to the user"""
game_ids = [g.id for g in self.games if g.is_installed or g.is_db_stored]
application = Gio.Application.get_default()
dlg = application.show_window(UninstallMultipleGamesDialog, parent=self.window)
dlg = application.show_window(UninstallDialog, parent=self.window)
dlg.add_games(game_ids)
def on_view_game(self, _widget):

View file

@ -12,19 +12,19 @@ from lutris.gui.dialogs import QuestionDialog
from lutris.gui.widgets.gi_composites import GtkTemplate
from lutris.util import datapath
from lutris.util.jobs import AsyncCall
from lutris.util.path_cache import remove_from_path_cache
from lutris.util.library_sync import delete_from_remote_library, sync_local_library
from lutris.util.log import logger
from lutris.util.path_cache import remove_from_path_cache
from lutris.util.strings import get_natural_sort_key, gtk_safe, human_size
from lutris.util.system import get_disk_size, is_removeable
@GtkTemplate(ui=os.path.join(datapath.get(), "ui", "uninstall-dialog.ui"))
class UninstallMultipleGamesDialog(Gtk.Dialog):
class UninstallDialog(Gtk.Dialog):
"""A dialog to uninstall and remove games. It lists the games and offers checkboxes to delete
the game files, and to remove from the library."""
__gtype_name__ = "UninstallMultipleGamesDialog"
__gtype_name__ = "UninstallDialog"
header_bar: Gtk.HeaderBar = GtkTemplate.Child()
message_label: Gtk.Label = GtkTemplate.Child()
@ -36,6 +36,7 @@ class UninstallMultipleGamesDialog(Gtk.Dialog):
def __init__(self, parent: Gtk.Window = None, **kwargs):
super().__init__(parent=parent, **kwargs)
self.parent = parent
self._setting_all_checkboxes = False
self.games: List[Game] = []
self.any_shared = False
@ -319,7 +320,7 @@ class UninstallMultipleGamesDialog(Gtk.Dialog):
if settings.read_bool_setting("library_sync_enabled") and games_removed_from_library:
delete_from_remote_library(games_removed_from_library)
self.parent.on_game_removed()
self.destroy()
def on_response(self, _dialog, response: Gtk.ResponseType) -> None:
@ -478,15 +479,13 @@ class GameRemovalRow(Gtk.ListBoxRow):
def perform_removal(self) -> None:
"""Performs the actions this row describes, uninstalling or deleting a game."""
# We uninstall installed games, and delete games where self.remove_from_library is true;
# but we must be careful to fire the game-removed single only once.
# We uninstall installed games, and delete games where self.remove_from_library is true
if self.game.is_installed:
remove_from_path_cache(self.game)
if self.remove_from_library:
self.game.uninstall(delete_files=self.delete_files, no_signal=True)
self.game.uninstall(delete_files=self.delete_files)
self.game.delete()
else:
self.game.uninstall(delete_files=self.delete_files)
elif self.remove_from_library:
self.game.delete()

View file

@ -146,7 +146,6 @@ class LutrisWindow(Gtk.ApplicationWindow,
GObject.add_emission_hook(Game, "game-updated", self.on_game_updated)
GObject.add_emission_hook(Game, "game-stopped", self.on_game_stopped)
GObject.add_emission_hook(Game, "game-installed", self.on_game_installed)
GObject.add_emission_hook(Game, "game-removed", self.on_game_removed)
GObject.add_emission_hook(Game, "game-unhandled-error", self.on_game_unhandled_error)
GObject.add_emission_hook(PreferencesDialog, "settings-changed", self.on_settings_changed)
MISSING_GAMES.updated.register(self.update_missing_games_sidebar_row)
@ -1092,7 +1091,7 @@ class LutrisWindow(Gtk.ApplicationWindow,
def on_game_installed(self, game):
return True
def on_game_removed(self, _game):
def on_game_removed(self):
"""Simple method used to refresh the view"""
self.sidebar.update_rows()
self.update_missing_games_sidebar_row()

View file

@ -190,7 +190,7 @@ class SteamService(BaseService):
logger.warning("Steam game %s has no AppID")
continue
if appid not in installed_appids:
steam_game.uninstall(no_signal=True)
steam_game.uninstall()
stats["removed"] += 1
logger.debug("%s Steam games removed", stats["removed"])
@ -207,8 +207,8 @@ class SteamService(BaseService):
steam_game = Game(game_id)
if not steam_game.playtime:
# Unsafe to emit a signal from a worker thread!
steam_game.uninstall(no_signal=True)
steam_game.delete(no_signal=True)
steam_game.uninstall()
steam_game.delete()
stats["deduped"] += 1
sync_media(installed_slugs)
logger.debug("%s Steam games deduplicated", stats["deduped"])

View file

@ -2,7 +2,7 @@
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<template class="UninstallMultipleGamesDialog" parent="GtkDialog">
<template class="UninstallDialog" parent="GtkDialog">
<property name="can-focus">False</property>
<property name="window-position">center-on-parent</property>
<property name="default-width">800</property>