#5657 Remove SerialKey::m_valid

This commit is contained in:
Andrew Nelless 2016-10-17 17:08:26 +01:00
parent c7dc198d82
commit 8b4d7abfb0
4 changed files with 934 additions and 950 deletions

View File

@ -15,73 +15,81 @@
#include <iostream>
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
SubscriptionManager& subscriptionManager) :
QDialog(parent),
ui(new Ui::ActivationDialog),
m_appConfig(&appConfig),
m_subscriptionManager (&subscriptionManager)
SubscriptionManager& subscriptionManager) :
QDialog(parent),
ui(new Ui::ActivationDialog),
m_appConfig(&appConfig),
m_subscriptionManager (&subscriptionManager)
{
ui->setupUi(this);
refreshSerialKey();
ui->setupUi(this);
refreshSerialKey();
}
void ActivationDialog::refreshSerialKey()
{
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
}
ActivationDialog::~ActivationDialog()
{
delete ui;
delete ui;
}
void ActivationDialog::reject()
{
if (m_subscriptionManager->activeEdition() == kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->skipActivation();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
}
}
QDialog::reject();
if (m_subscriptionManager->activeEdition() == kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->skipActivation();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
}
}
QDialog::reject();
}
void ActivationDialog::accept()
{
QMessageBox message;
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
QMessageBox message;
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
std::pair<bool, QString> result;
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
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 information:\n\n%1").arg(e.what()));
refreshSerialKey();
return;
}
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
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 information:\n\n%1").arg(e.what()));
refreshSerialKey();
return;
}
if (!result.first) {
message.critical(this, "Activation failed",
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
(m_subscriptionManager->activeEditionName()));
}
Edition edition = m_subscriptionManager->activeEdition();
if (edition != kUnregistered) {
if (m_subscriptionManager->serialKey().isTrial()) {
message.information(this, "Thanks!",
tr("Thanks for trying %1!").arg
(m_subscriptionManager->getEditionName(edition)));
}
else {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(m_subscriptionManager->getEditionName(edition)));
}
}
QDialog::accept();
QDialog::accept();
}

File diff suppressed because it is too large Load Diff

View File

@ -33,8 +33,7 @@ SerialKey::SerialKey(Edition edition):
m_warnTime(ULLONG_MAX),
m_expireTime(ULLONG_MAX),
m_edition(edition),
m_trial(false),
m_valid(true)
m_trial(false)
{
}
@ -43,46 +42,25 @@ SerialKey::SerialKey(std::string serial) :
m_warnTime(0),
m_expireTime(0),
m_edition(kBasic),
m_trial(true),
m_valid(false)
m_trial(true)
{
string plainText = decode(serial);
bool valid = false;
if (!plainText.empty()) {
parse(plainText);
valid = parse(plainText);
}
if (!m_valid) {
if (!valid) {
throw std::runtime_error ("Invalid serial key");
}
}
bool
SerialKey::isValid(time_t currentTime) const
{
bool result = false;
if (m_valid) {
if (m_trial) {
if (currentTime < m_expireTime) {
result = true;
}
}
else {
result = true;
}
}
return result;
}
bool
SerialKey::isExpiring(time_t currentTime) const
{
bool result = false;
if (m_valid) {
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
result = true;
}
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
result = true;
}
return result;
@ -93,12 +71,11 @@ SerialKey::isExpired(time_t currentTime) const
{
bool result = false;
if (m_valid) {
if (m_expireTime <= currentTime) {
result = true;
}
if (m_expireTime <= currentTime) {
result = true;
}
return result;
}
@ -209,13 +186,13 @@ SerialKey::decode(const std::string& serial)
return output;
}
void
bool
SerialKey::parse(std::string plainSerial)
{
string parityStart = plainSerial.substr(0, 1);
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
m_valid = false;
bool valid = false;
// check for parity chars { and }, record parity result, then remove them.
if (parityStart == "{" && parityEnd == "}") {
@ -247,7 +224,7 @@ SerialKey::parse(std::string plainSerial)
m_company = parts.at(5);
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
m_valid = true;
valid = true;
}
else if ((parts.size() == 9)
&& (parts.at(0).find("v2") != string::npos)) {
@ -260,9 +237,11 @@ SerialKey::parse(std::string plainSerial)
m_company = parts.at(6);
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
m_valid = true;
valid = true;
}
}
return valid;
}
Edition

View File

@ -31,7 +31,6 @@ public:
explicit SerialKey(Edition edition = kUnregistered);
explicit SerialKey(std::string serial);
bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const;
bool isExpired(time_t currentTime) const;
bool isTrial() const;
@ -44,7 +43,7 @@ public:
static Edition parseEdition(const std::string& editionStr);
private:
void parse(std::string plainSerial);
bool parse(std::string plainSerial);
std::string editionString() const;
#ifdef TEST_ENV
@ -67,7 +66,6 @@ private:
unsigned long long m_expireTime;
Edition m_edition;
bool m_trial;
bool m_valid;
};
@ -80,8 +78,7 @@ operator== (SerialKey const& lhs, SerialKey const& rhs) {
(lhs.m_warnTime == rhs.m_warnTime) &&
(lhs.m_expireTime == rhs.m_expireTime) &&
(lhs.m_edition == rhs.m_edition) &&
(lhs.m_trial == rhs.m_trial) &&
(lhs.m_valid == rhs.m_valid);
(lhs.m_trial == rhs.m_trial);
}
inline bool