diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-07-24 15:43:13 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-03 11:39:05 -0500 |
| commit | 048e3ac0d9b4e4258c9c2ac4d39d332f340e73a0 (patch) | |
| tree | 52e14f6e9d6dd6044ecf7935e6e8a560360143aa /src/createinstancedialogpages.h | |
| parent | 4ac8ab98563e223075c1c93852d4112ab6e4579c (diff) | |
split create instance dialog pages
Diffstat (limited to 'src/createinstancedialogpages.h')
| -rw-r--r-- | src/createinstancedialogpages.h | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/src/createinstancedialogpages.h b/src/createinstancedialogpages.h new file mode 100644 index 00000000..0baff666 --- /dev/null +++ b/src/createinstancedialogpages.h @@ -0,0 +1,219 @@ +#ifndef MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED +#define MODORGANIZER_CREATEINSTANCEDIALOGPAGES_INCLUDED + +#include <QLabel> +#include <QLineEdit> +#include <QCommandLinkButton> +#include "createinstancedialog.h" + +namespace MOBase { class IPluginGame; } + +namespace cid +{ + +QString makeDefaultPath(const std::wstring& dir); + +class PathChecker +{ +public: + PathChecker(QLabel* existsLabel, QLabel* invalidLabel); + + QString sanitizeFileName(const QString& name) const; + + // same thing as above, but allows path separators and colons + // + QString sanitizePath(const QString& path) const; + + bool checkName(QString parentDir, QString name) const; + bool checkPath(QString path) const; + +private: + QLabel* m_exists; + QString m_existsOriginal; + + QLabel* m_invalid; + QString m_invalidOriginal; + + void setPossiblePlaceholder( + QLabel* label, const QString& s, const QString& arg) const; +}; + + +class Page +{ +public: + Page(CreateInstanceDialog& dlg); + + virtual bool ready() const; + virtual bool skip() const; + virtual void activated(); + + void updateNavigation(); + void next(); + + virtual CreateInstanceDialog::Types selectedInstanceType() const; + virtual MOBase::IPluginGame* selectedGame() const; + virtual QString selectedGameLocation() const; + virtual QString selectedGameEdition() const; + virtual QString selectedInstanceName() const; + virtual CreateInstanceDialog::Paths selectedPaths() const; + +protected: + Ui::CreateInstanceDialog* ui; + CreateInstanceDialog& m_dlg; + const PluginContainer& m_pc; +}; + + +class InfoPage : public Page +{ +public: + InfoPage(CreateInstanceDialog& dlg); +}; + + +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); + 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; + + + std::vector<MOBase::IPluginGame*> sortedGamePlugins() const; + Game* findGame(MOBase::IPluginGame* game); + void createGames(); + void updateButton(Game* g); + void selectButton(Game* g); + QCommandLinkButton* createCustomButton(); + void createGameButton(Game* g); + void fillList(); + 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 EditionsPage : public Page +{ +public: + EditionsPage(CreateInstanceDialog& dlg); + + bool ready() const override; + bool skip() const override; + void activated() override; + QString selectedGameEdition() const override; + + void select(const QString& variant); + +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; + bool skip() const override; + void activated() override; + QString selectedInstanceName() const override; + +private: + PathChecker m_checker; + QString m_originalLabel; + bool m_modified; + bool m_okay; + + void onChanged(); + void updateWarnings(); +}; + + +class PathsPage : public Page +{ +public: + PathsPage(CreateInstanceDialog& dlg); + + bool ready() const override; + void activated() override; + + CreateInstanceDialog::Paths selectedPaths() const override; + +private: + PathChecker m_checker, m_advancedChecker; + QString m_lastInstanceName; + + void onChanged(); + bool checkPaths() const; + bool checkAdvancedPath(const QString& path) const; + bool checkVarPath(QString path) const; + void onAdvanced(); + void setPaths(const QString& name, bool force); + void setIfEmpty(QLineEdit* e, const QString& path, bool force); +}; + + +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 |
