#5657 Handle expired keys properly

This commit is contained in:
Andrew Nelless 2016-10-18 17:01:44 +01:00
parent 020b7974df
commit 02c23905d6
4 changed files with 47 additions and 38 deletions

View File

@ -81,8 +81,9 @@ void ActivationDialog::accept()
if (edition != kUnregistered) { if (edition != kUnregistered) {
if (m_LicenseManager->serialKey().isTrial()) { if (m_LicenseManager->serialKey().isTrial()) {
message.information(this, "Thanks!", message.information(this, "Thanks!",
tr("Thanks for trying %1!").arg tr("Thanks for trying %1!\n\n%2 days of your trial remain").arg
(m_LicenseManager->getEditionName(edition))); (m_LicenseManager->getEditionName(edition)).arg
(m_LicenseManager->serialKey().daysLeft(::time(0))));
} }
else { else {
message.information(this, "Activated!", message.information(this, "Activated!",

View File

@ -26,22 +26,16 @@
LicenseManager::LicenseManager(AppConfig* appConfig) : LicenseManager::LicenseManager(AppConfig* appConfig) :
m_AppConfig(appConfig), m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) { m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
/* Remove garbage serial keys from the registry */
m_AppConfig->setSerialKey("");
m_AppConfig->saveSettings();
}
} }
std::pair<bool, QString> std::pair<bool, QString>
LicenseManager::setSerialKey(QString serialKeyString) LicenseManager::setSerialKey(QString serialKeyString, bool acceptExpired)
{ {
std::pair<bool, QString> ret (true, ""); std::pair<bool, QString> ret (true, "");
time_t currentTime = ::time(0);
SerialKey serialKey (serialKeyString.toStdString()); SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isExpired(::time(0))) {
if (!acceptExpired && serialKey.isExpired(currentTime)) {
ret.first = false; ret.first = false;
ret.second = "Serial key expired"; ret.second = "Serial key expired";
return ret; return ret;
@ -50,22 +44,25 @@ LicenseManager::setSerialKey(QString serialKeyString)
if (serialKey != m_serialKey) { if (serialKey != m_serialKey) {
using std::swap; using std::swap;
swap (serialKey, m_serialKey); swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey (serialKeyString); m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString); notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (m_serialKey); emit serialKeyChanged (m_serialKey);
if (serialKey.isTrial()) {
emit endTrial(false);
}
if (m_serialKey.edition() != serialKey.edition()) { if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition (m_serialKey.edition()); m_AppConfig->setEdition (m_serialKey.edition());
emit editionChanged (m_serialKey.edition()); emit editionChanged (m_serialKey.edition());
} }
if (serialKey.isTrial()) {
emit endTrial(false);
}
if (m_serialKey.isTrial()) { if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0))); if (m_serialKey.isExpired(currentTime)) {
emit endTrial(true);
} else {
emit beginTrial(m_serialKey.isExpiring(currentTime));
}
} }
m_AppConfig->saveSettings(); m_AppConfig->saveSettings();
@ -92,13 +89,9 @@ LicenseManager::serialKey() const
return m_serialKey; return m_serialKey;
} }
void LicenseManager::refresh() const void LicenseManager::refresh(bool acceptExpired)
{ {
emit serialKeyChanged (m_serialKey); setSerialKey (m_AppConfig->serialKey(), acceptExpired);
emit editionChanged (m_serialKey.edition());
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
} }
void LicenseManager::skipActivation() void LicenseManager::skipActivation()

View File

@ -30,8 +30,8 @@ class LicenseManager: public QObject
public: public:
LicenseManager(AppConfig* appConfig); LicenseManager(AppConfig* appConfig);
std::pair<bool, QString> setSerialKey(QString serialKey); std::pair<bool, QString> setSerialKey(QString serialKey, bool acceptExpired = false);
void refresh() const; void refresh(bool acceptExpired = false);
Edition activeEdition() const; Edition activeEdition() const;
QString activeEditionName() const; QString activeEditionName() const;
SerialKey serialKey() const; SerialKey serialKey() const;

View File

@ -154,7 +154,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
connect (m_AppConfig, SIGNAL(sslToggled(bool)), connect (m_AppConfig, SIGNAL(sslToggled(bool)),
this, SLOT(sslToggled(bool)), Qt::QueuedConnection); this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
m_LicenseManager->refresh(); setWindowTitle (m_LicenseManager->activeEditionName());
m_LicenseManager->refresh(true);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -1064,15 +1065,14 @@ void MainWindow::beginTrial(bool isExpiring)
QString expiringNotice ("<html><head/><body><p><span style=\"" QString expiringNotice ("<html><head/><body><p><span style=\""
"font-weight:600;\">%1</span> days of " "font-weight:600;\">%1</span> days of "
"your %2 trial remain. <a href=" "your %2 trial remain. <a href="
"\"http://symless.com/synergy/trial/thanks?id=%3\">" "\"http://symless.com/pricing\">"
"<span style=\"text-decoration: underline;" "<span style=\"text-decoration: underline;"
" color:#0000ff;\">Buy now!</span></a>" " color:#0000ff;\">Buy now!</span></a>"
"</p></body></html>"); "</p></body></html>");
expiringNotice = expiringNotice.arg expiringNotice = expiringNotice
(m_LicenseManager->serialKey().daysLeft(::time(0))).arg .arg (m_LicenseManager->serialKey().daysLeft(::time(0)))
(LicenseManager::getEditionName(m_LicenseManager->activeEdition())).arg .arg (LicenseManager::getEditionName
(QString::fromStdString(m_LicenseManager->serialKey().toString())); (m_LicenseManager->activeEdition()));
this->m_trialLabel->setText(expiringNotice); this->m_trialLabel->setText(expiringNotice);
this->m_trialWidget->show(); this->m_trialWidget->show();
} }
@ -1081,7 +1081,22 @@ void MainWindow::beginTrial(bool isExpiring)
void MainWindow::endTrial(bool isExpired) void MainWindow::endTrial(bool isExpired)
{ {
if (!isExpired) { if (isExpired) {
QString expiredNotice (
"<html><head/><body><p>Your %1 trial has expired. <a href="
"\"http://symless.com/synergy/trial/thanks?id=%2\">"
"<span style=\"text-decoration: underline;color:#0000ff;\">"
"Buy now!</span></a></p></body></html>"
);
expiredNotice = expiredNotice
.arg(LicenseManager::getEditionName
(m_LicenseManager->activeEdition()))
.arg(QString::fromStdString
(m_LicenseManager->serialKey().toString()));
this->m_trialLabel->setText(expiredNotice);
this->m_trialWidget->show();
} else {
this->m_trialWidget->hide(); this->m_trialWidget->hide();
} }
setWindowTitle (m_LicenseManager->activeEditionName()); setWindowTitle (m_LicenseManager->activeEditionName());