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
|
#ifndef FOMODINSTALLERWINDOW_H
#define FOMODINSTALLERWINDOW_H
#include <qboxlayout.h>
#include <qbuttongroup.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qtextedit.h>
#include "FomodPlusInstaller.h"
#include "xml/ModuleConfiguration.h"
#include <QDialog>
#include <QStackedWidget>
#include <qradiobutton.h>
#include <ui/ScaleLabel.h>
#include "FomodInstallerWindow.h"
#include "lib/FileInstaller.h"
#include "ui/FomodViewModel.h"
#include "ui/Colors.h"
#include <QSplitter>
using namespace MOBase;
struct PluginData {
std::shared_ptr<PluginViewModel> plugin;
QAbstractButton* uiElement;
};
class FomodPlusInstaller;
/**
* @class FomodInstallerWindow
* @brief This class represents a window for the FOMOD installer.
*
* The FomodInstallerWindow class is designed to handle and manage the FOMOD installation
* process. It integrates functionalities specific to FOMOD package installations.
* By inheriting from QObject, it supports signal-slot mechanisms, enabling interaction
* and communication with other components in the application.
*
* This class is primarily intended to provide a user interface and functionality
* to process and run the FOMOD installer in a structured manner.
*/
class FomodInstallerWindow final : public QDialog {
Q_OBJECT
public:
FomodInstallerWindow(FomodPlusInstaller* installer,
GuessedValue<QString>& modName,
const std::shared_ptr<IFileTree>& tree,
QString fomodPath,
const std::shared_ptr<FomodViewModel>& viewModel,
const nlohmann::json& fomodJson,
QWidget* parent = nullptr);
void closeEvent(QCloseEvent* event) override;
void saveGeometryAndState() const;
void restoreGeometryAndState();
void populatePluginMap();
// So FomodPlusInstaller can check if the user wants to manually install
[[nodiscard]] bool isManualInstall() const
{
return mIsManualInstall;
}
[[nodiscard]] std::shared_ptr<FileInstaller> getFileInstaller() const { return mViewModel->getFileInstaller(); }
private slots:
void onNextClicked();
void updateCheckboxStates() const;
void onPluginToggled(bool selected, const std::shared_ptr<GroupViewModel>& group,
const std::shared_ptr<PluginViewModel>& plugin) const;
void onPluginManuallyUnchecked(const std::shared_ptr<PluginViewModel>& plugin) const;
void onPluginHovered(const std::shared_ptr<PluginViewModel>& plugin) const;
void onSelectPreviousClicked() const { this->selectPreviouslySelectedOptions(); }
void onResetChoicesClicked();
void onBackClicked() const;
void onCancelClicked()
{
this->saveGeometryAndState();
this->reject();
}
void onManualClicked()
{
mIsManualInstall = true;
this->saveGeometryAndState();
this->reject();
}
void onInstallClicked();
[[deprecated]] void toggleImagesShown() const;
private:
Logger& log = Logger::getInstance();
FomodPlusInstaller* mInstaller;
QString mFomodPath;
GuessedValue<QString>& mModName;
std::shared_ptr<IFileTree> mTree;
std::shared_ptr<FomodViewModel> mViewModel;
bool mInitialized{ false };
std::unordered_map<QString, PluginData> mPluginMap;
// Meta
bool mIsManualInstall{};
nlohmann::json mFomodJson;
// Buttons
QPushButton* mNextInstallButton{};
QPushButton* mBackButton{};
QPushButton* mCancelButton{};
QPushButton* mManualButton{};
QPushButton* mSelectPreviousButton{};
QPushButton* mResetChoicesButton{};
QPushButton* mHideImagesButton{};
// Widgets
QComboBox* mModNameInput{};
QLabel* mDescriptionBox{};
QSplitter* mCenterRow{};
QSplitter* mLeftPane{};
QStackedWidget* mInstallStepStack{};
QTextEdit* mNotificationsPanel{};
QWidget* mBottomRow{};
QWidget* mTopRow{};
ScaleLabel* mImageLabel{};
// Fn
void setupUi();
void updateButtons() const;
void updateInstallStepStack();
void updateDisplayForActivePlugin() const;
void applyFnFromJson(const std::string& pluginSelector, const std::function<void(QAbstractButton*)> &fn);
void stylePreviouslySelectedOptions();
void stylePreviouslyDeselectedOptions();
void selectPreviouslySelectedOptions() const;
[[nodiscard]] QString getColorStyle(UiColors::ColorApplication color_application) const;
[[nodiscard]] QBoxLayout* createContainerLayout();
[[nodiscard]] QSplitter* createCenterRow();
[[nodiscard]] QWidget* createTopRow();
[[nodiscard]] QComboBox* createModNameComboBox();
[[nodiscard]] QWidget* createBottomRow();
[[nodiscard]] QSplitter* createLeftPane();
[[nodiscard]] QWidget* createRightPane();
[[nodiscard]] QTextEdit* createNotificationPanel();
[[nodiscard]] QWidget* createStepWidget(const std::shared_ptr<StepViewModel>& installStep);
[[nodiscard]] QWidget* renderGroup(const std::shared_ptr<GroupViewModel>& group);
static QString createObjectName(const std::shared_ptr<PluginViewModel>& plugin,
const std::shared_ptr<GroupViewModel>& group);
QRadioButton* createPluginRadioButton(const std::shared_ptr<PluginViewModel>& plugin,
const std::shared_ptr<GroupViewModel>& group, QWidget* parent);
QCheckBox* createPluginCheckBox(const std::shared_ptr<PluginViewModel>& plugin,
const std::shared_ptr<GroupViewModel>& group, QWidget* parent);
void renderSelectExactlyOne(QWidget* parent, QLayout* parentLayout, const std::shared_ptr<GroupViewModel>& group);
void renderCheckboxGroup(QWidget* parent, QLayout* parentLayout,
const std::shared_ptr<GroupViewModel>& group);
QButtonGroup* renderRadioGroup(QWidget* parent, QLayout* parentLayout,
const std::shared_ptr<GroupViewModel>& group);
void addNotification(const QString& message, LogLevel level) const;
void logMessage(const LogLevel level, const std::string& message, const bool asNotification = true) const
{
log.logMessage(level, "[WINDOW] " + message);
if (asNotification) {
addNotification(QString::fromStdString(message), level);
}
}
};
#endif //FOMODINSTALLERWINDOW_H
|