Skip to content

Commit

Permalink
Save changes on close
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed May 9, 2020
1 parent b01cf2a commit 8fa14ee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class MainWindow : public QMainWindow
QString currentLibraryItem();
void reloadTrayIcon();
spt::User getCurrentUser();
void refreshPlaylists();
// I know these should be methods, I'm just lazy
QString cacheLocation;
QVector<spt::Playlist> *sptPlaylists;
Expand Down Expand Up @@ -117,7 +118,6 @@ class MainWindow : public QMainWindow
// Methods
QWidget *createCentralWidget();
QToolBar *createToolBar();
void refreshPlaylists();
bool loadSongs(const QVector<spt::Track> &tracks);
void setAlbumImage(const QString &url);
static QString formatTime(int ms);
Expand Down
19 changes: 16 additions & 3 deletions src/playlisteditdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "playlisteditdialog.hpp"

PlaylistEditDialog::PlaylistEditDialog(const spt::Playlist &playlist, int selectedIndex, QWidget *parent)
PlaylistEditDialog::PlaylistEditDialog(spt::Spotify *spotify, const spt::Playlist &playlist,
int selectedIndex, QWidget *parent)
: QDialog(parent)
{
setWindowTitle(playlist.name);
Expand Down Expand Up @@ -34,8 +35,20 @@ PlaylistEditDialog::PlaylistEditDialog(const spt::Playlist &playlist, int select
// Dialog buttons
auto buttons = new QDialogButtonBox(this);
buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QDialogButtonBox::connect(buttons, &QDialogButtonBox::accepted, [this] {
accept();
QDialogButtonBox::connect(buttons, &QDialogButtonBox::accepted, [this, playlist, spotify] {
auto pl = playlist;
pl.name = name->text();
pl.description = description->toPlainText();
pl.isPublic = isPublic->isChecked();
pl.collaborative = isCollaborative->isChecked();
auto result = spotify->editPlaylist(pl);
if (result.isEmpty())
{
accept();
return;
}
QMessageBox::warning(this, "Edit failed",
QString("Failed to save changes: %1").arg(result));
});
QDialogButtonBox::connect(buttons, &QDialogButtonBox::rejected, [this] {
reject();
Expand Down
4 changes: 3 additions & 1 deletion src/playlisteditdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#include <QPushButton>
#include <QDialogButtonBox>
#include <QCheckBox>
#include <QMessageBox>

class PlaylistEditDialog : public QDialog
{
Q_OBJECT

public:
PlaylistEditDialog(const spt::Playlist &playlist, int selectedIndex, QWidget *parent = nullptr);
PlaylistEditDialog(spt::Spotify *spotify, const spt::Playlist &playlist,
int selectedIndex, QWidget *parent = nullptr);

private:
QLineEdit *name;
Expand Down
8 changes: 5 additions & 3 deletions src/playlistmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ PlaylistMenu::PlaylistMenu(spt::Spotify &spotify, const spt::Playlist &playlist,
window->setStatus(status, true);
});
if (isOwner)
QAction::connect(addAction(Icon::get("document-edit"), "Edit"), &QAction::triggered, [this, playlist](bool checked)
QAction::connect(addAction(Icon::get("document-edit"), "Edit"), &QAction::triggered,
[this, playlist, &spotify, window](bool checked)
{
if (editDialog != nullptr)
delete editDialog;
editDialog = new PlaylistEditDialog(playlist, -1, parentWidget());
editDialog->show();
editDialog = new PlaylistEditDialog(&spotify, playlist, -1, parentWidget());
if (editDialog->exec() == QDialog::Accepted)
window->refreshPlaylists();
});
auto share = addMenu(Icon::get("document-share"), "Share");
auto sharePlaylist = share->addAction("Copy playlist link");
Expand Down

0 comments on commit 8fa14ee

Please sign in to comment.