From 8e908c2a78cc8e72a0ce8b6e1cdf1abf908949b6 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Thu, 19 Oct 2017 16:58:47 +0200 Subject: [PATCH] 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. --- bin/app/data/gui/license/license.css | 12 + bin/app/data/gui/startscreen/startscreen.css | 4 +- bin/app/user/ApplicationSettings_template.xml | 1 + src/app/main.cpp | 18 +- src/lib/Application.cpp | 29 +- src/lib/Application.h | 3 +- src/lib/CMakeLists.txt | 1 - src/lib/LicenseChecker.cpp | 65 ++-- src/lib/LicenseChecker.h | 13 +- .../controller/IDECommunicationController.cpp | 19 +- src/lib/project/Project.cpp | 11 - src/lib/settings/ApplicationSettings.cpp | 39 ++- src/lib/settings/ApplicationSettings.h | 3 + .../commands/CommandlineCommandConfig.cpp | 7 +- .../type/MessageDispatchWhenLicenseValid.h | 23 -- .../messaging/type/MessageForceEnterLicense.h | 7 +- src/lib_cxx/project/SourceGroupCxxEmpty.cpp | 1 - src/lib_gui/CMakeLists.txt | 4 +- .../qt/element/QtCodeFileTitleButton.cpp | 24 +- src/lib_gui/qt/element/QtRefreshBar.cpp | 13 - src/lib_gui/qt/element/QtRefreshBar.h | 5 - src/lib_gui/qt/network/QtUpdateChecker.cpp | 6 +- src/lib_gui/qt/view/QtMainView.cpp | 4 +- src/lib_gui/qt/window/QtLicense.cpp | 169 --------- src/lib_gui/qt/window/QtLicense.h | 36 -- src/lib_gui/qt/window/QtLicenseWindow.cpp | 326 ++++++++++++++++++ src/lib_gui/qt/window/QtLicenseWindow.h | 60 ++++ src/lib_gui/qt/window/QtMainWindow.cpp | 82 +++-- src/lib_gui/qt/window/QtMainWindow.h | 7 +- src/lib_gui/qt/window/QtStartScreen.cpp | 105 ++---- 30 files changed, 602 insertions(+), 495 deletions(-) delete mode 100644 src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h delete mode 100644 src/lib_gui/qt/window/QtLicense.cpp delete mode 100644 src/lib_gui/qt/window/QtLicense.h create mode 100644 src/lib_gui/qt/window/QtLicenseWindow.cpp create mode 100644 src/lib_gui/qt/window/QtLicenseWindow.h diff --git a/bin/app/data/gui/license/license.css b/bin/app/data/gui/license/license.css index 86d110fa..1dca75dc 100644 --- a/bin/app/data/gui/license/license.css +++ b/bin/app/data/gui/license/license.css @@ -1,3 +1,11 @@ +#title { + margin-left: 265px; +} + +#licenseOption { + font-weight: bold; +} + #licenseField { font-family: ""; font-size: 11px; @@ -6,6 +14,10 @@ width: 470px; } +#licenseField:disabled { + background: #F5F5F5; +} + #licenseError { color: red; } diff --git a/bin/app/data/gui/startscreen/startscreen.css b/bin/app/data/gui/startscreen/startscreen.css index 7a7acc6b..6b3cff93 100644 --- a/bin/app/data/gui/startscreen/startscreen.css +++ b/bin/app/data/gui/startscreen/startscreen.css @@ -42,7 +42,7 @@ font-weight: bold; } -#updateButton { +#updateButton, #upgradeButton { margin: 1px 0 3px; text-align: left; padding: 0; @@ -53,7 +53,7 @@ text-decoration: underline; } -#updateButton:disabled { +#updateButton:disabled, #upgradeButton:disabled { color: black; text-decoration: none; } diff --git a/bin/app/user/ApplicationSettings_template.xml b/bin/app/user/ApplicationSettings_template.xml index 18bab967..ac7dafc9 100644 --- a/bin/app/user/ApplicationSettings_template.xml +++ b/bin/app/user/ApplicationSettings_template.xml @@ -76,6 +76,7 @@ + diff --git a/src/app/main.cpp b/src/app/main.cpp index 55014ef6..316c61f4 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -23,7 +23,6 @@ #include "utility/logging/LoggerUtility.h" #include "utility/logging/logging.h" #include "utility/logging/LogManager.h" -#include "utility/messaging/type/MessageEnteredLicense.h" #include "utility/messaging/type/MessageInterruptTasks.h" #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageStatus.h" @@ -247,16 +246,21 @@ int main(int argc, char *argv[]) return 0; } - if (!checker->isCurrentLicenseValid()) // this works because the user cannot enter a license string while running the app in headless more. + if (!checker->isCurrentLicenseValid() && !ApplicationSettings::getInstance()->getNonCommercialUse()) { - std::cout << "No or invalide License" << std::endl; + std::string appName = argc > 0 && std::string(argv[0]).size() ? argv[0] : "sourcetrail"; + + std::cout << "\nERROR: No valid license option selected.\n\n"; + std::cout << "For commercial use please run:\n\n"; + std::cout << "\t" << appName << " config --license-string \n"; + std::cout << "or\n"; + std::cout << "\t" << appName << " config --license-file \n\n\n"; + std::cout << "For non-commercial use please run:\n\n"; + std::cout << "\t" << appName << " config --non-commercial-use true\n" << std::endl; + LOG_WARNING("Your current Sourcetrail license seems to be invalid. Please update your license info."); return 0; } - else - { - MessageEnteredLicense(checker->getCurrentLicenseType()).dispatch(); - } if (commandLineParser.hasError() ) { diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 7e2155e4..99843616 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -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 Application::getDialogView() return std::make_shared(nullptr); } -bool Application::isInTrial() const -{ - return m_licenseType == MessageEnteredLicense::LICENSE_NONE; -} - void Application::updateHistory(const std::vector& 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; diff --git a/src/lib/Application.h b/src/lib/Application.h index 72a58b47..63ec2664 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -55,8 +55,6 @@ public: int handleDialog(const std::string& message, const std::vector& options); std::shared_ptr getDialogView(); - bool isInTrial() const; - void updateHistory(const std::vector& history); void updateBookmarks(const std::vector>& bookmarks); @@ -93,6 +91,7 @@ private: std::shared_ptr m_updateChecker; MessageEnteredLicense::LicenseType m_licenseType; + TimeStamp m_lastLicenseCheck; }; #endif // APPLICATION_H diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 338471c9..ffd510b6 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/LicenseChecker.cpp b/src/lib/LicenseChecker.cpp index 3331f819..b4493b27 100644 --- a/src/lib/LicenseChecker.cpp +++ b/src/lib/LicenseChecker.cpp @@ -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()) diff --git a/src/lib/LicenseChecker.h b/src/lib/LicenseChecker.h index 7eb1e400..e61e9bbf 100644 --- a/src/lib/LicenseChecker.h +++ b/src/lib/LicenseChecker.h @@ -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 - , public MessageListener { 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 s_instance; - - std::shared_ptr m_pendingMessage; - bool m_forcedLicenseEntering; }; #endif // LICENSE_CHECKER_H diff --git a/src/lib/component/controller/IDECommunicationController.cpp b/src/lib/component/controller/IDECommunicationController.cpp index aaf52cf0..9051a9a9 100644 --- a/src/lib/component/controller/IDECommunicationController.cpp +++ b/src/lib/component/controller/IDECommunicationController.cpp @@ -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 msg = std::make_shared(); - // 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(message.cdbFileLocation, message.headerPaths)).dispatch(); + MessageProjectNew(message.cdbFileLocation, message.headerPaths).dispatch(); } else { diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 0d06a26e..b151b87f 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -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 options = { "Ok" }; - dialogView->confirm("You can't refresh the project in trial mode, please unlock with a license key.", options); - - MessageDispatchWhenLicenseValid(std::make_shared()).dispatch(); - - return false; - } - dialogView->showUnknownProgressDialog("Preparing Project", "Processing Files"); ScopedFunctor dialogHider([&dialogView](){ diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 79e8801e..a958e16c 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -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::s_instance; @@ -57,6 +60,20 @@ bool ApplicationSettings::load(const FilePath& filePath) "network/coati_port", "network/sourcetrail_port" )); + migrator.addMigration(3, std::make_shared( + [](const SettingsMigration* migration, Settings* settings) + { + License license; + bool isLoaded = license.loadFromEncodedString( + migration->getValueFromSettings(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("user/license/license", ""); } -std::string ApplicationSettings::getLicenseCheck() const -{ - return getValue("user/license/check", ""); -} - void ApplicationSettings::setLicenseString(const std::string& licenseString) { setValue("user/license/license", licenseString); } +std::string ApplicationSettings::getLicenseCheck() const +{ + return getValue("user/license/check", ""); +} + void ApplicationSettings::setLicenseCheck(const std::string& hash) { setValue("user/license/check", hash); } + +bool ApplicationSettings::getNonCommercialUse() const +{ + return getValue("user/license/non_commercial_use", false); +} + +void ApplicationSettings::setNonCommercialUse(bool nonCommercialUse) +{ + setValue("user/license/non_commercial_use", nonCommercialUse); +} diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index ca2ab4ad..23ac0687 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -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&); diff --git a/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp b/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp index d26c3d79..d704db55 100644 --- a/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp +++ b/src/lib/utility/commandline/commands/CommandlineCommandConfig.cpp @@ -111,7 +111,7 @@ void CommandConfig::setup() ("global-framework-search-paths,F", po::value>(), "Global include paths (once per path or comma separated)") ("show,s", "displays all settings") - ; + ("non-commercial-use", po::value(), "Enable non-commercial use. "); 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& 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") ) { diff --git a/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h b/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h deleted file mode 100644 index 381d1199..00000000 --- a/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h +++ /dev/null @@ -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 -{ -public: - MessageDispatchWhenLicenseValid(std::shared_ptr content) - : content(content) - { - } - - static const std::string getStaticType() - { - return "MessageDispatchWhenLicenseValid"; - } - - std::shared_ptr content; -}; - -#endif // MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H diff --git a/src/lib/utility/messaging/type/MessageForceEnterLicense.h b/src/lib/utility/messaging/type/MessageForceEnterLicense.h index 4ff7b0c9..4a6493f2 100644 --- a/src/lib/utility/messaging/type/MessageForceEnterLicense.h +++ b/src/lib/utility/messaging/type/MessageForceEnterLicense.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 { 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 diff --git a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp index 0eb5f7fe..8109e61f 100644 --- a/src/lib_cxx/project/SourceGroupCxxEmpty.cpp +++ b/src/lib_cxx/project/SourceGroupCxxEmpty.cpp @@ -3,7 +3,6 @@ #include "data/indexer/IndexerCommandCxxManual.h" #include "settings/ApplicationSettings.h" #include "utility/utility.h" -#include "Application.h" SourceGroupCxxEmpty::SourceGroupCxxEmpty(std::shared_ptr settings) : m_settings(settings) diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index b340dcd0..d64202e0 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -213,8 +213,8 @@ add_files( qt/window/QtIndexingDialog.h qt/window/QtKeyboardShortcuts.cpp qt/window/QtKeyboardShortcuts.h - qt/window/QtLicense.cpp - qt/window/QtLicense.h + qt/window/QtLicenseWindow.cpp + qt/window/QtLicenseWindow.h qt/window/QtMainWindow.cpp qt/window/QtMainWindow.h qt/window/QtPreferencesWindow.cpp diff --git a/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp b/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp index 8a3f8218..de2e3abf 100644 --- a/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp +++ b/src/lib_gui/qt/element/QtCodeFileTitleButton.cpp @@ -4,12 +4,12 @@ #include "utility/messaging/type/MessageActivateFile.h" #include "utility/messaging/type/MessageProjectEdit.h" +#include "Application.h" #include "project/Project.h" #include "qt/utility/QtContextMenu.h" #include "qt/utility/utilityQt.h" #include "settings/ColorScheme.h" #include "utility/ResourcePaths.h" -#include "Application.h" QtCodeFileTitleButton::QtCodeFileTitleButton(QWidget* parent) : QPushButton(parent) @@ -89,26 +89,18 @@ void QtCodeFileTitleButton::setProject(const std::string& name) setText(name.c_str()); m_filePath = FilePath(); - if (Application::getInstance()->isInTrial()) - { - setIcon(QIcon()); - setEnabled(false); - } - else - { - std::string text = ResourcePaths::getGuiPath().str() + "code_view/images/edit.png"; - setToolTip("edit project"); + std::string text = ResourcePaths::getGuiPath().str() + "code_view/images/edit.png"; + setToolTip("edit project"); - setIcon(utility::colorizePixmap( - QPixmap(text.c_str()), - ColorScheme::getInstance()->getColor("code/file/title/icon").c_str() - )); - } + setIcon(utility::colorizePixmap( + QPixmap(text.c_str()), + ColorScheme::getInstance()->getColor("code/file/title/icon").c_str() + )); } void QtCodeFileTitleButton::updateTexts() { - if (Application::getInstance()->isInTrial() || m_filePath.empty()) + if (m_filePath.empty()) { return; } diff --git a/src/lib_gui/qt/element/QtRefreshBar.cpp b/src/lib_gui/qt/element/QtRefreshBar.cpp index 10f5aa3e..e583689d 100644 --- a/src/lib_gui/qt/element/QtRefreshBar.cpp +++ b/src/lib_gui/qt/element/QtRefreshBar.cpp @@ -4,7 +4,6 @@ #include #include "utility/messaging/type/MessageRefresh.h" - #include "utility/ResourcePaths.h" #include "qt/utility/utilityQt.h" @@ -26,8 +25,6 @@ QtRefreshBar::QtRefreshBar() m_refreshButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac layout->addWidget(m_refreshButton); - m_refreshButton->setEnabled(false); - connect(m_refreshButton, &QPushButton::clicked, this, &QtRefreshBar::refreshClicked); refreshStyle(); @@ -53,13 +50,3 @@ void QtRefreshBar::refreshStyle() "search/button" )); } - -void QtRefreshBar::handleMessage(MessageEnteredLicense* message) -{ - m_onQtThread( - [=]() - { - m_refreshButton->setEnabled(true); - } - ); -} diff --git a/src/lib_gui/qt/element/QtRefreshBar.h b/src/lib_gui/qt/element/QtRefreshBar.h index 70604690..b63716e2 100644 --- a/src/lib_gui/qt/element/QtRefreshBar.h +++ b/src/lib_gui/qt/element/QtRefreshBar.h @@ -4,14 +4,11 @@ #include #include "qt/utility/QtThreadedFunctor.h" -#include "utility/messaging/type/MessageEnteredLicense.h" -#include "utility/messaging/MessageListener.h" class QPushButton; class QtRefreshBar : public QFrame - , public MessageListener { Q_OBJECT @@ -25,8 +22,6 @@ private slots: void refreshClicked(); private: - virtual void handleMessage(MessageEnteredLicense* message); - QtThreadedLambdaFunctor m_onQtThread; QPushButton* m_refreshButton; diff --git a/src/lib_gui/qt/network/QtUpdateChecker.cpp b/src/lib_gui/qt/network/QtUpdateChecker.cpp index c0a0a003..85498550 100644 --- a/src/lib_gui/qt/network/QtUpdateChecker.cpp +++ b/src/lib_gui/qt/network/QtUpdateChecker.cpp @@ -70,14 +70,12 @@ void QtUpdateChecker::check(bool force, std::function callback) switch (LicenseChecker::getInstance()->getCurrentLicenseType()) { case MessageEnteredLicense::LICENSE_NONE: - licenseString = "trial"; + case MessageEnteredLicense::LICENSE_NON_COMMERCIAL: + licenseString = "private"; break; case MessageEnteredLicense::LICENSE_TEST: licenseString = "test"; break; - case MessageEnteredLicense::LICENSE_NON_COMMERCIAL: - licenseString = "private"; - break; case MessageEnteredLicense::LICENSE_COMMERCIAL: licenseString = "commercial"; break; diff --git a/src/lib_gui/qt/view/QtMainView.cpp b/src/lib_gui/qt/view/QtMainView.cpp index 178a2f5a..ddfe0d98 100644 --- a/src/lib_gui/qt/view/QtMainView.cpp +++ b/src/lib_gui/qt/view/QtMainView.cpp @@ -145,12 +145,12 @@ void QtMainView::updateBookmarksMenu(const std::vector void QtMainView::handleMessage(MessageForceEnterLicense* message) { - bool expired = message->licenseExpired; + LicenseChecker::LicenseState state = message->state; m_onQtThread( [=]() { - m_window->forceEnterLicense(expired); + m_window->forceEnterLicense(state); } ); } diff --git a/src/lib_gui/qt/window/QtLicense.cpp b/src/lib_gui/qt/window/QtLicense.cpp deleted file mode 100644 index 91ca6a93..00000000 --- a/src/lib_gui/qt/window/QtLicense.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "qt/window/QtLicense.h" - -#include -#include -#include -#include - -#include "LicenseChecker.h" -#include "qt/utility/utilityQt.h" -#include "utility/ResourcePaths.h" - -QtLicense::QtLicense(QWidget *parent) - : QtWindow(false, parent) -{ -} - -QSize QtLicense::sizeHint() const -{ - return QSize(780, 520); -} - -void QtLicense::clear() -{ - if (m_licenseText) - { - m_licenseText->setText(""); - } - - if (m_errorLabel) - { - m_errorLabel->setText(" "); - } -} - -void QtLicense::load() -{ - clear(); - - std::string licenseString = LicenseChecker::getInstance()->getCurrentLicenseString(); - - if (licenseString.size() && m_licenseText) - { - m_licenseText->setText(licenseString.c_str()); - } - - updateCloseButton("Cancel"); -} - -void QtLicense::setErrorMessage(const QString& errorMessage) -{ - if (m_errorLabel) - { - m_errorLabel->setText(errorMessage); - } -} - -void QtLicense::populateWindow(QWidget* widget) -{ - QVBoxLayout* subLayout = new QVBoxLayout(); - subLayout->setContentsMargins(270, 0, 0, 0); - - QLabel* licenseName = new QLabel(); - licenseName->setText(QString::fromLatin1("Enter Licence")); - licenseName->setObjectName("title"); - subLayout->addWidget(licenseName); - - subLayout->addSpacing(10); - - QLabel* licenseIntro = new QLabel(); - licenseIntro->setText(QString::fromLatin1("Please enter a licence key to activate Sourcetrail:")); - licenseIntro->setObjectName("licenseIntro"); - subLayout->addWidget(licenseIntro); - - m_licenseText = new QTextEdit(); - m_licenseText->setObjectName("licenseField"); - m_licenseText->setAcceptRichText(false); - m_licenseText->setPlaceholderText( - "-----BEGIN LICENSE-----\n" - "Product: Sourcetrail\n" - "Licensed to:\n" - "License type:\n" - "Valid up to version:\n" - "-\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" - "xxxxxxxxxxxxxx\n" - "-----END LICENSE-----\n" - ); - subLayout->addWidget(m_licenseText); - - m_errorLabel = new QLabel(this); - m_errorLabel->setObjectName("licenseError"); - m_errorLabel->setText(" "); - subLayout->addWidget(m_errorLabel); - - subLayout->addSpacing(10); - - QLabel* linkLabel = new QLabel(this); - linkLabel->setObjectName("linkLabel"); - linkLabel->setText( - "Don't have a license key yet? " - "Please purchase a license, " - "or get a temporary test license."); - linkLabel->setOpenExternalLinks(true); - linkLabel->setWordWrap(true); - linkLabel->setGeometry(275, 300, 300, 50); - subLayout->addWidget(linkLabel); - - QVBoxLayout* layout = new QVBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->addLayout(subLayout); - layout->addSpacing(20); - - widget->setLayout(layout); -} - -void QtLicense::windowReady() -{ - m_content->setStyleSheet(m_content->styleSheet() + utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("license/license.css"))).c_str()); - - addLogo(); - - updateNextButton("Activate"); - setPreviousVisible(false); - - m_title->hide(); -} - -void QtLicense::handleNext() -{ - std::string licenseString = m_licenseText->toPlainText().toStdString(); - - LicenseChecker* checker = LicenseChecker::getInstance().get(); - LicenseChecker::LicenseState state = checker->checkLicenseString(licenseString); - - std::string errorString; - - switch (state) - { - case LicenseChecker::LICENSE_EMPTY: - errorString = "No licence key was entered."; - break; - case LicenseChecker::LICENSE_MOVED: - case LicenseChecker::LICENSE_MALFORMED: - errorString = "The entered license key is malformed."; - break; - case LicenseChecker::LICENSE_INVALID: - errorString = "The entered license key is invalid."; - break; - case LicenseChecker::LICENSE_EXPIRED: - errorString = "The entered license key is expired."; - break; - case LicenseChecker::LICENSE_VALID: - { - checker->saveCurrentLicenseString(licenseString); - m_errorLabel->setText(" "); - - emit finished(); - return; - } - } - - m_errorLabel->setText(errorString.c_str()); -} diff --git a/src/lib_gui/qt/window/QtLicense.h b/src/lib_gui/qt/window/QtLicense.h deleted file mode 100644 index 5d46f8c6..00000000 --- a/src/lib_gui/qt/window/QtLicense.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef QT_LICENSE_H -#define QT_LICENSE_H - -#include "qt/window/QtWindow.h" - -class QLabel; -class QPushButton; -class QTextEdit; - -class QtLicense - : public QtWindow -{ - Q_OBJECT - -public: - QtLicense(QWidget* parent = 0); - QSize sizeHint() const override; - - void clear(); - void load(); - - void setErrorMessage(const QString& errorMessage); - -protected: - // QtWindow implementation - virtual void populateWindow(QWidget* widget) override; - virtual void windowReady() override; - - virtual void handleNext() override; - -private: - QTextEdit* m_licenseText; - QLabel* m_errorLabel; -}; - -#endif // QT_LICENSE_H diff --git a/src/lib_gui/qt/window/QtLicenseWindow.cpp b/src/lib_gui/qt/window/QtLicenseWindow.cpp new file mode 100644 index 00000000..2201af34 --- /dev/null +++ b/src/lib_gui/qt/window/QtLicenseWindow.cpp @@ -0,0 +1,326 @@ +#include "qt/window/QtLicenseWindow.h" + +#include +#include +#include +#include +#include +#include + +#include "LicenseChecker.h" +#include "qt/utility/utilityQt.h" +#include "settings/ApplicationSettings.h" +#include "utility/ResourcePaths.h" + +QtLicenseWindow::QtLicenseWindow(QWidget *parent) + : QtWindow(false, parent) +{ +} + +QSize QtLicenseWindow::sizeHint() const +{ + return QSize(700, 500); +} + +void QtLicenseWindow::clear() +{ + if (m_licenseText) + { + m_commercialUse->setChecked(false); + m_privateUse->setChecked(false); + + m_licenseText->setText(""); + m_errorLabel->setText(" "); + } +} + +void QtLicenseWindow::load() +{ + clear(); + + std::string licenseString = LicenseChecker::getInstance()->getCurrentLicenseString(); + + if (licenseString.size() && m_licenseText) + { + m_commercialUse->setChecked(true); + + m_licenseText->setEnabled(true); + m_licenseText->setText(licenseString.c_str()); + } + else if (ApplicationSettings::getInstance()->getNonCommercialUse()) + { + m_privateUse->setChecked(true); + } +} + +void QtLicenseWindow::setErrorMessage(const QString& errorMessage) +{ + if (m_errorLabel) + { + m_errorLabel->setText(errorMessage); + } +} + +void QtLicenseWindow::populateWindow(QWidget* widget) +{ + QVBoxLayout* subLayout = new QVBoxLayout(); + subLayout->setContentsMargins(270, 0, 0, 0); + + // commercial + m_commercialUse = new QRadioButton("Commercial Use"); + m_commercialUse->setObjectName("licenseOption"); + subLayout->addWidget(m_commercialUse); + + QLabel* linkLabel = new QLabel(this); + linkLabel->setText( + "For commercial use please purchase a license, " + "or get a temporary test license."); + linkLabel->setOpenExternalLinks(true); + linkLabel->setWordWrap(true); + subLayout->addWidget(linkLabel); + + m_licenseText = new QTextEdit(); + m_licenseText->setObjectName("licenseField"); + m_licenseText->setAcceptRichText(false); + m_licenseText->setPlaceholderText( + "-----BEGIN LICENSE-----\n" + "Product: Sourcetrail\n" + "Licensed to:\n" + "License type:\n" + "Valid up to version:\n" + "-\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + "xxxxxxxxxxxxxx\n" + "-----END LICENSE-----\n" + ); + m_licenseText->setEnabled(false); + subLayout->addWidget(m_licenseText); + + m_errorLabel = new QLabel(" ", this); + m_errorLabel->setObjectName("licenseError"); + m_errorLabel->setWordWrap(true); + subLayout->addWidget(m_errorLabel); + + subLayout->addSpacing(10); + + + // private + m_privateUse = new QRadioButton("Non-Commercial Use"); + m_privateUse->setObjectName("licenseOption"); + subLayout->addWidget(m_privateUse); + + QLabel* licenseIntro2 = new QLabel("You confirm that you will use Sourcetrail solely for non-commercial purposes."); + licenseIntro2->setWordWrap(true); + subLayout->addWidget(licenseIntro2); + + QVBoxLayout* layout = new QVBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); + layout->addLayout(subLayout); + layout->addSpacing(20); + + widget->setLayout(layout); + + + connect(m_commercialUse, &QRadioButton::toggled, this, &QtLicenseWindow::optionChanged); + connect(m_privateUse, &QRadioButton::toggled, this, &QtLicenseWindow::optionChanged); +} + +void QtLicenseWindow::windowReady() +{ + m_content->setStyleSheet(m_content->styleSheet() + + utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("license/license.css"))).c_str()); + + addLogo(); + + updateTitle("Select Licence Option"); + + updateNextButton("Activate"); + setNextEnabled(false); + + setPreviousVisible(false); + updateCloseButton("Cancel"); +} + +void QtLicenseWindow::handleNext() +{ + if (m_commercialUse->isChecked()) + { + std::string licenseString = m_licenseText->toPlainText().toStdString(); + + LicenseChecker* checker = LicenseChecker::getInstance().get(); + LicenseChecker::LicenseState state = checker->checkLicenseString(licenseString); + + std::string errorString; + + switch (state) + { + case LicenseChecker::LICENSE_EMPTY: + errorString = "No licence key was entered."; + break; + case LicenseChecker::LICENSE_MOVED: + case LicenseChecker::LICENSE_MALFORMED: + errorString = "The entered license key is malformed."; + break; + case LicenseChecker::LICENSE_INVALID: + errorString = "The entered license key is invalid."; + break; + case LicenseChecker::LICENSE_EXPIRED: + errorString = "The entered license key is expired."; + break; + case LicenseChecker::LICENSE_VALID: + { + if (checker->getLicenseType(licenseString) == MessageEnteredLicense::LICENSE_NON_COMMERCIAL) + { + errorString = + "The entered license key does not permit commercial use. You no longer need a license " + "key for non-commercial use. Please choose the non-commercial option below."; + break; + } + + checker->saveCurrentLicenseString(licenseString); + m_errorLabel->setText(" "); + + ApplicationSettings::getInstance()->setNonCommercialUse(false); + ApplicationSettings::getInstance()->save(); + + emit finished(); + return; + } + } + + m_errorLabel->setText(errorString.c_str()); + } + else if (m_privateUse->isChecked()) + { + if (!m_confirmWindow) + { + m_confirmWindow = new QtNonCommercialInfoWindow(); + m_confirmWindow->setup(); + + connect(m_confirmWindow, &QtWindow::canceled, + [this]() + { + m_confirmWindow->hideWindow(); + raise(); + } + ); + + connect(m_confirmWindow, &QtWindow::finished, + [this]() + { + m_confirmWindow->hideWindow(); + raise(); + + ApplicationSettings::getInstance()->setNonCommercialUse(true); + ApplicationSettings::getInstance()->save(); + + emit finished(); + } + ); + } + + m_confirmWindow->showWindow(); + } +} + +void QtLicenseWindow::optionChanged() +{ + m_licenseText->setEnabled(m_commercialUse->isChecked()); + setNextEnabled(true); +} + + +QtNonCommercialInfoWindow::QtNonCommercialInfoWindow(QWidget *parent) + : QtWindow(false, parent) +{ +} + +QSize QtNonCommercialInfoWindow::sizeHint() const +{ + return QSize(450, 500); +} + +void QtNonCommercialInfoWindow::populateWindow(QWidget* widget) +{ + QVBoxLayout* layout = new QVBoxLayout(widget); + layout->setContentsMargins(0, 0, 0, 0); + + QLabel* titleLabel; + QLabel* textLabel; + + + titleLabel = new QLabel("Is your use non-commercial?"); + textLabel = new QLabel( + "A use is non-commercial only if it is in no manner primarily intended for or directed toward " + "commercial advantage or private monetary compensation."); + + QFont font = titleLabel->font(); + font.setBold(true); + titleLabel->setFont(font); + textLabel->setWordWrap(true); + + layout->addWidget(titleLabel); + layout->addWidget(textLabel); + layout->addSpacing(10); + + + titleLabel = new QLabel("When does non-commercial use NOT apply?"); + textLabel = new QLabel( + "

