diff --git a/ChangeLog b/ChangeLog index 039c46d520..a0978ce24f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,10 +8,12 @@ Bug fixes: - #6760 Synergy loses license when creating a System scope config - #6342 Updated copyright year in version to use build date - #6771 Added Ubuntu 16 to CI/CD -- #6792 License key expiry + Enhancements: - #6750 Integrate SonarCloud for static analysis and test coverage +- #6792 License key expiry +- #6799 Synergy "Business" edition v1.12.0-stable =========== diff --git a/src/gui/src/LicenseManager.cpp b/src/gui/src/LicenseManager.cpp index cd4272c591..1447b91bfa 100644 --- a/src/gui/src/LicenseManager.cpp +++ b/src/gui/src/LicenseManager.cpp @@ -126,20 +126,13 @@ LicenseManager::skipActivation() const QString LicenseManager::getEditionName(Edition const edition, bool trial) { - std::string name ("Synergy 1"); - switch (edition) { - case kUnregistered: - name += " (UNREGISTERED)"; - return QString::fromUtf8 (name.c_str(), static_cast(name.size())); - case kBasic: - name += " Basic"; - break; - default: - name += " Pro"; - } + SerialKeyEdition KeyEdition(edition); + std::string name = KeyEdition.getDisplayName(); + if (trial) { name += " (Trial)"; } + return QString::fromUtf8 (name.c_str(), static_cast(name.size())); } diff --git a/src/lib/shared/EditionType.h b/src/lib/shared/EditionType.h index 6544f6134f..e2d9e38e47 100644 --- a/src/lib/shared/EditionType.h +++ b/src/lib/shared/EditionType.h @@ -24,7 +24,8 @@ enum Edition { kBasic, kPro, Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN, - kUnregistered + kUnregistered, + kBusiness }; #endif // EDITIONTYPE_H diff --git a/src/lib/shared/SerialKey.cpp b/src/lib/shared/SerialKey.cpp index f7c1118c24..08829ba014 100644 --- a/src/lib/shared/SerialKey.cpp +++ b/src/lib/shared/SerialKey.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "SerialKeyEdition.h" using namespace std; static std::string hexEncode (std::string const& str); @@ -98,23 +99,7 @@ SerialKey::isTemporary() const Edition SerialKey::edition() const { - 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(); - } - } + return m_edition.getType(); } static std::string @@ -145,7 +130,7 @@ SerialKey::toString() const } else { oss << "v1;"; } - oss << editionString() << ";"; + oss << m_edition.getName() << ";"; oss << m_name << ";"; oss << m_userLimit << ";"; oss << m_email << ";"; @@ -238,7 +223,7 @@ SerialKey::parse(std::string plainSerial) if ((parts.size() == 8) && (parts.at(0).find("v1") != string::npos)) { // e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000} - m_edition = parseEdition(parts.at(1)); + m_edition.setType(parts.at(1)); m_name = parts.at(2); sscanf(parts.at(3).c_str(), "%d", &m_userLimit); m_email = parts.at(4); @@ -251,7 +236,7 @@ SerialKey::parse(std::string plainSerial) && (parts.at(0).find("v2") != string::npos)) { // e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000} m_KeyType.setKeyType(parts.at(1)); - m_edition = parseEdition(parts.at(2)); + m_edition.setType(parts.at(2)); m_name = parts.at(3); sscanf(parts.at(4).c_str(), "%d", &m_userLimit); m_email = parts.at(5); @@ -264,14 +249,3 @@ SerialKey::parse(std::string plainSerial) return valid; } - -Edition -SerialKey::parseEdition(std::string const& editionStr) -{ - Edition e = kBasic; - if (editionStr == "pro") { - e = kPro; - } - - return e; -} diff --git a/src/lib/shared/SerialKey.h b/src/lib/shared/SerialKey.h index b8b78636fb..abb16fca41 100644 --- a/src/lib/shared/SerialKey.h +++ b/src/lib/shared/SerialKey.h @@ -21,6 +21,7 @@ #include #include "EditionType.h" #include "SerialKeyType.h" +#include "SerialKeyEdition.h" #ifdef TEST_ENV #include @@ -42,11 +43,9 @@ public: std::string toString() const; static std::string decode(const std::string& serial); - static Edition parseEdition(const std::string& editionStr); private: bool parse(std::string plainSerial); - std::string editionString() const; #ifdef TEST_ENV private: @@ -63,7 +62,7 @@ private: unsigned m_userLimit; unsigned long long m_warnTime; unsigned long long m_expireTime; - Edition m_edition; + SerialKeyEdition m_edition; SerialKeyType m_KeyType; }; diff --git a/src/lib/shared/SerialKeyEdition.cpp b/src/lib/shared/SerialKeyEdition.cpp new file mode 100644 index 0000000000..02c1cf25ac --- /dev/null +++ b/src/lib/shared/SerialKeyEdition.cpp @@ -0,0 +1,96 @@ +#include +#include "SerialKeyEdition.h" + +const std::string SerialKeyEdition::PRO = "pro"; +const std::string SerialKeyEdition::BASIC = "basic"; +const std::string SerialKeyEdition::BUSINESS = "business"; +const std::string SerialKeyEdition::UNREGISTERED = "unregistered"; + +SerialKeyEdition::SerialKeyEdition() +{ + +} + +SerialKeyEdition::SerialKeyEdition(Edition type) : + m_Type(type) +{ + +} + +SerialKeyEdition::SerialKeyEdition(const std::string &type) +{ + setType(type); +} + +Edition +SerialKeyEdition::getType() const +{ + return m_Type; +} + +std::string +SerialKeyEdition::getName() const +{ + std::string Name; + + switch(getType()){ + case kPro: + Name = PRO; + break; + case kBasic: + Name = BASIC; + break; + case kBusiness: + Name = BUSINESS; + break; + case kUnregistered: + Name = UNREGISTERED; + break; + default: + break; + } + + return Name; +} + +std::string +SerialKeyEdition::getDisplayName() const +{ + const std::string ApplicationName = "Synergy 1 "; + std::string EditionName = getName(); + + if (!EditionName.empty()){ + if (EditionName == UNREGISTERED){ + std::transform(EditionName.begin(), EditionName.end(), EditionName.begin(), ::toupper); + EditionName = "(" + EditionName +")"; + } + else{ + EditionName[0] = static_cast(::toupper(EditionName[0])); + } + } + + return (ApplicationName + EditionName); +} + +void +SerialKeyEdition::setType(Edition type) +{ + m_Type = type; +} + +void +SerialKeyEdition::setType(const std::string& type) +{ + if (type == BASIC){ + m_Type = kBasic; + } + else if (type == PRO){ + m_Type = kPro; + } + else if (type == BUSINESS){ + m_Type = kBusiness; + } + else{ + m_Type = kUnregistered; + } +} diff --git a/src/lib/shared/SerialKeyEdition.h b/src/lib/shared/SerialKeyEdition.h new file mode 100644 index 0000000000..43fdb9efb2 --- /dev/null +++ b/src/lib/shared/SerialKeyEdition.h @@ -0,0 +1,54 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2016 Symless Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include "EditionType.h" + +class SerialKeyEdition +{ + friend bool operator== (SerialKeyEdition const&, SerialKeyEdition const&); +public: + SerialKeyEdition(); + explicit SerialKeyEdition(Edition type); + explicit SerialKeyEdition(const std::string& type); + + Edition getType() const; + std::string getName() const; + std::string getDisplayName() const; + + void setType(Edition type); + void setType(const std::string& type); + + static const std::string PRO; + static const std::string BASIC; + static const std::string BUSINESS; + static const std::string UNREGISTERED; + +private: + Edition m_Type = kUnregistered; +}; + +inline bool +operator== (SerialKeyEdition const& lhs, SerialKeyEdition const& rhs) { + return (lhs.m_Type == rhs.m_Type); +} + +inline bool +operator!= (SerialKeyEdition const& lhs, SerialKeyEdition const& rhs) { + return !(lhs == rhs); +} diff --git a/src/test/unittests/shared/SerialKeyEditionTests.cpp b/src/test/unittests/shared/SerialKeyEditionTests.cpp new file mode 100644 index 0000000000..b70c06c658 --- /dev/null +++ b/src/test/unittests/shared/SerialKeyEditionTests.cpp @@ -0,0 +1,61 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2016 Symless Inc. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define TEST_ENV + +#include "shared/SerialKeyEdition.h" +#include "test/global/gtest.h" + +TEST(SerialKeyEditionTests, DefaultEditionType_Unregistered) +{ + SerialKeyEdition edition; + EXPECT_EQ(kUnregistered, edition.getType()); + EXPECT_EQ(SerialKeyEdition::UNREGISTERED, edition.getName()); + EXPECT_EQ("Synergy 1 (UNREGISTERED)", edition.getDisplayName()); + +} + +TEST(SerialKeyEditionTests, SetEditionType_edition) +{ + SerialKeyEdition edition; + edition.setType(kPro); + EXPECT_EQ(kPro, edition.getType()); + EXPECT_EQ(SerialKeyEdition::PRO, edition.getName()); + EXPECT_EQ("Synergy 1 Pro", edition.getDisplayName()); +} + +TEST(SerialKeyEditionTests, SetEditionType_string) +{ + SerialKeyEdition edition; + edition.setType(SerialKeyEdition::BASIC); + EXPECT_EQ(kBasic, edition.getType()); + EXPECT_EQ(SerialKeyEdition::BASIC, edition.getName()); + EXPECT_EQ("Synergy 1 Basic", edition.getDisplayName()); +} + +TEST(SerialKeyEditionTests, SetEditionBusiness) +{ + SerialKeyEdition edition; + edition.setType(kBusiness); + EXPECT_EQ(kBusiness, edition.getType()); + EXPECT_EQ(SerialKeyEdition::BUSINESS, edition.getName()); + EXPECT_EQ("Synergy 1 Business", edition.getDisplayName()); +} + + + +