GH-1793 rearrange setup wizard logic to only check if they are needed once
This commit is contained in:
parent
ceb5fc6d75
commit
782384f185
@ -18,6 +18,9 @@
|
|||||||
#include "themes/CustomTheme.h"
|
#include "themes/CustomTheme.h"
|
||||||
|
|
||||||
#include "setupwizard/SetupWizard.h"
|
#include "setupwizard/SetupWizard.h"
|
||||||
|
#include "setupwizard/LanguageWizardPage.h"
|
||||||
|
#include "setupwizard/JavaWizardPage.h"
|
||||||
|
#include "setupwizard/AnalyticsWizardPage.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@ -359,16 +362,78 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
|
|
||||||
initAnalytics();
|
initAnalytics();
|
||||||
|
|
||||||
if(SetupWizard::isRequired())
|
if(createSetupWizard())
|
||||||
{
|
{
|
||||||
m_setupWizard = new SetupWizard(nullptr);
|
|
||||||
connect(m_setupWizard, &QDialog::finished, this, &MultiMC::setupWizardFinished);
|
|
||||||
m_setupWizard->show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
performMainStartupAction();
|
performMainStartupAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MultiMC::createSetupWizard()
|
||||||
|
{
|
||||||
|
bool javaRequired = [&]()
|
||||||
|
{
|
||||||
|
QString currentHostName = QHostInfo::localHostName();
|
||||||
|
QString oldHostName = settings()->get("LastHostname").toString();
|
||||||
|
if (currentHostName != oldHostName)
|
||||||
|
{
|
||||||
|
settings()->set("LastHostname", currentHostName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
QString currentJavaPath = settings()->get("JavaPath").toString();
|
||||||
|
QString actualPath = FS::ResolveExecutable(currentJavaPath);
|
||||||
|
if (actualPath.isNull())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
bool analyticsRequired = [&]()
|
||||||
|
{
|
||||||
|
if(BuildConfig.ANALYTICS_ID.isEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!settings()->get("Analytics").toBool())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (settings()->get("AnalyticsSeen").toInt() < analytics()->version())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
bool languageRequired = [&]()
|
||||||
|
{
|
||||||
|
if (settings()->get("Language").toString().isEmpty())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}();
|
||||||
|
bool wizardRequired = javaRequired || analyticsRequired || languageRequired;
|
||||||
|
|
||||||
|
if(wizardRequired)
|
||||||
|
{
|
||||||
|
m_setupWizard = new SetupWizard(nullptr);
|
||||||
|
if (languageRequired)
|
||||||
|
{
|
||||||
|
m_setupWizard->addPage(new LanguageWizardPage(m_setupWizard));
|
||||||
|
}
|
||||||
|
if (javaRequired)
|
||||||
|
{
|
||||||
|
m_setupWizard->addPage(new JavaWizardPage(m_setupWizard));
|
||||||
|
}
|
||||||
|
if(analyticsRequired)
|
||||||
|
{
|
||||||
|
m_setupWizard->addPage(new AnalyticsWizardPage(m_setupWizard));
|
||||||
|
}
|
||||||
|
connect(m_setupWizard, &QDialog::finished, this, &MultiMC::setupWizardFinished);
|
||||||
|
m_setupWizard->show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void MultiMC::setupWizardFinished(int status)
|
void MultiMC::setupWizardFinished(int status)
|
||||||
{
|
{
|
||||||
qDebug() << "Wizard result =" << status;
|
qDebug() << "Wizard result =" << status;
|
||||||
|
@ -186,6 +186,7 @@ private:
|
|||||||
void initMCEdit();
|
void initMCEdit();
|
||||||
void initAnalytics();
|
void initAnalytics();
|
||||||
void shutdownAnalytics();
|
void shutdownAnalytics();
|
||||||
|
bool createSetupWizard();
|
||||||
void performMainStartupAction();
|
void performMainStartupAction();
|
||||||
|
|
||||||
// sets the fatal error message and m_status to Failed.
|
// sets the fatal error message and m_status to Failed.
|
||||||
|
@ -41,25 +41,6 @@ bool AnalyticsWizardPage::validatePage()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnalyticsWizardPage::isRequired()
|
|
||||||
{
|
|
||||||
if(BuildConfig.ANALYTICS_ID.isEmpty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto settings = MMC->settings();
|
|
||||||
auto analytics = MMC->analytics();
|
|
||||||
if (!settings->get("Analytics").toBool())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (settings->get("AnalyticsSeen").toInt() < analytics->version())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AnalyticsWizardPage::retranslate()
|
void AnalyticsWizardPage::retranslate()
|
||||||
{
|
{
|
||||||
setTitle(tr("Analytics"));
|
setTitle(tr("Analytics"));
|
||||||
|
@ -14,7 +14,6 @@ public:
|
|||||||
virtual ~AnalyticsWizardPage();
|
virtual ~AnalyticsWizardPage();
|
||||||
|
|
||||||
bool validatePage() override;
|
bool validatePage() override;
|
||||||
static bool isRequired();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void retranslate() override;
|
void retranslate() override;
|
||||||
|
@ -197,24 +197,6 @@ bool JavaWizardPage::validatePage()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JavaWizardPage::isRequired()
|
|
||||||
{
|
|
||||||
QString currentHostName = QHostInfo::localHostName();
|
|
||||||
QString oldHostName = MMC->settings()->get("LastHostname").toString();
|
|
||||||
if (currentHostName != oldHostName)
|
|
||||||
{
|
|
||||||
MMC->settings()->set("LastHostname", currentHostName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
QString currentJavaPath = MMC->settings()->get("JavaPath").toString();
|
|
||||||
QString actualPath = FS::ResolveExecutable(currentJavaPath);
|
|
||||||
if (actualPath.isNull())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JavaWizardPage::wantsRefreshButton()
|
bool JavaWizardPage::wantsRefreshButton()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -31,7 +31,6 @@ public:
|
|||||||
void refresh() override;
|
void refresh() override;
|
||||||
void initializePage() override;
|
void initializePage() override;
|
||||||
bool validatePage() override;
|
bool validatePage() override;
|
||||||
static bool isRequired();
|
|
||||||
|
|
||||||
enum class JavaStatus
|
enum class JavaStatus
|
||||||
{
|
{
|
||||||
|
@ -47,14 +47,6 @@ bool LanguageWizardPage::validatePage()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanguageWizardPage::isRequired()
|
|
||||||
{
|
|
||||||
auto settings = MMC->settings();
|
|
||||||
if (settings->get("Language").toString().isEmpty())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LanguageWizardPage::retranslate()
|
void LanguageWizardPage::retranslate()
|
||||||
{
|
{
|
||||||
setTitle(tr("Language"));
|
setTitle(tr("Language"));
|
||||||
|
@ -19,8 +19,6 @@ public:
|
|||||||
|
|
||||||
bool validatePage() override;
|
bool validatePage() override;
|
||||||
|
|
||||||
static bool isRequired();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void retranslate() override;
|
void retranslate() override;
|
||||||
|
|
||||||
|
@ -11,13 +11,6 @@
|
|||||||
|
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
|
|
||||||
enum Page
|
|
||||||
{
|
|
||||||
Language,
|
|
||||||
Java,
|
|
||||||
Analytics,
|
|
||||||
};
|
|
||||||
|
|
||||||
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
|
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
|
||||||
{
|
{
|
||||||
setObjectName(QStringLiteral("SetupWizard"));
|
setObjectName(QStringLiteral("SetupWizard"));
|
||||||
@ -29,19 +22,6 @@ SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
|
|||||||
retranslate();
|
retranslate();
|
||||||
|
|
||||||
connect(this, &QWizard::currentIdChanged, this, &SetupWizard::pageChanged);
|
connect(this, &QWizard::currentIdChanged, this, &SetupWizard::pageChanged);
|
||||||
|
|
||||||
if (LanguageWizardPage::isRequired())
|
|
||||||
{
|
|
||||||
setPage(Page::Language, new LanguageWizardPage(this));
|
|
||||||
}
|
|
||||||
if (JavaWizardPage::isRequired())
|
|
||||||
{
|
|
||||||
setPage(Page::Java, new JavaWizardPage(this));
|
|
||||||
}
|
|
||||||
if(AnalyticsWizardPage::isRequired())
|
|
||||||
{
|
|
||||||
setPage(Page::Analytics, new AnalyticsWizardPage(this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupWizard::retranslate()
|
void SetupWizard::retranslate()
|
||||||
@ -106,15 +86,3 @@ void SetupWizard::changeEvent(QEvent *event)
|
|||||||
SetupWizard::~SetupWizard()
|
SetupWizard::~SetupWizard()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetupWizard::isRequired()
|
|
||||||
{
|
|
||||||
if (LanguageWizardPage::isRequired())
|
|
||||||
return true;
|
|
||||||
if (JavaWizardPage::isRequired())
|
|
||||||
return true;
|
|
||||||
if (AnalyticsWizardPage::isRequired())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -39,9 +39,6 @@ public: /* con/destructors */
|
|||||||
private slots:
|
private slots:
|
||||||
void pageChanged(int id);
|
void pageChanged(int id);
|
||||||
|
|
||||||
public: /* methods */
|
|
||||||
static bool isRequired();
|
|
||||||
|
|
||||||
private: /* methods */
|
private: /* methods */
|
||||||
void retranslate();
|
void retranslate();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user