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
|
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
This file is part of Mod Organizer.
Mod Organizer 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 3 of the License, or
(at your option) any later version.
Mod Organizer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ui_baincomplexinstallerdialog.h"
#include <QCompleter>
#include <uibase/textviewer.h>
#include "baincomplexinstallerdialog.h"
using namespace MOBase;
BainComplexInstallerDialog::BainComplexInstallerDialog(
const std::vector<std::shared_ptr<const MOBase::FileTreeEntry>>& subpackages,
const GuessedValue<QString>& modName, const QStringList& defaultOptions,
const QString& packageTXT, QWidget* parent)
: TutorableDialog("BainInstaller", parent), ui(new Ui::BainComplexInstallerDialog),
m_Manual(false), m_PackageTXT(packageTXT)
{
ui->setupUi(this);
for (auto iter = modName.variants().begin(); iter != modName.variants().end();
++iter) {
ui->nameCombo->addItem(*iter);
}
ui->nameCombo->setCurrentIndex(ui->nameCombo->findText(modName));
for (const auto& subpackage : subpackages) {
auto name = subpackage->name();
QListWidgetItem* item = new QListWidgetItem(name, ui->optionsList);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if (name.mid(0, 2) == "00" || defaultOptions.contains(name, Qt::CaseInsensitive)) {
item->setCheckState(Qt::Checked);
} else {
item->setCheckState(Qt::Unchecked);
}
ui->optionsList->addItem(item);
}
ui->packageBtn->setEnabled(!packageTXT.isEmpty());
ui->nameCombo->completer()->setCaseSensitivity(Qt::CaseSensitive);
}
BainComplexInstallerDialog::~BainComplexInstallerDialog()
{
delete ui;
}
QString BainComplexInstallerDialog::getName() const
{
return ui->nameCombo->currentText();
}
QStringList BainComplexInstallerDialog::updateTree(std::shared_ptr<IFileTree>& tree)
{
// Retrieve the list of selected names:
std::set<QString, FileNameComparator> selectedNames;
for (int i = 0; i < ui->optionsList->count(); ++i) {
QListWidgetItem* item = ui->optionsList->item(i);
if (item->checkState() == Qt::Checked) {
selectedNames.insert(item->text());
}
}
// Create a new empty tree and merge all the selected folder in it:
auto newTree = tree->createOrphanTree();
for (auto& entry : *tree) {
if (entry->isDir() && selectedNames.count(entry->name()) > 0) {
newTree->merge(entry->astree());
}
}
tree = newTree;
return QStringList(selectedNames.begin(), selectedNames.end());
}
void BainComplexInstallerDialog::on_okBtn_clicked()
{
this->accept();
}
void BainComplexInstallerDialog::on_cancelBtn_clicked()
{
this->reject();
}
void BainComplexInstallerDialog::on_manualBtn_clicked()
{
m_Manual = true;
this->reject();
}
void BainComplexInstallerDialog::on_packageBtn_clicked()
{
TextViewer viewer(m_PackageTXT, this);
viewer.setDescription("");
viewer.addFile(m_PackageTXT, false);
viewer.exec();
}
|