readme ideas and model caching and loading and such
This commit is contained in:
parent
7e7302528b
commit
93b73c9678
@ -85,3 +85,6 @@ QMultimedia.EncodingMode / Encoding quality...
|
|||||||
- on save metadata modal, run save in another thread (freezing)
|
- on save metadata modal, run save in another thread (freezing)
|
||||||
- on save metadata modal, return to previous state in table (jump to current song/restore scroll position)
|
- on save metadata modal, return to previous state in table (jump to current song/restore scroll position)
|
||||||
- on add to playlist, check if song already exists - prompt user for duplicate?
|
- on add to playlist, check if song already exists - prompt user for duplicate?
|
||||||
|
- drag and drop song(s) onto PlaylistPane to add to playlist
|
||||||
|
- font sizing
|
||||||
|
- font choicing? :o
|
||||||
|
|||||||
@ -93,9 +93,10 @@ class MusicTable(QTableView):
|
|||||||
# Set QTableView model to the Proxy model
|
# Set QTableView model to the Proxy model
|
||||||
# so it looks like the above note, i guess
|
# so it looks like the above note, i guess
|
||||||
|
|
||||||
# need a QStandardItemModel to do actions on cells
|
# need a QStandardItemModel to load data & do actions on cells
|
||||||
self.model2: QStandardItemModel = QStandardItemModel()
|
self.model2: QStandardItemModel = QStandardItemModel()
|
||||||
self.proxymodel: QSortFilterProxyModel = QSortFilterProxyModel()
|
self.proxymodel: QSortFilterProxyModel = QSortFilterProxyModel()
|
||||||
|
self.cache_models: dict[int | None, QStandardItemModel]
|
||||||
self.search_string: str | None = None
|
self.search_string: str | None = None
|
||||||
self.headers = HeaderTags()
|
self.headers = HeaderTags()
|
||||||
# db names of headers
|
# db names of headers
|
||||||
@ -722,76 +723,89 @@ class MusicTable(QTableView):
|
|||||||
)
|
)
|
||||||
params = ""
|
params = ""
|
||||||
debug(f'playlist_id: {playlist_id}')
|
debug(f'playlist_id: {playlist_id}')
|
||||||
# Load a playlist
|
is_playlist = 0
|
||||||
if len(playlist_id) > 0:
|
if len(playlist_id) > 0:
|
||||||
self.selected_playlist_id = playlist_id[0]
|
self.selected_playlist_id = playlist_id[0]
|
||||||
debug('load music table a playlist')
|
is_playlist = 1
|
||||||
try:
|
|
||||||
with DBA.DBAccess() as db:
|
|
||||||
query = f"SELECT id, {
|
|
||||||
fields} FROM song JOIN song_playlist sp ON id = sp.song_id WHERE sp.playlist_id = ?"
|
|
||||||
# fulltext search
|
|
||||||
if self.search_string:
|
|
||||||
# params = 3 * [self.search_string]
|
|
||||||
params = ["%" + self.search_string + "%"] * 3
|
|
||||||
if query.find("WHERE") == -1:
|
|
||||||
query = f"{query} WHERE {search_clause};"
|
|
||||||
else:
|
|
||||||
query = f"{query} AND {search_clause};"
|
|
||||||
data = db.query(
|
|
||||||
query, (self.selected_playlist_id, params))
|
|
||||||
else:
|
|
||||||
data = db.query(query, (self.selected_playlist_id,))
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
error(f"load_music_table() | Unhandled exception 1: {e}")
|
|
||||||
return
|
|
||||||
# Load the entire library
|
|
||||||
else:
|
else:
|
||||||
debug('load music table a Whole Table')
|
self.selected_playlist_id = None
|
||||||
try:
|
|
||||||
with DBA.DBAccess() as db:
|
# Check cache for already loaded QTableView QStandardItemModel
|
||||||
query = f"SELECT id, {fields} FROM song"
|
try:
|
||||||
# fulltext search
|
new_model = self.cache_models[self.selected_playlist_id]
|
||||||
if self.search_string:
|
self.model2 = new_model
|
||||||
params = ["%" + self.search_string + "%"] * 3
|
except KeyError:
|
||||||
if query.find("WHERE") == -1:
|
# Store the current loaded model
|
||||||
query = f"{query} WHERE {search_clause};"
|
self.cache_models[self.selected_playlist_id] = self.model2
|
||||||
|
# Query for a playlist
|
||||||
|
if is_playlist:
|
||||||
|
debug('load music table a playlist')
|
||||||
|
try:
|
||||||
|
with DBA.DBAccess() as db:
|
||||||
|
query = f"SELECT id, {
|
||||||
|
fields} FROM song JOIN song_playlist sp ON id = sp.song_id WHERE sp.playlist_id = ?"
|
||||||
|
# fulltext search
|
||||||
|
if self.search_string:
|
||||||
|
# params = 3 * [self.search_string]
|
||||||
|
params = ["%" + self.search_string + "%"] * 3
|
||||||
|
if query.find("WHERE") == -1:
|
||||||
|
query = f"{query} WHERE {search_clause};"
|
||||||
|
else:
|
||||||
|
query = f"{query} AND {search_clause};"
|
||||||
|
data = db.query(
|
||||||
|
query, (self.selected_playlist_id, params))
|
||||||
else:
|
else:
|
||||||
query = f"{query} AND {search_clause};"
|
data = db.query(query, (self.selected_playlist_id,))
|
||||||
data = db.query(
|
|
||||||
query,
|
except Exception as e:
|
||||||
(params),
|
error(f"load_music_table() | Unhandled exception 1: {e}")
|
||||||
)
|
return
|
||||||
except Exception as e:
|
# Query for the entire library
|
||||||
error(f"load_music_table() | Unhandled exception 2: {e}")
|
else:
|
||||||
return
|
debug('load music table a Whole Table')
|
||||||
# Populate the model
|
try:
|
||||||
row_count: int = 0
|
with DBA.DBAccess() as db:
|
||||||
# TODO: total time of playlist
|
query = f"SELECT id, {fields} FROM song"
|
||||||
# but how do i want to do this if user doesn't choose to see length field?
|
# fulltext search
|
||||||
# spawn new thread and calculate myself?
|
if self.search_string:
|
||||||
total_time: int = 0 # total time of all songs in seconds
|
params = ["%" + self.search_string + "%"] * 3
|
||||||
for row_data in data:
|
if query.find("WHERE") == -1:
|
||||||
# print(row_data)
|
query = f"{query} WHERE {search_clause};"
|
||||||
# if "length" in fields:
|
else:
|
||||||
row_count += 1
|
query = f"{query} AND {search_clause};"
|
||||||
id, *rest_of_data = row_data
|
data = db.query(
|
||||||
# handle different datatypes
|
query,
|
||||||
items = []
|
(params),
|
||||||
for item in rest_of_data:
|
)
|
||||||
if isinstance(item, int):
|
except Exception as e:
|
||||||
std_item = QStandardItem()
|
error(f"load_music_table() | Unhandled exception 2: {e}")
|
||||||
std_item.setData(item, Qt.ItemDataRole.DisplayRole)
|
return
|
||||||
std_item.setData(item, Qt.ItemDataRole.EditRole)
|
# Populate the model
|
||||||
else:
|
# row_count: int = 0
|
||||||
std_item = QStandardItem(str(item) if item else "")
|
# TODO: total time of playlist
|
||||||
items.append(std_item)
|
# but how do i want to do this if user doesn't choose to see length field?
|
||||||
# store database id in the row object using setData
|
# spawn new thread and calculate myself?
|
||||||
# - useful for fast db fetching and other model operations
|
total_time: int = 0 # total time of all songs in seconds
|
||||||
for item in items:
|
for row_data in data:
|
||||||
item.setData(id, Qt.ItemDataRole.UserRole)
|
# print(row_data)
|
||||||
self.model2.appendRow(items)
|
# if "length" in fields:
|
||||||
|
# row_count += 1
|
||||||
|
id, *rest_of_data = row_data
|
||||||
|
# handle different datatypes
|
||||||
|
items = []
|
||||||
|
for item in rest_of_data:
|
||||||
|
if isinstance(item, int):
|
||||||
|
std_item = QStandardItem()
|
||||||
|
std_item.setData(item, Qt.ItemDataRole.DisplayRole)
|
||||||
|
std_item.setData(item, Qt.ItemDataRole.EditRole)
|
||||||
|
else:
|
||||||
|
std_item = QStandardItem(str(item) if item else "")
|
||||||
|
items.append(std_item)
|
||||||
|
# store database id in the row object using setData
|
||||||
|
# - useful for fast db fetching and other model operations
|
||||||
|
for item in items:
|
||||||
|
item.setData(id, Qt.ItemDataRole.UserRole)
|
||||||
|
self.model2.appendRow(items)
|
||||||
|
|
||||||
# reloading the model destroys and makes new indexes
|
# reloading the model destroys and makes new indexes
|
||||||
# so we look for the new index of the current song on load
|
# so we look for the new index of the current song on load
|
||||||
@ -807,7 +821,9 @@ class MusicTable(QTableView):
|
|||||||
|
|
||||||
db_name: str = self.config.get("settings", "db").split("/").pop()
|
db_name: str = self.config.get("settings", "db").split("/").pop()
|
||||||
db_filename = self.config.get("settings", "db")
|
db_filename = self.config.get("settings", "db")
|
||||||
self.playlistStatsSignal.emit(f"Songs: {row_count} | Total time: {total_time} | {db_name} | {db_filename}")
|
# FIXME: total time implementation
|
||||||
|
total_time = 0
|
||||||
|
self.playlistStatsSignal.emit(f"Songs: {self.model2.rowCount()} | Total time: {total_time} | {db_name} | {db_filename}")
|
||||||
self.loadMusicTableSignal.emit()
|
self.loadMusicTableSignal.emit()
|
||||||
self.connect_data_changed()
|
self.connect_data_changed()
|
||||||
self.connect_layout_changed()
|
self.connect_layout_changed()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user