#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

@ -77,10 +77,18 @@ void ActivationDialog::accept()
return; return;
} }
if (m_subscriptionManager->activeEdition() != kUnregistered) { 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!", message.information(this, "Activated!",
tr("Thanks for activating %1!").arg tr("Thanks for activating %1!").arg
(m_subscriptionManager->activeEditionName())); (m_subscriptionManager->getEditionName(edition)));
}
} }
QDialog::accept(); QDialog::accept();

View File

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

View File

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