Running Sourcetrail for 'Non-Commercial Use' is not permitted, if your use is in some sense commercial. " + "Examples of commercial uses are:

" + "
  • you are using Sourcetrail to work on your company's projects (no matter whether you are working on " + "open-source projects as well),
  • " + "
  • you are a student and you use Sourcetrail for your work as a freelancer,
  • " + "
  • you use Sourcetrail in your spare time to help on your friend's new game and you are getting paid for that.
" + "

In cases like these you will need a commercial license.

" + ); + + titleLabel->setFont(font); + textLabel->setWordWrap(true); + + layout->addWidget(titleLabel); + layout->addWidget(textLabel); + layout->addSpacing(10); + + + titleLabel = new QLabel("Not sure?"); + textLabel = new QLabel( + "Contact mail@sourcetrail.com and explain your intended use in detail, then we may confirm whether a " + "non-commercial license applies." + ); + + titleLabel->setFont(font); + textLabel->setWordWrap(true); + + layout->addWidget(titleLabel); + layout->addWidget(textLabel); + layout->addStretch(); + + QCheckBox* checkbox = new QCheckBox("I confirm solely non-commercial use of Sourcetrail according to above conditions."); + connect(checkbox, &QCheckBox::toggled, + [checkbox, this]() + { + setNextEnabled(checkbox->isChecked()); + } + ); + layout->addWidget(checkbox); + layout->addStretch(); + + widget->setLayout(layout); +} + +void QtNonCommercialInfoWindow::windowReady() +{ + updateTitle("Non-Commercial Use Confirmation"); + updateCloseButton("Cancel"); + updateNextButton("Confirm"); + + setNextEnabled(false); + setPreviousVisible(false); +} \ No newline at end of file diff --git a/src/lib_gui/qt/window/QtLicenseWindow.h b/src/lib_gui/qt/window/QtLicenseWindow.h new file mode 100644 index 00000000..e7ea9d31 --- /dev/null +++ b/src/lib_gui/qt/window/QtLicenseWindow.h @@ -0,0 +1,60 @@ +#ifndef QT_LICENSE_WINDOW_H +#define QT_LICENSE_WINDOW_H + +#include "qt/window/QtWindow.h" + +class QLabel; +class QRadioButton; +class QTextEdit; + +class QtLicenseWindow + : public QtWindow +{ + Q_OBJECT + +public: + QtLicenseWindow(QWidget* parent = 0); + QSize sizeHint() const override; + + void clear(); + void load(); + + void setErrorMessage(const QString& errorMessage); + +protected: + // QtWindow implementation + virtual void populateWindow(QWidget* widget) override; + virtual void windowReady() override; + + virtual void handleNext() override; + +private slots: + void optionChanged(); + +private: + QRadioButton* m_commercialUse; + QRadioButton* m_privateUse; + + QTextEdit* m_licenseText; + QLabel* m_errorLabel; + + QtWindow* m_confirmWindow = nullptr; +}; + + +class QtNonCommercialInfoWindow + : public QtWindow +{ + Q_OBJECT + +public: + QtNonCommercialInfoWindow(QWidget* parent = 0); + QSize sizeHint() const override; + +protected: + // QtWindow implementation + virtual void populateWindow(QWidget* widget) override; + virtual void windowReady() override; +}; + +#endif // QT_LICENSE_WINDOW_H diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index 2d3d9d89..0f78cdd6 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -14,7 +14,6 @@ #include "component/view/TabbedView.h" #include "component/view/View.h" #include "data/bookmark/Bookmark.h" -#include "LicenseChecker.h" #include "qt/utility/QtContextMenu.h" #include "qt/utility/QtFileDialog.h" #include "qt/utility/utilityQt.h" @@ -24,7 +23,7 @@ #include "qt/window/QtAboutLicense.h" #include "qt/window/QtEulaWindow.h" #include "qt/window/QtKeyboardShortcuts.h" -#include "qt/window/QtLicense.h" +#include "qt/window/QtLicenseWindow.h" #include "qt/window/QtPreferencesWindow.h" #include "qt/window/QtStartScreen.h" #include "settings/ApplicationSettings.h" @@ -263,11 +262,11 @@ void QtMainWindow::loadWindow(bool showStartWindow) MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch(); } - setTrialActionsEnabled(licenseValid); + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); if (state == LicenseChecker::LICENSE_MOVED) { - ApplicationSettings::getInstance()->setLicenseString(""); + appSettings->setLicenseString(""); } if (showStartWindow) @@ -275,13 +274,13 @@ void QtMainWindow::loadWindow(bool showStartWindow) showStartScreen(); } - if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_EMPTY) + if (state != LicenseChecker::LICENSE_VALID && !appSettings->getNonCommercialUse()) { - forceEnterLicense(state == LicenseChecker::LICENSE_EXPIRED); + forceEnterLicense(state); } #ifndef Q_OS_WIN - if (ApplicationSettings::getInstance()->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION) + if (appSettings->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION) { showEula(true); } @@ -305,26 +304,40 @@ void QtMainWindow::saveLayout() settings.setValue("DOCK_LOCATIONS", this->saveState()); } -void QtMainWindow::forceEnterLicense(bool expired) +void QtMainWindow::forceEnterLicense(LicenseChecker::LicenseState state) { + QtLicenseWindow* window = dynamic_cast(m_windowStack.getTopWindow()); + if (window) + { + return; + } + enterLicense(); - QtLicense* enterLicenseWindow = dynamic_cast(m_windowStack.getTopWindow()); - if (!enterLicenseWindow) + window = dynamic_cast(m_windowStack.getTopWindow()); + if (!window) { LOG_ERROR("No enter license window on top of stack"); return; } - if (expired) + if (state == LicenseChecker::LICENSE_EXPIRED) { - enterLicenseWindow->setErrorMessage("The license key is expired."); + window->setErrorMessage("The license key is expired."); } - else + else if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_EMPTY) { - enterLicenseWindow->clear(); - enterLicenseWindow->setErrorMessage("Please re-enter your license key."); + window->clear(); + window->setErrorMessage("Please re-enter your license key."); } + + window->updateCloseButton("Quit"); + + setEnabled(false); + window->setEnabled(true); + + disconnect(window, &QtWindow::canceled, &m_windowStack, &QtWindowStack::popWindow); + connect(window, &QtWindow::canceled, dynamic_cast(QCoreApplication::instance()), &QApplication::quit); } void QtMainWindow::updateHistoryMenu(const std::vector& history) @@ -458,11 +471,11 @@ void QtMainWindow::showLicenses() void QtMainWindow::enterLicense() { - QtLicense* enterLicenseWindow = createWindow(); + QtLicenseWindow* enterLicenseWindow = createWindow(); enterLicenseWindow->setup(); - disconnect(enterLicenseWindow, &QtLicense::finished, &m_windowStack, &QtWindowStack::clearWindows); - connect(enterLicenseWindow, &QtLicense::finished, this, &QtMainWindow::enteredLicense); + disconnect(enterLicenseWindow, &QtLicenseWindow::finished, &m_windowStack, &QtWindowStack::clearWindows); + connect(enterLicenseWindow, &QtLicenseWindow::finished, this, &QtMainWindow::enteredLicense); enterLicenseWindow->load(); } @@ -477,9 +490,10 @@ void QtMainWindow::enteredLicense() m_windowStack.clearWindows(); - setTrialActionsEnabled(true); MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch(); + setEnabled(true); + if (showStartWindow) { showStartScreen(); @@ -732,8 +746,7 @@ void QtMainWindow::setupProjectMenu() QMenu *menu = new QMenu(tr("&Project"), this); menuBar()->addMenu(menu); - m_trialDisabledActions.push_back( - menu->addAction(tr("&New Project..."), this, &QtMainWindow::newProject, QKeySequence::New)); + menu->addAction(tr("&New Project..."), this, &QtMainWindow::newProject, QKeySequence::New); menu->addAction(tr("&Open Project..."), this, &QtMainWindow::openProject, QKeySequence::Open); QMenu *recentProjectMenu = new QMenu(tr("Recent Projects")); @@ -753,8 +766,8 @@ void QtMainWindow::setupProjectMenu() menu->addSeparator(); - m_trialDisabledActions.push_back(menu->addAction(tr("&Edit Project..."), this, &QtMainWindow::editProject)); - m_trialDisabledActions.push_back(menu->addSeparator()); + menu->addAction(tr("&Edit Project..."), this, &QtMainWindow::editProject); + menu->addSeparator(); menu->addAction(tr("E&xit"), QCoreApplication::instance(), &QCoreApplication::quit, QKeySequence::Quit); } @@ -764,21 +777,14 @@ void QtMainWindow::setupEditMenu() QMenu *menu = new QMenu(tr("&Edit"), this); menuBar()->addMenu(menu); - m_trialDisabledActions.push_back(menu->addAction(tr("&Refresh"), this, &QtMainWindow::refresh, QKeySequence::Refresh)); + menu->addAction(tr("&Refresh"), this, &QtMainWindow::refresh, QKeySequence::Refresh); if (utility::getOsType() == OS_WINDOWS) { - m_trialDisabledActions.push_back( - menu->addAction(tr("&Full Refresh"), this, &QtMainWindow::forceRefresh, QKeySequence(Qt::SHIFT + Qt::Key_F5)) - ); + menu->addAction(tr("&Full Refresh"), this, &QtMainWindow::forceRefresh, QKeySequence(Qt::SHIFT + Qt::Key_F5)); } else { - m_trialDisabledActions.push_back(menu->addAction( - tr("&Full Refresh"), - this, - &QtMainWindow::forceRefresh, - QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_R) - )); + menu->addAction(tr("&Full Refresh"), this, &QtMainWindow::forceRefresh, QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_R)); } menu->addSeparator(); @@ -906,10 +912,10 @@ void QtMainWindow::setupHelpMenu() menu->addAction(tr("Keyboard Shortcuts"), this, &QtMainWindow::showKeyboardShortcuts); menu->addAction(tr("Documentation"), this, &QtMainWindow::showDocumentation); menu->addAction(tr("Bug Tracker"), this, &QtMainWindow::showBugtracker); - menu->addAction(tr("Enter License..."), this, &QtMainWindow::enterLicense); menu->addSeparator(); + menu->addAction(tr("Select License..."), this, &QtMainWindow::enterLicense); menu->addAction(tr("End User License Agreement"), this, &QtMainWindow::showEula); menu->addAction(tr("3rd Party Licences"), this, &QtMainWindow::showLicenses); menu->addAction(tr("&About Sourcetrail"), this, &QtMainWindow::about); @@ -920,14 +926,6 @@ void QtMainWindow::setupHelpMenu() menu->addAction(tr("Show Log Folder"), this, &QtMainWindow::showLogFolder); } -void QtMainWindow::setTrialActionsEnabled(bool enabled) -{ - for (QAction* action : m_trialDisabledActions) - { - action->setEnabled(enabled); - } -} - QtMainWindow::DockWidget* QtMainWindow::getDockWidgetForView(View* view) { for (DockWidget& dock : m_dockWidgets) diff --git a/src/lib_gui/qt/window/QtMainWindow.h b/src/lib_gui/qt/window/QtMainWindow.h index c42059a0..983fdbda 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -8,6 +8,7 @@ #include #include "data/search/SearchMatch.h" +#include "LicenseChecker.h" #include "qt/window/QtWindowStack.h" class Bookmark; @@ -71,7 +72,7 @@ public: void loadDockWidgetLayout(); void loadWindow(bool showStartWindow); - void forceEnterLicense(bool expired); + void forceEnterLicense(LicenseChecker::LicenseState state); void updateHistoryMenu(const std::vector& history); void updateBookmarksMenu(const std::vector>& bookmarks); @@ -160,8 +161,6 @@ private: void setupBookmarksMenu(); void setupHelpMenu(); - void setTrialActionsEnabled(bool enabled); - DockWidget* getDockWidgetForView(View* view); void setShowDockWidgetTitleBars(bool showTitleBars); @@ -187,8 +186,6 @@ private: bool m_showDockWidgetTitleBars; - std::vector m_trialDisabledActions; - QtWindowStack m_windowStack; }; diff --git a/src/lib_gui/qt/window/QtStartScreen.cpp b/src/lib_gui/qt/window/QtStartScreen.cpp index 48d13b18..8cd1632a 100644 --- a/src/lib_gui/qt/window/QtStartScreen.cpp +++ b/src/lib_gui/qt/window/QtStartScreen.cpp @@ -145,7 +145,6 @@ void QtStartScreen::setupStartScreen() { License license; license.loadFromEncodedString(ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath()); - bool licenseValid = license.isValid(); setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("startscreen/startscreen.css"))).c_str()); addLogo(); @@ -166,52 +165,10 @@ void QtStartScreen::setupStartScreen() QtUpdateCheckerWidget* checker = new QtUpdateCheckerWidget(this); col->addWidget(checker); - if (!licenseValid) + col->addSpacing(30); + + if (license.isValid()) { - col->addSpacing(20); - - QLabel* welcomeLabel = new QLabel( - "Welcome to the trial version of Sourcetrail!
" - "Explore our preindexed projects to experience Sourcetrail's unique user interface. " - "More projects are available for download here.

