#5657 Rename SubscriptionManager to LicenseManager

This commit is contained in:
Andrew Nelless 2016-10-17 17:57:14 +01:00
parent 5a34da3ce0
commit fc67cdf56e
10 changed files with 208 additions and 208 deletions

View File

@ -61,12 +61,12 @@ SOURCES += src/main.cpp \
src/Fingerprint.cpp \
src/SslCertificate.cpp \
src/WebClient.cpp \
src/SubscriptionManager.cpp \
src/ActivationNotifier.cpp \
src/ActivationDialog.cpp \
src/CancelActivationDialog.cpp \
src/FailedLoginDialog.cpp \
../lib/shared/SerialKey.cpp
../lib/shared/SerialKey.cpp \
src/LicenseManager.cpp
HEADERS += src/MainWindow.h \
src/AboutDialog.h \
src/ServerConfig.h \
@ -108,14 +108,14 @@ HEADERS += src/MainWindow.h \
src/Fingerprint.h \
src/SslCertificate.h \
src/WebClient.h \
src/SubscriptionManager.h \
src/ActivationNotifier.h \
src/ElevateMode.h \
src/ActivationDialog.h \
src/CancelActivationDialog.h \
src/FailedLoginDialog.h \
../lib/shared/EditionType.h \
../lib/shared/SerialKey.h
../lib/shared/SerialKey.h \
src/LicenseManager.h
RESOURCES += res/Synergy.qrc
RC_FILE = res/win/Synergy.rc
macx {

View File

@ -7,7 +7,7 @@
#include "ActivationNotifier.h"
#include "MainWindow.h"
#include "QUtility.h"
#include "SubscriptionManager.h"
#include "LicenseManager.h"
#include "FailedLoginDialog.h"
#include <QMessageBox>
@ -15,11 +15,11 @@
#include <iostream>
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
SubscriptionManager& subscriptionManager) :
LicenseManager& licenseManager) :
QDialog(parent),
ui(new Ui::ActivationDialog),
m_appConfig(&appConfig),
m_subscriptionManager (&subscriptionManager)
m_LicenseManager (&licenseManager)
{
ui->setupUi(this);
refreshSerialKey();
@ -39,10 +39,10 @@ ActivationDialog::~ActivationDialog()
void ActivationDialog::reject()
{
if (m_subscriptionManager->activeEdition() == kUnregistered) {
if (m_LicenseManager->activeEdition() == kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->skipActivation();
m_LicenseManager->skipActivation();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
}
@ -59,7 +59,7 @@ void ActivationDialog::accept()
std::pair<bool, QString> result;
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
result = m_subscriptionManager->setSerialKey(serialKey);
result = m_LicenseManager->setSerialKey(serialKey);
}
catch (std::exception& e) {
message.critical(this, "Unknown Error",
@ -77,17 +77,17 @@ void ActivationDialog::accept()
return;
}
Edition edition = m_subscriptionManager->activeEdition();
Edition edition = m_LicenseManager->activeEdition();
if (edition != kUnregistered) {
if (m_subscriptionManager->serialKey().isTrial()) {
if (m_LicenseManager->serialKey().isTrial()) {
message.information(this, "Thanks!",
tr("Thanks for trying %1!").arg
(m_subscriptionManager->getEditionName(edition)));
(m_LicenseManager->getEditionName(edition)));
}
else {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(m_subscriptionManager->getEditionName(edition)));
(m_LicenseManager->getEditionName(edition)));
}
}

View File

@ -2,7 +2,7 @@
#define ACTIVATIONDIALOG_H
#include <QDialog>
#include <SubscriptionManager.h>
#include <LicenseManager.h>
namespace Ui {
class ActivationDialog;
@ -16,7 +16,7 @@ class ActivationDialog : public QDialog
public:
ActivationDialog(QWidget *parent, AppConfig& appConfig,
SubscriptionManager& subscriptionManager);
LicenseManager& licenseManager);
~ActivationDialog();
public slots:
@ -29,7 +29,7 @@ protected:
private:
Ui::ActivationDialog *ui;
AppConfig* m_appConfig;
SubscriptionManager* m_subscriptionManager;
LicenseManager* m_LicenseManager;
};
#endif // ACTIVATIONDIALOG_H

View File

