-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrarydialog.cpp
More file actions
284 lines (247 loc) · 12 KB
/
librarydialog.cpp
File metadata and controls
284 lines (247 loc) · 12 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include "librarydialog.h"
#include <QApplication>
#include <QFileInfo>
#include <QDebug>
LibraryDialog::LibraryDialog(QWidget *parent)
: QDialog(parent)
{
setWindowTitle("WakkaQt \xe2\x80\x94 Session Library");
setMinimumSize(660, 440);
resize(740, 520);
// ── Header ────────────────────────────────────────────────────────────
QLabel *headerLabel = new QLabel(
"<b>Session Library</b><br>"
"<small>Every recording is saved automatically. "
"Select a session and press <b>Resume Session</b> to re-adjust and re-render. "
"Use Ctrl+click or Shift+click to select multiple sessions for bulk deletion.</small>",
this);
headerLabel->setWordWrap(true);
headerLabel->setAlignment(Qt::AlignCenter);
headerLabel->setContentsMargins(0, 4, 0, 8);
// ── Session list ──────────────────────────────────────────────────────
m_list = new QListWidget(this);
m_list->setAlternatingRowColors(true);
m_list->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_list->setFont(QApplication::font());
// ── Detail panel ─────────────────────────────────────────────────────
m_detailLabel = new QLabel("Select a session to see details.", this);
m_detailLabel->setWordWrap(true);
m_detailLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
m_detailLabel->setMinimumHeight(72);
m_detailLabel->setTextFormat(Qt::RichText);
m_detailLabel->setStyleSheet("padding: 6px; border-top: 1px solid palette(mid);");
// ── Buttons ───────────────────────────────────────────────────────────
m_restoreBtn = new QPushButton("\xe2\x96\xb6 Resume Session", this);
m_restoreBtn->setToolTip("Restore this session and go to volume/offset adjustment and rendering");
m_restoreBtn->setEnabled(false);
m_renameBtn = new QPushButton("\xe2\x9c\x8e Rename", this);
m_renameBtn->setToolTip("Give this session a custom label");
m_renameBtn->setEnabled(false);
m_deleteBtn = new QPushButton("\xe2\x9c\x95 Delete", this);
m_deleteBtn->setToolTip("Permanently remove selected session(s) from the library (Ctrl+click to multi-select)");
m_deleteBtn->setEnabled(false);
m_closeBtn = new QPushButton("Close", this);
QHBoxLayout *btnRow = new QHBoxLayout;
btnRow->addWidget(m_restoreBtn);
btnRow->addWidget(m_renameBtn);
btnRow->addWidget(m_deleteBtn);
btnRow->addStretch();
btnRow->addWidget(m_closeBtn);
// ── Main layout ───────────────────────────────────────────────────────
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(headerLabel);
layout->addWidget(m_list, 1);
layout->addWidget(m_detailLabel);
layout->addSpacing(6);
layout->addLayout(btnRow);
setLayout(layout);
// ── Connections ───────────────────────────────────────────────────────
connect(m_list, &QListWidget::itemSelectionChanged,
this, &LibraryDialog::onSelectionChanged);
connect(m_list, &QListWidget::itemDoubleClicked,
this, &LibraryDialog::onRestoreClicked);
connect(m_restoreBtn, &QPushButton::clicked,
this, &LibraryDialog::onRestoreClicked);
connect(m_deleteBtn, &QPushButton::clicked,
this, &LibraryDialog::onDeleteClicked);
connect(m_renameBtn, &QPushButton::clicked,
this, &LibraryDialog::onRenameClicked);
connect(m_closeBtn, &QPushButton::clicked,
this, &QDialog::reject);
refreshList();
}
// ── refreshList ───────────────────────────────────────────────────────────────
void LibraryDialog::refreshList()
{
m_list->blockSignals(true);
m_list->clear();
m_entries = m_mgr.loadAll();
m_list->blockSignals(false);
if (m_entries.isEmpty()) {
QListWidgetItem *empty = new QListWidgetItem(
" (No sessions saved yet — sing something first!)");
empty->setFlags(Qt::NoItemFlags); // not selectable
m_list->addItem(empty);
m_detailLabel->setText(
"Sessions are saved automatically every time you reach the render step.<br>"
"They will appear here, ready to be restored at any time.");
m_restoreBtn->setEnabled(false);
m_deleteBtn->setEnabled(false);
m_renameBtn->setEnabled(false);
return;
}
for (const SessionEntry &e : m_entries) {
const QString line = QString("[%1] %2")
.arg(e.savedAt.toString("yyyy-MM-dd hh:mm"))
.arg(e.label);
QListWidgetItem *item = new QListWidgetItem(line);
item->setData(Qt::UserRole, e.id);
applyRowStyle(item, e);
m_list->addItem(item);
}
// Auto-select first row for convenience
if (m_list->count() > 0)
m_list->setCurrentRow(0);
}
// ── applyRowStyle ─────────────────────────────────────────────────────────────
void LibraryDialog::applyRowStyle(QListWidgetItem *item, const SessionEntry &entry)
{
const bool incomplete = !entry.hasAudio || !entry.hasWebcam;
if (incomplete) {
item->setForeground(QColor(180, 100, 90));
item->setToolTip("\xe2\x9a\xa0 Some recording files are missing for this session.");
} else {
item->setToolTip("Double-click or press \xe2\x80\x98Resume Session\xe2\x80\x99 to restore.");
}
}
// ── selectedId ────────────────────────────────────────────────────────────────
// Helper: returns the library id of the currently selected row, or empty.
static QString selectedId(QListWidget *list)
{
const QList<QListWidgetItem*> sel = list->selectedItems();
if (sel.isEmpty()) return {};
if (!(sel.first()->flags() & Qt::ItemIsSelectable)) return {};
return sel.first()->data(Qt::UserRole).toString();
}
// ── onSelectionChanged ────────────────────────────────────────────────────────
void LibraryDialog::onSelectionChanged()
{
// Count only rows that are actually selectable (filters out the empty-list placeholder)
int selectableCount = 0;
for (QListWidgetItem *item : m_list->selectedItems())
if (item->flags() & Qt::ItemIsSelectable)
++selectableCount;
// Restore and Rename require exactly one session; Delete works for any non-zero count.
m_restoreBtn->setEnabled(selectableCount == 1);
m_renameBtn->setEnabled(selectableCount == 1);
m_deleteBtn->setEnabled(selectableCount >= 1);
if (selectableCount == 0) {
m_detailLabel->setText("Select a session to see details.");
return;
}
if (selectableCount > 1) {
m_detailLabel->setText(
QString("<b>%1 sessions selected.</b><br>"
"<span style='color: gray;'>Press <b>Delete</b> to remove all of them.</span>")
.arg(selectableCount));
return;
}
// Exactly one — show full detail
const QString id = ::selectedId(m_list);
for (const SessionEntry &e : m_entries) {
if (e.id != id) continue;
const QString playbackInfo = e.playbackFile.isEmpty()
? QString("(original file path not recorded)")
: QFileInfo(e.playbackFile).fileName();
const QString filesStr =
(e.hasAudio && e.hasWebcam) ? "\xe2\x9c\x94 Vocal + Webcam"
: e.hasAudio ? "\xe2\x9c\x94 Vocal only (webcam missing)"
: e.hasWebcam ? "\xe2\x9c\x94 Webcam only (vocal missing)"
: "\xe2\x9a\xa0 Missing recording files";
m_detailLabel->setText(
QString("<b>Song / Media:</b> %1<br>"
"<b>Saved:</b> %2<br>"
"<b>Files:</b> %3 "
"<span style='color: gray; font-size: 10px;'>ID: %4</span>")
.arg(e.playbackName.isEmpty() ? playbackInfo : e.playbackName)
.arg(e.savedAt.toString("dddd, d MMMM yyyy \xe2\x80\x93 hh:mm:ss"))
.arg(filesStr)
.arg(e.id)
);
break;
}
}
// ── onRestoreClicked ──────────────────────────────────────────────────────────
void LibraryDialog::onRestoreClicked()
{
const QString id = ::selectedId(m_list);
if (id.isEmpty()) return;
m_selectedId = id;
emit sessionRestoreRequested(id);
accept();
}
// ── onDeleteClicked ───────────────────────────────────────────────────────────
void LibraryDialog::onDeleteClicked()
{
// Collect all selected, selectable ids
QStringList ids;
for (QListWidgetItem *item : m_list->selectedItems()) {
if (!(item->flags() & Qt::ItemIsSelectable)) continue;
const QString id = item->data(Qt::UserRole).toString();
if (!id.isEmpty())
ids << id;
}
if (ids.isEmpty()) return;
QString confirmMsg;
if (ids.size() == 1) {
QString label;
for (const SessionEntry &e : m_entries)
if (e.id == ids.first()) { label = e.label; break; }
confirmMsg = QString("Permanently delete this session?\n\n\"%1\"\n\nThis cannot be undone.")
.arg(label);
} else {
confirmMsg = QString("Permanently delete %1 sessions?\n\nThis cannot be undone.")
.arg(ids.size());
}
const int ret = QMessageBox::question(
this, "Delete Session", confirmMsg,
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (ret == QMessageBox::Yes) {
for (const QString &id : ids)
m_mgr.deleteSession(id);
m_detailLabel->setText(
ids.size() == 1 ? "Session deleted."
: QString("%1 sessions deleted.").arg(ids.size()));
refreshList();
}
}
// ── onRenameClicked ───────────────────────────────────────────────────────────
void LibraryDialog::onRenameClicked()
{
const QString id = ::selectedId(m_list);
if (id.isEmpty()) return;
QString currentLabel;
for (const SessionEntry &e : m_entries)
if (e.id == id) { currentLabel = e.label; break; }
bool ok = false;
const QString newName = QInputDialog::getText(
this,
"Rename Session",
"New session name:",
QLineEdit::Normal,
currentLabel,
&ok);
if (ok && !newName.trimmed().isEmpty()) {
m_mgr.renameSession(id, newName.trimmed());
const QString savedId = id; // refreshList clears the list
refreshList();
// Re-select the same entry
for (int i = 0; i < m_list->count(); ++i) {
if (m_list->item(i)->data(Qt::UserRole).toString() == savedId) {
m_list->setCurrentRow(i);
break;
}
}
}
}