62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
# Copyright 2021 (c) Anna Schumaker.
|
|
#
|
|
# Table: discs
|
|
# +--------+---------+--------+----------+
|
|
# | discid | albumid | number | subtitle |
|
|
# +--------+---------+--------+----------+
|
|
from gi.repository import GObject
|
|
from . import playlist
|
|
from . import sql
|
|
|
|
class Disc(playlist.Playlist):
|
|
def __init__(self, row):
|
|
playlist.Playlist.__init__(self, row, "media-optical")
|
|
self._number = row["number"]
|
|
self._subtitle = row["subtitle"]
|
|
|
|
def delete(self): Table.delete(self)
|
|
|
|
@GObject.Property
|
|
def name(self):
|
|
if self._subtitle:
|
|
return f"{self._number}: {self._subtitle}"
|
|
return f"Disc {self._number}"
|
|
|
|
@GObject.Property
|
|
def number(self): return self._number
|
|
|
|
@GObject.Property
|
|
def subtitle(self):
|
|
return self._subtitle if self._subtitle else ""
|
|
|
|
|
|
class DiscTable(playlist.ChildModel):
|
|
def __init__(self):
|
|
playlist.ChildModel.__init__(self, "discs", "albumid", "number")
|
|
|
|
def do_create(self):
|
|
sql.execute("CREATE TABLE IF NOT EXISTS discs "
|
|
"(discid INTEGER PRIMARY KEY, "
|
|
" albumid INTEGER, "
|
|
" plstateid INTEGER NOT NULL, "
|
|
" number INTEGER, "
|
|
" subtitle TEXT, "
|
|
" FOREIGN KEY(albumid) REFERENCES albums(albumid), "
|
|
" FOREIGN KEY(plstateid) REFERENCES playlist_states(plstateid), "
|
|
" UNIQUE(albumid, number))")
|
|
|
|
def do_factory(self, row):
|
|
return Disc(row)
|
|
|
|
def do_insert(self, plstate, album, number, subtitle):
|
|
return sql.execute("INSERT INTO discs (albumid, plstateid, number, subtitle) "
|
|
"VALUES (?, ?, ?, ?)",
|
|
[ album.rowid, plstate.rowid, number, subtitle ])
|
|
|
|
def do_lookup(self, album, number):
|
|
return sql.execute("SELECT * FROM discs WHERE (albumid=? AND number=?)",
|
|
[ album.rowid, number ])
|
|
|
|
|
|
Table = DiscTable()
|