Merge pull request #6799 from symless/SYNERGY-315-Synergy-Business-edition

SYNERGY-315 Synergy "Business" edition
This commit is contained in:
SerhiiGadzhilov 2020-10-02 12:41:54 +03:00 committed by GitHub
commit 19160b94fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 227 additions and 47 deletions

View File

@ -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
===========

View File

@ -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<int>(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<int>(name.size()));
}

View File

@ -24,7 +24,8 @@ enum Edition {
kBasic,
kPro,
Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN,
kUnregistered
kUnregistered,
kBusiness
};
#endif // EDITIONTYPE_H

View File

@ -25,6 +25,7 @@
#include <sstream>
#include <iomanip>
#include <stdexcept>
#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<int>(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;
}

View File

@ -21,6 +21,7 @@
#include <ctime>
#include "EditionType.h"
#include "SerialKeyType.h"
#include "SerialKeyEdition.h"
#ifdef TEST_ENV
#include <gtest/gtest_prod.h>
@ -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;
};

View File

@ -0,0 +1,96 @@
#include <algorithm>
#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<char>(::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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#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);
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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());
}