ui, logic: design for license ui and forcing the user to enter a key on first open

This change integrates the license key ui into the application and makes it necessary for the user to enter a correct
key. The check for a correct key is done on startup and whenever a project is loaded. The check for the key also
includes a check whether the location of the application has changed.
This commit is contained in:
Eberhard Graether
2016-01-18 11:42:31 +01:00
parent 23257a3071
commit 75b102a528
25 changed files with 397 additions and 145 deletions
+103 -32
View File
@@ -10,42 +10,102 @@
#include "License.h"
#include "PublicKey.h"
#include "settings/ApplicationSettings.h"
#include "utility/logging/logging.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FilePath.h"
QtLicense::QtLicense(QWidget *parent)
: QtSettingsWindow(parent)
: QtSettingsWindow(parent, 68)
{
raise();
}
QSize QtLicense::sizeHint() const
{
return QSize(600,600);
return QSize(725, 550);
}
void QtLicense::clear()
{
if (m_licenseText)
{
m_licenseText->setText("");
}
if (m_errorLabel)
{
m_errorLabel->setText(" ");
}
}
void QtLicense::setup()
{
setupForm();
setStyleSheet((
utility::getStyleSheet("data/gui/setting_window/window.css") +
utility::getStyleSheet("data/gui/license/license.css")
).c_str());
updateTitle("Enter License");
updateDoneButton("Ok");
}
addLogo();
void QtLicense::populateForm(QFormLayout* layout)
{
QLabel* licenseName = new QLabel();
licenseName->setText( QString::fromLatin1("Enter License:"));
QFont _font = licenseName->font();
_font.setPixelSize(36);
licenseName->setFont(_font);
layout->addWidget(licenseName);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(25, 100, 25, 30);
m_licenseText = new QTextEdit();
m_licenseText->setMinimumHeight(300);
layout->addWidget(m_licenseText);
QVBoxLayout* subLayout = new QVBoxLayout();
subLayout->setContentsMargins(250, 0, 0, 0);
QLabel* licenseName = new QLabel(this);
licenseName->setText(QString::fromLatin1("Enter Licence"));
licenseName->setObjectName("titleLabel");
subLayout->addWidget(licenseName);
subLayout->addSpacing(10);
QLabel* licenseIntro = new QLabel(this);
licenseIntro->setText(QString::fromLatin1("Please enter a licence key to activate Coati:"));
licenseIntro->setObjectName("licenseIntro");
subLayout->addWidget(licenseIntro);
m_licenseText = new QTextEdit(this);
m_licenseText->setObjectName("licenseField");
m_licenseText->setText(ApplicationSettings::getInstance()->getLicenseString().c_str());
m_licenseText->setPlaceholderText(
"-----BEGIN LICENSE-----\n"
"Jane Doe\n"
"Single User License\n"
"Coati 0\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxx\n"
"-----END LICENSE-----\n"
);
subLayout->addWidget(m_licenseText);
m_errorLabel = new QLabel(this);
m_errorLabel->setObjectName("licenseError");
m_errorLabel->setText(" ");
subLayout->addWidget(m_errorLabel);
subLayout->addSpacing(10);
QLabel* linkLabel = new QLabel(this);
linkLabel->setObjectName("linkLabel");
linkLabel->setText("<a href=\"http://coati.io/buy-license\">Don't have a license key yet?</a>");
linkLabel->setOpenExternalLinks(true);
linkLabel->setGeometry(275, 300, 300, 50);
subLayout->addWidget(linkLabel);
layout->addLayout(subLayout);
layout->addSpacing(20);
showButtons(layout);
updateDoneButton("Activate");
resize(725, 550);
}
void QtLicense::handleCancelButtonPress()
@@ -55,29 +115,40 @@ void QtLicense::handleCancelButtonPress()
void QtLicense::handleUpdateButtonPress()
{
License license;
bool isLoaded = license.loadFromString(m_licenseText->toPlainText().toStdString());
if(!isLoaded)
std::string licenseString = m_licenseText->toPlainText().toStdString();
if (licenseString.size() == 0)
{
LOG_WARNING("Failed Loading License");
m_errorLabel->setText("No licence key was entered.");
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.isValid())
if (license.isValid())
{
ApplicationSettings::getInstance()->setLicenseString(license.getLicenseString());
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
appSettings->setLicenseString(license.getLicenseString());
FilePath p("");
ApplicationSettings::getInstance()->setLicenseCheck(license.hashLocation(p.absolute().str()));
ApplicationSettings::getInstance()->save();
LOG_WARNING("License saved");
appSettings->setLicenseCheck(license.hashLocation(p.absolute().str()));
appSettings->save();
}
else
{
LOG_WARNING("License is not valid");
m_errorLabel->setText("The entered license key is invalid.");
return;
}
m_errorLabel->setText(" ");
setCancelAble(true);
emit finished();
}