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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#include <QComboBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QRadioButton>
#include <QPushButton>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QTextEdit>
#include <QCompleter>
#include <QStandardItemModel>
#include <QFormLayout>
#include <QApplication>
#include "archiveview.h"
#include "smglobals.h"
#include "helper.h"
/* Mapping Editor Widget */
MappingEditorWidget::MappingEditorWidget(const QString &caption, bool showClearButton, QWidget *parent) : QWidget(parent), mCaption(caption){
// the view
mModel = new QStandardItemModel(this);
mModel->setHorizontalHeaderItem(0, new QStandardItem(mCaption));
mProxy = new QSortFilterProxyModel(this);
mProxy->setSourceModel(mModel);
QVBoxLayout *viewLayout = new QVBoxLayout;
mView = new SmTreeView;
viewLayout->addWidget(mView);
mView->setModel(mProxy);
mView->setSortingEnabled(true);
// line editor
QHBoxLayout *editLayout = new QHBoxLayout;
QLabel *l2 = new QLabel(tr("Add:"));
mEditor = new QLineEdit;
mCompleter = new QCompleter(this);
mCompleterModel = new QStringListModel(this);
mCompleter->setModel(mCompleterModel);
mEditor->setCompleter(mCompleter);
editLayout->addWidget(l2);
editLayout->addWidget(mEditor);
// edit buttons
QHBoxLayout *editButtonLayout = new QHBoxLayout;
editButtonLayout->addStretch();
mClear = new QPushButton(tr("Clear"));
connect(mClear, &QPushButton::clicked, this, &MappingEditorWidget::clear);
if(showClearButton){
editButtonLayout->addWidget(mClear);
}
mRemove = new QPushButton(tr("&Remove"));
connect(mRemove, &QPushButton::clicked, this, &MappingEditorWidget::removeItem);
editButtonLayout->addWidget(mRemove);
mAdd = new QPushButton(tr("&Add"));
connect(mAdd, &QPushButton::clicked, this, &MappingEditorWidget::addItem);
editButtonLayout->addWidget(mAdd);
// main layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(viewLayout);
mainLayout->addLayout(editLayout);
mainLayout->addLayout(editButtonLayout);
setLayout(mainLayout);
}
void MappingEditorWidget::fillCompleter(const QStringList &completions){
mCompleterModel->setStringList(completions);
}
void MappingEditorWidget::setCurrentItems(const QStringList &items){
for(const QString &i : items){
QStandardItem *item = new QStandardItem(i);
item->setIcon(mDecorationIcon);
mModel->appendRow(item);
}
}
QStringList MappingEditorWidget::items() const{
QStringList retval;
for(int i = 0; i < mModel->rowCount(); ++i){
QStandardItem *item = mModel->item(i);
retval << item->text();
}
return retval;
}
void MappingEditorWidget::clear(){
mModel->clear();
mModel->setHorizontalHeaderItem(0, new QStandardItem(mCaption));
mEditor->clear();
}
void MappingEditorWidget::addItem(){
QString itemName = mEditor->text();
if(itemName.isEmpty()){
return;
}
QList<QStandardItem*> found = mModel->findItems(itemName, Qt::MatchFixedString);
if(found.size()){
return;
}
QStandardItem *newItem = new QStandardItem(itemName);
newItem->setIcon(mDecorationIcon);
mModel->appendRow(newItem);
mProxy->sort(0, mProxy->sortOrder());
mEditor->clear();
}
void MappingEditorWidget::removeItem(){
QModelIndexList sel = mView->selectionModel()->selectedRows();
if(sel.isEmpty()){
return;
}
QModelIndex real = mProxy->mapToSource(sel.first());
mModel->removeRow(real.row());
}
/* Mapping Editor */
MappingEditor::MappingEditor(const QString &caption, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) {
// Mapping Editor Widget
mWidget = new MappingEditorWidget(caption);
// buttons
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
mCancel = new QPushButton(tr("Cancel"));
connect(mCancel, &QPushButton::clicked, this, &MappingEditor::reject);
buttonLayout->addWidget(mCancel);
mAccept = new QPushButton(tr("Accept"));
connect(mAccept, &QPushButton::clicked, this, &MappingEditor::accept);
buttonLayout->addWidget(mAccept);
// dialog layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mWidget);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setMinimumWidth(300);
}
/* Metadata Editor Widget */
MetadataEditorWidget::MetadataEditorWidget(QWidget *parent) : QWidget(parent){
QLabel *captionL = new QLabel(tr("<b>Edit Metadata</b>"));
QGroupBox *genGB = new QGroupBox(tr("General"));
QFormLayout *genGBL = new QFormLayout;
mReleaseYear = new QSpinBox;
mReleaseYear->setMinimum(1900);
mReleaseYear->setMaximum(3000);
mReleaseYear->setValue(QDate::currentDate().year());
genGBL->addRow(tr("&Release Year"), mReleaseYear);
mSubject = new QLineEdit;
genGBL->addRow(tr("Name/Sub&ject"), mSubject);
genGB->setLayout(genGBL);
QGroupBox *srcGB = new QGroupBox(tr("Source"));
QHBoxLayout *srcGBL = new QHBoxLayout;
mTorrent = new QRadioButton(tr("BitTorrent"));
mTorrent->toggle();
mUsenet = new QRadioButton(tr("Usenet"));
srcGBL->addWidget(mTorrent);
srcGBL->addWidget(mUsenet);
srcGBL->addStretch();
srcGB->setLayout(srcGBL);
QGroupBox *reasonGB = new QGroupBox(tr("Reencode reason"));
QVBoxLayout *reasonGBL = new QVBoxLayout;
mReencReason = new QComboBox;
QStringList reasons = SmGlobals::instance()->reencReasons();
mReencReason->addItems(reasons);
connect(mReencReason, QOverload<const QString &>::of(&QComboBox::activated), this, &MetadataEditorWidget::addToComment);
QPushButton *clearB = new QPushButton(tr("Clear"));
reasonGBL->addWidget(mReencReason);
reasonGBL->addWidget(clearB);
reasonGBL->addStretch();
reasonGB->setLayout(reasonGBL);
QHBoxLayout *srcReasonL = new QHBoxLayout;
srcReasonL->addWidget(srcGB);
//comment
QGroupBox *commentGB = new QGroupBox(tr("Comment"));
mComment = new QTextEdit;
QHBoxLayout *commentGBL = new QHBoxLayout;
commentGBL->addWidget(mComment);
commentGBL->addWidget(reasonGB);
commentGB->setLayout(commentGBL);
connect(clearB, &QPushButton::clicked, [this] { mComment->clear(); });
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(captionL);
mainLayout->addWidget(genGB);
mainLayout->addLayout(srcReasonL);
mainLayout->addWidget(commentGB);
setLayout(mainLayout);
}
void MetadataEditorWidget::setMetadata(const QList<QVariant> &data){
mReleaseYear->setValue(data.at(ArchiveModel::ReleaseYear).toInt());
QString src = data.at(ArchiveModel::Source).toString();
if(src == "torrent"){
mTorrent->toggle();
}else{
mUsenet->toggle();
}
mSubject->setText(data.at(ArchiveModel::Subject).toString());
mComment->setText(data.at(ArchiveModel::Comment).toString());
mAdded = data.at(ArchiveModel::Added).toDate();
}
QList<QVariant> MetadataEditorWidget::metadata() const{
QList<QVariant> retval;
for(int i = 0; i < ArchiveModel::MetadataNumFields; ++i){
retval << QVariant();
}
retval[ArchiveModel::ReleaseYear] = mReleaseYear->value();
QString source = "torrent";
if(mUsenet->isChecked()){
source = "Usenet";
}
retval[ArchiveModel::Source] = source;
retval[ArchiveModel::Subject] = mSubject->text();
retval[ArchiveModel::Comment] = mComment->toPlainText();
retval[ArchiveModel::Added] = mAdded;
return retval;
}
void MetadataEditorWidget::addToComment(const QString &reason){
mComment->append(reason);
}
/* Metadata Editor */
MetadataEditor::MetadataEditor(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
mWidget = new MetadataEditorWidget;
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
mCancel = new QPushButton(tr("Cancel"));
connect(mCancel, &QPushButton::clicked, this, &MetadataEditor::reject);
buttonLayout->addWidget(mCancel);
mAccept = new QPushButton(tr("Accept"));
connect(mAccept, &QPushButton::clicked, this, &MetadataEditor::accept);
buttonLayout->addWidget(mAccept);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mWidget);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setMinimumWidth(400);
}
/* Part Editor */
PartEditor::PartEditor(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
QLabel *captionL = new QLabel(tr("Edit part"));
QFormLayout *editLayout = new QFormLayout;
// part no
mPartNo = new QSpinBox;
mPartNo->setMinimum(0);
mPartNo->setMaximum(1024);
editLayout->addRow(tr("Part &no"), mPartNo);
// subtitle
mSubtitle = new QLineEdit;
editLayout->addRow(tr("&Subtitle"), mSubtitle);
// buttons
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
mCancel = new QPushButton(tr("Cancel"));
connect(mCancel, &QPushButton::clicked, this, &PartEditor::reject);
mAccept = new QPushButton(tr("Accept"));
connect(mAccept, &QPushButton::clicked, this, &PartEditor::accept);
buttonLayout->addWidget(mCancel);
buttonLayout->addWidget(mAccept);
// main layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(captionL);
mainLayout->addLayout(editLayout);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
}
void PartEditor::setPartNo(int partNo){
mPartNo->setValue(partNo);
}
int PartEditor::partNo() const {
return mPartNo->value();
}
void PartEditor::setSubtitle(const QString &subtitle){
mSubtitle->setText(subtitle);
}
QString PartEditor::subtitle() const {
return mSubtitle->text();
}
|