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
|
#include "PackerDialog.h"
#include <QObject>
#include <QMessageBox>
#include <QPushButton>
#include <QStringList>
namespace BsaPacker
{
constexpr uint32_t DIALOG_WIDTH = 240;
constexpr uint32_t DIALOG_HEIGHT = 200;
constexpr uint32_t COMBO_MIN_WIDTH = 100;
constexpr uint32_t LIST_MIN_HEIGHT = 100;
PackerDialog::PackerDialog(const IModContext* modContext) :
m_ModContext(modContext),
buttonsOkCancelMod(QDialogButtonBox::Ok | QDialogButtonBox::Cancel)
{
QPushButton* ok = this->buttonsOkCancelMod.button(QDialogButtonBox::Ok);
ok->setEnabled(false);
this->labelChooseMod.setText(QObject::tr("Choose a mod to pack:"));
this->labelChooseName.setText(QObject::tr("Choose a name for the packed archive:"));
this->resize(DIALOG_WIDTH, DIALOG_HEIGHT);
this->setWindowTitle(QObject::tr("BSA Packer"));
this->comboModList.setMinimumWidth(COMBO_MIN_WIDTH);
this->listArchiveNames.setMinimumHeight(LIST_MIN_HEIGHT);
this->layoutHorizontal.addStretch(1);
this->layoutHorizontal.addWidget(&buttonsOkCancelMod);
this->layoutVertical.addWidget(&labelChooseMod);
this->layoutVertical.addWidget(&comboModList);
this->layoutVertical.addWidget(&labelChooseName);
this->layoutVertical.addWidget(&listArchiveNames);
this->layoutVertical.addLayout(&layoutHorizontal);
this->setLayout(&layoutVertical);
QObject::connect(&listArchiveNames, &QListWidget::itemSelectionChanged, this, &PackerDialog::RefreshOkButton, Qt::QueuedConnection);
QObject::connect(&listArchiveNames, qOverload<QListWidgetItem*>(&QListWidget::itemDoubleClicked), this, &QDialog::accept);
QObject::connect(&buttonsOkCancelMod, &QDialogButtonBox::accepted, this, &QDialog::accept);
QObject::connect(&buttonsOkCancelMod, &QDialogButtonBox::rejected, this, &QDialog::reject);
QObject::connect(&comboModList, qOverload<const QString&>(&QComboBox::currentTextChanged), [this](auto&& text) { this->UpdateNameList(text); });
}
bool PackerDialog::IsNewFilename() const
{
const int currentIndex = this->listArchiveNames.currentIndex().row() + 1;
const int count = this->listArchiveNames.count();
return currentIndex == count;
}
QString PackerDialog::SelectedMod() const
{
return this->comboModList.currentText();
}
QString PackerDialog::SelectedPluginItem() const
{
const QListWidgetItem* const currentItem = this->listArchiveNames.currentItem();
return currentItem != nullptr ? currentItem->text() : QString();
}
void PackerDialog::RefreshModList()
{
const QStringList validMods = this->m_ModContext->GetValidMods();
this->comboModList.clear();
this->comboModList.addItems(validMods);
}
void PackerDialog::UpdateNameList(const QString& modName)
{
this->listArchiveNames.clear();
const QString& modPath = this->m_ModContext->GetAbsoluteModPath(modName);
const QStringList& filenames = this->m_ModContext->GetPlugins(modPath);
this->listArchiveNames.addItems(filenames);
}
int PackerDialog::Exec()
{
return QDialog::exec();
}
void PackerDialog::RefreshSelectedName()
{
Q_EMIT this->comboModList.currentTextChanged(this->comboModList.currentText());
}
void PackerDialog::RefreshOkButton()
{
QPushButton* ok = this->buttonsOkCancelMod.button(QDialogButtonBox::Ok);
ok->setEnabled(this->listArchiveNames.currentItem() != nullptr);
}
} // namespace BsaPacker
|