From 7ecc0457e042f2ce4c36f40a389994578411e32c Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Tue, 17 Nov 2015 14:51:04 -0800 Subject: [PATCH] Show subscription warning once a day #4716 --- src/gui/gui.pro | 3 +-- src/gui/src/AppConfig.cpp | 5 ++++- src/gui/src/AppConfig.h | 3 +++ src/gui/src/MainWindow.cpp | 3 +-- src/gui/src/SetupWizard.cpp | 3 +-- src/gui/src/SubscriptionManager.cpp | 27 +++++++++++++++++++++++---- src/gui/src/SubscriptionManager.h | 6 +++++- src/gui/src/SubscriptionState.h | 28 ---------------------------- 8 files changed, 38 insertions(+), 40 deletions(-) delete mode 100644 src/gui/src/SubscriptionState.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 5ada72ff..6f5232af 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -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 { diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 6bbf7323..76e2234b 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -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) diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index 80de53f6..6a7c1905 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -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[]; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 2576c0e0..2f3ec96f 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -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()) { diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index e97030d8..13078220 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -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; } diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index b9b0f5ff..6820472e 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -17,15 +17,19 @@ #include "SubscriptionManager.h" + #include "CoreInterface.h" #include "EditionType.h" -#include "SubscriptionState.h" +#include "AppConfig.h" #include #include +#include +#include -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 here 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; +} diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index bc272ef4..54e7da34 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -19,10 +19,12 @@ #include +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; }; diff --git a/src/gui/src/SubscriptionState.h b/src/gui/src/SubscriptionState.h deleted file mode 100644 index e52a6df5..00000000 --- a/src/gui/src/SubscriptionState.h +++ /dev/null @@ -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 . - */ - -#ifndef SUBSCRIPTIONSTATE_H -#define SUBSCRIPTIONSTATE_H - -enum qSubscriptionState { - kValid, - kInvalid, - kExpiredSoon, - kExpired -}; - -#endif // SUBSCRIPTIONSTATE_H