#5657 Rename edition to activeLicense. WSFs
This commit is contained in:
parent
3b98a7b785
commit
4ad7c7fe39
|
@ -15,66 +15,66 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
|
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
|
||||||
SubscriptionManager& subscriptionManager) :
|
SubscriptionManager& subscriptionManager) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ActivationDialog),
|
ui(new Ui::ActivationDialog),
|
||||||
m_appConfig(&appConfig),
|
m_appConfig(&appConfig),
|
||||||
m_subscriptionManager (&subscriptionManager)
|
m_subscriptionManager (&subscriptionManager)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
refreshSerialKey();
|
refreshSerialKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivationDialog::refreshSerialKey()
|
void ActivationDialog::refreshSerialKey()
|
||||||
{
|
{
|
||||||
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
|
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
|
||||||
ui->m_pTextEditSerialKey->setFocus();
|
ui->m_pTextEditSerialKey->setFocus();
|
||||||
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
|
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivationDialog::~ActivationDialog()
|
ActivationDialog::~ActivationDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivationDialog::reject()
|
void ActivationDialog::reject()
|
||||||
{
|
{
|
||||||
if (m_subscriptionManager->edition() == Edition::kUnregistered) {
|
if (m_subscriptionManager->activeLicense() == Edition::kUnregistered) {
|
||||||
CancelActivationDialog cancelActivationDialog(this);
|
CancelActivationDialog cancelActivationDialog(this);
|
||||||
if (QDialog::Accepted == cancelActivationDialog.exec()) {
|
if (QDialog::Accepted == cancelActivationDialog.exec()) {
|
||||||
m_subscriptionManager->skipActivation();
|
m_subscriptionManager->skipActivation();
|
||||||
m_appConfig->activationHasRun(true);
|
m_appConfig->activationHasRun(true);
|
||||||
m_appConfig->saveSettings();
|
m_appConfig->saveSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivationDialog::accept()
|
void ActivationDialog::accept()
|
||||||
{
|
{
|
||||||
QMessageBox message;
|
QMessageBox message;
|
||||||
QString error;
|
QString error;
|
||||||
|
|
||||||
m_appConfig->activationHasRun(true);
|
m_appConfig->activationHasRun(true);
|
||||||
m_appConfig->saveSettings();
|
m_appConfig->saveSettings();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
|
QString serialKey = ui->m_pTextEditSerialKey->toPlainText();
|
||||||
m_subscriptionManager->setSerialKey(serialKey);
|
m_subscriptionManager->setSerialKey(serialKey);
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
message.critical(this, "Unknown Error",
|
message.critical(this, "Unknown Error",
|
||||||
tr("An error occurred while trying to activate Synergy. "
|
tr("An error occurred while trying to activate Synergy. "
|
||||||
"Please contact the helpdesk, and provide the "
|
"Please contact the helpdesk, and provide the "
|
||||||
"following details.\n\n%1").arg(e.what()));
|
"following details.\n\n%1").arg(e.what()));
|
||||||
refreshSerialKey();
|
refreshSerialKey();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_subscriptionManager->edition() != Edition::kUnregistered) {
|
if (m_subscriptionManager->activeLicense() != Edition::kUnregistered) {
|
||||||
message.information(this, "Activated!",
|
message.information(this, "Activated!",
|
||||||
tr("Thanks for activating %1!").arg
|
tr("Thanks for activating %1!").arg
|
||||||
(getEditionName(m_subscriptionManager->edition())));
|
(getEditionName(m_subscriptionManager->activeLicense())));
|
||||||
}
|
}
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -62,174 +62,174 @@ class SubscriptionManager;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class QSynergyApplication;
|
friend class QSynergyApplication;
|
||||||
friend class SetupWizard;
|
friend class SetupWizard;
|
||||||
friend class ActivationDialog;
|
friend class ActivationDialog;
|
||||||
friend class SettingsDialog;
|
friend class SettingsDialog;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum qSynergyState
|
enum qSynergyState
|
||||||
{
|
{
|
||||||
synergyDisconnected,
|
synergyDisconnected,
|
||||||
synergyConnecting,
|
synergyConnecting,
|
||||||
synergyConnected,
|
synergyConnected,
|
||||||
synergyTransfering
|
synergyTransfering
|
||||||
};
|
};
|
||||||
|
|
||||||
enum qSynergyType
|
enum qSynergyType
|
||||||
{
|
{
|
||||||
synergyClient,
|
synergyClient,
|
||||||
synergyServer
|
synergyServer
|
||||||
};
|
};
|
||||||
|
|
||||||
enum qLevel {
|
enum qLevel {
|
||||||
Error,
|
Error,
|
||||||
Info
|
Info
|
||||||
};
|
};
|
||||||
|
|
||||||
enum qRuningState {
|
enum qRuningState {
|
||||||
kStarted,
|
kStarted,
|
||||||
kStopped
|
kStopped
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QSettings& settings, AppConfig& appConfig,
|
MainWindow(QSettings& settings, AppConfig& appConfig,
|
||||||
SubscriptionManager& subscriptionManager);
|
SubscriptionManager& subscriptionManager);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setVisible(bool visible);
|
void setVisible(bool visible);
|
||||||
int synergyType() const { return m_pGroupClient->isChecked() ? synergyClient : synergyServer; }
|
int synergyType() const { return m_pGroupClient->isChecked() ? synergyClient : synergyServer; }
|
||||||
int synergyState() const { return m_SynergyState; }
|
int synergyState() const { return m_SynergyState; }
|
||||||
QString hostname() const { return m_pLineEditHostname->text(); }
|
QString hostname() const { return m_pLineEditHostname->text(); }
|
||||||
QString configFilename();
|
QString configFilename();
|
||||||
QString address();
|
QString address();
|
||||||
QString appPath(const QString& name);
|
QString appPath(const QString& name);
|
||||||
void open();
|
void open();
|
||||||
void clearLog();
|
void clearLog();
|
||||||
VersionChecker& versionChecker() { return m_VersionChecker; }
|
VersionChecker& versionChecker() { return m_VersionChecker; }
|
||||||
QString getScreenName();
|
QString getScreenName();
|
||||||
ServerConfig& serverConfig() { return m_ServerConfig; }
|
ServerConfig& serverConfig() { return m_ServerConfig; }
|
||||||
void showConfigureServer(const QString& message);
|
void showConfigureServer(const QString& message);
|
||||||
void showConfigureServer() { showConfigureServer(""); }
|
void showConfigureServer() { showConfigureServer(""); }
|
||||||
void autoAddScreen(const QString name);
|
void autoAddScreen(const QString name);
|
||||||
void updateZeroconfService();
|
void updateZeroconfService();
|
||||||
void serverDetected(const QString name);
|
void serverDetected(const QString name);
|
||||||
void updateLocalFingerprint();
|
void updateLocalFingerprint();
|
||||||
SubscriptionManager& subscriptionManager() const;
|
SubscriptionManager& subscriptionManager() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setEdition(Edition edition);
|
void setEdition(Edition edition);
|
||||||
void beginTrial();
|
void beginTrial(bool isExpiring);
|
||||||
void endTrial();
|
void endTrial(bool isExpired);
|
||||||
void appendLogRaw(const QString& text);
|
void appendLogRaw(const QString& text);
|
||||||
void appendLogInfo(const QString& text);
|
void appendLogInfo(const QString& text);
|
||||||
void appendLogDebug(const QString& text);
|
void appendLogDebug(const QString& text);
|
||||||
void appendLogError(const QString& text);
|
void appendLogError(const QString& text);
|
||||||
void startSynergy();
|
void startSynergy();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void sslToggled(bool enabled);
|
void sslToggled(bool enabled);
|
||||||
void on_m_pGroupClient_toggled(bool on);
|
void on_m_pGroupClient_toggled(bool on);
|
||||||
void on_m_pGroupServer_toggled(bool on);
|
void on_m_pGroupServer_toggled(bool on);
|
||||||
bool on_m_pButtonBrowseConfigFile_clicked();
|
bool on_m_pButtonBrowseConfigFile_clicked();
|
||||||
void on_m_pButtonConfigureServer_clicked();
|
void on_m_pButtonConfigureServer_clicked();
|
||||||
bool on_m_pActionSave_triggered();
|
bool on_m_pActionSave_triggered();
|
||||||
void on_m_pActionAbout_triggered();
|
void on_m_pActionAbout_triggered();
|
||||||
void on_m_pActionSettings_triggered();
|
void on_m_pActionSettings_triggered();
|
||||||
void on_m_pActivate_triggered();
|
void on_m_pActivate_triggered();
|
||||||
void synergyFinished(int exitCode, QProcess::ExitStatus);
|
void synergyFinished(int exitCode, QProcess::ExitStatus);
|
||||||
void trayActivated(QSystemTrayIcon::ActivationReason reason);
|
void trayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
void stopSynergy();
|
void stopSynergy();
|
||||||
void logOutput();
|
void logOutput();
|
||||||
void logError();
|
void logError();
|
||||||
void updateFound(const QString& version);
|
void updateFound(const QString& version);
|
||||||
void bonjourInstallFinished();
|
void bonjourInstallFinished();
|
||||||
|
|
||||||
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();
|
||||||
void createMenuBar();
|
void createMenuBar();
|
||||||
void createStatusBar();
|
void createStatusBar();
|
||||||
void createTrayIcon();
|
void createTrayIcon();
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void setIcon(qSynergyState state);
|
void setIcon(qSynergyState state);
|
||||||
void setSynergyState(qSynergyState state);
|
void setSynergyState(qSynergyState state);
|
||||||
bool checkForApp(int which, QString& app);
|
bool checkForApp(int which, QString& app);
|
||||||
bool clientArgs(QStringList& args, QString& app);
|
bool clientArgs(QStringList& args, QString& app);
|
||||||
bool serverArgs(QStringList& args, QString& app);
|
bool serverArgs(QStringList& args, QString& app);
|
||||||
void setStatus(const QString& status);
|
void setStatus(const QString& status);
|
||||||
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
|
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
|
||||||
void onModeChanged(bool startDesktop, bool applyService);
|
void onModeChanged(bool startDesktop, bool applyService);
|
||||||
void updateStateFromLogLine(const QString& line);
|
void updateStateFromLogLine(const QString& line);
|
||||||
QString getIPAddresses();
|
QString getIPAddresses();
|
||||||
void stopService();
|
void stopService();
|
||||||
void stopDesktop();
|
void stopDesktop();
|
||||||
void changeEvent(QEvent* event);
|
void changeEvent(QEvent* event);
|
||||||
void retranslateMenuBar();
|
void retranslateMenuBar();
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
bool isServiceRunning(QString name);
|
bool isServiceRunning(QString name);
|
||||||
#else
|
#else
|
||||||
bool isServiceRunning();
|
bool isServiceRunning();
|
||||||
#endif
|
#endif
|
||||||
bool isBonjourRunning();
|
bool isBonjourRunning();
|
||||||
void downloadBonjour();
|
void downloadBonjour();
|
||||||
void promptAutoConfig();
|
void promptAutoConfig();
|
||||||
QString getProfileRootForArg();
|
QString getProfileRootForArg();
|
||||||
void checkConnected(const QString& line);
|
void checkConnected(const QString& line);
|
||||||
void checkFingerprint(const QString& line);
|
void checkFingerprint(const QString& line);
|
||||||
bool autoHide();
|
bool autoHide();
|
||||||
QString getTimeStamp();
|
QString getTimeStamp();
|
||||||
void restartSynergy();
|
void restartSynergy();
|
||||||
void proofreadInfo();
|
void proofreadInfo();
|
||||||
|
|
||||||
void showEvent (QShowEvent*);
|
void showEvent (QShowEvent*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSettings& m_Settings;
|
QSettings& m_Settings;
|
||||||
AppConfig* m_AppConfig;
|
AppConfig* m_AppConfig;
|
||||||
SubscriptionManager* m_SubscriptionManager;
|
SubscriptionManager* m_SubscriptionManager;
|
||||||
QProcess* m_pSynergy;
|
QProcess* m_pSynergy;
|
||||||
int m_SynergyState;
|
int m_SynergyState;
|
||||||
ServerConfig m_ServerConfig;
|
ServerConfig m_ServerConfig;
|
||||||
QTemporaryFile* m_pTempConfigFile;
|
QTemporaryFile* m_pTempConfigFile;
|
||||||
QSystemTrayIcon* m_pTrayIcon;
|
QSystemTrayIcon* m_pTrayIcon;
|
||||||
QMenu* m_pTrayIconMenu;
|
QMenu* m_pTrayIconMenu;
|
||||||
bool m_AlreadyHidden;
|
bool m_AlreadyHidden;
|
||||||
VersionChecker m_VersionChecker;
|
VersionChecker m_VersionChecker;
|
||||||
IpcClient m_IpcClient;
|
IpcClient m_IpcClient;
|
||||||
QMenuBar* m_pMenuBar;
|
QMenuBar* m_pMenuBar;
|
||||||
QMenu* m_pMenuFile;
|
QMenu* m_pMenuFile;
|
||||||
QMenu* m_pMenuEdit;
|
QMenu* m_pMenuEdit;
|
||||||
QMenu* m_pMenuWindow;
|
QMenu* m_pMenuWindow;
|
||||||
QMenu* m_pMenuHelp;
|
QMenu* m_pMenuHelp;
|
||||||
ZeroconfService* m_pZeroconfService;
|
ZeroconfService* m_pZeroconfService;
|
||||||
DataDownloader* m_pDataDownloader;
|
DataDownloader* m_pDataDownloader;
|
||||||
QMessageBox* m_DownloadMessageBox;
|
QMessageBox* m_DownloadMessageBox;
|
||||||
QAbstractButton* m_pCancelButton;
|
QAbstractButton* m_pCancelButton;
|
||||||
QMutex m_UpdateZeroconfMutex;
|
QMutex m_UpdateZeroconfMutex;
|
||||||
bool m_SuppressAutoConfigWarning;
|
bool m_SuppressAutoConfigWarning;
|
||||||
CommandProcess* m_BonjourInstall;
|
CommandProcess* m_BonjourInstall;
|
||||||
bool m_SuppressEmptyServerWarning;
|
bool m_SuppressEmptyServerWarning;
|
||||||
qRuningState m_ExpectedRunningState;
|
qRuningState m_ExpectedRunningState;
|
||||||
QMutex m_StopDesktopMutex;
|
QMutex m_StopDesktopMutex;
|
||||||
SslCertificate* m_pSslCertificate;
|
SslCertificate* m_pSslCertificate;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
|
void on_m_pCheckBoxAutoConfig_toggled(bool checked);
|
||||||
void on_m_pComboServerList_currentIndexChanged(QString );
|
void on_m_pComboServerList_currentIndexChanged(QString );
|
||||||
void on_m_pButtonApply_clicked();
|
void on_m_pButtonApply_clicked();
|
||||||
void installBonjour();
|
void installBonjour();
|
||||||
void on_windowShown();
|
void on_windowShown();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void windowShown();
|
void windowShown();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,75 +22,82 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
|
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
|
||||||
m_AppConfig(appConfig),
|
m_AppConfig(appConfig),
|
||||||
m_serialKey(appConfig->edition()) {
|
m_serialKey(appConfig->edition()) {
|
||||||
try {
|
try {
|
||||||
setSerialKey(m_AppConfig->serialKey());
|
setSerialKey(m_AppConfig->serialKey());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
m_AppConfig->setSerialKey("");
|
m_AppConfig->setSerialKey("");
|
||||||
}
|
m_AppConfig->saveSettings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialKey
|
SerialKey
|
||||||
SubscriptionManager::setSerialKey(QString serialKeyString)
|
SubscriptionManager::setSerialKey(QString serialKeyString)
|
||||||
{
|
{
|
||||||
SerialKey serialKey (serialKeyString.toStdString());
|
SerialKey serialKey (serialKeyString.toStdString());
|
||||||
if (!serialKey.isValid (::time(0))) {
|
if (!serialKey.isValid (::time(0))) {
|
||||||
throw std::runtime_error ("Invalid serial key");
|
throw std::runtime_error ("Invalid serial key");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialKey != m_serialKey) {
|
if (serialKey != m_serialKey) {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
swap (serialKey, m_serialKey);
|
swap (serialKey, m_serialKey);
|
||||||
|
|
||||||
m_AppConfig->setSerialKey (serialKeyString);
|
m_AppConfig->setSerialKey (serialKeyString);
|
||||||
notifyActivation ("serial:" + serialKeyString);
|
notifyActivation ("serial:" + serialKeyString);
|
||||||
emit serialKeyChanged (m_serialKey);
|
emit serialKeyChanged (m_serialKey);
|
||||||
|
|
||||||
if (m_serialKey.edition() != serialKey.edition()) {
|
if (m_serialKey.edition() != serialKey.edition()) {
|
||||||
m_AppConfig->setEdition (m_serialKey.edition());
|
m_AppConfig->setEdition (m_serialKey.edition());
|
||||||
emit editionChanged (m_serialKey.edition());
|
emit editionChanged (m_serialKey.edition());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_serialKey.isTrial() != serialKey.isTrial()) {
|
if (serialKey.isTrial()) {
|
||||||
if (m_serialKey.isTrial()) {
|
emit endTrial(false);
|
||||||
emit beginTrial();
|
}
|
||||||
} else {
|
|
||||||
emit endTrial();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return serialKey;
|
if (m_serialKey.isTrial()) {
|
||||||
|
emit beginTrial(m_serialKey.isExpiring(::time(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_AppConfig->saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
return serialKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition SubscriptionManager::edition() const
|
Edition SubscriptionManager::activeLicense() const
|
||||||
{
|
{
|
||||||
return m_serialKey.edition();
|
return m_serialKey.edition();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SubscriptionManager::isTrial() const
|
void SubscriptionManager::update() const
|
||||||
{
|
{
|
||||||
return m_serialKey.isTrial();
|
emit serialKeyChanged (m_serialKey);
|
||||||
|
emit editionChanged (m_serialKey.edition());
|
||||||
|
if (m_serialKey.isTrial()) {
|
||||||
|
emit beginTrial(m_serialKey.isExpiring(::time(0)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubscriptionManager::skipActivation()
|
void SubscriptionManager::skipActivation()
|
||||||
{
|
{
|
||||||
notifyActivation ("skip:unknown");
|
notifyActivation ("skip:unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubscriptionManager::notifyActivation(QString identity)
|
void SubscriptionManager::notifyActivation(QString identity)
|
||||||
{
|
{
|
||||||
ActivationNotifier* notifier = new ActivationNotifier();
|
ActivationNotifier* notifier = new ActivationNotifier();
|
||||||
notifier->setIdentity(identity);
|
notifier->setIdentity(identity);
|
||||||
|
|
||||||
QThread* thread = new QThread();
|
QThread* thread = new QThread();
|
||||||
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
|
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
|
||||||
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
|
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
|
||||||
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
|
||||||
|
|
||||||
notifier->moveToThread(thread);
|
notifier->moveToThread(thread);
|
||||||
thread->start();
|
thread->start();
|
||||||
|
|
||||||
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,25 +25,25 @@ class AppConfig;
|
||||||
|
|
||||||
class SubscriptionManager: public QObject
|
class SubscriptionManager: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SubscriptionManager(AppConfig* appConfig);
|
SubscriptionManager(AppConfig* appConfig);
|
||||||
SerialKey setSerialKey(QString serialKey);
|
SerialKey setSerialKey(QString serialKey);
|
||||||
Edition edition() const;
|
void update() const;
|
||||||
bool isTrial() const;
|
Edition activeLicense() const;
|
||||||
void skipActivation();
|
void skipActivation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void notifyActivation(QString identity);
|
void notifyActivation(QString identity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AppConfig* m_AppConfig;
|
AppConfig* m_AppConfig;
|
||||||
SerialKey m_serialKey;
|
SerialKey m_serialKey;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void serialKeyChanged (SerialKey);
|
void serialKeyChanged (SerialKey) const;
|
||||||
void editionChanged (Edition);
|
void editionChanged (Edition) const;
|
||||||
void beginTrial ();
|
void beginTrial (bool expiring) const;
|
||||||
void endTrial ();
|
void endTrial (bool expired) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,194 +26,194 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
SerialKey::SerialKey(Edition edition):
|
SerialKey::SerialKey(Edition edition):
|
||||||
m_userLimit(1),
|
m_userLimit(1),
|
||||||
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)
|
m_valid(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(Edition::kBasic),
|
m_edition(Edition::kBasic),
|
||||||
m_trial(true),
|
m_trial(true),
|
||||||
m_valid(false)
|
m_valid(false)
|
||||||
{
|
{
|
||||||
string plainText = decode(serial);
|
string plainText = decode(serial);
|
||||||
if (!plainText.empty()) {
|
if (!plainText.empty()) {
|
||||||
parse(plainText);
|
parse(plainText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isValid(time_t currentTime) const
|
SerialKey::isValid(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (m_valid) {
|
if (m_valid) {
|
||||||
if (m_trial) {
|
if (m_trial) {
|
||||||
if (currentTime < m_expireTime) {
|
if (currentTime < m_expireTime) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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_valid) {
|
||||||
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
|
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isExpired(time_t currentTime) const
|
SerialKey::isExpired(time_t currentTime) const
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (m_valid) {
|
if (m_valid) {
|
||||||
if (m_expireTime <= currentTime) {
|
if (m_expireTime <= currentTime) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SerialKey::isTrial() const
|
SerialKey::isTrial() const
|
||||||
{
|
{
|
||||||
return m_trial;
|
return m_trial;
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition
|
Edition
|
||||||
SerialKey::edition() const
|
SerialKey::edition() const
|
||||||
{
|
{
|
||||||
return m_edition;
|
return m_edition;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
SerialKey::daysLeft(time_t currentTime) const
|
SerialKey::daysLeft(time_t currentTime) const
|
||||||
{
|
{
|
||||||
unsigned long long timeLeft = 0;
|
unsigned long long timeLeft = 0;
|
||||||
unsigned long long const day = 60 * 60 * 24;
|
unsigned long long const day = 60 * 60 * 24;
|
||||||
|
|
||||||
if (currentTime < m_expireTime) {
|
if (currentTime < m_expireTime) {
|
||||||
timeLeft = m_expireTime - currentTime;
|
timeLeft = m_expireTime - currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long dayLeft = 0;
|
unsigned long long dayLeft = 0;
|
||||||
dayLeft = timeLeft % day != 0 ? 1 : 0;
|
dayLeft = timeLeft % day != 0 ? 1 : 0;
|
||||||
|
|
||||||
return timeLeft / day + dayLeft;
|
return timeLeft / day + dayLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
SerialKey::decode(const std::string& serial) const
|
SerialKey::decode(const std::string& serial) const
|
||||||
{
|
{
|
||||||
static const char* const lut = "0123456789ABCDEF";
|
static const char* const lut = "0123456789ABCDEF";
|
||||||
string output;
|
string output;
|
||||||
size_t len = serial.length();
|
size_t len = serial.length();
|
||||||
if (len & 1) {
|
if (len & 1) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.reserve(len / 2);
|
output.reserve(len / 2);
|
||||||
for (size_t i = 0; i < len; i += 2) {
|
for (size_t i = 0; i < len; i += 2) {
|
||||||
|
|
||||||
char a = serial[i];
|
char a = serial[i];
|
||||||
char b = serial[i + 1];
|
char b = serial[i + 1];
|
||||||
|
|
||||||
const char* p = std::lower_bound(lut, lut + 16, a);
|
const char* p = std::lower_bound(lut, lut + 16, a);
|
||||||
const char* q = std::lower_bound(lut, lut + 16, b);
|
const char* q = std::lower_bound(lut, lut + 16, b);
|
||||||
|
|
||||||
if (*q != b || *p != a) {
|
if (*q != b || *p != a) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
output.push_back(static_cast<char>(((p - lut) << 4) | (q - lut)));
|
output.push_back(static_cast<char>(((p - lut) << 4) | (q - lut)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
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);
|
||||||
|
|
||||||
// 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 == "}") {
|
||||||
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
|
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
|
||||||
|
|
||||||
// tokenize serialised subscription.
|
// tokenize serialised subscription.
|
||||||
vector<string> parts;
|
vector<string> parts;
|
||||||
std::string::size_type pos = 0;
|
std::string::size_type pos = 0;
|
||||||
bool look = true;
|
bool look = true;
|
||||||
while (look) {
|
while (look) {
|
||||||
std::string::size_type start = pos;
|
std::string::size_type start = pos;
|
||||||
pos = plainSerial.find(";", pos);
|
pos = plainSerial.find(";", pos);
|
||||||
if (pos == string::npos) {
|
if (pos == string::npos) {
|
||||||
pos = plainSerial.length();
|
pos = plainSerial.length();
|
||||||
look = false;
|
look = false;
|
||||||
}
|
}
|
||||||
parts.push_back(plainSerial.substr(start, pos - start));
|
parts.push_back(plainSerial.substr(start, pos - start));
|
||||||
pos += 1;
|
pos += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((parts.size() == 8)
|
if ((parts.size() == 8)
|
||||||
&& (parts.at(0).find("v1") != string::npos)) {
|
&& (parts.at(0).find("v1") != string::npos)) {
|
||||||
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||||
m_edition = getEdition(parts.at(1));
|
m_edition = parseEdition(parts.at(1));
|
||||||
m_name = parts.at(2);
|
m_name = parts.at(2);
|
||||||
m_trial = false;
|
m_trial = false;
|
||||||
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
||||||
m_email = parts.at(4);
|
m_email = parts.at(4);
|
||||||
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;
|
m_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)) {
|
||||||
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
|
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||||
m_trial = parts.at(1) == "trial" ? true : false;
|
m_trial = parts.at(1) == "trial" ? true : false;
|
||||||
m_edition = getEdition(parts.at(2));
|
m_edition = parseEdition(parts.at(2));
|
||||||
m_name = parts.at(3);
|
m_name = parts.at(3);
|
||||||
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
|
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
|
||||||
m_email = parts.at(5);
|
m_email = parts.at(5);
|
||||||
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;
|
m_valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Edition
|
Edition
|
||||||
SerialKey::getEdition(std::string editionStr)
|
SerialKey::parseEdition(std::string editionStr)
|
||||||
{
|
{
|
||||||
Edition e = Edition::kBasic;
|
Edition e = Edition::kBasic;
|
||||||
if (editionStr == "pro") {
|
if (editionStr == "pro") {
|
||||||
e = Edition::kPro;
|
e = Edition::kPro;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,61 +26,61 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class SerialKey {
|
class SerialKey {
|
||||||
friend bool operator== (SerialKey const&, SerialKey const&);
|
friend bool operator== (SerialKey const&, SerialKey const&);
|
||||||
public:
|
public:
|
||||||
explicit SerialKey(Edition edition = Edition::kUnregistered);
|
explicit SerialKey(Edition edition = Edition::kUnregistered);
|
||||||
explicit SerialKey(std::string serial);
|
explicit SerialKey(std::string serial);
|
||||||
|
|
||||||
bool isValid(time_t currentTime) const;
|
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;
|
||||||
time_t daysLeft(time_t currentTime) const;
|
time_t daysLeft(time_t currentTime) const;
|
||||||
Edition edition() 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 parseEdition(std::string editionStr);
|
||||||
|
|
||||||
#ifdef TEST_ENV
|
#ifdef TEST_ENV
|
||||||
private:
|
private:
|
||||||
FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString);
|
FRIEND_TEST(SerialKeyTests, decode_empty_returnEmptyString);
|
||||||
FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString);
|
FRIEND_TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString);
|
||||||
FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText);
|
FRIEND_TEST(SerialKeyTests, decode_validSerial_returnPlainText);
|
||||||
FRIEND_TEST(SerialKeyTests, parse_noParty_invalid);
|
FRIEND_TEST(SerialKeyTests, parse_noParty_invalid);
|
||||||
FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid);
|
FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid);
|
||||||
FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid);
|
FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid);
|
||||||
FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid);
|
FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
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;
|
||||||
unsigned 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
|
inline bool
|
||||||
operator== (SerialKey const& lhs, SerialKey const& rhs) {
|
operator== (SerialKey const& lhs, SerialKey const& rhs) {
|
||||||
return (lhs.m_name == rhs.m_name) &&
|
return (lhs.m_name == rhs.m_name) &&
|
||||||
(lhs.m_email == rhs.m_email) &&
|
(lhs.m_email == rhs.m_email) &&
|
||||||
(lhs.m_company == rhs.m_company) &&
|
(lhs.m_company == rhs.m_company) &&
|
||||||
(lhs.m_userLimit == rhs.m_userLimit) &&
|
(lhs.m_userLimit == rhs.m_userLimit) &&
|
||||||
(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);
|
(lhs.m_valid == rhs.m_valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
operator!= (SerialKey const& lhs, SerialKey const& rhs) {
|
operator!= (SerialKey const& lhs, SerialKey const& rhs) {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue