45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""A TrackidModel with extra features."""
|
|
from gi.repository import GObject
|
|
from . import model
|
|
from .. import db
|
|
|
|
|
|
class Playlist(model.TrackidModel):
|
|
"""A TrackidModel with extra Playlist features."""
|
|
|
|
def __init__(self, sql: db.Connection,
|
|
playlist: db.playlist.Playlist = None):
|
|
"""Initialize the Playlist instance."""
|
|
super().__init__(sql=sql)
|
|
self.__playlist = None
|
|
|
|
if playlist is not None:
|
|
self.playlist = playlist
|
|
|
|
def add_track(self, track: db.tracks.Track) -> None:
|
|
"""Add a track to the playlist."""
|
|
if self.__playlist is not None:
|
|
self.__playlist.add_track(track)
|
|
|
|
def index(self, track: db.tracks.Track) -> int | None:
|
|
"""Find the index of a track in the list."""
|
|
if track is not None:
|
|
return super().index(track.trackid)
|
|
|
|
def remove_track(self, track: db.tracks.Track) -> None:
|
|
"""Remove a track from the playlist."""
|
|
if self.__playlist is not None:
|
|
self.__playlist.remove_track(track)
|
|
|
|
@GObject.Property(type=db.playlist.Playlist)
|
|
def playlist(self) -> db.playlist.Playlist | None:
|
|
"""Get the current db playlist."""
|
|
return self.__playlist
|
|
|
|
@playlist.setter
|
|
def playlist(self, new: db.playlist.Playlist | None) -> None:
|
|
"""Set a new db playlist to the playlist."""
|
|
self.__playlist = new
|
|
self.trackid_set = None if new is None else new.tracks
|