2021-10-07 20:48:26 -04:00
|
|
|
# Copyright 2021 (c) Anna Schumaker.
|
|
|
|
from gi.repository import GObject
|
|
|
|
from . import sql
|
|
|
|
from . import state
|
2021-10-09 13:40:17 -04:00
|
|
|
from . import table
|
2021-10-07 20:48:26 -04:00
|
|
|
|
|
|
|
class Playlist(GObject.GObject):
|
|
|
|
def __init__(self, row):
|
|
|
|
GObject.GObject.__init__(self)
|
|
|
|
self._rowid = row[0]
|
|
|
|
self._plstate = state.Table.get(row["plstateid"])
|
|
|
|
|
|
|
|
def has_children(self): return False
|
|
|
|
|
|
|
|
@GObject.Property
|
|
|
|
def name(self): raise NotImplementedError
|
|
|
|
|
|
|
|
@GObject.Property
|
|
|
|
def plist_state(self): return self._plstate
|
|
|
|
|
|
|
|
@GObject.Property
|
|
|
|
def rowid(self): return self._rowid
|
|
|
|
|
|
|
|
|
|
|
|
class ParentPlaylist(Playlist):
|
|
|
|
def has_children(self): return True
|
|
|
|
def get_child_table(self): raise NotImplementedError
|
|
|
|
|
|
|
|
def get_n_children(self):
|
|
|
|
return self.get_child_table().get_n_children(self)
|
|
|
|
|
|
|
|
def get_child(self, n):
|
|
|
|
return self.get_child_table().get_child(self, n)
|
|
|
|
|
|
|
|
def get_child_index(self, child):
|
|
|
|
return self.get_child_table().get_child_index(self, child)
|
|
|
|
|
|
|
|
def find_child(self, *args):
|
|
|
|
if (res := self.lookup_child(*args)) == None:
|
|
|
|
res = self.get_child_table().insert(self, *args)
|
|
|
|
self.emit("children-changed", self.get_child_index(res), 0, 1)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def lookup_child(self, *args):
|
|
|
|
return self.get_child_table().lookup(self, *args)
|
|
|
|
|
|
|
|
@GObject.Signal(arg_types=(int,int,int))
|
|
|
|
def children_changed(self, pos, rm, add): pass
|
2021-10-09 13:40:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
class Model(table.Model):
|
|
|
|
def insert(self, *args, **kwargs):
|
|
|
|
return super().insert(state.Table.insert(), *args)
|
|
|
|
|
|
|
|
def delete(self, plist):
|
|
|
|
state.Table.delete(plist.plist_state)
|
|
|
|
return super().delete(plist)
|
|
|
|
|
|
|
|
|
|
|
|
class ChildModel(table.Child):
|
|
|
|
def insert(self, *args, **kwargs):
|
|
|
|
return super().insert(state.Table.insert(), *args)
|
|
|
|
|
|
|
|
def delete(self, plist):
|
|
|
|
state.Table.delete(plist.plist_state)
|
|
|
|
return super().delete(plist)
|