#5657 Handle expired keys properly
This commit is contained in:
parent
020b7974df
commit
02c23905d6
|
@ -81,8 +81,9 @@ void ActivationDialog::accept()
|
|||
if (edition != kUnregistered) {
|
||||
if (m_LicenseManager->serialKey().isTrial()) {
|
||||
message.information(this, "Thanks!",
|
||||
tr("Thanks for trying %1!").arg
|
||||
(m_LicenseManager->getEditionName(edition)));
|
||||
tr("Thanks for trying %1!\n\n%2 days of your trial remain").arg
|
||||
(m_LicenseManager->getEditionName(edition)).arg
|
||||
(m_LicenseManager->serialKey().daysLeft(::time(0))));
|
||||
}
|
||||
else {
|
||||
message.information(this, "Activated!",
|
||||
|
|
|
@ -26,22 +26,16 @@
|
|||
LicenseManager::LicenseManager(AppConfig* appConfig) :
|
||||
m_AppConfig(appConfig),
|
||||
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>
|
||||
LicenseManager::setSerialKey(QString serialKeyString)
|
||||
LicenseManager::setSerialKey(QString serialKeyString, bool acceptExpired)
|
||||
{
|
||||
std::pair<bool, QString> ret (true, "");
|
||||
|
||||
time_t currentTime = ::time(0);
|
||||
SerialKey serialKey (serialKeyString.toStdString());
|
||||
if (serialKey.isExpired(::time(0))) {
|
||||
|
||||
if (!acceptExpired && serialKey.isExpired(currentTime)) {
|
||||
ret.first = false;
|
||||
ret.second = "Serial key expired";
|
||||
return ret;
|
||||
|
@ -50,22 +44,25 @@ LicenseManager::setSerialKey(QString serialKeyString)
|
|||
if (serialKey != m_serialKey) {
|
||||
using std::swap;
|
||||
swap (serialKey, m_serialKey);
|
||||
|
||||
m_AppConfig->setSerialKey (serialKeyString);
|
||||
notifyActivation ("serial:" + serialKeyString);
|
||||
emit serialKeyChanged (m_serialKey);
|
||||
|
||||
if (serialKey.isTrial()) {
|
||||
emit endTrial(false);
|
||||
}
|
||||
|
||||
if (m_serialKey.edition() != serialKey.edition()) {
|
||||
m_AppConfig->setEdition (m_serialKey.edition());
|
||||
emit editionChanged (m_serialKey.edition());
|
||||
}
|
||||
|
||||
if (serialKey.isTrial()) {
|
||||
emit endTrial(false);
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -92,13 +89,9 @@ LicenseManager::serialKey() const
|
|||
return m_serialKey;
|
||||
}
|
||||
|
||||
void LicenseManager::refresh() const
|
||||
void LicenseManager::refresh(bool acceptExpired)
|
||||
{
|
||||
emit serialKeyChanged (m_serialKey);
|
||||
emit editionChanged (m_serialKey.edition());
|
||||
if (m_serialKey.isTrial()) {
|
||||
emit beginTrial(m_serialKey.isExpiring(::time(0)));
|
||||
}
|
||||
setSerialKey (m_AppConfig->serialKey(), acceptExpired);
|
||||
}
|
||||
|
||||
void LicenseManager::skipActivation()
|
||||
|
|
|
@ -30,8 +30,8 @@ class LicenseManager: public QObject
|
|||
|
||||
public:
|
||||
LicenseManager(AppConfig* appConfig);
|
||||
std::pair<bool, QString> setSerialKey(QString serialKey);
|
||||
void refresh() const;
|
||||
std::pair<bool, QString> setSerialKey(QString serialKey, bool acceptExpired = false);
|
||||
void refresh(bool acceptExpired = false);
|
||||
Edition activeEdition() const;
|
||||
QString activeEditionName() const;
|
||||
SerialKey serialKey() const;
|
||||
|
|
|
@ -154,7 +154,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
|
|||
connect (m_AppConfig, SIGNAL(sslToggled(bool)),
|
||||
this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
|
||||
|
||||
m_LicenseManager->refresh();
|
||||
setWindowTitle (m_LicenseManager->activeEditionName());
|
||||
m_LicenseManager->refresh(true);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -1064,15 +1065,14 @@ void MainWindow::beginTrial(bool isExpiring)
|
|||
QString expiringNotice ("<html><head/><body><p><span style=\""
|
||||
"font-weight:600;\">%1</span> days of "
|
||||
"your %2 trial remain. <a href="
|
||||
"\"http://symless.com/synergy/trial/thanks?id=%3\">"
|
||||
"\"http://symless.com/pricing\">"
|
||||
"<span style=\"text-decoration: underline;"
|
||||
" color:#0000ff;\">Buy now!</span></a>"
|
||||
"</p></body></html>");
|
||||
expiringNotice = expiringNotice.arg
|
||||
(m_LicenseManager->serialKey().daysLeft(::time(0))).arg
|
||||
(LicenseManager::getEditionName(m_LicenseManager->activeEdition())).arg
|
||||
(QString::fromStdString(m_LicenseManager->serialKey().toString()));
|
||||
|
||||
expiringNotice = expiringNotice
|
||||
.arg (m_LicenseManager->serialKey().daysLeft(::time(0)))
|
||||
.arg (LicenseManager::getEditionName
|
||||
(m_LicenseManager->activeEdition()));
|
||||
this->m_trialLabel->setText(expiringNotice);
|
||||
this->m_trialWidget->show();
|
||||
}
|
||||
|
@ -1081,7 +1081,22 @@ void MainWindow::beginTrial(bool isExpiring)
|
|||
|
||||
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();
|
||||
}
|
||||
setWindowTitle (m_LicenseManager->activeEditionName());
|
||||
|
|
Loading…
Reference in New Issue