Add warning about expire and redesign warning/error popup

Fixes Github Issue #38
This commit is contained in:
Lars Toenning
2020-06-13 21:58:07 +02:00
committed by Mat Sutcliffe
parent 189bb15936
commit 1d4aa96e9b
7 changed files with 56 additions and 29 deletions

View File

@@ -97,6 +97,11 @@ namespace BlackConfig
return QDateTime::currentDateTime() > getEol();
}
int CBuildConfig::daysTillLifetimeExpiry()
{
return QDateTime::currentDateTime().daysTo(getEol());
}
const QString boolToYesNo(bool v)
{
return v ? QStringLiteral("yes") : QStringLiteral("no");

View File

@@ -109,6 +109,9 @@ namespace BlackConfig
//! Lifetime ended?
static bool isLifetimeExpired();
//! Days till lifetime end
static int daysTillLifetimeExpiry();
//! Vatsim client id
static int vatsimClientId(); // defined in buildconfig_gen.cpp.in

View File

@@ -1404,14 +1404,21 @@ namespace BlackCore
// checks
if (CBuildConfig::isLifetimeExpired())
{
this->cmdLineErrorMessage("Program expired " + CBuildConfig::getEol().toString());
this->cmdLineErrorMessage("Program expired since " + CBuildConfig::getEol().date().toString(),
"This version is no longer supported and usable. You have to install a newer version.");
return false;
}
if(CBuildConfig::daysTillLifetimeExpiry() <= 30)
{
this->cmdLineWarningMessage("This version will expire in " + QString::number(CBuildConfig::daysTillLifetimeExpiry()) + " days!",
"You'll need to update swift in order to use it thereafter.");
}
const QStringList verifyErrors = CDirectoryUtils::verifyRuntimeDirectoriesAndFiles();
if (!verifyErrors.isEmpty() && !m_applicationInfo.isUnitTest())
{
this->cmdLineErrorMessage("Missing runtime directories/files: " + verifyErrors.join(", "));
this->cmdLineErrorMessage("Missing runtime directories/files:", verifyErrors.join(", "));
return false;
}
@@ -1419,13 +1426,13 @@ namespace BlackCore
const QStringList args(QCoreApplication::instance()->arguments());
if (!m_parser.parse(args))
{
this->cmdLineErrorMessage(m_parser.errorText());
this->cmdLineErrorMessage("Parser error:", m_parser.errorText());
return false;
}
if (m_singleApplication && m_alreadyRunning && !this->skipSingleApplicationCheck())
{
this->cmdLineErrorMessage("Program must only run once");
this->cmdLineErrorMessage("Program must only run once", "You cannot run two or more instances side-by-side.");
return false;
}
@@ -1461,12 +1468,16 @@ namespace BlackCore
return !this->synchronizeSetup(timeoutMs).hasErrorMessages();
}
bool CApplication::cmdLineErrorMessage(const QString &errorMessage, bool retry) const
bool CApplication::cmdLineWarningMessage(const QString &text, const QString &informativeText) const
{
fputs(qPrintable(text + informativeText), stderr);
return false;
}
bool CApplication::cmdLineErrorMessage(const QString &text, const QString &informativeText, bool retry) const
{
Q_UNUSED(retry) // only works with UI version
fputs(qPrintable(errorMessage), stderr);
fputs("\n\n", stderr);
fputs(qPrintable(m_parser.helpText()), stderr);
fputs(qPrintable(text + informativeText), stderr);
return false;
}

View File

@@ -299,8 +299,11 @@ namespace BlackCore
//! \see synchronizeSetup
virtual bool parseAndSynchronizeSetup(int timeoutMs = BlackMisc::Network::CNetworkUtils::getLongTimeoutMs());
//! Display warning message
virtual bool cmdLineWarningMessage(const QString &text, const QString &informativeText = "") const;
//! Display error message
virtual bool cmdLineErrorMessage(const QString &cmdLineErrorMessage, bool retry = false) const;
virtual bool cmdLineErrorMessage(const QString &text, const QString &informativeText = "", bool retry = false) const;
//! Display error message
virtual bool cmdLineErrorMessage(const BlackMisc::CStatusMessageList &msgs, bool retry = false) const;

