#5657 Make SubscriptionManager backward compatible

This commit is contained in:
Andrew Nelless 2016-10-14 17:38:31 +01:00
parent 727fc5c220
commit 55414e4581
17 changed files with 205 additions and 75 deletions

View File

@ -30,7 +30,7 @@
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Found on your &lt;a href=&quot;https://symless.com/account/?source=gui&quot;&gt;account&lt;/a&gt; page.</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This can be found on your &lt;a href=&quot;https://symless.com/account/?source=gui&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;account&lt;/span&gt;&lt;/a&gt; page.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
@ -46,8 +46,8 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="acceptRichText">
<bool>false</bool>

View File

@ -27,6 +27,42 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="m_trialWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="Synergy.qrc">:/res/icons/16x16/warning.png</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="trialLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="m_pWidgetUpdate" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">

View File

@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="m_pTabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="m_pTabScreens">
<attribute name="title">

View File

@ -22,6 +22,12 @@ ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
m_subscriptionManager (&subscriptionManager)
{
ui->setupUi(this);
refreshSerialKey();
}
void ActivationDialog::refreshSerialKey()
{
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
}
@ -33,20 +39,21 @@ ActivationDialog::~ActivationDialog()
void ActivationDialog::reject()
{
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->notifySkip();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
QDialog::reject();
if (m_subscriptionManager->edition() == Edition::kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_subscriptionManager->skipActivation();
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
}
}
QDialog::reject();
}
void ActivationDialog::accept()
{
QMessageBox message;
QString error;
int edition = Unregistered;
m_appConfig->activationHasRun(true);
m_appConfig->saveSettings();
@ -60,13 +67,14 @@ void ActivationDialog::accept()
tr("An error occurred while trying to activate Synergy. "
"Please contact the helpdesk, and provide the "
"following details.\n\n%1").arg(e.what()));
refreshSerialKey();
return;
}
m_appConfig->setEdition(edition);
m_appConfig->saveSettings();
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg(getEditionName(edition)));
if (m_subscriptionManager->edition() != Edition::kUnregistered) {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(getEditionName(m_subscriptionManager->edition())));
}
QDialog::accept();
}

View File

@ -23,6 +23,9 @@ public slots:
void reject();
void accept();
protected:
void refreshSerialKey();
private:
Ui::ActivationDialog *ui;
AppConfig* m_appConfig;

View File

