From 1b8736a6e16265bc0654897d2396a7a5f615095b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Sat, 8 Oct 2016 13:42:40 +0200 Subject: [PATCH] logic: Rewrote license checking logic for trial and app merge --- cmake/licenses.cmake | 26 ++-- cmake/licenses.h.in | 21 ++- src/app/CMakeLists.txt | 1 - src/app/isTrial.cpp | 6 - src/lib/Application.cpp | 17 ++- src/lib/Application.h | 7 + src/lib/CMakeLists.txt | 1 - src/lib/LicenseChecker.cpp | 34 +++-- src/lib/LicenseChecker.h | 2 +- src/lib/Project.cpp | 3 +- src/lib/isTrial.h | 6 - .../type/MessageDispatchWhenLicenseValid.h | 4 +- src/lib_gui/qt/element/QtCodeFile.cpp | 6 +- src/lib_gui/qt/element/QtRefreshBar.cpp | 16 ++- src/lib_gui/qt/element/QtRefreshBar.h | 9 ++ src/lib_gui/qt/view/QtMainView.cpp | 2 +- src/lib_gui/qt/window/QtAboutLicense.cpp | 40 +++--- src/lib_gui/qt/window/QtLicense.cpp | 24 ---- src/lib_gui/qt/window/QtLicense.h | 4 - src/lib_gui/qt/window/QtMainWindow.cpp | 121 +++++++++++------- src/lib_gui/qt/window/QtMainWindow.h | 7 +- src/lib_gui/qt/window/QtStartScreen.cpp | 27 +++- src/lib_gui/qt/window/QtStartScreen.h | 4 +- src/lib_gui/qt/window/QtWindowStack.cpp | 10 ++ src/lib_gui/qt/window/QtWindowStack.h | 1 + src/lib_java/JavaProject.cpp | 5 +- 26 files changed, 228 insertions(+), 176 deletions(-) delete mode 100644 src/app/isTrial.cpp delete mode 100644 src/lib/isTrial.h diff --git a/cmake/licenses.cmake b/cmake/licenses.cmake index d1e4dae4..a5862c4f 100644 --- a/cmake/licenses.cmake +++ b/cmake/licenses.cmake @@ -14,23 +14,23 @@ function(ReadLicense licenseFile licenseVariable) set(LICENSES "${LICENSES}${var}${tempVariable}\"\;" PARENT_SCOPE) endfunction(ReadLicense) -function(AddLicense licenseName licenseURL licenseFile isNotInTrial) +function(AddLicense licenseName licenseURL licenseFile) ReadLicense(${licenseFile} ${licenseName}_license) set(LICENSES ${LICENSES} PARENT_SCOPE) - set(LICENSE_ARRAY "${LICENSE_ARRAY}\n\tThirdPartyLicense(\"${licenseName}\", \"${licenseURL}\", ${licenseName}_license, ${isNotInTrial})," PARENT_SCOPE) + set(LICENSE_ARRAY "${LICENSE_ARRAY}\n\tThirdPartyLicense(\"${licenseName}\", \"${licenseURL}\", ${licenseName}_license)," PARENT_SCOPE) endfunction(AddLicense) -AddLicense("Qt" "http://qt.io" "${LICENSEFOLDER}/qt_LICENSE.TXT" false) -AddLicense("Clang" "http://clang.llvm.org/" "${LICENSEFOLDER}/clang_LICENSE.TXT" true) -AddLicense("Boost" "http://www.boost.org" "${LICENSEFOLDER}/boost_LICENSE.TXT" false) -AddLicense("TinyXMl" "http://www.grinninglizard.com/tinyxml2/" "${LICENSEFOLDER}/tinyxml_LICENSE.TXT" false) -AddLicense("CppSQLite" "http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper-for-SQLite" "${LICENSEFOLDER}/CppSQLite_LICENSE.TXT" false) -AddLicense("Botan" "http://botan.randombit.net/" "${LICENSEFOLDER}/botan_LICENSE.TXT" true) -AddLicense("Guava" "https://github.com/google/guava" "${LICENSEFOLDER}/guava_LICENSE.TXT" true) -AddLicense("Javaparser" "http://javaparser.org/" "${LICENSEFOLDER}/javaparser_LICENSE.TXT" true) -AddLicense("Javaslang" "http://www.javaslang.io/" "${LICENSEFOLDER}/javaslang_LICENSE.TXT" true) -AddLicense("Javassist" "http://www.javassist.org/" "${LICENSEFOLDER}/javassist_LICENSE.TXT" true) -AddLicense("JavaSymbolSolver" "https://github.com/ftomassetti/java-symbol-solver" "${LICENSEFOLDER}/JavaSymbolSolver_LICENSE.TXT" true) +AddLicense("Qt" "http://qt.io" "${LICENSEFOLDER}/qt_LICENSE.TXT") +AddLicense("Clang" "http://clang.llvm.org/" "${LICENSEFOLDER}/clang_LICENSE.TXT") +AddLicense("Boost" "http://www.boost.org" "${LICENSEFOLDER}/boost_LICENSE.TXT") +AddLicense("TinyXMl" "http://www.grinninglizard.com/tinyxml2/" "${LICENSEFOLDER}/tinyxml_LICENSE.TXT") +AddLicense("CppSQLite" "http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper-for-SQLite" "${LICENSEFOLDER}/CppSQLite_LICENSE.TXT") +AddLicense("Botan" "http://botan.randombit.net/" "${LICENSEFOLDER}/botan_LICENSE.TXT") +AddLicense("Guava" "https://github.com/google/guava" "${LICENSEFOLDER}/guava_LICENSE.TXT") +AddLicense("Javaparser" "http://javaparser.org/" "${LICENSEFOLDER}/javaparser_LICENSE.TXT") +AddLicense("Javaslang" "http://www.javaslang.io/" "${LICENSEFOLDER}/javaslang_LICENSE.TXT") +AddLicense("Javassist" "http://www.javassist.org/" "${LICENSEFOLDER}/javassist_LICENSE.TXT") +AddLicense("JavaSymbolSolver" "https://github.com/ftomassetti/java-symbol-solver" "${LICENSEFOLDER}/JavaSymbolSolver_LICENSE.TXT") set(LICENSE_ARRAY "${LICENSE_ARRAY}\n") diff --git a/cmake/licenses.h.in b/cmake/licenses.h.in index c37c6abd..11fd4af6 100644 --- a/cmake/licenses.h.in +++ b/cmake/licenses.h.in @@ -7,12 +7,23 @@ struct ThirdPartyLicense { const char* name; const char* url; const char* license; - const bool isNotInTrial; - ThirdPartyLicense() : name(0), url(0), license(0), isNotInTrial(false) {} - ThirdPartyLicense(const char* name, const char* url, const char* license, const bool isNotInTrial) - : name(name), url(url), license(license), isNotInTrial(isNotInTrial) {} - bool isEmpty() const { return (name == 0 && url == 0 && license == 0); } + ThirdPartyLicense() + : name(0) + , url(0) + , license(0) + {} + + ThirdPartyLicense(const char* name, const char* url, const char* license) + : name(name) + , url(url) + , license(license) + {} + + bool isEmpty() const + { + return (name == 0 && url == 0 && license == 0); + } }; // License Textfiles diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 0a509dda..7565aa8a 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,6 +1,5 @@ add_files( APP_FILES - isTrial.cpp main.cpp ) diff --git a/src/app/isTrial.cpp b/src/app/isTrial.cpp deleted file mode 100644 index 2fcc5596..00000000 --- a/src/app/isTrial.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "isTrial.h" - -bool isTrial() -{ - return false; -} diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 715ac772..cd799905 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -5,7 +5,6 @@ #include "utility/logging/logging.h" #include "utility/logging/LogManager.h" #include "utility/messaging/MessageQueue.h" -#include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" #include "utility/messaging/type/MessageStatus.h" #include "utility/messaging/type/MessageShowStartScreen.h" #include "utility/scheduling/TaskScheduler.h" @@ -20,7 +19,6 @@ #include "component/view/MainView.h" #include "component/view/ViewFactory.h" #include "data/StorageCache.h" -#include "isTrial.h" #include "LicenseChecker.h" #include "settings/ApplicationSettings.h" #include "settings/ColorScheme.h" @@ -46,10 +44,10 @@ void Application::createInstance( s_instance->m_mainView = viewFactory->createMainView(); s_instance->m_mainView->setTitle("Coati"); - MessageDispatchWhenLicenseValid(std::make_shared()).dispatch(); - s_instance->m_componentManager->setup(s_instance->m_mainView.get()); s_instance->m_mainView->loadLayout(); + + MessageShowStartScreen().dispatch(); } if (networkFactory != nullptr) @@ -107,6 +105,7 @@ std::shared_ptr Application::s_instance; Application::Application(bool withGUI) : m_hasGUI(withGUI) + , m_isInTrial(false) { LicenseChecker::createInstance(); } @@ -151,6 +150,11 @@ void Application::setTitle(const std::string& title) m_mainView->setTitle(title); } +bool Application::isInTrial() const +{ + return m_isInTrial; +} + void Application::createAndLoadProject(const FilePath& projectSettingsFilePath) { MessageStatus("Loading Project: " + projectSettingsFilePath.str(), false, true).dispatch(); @@ -210,6 +214,11 @@ void Application::handleMessage(MessageActivateWindow* message) } } +void Application::handleMessage(MessageEnteredLicense* message) +{ + m_isInTrial = false; +} + void Application::handleMessage(MessageFinishedParsing* message) { m_project->logStats(); diff --git a/src/lib/Application.h b/src/lib/Application.h index a0583f4d..94aea5af 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -6,6 +6,7 @@ #include "component/ComponentManager.h" #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageActivateWindow.h" +#include "utility/messaging/type/MessageEnteredLicense.h" #include "utility/messaging/type/MessageFinishedParsing.h" #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageRefresh.h" @@ -24,6 +25,7 @@ class ProjectFactoryModule; class Application : public MessageListener + , public MessageListener , public MessageListener , public MessageListener , public MessageListener @@ -52,12 +54,15 @@ public: void setTitle(const std::string& title); + bool isInTrial() const; + private: static std::shared_ptr s_instance; Application(bool withGUI=true); virtual void handleMessage(MessageActivateWindow* message); + virtual void handleMessage(MessageEnteredLicense* message); virtual void handleMessage(MessageFinishedParsing* message); virtual void handleMessage(MessageLoadProject* message); virtual void handleMessage(MessageRefresh* message); @@ -78,6 +83,8 @@ private: std::shared_ptr m_componentManager; std::shared_ptr m_ideCommunicationController; + + bool m_isInTrial; }; #endif // APPLICATION_H diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index ff58492f..39737368 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -366,7 +366,6 @@ add_files( Application.cpp Application.h - isTrial.h LicenseChecker.cpp LicenseChecker.h Project.cpp diff --git a/src/lib/LicenseChecker.cpp b/src/lib/LicenseChecker.cpp index d7b03c56..5b41d771 100644 --- a/src/lib/LicenseChecker.cpp +++ b/src/lib/LicenseChecker.cpp @@ -4,7 +4,6 @@ #include "utility/messaging/type/MessageForceEnterLicense.h" #include "utility/messaging/type/MessageStatus.h" -#include "isTrial.h" #include "License.h" #include "PublicKey.h" #include "settings/ApplicationSettings.h" @@ -118,29 +117,26 @@ LicenseChecker::LicenseChecker() void LicenseChecker::handleMessage(MessageDispatchWhenLicenseValid* message) { - if (!isTrial()) + MessageStatus("preparing...", false, true).dispatch(); + + LicenseState state = checkCurrentLicense(); + + MessageStatus("ready").dispatch(); + + if (state == LICENSE_VALID || message->allowTrial) { - MessageStatus("preparing...", false, true).dispatch(); + message->content->dispatch(); + } + else + { + m_pendingMessage = message->content; - LicenseState state = checkCurrentLicense(); - - MessageStatus("ready").dispatch(); - - if (state != LICENSE_VALID) + if (!m_forcedLicenseEntering) { - m_pendingMessage = message->content; - - if (!m_forcedLicenseEntering) - { - m_forcedLicenseEntering = true; - MessageForceEnterLicense(state == LICENSE_EXPIRED).dispatch(); - } - - return; + m_forcedLicenseEntering = true; + MessageForceEnterLicense(state == LICENSE_EXPIRED).dispatch(); } } - - message->content->dispatch(); } void LicenseChecker::handleMessage(MessageEnteredLicense* message) diff --git a/src/lib/LicenseChecker.h b/src/lib/LicenseChecker.h index f3eb320f..12d7a3c0 100644 --- a/src/lib/LicenseChecker.h +++ b/src/lib/LicenseChecker.h @@ -2,8 +2,8 @@ #define LICENSE_CHECKER_H #include "utility/messaging/MessageListener.h" -#include "utility/messaging/type/MessageEnteredLicense.h" #include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" +#include "utility/messaging/type/MessageEnteredLicense.h" class License; diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 3314d973..e978a629 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -28,7 +28,6 @@ #include "Application.h" #include "CxxProject.h" #include "JavaProject.h" -#include "isTrial.h" Project::~Project() { @@ -86,7 +85,7 @@ bool Project::refresh(bool forceRefresh) } } - if (forceRefresh && question.size() && Application::getInstance()->hasGUI() && !isTrial()) + if (forceRefresh && question.size() && Application::getInstance()->hasGUI()) { std::vector options; options.push_back("Yes"); diff --git a/src/lib/isTrial.h b/src/lib/isTrial.h deleted file mode 100644 index e8d280d2..00000000 --- a/src/lib/isTrial.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef IS_TRIAL_H -#define IS_TRIAL_H - -bool isTrial(); - -#endif // IS_TRIAL_H diff --git a/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h b/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h index 381d1199..14961cfc 100644 --- a/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h +++ b/src/lib/utility/messaging/type/MessageDispatchWhenLicenseValid.h @@ -7,8 +7,9 @@ class MessageDispatchWhenLicenseValid : public Message { public: - MessageDispatchWhenLicenseValid(std::shared_ptr content) + MessageDispatchWhenLicenseValid(std::shared_ptr content, bool allowTrial = false) : content(content) + , allowTrial(allowTrial) { } @@ -18,6 +19,7 @@ public: } std::shared_ptr content; + const bool allowTrial; }; #endif // MESSAGE_DISPATCH_WHEN_LICENSE_VALID_H diff --git a/src/lib_gui/qt/element/QtCodeFile.cpp b/src/lib_gui/qt/element/QtCodeFile.cpp index d060be1b..2912b33c 100644 --- a/src/lib_gui/qt/element/QtCodeFile.cpp +++ b/src/lib_gui/qt/element/QtCodeFile.cpp @@ -11,9 +11,9 @@ #include "utility/messaging/type/MessageChangeFileView.h" #include "utility/messaging/type/MessageProjectEdit.h" +#include "Application.h" #include "data/location/TokenLocation.h" #include "data/location/TokenLocationFile.h" -#include "isTrial.h" #include "qt/element/QtCodeNavigator.h" #include "qt/element/QtCodeSnippet.h" #include "qt/utility/utilityQt.h" @@ -144,7 +144,7 @@ QtCodeSnippet* QtCodeFile::addCodeSnippet(const CodeSnippetParams& params) title->setFixedHeight(std::max(title->fontMetrics().height() * 1.2, 28.0)); title->setSizePolicy(title->sizePolicy().horizontalPolicy(), QSizePolicy::Fixed); - if (isTrial()) + if (Application::getInstance()->isInTrial()) { title->setEnabled(false); } @@ -404,7 +404,7 @@ void QtCodeFile::updateSnippets() void QtCodeFile::updateTitleBar() { - if (isTrial()) + if (Application::getInstance()->isInTrial()) { return; } diff --git a/src/lib_gui/qt/element/QtRefreshBar.cpp b/src/lib_gui/qt/element/QtRefreshBar.cpp index 5cc5d2cd..13567a72 100644 --- a/src/lib_gui/qt/element/QtRefreshBar.cpp +++ b/src/lib_gui/qt/element/QtRefreshBar.cpp @@ -10,7 +10,6 @@ #include "qt/utility/utilityQt.h" #include "settings/ApplicationSettings.h" #include "settings/ColorScheme.h" -#include "isTrial.h" QtRefreshBar::QtRefreshBar() { @@ -28,10 +27,7 @@ QtRefreshBar::QtRefreshBar() m_refreshButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac layout->addWidget(m_refreshButton); - if (isTrial()) - { - m_refreshButton->setEnabled(false); - } + m_refreshButton->setEnabled(false); connect(m_refreshButton, SIGNAL(clicked()), this, SLOT(refreshClicked())); @@ -59,3 +55,13 @@ void QtRefreshBar::refreshStyle() ColorScheme::getInstance()->getColor("search/button/icon").c_str() )); } + +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 64fac318..70604690 100644 --- a/src/lib_gui/qt/element/QtRefreshBar.h +++ b/src/lib_gui/qt/element/QtRefreshBar.h @@ -3,10 +3,15 @@ #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 @@ -20,6 +25,10 @@ private slots: void refreshClicked(); private: + virtual void handleMessage(MessageEnteredLicense* message); + + QtThreadedLambdaFunctor m_onQtThread; + QPushButton* m_refreshButton; }; diff --git a/src/lib_gui/qt/view/QtMainView.cpp b/src/lib_gui/qt/view/QtMainView.cpp index fce66c86..42ed224e 100644 --- a/src/lib_gui/qt/view/QtMainView.cpp +++ b/src/lib_gui/qt/view/QtMainView.cpp @@ -144,7 +144,7 @@ void QtMainView::doSetTitle(const std::string& title) void QtMainView::doActivateWindow() { // It's platform dependent which of these commands does the right thing, for now we just use them all at once. - m_window->activateWindow(); + m_window->setEnabled(true); m_window->raise(); m_window->setFocus(Qt::ActiveWindowFocusReason); } diff --git a/src/lib_gui/qt/window/QtAboutLicense.cpp b/src/lib_gui/qt/window/QtAboutLicense.cpp index 77a151f9..6a460225 100644 --- a/src/lib_gui/qt/window/QtAboutLicense.cpp +++ b/src/lib_gui/qt/window/QtAboutLicense.cpp @@ -9,7 +9,6 @@ #include #include "licenses.h" -#include "isTrial.h" QtAboutLicense::QtAboutLicense(QWidget *parent) : QtWindow(parent) @@ -30,30 +29,27 @@ void QtAboutLicense::populateWindow(QWidget* widget) for (ThirdPartyLicense license : licenses3rdParties) { - if( !(isTrial() && license.isNotInTrial) ) - { - QLabel* licenseName = new QLabel(); - licenseName->setText( QString::fromLatin1(license.name)); - QFont _font = licenseName->font(); - _font.setPixelSize(36); - _font.setBold(true); - licenseName->setFont(_font); - layout->addWidget(licenseName); + QLabel* licenseName = new QLabel(); + licenseName->setText( QString::fromLatin1(license.name)); + QFont _font = licenseName->font(); + _font.setPixelSize(36); + _font.setBold(true); + licenseName->setFont(_font); + layout->addWidget(licenseName); - QLabel* licenseURL = new QLabel(); - licenseURL->setText(QString::fromLatin1("(Website)") - .arg(QString::fromLatin1(license.url))); - licenseURL->setOpenExternalLinks(true); - layout->addWidget(licenseURL); + QLabel* licenseURL = new QLabel(); + licenseURL->setText(QString::fromLatin1("(Website)") + .arg(QString::fromLatin1(license.url))); + licenseURL->setOpenExternalLinks(true); + layout->addWidget(licenseURL); - QLabel* licenseText = new QLabel(); - licenseText->setFixedWidth(450); - licenseText->setWordWrap(true); - licenseText->setText(QString::fromLatin1(license.license)); - layout->addWidget(licenseText); + QLabel* licenseText = new QLabel(); + licenseText->setFixedWidth(450); + licenseText->setWordWrap(true); + licenseText->setText(QString::fromLatin1(license.license)); + layout->addWidget(licenseText); - layout->addSpacing(50); - } + layout->addSpacing(50); } widget->setLayout(layout); diff --git a/src/lib_gui/qt/window/QtLicense.cpp b/src/lib_gui/qt/window/QtLicense.cpp index fef01930..9f73aa32 100644 --- a/src/lib_gui/qt/window/QtLicense.cpp +++ b/src/lib_gui/qt/window/QtLicense.cpp @@ -8,12 +8,10 @@ #include "LicenseChecker.h" #include "qt/utility/utilityQt.h" #include "utility/file/FilePath.h" -#include "utility/messaging/type/MessageEnteredLicense.h" #include "utility/ResourcePaths.h" QtLicense::QtLicense(QWidget *parent) : QtWindow(parent) - , m_forced(false) { raise(); } @@ -47,16 +45,9 @@ void QtLicense::load() m_licenseText->setText(licenseString.c_str()); } - m_forced = false; updateCloseButton("Cancel"); } -void QtLicense::loadForced() -{ - m_forced = true; - updateCloseButton("Quit Coati"); -} - void QtLicense::setErrorMessage(const QString& errorMessage) { if (m_errorLabel) @@ -135,18 +126,6 @@ void QtLicense::windowReady() m_title->hide(); } -void QtLicense::handleClose() -{ - if (m_forced) - { - QApplication::quit(); - } - else - { - emit canceled(); - } -} - void QtLicense::handleNext() { std::string licenseString = m_licenseText->toPlainText().toStdString(); @@ -174,9 +153,6 @@ void QtLicense::handleNext() case LicenseChecker::LICENSE_VALID: { checker->saveCurrentLicenseString(licenseString); - MessageEnteredLicense().dispatch(); - - setCancelAble(true); m_errorLabel->setText(" "); emit finished(); diff --git a/src/lib_gui/qt/window/QtLicense.h b/src/lib_gui/qt/window/QtLicense.h index b451cb2e..5d46f8c6 100644 --- a/src/lib_gui/qt/window/QtLicense.h +++ b/src/lib_gui/qt/window/QtLicense.h @@ -18,7 +18,6 @@ public: void clear(); void load(); - void loadForced(); void setErrorMessage(const QString& errorMessage); @@ -28,13 +27,10 @@ protected: virtual void windowReady() override; virtual void handleNext() override; - virtual void handleClose() override; private: QTextEdit* m_licenseText; QLabel* m_errorLabel; - - bool m_forced; }; #endif // QT_LICENSE_H diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index e1fb5386..4edfd73e 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -13,6 +13,7 @@ #include "Application.h" #include "component/view/View.h" #include "component/view/CompositeView.h" +#include "LicenseChecker.h" #include "qt/utility/QtContextMenu.h" #include "qt/utility/utilityQt.h" #include "qt/view/QtViewWidgetWrapper.h" @@ -26,6 +27,7 @@ #include "utility/logging/logging.h" #include "utility/messaging/type/MessageCodeReference.h" #include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" +#include "utility/messaging/type/MessageEnteredLicense.h" #include "utility/messaging/type/MessageFind.h" #include "utility/messaging/type/MessageInterruptTasks.h" #include "utility/messaging/type/MessageLoadProject.h" @@ -40,7 +42,6 @@ #include "utility/tracing.h" #include "utility/UserPaths.h" #include "version.h" -#include "isTrial.h" QtViewToggle::QtViewToggle(View* view, QWidget *parent) : QWidget(parent) @@ -278,16 +279,11 @@ void QtMainWindow::forceEnterLicense(bool expired) { enterLicenseWindow->clear(); } - - enterLicenseWindow->loadForced(); - - this->setEnabled(false); - enterLicenseWindow->setEnabled(true); } bool QtMainWindow::event(QEvent* event) { - if (isEnabled() && event->type() == QEvent::WindowActivate) + if (event->type() == QEvent::WindowActivate) { MessageWindowFocus().dispatch(); } @@ -318,12 +314,6 @@ void QtMainWindow::contextMenuEvent(QContextMenuEvent* event) QtContextMenu::getInstance()->showDefault(event, this); } -void QtMainWindow::activateWindow() -{ - this->setEnabled(true); - m_windowStack.popWindow(); -} - void QtMainWindow::about() { QtAbout* aboutWindow = createWindow(); @@ -358,11 +348,30 @@ void QtMainWindow::enterLicense() enterLicenseWindow->setup(); disconnect(enterLicenseWindow, SIGNAL(finished()), &m_windowStack, SLOT(clearWindows())); - connect(enterLicenseWindow, SIGNAL(finished()), this, SLOT(activateWindow())); + connect(enterLicenseWindow, SIGNAL(finished()), this, SLOT(enteredLicense())); enterLicenseWindow->load(); } +void QtMainWindow::enteredLicense() +{ + bool showStartWindow = false; + if (m_windowStack.getWindowCount() > 0 && dynamic_cast(m_windowStack.getBottomWindow())) + { + showStartWindow = true; + } + + m_windowStack.clearWindows(); + + setTrialActionsEnabled(true); + MessageEnteredLicense().dispatch(); + + if (showStartWindow) + { + showStartScreen(); + } +} + void QtMainWindow::showDataFolder() { QDesktopServices::openUrl(QUrl(("file:///" + UserPaths::getUserDataPath()).c_str(), QUrl::TolerantMode)); @@ -376,10 +385,31 @@ void QtMainWindow::showLogFolder() void QtMainWindow::showStartScreen() { QtStartScreen* startScreen = createWindow(); - startScreen->setupStartScreen(); + + LicenseChecker::LicenseState state = LicenseChecker::getInstance()->checkCurrentLicense(); + bool licenseValid = (state == LicenseChecker::LICENSE_VALID); + + startScreen->setupStartScreen(licenseValid); + setTrialActionsEnabled(licenseValid); + + if (licenseValid) + { + MessageEnteredLicense().dispatch(); + } connect(startScreen, SIGNAL(openOpenProjectDialog()), this, SLOT(openProject())); connect(startScreen, SIGNAL(openNewProjectDialog()), this, SLOT(newProject())); + connect(startScreen, SIGNAL(openEnterLicenseDialog()), this, SLOT(enterLicense())); + + if (state == LicenseChecker::LICENSE_MOVED) + { + ApplicationSettings::getInstance()->setLicenseString(""); + } + + if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_EMPTY) + { + forceEnterLicense(state == LicenseChecker::LICENSE_EXPIRED); + } } void QtMainWindow::hideStartScreen() @@ -411,7 +441,8 @@ void QtMainWindow::openProject(const QString &path) if (!fileName.isEmpty()) { MessageDispatchWhenLicenseValid( - std::make_shared(fileName.toStdString(), false) + std::make_shared(fileName.toStdString(), false), + true ).dispatch(); m_windowStack.clearWindows(); } @@ -551,11 +582,8 @@ void QtMainWindow::setupProjectMenu() QMenu *menu = new QMenu(tr("&Project"), this); menuBar()->addMenu(menu); - if(!isTrial()) - { - menu->addAction(tr("&New Project..."), this, SLOT(newProject()), QKeySequence::New); - menu->addAction(tr("&Open Project..."), this, SLOT(openProject()), QKeySequence::Open); - } + m_trialDisabledActions.push_back(menu->addAction(tr("&New Project..."), this, SLOT(newProject()), QKeySequence::New)); + m_trialDisabledActions.push_back(menu->addAction(tr("&Open Project..."), this, SLOT(openProject()), QKeySequence::Open)); QMenu *recentProjectMenu = new QMenu(tr("Recent Projects")); menu->addMenu(recentProjectMenu); @@ -574,12 +602,8 @@ void QtMainWindow::setupProjectMenu() menu->addSeparator(); - if(!isTrial()) - { - menu->addAction(tr("&Edit Project..."), this, SLOT(editProject())); - - menu->addSeparator(); - } + m_trialDisabledActions.push_back(menu->addAction(tr("&Edit Project..."), this, SLOT(editProject()))); + m_trialDisabledActions.push_back(menu->addSeparator()); menu->addAction(tr("E&xit"), QCoreApplication::instance(), SLOT(quit()), QKeySequence::Quit); } @@ -593,22 +617,21 @@ void QtMainWindow::setupEditMenu() menu->addAction(tr("Forward"), this, SLOT(redo()), QKeySequence::Redo); menu->addSeparator(); - if(!isTrial()) + m_trialDisabledActions.push_back(menu->addAction(tr("&Refresh"), this, SLOT(refresh()), QKeySequence::Refresh)); + if (QSysInfo::windowsVersion() != QSysInfo::WV_None) { - menu->addAction(tr("&Refresh"), this, SLOT(refresh()), QKeySequence::Refresh); - if (QSysInfo::windowsVersion() != QSysInfo::WV_None) - { - menu->addAction(tr("&Force Refresh"), this, SLOT(forceRefresh()), QKeySequence(Qt::SHIFT + Qt::Key_F5)); - } - else - { - menu->addAction( - tr("&Force Refresh"), - this, - SLOT(forceRefresh()), - QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_R) - ); - } + m_trialDisabledActions.push_back( + menu->addAction(tr("&Force Refresh"), this, SLOT(forceRefresh()), QKeySequence(Qt::SHIFT + Qt::Key_F5)) + ); + } + else + { + m_trialDisabledActions.push_back(menu->addAction( + tr("&Force Refresh"), + this, + SLOT(forceRefresh()), + QKeySequence(Qt::SHIFT + Qt::CTRL + Qt::Key_R) + )); } menu->addSeparator(); @@ -661,11 +684,7 @@ void QtMainWindow::setupHelpMenu() menu->addAction(tr("Documentation"), this, SLOT(showDocumentation())); menu->addAction(tr("Bug Tracker"), this, SLOT(showBugtracker())); menu->addAction(tr("Licences"), this, SLOT(showLicenses())); - - if(!isTrial()) - { - menu->addAction(tr("Enter License..."), this, SLOT(enterLicense())); - } + menu->addAction(tr("Enter License..."), this, SLOT(enterLicense())); menu->addSeparator(); @@ -673,6 +692,14 @@ void QtMainWindow::setupHelpMenu() menu->addAction(tr("Show Log Folder"), this, SLOT(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 b8825a17..f9516070 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -93,14 +93,13 @@ protected: void contextMenuEvent(QContextMenuEvent* event); public slots: - void activateWindow(); - void about(); void openSettings(); void showBugtracker(); void showDocumentation(); void showLicenses(); void enterLicense(); + void enteredLicense(); void showDataFolder(); void showLogFolder(); @@ -151,6 +150,8 @@ private: void setupViewMenu(); void setupHelpMenu(); + void setTrialActionsEnabled(bool enabled); + DockWidget* getDockWidgetForView(View* view); void setShowDockWidgetTitleBars(bool showTitleBars); @@ -166,6 +167,8 @@ 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 37f7ddf9..8059324c 100644 --- a/src/lib_gui/qt/window/QtStartScreen.cpp +++ b/src/lib_gui/qt/window/QtStartScreen.cpp @@ -16,7 +16,6 @@ #include "qt/utility/utilityQt.h" #include "utility/logging/logging.h" #include "utility/Version.h" -#include "isTrial.h" QtRecentProjectButton::QtRecentProjectButton(QWidget* parent) : QPushButton(parent) @@ -49,7 +48,8 @@ void QtRecentProjectButton::handleButtonClick() if (m_projectExists) { MessageDispatchWhenLicenseValid( - std::make_shared(m_projectFilePath.str(), false) + std::make_shared(m_projectFilePath.str(), false), + true ).dispatch(); } else @@ -121,7 +121,7 @@ void QtStartScreen::updateButtons() setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "startscreen/startscreen.css").c_str()); } -void QtStartScreen::setupStartScreen() +void QtStartScreen::setupStartScreen(bool unlocked) { setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "startscreen/startscreen.css").c_str()); addLogo(); @@ -135,7 +135,7 @@ void QtStartScreen::setupStartScreen() QVBoxLayout* col = new QVBoxLayout(); layout->addLayout(col, 2); - if (isTrial()) + if (!unlocked) { col->addSpacing(50); @@ -153,6 +153,18 @@ void QtStartScreen::setupStartScreen() col->addWidget(welcomeLabel, 0, Qt::AlignHCenter | Qt::AlignTop); col->addStretch(); + 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, SIGNAL(clicked()), this, SLOT(handleUnlockButton())); + col->addWidget(unlockButton); + + QHBoxLayout* row = new QHBoxLayout(); + row->addWidget(unlockButton); + row->addStretch(); + col->addLayout(row); + layout->addStretch(1); } else @@ -194,7 +206,7 @@ void QtStartScreen::setupStartScreen() layout->addLayout(col, 1); QLabel* recentProjectsLabel = new QLabel("Recent Projects: ", this); - if (isTrial()) + if (!unlocked) { recentProjectsLabel->setText("Projects:"); } @@ -243,6 +255,11 @@ void QtStartScreen::handleOpenProjectButton() emit openOpenProjectDialog(); } +void QtStartScreen::handleUnlockButton() +{ + emit openEnterLicenseDialog(); +} + void QtStartScreen::handleRecentButton() { emit finished(); diff --git a/src/lib_gui/qt/window/QtStartScreen.h b/src/lib_gui/qt/window/QtStartScreen.h index 56d67a32..8a3c27f4 100644 --- a/src/lib_gui/qt/window/QtStartScreen.h +++ b/src/lib_gui/qt/window/QtStartScreen.h @@ -34,15 +34,17 @@ public: QtStartScreen(QWidget* parent = 0); QSize sizeHint() const override; - void setupStartScreen(); + void setupStartScreen(bool unlocked); signals: void openOpenProjectDialog(); void openNewProjectDialog(); + void openEnterLicenseDialog(); private slots: void handleNewProjectButton(); void handleOpenProjectButton(); + void handleUnlockButton(); void handleRecentButton(); void updateButtons(); diff --git a/src/lib_gui/qt/window/QtWindowStack.cpp b/src/lib_gui/qt/window/QtWindowStack.cpp index aabb8d44..900d7820 100644 --- a/src/lib_gui/qt/window/QtWindowStack.cpp +++ b/src/lib_gui/qt/window/QtWindowStack.cpp @@ -21,6 +21,16 @@ QtWindowStackElement* QtWindowStack::getTopWindow() return nullptr; } +QtWindowStackElement* QtWindowStack::getBottomWindow() +{ + if (m_stack.size()) + { + return m_stack.front(); + } + + return nullptr; +} + size_t QtWindowStack::getWindowCount() { return m_stack.size(); diff --git a/src/lib_gui/qt/window/QtWindowStack.h b/src/lib_gui/qt/window/QtWindowStack.h index e92ba0b1..a54fb688 100644 --- a/src/lib_gui/qt/window/QtWindowStack.h +++ b/src/lib_gui/qt/window/QtWindowStack.h @@ -30,6 +30,7 @@ public: QtWindowStack(QObject* parent = nullptr); QtWindowStackElement* getTopWindow(); + QtWindowStackElement* getBottomWindow(); size_t getWindowCount(); public slots: diff --git a/src/lib_java/JavaProject.cpp b/src/lib_java/JavaProject.cpp index 393b12a3..993fe007 100644 --- a/src/lib_java/JavaProject.cpp +++ b/src/lib_java/JavaProject.cpp @@ -10,7 +10,6 @@ #include "utility/ResourcePaths.h" #include "utility/utilityString.h" #include "Application.h" -#include "isTrial.h" JavaProject::JavaProject( std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy, DialogView* dialogView @@ -39,7 +38,7 @@ bool JavaProject::prepareIndexing() m_rootDirectories.reset(); std::string errorString; - if (!JavaEnvironmentFactory::getInstance() && !isTrial()) + if (!JavaEnvironmentFactory::getInstance()) { #ifdef _WIN32 const std::string separator = ";"; @@ -65,7 +64,7 @@ bool JavaProject::prepareIndexing() MessageStatus(errorString, true, false).dispatch(); } - if (!JavaEnvironmentFactory::getInstance() && !isTrial()) + if (!JavaEnvironmentFactory::getInstance()) { std::string dialogMessage = "Coati was unable to locate Java on this machine.\nPlease make sure to provide the correct Java Path in the preferences.";