#5657 Create a global SubscriptionManager instance
This commit is contained in:
parent
743e96f277
commit
540882056f
|
@ -7,7 +7,8 @@ DEFINES += VERSION_REVISION=\\\"$$QMAKE_VERSION_REVISION\\\"
|
||||||
DEPENDPATH += . \
|
DEPENDPATH += . \
|
||||||
res
|
res
|
||||||
INCLUDEPATH += . \
|
INCLUDEPATH += . \
|
||||||
src
|
src \
|
||||||
|
../lib/shared/
|
||||||
FORMS += res/MainWindowBase.ui \
|
FORMS += res/MainWindowBase.ui \
|
||||||
res/AboutDialogBase.ui \
|
res/AboutDialogBase.ui \
|
||||||
res/ServerConfigDialogBase.ui \
|
res/ServerConfigDialogBase.ui \
|
||||||
|
@ -102,7 +103,6 @@ HEADERS += src/MainWindow.h \
|
||||||
src/DataDownloader.h \
|
src/DataDownloader.h \
|
||||||
src/AddClientDialog.h \
|
src/AddClientDialog.h \
|
||||||
src/CommandProcess.h \
|
src/CommandProcess.h \
|
||||||
src/EditionType.h \
|
|
||||||
src/ProcessorArch.h \
|
src/ProcessorArch.h \
|
||||||
src/CoreInterface.h \
|
src/CoreInterface.h \
|
||||||
src/Fingerprint.h \
|
src/Fingerprint.h \
|
||||||
|
@ -114,6 +114,7 @@ HEADERS += src/MainWindow.h \
|
||||||
src/ActivationDialog.h \
|
src/ActivationDialog.h \
|
||||||
src/CancelActivationDialog.h \
|
src/CancelActivationDialog.h \
|
||||||
src/FailedLoginDialog.h \
|
src/FailedLoginDialog.h \
|
||||||
|
../lib/shared/EditionType.h \
|
||||||
../lib/shared/SerialKey.h
|
../lib/shared/SerialKey.h
|
||||||
RESOURCES += res/Synergy.qrc
|
RESOURCES += res/Synergy.qrc
|
||||||
RC_FILE = res/win/Synergy.rc
|
RC_FILE = res/win/Synergy.rc
|
||||||
|
|
|
@ -14,10 +14,12 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig) :
|
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
|
||||||
|
SubscriptionManager& subscriptionManager) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ActivationDialog),
|
ui(new Ui::ActivationDialog),
|
||||||
m_appConfig(&appConfig)
|
m_appConfig(&appConfig),
|
||||||
|
m_subscriptionManager (&subscriptionManager)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->m_pTextEditSerialKey->setFocus();
|
ui->m_pTextEditSerialKey->setFocus();
|
||||||
|
@ -67,17 +69,8 @@ void ActivationDialog::accept()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
|
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
|
||||||
|
SubscriptionManager subscriptionManager (m_appConfig);
|
||||||
if (!m_appConfig->setSerialKey(serialKey, error)) {
|
subscriptionManager.setSerialKey (serialKey);
|
||||||
message.critical(this, "Invalid Serial Key", tr("%1").arg(error));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SubscriptionManager subscriptionManager(this, *m_appConfig, edition);
|
|
||||||
if (!subscriptionManager.activateSerial(serialKey)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
notifyActivation("serial:" + m_appConfig->serialKey());
|
notifyActivation("serial:" + m_appConfig->serialKey());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define ACTIVATIONDIALOG_H
|
#define ACTIVATIONDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <SubscriptionManager.h>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ActivationDialog;
|
class ActivationDialog;
|
||||||
|
@ -14,7 +15,8 @@ class ActivationDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ActivationDialog(QWidget *parent, AppConfig& appConfig);
|
ActivationDialog(QWidget *parent, AppConfig& appConfig,
|
||||||
|
SubscriptionManager& subscriptionManager);
|
||||||
~ActivationDialog();
|
~ActivationDialog();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -27,6 +29,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
Ui::ActivationDialog *ui;
|
Ui::ActivationDialog *ui;
|
||||||
AppConfig* m_appConfig;
|
AppConfig* m_appConfig;
|
||||||
|
SubscriptionManager* m_subscriptionManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ACTIVATIONDIALOG_H
|
#endif // ACTIVATIONDIALOG_H
|
||||||
|
|
|
@ -244,13 +244,10 @@ void AppConfig::setEdition(int e) {
|
||||||
|
|
||||||
int AppConfig::edition() const { return m_Edition; }
|
int AppConfig::edition() const { return m_Edition; }
|
||||||
|
|
||||||
bool AppConfig::setSerialKey(QString serial, QString& errorOut) {
|
QString AppConfig::setSerialKey(QString serial) {
|
||||||
if (serial.isEmpty()) {
|
using std::swap;
|
||||||
errorOut = "Your serial key cannot be blank.";
|
swap (serial, m_Serialkey);
|
||||||
return false;
|
return serial;
|
||||||
}
|
|
||||||
m_Serialkey = serial;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppConfig::clearSerialKey()
|
void AppConfig::clearSerialKey()
|
||||||
|
|
|
@ -79,7 +79,7 @@ class AppConfig: public QObject
|
||||||
void setAutoConfigPrompted(bool prompted);
|
void setAutoConfigPrompted(bool prompted);
|
||||||
void setEdition(int e);
|
void setEdition(int e);
|
||||||
int edition() const;
|
int edition() const;
|
||||||
bool setSerialKey(QString serial, QString& error);
|
QString setSerialKey(QString serial);
|
||||||
void clearSerialKey();
|
void clearSerialKey();
|
||||||
QString serialKey();
|
QString serialKey();
|
||||||
int lastExpiringWarningTime() const;
|
int lastExpiringWarningTime() const;
|
||||||
|
|
|
@ -76,12 +76,14 @@ static const char* synergyIconFiles[] =
|
||||||
":/res/icons/16x16/synergy-transfering.png"
|
":/res/icons/16x16/synergy-transfering.png"
|
||||||
};
|
};
|
||||||
|
|
||||||
MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
|
MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
|
||||||
|
SubscriptionManager& subscriptionManager) :
|
||||||
m_Settings(settings),
|
m_Settings(settings),
|
||||||
m_AppConfig(appConfig),
|
m_AppConfig(&appConfig),
|
||||||
|
m_SubscriptionManager(&subscriptionManager),
|
||||||
m_pSynergy(NULL),
|
m_pSynergy(NULL),
|
||||||
m_SynergyState(synergyDisconnected),
|
m_SynergyState(synergyDisconnected),
|
||||||
m_ServerConfig(&m_Settings, 5, 3, m_AppConfig.screenName(), this),
|
m_ServerConfig(&m_Settings, 5, 3, m_AppConfig->screenName(), this),
|
||||||
m_pTempConfigFile(NULL),
|
m_pTempConfigFile(NULL),
|
||||||
m_pTrayIcon(NULL),
|
m_pTrayIcon(NULL),
|
||||||
m_pTrayIconMenu(NULL),
|
m_pTrayIconMenu(NULL),
|
||||||
|
@ -135,12 +137,12 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
|
||||||
|
|
||||||
m_pComboServerList->hide();
|
m_pComboServerList->hide();
|
||||||
|
|
||||||
setEdition(m_AppConfig.edition());
|
setEdition(m_AppConfig->edition());
|
||||||
|
|
||||||
m_pLabelPadlock->hide();
|
m_pLabelPadlock->hide();
|
||||||
connect (this, SIGNAL(windowShown()), this, SLOT(on_windowShown()), Qt::QueuedConnection);
|
connect (this, SIGNAL(windowShown()), this, SLOT(on_windowShown()), Qt::QueuedConnection);
|
||||||
connect (&m_AppConfig, SIGNAL(editionSet(int)), this, SLOT(setEdition(int)), Qt::QueuedConnection);
|
connect (m_AppConfig, SIGNAL(editionSet(int)), this, SLOT(setEdition(int)), Qt::QueuedConnection);
|
||||||
connect (&m_AppConfig, SIGNAL(sslToggled(bool)), this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
|
connect (m_AppConfig, SIGNAL(sslToggled(bool)), this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -498,7 +500,7 @@ void MainWindow::restartSynergy()
|
||||||
|
|
||||||
void MainWindow::proofreadInfo()
|
void MainWindow::proofreadInfo()
|
||||||
{
|
{
|
||||||
setEdition(m_AppConfig.edition()); // Why is this here?
|
setEdition(m_AppConfig->edition()); // Why is this here?
|
||||||
|
|
||||||
int oldState = m_SynergyState;
|
int oldState = m_SynergyState;
|
||||||
m_SynergyState = synergyDisconnected;
|
m_SynergyState = synergyDisconnected;
|
||||||
|
@ -566,7 +568,7 @@ void MainWindow::startSynergy()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (m_AppConfig.getCryptoEnabled()) {
|
if (m_AppConfig->getCryptoEnabled()) {
|
||||||
args << "--enable-crypto";
|
args << "--enable-crypto";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,18 +736,6 @@ QString MainWindow::appPath(const QString& name)
|
||||||
|
|
||||||
bool MainWindow::serverArgs(QStringList& args, QString& app)
|
bool MainWindow::serverArgs(QStringList& args, QString& app)
|
||||||
{
|
{
|
||||||
int edition;
|
|
||||||
SubscriptionManager subscriptionManager(this, appConfig(), edition);
|
|
||||||
if (subscriptionManager.fileExists())
|
|
||||||
{
|
|
||||||
if (!subscriptionManager.checkSubscription()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setEdition(edition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
app = appPath(appConfig().synergysName());
|
app = appPath(appConfig().synergysName());
|
||||||
|
|
||||||
if (!QFile::exists(app))
|
if (!QFile::exists(app))
|
||||||
|
@ -894,7 +884,7 @@ void MainWindow::setSynergyState(qSynergyState state)
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case synergyConnected: {
|
case synergyConnected: {
|
||||||
if (m_AppConfig.getCryptoEnabled()) {
|
if (m_AppConfig->getCryptoEnabled()) {
|
||||||
m_pLabelPadlock->show();
|
m_pLabelPadlock->show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1009,13 +999,13 @@ void MainWindow::updateZeroconfService()
|
||||||
QMutexLocker locker(&m_UpdateZeroconfMutex);
|
QMutexLocker locker(&m_UpdateZeroconfMutex);
|
||||||
|
|
||||||
if (isBonjourRunning()) {
|
if (isBonjourRunning()) {
|
||||||
if (!m_AppConfig.wizardShouldRun()) {
|
if (!m_AppConfig->wizardShouldRun()) {
|
||||||
if (m_pZeroconfService) {
|
if (m_pZeroconfService) {
|
||||||
delete m_pZeroconfService;
|
delete m_pZeroconfService;
|
||||||
m_pZeroconfService = NULL;
|
m_pZeroconfService = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_AppConfig.autoConfig() || synergyType() == synergyServer) {
|
if (m_AppConfig->autoConfig() || synergyType() == synergyServer) {
|
||||||
m_pZeroconfService = new ZeroconfService(this);
|
m_pZeroconfService = new ZeroconfService(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1027,7 @@ void MainWindow::serverDetected(const QString name)
|
||||||
void MainWindow::setEdition(int edition)
|
void MainWindow::setEdition(int edition)
|
||||||
{
|
{
|
||||||
setWindowTitle(getEditionName(edition));
|
setWindowTitle(getEditionName(edition));
|
||||||
if (m_AppConfig.getCryptoEnabled()) {
|
if (m_AppConfig->getCryptoEnabled()) {
|
||||||
m_pSslCertificate = new SslCertificate(this);
|
m_pSslCertificate = new SslCertificate(this);
|
||||||
m_pSslCertificate->generateCertificate();
|
m_pSslCertificate->generateCertificate();
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1037,7 @@ void MainWindow::setEdition(int edition)
|
||||||
|
|
||||||
void MainWindow::updateLocalFingerprint()
|
void MainWindow::updateLocalFingerprint()
|
||||||
{
|
{
|
||||||
if (m_AppConfig.getCryptoEnabled() && Fingerprint::local().fileExists()) {
|
if (m_AppConfig->getCryptoEnabled() && Fingerprint::local().fileExists()) {
|
||||||
m_pLabelFingerprint->setVisible(true);
|
m_pLabelFingerprint->setVisible(true);
|
||||||
m_pLabelLocalFingerprint->setVisible(true);
|
m_pLabelLocalFingerprint->setVisible(true);
|
||||||
m_pLabelLocalFingerprint->setText(Fingerprint::local().readFirst());
|
m_pLabelLocalFingerprint->setText(Fingerprint::local().readFirst());
|
||||||
|
@ -1058,6 +1048,12 @@ void MainWindow::updateLocalFingerprint()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SubscriptionManager&
|
||||||
|
MainWindow::subscriptionManager() const
|
||||||
|
{
|
||||||
|
return *m_SubscriptionManager;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pGroupClient_toggled(bool on)
|
void MainWindow::on_m_pGroupClient_toggled(bool on)
|
||||||
{
|
{
|
||||||
m_pGroupServer->setChecked(!on);
|
m_pGroupServer->setChecked(!on);
|
||||||
|
@ -1159,7 +1155,7 @@ void MainWindow::on_m_pButtonConfigureServer_clicked()
|
||||||
|
|
||||||
void MainWindow::on_m_pActivate_triggered()
|
void MainWindow::on_m_pActivate_triggered()
|
||||||
{
|
{
|
||||||
ActivationDialog activationDialog (this, this->appConfig());
|
ActivationDialog activationDialog(this, appConfig(), subscriptionManager());
|
||||||
activationDialog.exec();
|
activationDialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1320,16 +1316,16 @@ void MainWindow::promptAutoConfig()
|
||||||
QMessageBox::Yes | QMessageBox::No);
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
if (r == QMessageBox::Yes) {
|
if (r == QMessageBox::Yes) {
|
||||||
m_AppConfig.setAutoConfig(true);
|
m_AppConfig->setAutoConfig(true);
|
||||||
downloadBonjour();
|
downloadBonjour();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_AppConfig.setAutoConfig(false);
|
m_AppConfig->setAutoConfig(false);
|
||||||
m_pCheckBoxAutoConfig->setChecked(false);
|
m_pCheckBoxAutoConfig->setChecked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_AppConfig.setAutoConfigPrompted(true);
|
m_AppConfig->setAutoConfigPrompted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pComboServerList_currentIndexChanged(QString )
|
void MainWindow::on_m_pComboServerList_currentIndexChanged(QString )
|
||||||
|
@ -1377,8 +1373,8 @@ void MainWindow::bonjourInstallFinished()
|
||||||
|
|
||||||
void MainWindow::on_windowShown()
|
void MainWindow::on_windowShown()
|
||||||
{
|
{
|
||||||
if (!m_AppConfig.activationHasRun() && (m_AppConfig.edition() == Unregistered)) {
|
if (!m_AppConfig->activationHasRun() && (m_AppConfig->edition() == Unregistered)) {
|
||||||
ActivationDialog activationDialog (this, m_AppConfig);
|
ActivationDialog activationDialog (this, appConfig(), subscriptionManager());
|
||||||
activationDialog.exec();
|
activationDialog.exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ class ZeroconfService;
|
||||||
class DataDownloader;
|
class DataDownloader;
|
||||||
class CommandProcess;
|
class CommandProcess;
|
||||||
class SslCertificate;
|
class SslCertificate;
|
||||||
|
class SubscriptionManager;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
{
|
{
|
||||||
|
@ -94,7 +95,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QSettings& settings, AppConfig& appConfig);
|
MainWindow(QSettings& settings, AppConfig& appConfig,
|
||||||
|
SubscriptionManager& subscriptionManager);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -116,6 +118,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
void updateZeroconfService();
|
void updateZeroconfService();
|
||||||
void serverDetected(const QString name);
|
void serverDetected(const QString name);
|
||||||
void updateLocalFingerprint();
|
void updateLocalFingerprint();
|
||||||
|
SubscriptionManager& subscriptionManager() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setEdition(int edition);
|
void setEdition(int edition);
|
||||||
|
@ -145,7 +148,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSettings& settings() { return m_Settings; }
|
QSettings& settings() { return m_Settings; }
|
||||||
AppConfig& appConfig() { return m_AppConfig; }
|
AppConfig& appConfig() { return *m_AppConfig; }
|
||||||
QProcess* synergyProcess() { return m_pSynergy; }
|
QProcess* synergyProcess() { return m_pSynergy; }
|
||||||
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
|
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
@ -188,7 +191,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings& m_Settings;
|
QSettings& m_Settings;
|
||||||
AppConfig& m_AppConfig;
|
AppConfig* m_AppConfig;
|
||||||
|
SubscriptionManager* m_SubscriptionManager;
|
||||||
QProcess* m_pSynergy;
|
QProcess* m_pSynergy;
|
||||||
int m_SynergyState;
|
int m_SynergyState;
|
||||||
ServerConfig m_ServerConfig;
|
ServerConfig m_ServerConfig;
|
||||||
|
|
|
@ -51,9 +51,6 @@ getEditionName (int edition) {
|
||||||
else if (edition == Pro) {
|
else if (edition == Pro) {
|
||||||
return "Synergy Pro";
|
return "Synergy Pro";
|
||||||
}
|
}
|
||||||
else if (edition == Trial) {
|
|
||||||
return "Synergy Trial";
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
return "Synergy (UNREGISTERED)";
|
return "Synergy (UNREGISTERED)";
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,152 +16,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SubscriptionManager.h"
|
#include "SubscriptionManager.h"
|
||||||
|
|
||||||
|
|
||||||
#include "CoreInterface.h"
|
|
||||||
#include "EditionType.h"
|
#include "EditionType.h"
|
||||||
#include "AppConfig.h"
|
#include "AppConfig.h"
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include <QMessageBox>
|
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
|
||||||
#include <QDir>
|
m_AppConfig(appConfig) {
|
||||||
#include <QFile>
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QDate>
|
|
||||||
|
|
||||||
static const char purchaseURL[] = "https://symless.com/account/";
|
|
||||||
|
|
||||||
SubscriptionManager::SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition) :
|
|
||||||
m_pParent(parent),
|
|
||||||
m_AppConfig(appConfig),
|
|
||||||
m_Edition(edition)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SubscriptionManager::activateSerial(const QString& serial)
|
void
|
||||||
|
SubscriptionManager::setSerialKey(QString serialKeyString)
|
||||||
{
|
{
|
||||||
m_Edition = Unregistered;
|
SerialKey serialKey (serialKeyString.toStdString());
|
||||||
persistDirectory();
|
if (serialKey.isValid (::time(0)) && (serialKey != m_serialKey)) {
|
||||||
CoreInterface coreInterface;
|
m_AppConfig->setSerialKey (serialKeyString);
|
||||||
QString output;
|
emit serialKeyChanged (serialKey);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
output = coreInterface.activateSerial(serial);
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
m_ErrorMessage = e.what();
|
|
||||||
checkError(m_ErrorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkOutput(output);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SubscriptionManager::checkSubscription()
|
|
||||||
{
|
|
||||||
m_Edition = Unregistered;
|
|
||||||
persistDirectory();
|
|
||||||
CoreInterface coreInterface;
|
|
||||||
QString output;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
output = coreInterface.checkSubscription();
|
|
||||||
}
|
|
||||||
catch (std::exception& e)
|
|
||||||
{
|
|
||||||
m_ErrorMessage = e.what();
|
|
||||||
checkError(m_ErrorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkOutput(output);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SubscriptionManager::fileExists()
|
|
||||||
{
|
|
||||||
CoreInterface coreInterface;
|
|
||||||
QString serialKeyFilePath = coreInterface.getSerialKeyFilePath();
|
|
||||||
|
|
||||||
return QFile::exists(serialKeyFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubscriptionManager::checkError(QString& error)
|
|
||||||
{
|
|
||||||
if (error.contains("trial has expired")) {
|
|
||||||
QMessageBox::warning(m_pParent, tr("Subscription warning"),
|
|
||||||
tr("Your trial has expired. Click <a href='%1'>here</a> to purchase").arg(purchaseURL));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QMessageBox::warning(m_pParent, tr("Subscription error"),
|
|
||||||
tr("An error occurred while trying to activate Synergy using your serial key. "
|
|
||||||
"Please contact the helpdesk, and provide the "
|
|
||||||
"following details.\n\n%1").arg(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubscriptionManager::checkOutput(QString& output)
|
|
||||||
{
|
|
||||||
getEditionType(output);
|
|
||||||
checkExpiring(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubscriptionManager::getEditionType(QString& output)
|
|
||||||
{
|
|
||||||
if (output.contains("pro subscription valid")) {
|
|
||||||
m_Edition = Pro;
|
|
||||||
}
|
|
||||||
else if (output.contains("basic subscription valid")) {
|
|
||||||
m_Edition = Basic;
|
|
||||||
}
|
|
||||||
else if (output.contains("trial subscription valid")) {
|
|
||||||
m_Edition = Trial;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubscriptionManager::checkExpiring(QString& output)
|
|
||||||
{
|
|
||||||
if (output.contains("trial will end in") && shouldWarnExpiring()) {
|
|
||||||
QRegExp dayLeftRegex(".*trial will end in ([0-9]+) day.*");
|
|
||||||
if (dayLeftRegex.exactMatch(output)) {
|
|
||||||
QString dayLeft = dayLeftRegex.cap(1);
|
|
||||||
|
|
||||||
QMessageBox::warning(m_pParent, tr("Subscription warning"),
|
|
||||||
tr("Your trial will end in %1 %2. Click <a href='%3'>here</a> to purchase")
|
|
||||||
.arg(dayLeft)
|
|
||||||
.arg(dayLeft == "1" ? "day" : "days")
|
|
||||||
.arg(purchaseURL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SubscriptionManager::shouldWarnExpiring()
|
|
||||||
{
|
|
||||||
// warn users about expiring subscription once a day
|
|
||||||
int lastExpiringWarningTime = m_AppConfig.lastExpiringWarningTime();
|
|
||||||
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
||||||
int currentTime = currentDateTime.toTime_t();
|
|
||||||
const int secondPerDay = 60 * 60 * 24;
|
|
||||||
bool result = false;
|
|
||||||
if ((currentTime - lastExpiringWarningTime) > secondPerDay) {
|
|
||||||
result = true;
|
|
||||||
m_AppConfig.setLastExpiringWarningTime(currentTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubscriptionManager::persistDirectory()
|
|
||||||
{
|
|
||||||
CoreInterface coreInterface;
|
|
||||||
QString profileDir = coreInterface.getProfileDir();
|
|
||||||
|
|
||||||
QDir dir(profileDir);
|
|
||||||
if (!dir.exists()) {
|
|
||||||
dir.mkpath(".");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,31 +17,23 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QObject>
|
||||||
|
#include <SerialKey.h>
|
||||||
|
|
||||||
class AppConfig;
|
class AppConfig;
|
||||||
|
|
||||||
class SubscriptionManager : public QWidget
|
class SubscriptionManager: public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition);
|
SubscriptionManager (AppConfig* appConfig);
|
||||||
|
void setSerialKey (QString serialKey);
|
||||||
bool activateSerial(const QString& serial);
|
|
||||||
bool checkSubscription();
|
|
||||||
bool fileExists();
|
|
||||||
QString getLastError(){ return m_ErrorMessage; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkError(QString& error);
|
AppConfig* m_AppConfig;
|
||||||
void checkOutput(QString& output);
|
SerialKey m_serialKey;
|
||||||
void getEditionType(QString& output);
|
|
||||||
void checkExpiring(QString& output);
|
|
||||||
bool shouldWarnExpiring();
|
|
||||||
void persistDirectory();
|
|
||||||
|
|
||||||
private:
|
signals:
|
||||||
QString m_ErrorMessage;
|
void serialKeyChanged (SerialKey);
|
||||||
QWidget* m_pParent;
|
|
||||||
AppConfig& m_AppConfig;
|
|
||||||
int& m_Edition;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define TRAY_RETRY_WAIT 2000
|
#define TRAY_RETRY_WAIT 2000
|
||||||
|
|
||||||
#include "QSynergyApplication.h"
|
#include "QSynergyApplication.h"
|
||||||
|
#include "SubscriptionManager.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "AppConfig.h"
|
#include "AppConfig.h"
|
||||||
#include "SetupWizard.h"
|
#include "SetupWizard.h"
|
||||||
|
@ -82,11 +83,12 @@ int main(int argc, char* argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
AppConfig appConfig(&settings);
|
AppConfig appConfig (&settings);
|
||||||
|
SubscriptionManager subscriptionManager (&appConfig);
|
||||||
|
|
||||||
app.switchTranslator(appConfig.language());
|
app.switchTranslator(appConfig.language());
|
||||||
|
|
||||||
MainWindow mainWindow(settings, appConfig);
|
MainWindow mainWindow(settings, appConfig, subscriptionManager);
|
||||||
SetupWizard setupWizard(mainWindow, true);
|
SetupWizard setupWizard(mainWindow, true);
|
||||||
|
|
||||||
if (appConfig.wizardShouldRun())
|
if (appConfig.wizardShouldRun())
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
|
|
||||||
/* Do not reorder these! */
|
/* Do not reorder these! */
|
||||||
|
|
||||||
enum EditionType {
|
enum Edition {
|
||||||
Basic,
|
Basic,
|
||||||
Pro,
|
Pro,
|
||||||
Trial,
|
Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN,
|
||||||
Unregistered
|
Unregistered
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,11 +24,18 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
SerialKey::SerialKey():
|
||||||
|
m_warnTime(1),
|
||||||
|
m_expireTime(1),
|
||||||
|
m_trial(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
SerialKey::SerialKey(std::string serial) :
|
SerialKey::SerialKey(std::string serial) :
|
||||||
m_userLimit(1),
|
m_userLimit(1),
|
||||||
m_warnTime(0),
|
m_warnTime(0),
|
||||||
m_expireTime(0),
|
m_expireTime(0),
|
||||||
m_edition(kBasic),
|
m_edition(Edition::Basic),
|
||||||
m_trial(true),
|
m_trial(true),
|
||||||
m_valid(false)
|
m_valid(false)
|
||||||
{
|
{
|
||||||
|
@ -39,7 +46,7 @@ SerialKey::SerialKey(std::string serial) :
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isValid(unsigned long long currentTime) const
|
SerialKey::isValid(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
@ -58,7 +65,7 @@ SerialKey::isValid(unsigned long long currentTime) const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isExpiring(unsigned long long currentTime) const
|
SerialKey::isExpiring(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
@ -72,7 +79,7 @@ SerialKey::isExpiring(unsigned long long currentTime) const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isExpired(unsigned long long currentTime) const
|
SerialKey::isExpired(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
@ -91,14 +98,14 @@ SerialKey::isTrial() const
|
||||||
return m_trial;
|
return m_trial;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
Edition
|
||||||
SerialKey::edition() const
|
SerialKey::edition() const
|
||||||
{
|
{
|
||||||
return m_edition;
|
return m_edition;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long
|
time_t
|
||||||
SerialKey::dayLeft(unsigned long long currentTime) const
|
SerialKey::daysLeft(time_t currentTime) const
|
||||||
{
|
{
|
||||||
unsigned long long timeLeft = 0;
|
unsigned long long timeLeft = 0;
|
||||||
if (m_expireTime > currentTime) {
|
if (m_expireTime > currentTime) {
|
||||||
|
@ -195,9 +202,9 @@ SerialKey::parse(std::string plainSerial)
|
||||||
Edition
|
Edition
|
||||||
SerialKey::getEdition(std::string editionStr)
|
SerialKey::getEdition(std::string editionStr)
|
||||||
{
|
{
|
||||||
Edition e = kBasic;
|
Edition e = Edition::Basic;
|
||||||
if (editionStr == "pro") {
|
if (editionStr == "pro") {
|
||||||
e = kPro;
|
e = Edition::Pro;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
|
|
|
@ -18,31 +18,29 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <ctime>
|
||||||
|
#include "EditionType.h"
|
||||||
|
|
||||||
#ifdef TEST_ENV
|
#ifdef TEST_ENV
|
||||||
#include "gtest/gtest_prod.h"
|
#include "gtest/gtest_prod.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum Edition{
|
|
||||||
kBasic,
|
|
||||||
kPro
|
|
||||||
};
|
|
||||||
|
|
||||||
class SerialKey {
|
class SerialKey {
|
||||||
public:
|
public:
|
||||||
|
SerialKey();
|
||||||
SerialKey(std::string serial);
|
SerialKey(std::string serial);
|
||||||
|
|
||||||
bool isValid(unsigned long long currentTime) const;
|
bool isValid(time_t currentTime) const;
|
||||||
bool isExpiring(unsigned long long currentTime) const;
|
bool isExpiring(time_t currentTime) const;
|
||||||
bool isExpired(unsigned long long currentTime) const;
|
bool isExpired(time_t currentTime) const;
|
||||||
bool isTrial() const;
|
bool isTrial() const;
|
||||||
int edition() const;
|
time_t daysLeft(time_t currentTime) const;
|
||||||
unsigned long long dayLeft(unsigned long long currentTime) const;
|
Edition edition() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string decode(const std::string& serial) const;
|
std::string decode(const std::string& serial) const;
|
||||||
void parse(std::string plainSerial);
|
void parse(std::string plainSerial);
|
||||||
Edition getEdition(std::string editionStr);
|
Edition getEdition(std::string editionStr);
|
||||||
|
|
||||||
#ifdef TEST_ENV
|
#ifdef TEST_ENV
|
||||||
private:
|
private:
|
||||||
|
@ -59,10 +57,21 @@ private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
std::string m_email;
|
std::string m_email;
|
||||||
std::string m_company;
|
std::string m_company;
|
||||||
int m_userLimit;
|
unsigned m_userLimit;
|
||||||
unsigned long long m_warnTime;
|
unsigned long long m_warnTime;
|
||||||
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;
|
bool m_valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
operator== (SerialKey const& lhs, SerialKey const& rhs) {
|
||||||
|
return (lhs.edition() == rhs.edition());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
operator!= (SerialKey const& lhs, SerialKey const& rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue