diff --git a/CMakeLists.txt b/CMakeLists.txt index a475b9f7..feaa94a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ project(${PROJECT_NAME}) if(UNIX AND NOT APPLE) set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib/:$$ORIGIN/lib/") include(cmake/external.cmake) endif() diff --git a/script/build.sh b/script/build.sh index 2f376d6f..4286e221 100755 --- a/script/build.sh +++ b/script/build.sh @@ -12,38 +12,38 @@ then if [ "$2" = "test" ] then #echo "release test" - ninja -C build/Release Coati_test && cd bin/test && Release/Coati_test + cmake --build build/Release --target Coati_test && cd bin/test && Release/Coati_test elif [ "$2" = "trial" ] then - ninja -C build/Release Coati_trial && cd bin/app && Release/Coati_trial + cmake --build build/Release --target Coati_trial && cd bin/app && Release/Coati_trial elif [ "$2" = "keygen" ] then #echo "release keygen" - ninja -C build/Release Coati_license_generator && cd bin/license_generator && Release/Coati_license_generator + cmake --build build/Release --target Coati_license_generator && cd bin/license_generator && Release/Coati_license_generator else #echo "release app" - ninja -C build/Release Coati && cd bin/app && Release/Coati + cmake --build build/Release --target Coati && cd bin/app && Release/Coati fi elif [ "$1" = "debug" ] || [ "$1" = "d" ] then if [ "$2" = "test" ] then #echo "debug test" - ninja -C build/Debug Coati_test && cd bin/test && Debug/Coati_test + cmake --build build/Debug --target Coati_test && cd bin/test && Debug/Coati_test elif [ "$2" = "trial" ] then - ninja -C build/Debug Coati_trial && cd bin/app && Debug/Coati_trial + cmake --build build/Debug --target Coati_trial && cd bin/app && Debug/Coati_trial elif [ "$2" = "keygen" ] then #echo "debug keygen" - ninja -C build/Debug Coati_license_generator && cd bin/license_generator && Debug/Coati_license_generator_d + cmake --build build/Debug --target Coati_license_generator && cd bin/license_generator && Debug/Coati_license_generator_d else #echo "debug app" - ninja -C build/Debug Coati && cd bin/app && Debug/Coati + cmake --build build/Debug --target Coati && cd bin/app && Debug/Coati fi elif [ "$1" = "package" ] || [ "$1" = "p" ] then - ninja package -C build/Release Coati + cmake --target package --build build/Release Coati mkdir -p distr && cp build/Release/Coati*.tar.gz distr #&& cp build/Release/Coati*.deb distr echo "Packages copied into the distr folder" else diff --git a/src/app/main.cpp b/src/app/main.cpp index 54ebe450..7d2f2b7f 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -18,7 +18,21 @@ #include "version.h" #include "settings/ProjectSettings.h" -#include "utility/solution/SolutionParserCompilationDatabase.h" +#include "utility/messaging/MessageListener.h" +#include "utility/messaging/type/MessageFinishedParsing.h" + + +class Quitter : public MessageListener +{ +public: + Quitter(QCoreApplication* app){}; + virtual ~Quitter(){}; +private: + virtual void handleMessage(MessageFinishedParsing* message) + { + QCoreApplication::exit(0); + } +}; void init() { @@ -30,8 +44,6 @@ void init() fileLogger->setLogLevel(Logger::LOG_ALL); FileLogger::setFilePath(UserPaths::getLogPath()); LogManager::getInstance()->addLogger(fileLogger); - - utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); } int main(int argc, char *argv[]) @@ -40,33 +52,52 @@ int main(int argc, char *argv[]) Version version = Version::fromString(GIT_VERSION_NUMBER); QApplication::setApplicationVersion(version.toDisplayString().c_str()); + QCoreApplication* qtApp = new QCoreApplication(argc, argv); setup(argc, argv); - QtApplication qtApp(argc, argv); - - qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps); - - init(); - - QtCommandLineParser commandLineParser; - commandLineParser.setup(); - commandLineParser.process(qtApp); - - QtViewFactory viewFactory; - QtNetworkFactory networkFactory; - - if(AppPath::getAppPath().empty()) + if(AppPath::getAppPath().empty()) { AppPath::setAppPath(QCoreApplication::applicationDirPath().toStdString()); } - LicenseChecker checker; + init(); - std::shared_ptr app = Application::create(version, &viewFactory, &networkFactory); + QtCommandLineParser commandLineParser; + commandLineParser.setup(); + commandLineParser.process(*qtApp); + commandLineParser.evaluateCommandline(); + std::shared_ptr app; - checker.setApp(app.get()); + if(commandLineParser.noGUI()) + { + app = Application::create( version ); + commandLineParser.projectLoad(); - commandLineParser.parseCommandline(); + Quitter quitter(qtApp); + return qtApp->exec(); + } + else + { + // replace the qt app with a gui qt app + // FIXME qtApp to shared_ptr + qtApp->quit(); + delete qtApp; + qtApp = new QtApplication(argc, argv); + qtApp->setAttribute(Qt::AA_UseHighDpiPixmaps); - return qtApp.exec(); + utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); + + QtViewFactory viewFactory; + QtNetworkFactory networkFactory; + + LicenseChecker checker; + + app = Application::create(version, &viewFactory, &networkFactory); + + checker.setApp(app.get()); + + commandLineParser.projectLoad(); + return qtApp->exec(); + } } + diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 18b58133..1c0f94e5 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -50,6 +50,20 @@ std::shared_ptr Application::create( return ptr; } +std::shared_ptr Application::create(const Version& version) +{ + Version::setApplicationVersion(version); + loadSettings(); + + std::shared_ptr ptr(new Application()); + ptr->m_storageCache = std::make_shared(); + + ptr->m_project = Project::create(ptr->m_storageCache.get()); + ptr->startMessagingAndScheduling(); + + return ptr; +} + void Application::loadSettings() { ApplicationSettings::getInstance()->load(FilePath(UserPaths::getAppSettingsPath())); @@ -66,7 +80,10 @@ Application::~Application() { MessageQueue::getInstance()->stopMessageLoop(); TaskScheduler::getInstance()->stopSchedulerLoop(); - m_mainView->saveLayout(); + if(m_mainView) + { + m_mainView->saveLayout(); + } } void Application::loadProject(const FilePath& projectSettingsFilePath) @@ -76,18 +93,20 @@ void Application::loadProject(const FilePath& projectSettingsFilePath) loadSettings(); updateRecentProjects(projectSettingsFilePath); - m_mainView->setTitle( - "Coati - " + - projectSettingsFilePath.fileName()); - - m_storageCache->clear(); - m_componentManager->refreshViews(); + m_storageCache->clear(); m_project = Project::create(m_storageCache.get()); m_project->load(projectSettingsFilePath); - m_mainView->updateRecentProjectMenu(); - m_mainView->hideStartScreen(); + if(m_mainView) + { + m_componentManager->refreshViews(); + m_mainView->setTitle( + "Coati - " + + projectSettingsFilePath.fileName()); + m_mainView->updateRecentProjectMenu(); + m_mainView->hideStartScreen(); + } } void Application::refreshProject() @@ -95,7 +114,10 @@ void Application::refreshProject() MessageStatus("Refreshing Project").dispatch(); m_storageCache->clear(); - m_componentManager->refreshViews(); + if(m_componentManager) + { + m_componentManager->refreshViews(); + } m_project->reload(); } @@ -110,19 +132,27 @@ void Application::saveProject(const FilePath& projectSettingsFilePath) void Application::showLicenseScreen() { - m_mainView->showLicenseScreen(); + if(m_mainView) + { + m_mainView->showLicenseScreen(); + } } void Application::handleMessage(MessageActivateWindow* message) { - m_mainView->activateWindow(); + if(m_mainView) + { + m_mainView->activateWindow(); + } } void Application::handleMessage(MessageFinishedParsing* message) { m_project->logStats(); - - MessageRefresh().refreshUiOnly().dispatch(); + if(m_mainView) + { + MessageRefresh().refreshUiOnly().dispatch(); + } } void Application::handleMessage(MessageLoadProject* message) diff --git a/src/lib/Application.h b/src/lib/Application.h index 9c8be457..7be2bebe 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -28,6 +28,7 @@ class Application { public: static std::shared_ptr create(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory); + static std::shared_ptr create(const Version& version); static void loadSettings(); ~Application(); diff --git a/src/lib_gui/qt/commandline/QtCommandLineParser.cpp b/src/lib_gui/qt/commandline/QtCommandLineParser.cpp index 376efd11..152a6d1c 100644 --- a/src/lib_gui/qt/commandline/QtCommandLineParser.cpp +++ b/src/lib_gui/qt/commandline/QtCommandLineParser.cpp @@ -7,6 +7,8 @@ QtCommandLineParser::QtCommandLineParser() + : m_projectFileString("") + , m_noGUI(false) { } @@ -25,45 +27,72 @@ void QtCommandLineParser::setup() QCoreApplication::translate("main", "Load Coati with the a Coatiprojectfile ."), QCoreApplication::translate("main", "CoatiProject")); addOption(projectOption); + QCommandLineOption parseProjectWithoutGUIOption(QStringList() << "d" << "database", + QCoreApplication::translate("main", "Start coati to parse the Coatiprojectfile . Result *.coatidb"), + QCoreApplication::translate("main", "CoatiProject")); + addOption(parseProjectWithoutGUIOption); } -void QtCommandLineParser::parseCommandline() +void QtCommandLineParser::evaluateCommandline() { + if (isSet("database")) + { + m_noGUI = true; + processProjectfile(value("database").toStdString()); + } if(isSet("project")) { - QString projectfilename = value("project") ; - FilePath projectfile(projectfilename.toStdString()); - bool isValidProjectfile = true; - std::stringstream errorstring("Provided Projectfile is not valid: "); - errorstring << "Provided Projectfile('" << projectfile.fileName() << ") "; - if(!projectfile.exists()) - { - errorstring << "does not exist"; - isValidProjectfile = false; - } - - if(projectfile.extension() != ".coatiproject") - { - errorstring << "has a wrong fileending"; - isValidProjectfile = false; - } - - std::shared_ptr configManager = ConfigManager::createEmpty(); - if(!configManager->load(TextAccess::createFromFile(projectfile.str()))) - { - errorstring << "could not be loaded"; - isValidProjectfile = false; - } - - if(isValidProjectfile) - { - MessageLoadProject(projectfile.str(), false).dispatch(); - } - else - { - MessageStatus(errorstring.str(), true).dispatch(); - LOG_ERROR(errorstring.str()); - } + processProjectfile(value("project").toStdString()); } -} \ No newline at end of file +} + +void QtCommandLineParser::projectLoad() +{ + if (!m_projectFileString.empty()) + { + MessageLoadProject(m_projectFileString, false).dispatch(); + } +} + +void QtCommandLineParser::processProjectfile(const std::string& file) +{ + FilePath projectfile(file); + bool isValidProjectfile = true; + std::stringstream errorstring("Provided Projectfile is not valid: "); + errorstring << "Provided Projectfile('" << projectfile.fileName() << ") "; + if(!projectfile.exists()) + { + errorstring << "does not exist"; + isValidProjectfile = false; + } + + if(projectfile.extension() != ".coatiproject") + { + errorstring << "has a wrong fileending"; + isValidProjectfile = false; + } + + std::shared_ptr configManager = ConfigManager::createEmpty(); + if(!configManager->load(TextAccess::createFromFile(projectfile.str()))) + { + errorstring << "could not be loaded"; + isValidProjectfile = false; + } + + if(isValidProjectfile) + { + m_projectFileString = projectfile.str(); + } + else + { + MessageStatus(errorstring.str(), true).dispatch(); + LOG_ERROR(errorstring.str()); + } +} + +bool QtCommandLineParser::noGUI() +{ + return m_noGUI; +} + diff --git a/src/lib_gui/qt/commandline/QtCommandLineParser.h b/src/lib_gui/qt/commandline/QtCommandLineParser.h index 08cd2f5f..4ef12974 100644 --- a/src/lib_gui/qt/commandline/QtCommandLineParser.h +++ b/src/lib_gui/qt/commandline/QtCommandLineParser.h @@ -1,6 +1,7 @@ #ifndef QTCOMMANDLINEPARSER_H #define QTCOMMANDLINEPARSER_H +#include #include #include "Application.h" @@ -10,10 +11,16 @@ public: QtCommandLineParser(); ~QtCommandLineParser(); void setup(); - void parseCommandline(); + void evaluateCommandline(); + void projectLoad(); + bool noGUI(); private: + std::string m_projectFileString; + bool m_noGUI; + void processProjectfile(const std::string& file); }; #endif //QTCOMMANDLINEPARSER_H + diff --git a/src/lib_gui/qt/window/QtSplashScreen.cpp b/src/lib_gui/qt/window/QtSplashScreen.cpp index bfb5e1d0..1c302c9c 100644 --- a/src/lib_gui/qt/window/QtSplashScreen.cpp +++ b/src/lib_gui/qt/window/QtSplashScreen.cpp @@ -1,6 +1,6 @@ #include "qt/window/QtSplashScreen.h" -#include +#include #include #include @@ -38,7 +38,7 @@ QtSplashScreen::~QtSplashScreen() { } -void QtSplashScreen::exec(QApplication& app) +void QtSplashScreen::exec(QCoreApplication& app) { m_state = 0; QTimer* timer = new QTimer(this); diff --git a/src/lib_gui/qt/window/QtSplashScreen.h b/src/lib_gui/qt/window/QtSplashScreen.h index 7748ed7a..d813507d 100644 --- a/src/lib_gui/qt/window/QtSplashScreen.h +++ b/src/lib_gui/qt/window/QtSplashScreen.h @@ -5,7 +5,7 @@ #include #include -class QApplication; +class QCoreApplication; class QPixmap; class QtSplashScreen @@ -17,7 +17,7 @@ public: QtSplashScreen(const QPixmap& pixmap, Qt::WindowFlags f = 0); virtual ~QtSplashScreen(); - void exec(QApplication& app); + void exec(QCoreApplication& app); void setMessage(const QString& str); void setVersion(const QString& str);