logic: Show error message when license expired
* moved all license checking logic to LicenseChecker * create LicenseChecker instance in app * Notify MainView with MessageForceEnterLicense
This commit is contained in:
@@ -11,7 +11,7 @@ QtMainView::QtMainView()
|
||||
, m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1))
|
||||
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
|
||||
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
|
||||
, m_forceLicenseScreenFunctor(std::bind(&QtMainView::doForceLicenseScreen, this))
|
||||
, m_forceLicenseScreenFunctor(std::bind(&QtMainView::doForceLicenseScreen, this, std::placeholders::_1))
|
||||
{
|
||||
m_window = std::make_shared<QtMainWindow>();
|
||||
m_window->show();
|
||||
@@ -89,9 +89,9 @@ void QtMainView::updateRecentProjectMenu()
|
||||
m_updateRecentProjectMenuFunctor();
|
||||
}
|
||||
|
||||
void QtMainView::forceLicenseScreen()
|
||||
void QtMainView::handleMessage(MessageForceEnterLicense* message)
|
||||
{
|
||||
m_forceLicenseScreenFunctor();
|
||||
m_forceLicenseScreenFunctor(message->licenseExpired);
|
||||
}
|
||||
|
||||
void QtMainView::handleMessage(MessageProjectNew* message)
|
||||
@@ -140,7 +140,7 @@ void QtMainView::doUpdateRecentProjectMenu()
|
||||
m_window->updateRecentProjectMenu();
|
||||
}
|
||||
|
||||
void QtMainView::doForceLicenseScreen()
|
||||
void QtMainView::doForceLicenseScreen(bool expired)
|
||||
{
|
||||
m_window->forceEnterLicense();
|
||||
m_window->forceEnterLicense(expired);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageForceEnterLicense.h"
|
||||
#include "utility/messaging/type/MessageProjectNew.h"
|
||||
#include "utility/messaging/type/MessageShowStartScreen.h"
|
||||
|
||||
@@ -18,6 +19,7 @@ class View;
|
||||
|
||||
class QtMainView
|
||||
: public MainView
|
||||
, public MessageListener<MessageForceEnterLicense>
|
||||
, public MessageListener<MessageProjectNew>
|
||||
, public MessageListener<MessageShowStartScreen>
|
||||
{
|
||||
@@ -43,9 +45,9 @@ public:
|
||||
virtual void setTitle(const std::string& title);
|
||||
virtual void activateWindow();
|
||||
virtual void updateRecentProjectMenu();
|
||||
virtual void forceLicenseScreen();
|
||||
|
||||
private:
|
||||
void handleMessage(MessageForceEnterLicense* message);
|
||||
void handleMessage(MessageProjectNew* message);
|
||||
void handleMessage(MessageShowStartScreen* message);
|
||||
|
||||
@@ -55,7 +57,7 @@ private:
|
||||
void doSetTitle(const std::string& title);
|
||||
void doActivateWindow();
|
||||
void doUpdateRecentProjectMenu();
|
||||
void doForceLicenseScreen();
|
||||
void doForceLicenseScreen(bool expired);
|
||||
|
||||
std::shared_ptr<QtMainWindow> m_window;
|
||||
std::vector<View*> m_views;
|
||||
@@ -66,7 +68,7 @@ private:
|
||||
QtThreadedFunctor<const std::string&> m_setTitleFunctor;
|
||||
QtThreadedFunctor<> m_activateWindowFunctor;
|
||||
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
|
||||
QtThreadedFunctor<> m_forceLicenseScreenFunctor;
|
||||
QtThreadedFunctor<bool> m_forceLicenseScreenFunctor;
|
||||
};
|
||||
|
||||
#endif // QT_MAIN_VIEW_H
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include "License.h"
|
||||
#include "PublicKey.h"
|
||||
#include "LicenseChecker.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/AppPath.h"
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/messaging/type/MessageEnteredLicense.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
@@ -42,17 +39,19 @@ void QtLicense::load()
|
||||
{
|
||||
clear();
|
||||
|
||||
License license;
|
||||
bool isLoaded = license.loadFromEncodedString(
|
||||
ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath());
|
||||
if (!isLoaded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::string licenseString = LicenseChecker::getInstance()->getCurrentLicenseString();
|
||||
|
||||
if (m_licenseText)
|
||||
if (licenseString.size() && m_licenseText)
|
||||
{
|
||||
m_licenseText->setText(license.getLicenseString().c_str());
|
||||
m_licenseText->setText(licenseString.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void QtLicense::setErrorMessage(const QString& errorMessage)
|
||||
{
|
||||
if (m_errorLabel)
|
||||
{
|
||||
m_errorLabel->setText(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,47 +135,39 @@ void QtLicense::handleClose()
|
||||
void QtLicense::handleNext()
|
||||
{
|
||||
std::string licenseString = m_licenseText->toPlainText().toStdString();
|
||||
if (licenseString.size() == 0)
|
||||
|
||||
LicenseChecker* checker = LicenseChecker::getInstance().get();
|
||||
LicenseChecker::LicenseState state = checker->checkLicenseString(licenseString);
|
||||
|
||||
std::string errorString;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
m_errorLabel->setText("No licence key was entered.");
|
||||
return;
|
||||
case LicenseChecker::LICENSE_EMPTY:
|
||||
errorString = "No licence key was entered.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_MOVED:
|
||||
case LicenseChecker::LICENSE_MALFORMED:
|
||||
errorString = "The entered license key is malformed.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_INVALID:
|
||||
errorString = "The entered license key is invalid.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_EXPIRED:
|
||||
errorString = "The entered license key is expired.";
|
||||
break;
|
||||
case LicenseChecker::LICENSE_VALID:
|
||||
{
|
||||
checker->saveCurrentLicenseString(licenseString);
|
||||
MessageEnteredLicense().dispatch();
|
||||
|
||||
setCancelAble(true);
|
||||
m_errorLabel->setText(" ");
|
||||
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
License license;
|
||||
bool isLoaded = license.loadFromString(licenseString);
|
||||
if (!isLoaded)
|
||||
{
|
||||
m_errorLabel->setText("The entered license key is malformed.");
|
||||
return;
|
||||
}
|
||||
|
||||
license.loadPublicKeyFromString(PublicKey);
|
||||
license.print();
|
||||
|
||||
if (license.isExpired())
|
||||
{
|
||||
m_errorLabel->setText("The entered license key is expired");
|
||||
return;
|
||||
}
|
||||
else if (license.isValid())
|
||||
{
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
std::string appLocation = AppPath::getAppPath();
|
||||
appSettings->setLicenseString(license.getLicenseEncodedString(appLocation));
|
||||
FilePath p(appLocation);
|
||||
appSettings->setLicenseCheck(license.hashLocation(p.absolute().str()));
|
||||
appSettings->save();
|
||||
|
||||
MessageEnteredLicense().dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_errorLabel->setText("The entered license key is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_errorLabel->setText(" ");
|
||||
setCancelAble(true);
|
||||
|
||||
emit finished();
|
||||
m_errorLabel->setText(errorString.c_str());
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ public:
|
||||
void clear();
|
||||
void load();
|
||||
|
||||
void setErrorMessage(const QString& errorMessage);
|
||||
|
||||
protected:
|
||||
// QtWindow implementation
|
||||
virtual void populateWindow(QWidget* widget) override;
|
||||
|
||||
@@ -262,7 +262,7 @@ void QtMainWindow::saveLayout()
|
||||
settings.setValue("DOCK_LOCATIONS", this->saveState());
|
||||
}
|
||||
|
||||
void QtMainWindow::forceEnterLicense()
|
||||
void QtMainWindow::forceEnterLicense(bool expired)
|
||||
{
|
||||
enterLicense();
|
||||
|
||||
@@ -272,7 +272,15 @@ void QtMainWindow::forceEnterLicense()
|
||||
LOG_ERROR("No enter license window on top of stack");
|
||||
return;
|
||||
}
|
||||
enterLicenseWindow->clear();
|
||||
|
||||
if (expired)
|
||||
{
|
||||
enterLicenseWindow->setErrorMessage("The license key is expired.");
|
||||
}
|
||||
else
|
||||
{
|
||||
enterLicenseWindow->clear();
|
||||
}
|
||||
|
||||
this->setEnabled(false);
|
||||
enterLicenseWindow->setEnabled(true);
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
void loadLayout();
|
||||
void saveLayout();
|
||||
|
||||
void forceEnterLicense();
|
||||
void forceEnterLicense(bool expired);
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event);
|
||||
|
||||
Reference in New Issue
Block a user