diff --git a/src/gui/gui.pro b/src/gui/gui.pro index a901aee1..6f5232af 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -61,8 +61,8 @@ SOURCES += src/main.cpp \ src/SslCertificate.cpp \ src/Plugin.cpp \ src/WebClient.cpp \ - ../lib/common/PluginVersion.cpp - + ../lib/common/PluginVersion.cpp \ + src/SubscriptionManager.cpp HEADERS += src/MainWindow.h \ src/AboutDialog.h \ src/ServerConfig.h \ @@ -108,8 +108,8 @@ HEADERS += src/MainWindow.h \ src/SslCertificate.h \ src/Plugin.h \ src/WebClient.h \ - ../lib/common/PluginVersion.h - + ../lib/common/PluginVersion.h \ + src/SubscriptionManager.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/res/SetupWizardBase.ui b/src/gui/res/SetupWizardBase.ui index 03e00510..8339e54a 100644 --- a/src/gui/res/SetupWizardBase.ui +++ b/src/gui/res/SetupWizardBase.ui @@ -227,7 +227,7 @@ - + Subscription diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 3f1b666b..70f6e2aa 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -51,6 +51,20 @@ QString CoreInterface::getArch() return run(args); } +QString CoreInterface::activateSerial(const QString& serial) +{ + QStringList args("--subscription-serial"); + args << serial; + + return run(args); +} + +QString CoreInterface::checkSubscription() +{ + QStringList args("--check-subscription"); + return run(args); +} + QString CoreInterface::run(const QStringList& args, const QString& input) { QString program( diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index 55d954c1..39206859 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -28,5 +28,7 @@ public: QString getProfileDir(); QString getInstalledDir(); QString getArch(); + QString activateSerial(const QString& serial); + QString checkSubscription(); QString run(const QStringList& args, const QString& input = ""); }; diff --git a/src/gui/src/PluginWizardPage.cpp b/src/gui/src/PluginWizardPage.cpp index f2a28692..ecbc26e4 100644 --- a/src/gui/src/PluginWizardPage.cpp +++ b/src/gui/src/PluginWizardPage.cpp @@ -21,6 +21,7 @@ #include "SslCertificate.h" #include "PluginManager.h" #include "MainWindow.h" +#include "EditionType.h" #include #include @@ -29,6 +30,7 @@ PluginWizardPage::PluginWizardPage(MainWindow& mainWindow, QWidget *parent) : QWizardPage(parent), m_Finished(false), + m_Edition(Unknown), m_pSslCertificate(NULL), m_mainWindow(mainWindow) { @@ -62,8 +64,8 @@ void PluginWizardPage::initializePage() { QWizardPage::initializePage(); - if (m_Email.isEmpty() || - m_Password.isEmpty()) { + if (m_Edition == Unknown || + m_Edition == Basic) { updateStatus(tr("Setup complete.")); showFinished(); return; diff --git a/src/gui/src/PluginWizardPage.h b/src/gui/src/PluginWizardPage.h index 0985c5db..5c889e0b 100644 --- a/src/gui/src/PluginWizardPage.h +++ b/src/gui/src/PluginWizardPage.h @@ -36,8 +36,7 @@ public: ~PluginWizardPage(); void setFinished(bool b) { m_Finished = b; } - void setEmail(QString e) { m_Email = e; } - void setPassword(QString p) { m_Password = p; } + void setEdition(int edition) { m_Edition = edition; } bool isComplete() const; void initializePage(); @@ -58,8 +57,7 @@ private: private: bool m_Finished; - QString m_Email; - QString m_Password; + int m_Edition; PluginManager m_PluginManager; SslCertificate* m_pSslCertificate; QThread* m_pThread; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index 29b3b9ce..010290fd 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -18,6 +18,7 @@ #include "SetupWizard.h" #include "MainWindow.h" #include "WebClient.h" +#include "SubscriptionManager.h" #include "EditionType.h" #include "QSynergyApplication.h" #include "QUtility.h" @@ -85,7 +86,7 @@ bool SetupWizard::validateCurrentPage() } else { WebClient webClient; - m_Edition = webClient .getEdition( + m_Edition = webClient.getEdition( m_pLineEditEmail->text(), m_pLineEditPassword->text(), message, @@ -95,12 +96,36 @@ bool SetupWizard::validateCurrentPage() return false; } else { - m_pPluginPage->setEmail(m_pLineEditEmail->text()); - m_pPluginPage->setPassword(m_pLineEditPassword->text()); + m_pPluginPage->setEdition(m_Edition); return true; } } } + else if (m_pRadioButtonSubscription->isChecked()) { + if (m_pLineEditSerialKey->text().isEmpty()) { + message.setText(tr("Please enter your subscription serial key.")); + message.exec(); + return false; + } + else { + // plugin page no longer requires email and password + // create subscription file in profile directory + SubscriptionManager subscriptionManager; + bool r = subscriptionManager.activateSerial(m_pLineEditSerialKey->text()); + if (!r) { + return r; + } + + // check if the serial is valid + r = subscriptionManager.checkSubscription(m_Edition); + + if (r) { + m_pPluginPage->setEdition(m_Edition); + } + + return r; + } + } else { return true; } @@ -170,6 +195,7 @@ void SetupWizard::accept() appConfig.setUserToken(hashResult); appConfig.setEdition(m_Edition); } + m_MainWindow.setEdition(m_Edition); m_MainWindow.updateLocalFingerprint(); @@ -221,7 +247,7 @@ void SetupWizard::on_m_pRadioButtonActivate_toggled(bool checked) } } -void SetupWizard::on_radioButton_toggled(bool checked) +void SetupWizard::on_m_pRadioButtonSubscription_toggled(bool checked) { if (checked) { m_pLineEditEmail->setEnabled(false); diff --git a/src/gui/src/SetupWizard.h b/src/gui/src/SetupWizard.h index 7bdf57a1..9a4151bf 100644 --- a/src/gui/src/SetupWizard.h +++ b/src/gui/src/SetupWizard.h @@ -47,7 +47,7 @@ private: PluginWizardPage* m_pPluginPage; private slots: - void on_radioButton_toggled(bool checked); + void on_m_pRadioButtonSubscription_toggled(bool checked); void on_m_pRadioButtonActivate_toggled(bool checked); void on_m_pRadioButtonSkip_toggled(bool checked); void on_m_pComboLanguage_currentIndexChanged(int index); diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp new file mode 100644 index 00000000..2f6cfa1a --- /dev/null +++ b/src/gui/src/SubscriptionManager.cpp @@ -0,0 +1,88 @@ +/* + * 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 . + */ + +#include "SubscriptionManager.h" + +#include "CoreInterface.h" +#include "EditionType.h" + +#include + +SubscriptionManager::SubscriptionManager() +{ +} + +bool SubscriptionManager::activateSerial(const QString& serial) +{ + CoreInterface coreInterface; + + try + { + coreInterface.activateSerial(serial); + } + catch (std::exception& e) + { + showErrorDialog(e.what()); + return false; + } + + return true; +} + +bool SubscriptionManager::checkSubscription(int& edition) +{ + edition = Unknown; + CoreInterface coreInterface; + QString output; + try + { + output = coreInterface.checkSubscription(); + } + catch (std::exception& e) + { + showErrorDialog(e.what()); + return false; + } + + if (output.contains("subscription will expire soon")) { + QMessageBox::warning( + this, tr("Activate Subscription"), + tr("Your subscription will be expired soon.")); + } + + edition = getEditionType(output); + + return true; +} + +void SubscriptionManager::showErrorDialog(const QString& errorMsg) +{ + 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)); +} + +int SubscriptionManager::getEditionType(QString& string) +{ + if (string.contains("full subscription valid")) { + return Pro; + } + + return Unknown; +} diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h new file mode 100644 index 00000000..d7eec67f --- /dev/null +++ b/src/gui/src/SubscriptionManager.h @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +#pragma once + +#include + +class SubscriptionManager : public QWidget +{ +public: + SubscriptionManager(); + + bool activateSerial(const QString& serial); + bool checkSubscription(int& edition); + +private: + void showErrorDialog(const QString& errorMsg); + int getEditionType(QString& string); +};