diff --git a/src/gui/res/MainWindowBase.ui b/src/gui/res/MainWindowBase.ui index ac70cfd9..b3fb0a75 100644 --- a/src/gui/res/MainWindowBase.ui +++ b/src/gui/res/MainWindowBase.ui @@ -55,7 +55,7 @@ - <html><head/><body><p><span style=" font-weight:600;">6</span> days of your Synergy Pro trial remain. <a href="http://symless.com/pricing?src=gui"><span style=" text-decoration: underline; color:#0000ff;">Buy now!</span></a></p></body></html> + <html><head/><body><p><span style=" font-weight:600;">%1</span> days of your Synergy Pro trial remain. <a href="http://symless.com/pricing?src=gui"><span style=" text-decoration: underline; color:#0000ff;">Buy now!</span></a></p></body></html> true diff --git a/src/gui/src/ActivationDialog.cpp b/src/gui/src/ActivationDialog.cpp index 62bc0e23..1dbef32e 100644 --- a/src/gui/src/ActivationDialog.cpp +++ b/src/gui/src/ActivationDialog.cpp @@ -39,7 +39,7 @@ ActivationDialog::~ActivationDialog() void ActivationDialog::reject() { - if (m_subscriptionManager->activeLicense() == kUnregistered) { + if (m_subscriptionManager->activeEdition() == kUnregistered) { CancelActivationDialog cancelActivationDialog(this); if (QDialog::Accepted == cancelActivationDialog.exec()) { m_subscriptionManager->skipActivation(); @@ -53,28 +53,35 @@ void ActivationDialog::reject() void ActivationDialog::accept() { QMessageBox message; - QString error; - m_appConfig->activationHasRun(true); m_appConfig->saveSettings(); + std::pair result; try { QString serialKey = ui->m_pTextEditSerialKey->toPlainText(); - m_subscriptionManager->setSerialKey(serialKey); + result = m_subscriptionManager->setSerialKey(serialKey); } catch (std::exception& e) { message.critical(this, "Unknown Error", tr("An error occurred while trying to activate Synergy. " "Please contact the helpdesk, and provide the " - "following details.\n\n%1").arg(e.what())); + "following information:\n\n%1").arg(e.what())); refreshSerialKey(); return; } - if (m_subscriptionManager->activeLicense() != kUnregistered) { + if (!result.first) { + message.critical(this, "Activation failed", + tr("%1").arg(result.second)); + refreshSerialKey(); + return; + } + + if (m_subscriptionManager->activeEdition() != kUnregistered) { message.information(this, "Activated!", tr("Thanks for activating %1!").arg - (getEditionName(m_subscriptionManager->activeLicense()))); + (m_subscriptionManager->activeEditionName())); } + QDialog::accept(); } diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index ad9d37d0..76244627 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -154,7 +154,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig, connect (m_AppConfig, SIGNAL(sslToggled(bool)), this, SLOT(sslToggled(bool)), Qt::QueuedConnection); - m_SubscriptionManager->update(); + m_SubscriptionManager->refresh(); } MainWindow::~MainWindow() @@ -547,6 +547,10 @@ void MainWindow::startSynergy() args << "--name" << getScreenName(); + if (!appConfig().serialKey().isEmpty()) { + args << "--serial-key " << appConfig().serialKey(); + } + if (desktopMode) { setSynergyProcess(new QProcess(this)); @@ -1038,7 +1042,7 @@ void MainWindow::serverDetected(const QString name) void MainWindow::setEdition(Edition edition) { - setWindowTitle(getEditionName(edition)); + setWindowTitle(m_SubscriptionManager->getEditionName (edition)); if (m_AppConfig->getCryptoEnabled()) { m_pSslCertificate = new SslCertificate(this); m_pSslCertificate->generateCertificate(); @@ -1050,8 +1054,19 @@ void MainWindow::setEdition(Edition edition) void MainWindow::beginTrial(bool isExpiring) { if (isExpiring) { + QString expiringNotice = "

%1 days of " + "your Synergy Pro trial remain. " + "Buy now!" + "

"; + expiringNotice = expiringNotice.arg + (m_SubscriptionManager->serialKey().daysLeft(::time(0))); + this->m_trialLabel->setText(expiringNotice); this->m_trialWidget->show(); } + setWindowTitle (m_SubscriptionManager->activeEditionName()); } void MainWindow::endTrial(bool isExpired) @@ -1059,6 +1074,7 @@ void MainWindow::endTrial(bool isExpired) if (!isExpired) { this->m_trialWidget->hide(); } + setWindowTitle (m_SubscriptionManager->activeEditionName()); } void MainWindow::updateLocalFingerprint() diff --git a/src/gui/src/QUtility.cpp b/src/gui/src/QUtility.cpp index c35f9638..589e74cf 100644 --- a/src/gui/src/QUtility.cpp +++ b/src/gui/src/QUtility.cpp @@ -43,19 +43,6 @@ void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData) } } -QString -getEditionName (int edition) { - if (edition == kBasic) { - return "Synergy Basic"; - } - else if (edition == kPro) { - return "Synergy Pro"; - } - else { - return "Synergy (UNREGISTERED)"; - } -} - QString hash(const QString& string) { QByteArray data = string.toUtf8(); diff --git a/src/gui/src/QUtility.h b/src/gui/src/QUtility.h index ca00d06f..0738d96c 100644 --- a/src/gui/src/QUtility.h +++ b/src/gui/src/QUtility.h @@ -29,4 +29,3 @@ QString hash(const QString& string); QString getFirstMacAddress(); qProcessorArch getProcessorArch(); QString getOSInformation(); -QString getEditionName (int edition); diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 17a1b432..b42cc98d 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -20,6 +20,7 @@ #include "AppConfig.h" #include #include +#include #include SubscriptionManager::SubscriptionManager(AppConfig* appConfig) : @@ -28,18 +29,24 @@ SubscriptionManager::SubscriptionManager(AppConfig* appConfig) : try { setSerialKey(m_AppConfig->serialKey()); } catch (...) { + /* Remove garbage serial keys from the registry */ m_AppConfig->setSerialKey(""); + m_AppConfig->setEdition(kUnregistered); m_AppConfig->saveSettings(); } } -SerialKey +std::pair SubscriptionManager::setSerialKey(QString serialKeyString) { + std::pair ret (true, ""); + SerialKey serialKey (serialKeyString.toStdString()); - if (!serialKey.isValid (::time(0))) { - throw std::runtime_error ("Invalid serial key"); - } + if (serialKey.isExpired(::time(0))) { + ret.first = false; + ret.second = "Serial key expired"; + return ret; + } if (serialKey != m_serialKey) { using std::swap; @@ -65,15 +72,28 @@ SubscriptionManager::setSerialKey(QString serialKeyString) m_AppConfig->saveSettings(); } - return serialKey; + return ret; } -Edition SubscriptionManager::activeLicense() const +Edition +SubscriptionManager::activeEdition() const { - return m_serialKey.edition(); + return m_serialKey.edition(); } -void SubscriptionManager::update() const +QString +SubscriptionManager::activeEditionName() const +{ + return getEditionName(activeEdition(), m_serialKey.isTrial()); +} + +SerialKey +SubscriptionManager::serialKey() const +{ + return m_serialKey; +} + +void SubscriptionManager::refresh() const { emit serialKeyChanged (m_serialKey); emit editionChanged (m_serialKey.edition()); @@ -84,7 +104,27 @@ void SubscriptionManager::update() const void SubscriptionManager::skipActivation() { - notifyActivation ("skip:unknown"); + notifyActivation ("skip:unknown"); +} + +QString +SubscriptionManager::getEditionName(Edition const edition, bool trial) +{ + std::string name ("Synergy "); + switch (edition) { + case kUnregistered: + name += "(UNREGISTERED)"; + return QString::fromUtf8 (name.c_str(), name.size()); + case kBasic: + name += "Basic"; + break; + default: + name += "Pro"; + } + if (trial) { + name += " (Trial)"; + } + return QString::fromUtf8 (name.c_str(), name.size()); } void SubscriptionManager::notifyActivation(QString identity) diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index 56c3e48c..5023ddc2 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -20,6 +20,7 @@ #include #include #include +#include class AppConfig; @@ -29,10 +30,13 @@ class SubscriptionManager: public QObject public: SubscriptionManager(AppConfig* appConfig); - SerialKey setSerialKey(QString serialKey); - void update() const; - Edition activeLicense() const; + std::pair setSerialKey(QString serialKey); + void refresh() const; + Edition activeEdition() const; + QString activeEditionName() const; + SerialKey serialKey() const; void skipActivation(); + static QString getEditionName(Edition edition, bool trial = false); private: void notifyActivation(QString identity); diff --git a/src/lib/shared/SerialKey.cpp b/src/lib/shared/SerialKey.cpp index 77b353dd..ef3588ef 100644 --- a/src/lib/shared/SerialKey.cpp +++ b/src/lib/shared/SerialKey.cpp @@ -22,6 +22,9 @@ #include #include #include +#include +#include +#include using namespace std; @@ -47,6 +50,9 @@ SerialKey::SerialKey(std::string serial) : if (!plainText.empty()) { parse(plainText); } + if (!m_valid) { + throw std::runtime_error ("Invalid serial key"); + } } bool @@ -105,7 +111,51 @@ SerialKey::isTrial() const Edition SerialKey::edition() const { - return m_edition; + return m_edition; +} + +std::string +SerialKey::editionString() const +{ + switch (edition()) { + case kBasic: + return "basic"; + case kPro: + return "pro"; + default: { + std::ostringstream oss; + oss << static_cast(edition()); + return oss.str(); + } + } +} + +static std::string +hexEncode (std::string const& str) { + std::ostringstream oss; + for (size_t i = 0; i < str.size(); ++i) { + int c = str[i]; + oss << std::setfill('0') << std::hex << std::setw(2) + << std::uppercase; + oss << c; + } + return oss.str(); +} + +std::string +SerialKey::toString() const +{ + std::ostringstream oss; + oss << "v2;"; + oss << (isTrial() ? "trial" : "lifetime") << ";"; + oss << editionString() << ";"; + oss << m_name << ";"; + oss << m_userLimit << ";"; + oss << m_email << ";"; + oss << m_company << ";"; + oss << m_warnTime << ";"; + oss << m_expireTime; + return hexEncode(oss.str()); } time_t @@ -118,10 +168,16 @@ SerialKey::daysLeft(time_t currentTime) const timeLeft = m_expireTime - currentTime; } - unsigned long long dayLeft = 0; - dayLeft = timeLeft % day != 0 ? 1 : 0; + unsigned long long daysLeft = 0; + daysLeft = timeLeft % day != 0 ? 1 : 0; - return timeLeft / day + dayLeft; + return timeLeft / day + daysLeft; +} + +std::string +SerialKey::email() const +{ + return m_email; } std::string @@ -208,7 +264,7 @@ SerialKey::parse(std::string plainSerial) } Edition -SerialKey::parseEdition(std::string editionStr) +SerialKey::parseEdition(std::string const& editionStr) { Edition e = kBasic; if (editionStr == "pro") { diff --git a/src/lib/shared/SerialKey.h b/src/lib/shared/SerialKey.h index 01884d86..dd73ad16 100644 --- a/src/lib/shared/SerialKey.h +++ b/src/lib/shared/SerialKey.h @@ -36,12 +36,15 @@ public: bool isExpired(time_t currentTime) const; bool isTrial() const; time_t daysLeft(time_t currentTime) const; + std::string email() const; Edition edition() const; + std::string toString() const; private: std::string decode(const std::string& serial) const; void parse(std::string plainSerial); - Edition parseEdition(std::string editionStr); + Edition parseEdition(const std::string& editionStr); + std::string editionString() const; #ifdef TEST_ENV private: