summaryrefslogtreecommitdiff
path: root/src/createinstancedialogpages.h
blob: e239c196e31c61dc28bbc2d528934d3763f5d6eb (plain)
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
#ifndef MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED
#define MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED

#include "createinstancedialog.h"
#include <filterwidget.h>

#include <QLabel>
#include <QLineEdit>
#include <QCommandLinkButton>

namespace MOBase { class IPluginGame; }
class NexusConnectionUI;


namespace cid
{

QString makeDefaultPath(const std::wstring& dir);


class PlaceholderLabel
{
public:
  PlaceholderLabel(QLabel* label);
  void setText(const QString& arg);
  void setVisible(bool b);

private:
  QLabel* m_label;
  QString m_original;
};


class Page
{
public:
  Page(CreateInstanceDialog& dlg);

  virtual bool ready() const;
  virtual void activated();

  void setSkip(bool b);
  bool skip() const;

  void updateNavigation();
  void next();

  virtual CreateInstanceDialog::Types selectedInstanceType() const;
  virtual MOBase::IPluginGame* selectedGame() const;
  virtual QString selectedGameLocation() const;
  virtual QString selectedGameVariant() const;
  virtual QString selectedInstanceName() const;
  virtual CreateInstanceDialog::Paths selectedPaths() const;

protected:
  Ui::CreateInstanceDialog* ui;
  CreateInstanceDialog& m_dlg;
  const PluginContainer& m_pc;
  bool m_skip;

  virtual bool doSkip() const;
};


class IntroPage : public Page
{
public:
  IntroPage(CreateInstanceDialog& dlg);

protected:
  bool doSkip() const override;
};


class TypePage : public Page
{
public:
  TypePage(CreateInstanceDialog& dlg);

  bool ready() const override;
  CreateInstanceDialog::Types selectedInstanceType() const override;

  void global();
  void portable();

private:
  CreateInstanceDialog::Types m_type;
};


class GamePage : public Page
{
public:
  GamePage(CreateInstanceDialog& dlg);

  bool ready() const override;
  MOBase::IPluginGame* selectedGame() const override;
  QString selectedGameLocation() const override;

  void select(MOBase::IPluginGame* game, const QString& dir={});
  void selectCustom();

  void warnUnrecognized(const QString& path);

private:
  struct Game
  {
    MOBase::IPluginGame* game = nullptr;
    QCommandLinkButton* button = nullptr;
    QString dir;
    bool installed = false;

    Game(MOBase::IPluginGame* g);
    Game(const Game&) = delete;
    Game& operator=(const Game&) = delete;
  };

  std::vector<std::unique_ptr<Game>> m_games;
  Game* m_selection;
  MOBase::FilterWidget m_filter;

  std::vector<MOBase::IPluginGame*> sortedGamePlugins() const;
  Game* findGame(MOBase::IPluginGame* game);
  void createGames();
  void updateButton(Game* g);
  void selectButton(Game* g);
  void clearButtons();
  void addButton(QAbstractButton* b);
  QCommandLinkButton* createCustomButton();
  void createGameButton(Game* g);
  void fillList();
  void onFilter();
  Game* checkInstallation(const QString& path, Game* g);
  MOBase::IPluginGame* findAnotherGame(const QString& path);
  bool confirmUnknown(const QString& path, MOBase::IPluginGame* game);
  MOBase::IPluginGame* confirmOtherGame(
    const QString& path,
    MOBase::IPluginGame* selectedGame, MOBase::IPluginGame* guessedGame);
};


class VariantsPage : public Page
{
public:
  VariantsPage(CreateInstanceDialog& dlg);

  bool ready() const override;
  void activated() override;
  QString selectedGameVariant() const override;

  void select(const QString& variant);

protected:
  bool doSkip() const override;

private:
  MOBase::IPluginGame* m_previousGame;
  std::vector<QCommandLinkButton*> m_buttons;
  QString m_selection;

  void fillList();
};


class NamePage : public Page
{
public:
  NamePage(CreateInstanceDialog& dlg);

  bool ready() const override;
  void activated() override;
  QString selectedInstanceName() const override;

protected:
  bool doSkip() const override;

private:
  mutable PlaceholderLabel m_label, m_exists, m_invalid;
  bool m_modified;
  bool m_okay;

  void onChanged();
  void updateWarnings();
  bool checkName(QString parentDir, QString name);
};


class PathsPage : public Page
{
public:
  PathsPage(CreateInstanceDialog& dlg);

  bool ready() const override;
  void activated() override;

  CreateInstanceDialog::Paths selectedPaths() const override;

private:
  QString m_lastInstanceName;
  CreateInstanceDialog::Types m_lastType;
  PlaceholderLabel m_label;
  mutable PlaceholderLabel m_simpleExists, m_simpleInvalid;
  mutable PlaceholderLabel m_advancedExists, m_advancedInvalid;

  void onChanged();
  bool checkPaths() const;
  bool checkAdvancedPath(const QString& path) const;
  QString resolve(const QString& path) const;
  void onAdvanced();
  void setPaths(const QString& name, bool force);
  void setIfEmpty(QLineEdit* e, const QString& path, bool force);
  bool checkPath(
    QString path,
    PlaceholderLabel& existsLabel, PlaceholderLabel& invalidLabel) const;
};


class NexusPage : public Page
{
public:
  NexusPage(CreateInstanceDialog& dlg);
  ~NexusPage();

  bool ready() const override;
  void activated() override;

protected:
  bool doSkip() const override;

private:
  std::unique_ptr<NexusConnectionUI> m_connectionUI;
  bool m_skip;
};


class ConfirmationPage : public Page
{
public:
  ConfirmationPage(CreateInstanceDialog& dlg);

  void activated() override;

  QString toLocalizedString(CreateInstanceDialog::Types t) const;
  QString makeReview() const;
  QString dirLine(const QString& caption, const QString& path) const;
};

} // namespace

#endif // MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED