Skip to content

Commit

Permalink
fix: prevent accidental playlist overwrite if placeholder is not avai…
Browse files Browse the repository at this point in the history
…lable
  • Loading branch information
vzhd1701 committed Oct 16, 2021
1 parent 72cd11b commit f686e6e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions gridplayer/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ def cmd_save_playlist(self):
if self.saved_playlist is not None:
save_path = self.saved_playlist["path"]
else:
save_path = os.path.join(QtCore.QDir.currentPath(), "Untitled.gpls")
save_path = os.path.join(QtCore.QDir.homePath(), "Untitled.gpls")

logger.debug(f"Proposed playlist save path: {save_path}")

with ModalWindow(self):
file_path = QtWidgets.QFileDialog.getSaveFileName(
Expand All @@ -800,8 +802,21 @@ def cmd_save_playlist(self):
if file_path[0]:
file_path = os.path.abspath(file_path[0])

# if not file_path.endswith(".gpls"):
# file_path += ".gpls"
# filename placeholder is not available if file doesn't exist
# problematic for new playlists, need to prevent accidental overwrite
# occurs in Flatpak, maybe in other sandboxes that use portal
if not file_path.endswith(".gpls"):
file_path += ".gpls"

if os.path.isfile(file_path):
file = os.path.basename(file_path)
with ModalWindow(self):
ret = QCustomMessageBox.question(
self, "Playlist", f"Do you want to overwrite {file}?"
)

if ret != QMessageBox.Yes:
return

save_playlist(file_path, playlist)

Expand Down

0 comments on commit f686e6e

Please sign in to comment.