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