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:
@@ -8,6 +8,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_showLicenseScreenFunctor(std::bind(&QtMainView::doShowLicenseScreen, this))
|
||||
{
|
||||
m_window = std::make_shared<QtMainWindow>();
|
||||
m_window->show();
|
||||
@@ -86,6 +87,11 @@ void QtMainView::updateRecentProjectMenu()
|
||||
m_updateRecentProjectMenuFunctor();
|
||||
}
|
||||
|
||||
void QtMainView::showLicenseScreen()
|
||||
{
|
||||
m_showLicenseScreenFunctor();
|
||||
}
|
||||
|
||||
void QtMainView::doUpdateRecentProjectMenu()
|
||||
{
|
||||
m_window->updateRecentProjectMenu();
|
||||
@@ -103,3 +109,8 @@ void QtMainView::doActivateWindow()
|
||||
m_window->raise();
|
||||
m_window->setFocus(Qt::ActiveWindowFocusReason);
|
||||
}
|
||||
|
||||
void QtMainView::doShowLicenseScreen()
|
||||
{
|
||||
m_window->forceEnterLicense();
|
||||
}
|
||||
|
||||
@@ -37,11 +37,13 @@ public:
|
||||
virtual void setTitle(const std::string& title);
|
||||
virtual void activateWindow();
|
||||
virtual void updateRecentProjectMenu();
|
||||
virtual void showLicenseScreen();
|
||||
|
||||
private:
|
||||
void doSetTitle(const std::string& title);
|
||||
void doActivateWindow();
|
||||
void doUpdateRecentProjectMenu();
|
||||
void doShowLicenseScreen();
|
||||
|
||||
std::shared_ptr<QtMainWindow> m_window;
|
||||
std::vector<View*> m_views;
|
||||
@@ -49,6 +51,7 @@ private:
|
||||
QtThreadedFunctor<const std::string&> m_setTitleFunctor;
|
||||
QtThreadedFunctor<> m_activateWindowFunctor;
|
||||
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
|
||||
QtThreadedFunctor<> m_showLicenseScreenFunctor;
|
||||
};
|
||||
|
||||
#endif // QT_MAIN_VIEW_H
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ public:
|
||||
QtLicense(QWidget* parent = 0);
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
void clear();
|
||||
|
||||
virtual void setup() override;
|
||||
protected:
|
||||
virtual void populateForm(QFormLayout* layout) override;
|
||||
|
||||
private slots:
|
||||
void handleCancelButtonPress();
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
QPushButton* m_updateButton;
|
||||
|
||||
QTextEdit* m_licenseText;
|
||||
|
||||
QLabel* m_errorLabel;
|
||||
};
|
||||
|
||||
#endif //QT_LICENSE_H
|
||||
|
||||
@@ -243,6 +243,16 @@ void QtMainWindow::saveLayout()
|
||||
settings.setValue("DOCK_LOCATIONS", this->saveState());
|
||||
}
|
||||
|
||||
void QtMainWindow::forceEnterLicense()
|
||||
{
|
||||
enterLicense();
|
||||
m_enterLicenseWindow->clear();
|
||||
m_enterLicenseWindow->setCancelAble(false);
|
||||
|
||||
this->setEnabled(false);
|
||||
m_enterLicenseWindow->setEnabled(true);
|
||||
}
|
||||
|
||||
bool QtMainWindow::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::WindowActivate)
|
||||
@@ -297,6 +307,12 @@ void QtMainWindow::clearWindows()
|
||||
m_windowStack.clear();
|
||||
}
|
||||
|
||||
void QtMainWindow::activateWindow()
|
||||
{
|
||||
this->setEnabled(true);
|
||||
popWindow();
|
||||
}
|
||||
|
||||
void QtMainWindow::about()
|
||||
{
|
||||
if (!m_aboutWindow)
|
||||
@@ -345,11 +361,11 @@ void QtMainWindow::enterLicense()
|
||||
m_enterLicenseWindow = std::make_shared<QtLicense>(this);
|
||||
m_enterLicenseWindow->setup();
|
||||
|
||||
connect(m_enterLicenseWindow.get(), SIGNAL(finished()), this, SLOT(popWindow()));
|
||||
connect(m_enterLicenseWindow.get(), SIGNAL(finished()), this, SLOT(activateWindow()));
|
||||
connect(m_enterLicenseWindow.get(), SIGNAL(canceled()), this, SLOT(popWindow()));
|
||||
}
|
||||
|
||||
pushWindow(m_enterLicenseWindow)
|
||||
pushWindow(m_enterLicenseWindow.get());
|
||||
}
|
||||
|
||||
void QtMainWindow::showStartScreen()
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
void loadLayout();
|
||||
void saveLayout();
|
||||
|
||||
void forceEnterLicense();
|
||||
|
||||
protected:
|
||||
bool event(QEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
@@ -92,6 +94,8 @@ public slots:
|
||||
void popWindow();
|
||||
void clearWindows();
|
||||
|
||||
void activateWindow();
|
||||
|
||||
void about();
|
||||
void openSettings();
|
||||
void showLicenses();
|
||||
|
||||
@@ -18,6 +18,7 @@ QtSettingsWindow::QtSettingsWindow(QWidget *parent, int displacement)
|
||||
, m_cancelButton(nullptr)
|
||||
, m_doneButton(nullptr)
|
||||
, m_mousePressedInWindow(false)
|
||||
, m_cancelAble(true)
|
||||
{
|
||||
QSize windowSize = sizeHint();
|
||||
move(parent->pos().x() + parent->width() / 2 - 250, parent->pos().y() + parent->height() / 2 - 250);
|
||||
@@ -60,12 +61,24 @@ QSize QtSettingsWindow::sizeHint() const
|
||||
return QSize(500, 500);
|
||||
}
|
||||
|
||||
void QtSettingsWindow::setCancelAble(bool cancelable)
|
||||
{
|
||||
if (m_cancelButton)
|
||||
{
|
||||
m_cancelButton->setEnabled(cancelable);
|
||||
}
|
||||
|
||||
m_cancelAble = cancelable;
|
||||
}
|
||||
|
||||
void QtSettingsWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->key() == Qt::Key_Escape)
|
||||
if (m_cancelAble && event->key() == Qt::Key_Escape)
|
||||
{
|
||||
emit canceled();
|
||||
}
|
||||
|
||||
QWidget::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void QtSettingsWindow::resizeEvent(QResizeEvent *event)
|
||||
@@ -139,6 +152,34 @@ void QtSettingsWindow::setupForm()
|
||||
|
||||
form->setLayout(layout);
|
||||
|
||||
windowLayout->addWidget(scrollArea);
|
||||
windowLayout->addSpacing(20);
|
||||
|
||||
showButtons(windowLayout);
|
||||
|
||||
m_window->setLayout(windowLayout);
|
||||
resize(QSize(600, 620));
|
||||
|
||||
scrollArea->raise();
|
||||
}
|
||||
|
||||
void QtSettingsWindow::populateForm(QFormLayout* layout)
|
||||
{
|
||||
}
|
||||
|
||||
void QtSettingsWindow::addLogo()
|
||||
{
|
||||
QtDeviceScaledPixmap coatiLogo("data/gui/startscreen/logo.png");
|
||||
coatiLogo.scaleToWidth(200);
|
||||
|
||||
QLabel* coatiLogoLabel = new QLabel(this);
|
||||
coatiLogoLabel->setPixmap(coatiLogo.pixmap());
|
||||
coatiLogoLabel->resize(coatiLogo.width(), coatiLogo.height());
|
||||
coatiLogoLabel->move(30,10);
|
||||
}
|
||||
|
||||
void QtSettingsWindow::showButtons(QVBoxLayout* layout)
|
||||
{
|
||||
m_cancelButton = new QPushButton("Cancel");
|
||||
m_cancelButton->setObjectName("windowButton");
|
||||
m_doneButton = new QPushButton("Done");
|
||||
@@ -153,18 +194,7 @@ void QtSettingsWindow::setupForm()
|
||||
buttons->addWidget(m_doneButton);
|
||||
m_buttonsLayout = buttons;
|
||||
|
||||
windowLayout->addWidget(scrollArea);
|
||||
windowLayout->addSpacing(20);
|
||||
windowLayout->addLayout(buttons);
|
||||
|
||||
m_window->setLayout(windowLayout);
|
||||
resize(QSize(600, 620));
|
||||
|
||||
scrollArea->raise();
|
||||
}
|
||||
|
||||
void QtSettingsWindow::populateForm(QFormLayout* layout)
|
||||
{
|
||||
layout->addLayout(buttons);
|
||||
}
|
||||
|
||||
void QtSettingsWindow::updateTitle(QString title)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
class QFormLayout;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QVBoxLayout;
|
||||
|
||||
class QtSettingsWindow
|
||||
: public QWidget
|
||||
@@ -21,6 +22,8 @@ public:
|
||||
|
||||
virtual void setup() = 0;
|
||||
|
||||
void setCancelAble(bool cancelAble);
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
void canceled();
|
||||
@@ -35,6 +38,9 @@ protected:
|
||||
void setupForm();
|
||||
virtual void populateForm(QFormLayout* layout);
|
||||
|
||||
void addLogo();
|
||||
void showButtons(QVBoxLayout* layout);
|
||||
|
||||
void updateTitle(QString title);
|
||||
void updateDoneButton(QString text);
|
||||
void hideCancelButton(bool hidden);
|
||||
@@ -56,6 +62,7 @@ private:
|
||||
int m_displacment;
|
||||
QPoint m_dragPosition;
|
||||
bool m_mousePressedInWindow;
|
||||
bool m_cancelAble;
|
||||
};
|
||||
|
||||
#endif //QT_SETTINGS_WINDOW_H
|
||||
|
||||
@@ -35,12 +35,7 @@ void QtStartScreen::setup()
|
||||
{
|
||||
setStyleSheet(utility::getStyleSheet("data/gui/startscreen/startscreen.css").c_str());
|
||||
|
||||
QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo.png");
|
||||
coati_logo.scaleToWidth(200);
|
||||
QLabel* coatiLogoLabel = new QLabel(this);
|
||||
coatiLogoLabel->setPixmap(coati_logo.pixmap());
|
||||
coatiLogoLabel->resize(coati_logo.width(), coati_logo.height());
|
||||
coatiLogoLabel->move(30,10);
|
||||
addLogo();
|
||||
|
||||
if(!isTrial())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user