#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> <item>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <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>
<property name="openExternalLinks"> <property name="openExternalLinks">
<bool>true</bool> <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; <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; &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; } 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;/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; font-family:'Sans'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &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>
<property name="acceptRichText"> <property name="acceptRichText">
<bool>false</bool> <bool>false</bool>

View File

@ -27,6 +27,42 @@
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2"> <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> <item>
<widget class="QWidget" name="m_pWidgetUpdate" native="true"> <widget class="QWidget" name="m_pWidgetUpdate" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -136,13 +136,28 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig,
m_SuppressAutoConfigWarning = false; m_SuppressAutoConfigWarning = false;
m_pComboServerList->hide(); m_pComboServerList->hide();
setEdition(m_AppConfig->edition());
m_pLabelPadlock->hide(); m_pLabelPadlock->hide();
connect (this, SIGNAL(windowShown()), this, SLOT(on_windowShown()), Qt::QueuedConnection); setEdition (m_SubscriptionManager->edition());
connect (m_AppConfig, SIGNAL(editionSet(int)), this, SLOT(setEdition(int)), Qt::QueuedConnection);
connect (m_AppConfig, SIGNAL(sslToggled(bool)), this, SLOT(sslToggled(bool)), Qt::QueuedConnection); 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() 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)); setWindowTitle(getEditionName(edition));
if (m_AppConfig->getCryptoEnabled()) { if (m_AppConfig->getCryptoEnabled()) {
@ -1035,6 +1050,16 @@ void MainWindow::setEdition(int edition)
saveSettings(); saveSettings();
} }
void MainWindow::beginTrial()
{
this->m_trialWidget->show();
}
void MainWindow::endTrial()
{
this->m_trialWidget->hide();
}
void MainWindow::updateLocalFingerprint() void MainWindow::updateLocalFingerprint()
{ {
if (m_AppConfig->getCryptoEnabled() && Fingerprint::local().fileExists()) { if (m_AppConfig->getCryptoEnabled() && Fingerprint::local().fileExists()) {
@ -1373,7 +1398,7 @@ void MainWindow::bonjourInstallFinished()
void MainWindow::on_windowShown() 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 activationDialog (this, appConfig(), subscriptionManager());
activationDialog.exec(); activationDialog.exec();
} }

View File

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

View File

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

View File

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

View File

@ -22,21 +22,59 @@
#include <QThread> #include <QThread>
SubscriptionManager::SubscriptionManager(AppConfig* appConfig) : SubscriptionManager::SubscriptionManager(AppConfig* appConfig) :
m_AppConfig(appConfig) { m_AppConfig(appConfig),
m_serialKey(appConfig->edition()) {
try {
setSerialKey(m_AppConfig->serialKey());
} catch (...) {
m_AppConfig->setSerialKey("");
}
} }
void SerialKey
SubscriptionManager::setSerialKey(QString serialKeyString) SubscriptionManager::setSerialKey(QString serialKeyString)
{ {
SerialKey serialKey (serialKeyString.toStdString()); SerialKey serialKey (serialKeyString.toStdString());
if (serialKey.isValid (::time(0)) && (serialKey != m_serialKey)) { 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); m_AppConfig->setSerialKey (serialKeyString);
notifyActivation ("serial:" + serialKeyString); notifyActivation ("serial:" + serialKeyString);
emit serialKeyChanged (serialKey); 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();
}
} }
} }
void SubscriptionManager::notifySkip() return serialKey;
}
Edition SubscriptionManager::edition() const
{
return m_serialKey.edition();
}
bool SubscriptionManager::isTrial() const
{
return m_serialKey.isTrial();
}
void SubscriptionManager::skipActivation()
{ {
notifyActivation ("skip:unknown"); notifyActivation ("skip:unknown");
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -26,9 +26,10 @@
#endif #endif
class SerialKey { class SerialKey {
friend bool operator== (SerialKey const&, SerialKey const&);
public: public:
SerialKey(); explicit SerialKey(Edition edition = Edition::kUnregistered);
SerialKey(std::string serial); explicit SerialKey(std::string serial);
bool isValid(time_t currentTime) const; bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const; bool isExpiring(time_t currentTime) const;
@ -68,7 +69,15 @@ private:
inline bool inline bool
operator== (SerialKey const& lhs, SerialKey const& rhs) { 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 inline bool