@ -0,0 +1,144 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015 Synergy Seamless 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/>.
*/
#include "LicenseManager.h"
#include "EditionType.h"
#include "AppConfig.h"
#include <ctime>
#include <stdexcept>
#include <utility>
#include <QThread>
LicenseManager::LicenseManager(AppConfig* appConfig) :
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
/* Remove garbage serial keys from the registry */
m_AppConfig->setSerialKey("");
m_AppConfig->setEdition(kUnregistered);
m_AppConfig->saveSettings();
}
}
std::pair<bool, QString>
LicenseManager::setSerialKey(QString serialKeyString)
{
std::pair<bool, QString> ret (true, "");
SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isExpired(::time(0))) {
ret.first = false;
ret.second = "Serial key expired";
return ret;
}
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (m_serialKey);
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition (m_serialKey.edition());
emit editionChanged (m_serialKey.edition());
}
if (serialKey.isTrial()) {
emit endTrial(false);
}
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
m_AppConfig->saveSettings();
}
return ret;
}
Edition
LicenseManager::activeEdition() const
{
return m_serialKey.edition();
}
QString
LicenseManager::activeEditionName() const
{
return getEditionName(activeEdition(), m_serialKey.isTrial());
}
SerialKey
LicenseManager::serialKey() const
{
return m_serialKey;
}
void LicenseManager::refresh() const
{
emit serialKeyChanged (m_serialKey);
emit editionChanged (m_serialKey.edition());
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
}
void LicenseManager::skipActivation()
{
notifyActivation ("skip:unknown");
}
QString
LicenseManager::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 LicenseManager::notifyActivation(QString identity)
{
ActivationNotifier* notifier = new ActivationNotifier();
notifier->setIdentity(identity);
QThread* thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
notifier->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
}

View File

@ -24,12 +24,12 @@
class AppConfig;
class SubscriptionManager: public QObject
class LicenseManager: public QObject
{
Q_OBJECT
public:
SubscriptionManager(AppConfig* appConfig);
LicenseManager(AppConfig* appConfig);
std::pair<bool, QString> setSerialKey(QString serialKey);
void refresh() const;
Edition activeEdition() const;

View File

@ -30,7 +30,7 @@
#include "ZeroconfService.h"
#include "DataDownloader.h"
#include "CommandProcess.h"
#include "SubscriptionManager.h"
#include "LicenseManager.h"
#include "EditionType.h"
#include "QUtility.h"
#include "ProcessorArch.h"
@ -77,10 +77,10 @@ static const char* synergyIconFiles[] =
};
MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
SubscriptionManager& subscriptionManager) :
LicenseManager& licenseManager) :
m_Settings(settings),
m_AppConfig(&appConfig),
m_SubscriptionManager(&subscriptionManager),
m_LicenseManager(&licenseManager),
m_pSynergy(NULL),
m_SynergyState(synergyDisconnected),
m_ServerConfig(&m_Settings, 5, 3, m_AppConfig->screenName(), this),
@ -142,19 +142,19 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
connect (this, SIGNAL(windowShown()),
this, SLOT(on_windowShown()), Qt::QueuedConnection);
connect (m_SubscriptionManager, SIGNAL(editionChanged(Edition)),
connect (m_LicenseManager, SIGNAL(editionChanged(Edition)),
this, SLOT(setEdition(Edition)), Qt::QueuedConnection);
connect (m_SubscriptionManager, SIGNAL(beginTrial(bool)),
connect (m_LicenseManager, SIGNAL(beginTrial(bool)),
this, SLOT(beginTrial(bool)), Qt::QueuedConnection);
connect (m_SubscriptionManager, SIGNAL(endTrial(bool)),
connect (m_LicenseManager, SIGNAL(endTrial(bool)),
this, SLOT(endTrial(bool)), Qt::QueuedConnection);
connect (m_AppConfig, SIGNAL(sslToggled(bool)),
this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
m_SubscriptionManager->refresh();
m_LicenseManager->refresh();
}
MainWindow::~MainWindow()
@ -447,7 +447,7 @@ void MainWindow::checkConnected(const QString& line)
void MainWindow::checkLicense(const QString &line)
{
if (line.contains("trial has expired")) {
m_SubscriptionManager->refresh();
m_LicenseManager->refresh();
}
}
@ -1049,7 +1049,7 @@ void MainWindow::serverDetected(const QString name)
void MainWindow::setEdition(Edition edition)
{
setWindowTitle(m_SubscriptionManager->getEditionName (edition));
setWindowTitle(m_LicenseManager->getEditionName (edition));
if (m_AppConfig->getCryptoEnabled()) {
m_pSslCertificate = new SslCertificate(this);
m_pSslCertificate->generateCertificate();
@ -1069,11 +1069,11 @@ void MainWindow::beginTrial(bool isExpiring)
" color:#0000ff;\">Buy now!</span></a>"
"</p></body></html>";
expiringNotice = expiringNotice.arg
(m_SubscriptionManager->serialKey().daysLeft(::time(0)));
(m_LicenseManager->serialKey().daysLeft(::time(0)));
this->m_trialLabel->setText(expiringNotice);
this->m_trialWidget->show();
}
setWindowTitle (m_SubscriptionManager->activeEditionName());
setWindowTitle (m_LicenseManager->activeEditionName());
}
void MainWindow::endTrial(bool isExpired)
@ -1081,7 +1081,7 @@ void MainWindow::endTrial(bool isExpired)
if (!isExpired) {
this->m_trialWidget->hide();
}
setWindowTitle (m_SubscriptionManager->activeEditionName());
setWindowTitle (m_LicenseManager->activeEditionName());
}
void MainWindow::updateLocalFingerprint()
@ -1097,10 +1097,10 @@ void MainWindow::updateLocalFingerprint()
}
}
SubscriptionManager&
MainWindow::subscriptionManager() const
LicenseManager&
MainWindow::licenseManager() const
{
return *m_SubscriptionManager;
return *m_LicenseManager;
}
void MainWindow::on_m_pGroupClient_toggled(bool on)
@ -1204,7 +1204,7 @@ void MainWindow::on_m_pButtonConfigureServer_clicked()
void MainWindow::on_m_pActivate_triggered()
{
ActivationDialog activationDialog(this, appConfig(), subscriptionManager());
ActivationDialog activationDialog(this, appConfig(), licenseManager());
activationDialog.exec();
}
@ -1423,7 +1423,7 @@ void MainWindow::bonjourInstallFinished()
void MainWindow::on_windowShown()
{
if (!m_AppConfig->activationHasRun() && (m_AppConfig->edition() == kUnregistered)) {
ActivationDialog activationDialog (this, appConfig(), subscriptionManager());
ActivationDialog activationDialog (this, appConfig(), licenseManager());
activationDialog.exec();
}
}

