logic: Added Non-Commercial Use option and removed trial mode

* Added non-commercial use option to enter license window
* Show enter license window on first start and force license selection
* Added ApplicationSettings migration that removed private/academic license and switches user to non-commercial mode
* Added commandline option to choose non-commercial use and provide better hints to license selection
* Removed trial mode

fortune cookie message = A secret admirer will soon send you a sign of affection.
This commit is contained in:
Eberhard Graether
2017-10-19 16:58:47 +02:00
parent c3a5405cc4
commit 8e908c2a78
30 changed files with 602 additions and 495 deletions
+20 -9
View File
@@ -7,6 +7,7 @@
#include "utility/messaging/filter_types/MessageFilterNewErrors.h"
#include "utility/messaging/filter_types/MessageFilterSearchAutocomplete.h"
#include "utility/messaging/MessageQueue.h"
#include "utility/messaging/type/MessageForceEnterLicense.h"
#include "utility/messaging/type/MessageQuitApplication.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/scheduling/TaskScheduler.h"
@@ -112,6 +113,7 @@ void Application::loadStyle(const FilePath& colorSchemePath)
Application::Application(bool withGUI)
: m_hasGUI(withGUI)
, m_licenseType(MessageEnteredLicense::LICENSE_NONE)
, m_lastLicenseCheck(TimeStamp::now())
{
LicenseChecker::createInstance();
}
@@ -159,11 +161,6 @@ std::shared_ptr<DialogView> Application::getDialogView()
return std::make_shared<DialogView>(nullptr);
}
bool Application::isInTrial() const
{
return m_licenseType == MessageEnteredLicense::LICENSE_NONE;
}
void Application::updateHistory(const std::vector<SearchMatch>& history)
{
m_mainView->updateHistoryMenu(history);
@@ -323,10 +320,26 @@ void Application::handleMessage(MessageSwitchColorScheme* message)
void Application::handleMessage(MessageWindowFocus* message)
{
if (message->focusIn && m_project && ApplicationSettings::getInstance()->getAutomaticUpdateCheck())
if (!message->focusIn)
{
return;
}
if (m_project && ApplicationSettings::getInstance()->getAutomaticUpdateCheck())
{
m_updateChecker->checkUpdate();
}
if (!ApplicationSettings::getInstance()->getNonCommercialUse() && TimeStamp::now().deltaHours(m_lastLicenseCheck) > 1)
{
m_lastLicenseCheck = TimeStamp::now();
LicenseChecker::LicenseState state = LicenseChecker::getInstance()->checkCurrentLicense();
if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_MOVED)
{
MessageForceEnterLicense(state).dispatch();
}
}
}
void Application::startMessagingAndScheduling()
@@ -406,12 +419,10 @@ void Application::updateTitle()
switch (m_licenseType)
{
case MessageEnteredLicense::LICENSE_NONE:
title += " [trial]";
break;
case MessageEnteredLicense::LICENSE_TEST:
title += " [test]";
break;
case MessageEnteredLicense::LICENSE_NONE:
case MessageEnteredLicense::LICENSE_NON_COMMERCIAL:
title += " [non-commercial]";
break;
+1 -2
View File
@@ -55,8 +55,6 @@ public:
int handleDialog(const std::string& message, const std::vector<std::string>& options);
std::shared_ptr<DialogView> getDialogView();
bool isInTrial() const;
void updateHistory(const std::vector<SearchMatch>& history);
void updateBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks);
@@ -93,6 +91,7 @@ private:
std::shared_ptr<UpdateChecker> m_updateChecker;
MessageEnteredLicense::LicenseType m_licenseType;
TimeStamp m_lastLicenseCheck;
};
#endif // APPLICATION_H
-1
View File
@@ -385,7 +385,6 @@ add_files(
utility/messaging/type/MessageCodeReference.h
utility/messaging/type/MessageColorSchemeTest.h
utility/messaging/type/MessageDeactivateEdge.h
utility/messaging/type/MessageDispatchWhenLicenseValid.h
utility/messaging/type/MessageDisplayBookmarkCreator.h
utility/messaging/type/MessageDisplayBookmarks.h
utility/messaging/type/MessageEnteredLicense.h
+32 -33
View File
@@ -98,7 +98,7 @@ LicenseChecker::LicenseState LicenseChecker::checkCurrentLicense() const
return checkLicense(license);
}
LicenseChecker::LicenseState LicenseChecker::checkLicenseString(const std::string licenseString) const
LicenseChecker::LicenseState LicenseChecker::checkLicenseString(const std::string& licenseString) const
{
if (licenseString.size() == 0)
{
@@ -145,42 +145,41 @@ MessageEnteredLicense::LicenseType LicenseChecker::getCurrentLicenseType() const
return MessageEnteredLicense::LICENSE_COMMERCIAL;
}
MessageEnteredLicense::LicenseType LicenseChecker::getLicenseType(const std::string& licenseString) const
{
if (licenseString.size() == 0)
{
return MessageEnteredLicense::LICENSE_NONE;
}
License license;
bool isLoaded = license.loadFromString(licenseString);
if (!isLoaded)
{
return MessageEnteredLicense::LICENSE_NONE;
}
LicenseState state = checkLicense(license);
if (state != LICENSE_VALID)
{
return MessageEnteredLicense::LICENSE_NONE;
}
else if (license.isTestLicense())
{
return MessageEnteredLicense::LICENSE_TEST;
}
else if (license.isNonCommercialLicenseType())
{
return MessageEnteredLicense::LICENSE_NON_COMMERCIAL;
}
return MessageEnteredLicense::LICENSE_COMMERCIAL;
}
LicenseChecker::LicenseChecker()
: m_forcedLicenseEntering(false)
{
}
void LicenseChecker::handleMessage(MessageDispatchWhenLicenseValid* message)
{
LicenseState state = checkCurrentLicense();
if (state == LICENSE_VALID)
{
message->content->dispatch();
}
else
{
m_pendingMessage = message->content;
if (!m_forcedLicenseEntering)
{
m_forcedLicenseEntering = true;
MessageForceEnterLicense(state == LICENSE_EXPIRED).dispatch();
}
}
}
void LicenseChecker::handleMessage(MessageEnteredLicense* message)
{
m_forcedLicenseEntering = false;
if (m_pendingMessage)
{
m_pendingMessage->dispatch();
m_pendingMessage.reset();
}
}
LicenseChecker::LicenseState LicenseChecker::checkLicense(License& license) const
{
if (license.isExpired())
+2 -11
View File
@@ -1,15 +1,11 @@
#ifndef LICENSE_CHECKER_H
#define LICENSE_CHECKER_H
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
#include "utility/messaging/type/MessageEnteredLicense.h"
class License;
class LicenseChecker
: public MessageListener<MessageDispatchWhenLicenseValid>
, public MessageListener<MessageEnteredLicense>
{
public:
enum LicenseState
@@ -32,24 +28,19 @@ public:
bool isCurrentLicenseValid();
LicenseState checkCurrentLicense() const;
LicenseState checkLicenseString(const std::string licenseString) const;
LicenseState checkLicenseString(const std::string& licenseString) const;
MessageEnteredLicense::LicenseType getCurrentLicenseType() const;
MessageEnteredLicense::LicenseType getLicenseType(const std::string& licenseString) const;
private:
LicenseChecker();
LicenseChecker(const LicenseChecker&) = delete;
void operator=(const LicenseChecker&) = delete;
void handleMessage(MessageDispatchWhenLicenseValid* message);
void handleMessage(MessageEnteredLicense* message);
LicenseState checkLicense(License& license) const;
static std::shared_ptr<LicenseChecker> s_instance;
std::shared_ptr<MessageBase> m_pendingMessage;
bool m_forcedLicenseEntering;
};
#endif // LICENSE_CHECKER_H
@@ -4,7 +4,6 @@
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageActivateSourceLocations.h"
#include "utility/messaging/type/MessageActivateWindow.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
#include "utility/messaging/type/MessageProjectNew.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/messaging/type/MessageActivateFile.h"
@@ -143,29 +142,13 @@ void IDECommunicationController::handleSetActiveTokenMessage(
void IDECommunicationController::handleCreateProjectMessage(const NetworkProtocolHelper::CreateProjectMessage& message)
{
LOG_ERROR_STREAM(<< "Network Protocol CreateProjectMessage not supported anymore.");
// if (message.valid)
// {
// if (message.ideId == "vs")
// {
// std::shared_ptr<MessageProjectNew> msg = std::make_shared<MessageProjectNew>();
// msg->setSolutionPath(message.solutionFileLocation);
// msg->ideId = message.ideId;
// MessageDispatchWhenLicenseValid(msg).dispatch();
// }
// else
// {
// LOG_ERROR_STREAM(<< "Unable to parse provided solution, unknown format");
// }
// }
}
void IDECommunicationController::handleCreateCDBProjectMessage(const NetworkProtocolHelper::CreateCDBProjectMessage& message)
{
if (message.valid)
{
MessageDispatchWhenLicenseValid(
std::make_shared<MessageProjectNew>(message.cdbFileLocation, message.headerPaths)).dispatch();
MessageProjectNew(message.cdbFileLocation, message.headerPaths).dispatch();
}
else
{
-11
View File
@@ -22,7 +22,6 @@
#include "utility/file/FilePath.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageClearErrorCount.h"
#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageStatus.h"
@@ -131,16 +130,6 @@ bool Project::refresh(bool forceRefresh)
}
}
if (Application::getInstance()->isInTrial())
{
std::vector<std::string> options = { "Ok" };
dialogView->confirm("You can't refresh the project in trial mode, please unlock with a license key.", options);
MessageDispatchWhenLicenseValid(std::make_shared<MessageRefresh>()).dispatch();
return false;
}
dialogView->showUnknownProgressDialog("Preparing Project", "Processing Files");
ScopedFunctor dialogHider([&dialogView](){
+33 -6
View File
@@ -1,7 +1,10 @@
#include "settings/ApplicationSettings.h"
#include "License.h"
#include "settings/migration/SettingsMigrator.h"
#include "settings/migration/SettingsMigrationLambda.h"
#include "settings/migration/SettingsMigrationMoveKey.h"
#include "utility/AppPath.h"
#include "utility/ResourcePaths.h"
#include "utility/Status.h"
#include "utility/TimeStamp.h"
@@ -9,7 +12,7 @@
#include "utility/UserPaths.h"
#include "utility/Version.h"
const size_t ApplicationSettings::VERSION = 2;
const size_t ApplicationSettings::VERSION = 3;
std::shared_ptr<ApplicationSettings> ApplicationSettings::s_instance;
@@ -57,6 +60,20 @@ bool ApplicationSettings::load(const FilePath& filePath)
"network/coati_port",
"network/sourcetrail_port"
));
migrator.addMigration(3, std::make_shared<SettingsMigrationLambda>(
[](const SettingsMigration* migration, Settings* settings)
{
License license;
bool isLoaded = license.loadFromEncodedString(
migration->getValueFromSettings<std::string>(settings, "user/license/license", ""), AppPath::getAppPath());
if (isLoaded && license.isValid() && license.isNonCommercialLicenseType())
{
migration->removeValuesInSettings(settings, "user/license/license");
migration->removeValuesInSettings(settings, "user/license/check");
migration->setValueInSettings(settings, "user/license/non_commercial_use", true);
}
}
));
bool migrated = migrator.migrate(this, ApplicationSettings::VERSION);
@@ -524,17 +541,27 @@ std::string ApplicationSettings::getLicenseString() const
return getValue<std::string>("user/license/license", "");
}
std::string ApplicationSettings::getLicenseCheck() const
{
return getValue<std::string>("user/license/check", "");
}
void ApplicationSettings::setLicenseString(const std::string& licenseString)
{
setValue<std::string>("user/license/license", licenseString);
}
std::string ApplicationSettings::getLicenseCheck() const
{
return getValue<std::string>("user/license/check", "");
}
void ApplicationSettings::setLicenseCheck(const std::string& hash)
{
setValue<std::string>("user/license/check", hash);
}
bool ApplicationSettings::getNonCommercialUse() const
{
return getValue<bool>("user/license/non_commercial_use", false);
}
void ApplicationSettings::setNonCommercialUse(bool nonCommercialUse)
{
setValue<bool>("user/license/non_commercial_use", nonCommercialUse);
}
+3
View File
@@ -159,6 +159,9 @@ public:
std::string getLicenseCheck() const;
void setLicenseCheck(const std::string& hash);
bool getNonCommercialUse() const;
void setNonCommercialUse(bool nonCommercialUse);
private:
ApplicationSettings(const ApplicationSettings&);
void operator=(const ApplicationSettings&);
@@ -111,7 +111,7 @@ void CommandConfig::setup()
("global-framework-search-paths,F", po::value<std::vector<std::string>>(),
"Global include paths (once per path or comma separated)")
("show,s", "displays all settings")
;
("non-commercial-use", po::value<bool>(), "Enable non-commercial use. <true/false>");
m_options.add(options);
}
@@ -142,9 +142,6 @@ void CommandConfig::printSettings(ApplicationSettings* settings)
printVector("global-header-search-paths", settings->getHeaderSearchPaths());
printVector("global-framework-search-paths", settings->getFrameworkSearchPaths());
printVector("jre-system-library-paths", settings->getJreSystemLibraryPaths());
License license;
license.loadFromEncodedString(settings->getLicenseString(), AppPath::getAppPath());
std::cout << "\nValid license: " << license.isValid() << std::endl;
}
@@ -205,6 +202,8 @@ ReturnStatus CommandConfig::parse(std::vector<std::string>& args)
parseAndSetValue(&ApplicationSettings::setHeaderSearchPaths, "global-header-search-paths", settings, vm);
parseAndSetValue(&ApplicationSettings::setFrameworkSearchPaths, "global-framework-search-paths", settings, vm);
parseAndSetValue(&ApplicationSettings::setNonCommercialUse, "non-commercial-use", settings, vm);
// license
if (vm.count("license-string") || vm.count("license-file") )
{
@@ -1,23 +0,0 @@
#ifndef MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H
#define MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H
#include "utility/messaging/Message.h"
class MessageDispatchWhenLicenseValid
: public Message<MessageDispatchWhenLicenseValid>
{
public:
MessageDispatchWhenLicenseValid(std::shared_ptr<MessageBase> content)
: content(content)
{
}
static const std::string getStaticType()
{
return "MessageDispatchWhenLicenseValid";
}
std::shared_ptr<MessageBase> content;
};
#endif // MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H
@@ -1,14 +1,15 @@
#ifndef MESSAGE_FORCE_ENTER_LICENSE_H
#define MESSAGE_FORCE_ENTER_LICENSE_H
#include "LicenseChecker.h"
#include "utility/messaging/Message.h"
class MessageForceEnterLicense
: public Message<MessageForceEnterLicense>
{
public:
MessageForceEnterLicense(bool licenseExpired)
: licenseExpired(licenseExpired)
MessageForceEnterLicense(LicenseChecker::LicenseState state)
: state(state)
{
setSendAsTask(false);
}
@@ -18,7 +19,7 @@ public:
return "MessageForceEnterLicense";
}
bool licenseExpired;
const LicenseChecker::LicenseState state;
};
#endif // MESSAGE_FORCE_ENTER_LICENSE_H