51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""An object for managing the visible and active playlists."""
|
|
from gi.repository import GObject
|
|
from . import playlist
|
|
from .. import db
|
|
|
|
|
|
class Factory(GObject.GObject):
|
|
"""Our playlist model factory."""
|
|
|
|
sql = GObject.Property(type=db.Connection)
|
|
|
|
db_active = GObject.Property(type=db.playlist.Playlist)
|
|
db_previous = GObject.Property(type=db.playlist.Playlist)
|
|
db_visible = GObject.Property(type=db.playlist.Playlist)
|
|
|
|
visible_playlist = GObject.Property(type=playlist.Playlist)
|
|
|
|
def __init__(self, sql: db.Connection):
|
|
"""Initialize the Playlist Factory."""
|
|
super().__init__(sql=sql)
|
|
self.sql.bind_property("active-playlist", self, "db-active")
|
|
self.connect("notify", self.__notify_db_playlists)
|
|
|
|
def __run_factory(self, label: str) -> None:
|
|
db_plist = self.get_property(f"db-{label}")
|
|
plist = self.get_property(f"{label}-playlist")
|
|
|
|
print(f"factory: {label} playlist is:",
|
|
"<None>" if db_plist is None else db_plist.name)
|
|
|
|
if db_plist is None:
|
|
plist.playlist = None
|
|
new = None
|
|
elif plist is None:
|
|
new = playlist.Playlist(self.sql, db_plist)
|
|
else:
|
|
plist.playlist = db_plist
|
|
return
|
|
|
|
self.set_property(f"{label}-playlist", new)
|
|
|
|
def __notify_db_playlists(self, factory: GObject.GObject, param) -> None:
|
|
match param.name:
|
|
case "db-active" | "db-previous":
|
|
plist = self.get_property(param.name)
|
|
name = "<None>" if plist is None else plist.name
|
|
print(f"factory: {param.name[3:]} playlist is:", name)
|
|
case "db-visible":
|
|
self.__run_factory("visible")
|