diff --git a/src/app/main.cpp b/src/app/main.cpp index ec62e03b..cbe6c667 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -23,6 +23,7 @@ #include "utility/logging/logging.h" #include "utility/logging/LogManager.h" #include "utility/messaging/type/MessageEnteredLicense.h" +#include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageStatus.h" #include "utility/ResourcePaths.h" #include "utility/ScopedFunctor.h" @@ -123,6 +124,25 @@ void prefillCxxFrameworkPaths() } } +void prefillPaths() +{ + prefillJavaRuntimePath(); + prefillMavenExecutablePath(); + prefillCxxHeaderPaths(); + prefillCxxFrameworkPaths(); +} + +void addLanguageModules() +{ + SourceGroupFactory::getInstance()->addModule(std::make_shared()); + SourceGroupFactory::getInstance()->addModule(std::make_shared()); + SourceGroupFactory::getInstance()->addModule(std::make_shared()); + + IndexerFactory::getInstance()->addModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); + IndexerFactory::getInstance()->addModule(std::make_shared()); +} + int main(int argc, char *argv[]) { QApplication::setApplicationName("Sourcetrail"); @@ -164,18 +184,8 @@ int main(int argc, char *argv[]) Application::destroyInstance(); }); - prefillJavaRuntimePath(); - prefillMavenExecutablePath(); - prefillCxxHeaderPaths(); - prefillCxxFrameworkPaths(); - - SourceGroupFactory::getInstance()->addModule(std::make_shared()); - SourceGroupFactory::getInstance()->addModule(std::make_shared()); - SourceGroupFactory::getInstance()->addModule(std::make_shared()); - - IndexerFactory::getInstance()->addModule(std::make_shared()); - IndexerFactory::getInstance()->addModule(std::make_shared()); - IndexerFactory::getInstance()->addModule(std::make_shared()); + prefillPaths(); + addLanguageModules(); std::shared_ptr checker = LicenseChecker::getInstance(); @@ -202,7 +212,10 @@ int main(int argc, char *argv[]) } else { - commandLineParser.projectLoad(); + MessageLoadProject( + commandLineParser.getProjectFilePath(), + commandLineParser.getFullProjectRefresh() + ).dispatch(); } return qtApp.exec(); } @@ -226,18 +239,11 @@ int main(int argc, char *argv[]) Application::destroyInstance(); }); - prefillJavaRuntimePath(); - prefillMavenExecutablePath(); - prefillCxxHeaderPaths(); - prefillCxxFrameworkPaths(); + prefillPaths(); + addLanguageModules(); - SourceGroupFactory::getInstance()->addModule(std::make_shared()); - SourceGroupFactory::getInstance()->addModule(std::make_shared()); - SourceGroupFactory::getInstance()->addModule(std::make_shared()); - - IndexerFactory::getInstance()->addModule(std::make_shared()); - IndexerFactory::getInstance()->addModule(std::make_shared()); - IndexerFactory::getInstance()->addModule(std::make_shared()); + utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); + utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf"); if (commandLineParser.hasError()) { @@ -245,12 +251,12 @@ int main(int argc, char *argv[]) } else { - commandLineParser.projectLoad(); + MessageLoadProject( + commandLineParser.getProjectFilePath(), + commandLineParser.getFullProjectRefresh() + ).dispatch(); } - utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); - utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".ttf"); - return qtApp.exec(); } } diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 056dc109..08cd1d9a 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -183,13 +183,13 @@ void Application::createAndLoadProject(const FilePath& projectSettingsFilePath) if (m_project) { - m_project->load(); - if (m_hasGUI) { updateTitle(); m_mainView->hideStartScreen(); } + + m_project->load(); } else { diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index c679ac96..e1e1eb51 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -403,7 +403,6 @@ add_files( utility/messaging/type/MessageShowErrors.h utility/messaging/type/MessageShowReference.h utility/messaging/type/MessageShowScope.h - utility/messaging/type/MessageShowStartScreen.h utility/messaging/type/MessageShowStatus.h utility/messaging/type/MessageStatus.h utility/messaging/type/MessageStatusFilterChanged.h diff --git a/src/lib/utility/commandline/CommandLineParser.cpp b/src/lib/utility/commandline/CommandLineParser.cpp index 67ff56da..acbdfe1f 100644 --- a/src/lib/utility/commandline/CommandLineParser.cpp +++ b/src/lib/utility/commandline/CommandLineParser.cpp @@ -5,8 +5,6 @@ #include "boost/program_options.hpp" #include "utility/ConfigManager.h" -#include "utility/messaging/type/MessageLoadProject.h" -#include "utility/messaging/type/MessageShowStartScreen.h" #include "utility/text/TextAccess.h" #include "utility/utilityString.h" #include "License.h" @@ -151,7 +149,7 @@ bool CommandLineParser::startedWithLicense() void CommandLineParser::processProjectfile(const std::string& file) { - FilePath projectfile(file); + FilePath projectfile = FilePath(file).absolute(); const std::string errorstring = "Provided Projectfile is not valid:\n* Provided Projectfile('" + projectfile.fileName() + "') "; if (!projectfile.exists()) @@ -173,21 +171,7 @@ void CommandLineParser::processProjectfile(const std::string& file) return; } - m_projectFile = projectfile.absolute(); -} - -void CommandLineParser::projectLoad() -{ - if (m_projectFile.exists() && - (m_projectFile.extension() == ".srctrlprj" || m_projectFile.extension() == ".coatiproject")) - { - MessageLoadProject(m_projectFile, m_force).dispatch(); - } - else - { - MessageShowStartScreen().dispatch(); - } - + m_projectFile = projectfile; } License CommandLineParser::getLicense() @@ -195,3 +179,12 @@ License CommandLineParser::getLicense() return m_license; } +const FilePath& CommandLineParser::getProjectFilePath() const +{ + return m_projectFile; +} + +bool CommandLineParser::getFullProjectRefresh() const +{ + return m_force; +} diff --git a/src/lib/utility/commandline/CommandLineParser.h b/src/lib/utility/commandline/CommandLineParser.h index a8301b56..2f03b7b8 100644 --- a/src/lib/utility/commandline/CommandLineParser.h +++ b/src/lib/utility/commandline/CommandLineParser.h @@ -13,11 +13,15 @@ public: bool runWithoutGUI(); bool exitApplication(); - void projectLoad(); bool startedWithLicense(); bool hasError(); + std::string getError(); License getLicense(); + + const FilePath& getProjectFilePath() const; + bool getFullProjectRefresh() const; + private: void processProjectfile(const std::string& file); void processLicense(const bool isLoaded); diff --git a/src/lib/utility/messaging/type/MessageShowStartScreen.h b/src/lib/utility/messaging/type/MessageShowStartScreen.h deleted file mode 100644 index a0449829..00000000 --- a/src/lib/utility/messaging/type/MessageShowStartScreen.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MESSAGE_SHOW_START_SCREEN_H -#define MESSAGE_SHOW_START_SCREEN_H - -#include "utility/messaging/Message.h" - -class MessageShowStartScreen - : public Message -{ -public: - MessageShowStartScreen() - { - } - - static const std::string getStaticType() - { - return "MessageShowStartScreen"; - } -}; - -#endif // MESSAGE_SHOW_START_SCREEN_H diff --git a/src/lib_gui/qt/view/QtMainView.cpp b/src/lib_gui/qt/view/QtMainView.cpp index b4639e92..2f803a5e 100644 --- a/src/lib_gui/qt/view/QtMainView.cpp +++ b/src/lib_gui/qt/view/QtMainView.cpp @@ -150,6 +150,18 @@ void QtMainView::handleMessage(MessageForceEnterLicense* message) ); } +void QtMainView::handleMessage(MessageLoadProject* message) +{ + bool showStartWindow = message->projectSettingsFilePath.empty(); + + m_onQtThread( + [=]() + { + m_window->loadWindow(showStartWindow); + } + ); +} + void QtMainView::handleMessage(MessageProjectEdit* message) { m_onQtThread( @@ -172,13 +184,3 @@ void QtMainView::handleMessage(MessageProjectNew* message) } ); } - -void QtMainView::handleMessage(MessageShowStartScreen* message) -{ - m_onQtThread( - [=]() - { - m_window->showStartScreen(); - } - ); -} diff --git a/src/lib_gui/qt/view/QtMainView.h b/src/lib_gui/qt/view/QtMainView.h index 46ba4fb7..9dddec8b 100644 --- a/src/lib_gui/qt/view/QtMainView.h +++ b/src/lib_gui/qt/view/QtMainView.h @@ -11,9 +11,9 @@ #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageForceEnterLicense.h" +#include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageProjectEdit.h" #include "utility/messaging/type/MessageProjectNew.h" -#include "utility/messaging/type/MessageShowStartScreen.h" class QtMainWindow; class View; @@ -21,9 +21,9 @@ class View; class QtMainView : public MainView , public MessageListener + , public MessageListener , public MessageListener , public MessageListener - , public MessageListener { public: QtMainView(); @@ -55,9 +55,9 @@ public: private: void handleMessage(MessageForceEnterLicense* message); + void handleMessage(MessageLoadProject* message); void handleMessage(MessageProjectEdit* message); void handleMessage(MessageProjectNew* message); - void handleMessage(MessageShowStartScreen* message); std::shared_ptr m_window; std::vector m_views; diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index d26f2773..d3a2f6ce 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -99,7 +99,8 @@ bool MouseReleaseFilter::eventFilter(QObject* obj, QEvent* event) QtMainWindow::QtMainWindow() - : m_historyMenu(nullptr) + : m_loaded(false) + , m_historyMenu(nullptr) , m_bookmarksMenu(nullptr) , m_showDockWidgetTitleBars(true) , m_windowStack(this) @@ -224,7 +225,48 @@ void QtMainWindow::loadDockWidgetLayout() { dock.action->setChecked(!dock.widget->isHidden()); } +} +void QtMainWindow::loadWindow(bool showStartWindow) +{ + if (m_loaded) + { + return; + } + + m_loaded = true; + + LicenseChecker::LicenseState state = LicenseChecker::getInstance()->checkCurrentLicense(); + bool licenseValid = (state == LicenseChecker::LICENSE_VALID); + + if (licenseValid) + { + MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch(); + } + + setTrialActionsEnabled(licenseValid); + + if (state == LicenseChecker::LICENSE_MOVED) + { + ApplicationSettings::getInstance()->setLicenseString(""); + } + + if (showStartWindow) + { + showStartScreen(); + } + + if (state != LicenseChecker::LICENSE_VALID && state != LicenseChecker::LICENSE_EMPTY) + { + forceEnterLicense(state == LicenseChecker::LICENSE_EXPIRED); + } + +#ifndef Q_OS_WIN + if (ApplicationSettings::getInstance()->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION) + { + showEula(true); + } +#endif } void QtMainWindow::saveLayout() @@ -446,41 +488,17 @@ void QtMainWindow::showLogFolder() void QtMainWindow::showStartScreen() { - LicenseChecker::LicenseState state = LicenseChecker::getInstance()->checkCurrentLicense(); - bool licenseValid = (state == LicenseChecker::LICENSE_VALID); - - if (licenseValid) + if (dynamic_cast(m_windowStack.getTopWindow())) { - MessageEnteredLicense(LicenseChecker::getInstance()->getCurrentLicenseType()).dispatch(); + return; } - setTrialActionsEnabled(licenseValid); - - if (state == LicenseChecker::LICENSE_MOVED) - { - ApplicationSettings::getInstance()->setLicenseString(""); - } - - QtStartScreen* startScreen = createWindow(); - startScreen->setupStartScreen(licenseValid); + startScreen->setupStartScreen(); 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_VALID && state != LicenseChecker::LICENSE_EMPTY) - { - forceEnterLicense(state == LicenseChecker::LICENSE_EXPIRED); - } - -#ifndef Q_OS_WIN - if (ApplicationSettings::getInstance()->getAcceptedEulaVersion() < QtEulaWindow::EULA_VERSION) - { - showEula(true); - } -#endif - } void QtMainWindow::hideStartScreen() @@ -769,6 +787,8 @@ void QtMainWindow::setupViewMenu() QMenu *menu = new QMenu(tr("&View"), this); menuBar()->addMenu(menu); + menu->addAction(tr("Show Start Window"), this, SLOT(showStartScreen())); + m_showTitleBarsAction = new QAction("Show Title Bars", this); m_showTitleBarsAction->setCheckable(true); m_showTitleBarsAction->setChecked(m_showDockWidgetTitleBars); diff --git a/src/lib_gui/qt/window/QtMainWindow.h b/src/lib_gui/qt/window/QtMainWindow.h index 2a8bc9ed..53fb55f4 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -67,6 +67,7 @@ public: void saveLayout(); void loadDockWidgetLayout(); + void loadWindow(bool showStartWindow); void forceEnterLicense(bool expired); @@ -163,6 +164,9 @@ private: T* createWindow(); std::vector m_dockWidgets; + + bool m_loaded; + QMenu* m_viewMenu; QAction* m_viewSeparator; diff --git a/src/lib_gui/qt/window/QtStartScreen.cpp b/src/lib_gui/qt/window/QtStartScreen.cpp index c066a2a8..c47669de 100644 --- a/src/lib_gui/qt/window/QtStartScreen.cpp +++ b/src/lib_gui/qt/window/QtStartScreen.cpp @@ -14,6 +14,7 @@ #include "qt/utility/utilityQt.h" #include "utility/Version.h" #include "License.h" +#include "PublicKey.h" #include "utility/AppPath.h" QtRecentProjectButton::QtRecentProjectButton(QWidget* parent) @@ -138,8 +139,13 @@ size_t i = 0; setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("startscreen/startscreen.css"))).c_str()); } -void QtStartScreen::setupStartScreen(bool unlocked) +void QtStartScreen::setupStartScreen() { + License license; + license.loadFromEncodedString(ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath()); + license.loadPublicKeyFromString(PUBLIC_KEY); + bool licenseValid = license.isValid(); + setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("startscreen/startscreen.css"))).c_str()); addLogo(); @@ -152,7 +158,7 @@ void QtStartScreen::setupStartScreen(bool unlocked) QVBoxLayout* col = new QVBoxLayout(); layout->addLayout(col, 2); - if (!unlocked) + if (!licenseValid) { col->addSpacing(4); @@ -207,19 +213,15 @@ void QtStartScreen::setupStartScreen(bool unlocked) col->addSpacing(20); - License license; - license.loadFromEncodedString( - ApplicationSettings::getInstance()->getLicenseString(), AppPath::getAppPath()); + std::string licenseString = license.getLicenseInfo(); - std::string licenseString = license.getLicenseInfo(); - - QLabel* licenseHeader = new QLabel("Licensed to:"); - licenseHeader->setObjectName("licenseHeaderLabel"); - col->addWidget(licenseHeader); - col->addSpacing(2); + QLabel* licenseHeader = new QLabel("Licensed to:"); + licenseHeader->setObjectName("licenseHeaderLabel"); + col->addWidget(licenseHeader); + col->addSpacing(2); QLabel* licenseLabel = new QLabel(licenseString.c_str()); - licenseLabel->setObjectName("licenseLabel"); - col->addWidget(licenseLabel); + licenseLabel->setObjectName("licenseLabel"); + col->addWidget(licenseLabel); col->addStretch(); @@ -248,7 +250,7 @@ void QtStartScreen::setupStartScreen(bool unlocked) layout->addLayout(col, 1); QLabel* recentProjectsLabel = new QLabel("Recent Projects: ", this); - if (!unlocked) + if (!licenseValid) { recentProjectsLabel->setText("Projects:"); } diff --git a/src/lib_gui/qt/window/QtStartScreen.h b/src/lib_gui/qt/window/QtStartScreen.h index 8db8a8f5..642807eb 100644 --- a/src/lib_gui/qt/window/QtStartScreen.h +++ b/src/lib_gui/qt/window/QtStartScreen.h @@ -34,7 +34,7 @@ public: QtStartScreen(QWidget* parent = 0); QSize sizeHint() const override; - void setupStartScreen(bool unlocked); + void setupStartScreen(); signals: void openOpenProjectDialog();