@ -157,7 +157,7 @@ void AppConfig::loadSettings()
}
m_ElevateMode = static_cast<ElevateMode>(elevateMode.toInt());
m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool();
m_Edition = settings().value("edition", Unregistered).toInt();
m_Edition = static_cast<Edition>(settings().value("edition", kUnregistered).toInt());
m_ActivateEmail = settings().value("activateEmail", "").toString();
m_CryptoEnabled = settings().value("cryptoEnabled", true).toBool();
m_AutoHide = settings().value("autoHide", false).toBool();
@ -237,12 +237,11 @@ void AppConfig::setAutoConfigPrompted(bool prompted)
m_AutoConfigPrompted = prompted;
}
void AppConfig::setEdition(int e) {
void AppConfig::setEdition(Edition e) {
m_Edition = e;
emit editionSet (e);
}
int AppConfig::edition() const { return m_Edition; }
Edition AppConfig::edition() const { return m_Edition; }
QString AppConfig::setSerialKey(QString serial) {
using std::swap;
@ -276,7 +275,7 @@ void AppConfig::setCryptoEnabled(bool e) {
}
bool AppConfig::getCryptoEnabled() const {
return (edition() == Pro) && m_CryptoEnabled;
return (edition() == kPro) && m_CryptoEnabled;
}
void AppConfig::setAutoHide(bool b) { m_AutoHide = b; }

View File

@ -23,6 +23,7 @@
#include <QObject>
#include <QString>
#include "ElevateMode.h"
#include <EditionType.h>
// this should be incremented each time a new page is added. this is
// saved to settings when the user finishes running the wizard. if
@ -77,8 +78,8 @@ class AppConfig: public QObject
void setAutoConfig(bool autoConfig);
bool autoConfigPrompted();
void setAutoConfigPrompted(bool prompted);
void setEdition(int e);
int edition() const;
void setEdition(Edition);
Edition edition() const;
QString setSerialKey(QString serial);
void clearSerialKey();
QString serialKey();
@ -134,7 +135,7 @@ class AppConfig: public QObject
bool m_AutoConfig;
ElevateMode m_ElevateMode;
bool m_AutoConfigPrompted;
int m_Edition;
Edition m_Edition;
QString m_ActivateEmail;
bool m_CryptoEnabled;
bool m_AutoHide;
@ -147,7 +148,6 @@ class AppConfig: public QObject
static const char m_SynergyLogDir[];
signals:
void editionSet(int);
void sslToggled(bool enabled);
};

View File

@ -136,13 +136,28 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
m_SuppressAutoConfigWarning = false;
m_pComboServerList->hide();
setEdition(m_AppConfig->edition());
m_pLabelPadlock->hide();
connect (this, SIGNAL(windowShown()), this, SLOT(on_windowShown()), Qt::QueuedConnection);
connect (m_AppConfig, SIGNAL(editionSet(int)), this, SLOT(setEdition(int)), Qt::QueuedConnection);
connect (m_AppConfig, SIGNAL(sslToggled(bool)), this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
setEdition (m_SubscriptionManager->edition());
this->m_trialWidget->hide();
if (m_SubscriptionManager->isTrial()) {
beginTrial();
}
connect (this, SIGNAL(windowShown()),
this, SLOT(on_windowShown()), Qt::QueuedConnection);
connect (m_SubscriptionManager, SIGNAL(editionChanged(Edition)),
this, SLOT(setEdition(Edition)), Qt::QueuedConnection);
connect (m_SubscriptionManager, SIGNAL(beginTrial()),
this, SLOT(beginTrial()), Qt::QueuedConnection);
connect (m_SubscriptionManager, SIGNAL(endTrial()),
this, SLOT(endTrial()), Qt::QueuedConnection);
connect (m_AppConfig, SIGNAL(sslToggled(bool)),
this, SLOT(sslToggled(bool)), Qt::QueuedConnection);
}
MainWindow::~MainWindow()
@ -1024,7 +1039,7 @@ void MainWindow::serverDetected(const QString name)
}
}
void MainWindow::setEdition(int edition)
void MainWindow::setEdition(Edition edition)
{
setWindowTitle(getEditionName(edition));
if (m_AppConfig->getCryptoEnabled()) {
@ -1035,6 +1050,16 @@ void MainWindow::setEdition(int edition)
saveSettings();
}
void MainWindow::beginTrial()
{
this->m_trialWidget->show();
}
void MainWindow::endTrial()
{
this->m_trialWidget->hide();
}
void MainWindow::updateLocalFingerprint()
{
if (m_AppConfig->getCryptoEnabled() && Fingerprint::local().fileExists()) {
@ -1373,7 +1398,7 @@ void MainWindow::bonjourInstallFinished()
void MainWindow::on_windowShown()
{
if (!m_AppConfig->activationHasRun() && (m_AppConfig->edition() == Unregistered)) {
if (!m_AppConfig->activationHasRun() && (m_AppConfig->edition() == kUnregistered)) {
ActivationDialog activationDialog (this, appConfig(), subscriptionManager());
activationDialog.exec();
}

View File

@ -121,7 +121,9 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
SubscriptionManager& subscriptionManager() const;
public slots:
void setEdition(int edition);
void setEdition(Edition edition);
void beginTrial();
void endTrial();
void appendLogRaw(const QString& text);
void appendLogInfo(const QString& text);
void appendLogDebug(const QString& text);

View File

@ -45,10 +45,10 @@ void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData)
QString
getEditionName (int edition) {
if (edition == Basic) {
if (edition == kBasic) {
return "Synergy Basic";
}
else if (edition == Pro) {
else if (edition == kPro) {
return "Synergy Pro";
}
else {

View File

@ -64,7 +64,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
#endif
m_pCheckBoxEnableCrypto->setChecked(m_appConfig.getCryptoEnabled());
m_pCheckBoxEnableCrypto->setEnabled(m_appConfig.edition() == Pro);
m_pCheckBoxEnableCrypto->setEnabled(m_appConfig.edition() == kPro);
}
void SettingsDialog::accept()

View File

@ -22,21 +22,59 @@
#include <QThread>
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
m_AppConfig(appConfig) {
}
void
SubscriptionManager::setSerialKey(QString serialKeyString)
{
SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isValid (::time(0)) && (serialKey != m_serialKey)) {
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (serialKey);
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
m_AppConfig->setSerialKey("");
}
}
void SubscriptionManager::notifySkip()
SerialKey
SubscriptionManager::setSerialKey(QString serialKeyString)
{
SerialKey serialKey (serialKeyString.toStdString());
if (!serialKey.isValid (::time(0))) {
throw std::runtime_error ("Invalid serial key");
}
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (m_serialKey);
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition (m_serialKey.edition());
emit editionChanged (m_serialKey.edition());
}
if (m_serialKey.isTrial() != serialKey.isTrial()) {
if (m_serialKey.isTrial()) {
emit beginTrial();
} else {
emit endTrial();
}
}
}
return serialKey;
}
Edition SubscriptionManager::edition() const
{
return m_serialKey.edition();
}
bool SubscriptionManager::isTrial() const
{
return m_serialKey.isTrial();
}
void SubscriptionManager::skipActivation()
{
notifyActivation ("skip:unknown");
}

View File

@ -28,12 +28,14 @@ class SubscriptionManager: public QObject
Q_OBJECT
public:
SubscriptionManager (AppConfig* appConfig);
void setSerialKey (QString serialKey);
void notifySkip ();
SubscriptionManager(AppConfig* appConfig);
SerialKey setSerialKey(QString serialKey);
Edition edition() const;
bool isTrial() const;
void skipActivation();
private:
void notifyActivation (QString identity);
void notifyActivation(QString identity);
private:
AppConfig* m_AppConfig;
@ -42,4 +44,6 @@ private:
signals:
void serialKeyChanged (SerialKey);
void editionChanged (Edition);
void beginTrial ();
void endTrial ();
};

View File

@ -84,6 +84,7 @@ int main(int argc, char* argv[])
QSettings settings;
AppConfig appConfig (&settings);
qRegisterMetaType<Edition>("Edition");
SubscriptionManager subscriptionManager (&appConfig);
app.switchTranslator(appConfig.language());

View File

@ -21,10 +21,10 @@
/* Do not reorder these! */
enum Edition {
Basic,
Pro,
kBasic,
kPro,
Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN,
Unregistered
kUnregistered
};
#endif // EDITIONTYPE_H

View File

@ -21,13 +21,17 @@
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
SerialKey::SerialKey():
m_warnTime(1),
m_expireTime(1),
m_trial(true)
SerialKey::SerialKey(Edition edition):
m_userLimit(1),
m_warnTime(ULLONG_MAX),
m_expireTime(ULLONG_MAX),
m_edition(edition),
m_trial(false),
m_valid(true)
{
}
@ -35,13 +39,13 @@ SerialKey::SerialKey(std::string serial) :
m_userLimit(1),
m_warnTime(0),
m_expireTime(0),
m_edition(Edition::Basic),
m_edition(Edition::kBasic),
m_trial(true),
m_valid(false)
{
string plainText = decode(serial);
if (!plainText.empty()) {
parse(serial);
parse(plainText);
}
}
@ -70,7 +74,7 @@ SerialKey::isExpiring(time_t currentTime) const
bool result = false;
if (m_valid) {
if (m_warnTime < currentTime && currentTime < m_expireTime) {
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
result = true;
}
}
@ -84,7 +88,7 @@ SerialKey::isExpired(time_t currentTime) const
bool result = false;
if (m_valid) {
if (currentTime > m_expireTime) {
if (m_expireTime <= currentTime) {
result = true;
}
}
@ -108,7 +112,7 @@ time_t
SerialKey::daysLeft(time_t currentTime) const
{
unsigned long long timeLeft = 0;
if (m_expireTime > currentTime) {
if (currentTime < m_expireTime) {
timeLeft = m_expireTime - currentTime;
}
@ -176,6 +180,7 @@ SerialKey::parse(std::string plainSerial)
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
m_edition = getEdition(parts.at(1));
m_name = parts.at(2);
m_trial = false;
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
m_email = parts.at(4);
m_company = parts.at(5);
@ -202,9 +207,9 @@ SerialKey::parse(std::string plainSerial)
Edition
SerialKey::getEdition(std::string editionStr)
{
Edition e = Edition::Basic;
Edition e = Edition::kBasic;
if (editionStr == "pro") {
e = Edition::Pro;
e = Edition::kPro;
}
return e;

View File

@ -26,9 +26,10 @@
#endif
class SerialKey {
friend bool operator== (SerialKey const&, SerialKey const&);
public:
SerialKey();
SerialKey(std::string serial);
explicit SerialKey(Edition edition = Edition::kUnregistered);
explicit SerialKey(std::string serial);
bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const;
@ -68,7 +69,15 @@ private:
inline bool
operator== (SerialKey const& lhs, SerialKey const& rhs) {
return (lhs.edition() == rhs.edition());
return (lhs.m_name == rhs.m_name) &&
(lhs.m_email == rhs.m_email) &&
(lhs.m_company == rhs.m_company) &&
(lhs.m_userLimit == rhs.m_userLimit) &&
(lhs.m_warnTime == rhs.m_warnTime) &&
(lhs.m_expireTime == rhs.m_expireTime) &&
(lhs.m_edition == rhs.m_edition) &&
(lhs.m_trial == rhs.m_trial) &&
(lhs.m_valid == rhs.m_valid);
}
inline bool