collections: Filter out removed manually added games
This commit is contained in:
@@ -7,7 +7,9 @@ from typing import TYPE_CHECKING, Any, cast
|
|||||||
|
|
||||||
from gi.repository import Gio, GLib, GObject
|
from gi.repository import Gio, GLib, GObject
|
||||||
|
|
||||||
from cartridges import SETTINGS
|
from cartridges import SETTINGS, games
|
||||||
|
from cartridges.games import Game
|
||||||
|
from cartridges.sources import imported
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .application import Application
|
from .application import Application
|
||||||
@@ -34,7 +36,7 @@ class Collection(Gio.SimpleActionGroup):
|
|||||||
def __init__(self, **kwargs: Any):
|
def __init__(self, **kwargs: Any):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self.game_ids = []
|
self.game_ids = self.game_ids or []
|
||||||
self.bind_property(
|
self.bind_property(
|
||||||
"icon",
|
"icon",
|
||||||
self,
|
self,
|
||||||
@@ -66,19 +68,29 @@ class Collection(Gio.SimpleActionGroup):
|
|||||||
|
|
||||||
|
|
||||||
def _get_collections() -> Generator[Collection]:
|
def _get_collections() -> Generator[Collection]:
|
||||||
|
manually_added_game_ids = {
|
||||||
|
game.game_id
|
||||||
|
for game in cast(Iterable[Game], games.model)
|
||||||
|
if game.source.startswith(imported.ID)
|
||||||
|
}
|
||||||
for data in SETTINGS.get_value("collections").unpack():
|
for data in SETTINGS.get_value("collections").unpack():
|
||||||
if data.get("removed"):
|
if data.get("removed"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
collection = Collection()
|
|
||||||
for prop, value in data.items():
|
|
||||||
try:
|
try:
|
||||||
collection.set_property(prop, value)
|
yield Collection(
|
||||||
except TypeError:
|
name=data["name"],
|
||||||
|
icon=data["icon"],
|
||||||
|
game_ids=[
|
||||||
|
ident
|
||||||
|
for ident in data["game-ids"]
|
||||||
|
if not ident.startswith(imported.ID)
|
||||||
|
or ident in manually_added_game_ids
|
||||||
|
],
|
||||||
|
)
|
||||||
|
except (KeyError, TypeError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield collection
|
|
||||||
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
"""Load collections from GSettings."""
|
"""Load collections from GSettings."""
|
||||||
|
|||||||
Reference in New Issue
Block a user