From 26a09c67828d4f1725dde784457ecd122ef887db Mon Sep 17 00:00:00 2001 From: Jamie Gravendeel Date: Mon, 22 Dec 2025 14:04:27 +0100 Subject: [PATCH] collections: Save to GSettings --- cartridges/collections.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cartridges/collections.py b/cartridges/collections.py index e6c0d6b..b5411ee 100644 --- a/cartridges/collections.py +++ b/cartridges/collections.py @@ -1,10 +1,10 @@ # SPDX-License-Identifier: GPL-3.0-or-later # SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel -from collections.abc import Generator -from typing import Any +from collections.abc import Generator, Iterable +from typing import Any, cast -from gi.repository import Gio, GObject +from gi.repository import Gio, GLib, GObject from cartridges import SETTINGS @@ -52,6 +52,26 @@ def _get_collections() -> Generator[Collection]: def load(): """Load collections from GSettings.""" model.splice(0, 0, tuple(_get_collections())) + save() + + +def save(): + """Save collections to GSettings.""" + SETTINGS.set_value( + "collections", + GLib.Variant( + "aa{sv}", + ( + { + "name": GLib.Variant.new_string(collection.name), + "icon": GLib.Variant.new_string(collection.icon), + "game-ids": GLib.Variant.new_strv(collection.game_ids), + "removed": GLib.Variant.new_boolean(collection.removed), + } + for collection in cast(Iterable[Collection], model) + ), + ), + ) model = Gio.ListStore.new(Collection)