View File

@@ -184,7 +184,7 @@ namespace BlackCore
ok = true;
break;
}
retry = sApp->cmdLineErrorMessage(QStringLiteral("URL '%1' not reachable").arg(urlString), true);
retry = sApp->cmdLineErrorMessage(QStringLiteral("URL '%1' not reachable").arg(urlString), "", true);
}
while (retry);
}

View File

@@ -590,26 +590,27 @@ namespace BlackGui
return "1.0";
}
bool CGuiApplication::cmdLineErrorMessage(const QString &errorMessage, bool retry) const
bool CGuiApplication::cmdLineWarningMessage(const QString &text, const QString &informativeText) const
{
const QString helpText(beautifyHelpMessage(m_parser.helpText()));
constexpr int MaxLength = 60;
QMessageBox warningBox(QMessageBox::Warning, QGuiApplication::applicationDisplayName(), "<b>" +text + "</b>");
warningBox.setInformativeText(informativeText);
return warningBox.exec();
}
QString htmlMsg;
if (errorMessage.length() > MaxLength)
{
htmlMsg = "<html><head/><body><h4>" + errorMessage.left(MaxLength) + "..." + "</h4>" +
"Details: " + errorMessage + "<br><br>";
}
bool CGuiApplication::cmdLineErrorMessage(const QString &text, const QString &informativeText, bool retry) const
{
QMessageBox errorBox(QMessageBox::Critical, QGuiApplication::applicationDisplayName(), "<b>" +text + "</b>");
if(informativeText.length() < 300)
errorBox.setInformativeText(informativeText);
else
{
htmlMsg = "<html><head/><body><h4>" + errorMessage + "</h4>";
}
htmlMsg += helpText + "</body></html>";
errorBox.setDetailedText(informativeText);
errorBox.addButton(QMessageBox::Abort);
if(retry)
errorBox.addButton(QMessageBox::Retry);
const int r = errorBox.exec();
const int r = QMessageBox::warning(nullptr,
QGuiApplication::applicationDisplayName(),
htmlMsg, QMessageBox::Abort, retry ? QMessageBox::Retry : QMessageBox::NoButton);
return (r == QMessageBox::Retry);
}
@@ -619,11 +620,10 @@ namespace BlackGui
if (!msgs.hasErrorMessages()) { return false; }
static const CPropertyIndexList propertiesSingle({ CStatusMessage::IndexMessage });
static const CPropertyIndexList propertiesMulti({ CStatusMessage::IndexSeverityAsString, CStatusMessage::IndexMessage });
const QString helpText(CGuiApplication::beautifyHelpMessage(m_parser.helpText()));
const QString msgsHtml = msgs.toHtml(msgs.size() > 1 ? propertiesMulti : propertiesSingle);
const int r = QMessageBox::critical(nullptr,
QGuiApplication::applicationDisplayName(),
"<html><head><body>" + msgsHtml + "<br><br>" + helpText + "</body></html>", QMessageBox::Abort, retry ? QMessageBox::Retry : QMessageBox::NoButton);
"<html><head><body>" + msgsHtml + "</body></html>", QMessageBox::Abort, retry ? QMessageBox::Retry : QMessageBox::NoButton);
return (r == QMessageBox::Retry);
}

View File

@@ -125,9 +125,14 @@ namespace BlackGui
//! Set window title
QString setExtraWindowTitle(const QString &extraInfo, QWidget *mainWindowWidget = mainApplicationWidget()) const;
//! \name print warning message
//! @{
virtual bool cmdLineWarningMessage(const QString &text, const QString &informativeText) const override;
//! @}
//! \name print messages generated during parsing / cmd handling
//! @{
virtual bool cmdLineErrorMessage(const QString &cmdLineErrorMessage, bool retry = false) const override;
virtual bool cmdLineErrorMessage(const QString &text, const QString &informativeText = "", bool retry = false) const override;
virtual bool cmdLineErrorMessage(const BlackMisc::CStatusMessageList &msgs, bool retry = false) const override;
//! @}