From 19835b6aaa75f3241f92fc347e4dd7d656f4deb2 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 23 Oct 2015 15:37:16 -0700 Subject: [PATCH] Allow software to be time limited with serial key #4716 --- src/gui/gui.pro | 3 ++- src/gui/src/CoreInterface.cpp | 6 +++++ src/gui/src/CoreInterface.h | 1 + src/gui/src/MainWindow.cpp | 25 ++++++++++++++---- src/gui/src/SetupWizard.cpp | 17 ++++++------ src/gui/src/SubscriptionManager.cpp | 40 +++++++++++++++++------------ src/gui/src/SubscriptionManager.h | 10 +++++--- src/gui/src/SubscriptionState.h | 28 ++++++++++++++++++++ 8 files changed, 97 insertions(+), 33 deletions(-) create mode 100644 src/gui/src/SubscriptionState.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 6f5232af..5ada72ff 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -109,7 +109,8 @@ HEADERS += src/MainWindow.h \ src/Plugin.h \ src/WebClient.h \ ../lib/common/PluginVersion.h \ - src/SubscriptionManager.h + src/SubscriptionManager.h \ + src/SubscriptionState.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 70f6e2aa..9bc8d132 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -51,6 +51,12 @@ QString CoreInterface::getArch() return run(args); } +QString CoreInterface::getSubscriptionFilename() +{ + QStringList args("--get-subscription-filename"); + return run(args); +} + QString CoreInterface::activateSerial(const QString& serial) { QStringList args("--subscription-serial"); diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index 39206859..dc2f9fb6 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -28,6 +28,7 @@ public: QString getProfileDir(); QString getInstalledDir(); QString getArch(); + QString getSubscriptionFilename(); QString activateSerial(const QString& serial); QString checkSubscription(); QString run(const QStringList& args, const QString& input = ""); diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index daf535a5..99cd9336 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -31,6 +31,8 @@ #include "ZeroconfService.h" #include "DataDownloader.h" #include "CommandProcess.h" +#include "SubscriptionManager.h" +#include "SubscriptionState.h" #include "EditionType.h" #include "QUtility.h" #include "ProcessorArch.h" @@ -553,11 +555,8 @@ void MainWindow::startSynergy() if ((synergyType() == synergyClient && !clientArgs(args, app)) || (synergyType() == synergyServer && !serverArgs(args, app))) { - if (desktopMode) - { - stopSynergy(); - return; - } + stopSynergy(); + return; } if (desktopMode) @@ -699,6 +698,22 @@ QString MainWindow::appPath(const QString& name) bool MainWindow::serverArgs(QStringList& args, QString& app) { + SubscriptionManager subscriptionManager; + if (subscriptionManager.checkSubscriptionExist()) + { + int edition; + int state = subscriptionManager.checkSubscription(edition); + + if (state == kInvalid) { + return false; + } + else if (state == kExpired) { + QMessageBox::warning(this, tr("Subscription is expired"), + tr("Your subscription is expired. Please purchase.")); + return false; + } + } + app = appPath(appConfig().synergysName()); if (!QFile::exists(app)) diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index fd3d7172..cc8fd9ca 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -20,6 +20,7 @@ #include "WebClient.h" #include "SubscriptionManager.h" #include "EditionType.h" +#include "SubscriptionState.h" #include "QSynergyApplication.h" #include "QUtility.h" @@ -127,19 +128,19 @@ bool SetupWizard::validateCurrentPage() else { // create subscription file in profile directory SubscriptionManager subscriptionManager; - bool r = subscriptionManager.activateSerial(m_pLineEditSerialKey->text()); + bool r = subscriptionManager.activateSerial(m_pLineEditSerialKey->text(), m_Edition); if (!r) { + message.setText(tr("An error occurred while trying to activate using a serial key. " + "Please contact the helpdesk, and provide the " + "following details.\n\n%1").arg(subscriptionManager.getLastError())); + message.exec(); + return r; } - // check if the serial is valid - r = subscriptionManager.checkSubscription(m_Edition); + m_pPluginPage->setEdition(m_Edition); - if (r) { - m_pPluginPage->setEdition(m_Edition); - } - - return r; + return true; } } else { diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 2f6cfa1a..a0c10916 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -19,31 +19,37 @@ #include "CoreInterface.h" #include "EditionType.h" +#include "SubscriptionState.h" #include +#include SubscriptionManager::SubscriptionManager() { } -bool SubscriptionManager::activateSerial(const QString& serial) +bool SubscriptionManager::activateSerial(const QString& serial, int& edition) { + edition = Unknown; CoreInterface coreInterface; + QString output; try { - coreInterface.activateSerial(serial); + output = coreInterface.activateSerial(serial); } catch (std::exception& e) { - showErrorDialog(e.what()); + m_ErrorMessage = e.what(); return false; } + edition = getEditionType(output); + return true; } -bool SubscriptionManager::checkSubscription(int& edition) +int SubscriptionManager::checkSubscription(int& edition) { edition = Unknown; CoreInterface coreInterface; @@ -54,28 +60,30 @@ bool SubscriptionManager::checkSubscription(int& edition) } catch (std::exception& e) { - showErrorDialog(e.what()); - return false; + m_ErrorMessage = e.what(); + + if (m_ErrorMessage.contains("subscription has expired")) { + return kExpired; + } + + return kInvalid; } if (output.contains("subscription will expire soon")) { - QMessageBox::warning( - this, tr("Activate Subscription"), - tr("Your subscription will be expired soon.")); + return kExpiredSoon; } edition = getEditionType(output); - return true; + return kValid; } -void SubscriptionManager::showErrorDialog(const QString& errorMsg) +bool SubscriptionManager::checkSubscriptionExist() { - QMessageBox::critical( - this, "Activate Subscription", - tr("An error occurred while trying to activate using a serial key. " - "Please contact the helpdesk, and provide the " - "following details.\n\n%1").arg(errorMsg)); + CoreInterface coreInterface; + QString subscriptionFilename = coreInterface.getSubscriptionFilename(); + + return QFile::exists(subscriptionFilename); } int SubscriptionManager::getEditionType(QString& string) diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index d7eec67f..1af14ad6 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -24,10 +24,14 @@ class SubscriptionManager : public QWidget public: SubscriptionManager(); - bool activateSerial(const QString& serial); - bool checkSubscription(int& edition); + bool activateSerial(const QString& serial, int& edition); + int checkSubscription(int& edition); + bool checkSubscriptionExist(); + QString getLastError(){ return m_ErrorMessage; } private: - void showErrorDialog(const QString& errorMsg); int getEditionType(QString& string); + +private: + QString m_ErrorMessage; }; diff --git a/src/gui/src/SubscriptionState.h b/src/gui/src/SubscriptionState.h new file mode 100644 index 00000000..e52a6df5 --- /dev/null +++ b/src/gui/src/SubscriptionState.h @@ -0,0 +1,28 @@ +/* + * 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 . + */ + +#ifndef SUBSCRIPTIONSTATE_H +#define SUBSCRIPTIONSTATE_H + +enum qSubscriptionState { + kValid, + kInvalid, + kExpiredSoon, + kExpired +}; + +#endif // SUBSCRIPTIONSTATE_H