" - "If you want to use Sourcetrail on your own source code please " - "purchase a license, " - "or get a temporary test license.", this); - welcomeLabel->setOpenExternalLinks(true); - welcomeLabel->setObjectName("welcomeLabel"); - welcomeLabel->setWordWrap(true); - welcomeLabel->setAlignment(Qt::AlignTop); - - col->addWidget(welcomeLabel, 0, Qt::AlignHCenter | Qt::AlignTop); - col->addStrut(260); - col->addStretch(); - - QPushButton* openProjectButton = new QPushButton("Open Project", this); - openProjectButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - openProjectButton->setObjectName("projectButton"); - openProjectButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(openProjectButton, &QPushButton::clicked, this, &QtStartScreen::handleOpenProjectButton); - col->addWidget(openProjectButton); - - col->addSpacing(8); - - QPushButton* unlockButton = new QPushButton("Unlock", this); - unlockButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - unlockButton->setObjectName("projectButton"); - unlockButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(unlockButton, &QPushButton::clicked, this, &QtStartScreen::handleUnlockButton); - - QHBoxLayout* row = new QHBoxLayout(); - row->addWidget(unlockButton); - row->addStretch(); - col->addLayout(row); - - layout->addStretch(1); - } - else - { - col->addSpacing(30); - std::string licenseString = license.getLicenseInfo(); QLabel* licenseHeader = new QLabel("Licensed to:"); @@ -221,27 +178,39 @@ void QtStartScreen::setupStartScreen() QLabel* licenseLabel = new QLabel(licenseString.c_str()); licenseLabel->setObjectName("licenseLabel"); col->addWidget(licenseLabel); - - col->addStretch(); - - QPushButton* newProjectButton = new QPushButton("New Project", this); - newProjectButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - newProjectButton->setObjectName("projectButton"); - newProjectButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(newProjectButton, &QPushButton::clicked, this, &QtStartScreen::handleNewProjectButton); - col->addWidget(newProjectButton); - - col->addSpacing(8); - - QPushButton* openProjectButton = new QPushButton("Open Project", this); - openProjectButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - openProjectButton->setObjectName("projectButton"); - openProjectButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - connect(openProjectButton, &QPushButton::clicked, this, &QtStartScreen::handleOpenProjectButton); - col->addWidget(openProjectButton); - - layout->addStretch(2); } + else + { + QLabel* licenseHeader = new QLabel("Not licensed for
commercial use."); + licenseHeader->setObjectName("licenseHeaderLabel"); + col->addWidget(licenseHeader); + + QPushButton* upgradeButton = new QPushButton("upgrade"); + upgradeButton->setObjectName("upgradeButton"); + upgradeButton->setCursor(Qt::PointingHandCursor); + col->addWidget(upgradeButton); + connect(upgradeButton, &QPushButton::clicked, [this](){ emit openEnterLicenseDialog(); }); + } + + col->addStretch(); + + QPushButton* newProjectButton = new QPushButton("New Project", this); + newProjectButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + newProjectButton->setObjectName("projectButton"); + newProjectButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + connect(newProjectButton, &QPushButton::clicked, this, &QtStartScreen::handleNewProjectButton); + col->addWidget(newProjectButton); + + col->addSpacing(8); + + QPushButton* openProjectButton = new QPushButton("Open Project", this); + openProjectButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + openProjectButton->setObjectName("projectButton"); + openProjectButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + connect(openProjectButton, &QPushButton::clicked, this, &QtStartScreen::handleOpenProjectButton); + col->addWidget(openProjectButton); + + layout->addStretch(2); } { @@ -249,10 +218,6 @@ void QtStartScreen::setupStartScreen() layout->addLayout(col, 1); QLabel* recentProjectsLabel = new QLabel("Recent Projects: ", this); - if (!licenseValid) - { - recentProjectsLabel->setText("Projects:"); - } recentProjectsLabel->setObjectName("recentLabel"); col->addWidget(recentProjectsLabel);