Show subscription warning once a day #4716

This commit is contained in:
Jerry (Xinyu Hou) 2015-11-17 14:51:04 -08:00
parent f8e9047c36
commit 7ecc0457e0
8 changed files with 38 additions and 40 deletions

View File

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

View File

@ -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);
@ -133,6 +134,7 @@ void AppConfig::loadSettings()
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()
@ -155,6 +157,7 @@ void AppConfig::saveSettings()
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)

View File

@ -80,6 +80,8 @@ class AppConfig
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; }
@ -132,6 +134,7 @@ class AppConfig
bool m_CryptoEnabled;
bool m_AutoHide;
QString m_Serialkey;
int m_LastExpiringWarningTime;
static const char m_SynergysName[];
static const char m_SynergycName[];

View File

@ -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"
@ -699,7 +698,7 @@ QString MainWindow::appPath(const QString& name)
bool MainWindow::serverArgs(QStringList& args, QString& app)
{
int edition;
SubscriptionManager subscriptionManager(this, edition);
SubscriptionManager subscriptionManager(this, appConfig(), edition);
if (subscriptionManager.checkSubscriptionExist())
{
if (!subscriptionManager.checkSubscription()) {

View File

@ -20,7 +20,6 @@
#include "WebClient.h"
#include "SubscriptionManager.h"
#include "EditionType.h"
#include "SubscriptionState.h"
#include "QSynergyApplication.h"
#include "QUtility.h"
@ -127,7 +126,7 @@ bool SetupWizard::validateCurrentPage()
}
else {
// create subscription file in profile directory
SubscriptionManager subscriptionManager(this, m_Edition);
SubscriptionManager subscriptionManager(this, m_MainWindow.appConfig(), m_Edition);
if (!subscriptionManager.activateSerial(m_pLineEditSerialKey->text())) {
return false;
}

View File

@ -17,15 +17,19 @@
#include "SubscriptionManager.h"
#include "CoreInterface.h"
#include "EditionType.h"
#include "SubscriptionState.h"
#include "AppConfig.h"
#include <QMessageBox>
#include <QFile>
#include <QDateTime>
#include <QDate>
SubscriptionManager::SubscriptionManager(QWidget* parent, int& edition) :
SubscriptionManager::SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition) :
m_pParent(parent),
m_AppConfig(appConfig),
m_Edition(edition)
{
@ -117,12 +121,11 @@ void SubscriptionManager::getEditionType(QString& output)
void SubscriptionManager::checkExpiring(QString& output)
{
if (output.contains("trial will end in")) {
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);
// TODO: warn user once a day
QMessageBox::warning(m_pParent, tr("Subscription warning"),
tr("Your trial will end in %1 %2. Click <a href='https://synergy-project.org/account/'>here</a> to purchase")
.arg(dayLeft)
@ -130,3 +133,19 @@ void SubscriptionManager::checkExpiring(QString& output)
}
}
}
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 result;
}

View File

@ -19,10 +19,12 @@
#include <QWidget>
class AppConfig;
class SubscriptionManager : public QWidget
{
public:
SubscriptionManager(QWidget* parent, int& edition);
SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition);
bool activateSerial(const QString& serial);
bool checkSubscription();
@ -34,9 +36,11 @@ private:
void checkOutput(QString& output);
void getEditionType(QString& output);
void checkExpiring(QString& output);
bool shouldWarnExpiring();
private:
QString m_ErrorMessage;
QWidget* m_pParent;
AppConfig& m_AppConfig;
int& m_Edition;
};

View File

@ -1,28 +0,0 @@
/*
* 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