View File

@ -58,7 +58,7 @@ class ZeroconfService;
class DataDownloader;
class CommandProcess;
class SslCertificate;
class SubscriptionManager;
class LicenseManager;
class MainWindow : public QMainWindow, public Ui::MainWindowBase
{
@ -96,7 +96,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
public:
MainWindow(QSettings& settings, AppConfig& appConfig,
SubscriptionManager& subscriptionManager);
LicenseManager& licenseManager);
~MainWindow();
public:
@ -118,7 +118,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
void updateZeroconfService();
void serverDetected(const QString name);
void updateLocalFingerprint();
SubscriptionManager& subscriptionManager() const;
LicenseManager& licenseManager() const;
public slots:
void setEdition(Edition edition);
@ -195,7 +195,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
private:
QSettings& m_Settings;
AppConfig* m_AppConfig;
SubscriptionManager* m_SubscriptionManager;
LicenseManager* m_LicenseManager;
QProcess* m_pSynergy;
int m_SynergyState;
ServerConfig m_ServerConfig;

View File

@ -19,7 +19,7 @@
#include "MainWindow.h"
#include "WebClient.h"
#include "ActivationNotifier.h"
#include "SubscriptionManager.h"
#include "LicenseManager.h"
#include "EditionType.h"
#include "QSynergyApplication.h"
#include "QUtility.h"

View File

@ -1,144 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015 Synergy Seamless 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/>.
*/
#include "SubscriptionManager.h"
#include "EditionType.h"
#include "AppConfig.h"
#include <ctime>
#include <stdexcept>
#include <utility>
#include <QThread>
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
/* Remove garbage serial keys from the registry */
m_AppConfig->setSerialKey("");
m_AppConfig->setEdition(kUnregistered);
m_AppConfig->saveSettings();
}
}
std::pair<bool, QString>
SubscriptionManager::setSerialKey(QString serialKeyString)
{
std::pair<bool, QString> ret (true, "");
SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isExpired(::time(0))) {
ret.first = false;
ret.second = "Serial key expired";
return ret;
}
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (m_serialKey);
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition (m_serialKey.edition());
emit editionChanged (m_serialKey.edition());
}
if (serialKey.isTrial()) {
emit endTrial(false);
}
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
m_AppConfig->saveSettings();
}
return ret;
}
Edition
SubscriptionManager::activeEdition() const
{
return m_serialKey.edition();
}
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());
if (m_serialKey.isTrial()) {
emit beginTrial(m_serialKey.isExpiring(::time(0)));
}
}
void SubscriptionManager::skipActivation()
{
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)
{
ActivationNotifier* notifier = new ActivationNotifier();
notifier->setIdentity(identity);
QThread* thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
notifier->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
}

View File

@ -20,7 +20,7 @@
#define TRAY_RETRY_WAIT 2000
#include "QSynergyApplication.h"
#include "SubscriptionManager.h"
#include "LicenseManager.h"
#include "MainWindow.h"
#include "AppConfig.h"
#include "SetupWizard.h"
@ -85,11 +85,11 @@ int main(int argc, char* argv[])
QSettings settings;
AppConfig appConfig (&settings);
qRegisterMetaType<Edition>("Edition");
SubscriptionManager subscriptionManager (&appConfig);
LicenseManager licenseManager (&appConfig);
app.switchTranslator(appConfig.language());
MainWindow mainWindow(settings, appConfig, subscriptionManager);
MainWindow mainWindow(settings, appConfig, licenseManager);
SetupWizard setupWizard(mainWindow, true);
if (appConfig.wizardShouldRun())