Adjust hidden and favorites code for consistency, also add some commenting.

This commit is contained in:
Daniel Johnson 2024-02-17 07:44:14 -05:00 committed by Mathieu Comandon
parent 87db808be2
commit fefbb38d12
4 changed files with 27 additions and 28 deletions

View file

@ -170,11 +170,6 @@ class Game(GObject.Object):
"""Return whether the game can be upgraded"""
return self.is_installed and self.service in ["gog", "itchio"]
@property
def is_favorite(self):
"""Return whether the game is in the user's favorites"""
return "favorite" in self.get_categories()
def get_categories(self):
"""Return the categories the game is in."""
return categories_db.get_categories_in_game(self.id) if self.is_db_stored else []
@ -218,25 +213,33 @@ class Game(GObject.Object):
if not no_signal:
self.emit("game-updated")
def add_to_favorites(self):
"""Add the game to the 'favorite' category"""
self.add_category("favorite")
@property
def is_favorite(self) -> bool:
"""Return whether the game is in the user's favorites"""
return "favorite" in self.get_categories()
def remove_from_favorites(self):
"""Remove game from favorites"""
self.remove_category("favorite")
def mark_as_favorite(self, is_favorite: bool) -> None:
"""Place the game in the favorite's category, or remove it.
This change is applied at once, and does not need to be saved."""
if self.is_favorite != bool(is_favorite):
if is_favorite:
self.add_category("favorite")
else:
self.remove_category("favorite")
@property
def is_hidden(self):
def is_hidden(self) -> bool:
"""Return whether the game is in the user's favorites"""
return ".hidden" in self.get_categories()
def set_hidden(self, is_hidden):
"""Do not show this game in the UI"""
if is_hidden:
self.add_category(".hidden")
else:
self.remove_category(".hidden")
def mark_as_hidden(self, is_hidden: bool) -> None:
"""Place the game in the hidden category, or remove it.
This change is applied at once, and does not need to be saved."""
if self.is_hidden != bool(is_hidden):
if is_hidden:
self.add_category(".hidden")
else:
self.remove_category(".hidden")
@property
def log_buffer(self):

View file

@ -337,14 +337,12 @@ class GameActions(BaseGameActions):
def on_add_favorite_game(self, _widget):
"""Add to favorite Games list"""
for game in self.games:
if not game.is_favorite:
game.add_to_favorites()
game.mark_as_favorite(True)
def on_delete_favorite_game(self, _widget):
"""delete from favorites"""
for game in self.games:
if game.is_favorite:
game.remove_from_favorites()
game.mark_as_favorite(False)
def on_edit_game_categories(self, _widget):
"""Edit game categories"""
@ -354,14 +352,12 @@ class GameActions(BaseGameActions):
def on_hide_game(self, _widget):
"""Add a game to the list of hidden games"""
for game in self.games:
if not game.is_hidden:
game.set_hidden(True)
game.mark_as_hidden(True)
def on_unhide_game(self, _widget):
"""Removes a game from the list of hidden games"""
for game in self.games:
if game.is_hidden:
game.set_hidden(False)
game.mark_as_hidden(False)
def on_execute_script_clicked(self, _widget):
"""Execute the game's associated script"""

View file

@ -17,5 +17,5 @@ def migrate():
for game_id in game_ids:
game = Game(game_id)
game.set_hidden(True)
game.mark_as_hidden(True)
logger.info("Migrated '%s' to '.hidden' category.", game.name)

View file

@ -19,5 +19,5 @@ def migrate():
return []
for game_id in game_ids:
game = Game(game_id)
game.set_hidden(True)
game.mark_as_hidden(True)
settings.write_setting("library_ignores", '', section="lutris")