mirror of
https://github.com/debauchee/barrier.git
synced 2026-06-30 17:06:29 +08:00
Merge branch 'jerry-sandbox2'
This commit is contained in:
@@ -62,7 +62,8 @@ SOURCES += src/main.cpp \
|
||||
src/Plugin.cpp \
|
||||
src/WebClient.cpp \
|
||||
../lib/common/PluginVersion.cpp \
|
||||
src/SubscriptionManager.cpp
|
||||
src/SubscriptionManager.cpp \
|
||||
src/ActivationNotifier.cpp
|
||||
HEADERS += src/MainWindow.h \
|
||||
src/AboutDialog.h \
|
||||
src/ServerConfig.h \
|
||||
@@ -110,7 +111,7 @@ HEADERS += src/MainWindow.h \
|
||||
src/WebClient.h \
|
||||
../lib/common/PluginVersion.h \
|
||||
src/SubscriptionManager.h \
|
||||
src/SubscriptionState.h
|
||||
src/ActivationNotifier.h
|
||||
RESOURCES += res/Synergy.qrc
|
||||
RC_FILE = res/win/Synergy.rc
|
||||
macx {
|
||||
|
||||
@@ -15,14 +15,22 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SUBSCRIPTIONSTATE_H
|
||||
#define SUBSCRIPTIONSTATE_H
|
||||
#include "ActivationNotifier.h"
|
||||
|
||||
enum qSubscriptionState {
|
||||
kValid,
|
||||
kInvalid,
|
||||
kExpiredSoon,
|
||||
kExpired
|
||||
};
|
||||
#include "CoreInterface.h"
|
||||
|
||||
#endif // SUBSCRIPTIONSTATE_H
|
||||
ActivationNotifier::ActivationNotifier(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ActivationNotifier::setIdentity(QString identity)
|
||||
{
|
||||
m_Identity = identity;
|
||||
}
|
||||
|
||||
void ActivationNotifier::notify()
|
||||
{
|
||||
CoreInterface coreInterface;
|
||||
coreInterface.notifyActivation(m_Identity);
|
||||
}
|
||||
41
src/gui/src/ActivationNotifier.h
Normal file
41
src/gui/src/ActivationNotifier.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 ACTIVATIONNOTIFIER_H
|
||||
#define ACTIVATIONNOTIFIER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class ActivationNotifier : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ActivationNotifier(QObject *parent = 0);
|
||||
|
||||
void setIdentity(QString identity);
|
||||
|
||||
public slots:
|
||||
void notify();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
QString m_Identity;
|
||||
};
|
||||
|
||||
#endif // ACTIVATIONNOTIFIER_H
|
||||
@@ -58,7 +58,8 @@ AppConfig::AppConfig(QSettings* settings) :
|
||||
m_ElevateMode(false),
|
||||
m_AutoConfigPrompted(false),
|
||||
m_CryptoEnabled(false),
|
||||
m_AutoHide(false)
|
||||
m_AutoHide(false),
|
||||
m_LastExpiringWarningTime(0)
|
||||
{
|
||||
Q_ASSERT(m_pSettings);
|
||||
|
||||
@@ -129,10 +130,10 @@ void AppConfig::loadSettings()
|
||||
m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool();
|
||||
m_Edition = settings().value("edition", Unknown).toInt();
|
||||
m_ActivateEmail = settings().value("activateEmail", "").toString();
|
||||
m_UserToken = settings().value("userToken", "").toString();
|
||||
m_CryptoEnabled = settings().value("cryptoEnabled", false).toBool();
|
||||
m_AutoHide = settings().value("autoHide", false).toBool();
|
||||
m_Serialkey = settings().value("serialKey", "").toString();
|
||||
m_LastExpiringWarningTime = settings().value("lastExpiringWarningTime", 0).toInt();
|
||||
}
|
||||
|
||||
void AppConfig::saveSettings()
|
||||
@@ -151,10 +152,10 @@ void AppConfig::saveSettings()
|
||||
settings().setValue("autoConfigPrompted", m_AutoConfigPrompted);
|
||||
settings().setValue("edition", m_Edition);
|
||||
settings().setValue("activateEmail", m_ActivateEmail);
|
||||
settings().setValue("userToken", m_UserToken);
|
||||
settings().setValue("cryptoEnabled", m_CryptoEnabled);
|
||||
settings().setValue("autoHide", m_AutoHide);
|
||||
settings().setValue("serialKey", m_Serialkey);
|
||||
settings().setValue("lastExpiringWarningTime", m_LastExpiringWarningTime);
|
||||
}
|
||||
|
||||
void AppConfig::setAutoConfig(bool autoConfig)
|
||||
|
||||
@@ -76,10 +76,10 @@ class AppConfig
|
||||
int edition() { return m_Edition; }
|
||||
void setActivateEmail(QString e) { m_ActivateEmail = e; }
|
||||
QString activateEmail() { return m_ActivateEmail; }
|
||||
void setUserToken(QString t) { m_UserToken = t; }
|
||||
QString userToken() { return m_UserToken; }
|
||||
void setSerialKey(QString serial) { m_Serialkey = serial; }
|
||||
QString serialKey() { return m_Serialkey; }
|
||||
int lastExpiringWarningTime() const { return m_LastExpiringWarningTime; }
|
||||
void setLastExpiringWarningTime(int t) { m_LastExpiringWarningTime = t; }
|
||||
|
||||
QString synergysName() const { return m_SynergysName; }
|
||||
QString synergycName() const { return m_SynergycName; }
|
||||
@@ -95,6 +95,8 @@ class AppConfig
|
||||
void setAutoHide(bool b) { m_AutoHide = b; }
|
||||
bool getAutoHide() { return m_AutoHide; }
|
||||
|
||||
void saveSettings();
|
||||
|
||||
protected:
|
||||
QSettings& settings() { return *m_pSettings; }
|
||||
void setScreenName(const QString& s) { m_ScreenName = s; }
|
||||
@@ -109,7 +111,6 @@ class AppConfig
|
||||
void setElevateMode(bool b) { m_ElevateMode = b; }
|
||||
|
||||
void loadSettings();
|
||||
void saveSettings();
|
||||
|
||||
private:
|
||||
QSettings* m_pSettings;
|
||||
@@ -128,10 +129,10 @@ class AppConfig
|
||||
bool m_AutoConfigPrompted;
|
||||
int m_Edition;
|
||||
QString m_ActivateEmail;
|
||||
QString m_UserToken;
|
||||
bool m_CryptoEnabled;
|
||||
bool m_AutoHide;
|
||||
QString m_Serialkey;
|
||||
int m_LastExpiringWarningTime;
|
||||
|
||||
static const char m_SynergysName[];
|
||||
static const char m_SynergycName[];
|
||||
|
||||
@@ -18,17 +18,46 @@
|
||||
#include "CommandProcess.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <stdexcept>
|
||||
|
||||
CommandProcess::CommandProcess(QString cmd, QStringList arguments) :
|
||||
CommandProcess::CommandProcess(QString cmd, QStringList arguments, QString input) :
|
||||
m_Command(cmd),
|
||||
m_Arguments(arguments)
|
||||
m_Arguments(arguments),
|
||||
m_Input(input)
|
||||
{
|
||||
}
|
||||
|
||||
void CommandProcess::run()
|
||||
QString CommandProcess::run()
|
||||
{
|
||||
QProcess process;
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.start(m_Command, m_Arguments);
|
||||
process.waitForFinished();
|
||||
bool success = process.waitForStarted();
|
||||
|
||||
QString output, error;
|
||||
if (success)
|
||||
{
|
||||
if (!m_Input.isEmpty()) {
|
||||
process.write(m_Input.toStdString().c_str());
|
||||
}
|
||||
|
||||
if (process.waitForFinished()) {
|
||||
output = process.readAllStandardOutput().trimmed();
|
||||
error = process.readAllStandardError().trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
int code = process.exitCode();
|
||||
if (!error.isEmpty() || !success || code != 0)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
QString("Code: %1\nError: %2")
|
||||
.arg(process.exitCode())
|
||||
.arg(error.isEmpty() ? "Unknown" : error)
|
||||
.toStdString());
|
||||
}
|
||||
|
||||
emit finished();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -25,17 +25,18 @@ class CommandProcess : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CommandProcess(QString cmd, QStringList arguments);
|
||||
CommandProcess(QString cmd, QStringList arguments, QString input = "");
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
public slots:
|
||||
void run();
|
||||
QString run();
|
||||
|
||||
private:
|
||||
QString m_Command;
|
||||
QStringList m_Arguments;
|
||||
QString m_Input;
|
||||
};
|
||||
|
||||
#endif // COMMANDTHREAD_H
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
#include "CoreInterface.h"
|
||||
|
||||
#include "CommandProcess.h"
|
||||
#include "QUtility.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#include <stdexcept>
|
||||
@@ -71,39 +74,26 @@ QString CoreInterface::checkSubscription()
|
||||
return run(args);
|
||||
}
|
||||
|
||||
QString CoreInterface::notifyActivation(const QString& identity)
|
||||
{
|
||||
QStringList args("--notify-activation");
|
||||
|
||||
QString input(identity + ":" + hash(getFirstMacAddress()));
|
||||
QString os= getOSInformation();
|
||||
if (!os.isEmpty()) {
|
||||
input.append(":").append(os);
|
||||
}
|
||||
input.append("\n");
|
||||
|
||||
return run(args, input);
|
||||
}
|
||||
|
||||
QString CoreInterface::run(const QStringList& args, const QString& input)
|
||||
{
|
||||
QString program(
|
||||
QCoreApplication::applicationDirPath()
|
||||
+ "/" + kCoreBinary);
|
||||
|
||||
QProcess process;
|
||||
process.setReadChannel(QProcess::StandardOutput);
|
||||
process.start(program, args);
|
||||
bool success = process.waitForStarted();
|
||||
|
||||
QString output, error;
|
||||
if (success)
|
||||
{
|
||||
if (!input.isEmpty()) {
|
||||
process.write(input.toStdString().c_str());
|
||||
}
|
||||
|
||||
if (process.waitForFinished()) {
|
||||
output = process.readAllStandardOutput().trimmed();
|
||||
error = process.readAllStandardError().trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
int code = process.exitCode();
|
||||
if (!error.isEmpty() || !success || code != 0)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
QString("Code: %1\nError: %2")
|
||||
.arg(process.exitCode())
|
||||
.arg(error.isEmpty() ? "Unknown" : error)
|
||||
.toStdString());
|
||||
}
|
||||
|
||||
return output;
|
||||
CommandProcess commandProcess(program, args, input);
|
||||
return commandProcess.run();
|
||||
}
|
||||
|
||||
@@ -31,5 +31,6 @@ public:
|
||||
QString getSubscriptionFilename();
|
||||
QString activateSerial(const QString& serial);
|
||||
QString checkSubscription();
|
||||
QString notifyActivation(const QString& identity);
|
||||
QString run(const QStringList& args, const QString& input = "");
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
enum qEditionType {
|
||||
Basic,
|
||||
Pro,
|
||||
Trial,
|
||||
Unknown
|
||||
};
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "DataDownloader.h"
|
||||
#include "CommandProcess.h"
|
||||
#include "SubscriptionManager.h"
|
||||
#include "SubscriptionState.h"
|
||||
#include "EditionType.h"
|
||||
#include "QUtility.h"
|
||||
#include "ProcessorArch.h"
|
||||
@@ -135,7 +134,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
|
||||
|
||||
m_pComboServerList->hide();
|
||||
|
||||
updateEdition();
|
||||
setEdition(m_AppConfig.edition());
|
||||
|
||||
m_pLabelPadlock->hide();
|
||||
|
||||
@@ -698,22 +697,19 @@ QString MainWindow::appPath(const QString& name)
|
||||
|
||||
bool MainWindow::serverArgs(QStringList& args, QString& app)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
if (subscriptionManager.checkSubscriptionExist())
|
||||
int edition;
|
||||
SubscriptionManager subscriptionManager(this, appConfig(), edition);
|
||||
if (subscriptionManager.fileExists())
|
||||
{
|
||||
int edition;
|
||||
int state = subscriptionManager.checkSubscription(edition);
|
||||
|
||||
if (state == kInvalid) {
|
||||
if (!subscriptionManager.checkSubscription()) {
|
||||
return false;
|
||||
}
|
||||
else if (state == kExpired) {
|
||||
QMessageBox::warning(this, tr("Subscription is expired"),
|
||||
tr("Your subscription is expired. Please purchase."));
|
||||
return false;
|
||||
else {
|
||||
setEdition(edition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
app = appPath(appConfig().synergysName());
|
||||
|
||||
if (!QFile::exists(app))
|
||||
@@ -962,7 +958,7 @@ void MainWindow::changeEvent(QEvent* event)
|
||||
retranslateUi(this);
|
||||
retranslateMenuBar();
|
||||
|
||||
updateEdition();
|
||||
setEdition(m_AppConfig.edition());
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1011,6 +1007,9 @@ void MainWindow::setEdition(int type)
|
||||
else if (type == Pro) {
|
||||
title = "Synergy Pro";
|
||||
}
|
||||
else if (type == Trial) {
|
||||
title = "Synergy Trial";
|
||||
}
|
||||
else {
|
||||
title = "Synergy (UNREGISTERED)";
|
||||
}
|
||||
@@ -1305,20 +1304,6 @@ void MainWindow::promptAutoConfig()
|
||||
m_AppConfig.setAutoConfigPrompted(true);
|
||||
}
|
||||
|
||||
void MainWindow::updateEdition()
|
||||
{
|
||||
QString mac = getFirstMacAddress();
|
||||
QString hashSrc = m_AppConfig.activateEmail() + mac;
|
||||
QString hashResult = hash(hashSrc);
|
||||
|
||||
if (hashResult == m_AppConfig.userToken()) {
|
||||
setEdition(m_AppConfig.edition());
|
||||
}
|
||||
else {
|
||||
setEdition(Unknown);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pComboServerList_currentIndexChanged(QString )
|
||||
{
|
||||
if (m_pComboServerList->count() != 0) {
|
||||
|
||||
@@ -172,7 +172,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||
bool isBonjourRunning();
|
||||
void downloadBonjour();
|
||||
void promptAutoConfig();
|
||||
void updateEdition();
|
||||
QString getProfileRootForArg();
|
||||
void checkConnected(const QString& line);
|
||||
void checkFingerprint(const QString& line);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "PluginManager.h"
|
||||
|
||||
#include "CoreInterface.h"
|
||||
#include "CommandProcess.h"
|
||||
#include "DataDownloader.h"
|
||||
#include "QUtility.h"
|
||||
#include "ProcessorArch.h"
|
||||
|
||||
@@ -64,8 +64,7 @@ void PluginWizardPage::initializePage()
|
||||
{
|
||||
QWizardPage::initializePage();
|
||||
|
||||
if (m_Edition == Unknown ||
|
||||
m_Edition == Basic) {
|
||||
if (m_Edition != Pro) {
|
||||
updateStatus(tr("Setup complete."));
|
||||
showFinished();
|
||||
return;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "QUtility.h"
|
||||
|
||||
#include "ProcessorArch.h"
|
||||
#include "CommandProcess.h"
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include <QProcess>
|
||||
@@ -90,3 +91,23 @@ qProcessorArch getProcessorArch()
|
||||
|
||||
return kProcessorArchUnknown;
|
||||
}
|
||||
|
||||
QString getOSInformation()
|
||||
{
|
||||
QString result;
|
||||
|
||||
#if defined(Q_OS_LINUX)
|
||||
QStringList arguments;
|
||||
arguments.append("/etc/os-release");
|
||||
CommandProcess cp("/bin/cat", arguments);
|
||||
QString output = cp.run();
|
||||
|
||||
QRegExp resultRegex(".*PRETTY_NAME=\"([^\"]+)\".*");
|
||||
if (resultRegex.exactMatch(output)) {
|
||||
QString OSInfo = resultRegex.cap(1);
|
||||
result = OSInfo;
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -28,3 +28,4 @@ void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData);
|
||||
QString hash(const QString& string);
|
||||
QString getFirstMacAddress();
|
||||
qProcessorArch getProcessorArch();
|
||||
QString getOSInformation();
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
#include "SetupWizard.h"
|
||||
#include "MainWindow.h"
|
||||
#include "WebClient.h"
|
||||
#include "ActivationNotifier.h"
|
||||
#include "SubscriptionManager.h"
|
||||
#include "EditionType.h"
|
||||
#include "SubscriptionState.h"
|
||||
#include "QSynergyApplication.h"
|
||||
#include "QUtility.h"
|
||||
|
||||
@@ -103,7 +103,7 @@ bool SetupWizard::validateCurrentPage()
|
||||
QMessageBox::StandardButton reply =
|
||||
QMessageBox::information(
|
||||
this, tr("Setup Synergy"),
|
||||
tr("Would you like to use serial key to activate?"),
|
||||
tr("Would you like to use your serial key instead?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes) {
|
||||
@@ -127,15 +127,9 @@ bool SetupWizard::validateCurrentPage()
|
||||
}
|
||||
else {
|
||||
// create subscription file in profile directory
|
||||
SubscriptionManager subscriptionManager;
|
||||
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;
|
||||
SubscriptionManager subscriptionManager(this, m_MainWindow.appConfig(), m_Edition);
|
||||
if (!subscriptionManager.activateSerial(m_pLineEditSerialKey->text())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pPluginPage->setEdition(m_Edition);
|
||||
@@ -206,21 +200,27 @@ void SetupWizard::accept()
|
||||
|
||||
if (m_pRadioButtonActivate->isChecked()) {
|
||||
appConfig.setActivateEmail(m_pLineEditEmail->text());
|
||||
QString mac = getFirstMacAddress();
|
||||
QString hashSrc = m_pLineEditEmail->text() + mac;
|
||||
QString hashResult = hash(hashSrc);
|
||||
appConfig.setUserToken(hashResult);
|
||||
appConfig.setEdition(m_Edition);
|
||||
|
||||
notifyActivation("login:" + m_pLineEditEmail->text());
|
||||
}
|
||||
|
||||
if (m_pRadioButtonSubscription->isChecked())
|
||||
{
|
||||
appConfig.setSerialKey(m_pLineEditSerialKey->text());
|
||||
|
||||
notifyActivation("serial:" + m_pLineEditSerialKey->text());
|
||||
}
|
||||
|
||||
if (m_pRadioButtonSkip->isChecked())
|
||||
{
|
||||
notifyActivation("skip:unknown");
|
||||
}
|
||||
|
||||
appConfig.setEdition(m_Edition);
|
||||
m_MainWindow.setEdition(m_Edition);
|
||||
m_MainWindow.updateLocalFingerprint();
|
||||
|
||||
appConfig.saveSettings();
|
||||
settings.sync();
|
||||
|
||||
QWizard::accept();
|
||||
@@ -242,9 +242,28 @@ void SetupWizard::reject()
|
||||
m_MainWindow.open();
|
||||
}
|
||||
|
||||
// treat cancel as skip
|
||||
CoreInterface coreInterface;
|
||||
coreInterface.notifyActivation("skip:unknown");
|
||||
|
||||
QWizard::reject();
|
||||
}
|
||||
|
||||
void SetupWizard::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);
|
||||
}
|
||||
|
||||
void SetupWizard::on_m_pComboLanguage_currentIndexChanged(int index)
|
||||
{
|
||||
QString ietfCode = m_pComboLanguage->itemData(index).toString();
|
||||
|
||||
@@ -43,6 +43,7 @@ protected:
|
||||
void changeEvent(QEvent* event);
|
||||
void accept();
|
||||
void reject();
|
||||
void notifyActivation(QString identity);
|
||||
|
||||
private:
|
||||
MainWindow& m_MainWindow;
|
||||
|
||||
@@ -17,20 +17,30 @@
|
||||
|
||||
#include "SubscriptionManager.h"
|
||||
|
||||
|
||||
#include "CoreInterface.h"
|
||||
#include "EditionType.h"
|
||||
#include "SubscriptionState.h"
|
||||
#include "AppConfig.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QDateTime>
|
||||
#include <QDate>
|
||||
|
||||
SubscriptionManager::SubscriptionManager()
|
||||
static const char purchaseURL[] = "https://synergy-project.org/account/";
|
||||
|
||||
SubscriptionManager::SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition) :
|
||||
m_pParent(parent),
|
||||
m_AppConfig(appConfig),
|
||||
m_Edition(edition)
|
||||
{
|
||||
}
|
||||
|
||||
bool SubscriptionManager::activateSerial(const QString& serial, int& edition)
|
||||
bool SubscriptionManager::activateSerial(const QString& serial)
|
||||
{
|
||||
edition = Unknown;
|
||||
m_Edition = Unknown;
|
||||
persistDirectory();
|
||||
CoreInterface coreInterface;
|
||||
QString output;
|
||||
|
||||
@@ -41,17 +51,19 @@ bool SubscriptionManager::activateSerial(const QString& serial, int& edition)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
m_ErrorMessage = e.what();
|
||||
checkError(m_ErrorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
edition = getEditionType(output);
|
||||
checkOutput(output);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int SubscriptionManager::checkSubscription(int& edition)
|
||||
bool SubscriptionManager::checkSubscription()
|
||||
{
|
||||
edition = Unknown;
|
||||
m_Edition = Unknown;
|
||||
persistDirectory();
|
||||
CoreInterface coreInterface;
|
||||
QString output;
|
||||
try
|
||||
@@ -61,24 +73,16 @@ int SubscriptionManager::checkSubscription(int& edition)
|
||||
catch (std::exception& e)
|
||||
{
|
||||
m_ErrorMessage = e.what();
|
||||
|
||||
if (m_ErrorMessage.contains("subscription has expired")) {
|
||||
return kExpired;
|
||||
}
|
||||
|
||||
return kInvalid;
|
||||
checkError(m_ErrorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (output.contains("subscription will expire soon")) {
|
||||
return kExpiredSoon;
|
||||
}
|
||||
checkOutput(output);
|
||||
|
||||
edition = getEditionType(output);
|
||||
|
||||
return kValid;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubscriptionManager::checkSubscriptionExist()
|
||||
bool SubscriptionManager::fileExists()
|
||||
{
|
||||
CoreInterface coreInterface;
|
||||
QString subscriptionFilename = coreInterface.getSubscriptionFilename();
|
||||
@@ -86,11 +90,78 @@ bool SubscriptionManager::checkSubscriptionExist()
|
||||
return QFile::exists(subscriptionFilename);
|
||||
}
|
||||
|
||||
int SubscriptionManager::getEditionType(QString& string)
|
||||
void SubscriptionManager::checkError(QString& error)
|
||||
{
|
||||
if (string.contains("full subscription valid")) {
|
||||
return Pro;
|
||||
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 using a 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 Unknown;
|
||||
return result;
|
||||
}
|
||||
|
||||
void SubscriptionManager::persistDirectory()
|
||||
{
|
||||
CoreInterface coreInterface;
|
||||
QString profileDir = coreInterface.getProfileDir();
|
||||
|
||||
QDir dir(profileDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,19 +19,29 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class AppConfig;
|
||||
|
||||
class SubscriptionManager : public QWidget
|
||||
{
|
||||
public:
|
||||
SubscriptionManager();
|
||||
SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition);
|
||||
|
||||
bool activateSerial(const QString& serial, int& edition);
|
||||
int checkSubscription(int& edition);
|
||||
bool checkSubscriptionExist();
|
||||
bool activateSerial(const QString& serial);
|
||||
bool checkSubscription();
|
||||
bool fileExists();
|
||||
QString getLastError(){ return m_ErrorMessage; }
|
||||
|
||||
private:
|
||||
int getEditionType(QString& string);
|
||||
void checkError(QString& error);
|
||||
void checkOutput(QString& output);
|
||||
void getEditionType(QString& output);
|
||||
void checkExpiring(QString& output);
|
||||
bool shouldWarnExpiring();
|
||||
void persistDirectory();
|
||||
|
||||
private:
|
||||
QString m_ErrorMessage;
|
||||
QWidget* m_pParent;
|
||||
AppConfig& m_AppConfig;
|
||||
int& m_Edition;
|
||||
};
|
||||
|
||||
@@ -95,5 +95,6 @@ QString WebClient::request(
|
||||
QStringList args("--login-auth");
|
||||
// hash password in case it contains interesting chars.
|
||||
QString credentials(email + ":" + hash(password) + "\n");
|
||||
|
||||
return m_CoreInterface.run(args, credentials);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user