collections: Save to GSettings
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
# SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel
|
# SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel
|
||||||
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator, Iterable
|
||||||
from typing import Any
|
from typing import Any, cast
|
||||||
|
|
||||||
from gi.repository import Gio, GObject
|
from gi.repository import Gio, GLib, GObject
|
||||||
|
|
||||||
from cartridges import SETTINGS
|
from cartridges import SETTINGS
|
||||||
|
|
||||||
@@ -52,6 +52,26 @@ def _get_collections() -> Generator[Collection]:
|
|||||||
def load():
|
def load():
|
||||||
"""Load collections from GSettings."""
|
"""Load collections from GSettings."""
|
||||||
model.splice(0, 0, tuple(_get_collections()))
|
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)
|
model = Gio.ListStore.new(Collection)
|
||||||
|
|||||||
Reference in New Issue
Block a user