From 3b2e113401a490f6273b6690f517343cc7356cd6 Mon Sep 17 00:00:00 2001 From: Nikolay Tischenko Date: Mon, 27 Sep 2010 15:17:29 +0700 Subject: [PATCH] Optionally appending current playlist to selected playlist if it exists --- src/mainwindow.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 63017be..e365dc1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -119,9 +119,30 @@ void MainWindow::_add_directory() { void MainWindow::_save_playlist() { QString name = QInputDialog::getText(this, "Playlist name", "Name:"); - Playlist playlist = _library->getCurrentPlaylist(); - playlist.setName(name); - _library->savePlaylist(playlist); + QList playlists = _library->getPlaylistsNames(); + bool append = false; + if (playlists.contains(name)) { + if (QMessageBox::question(this, "Append to playlist?", "Playlist with name \""+name+"\" already exists.\n" + "Dow you want to append current playlist to it?", + QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) { + append = true; + } else { + append = false; + } + } + if (append) { + Playlist cur = _library->getCurrentPlaylist(); + Playlist target = _library->getPlaylist(name); + QList tracks = cur.tracks(); + foreach (Track track, tracks) { + target.addTrack(track); + } + _library->savePlaylist(target); + } else { + Playlist playlist = _library->getCurrentPlaylist(); + playlist.setName(name); + _library->savePlaylist(playlist); + } } void MainWindow::_clear_current_playlist() { -- 1.7.9.5