From 4bb88a51b7d3c433dd12c0327896ca8e83307468 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 17 Jul 2017 15:31:06 +0200 Subject: [PATCH] ui: Show license type label in title bar: "Sourcetrail [trial, test, non-commercial]" --- src/app/main.cpp | 2 +- src/lib/Application.cpp | 23 ++++++++++++--- src/lib/Application.h | 2 +- src/lib/LicenseChecker.cpp | 28 +++++++++++++++++++ src/lib/LicenseChecker.h | 2 ++ .../messaging/type/MessageEnteredLicense.h | 13 ++++++++- src/lib_gui/qt/window/QtMainWindow.cpp | 4 +-- src/lib_license/License.cpp | 24 ++++++++-------- src/lib_license/License.h | 3 +- 9 files changed, 78 insertions(+), 23 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index 844a7456..ec62e03b 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -193,7 +193,7 @@ int main(int argc, char *argv[]) } else { - MessageEnteredLicense().dispatch(); + MessageEnteredLicense(checker->getCurrentLicenseType()).dispatch(); } if (commandLineParser.hasError() ) diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 549e47e0..056dc109 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -106,7 +106,7 @@ void Application::loadStyle(const FilePath& colorSchemePath) Application::Application(bool withGUI) : m_hasGUI(withGUI) - , m_isInTrial(true) + , m_licenseType(MessageEnteredLicense::LICENSE_NONE) { LicenseChecker::createInstance(); } @@ -156,7 +156,7 @@ std::shared_ptr Application::getDialogView() bool Application::isInTrial() const { - return m_isInTrial; + return m_licenseType == MessageEnteredLicense::LICENSE_NONE; } void Application::updateHistory(const std::vector& history) @@ -242,7 +242,7 @@ void Application::handleMessage(MessageEnteredLicense* message) { MessageStatus("Found valid license key, unlocked application.").dispatch(); - m_isInTrial = false; + m_licenseType = message->type; updateTitle(); } @@ -381,7 +381,22 @@ void Application::updateTitle() { if (m_hasGUI) { - std::string title = m_isInTrial ? "Sourcetrail [Trial]" : "Sourcetrail"; + std::string title = "Sourcetrail"; + + switch (m_licenseType) + { + case MessageEnteredLicense::LICENSE_NONE: + title += " [trial]"; + break; + case MessageEnteredLicense::LICENSE_TEST: + title += " [test]"; + break; + case MessageEnteredLicense::LICENSE_NON_COMMERCIAL: + title += " [non-commercial]"; + break; + case MessageEnteredLicense::LICENSE_COMMERCIAL: + break; + } if (m_project) { diff --git a/src/lib/Application.h b/src/lib/Application.h index d454075c..37c0dd38 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -87,7 +87,7 @@ private: std::shared_ptr m_ideCommunicationController; - bool m_isInTrial; + MessageEnteredLicense::LicenseType m_licenseType; }; #endif // APPLICATION_H diff --git a/src/lib/LicenseChecker.cpp b/src/lib/LicenseChecker.cpp index 692dcdff..a052c277 100644 --- a/src/lib/LicenseChecker.cpp +++ b/src/lib/LicenseChecker.cpp @@ -128,6 +128,34 @@ LicenseChecker::LicenseState LicenseChecker::checkLicenseString(const std::strin return checkLicense(license); } +MessageEnteredLicense::LicenseType LicenseChecker::getCurrentLicenseType() const +{ + License license; + bool isLoaded = license.loadFromEncodedString( + ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath()); + + 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) { diff --git a/src/lib/LicenseChecker.h b/src/lib/LicenseChecker.h index 12d7a3c0..7eb1e400 100644 --- a/src/lib/LicenseChecker.h +++ b/src/lib/LicenseChecker.h @@ -34,6 +34,8 @@ public: LicenseState checkCurrentLicense() const; LicenseState checkLicenseString(const std::string licenseString) const; + MessageEnteredLicense::LicenseType getCurrentLicenseType() const; + private: LicenseChecker(); LicenseChecker(const LicenseChecker&) = delete; diff --git a/src/lib/utility/messaging/type/MessageEnteredLicense.h b/src/lib/utility/messaging/type/MessageEnteredLicense.h index 6e538d39..9c270b9b 100644 --- a/src/lib/utility/messaging/type/MessageEnteredLicense.h +++ b/src/lib/utility/messaging/type/MessageEnteredLicense.h @@ -7,7 +7,16 @@ class MessageEnteredLicense : public Message { public: - MessageEnteredLicense() + enum LicenseType + { + LICENSE_NONE, + LICENSE_TEST, + LICENSE_NON_COMMERCIAL, + LICENSE_COMMERCIAL + }; + + MessageEnteredLicense(LicenseType type) + : type(type) { setSendAsTask(false); } @@ -16,6 +25,8 @@ public: { return "MessageEnteredLicense"; } + + const LicenseType type; }; #endif // MESSAGE_ENTERED_LICENSE_H diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index f2637d61..d26f2773 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -426,7 +426,7 @@ void QtMainWindow::enteredLicense() m_windowStack.clearWindows(); setTrialActionsEnabled(true); - MessageEnteredLicense().dispatch(); + MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch(); if (showStartWindow) { @@ -451,7 +451,7 @@ void QtMainWindow::showStartScreen() if (licenseValid) { - MessageEnteredLicense().dispatch(); + MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch(); } setTrialActionsEnabled(licenseValid); diff --git a/src/lib_license/License.cpp b/src/lib_license/License.cpp index dce8c191..020eba2f 100644 --- a/src/lib_license/License.cpp +++ b/src/lib_license/License.cpp @@ -150,6 +150,18 @@ bool License::isTestLicense() const return m_type == LicenseConstants::TEST_LICENSE_STRING; } +bool License::isNonCommercialLicenseType() const +{ + for ( const std::string nonCommercialLicenseType : NON_COMMERCIAL_LICENSE_TYPES) + { + if (m_type == nonCommercialLicenseType) + { + return true; + } + } + return false; +} + unsigned int License::getSeats() const { return m_seats; @@ -196,18 +208,6 @@ std::string License::getLicenseInfo() const return info; } -bool License::isNonCommercialLicenseType() const -{ - for ( const std::string nonCommercialLicenseType : NON_COMMERCIAL_LICENSE_TYPES) - { - if (m_type == nonCommercialLicenseType) - { - return true; - } - } - return false; -} - std::string License::getUser() const { return m_user; diff --git a/src/lib_license/License.h b/src/lib_license/License.h index 08a6ab82..8fdc9555 100644 --- a/src/lib_license/License.h +++ b/src/lib_license/License.h @@ -94,6 +94,7 @@ public: bool isValid() const; bool isExpired() const; bool isTestLicense() const; + bool isNonCommercialLicenseType() const; void print(); @@ -105,8 +106,6 @@ private: bool extractData(const std::string& string, LICENSE_LINE line); std::string removeCaption(const std::string& line, const std::string& caption) const; - bool isNonCommercialLicenseType() const; - std::string m_publicKeyFilename; std::shared_ptr m_publicKey;