-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplaylists.cpp
More file actions
152 lines (127 loc) · 5.1 KB
/
playlists.cpp
File metadata and controls
152 lines (127 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2023 by Linwood Ferguson, licensed under GNU GPLv3
#include "playlists.h"
#include "musiclibrary.h"
#include <QVBoxLayout>
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QListView>
#include <QComboBox>
#include <QDebug>
#include <QLabel>
#include <QFrame>
#include "piconstants.h"
#include <cassert>
playLists::playLists(MainWindow* parent, musicLibrary* lib, QString thisTitle, int BookId)
{
// Popup to allow adding and removing of a given title (the one displayed) from a playlist
// Also allows adding a new playlist
qDebug() << "Entered";
mParent = parent;
mMusicLibrary = lib;
mTitle = thisTitle;
mBookID = BookId;
setWindowTitle("Playlists for - " + mTitle);
this->setWindowFlags(Qt::Window|Qt::Dialog);
this->setObjectName("playLists");
this->setStyleSheet("QLabel {background-color: " MUSICALPI_POPUP_BACKGROUND_COLOR "}"
"QFrame {background-color: " MUSICALPI_POPUP_BACKGROUND_COLOR "}"
"playLists {background-color: " MUSICALPI_POPUP_BACKGROUND_COLOR "}"
);
gl = new QGridLayout(this);
titlePrompt= new QLabel(this);
changePrompt = new QLabel(this);
dropdown = new QComboBox(this);
listDropdown = new QListView(dropdown);
dropdown->setObjectName("dropdown");
dropdown->setView(listDropdown);
changeState = new QPushButton(this);
// Show our title
gl->addWidget(titlePrompt,0,0,1,2,Qt::AlignCenter);
// to change lists' contents
gl->addWidget(changePrompt,1,0,1,2,Qt::AlignLeft);
gl->addWidget(dropdown, 2,0,1,1,Qt::AlignLeft); // Note we don't put the qlistview here or for reasons unclear it screws up.
gl->addWidget(changeState, 2,1,1,1,Qt::AlignRight);
// Separator line
hline = new QFrame(this);
hline->setFrameShape(QFrame::HLine);
hline->setFrameShadow(QFrame::Sunken);
gl->addWidget(hline, 3,0,1,2);
hline->setFixedHeight(30);
// To create a new list
addPrompt = new QLabel(this);
newList = new QLineEdit(this);
saveNew = new QPushButton(this);
gl->addWidget(addPrompt,4,0,1,2,Qt::AlignLeft);
gl->addWidget(newList, 5,0,1,1,Qt::AlignLeft);
gl->addWidget(saveNew, 5,1,1,1,Qt::AlignRight);
errorMsg = new QLabel(this);
gl->addWidget(errorMsg, 6,0,1,2,Qt::AlignLeft);
titlePrompt->setText("Song: " + mTitle);
titlePrompt->setProperty("Heading",true);
changePrompt->setText("Use dropdown to pick a list to change as indicated");
changeState->setText("Save");
addPrompt->setText("Use this to add entirely new list (title is added automatically):");
saveNew->setText("Add New");
newList->setText("");
newList->setMinimumWidth(300);
errorMsg->setProperty("ErrorMessage",true);
loadDropdown();
connect(dropdown,SIGNAL(currentIndexChanged(int)),this,SLOT(changeList(int)));
connect(newList,SIGNAL(textChanged(QString)),this,SLOT(newListChanged(QString)));
connect(changeState,SIGNAL(pressed()),this,SLOT(doChangeState()));
connect(saveNew,SIGNAL(pressed()),this,SLOT(doSaveNew()));
this->setLayout(gl);
this->show();
// Do this after show so it sizes appropriately
saveNew->hide();
changeList(mMusicLibrary->ActiveListIndex);
}
void playLists::loadDropdown()
{
// The musicLibrary knows this info already, for loading we just load its dropdown data (which it persists)
dropdown->clear();
dropdown->addItem("Pull down to select list/action",0);
for(int i=1; i < mMusicLibrary->dropdown->count(); i++) // Skip zero which is the "All lists"; if we have no others this is empty
{
if(mMusicLibrary->bookInList(mMusicLibrary->dropdown->itemData((i)).toInt()))
dropdown->addItem("Remove: " + mMusicLibrary->dropdown->itemText(i) + " (already present)",mMusicLibrary->dropdown->itemData(i));
else
dropdown->addItem("Add into: " + mMusicLibrary->dropdown->itemText(i),mMusicLibrary->dropdown->itemData(i));
}
dropdown->setCurrentIndex(mMusicLibrary->ActiveListIndex);
}
void playLists::changeList(int newIndex)
{
qDebug() << "new index = " << newIndex << ", which is " << dropdown->itemText(newIndex) << " with value " << dropdown->itemData(newIndex).toInt();
if(newIndex == 0) changeState->hide();
else changeState->show();
}
void playLists::newListChanged(QString val)
{
if(val == "") saveNew->hide();
else saveNew->show();
}
void playLists::doChangeState()
{
assert(dropdown->currentIndex()); // Shouldn't be able to get here with the zero index as button shoul dbe hidden
QString result;
if(dropdown->currentText().left(3)=="Add") result = mMusicLibrary->addBookToList(dropdown->currentIndex());
else result = mMusicLibrary->removeBookFromList(dropdown->currentIndex());
errorMsg->setText(result);
if(result=="")
{
loadDropdown();
}
}
void playLists::doSaveNew()
{
QString result;
result = mMusicLibrary->addNewList(mMusicLibrary->calibreListPrefix + newList->text());
errorMsg->setText(result);
if(result=="")
{
loadDropdown();
newList->setText("");
}
}