Close playlists; refine opening playlists
This commit is contained in:
parent
ada25eaa26
commit
ffef3cd1c7
27
app/model.py
27
app/model.py
@ -175,6 +175,22 @@ class Playlists(Base):
|
||||
session.commit()
|
||||
return pl.id
|
||||
|
||||
@staticmethod
|
||||
def open(plid):
|
||||
"Record playlist as loaded and used now"
|
||||
|
||||
p = session.query(Playlists).filter(Playlists.id == plid).one()
|
||||
p.loaded = True
|
||||
p.last_used = datetime.now()
|
||||
session.commit()
|
||||
|
||||
def close(plid):
|
||||
"Record playlist as no longer loaded"
|
||||
|
||||
p = session.query(Playlists).filter(Playlists.id == plid).one()
|
||||
p.loaded = False
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def get_last_used():
|
||||
"""
|
||||
@ -193,6 +209,17 @@ class Playlists(Base):
|
||||
|
||||
return session.query(Playlists).all()
|
||||
|
||||
@staticmethod
|
||||
def get_name(plid):
|
||||
"""
|
||||
Return name of playlist with id 'plid'
|
||||
"""
|
||||
|
||||
return (
|
||||
session.query(Playlists.name)
|
||||
.filter(Playlists.id == plid)
|
||||
).one()[0]
|
||||
|
||||
@classmethod
|
||||
def get_playlist_by_id(cls, plid):
|
||||
"Returns a playlist object for playlist id"
|
||||
|
||||
@ -119,11 +119,12 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
def connect_signals_slots(self):
|
||||
self.actionAdd_file.triggered.connect(self.add_file)
|
||||
self.action_Clear_selection.triggered.connect(self.clear_selection)
|
||||
self.actionClosePlaylist.triggered.connect(self.close_playlist)
|
||||
self.actionFade.triggered.connect(self.fade)
|
||||
self.actionNewPlaylist.triggered.connect(self.create_playlist)
|
||||
self.actionOpenPlaylist.triggered.connect(self.select_playlist)
|
||||
self.actionPlay_next.triggered.connect(self.play_next)
|
||||
self.actionSearch_database.triggered.connect(self.search_database)
|
||||
self.actionOpenPlaylist.triggered.connect(self.select_playlist)
|
||||
self.actionSkip_next.triggered.connect(self.play_next)
|
||||
self.actionSkipToEnd.triggered.connect(self.test_skip_to_end)
|
||||
self.actionSkipToFade.triggered.connect(self.test_skip_to_fade)
|
||||
@ -160,6 +161,11 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
|
||||
self.music.set_volume(volume)
|
||||
|
||||
def close_playlist(self):
|
||||
Playlists.close(self.current_playlist().id)
|
||||
index = self.tabPlaylist.currentIndex()
|
||||
self.tabPlaylist.removeTab(index)
|
||||
|
||||
def disable_play_next_controls(self):
|
||||
DEBUG("disable_play_next_controls()")
|
||||
self.actionPlay_next.setEnabled(False)
|
||||
@ -244,12 +250,15 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# Update metadata
|
||||
next_track_id = self.current_playlist().started_playing_next()
|
||||
|
||||
self.next_track = Tracks.get_track(next_track_id)
|
||||
# Check we can read it
|
||||
if not os.access(self.next_track.path, os.R_OK):
|
||||
self.show_warning(
|
||||
"Can't read next track",
|
||||
self.next_track.path)
|
||||
if next_track_id is not None:
|
||||
self.next_track = Tracks.get_track(next_track_id)
|
||||
# Check we can read it
|
||||
if not os.access(self.next_track.path, os.R_OK):
|
||||
self.show_warning(
|
||||
"Can't read next track",
|
||||
self.next_track.path)
|
||||
else:
|
||||
self.next_track = None
|
||||
|
||||
# Tell database to record it as played
|
||||
self.current_track.update_lastplayed()
|
||||
@ -291,6 +300,12 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
def select_playlist(self):
|
||||
dlg = SelectPlaylistDialog(self)
|
||||
dlg.exec()
|
||||
playlist = Playlist()
|
||||
plid = dlg.plid
|
||||
dlg.close()
|
||||
playlist.load_playlist(plid)
|
||||
new_tab = self.tabPlaylist.addTab(playlist, Playlists.get_name(plid))
|
||||
self.tabPlaylist.setCurrentIndex(new_tab)
|
||||
|
||||
def set_next_track(self):
|
||||
"Set selected track as next"
|
||||
@ -543,16 +558,14 @@ class SelectPlaylistDialog(QDialog):
|
||||
self.ui.lstPlaylists.addItem(p)
|
||||
|
||||
def list_doubleclick(self, entry):
|
||||
plid = entry.data(Qt.UserRole)
|
||||
self.parent().load_playlist(plid)
|
||||
self.close()
|
||||
self.plid = entry.data(Qt.UserRole)
|
||||
self.accept()
|
||||
|
||||
def open(self):
|
||||
if self.ui.lstPlaylists.selectedItems():
|
||||
item = self.ui.lstPlaylists.currentItem()
|
||||
plid = item.data(Qt.UserRole)
|
||||
self.parent().load_playlist(plid)
|
||||
self.close()
|
||||
self.plid = item.data(Qt.UserRole)
|
||||
self.accept()
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -80,6 +80,7 @@ class Playlist(QTableWidget):
|
||||
self.customContextMenuRequested.connect(self._context_menu)
|
||||
self.viewport().installEventFilter(self)
|
||||
|
||||
self.id = None
|
||||
self.current_track_start_time = None
|
||||
self.played_tracks = []
|
||||
|
||||
@ -283,6 +284,8 @@ class Playlist(QTableWidget):
|
||||
|
||||
DEBUG(f"load_playlist(plid={plid})")
|
||||
|
||||
self.id = plid
|
||||
Playlists.open(plid)
|
||||
p = Playlists.get_playlist_by_id(plid)
|
||||
|
||||
# We need to retrieve playlist tracks and playlist notes, then
|
||||
@ -456,6 +459,7 @@ class Playlist(QTableWidget):
|
||||
def _mark_next_track(self):
|
||||
"Set up metadata for next track in playlist if there is one."
|
||||
|
||||
found_next_track = False
|
||||
current_row = self._meta_get_current()
|
||||
if current_row is not None:
|
||||
start = current_row + 1
|
||||
@ -466,8 +470,12 @@ class Playlist(QTableWidget):
|
||||
if row in notes_rows:
|
||||
continue
|
||||
self._meta_set_next(row)
|
||||
found_next_track = True
|
||||
break
|
||||
|
||||
if not found_next_track:
|
||||
return None
|
||||
|
||||
self._repaint()
|
||||
|
||||
track_id = self._get_row_id(row)
|
||||
|
||||
@ -929,7 +929,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
</action>
|
||||
<action name="actionClosePlaylist">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Close</string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user