forked from Wobbl/Wobuzz
Implemented sorting by track title, artist name etc...
(Sorting order is not getting saved.)
This commit is contained in:
parent
1b69321c05
commit
3dd9123332
3 changed files with 100 additions and 21 deletions
|
@ -22,7 +22,15 @@ class Playlist:
|
|||
# no other playlist can be created using the same name
|
||||
self.app.utils.unique_names.append(self.title)
|
||||
|
||||
self.sorting: list[Qt.SortOrder] | None = None # Custom sort order if None
|
||||
# the number is the index of the header section,
|
||||
# the bool is the sorting order (True = ascending, False = descending)
|
||||
self.sorting: list[tuple[int, bool]] = [
|
||||
(0, True),
|
||||
(1, True),
|
||||
(2, True),
|
||||
(3, True),
|
||||
(4, True)
|
||||
]
|
||||
self.tracks: list[Track] = []
|
||||
self.current_track_index = 0
|
||||
self.current_track: Track | None = None
|
||||
|
@ -127,6 +135,30 @@ class Playlist:
|
|||
|
||||
def load_from_wbz(self, path):
|
||||
self.load_from_m3u(path) # placeholder
|
||||
|
||||
def sync(self, view, user_sort: bool=False):
|
||||
num_tracks = view.topLevelItemCount()
|
||||
|
||||
i = 0
|
||||
|
||||
while i < num_tracks:
|
||||
track_item = view.topLevelItem(i)
|
||||
track = track_item.track
|
||||
|
||||
track_item.index = i
|
||||
|
||||
if user_sort:
|
||||
track_item.index_user_sort = i
|
||||
|
||||
self.tracks[i] = track
|
||||
|
||||
track.set_occurrences()
|
||||
|
||||
i += 1
|
||||
|
||||
# make sure the next track is cached (could be moved by user)
|
||||
if self.app.player.current_playlist == self and self.has_tracks():
|
||||
self.app.player.cache_next_track()
|
||||
|
||||
def has_tracks(self):
|
||||
return len(self.tracks) > 0
|
||||
|
@ -169,7 +201,12 @@ class Playlist:
|
|||
return self.current_track.sound, self.current_track.duration
|
||||
|
||||
def save(self):
|
||||
wbz_data = ""
|
||||
|
||||
first_view = list(self.views.values())[0]
|
||||
first_view.sortItems(4, Qt.SortOrder.AscendingOrder)
|
||||
self.sync(first_view)
|
||||
|
||||
wbz_data = "#WOBUZZM3U\n"
|
||||
|
||||
for track in self.tracks:
|
||||
wbz_data += f"{track.path}\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue