Allow software to be time limited with serial key #4716

This commit is contained in:
Jerry (Xinyu Hou) 2015-10-23 15:37:16 -07:00
parent 75adb5aa8d
commit 19835b6aaa
8 changed files with 97 additions and 33 deletions

View File

@ -109,7 +109,8 @@ HEADERS += src/MainWindow.h \
src/Plugin.h \ src/Plugin.h \
src/WebClient.h \ src/WebClient.h \
../lib/common/PluginVersion.h \ ../lib/common/PluginVersion.h \
src/SubscriptionManager.h src/SubscriptionManager.h \
src/SubscriptionState.h
RESOURCES += res/Synergy.qrc RESOURCES += res/Synergy.qrc
RC_FILE = res/win/Synergy.rc RC_FILE = res/win/Synergy.rc
macx { macx {

View File

@ -51,6 +51,12 @@ QString CoreInterface::getArch()
return run(args); return run(args);
} }
QString CoreInterface::getSubscriptionFilename()
{
QStringList args("--get-subscription-filename");
return run(args);
}
QString CoreInterface::activateSerial(const QString& serial) QString CoreInterface::activateSerial(const QString& serial)
{ {
QStringList args("--subscription-serial"); QStringList args("--subscription-serial");

View File

@ -28,6 +28,7 @@ public:
QString getProfileDir(); QString getProfileDir();
QString getInstalledDir(); QString getInstalledDir();
QString getArch(); QString getArch();
QString getSubscriptionFilename();
QString activateSerial(const QString& serial); QString activateSerial(const QString& serial);
QString checkSubscription(); QString checkSubscription();
QString run(const QStringList& args, const QString& input = ""); QString run(const QStringList& args, const QString& input = "");

View File

@ -31,6 +31,8 @@
#include "ZeroconfService.h" #include "ZeroconfService.h"
#include "DataDownloader.h" #include "DataDownloader.h"
#include "CommandProcess.h" #include "CommandProcess.h"
#include "SubscriptionManager.h"
#include "SubscriptionState.h"
#include "EditionType.h" #include "EditionType.h"
#include "QUtility.h" #include "QUtility.h"
#include "ProcessorArch.h" #include "ProcessorArch.h"
@ -552,13 +554,10 @@ void MainWindow::startSynergy()
if ((synergyType() == synergyClient && !clientArgs(args, app)) if ((synergyType() == synergyClient && !clientArgs(args, app))
|| (synergyType() == synergyServer && !serverArgs(args, app))) || (synergyType() == synergyServer && !serverArgs(args, app)))
{
if (desktopMode)
{ {
stopSynergy(); stopSynergy();
return; return;
} }
}
if (desktopMode) if (desktopMode)
{ {
@ -699,6 +698,22 @@ QString MainWindow::appPath(const QString& name)
bool MainWindow::serverArgs(QStringList& args, QString& app) 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()); app = appPath(appConfig().synergysName());
if (!QFile::exists(app)) if (!QFile::exists(app))

View File

@ -20,6 +20,7 @@
#include "WebClient.h" #include "WebClient.h"
#include "SubscriptionManager.h" #include "SubscriptionManager.h"
#include "EditionType.h" #include "EditionType.h"
#include "SubscriptionState.h"
#include "QSynergyApplication.h" #include "QSynergyApplication.h"
#include "QUtility.h" #include "QUtility.h"
@ -127,19 +128,19 @@ bool SetupWizard::validateCurrentPage()
else { else {
// create subscription file in profile directory // create subscription file in profile directory
SubscriptionManager subscriptionManager; SubscriptionManager subscriptionManager;
bool r = subscriptionManager.activateSerial(m_pLineEditSerialKey->text()); bool r = subscriptionManager.activateSerial(m_pLineEditSerialKey->text(), m_Edition);
if (!r) { 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; return r;
} }
// check if the serial is valid
r = subscriptionManager.checkSubscription(m_Edition);
if (r) {
m_pPluginPage->setEdition(m_Edition); m_pPluginPage->setEdition(m_Edition);
}
return r; return true;
} }
} }
else { else {

View File

@ -19,31 +19,37 @@
#include "CoreInterface.h" #include "CoreInterface.h"
#include "EditionType.h" #include "EditionType.h"
#include "SubscriptionState.h"
#include <QMessageBox> #include <QMessageBox>
#include <QFile>
SubscriptionManager::SubscriptionManager() SubscriptionManager::SubscriptionManager()
{ {
} }
bool SubscriptionManager::activateSerial(const QString& serial) bool SubscriptionManager::activateSerial(const QString& serial, int& edition)
{ {
edition = Unknown;
CoreInterface coreInterface; CoreInterface coreInterface;
QString output;
try try
{ {
coreInterface.activateSerial(serial); output = coreInterface.activateSerial(serial);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
showErrorDialog(e.what()); m_ErrorMessage = e.what();
return false; return false;
} }
edition = getEditionType(output);
return true; return true;
} }
bool SubscriptionManager::checkSubscription(int& edition) int SubscriptionManager::checkSubscription(int& edition)
{ {
edition = Unknown; edition = Unknown;
CoreInterface coreInterface; CoreInterface coreInterface;
@ -54,28 +60,30 @@ bool SubscriptionManager::checkSubscription(int& edition)
} }
catch (std::exception& e) catch (std::exception& e)
{ {
showErrorDialog(e.what()); m_ErrorMessage = e.what();
return false;
if (m_ErrorMessage.contains("subscription has expired")) {
return kExpired;
}
return kInvalid;
} }
if (output.contains("subscription will expire soon")) { if (output.contains("subscription will expire soon")) {
QMessageBox::warning( return kExpiredSoon;
this, tr("Activate Subscription"),
tr("Your subscription will be expired soon."));
} }
edition = getEditionType(output); edition = getEditionType(output);
return true; return kValid;
} }
void SubscriptionManager::showErrorDialog(const QString& errorMsg) bool SubscriptionManager::checkSubscriptionExist()
{ {
QMessageBox::critical( CoreInterface coreInterface;
this, "Activate Subscription", QString subscriptionFilename = coreInterface.getSubscriptionFilename();
tr("An error occurred while trying to activate using a serial key. "
"Please contact the helpdesk, and provide the " return QFile::exists(subscriptionFilename);
"following details.\n\n%1").arg(errorMsg));
} }
int SubscriptionManager::getEditionType(QString& string) int SubscriptionManager::getEditionType(QString& string)

View File

@ -24,10 +24,14 @@ class SubscriptionManager : public QWidget
public: public:
SubscriptionManager(); SubscriptionManager();
bool activateSerial(const QString& serial); bool activateSerial(const QString& serial, int& edition);
bool checkSubscription(int& edition); int checkSubscription(int& edition);
bool checkSubscriptionExist();
QString getLastError(){ return m_ErrorMessage; }
private: private:
void showErrorDialog(const QString& errorMsg);
int getEditionType(QString& string); int getEditionType(QString& string);
private:
QString m_ErrorMessage;
}; };

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SUBSCRIPTIONSTATE_H
#define SUBSCRIPTIONSTATE_H
enum qSubscriptionState {
kValid,
kInvalid,
kExpiredSoon,
kExpired
};
#endif // SUBSCRIPTIONSTATE_H