diff --git a/cmake/LinuxPackage.cmake b/cmake/LinuxPackage.cmake index a308c6c5..972e1b58 100644 --- a/cmake/LinuxPackage.cmake +++ b/cmake/LinuxPackage.cmake @@ -98,48 +98,52 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) # Add shared files to full and trial version -AddSharedToComponent(FULLVERSION) -AddSharedToComponent(TRIALVERSION) +AddSharedToComponent(FULL) +AddSharedToComponent(TRIAL) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/ide_plugins/sublime_text DESTINATION plugin - COMPONENT FULLVERSION + COMPONENT FULL ) INSTALL(FILES ${CMAKE_SOURCE_DIR}/setup/Linux/coati.desktop - ${CMAKE_SOURCE_DIR}/setup/Linux/application-x-coati.xml + ${CMAKE_SOURCE_DIR}/setup/Linux/coati-mime.xml DESTINATION setup - COMPONENT FULLVERSION + COMPONENT FULL ) - INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/setup/Linux/install.sh ${CMAKE_SOURCE_DIR}/setup/Linux/deinstall.sh ${CMAKE_SOURCE_DIR}/setup/Linux/removeConfigs.sh + DESTINATION setup + COMPONENT FULL +) + +INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/setup/Linux/Coati_trial.sh DESTINATION . - COMPONENT TRIALVERSION + COMPONENT TRIAL ) INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/setup/Linux/Coati.sh DESTINATION . - COMPONENT FULLVERSION + COMPONENT FULL ) INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/bin/app/Release/Coati_upx DESTINATION . - COMPONENT FULLVERSION + COMPONENT FULL RENAME Coati ) INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/bin/app/Release/Coati_trial_upx DESTINATION . - COMPONENT TRIALVERSION + COMPONENT TRIAL RENAME Coati_trial ) @@ -150,7 +154,15 @@ SET(CPACK_ARCHIVE_COMPONENT_INSTALL "ON") string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_VERSION_NUMBER}") string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_VERSION_NUMBER}") string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_VERSION_NUMBER}") -set(VERSION_NUMBER "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_PATCH}") +if(${GIT_VERSION_NUMBER} STREQUAL ${VERSION_PATCH}) + SET(VERSIONA_PATCH 0) +endif() +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_VERSION_NUMBER}") +if(${GIT_VERSION_NUMBER} STREQUAL ${VERSION_COMMIT}) + set(VERSION_NUMBER "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_PATCH}") +else() + set(VERSION_NUMBER "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_PATCH}_${VERSION_COMMIT}") +endif() SET(CPACK_PACKAGE_NAME "Coati") SET(CPACK_PACKAGING_INSTALL_PREFIX "") @@ -159,8 +171,10 @@ SET(CPACK_PACKAGE_VERSION ${VERSION_NUMBER}) SET(CPACK_PACKAGE_VENDOR "Coati Software") SET(CPACK_INSTALL_SCRIPT "${CMAKE_SOURCE_DIR}/cmake/pre_install_linux.cmake") SET(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR}") +SET(CPACK_PACKAGE_FILE_NAME "Coati_${VERSION_NUMBER}_${CPACK_SYSTEM_NAME}") #SET(CPACK_PACKAGE_EXECUTABLES "Coati") SET(CPACK_STRIP_FILES "coati/Coati") SET(CPACK_PACKAGE_CONTACT "astallinger@coati.io") INCLUDE(CPack) + diff --git a/setup/Linux/Coati.sh b/setup/Linux/Coati.sh index d2ed7b9a..6c9a69f8 100755 --- a/setup/Linux/Coati.sh +++ b/setup/Linux/Coati.sh @@ -10,7 +10,6 @@ done COATI_PATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" #setup data folder -echo $COATI_PATH if [ ! -d "${HOME}/.config/coati" ]; then # Control will enter here if $DIRECTORY doesn't exist. mkdir ${HOME}/.config/coati @@ -21,4 +20,4 @@ fi export LD_LIBRARY_PATH="$COATI_PATH/lib:LD_LIBRARY_PATH" export QT_XKB_CONFIG_ROOT="/usr/share/X11/xkb:$QT_XKB_CONFIG_ROOT" export QT_QPA_FONTDIR="$COATI_PATH/data/fonts:$QT_QPA_FONTDIR" -exec $COATI_PATH/Coati +exec $COATI_PATH/Coati $@ diff --git a/setup/Linux/application-x-coati.xml b/setup/Linux/coati-mime.xml similarity index 100% rename from setup/Linux/application-x-coati.xml rename to setup/Linux/coati-mime.xml diff --git a/setup/Linux/deinstall.sh b/setup/Linux/deinstall.sh index 34478e43..9f7de119 100755 --- a/setup/Linux/deinstall.sh +++ b/setup/Linux/deinstall.sh @@ -10,9 +10,10 @@ case ${ans:=y} in [yY]*) ;; *) exit ;; esac echo "Run this script as root" rm /usr/bin/Coati -rm /usr/share/mime/packages/application-x-coatiproject +rm /usr/share/mime/packages/coati-mime.xml rm /usr/share/applications/coati.desktop rm /usr/share/icons/coati.png rm /usr/share/icons/project-coati.png +rm /opt/coati -rf update-mime/database /usr/share/mime diff --git a/setup/Linux/install.sh b/setup/Linux/install.sh index c40ed9d0..d6622ec9 100755 --- a/setup/Linux/install.sh +++ b/setup/Linux/install.sh @@ -2,7 +2,7 @@ MY_PATH=`dirname "$0"` MY_PATH=../$MY_PATH -cat EULA.txt +cat ../EULA.txt echo "Agree to the EULA" printf 'enter [y/n] ' read ans @@ -10,10 +10,12 @@ case ${ans:=y} in [yY]*) ;; *) exit ;; esac echo "Run this script as root" -ln -s $MY_PATH/Coati.sh /usr/bin/Coati -cp $MY_PATH/setup/application-x-coatiproject /usr/share/mime/packages -cp $MY_PATH/setup/coati.desktop /usr/share/applications/ -cp $MY_PATH/data/gui/icon/logo_1024_1024.png /usr/share/icon/coati.png -cp $MY_PATH/data/gui/icon/project_256_256.png /usr/share/icons/project-coati.png -update-mime-database /usr/share/mime +cp -rf $MY_PATH/ /opt/coati/ > /dev/null +cp $MY_PATH/setup/coati-mime.xml /usr/share/mime/packages > /dev/null +cp $MY_PATH/setup/coati.desktop /usr/share/applications/ > /dev/null +cp $MY_PATH/data/gui/icon/logo_1024_1024.png /usr/share/icons/coati.png > /dev/null +cp $MY_PATH/data/gui/icon/project_256_256.png /usr/share/icons/project-coati.png > /dev/null +update-mime-database /usr/share/mime > /dev/null + +ln -s /opt/coati/coati.sh /usr/bin/coati > /dev/null diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 43f7f055..907787cb 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -3,6 +3,9 @@ add_files( data/parser/cxx/TaskParseCxx.cpp + utility/commandline/CommandLineParser.cpp + utility/commandline/CommandLineParser.h + isTrial.cpp LicenseChecker.h main.cpp diff --git a/src/app/LicenseChecker.h b/src/app/LicenseChecker.h index 8ea1ba51..f5d05d3e 100644 --- a/src/app/LicenseChecker.h +++ b/src/app/LicenseChecker.h @@ -8,6 +8,7 @@ #include "utility/messaging/type/MessageProjectNew.h" #include "utility/messaging/type/MessageStatus.h" +#include "Application.h" #include "License.h" #include "PublicKey.h" #include "settings/ApplicationSettings.h" diff --git a/src/app/main.cpp b/src/app/main.cpp index a4f66f44..045bb00e 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,4 +1,5 @@ #include "utility/AppPath.h" +#include "utility/commandline/CommandLineParser.h" #include "utility/logging/ConsoleLogger.h" #include "utility/logging/FileLogger.h" #include "utility/logging/LogManager.h" @@ -9,9 +10,9 @@ #include "Application.h" #include "includes.h" // defines 'void setup(int argc, char *argv[])' #include "LicenseChecker.h" -#include "qt/commandline/QtCommandLineParser.h" #include "qt/network/QtNetworkFactory.h" #include "qt/QtApplication.h" +#include "qt/QtCoreApplication.h" #include "qt/utility/utilityQt.h" #include "qt/view/QtViewFactory.h" #include "qt/window/QtMainWindow.h" @@ -30,8 +31,17 @@ void init() fileLogger->setLogLevel(Logger::LOG_ALL); FileLogger::setFilePath(UserPaths::getLogPath()); LogManager::getInstance()->addLogger(fileLogger); +} - utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); +void prepare(int argc, char *argv[]) +{ + if (AppPath::getAppPath().empty()) + { + AppPath::setAppPath(QCoreApplication::applicationDirPath().toStdString() + "/"); + } + setup(argc, argv); + + init(); } int main(int argc, char *argv[]) @@ -41,31 +51,49 @@ int main(int argc, char *argv[]) Version version = Version::fromString(GIT_VERSION_NUMBER); QApplication::setApplicationVersion(version.toDisplayString().c_str()); - QtApplication qtApp(argc, argv); - if(AppPath::getAppPath().empty()) + CommandLineParser commandLineParser(argc, argv, version.toString()); + if (commandLineParser.exitApplication()) { - AppPath::setAppPath(QCoreApplication::applicationDirPath().toStdString()); + return 0; } - setup(argc, argv); - qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps); + if (commandLineParser.runWithoutGUI()) + { + // headless Coati + QtCoreApplication qtApp(argc, argv); + prepare(argc,argv); - init(); + std::shared_ptr app = Application::create( version ); - QtCommandLineParser commandLineParser; - commandLineParser.setup(); - commandLineParser.process(qtApp); + if (commandLineParser.startedWithLicense()) + { + qtApp.saveLicense(commandLineParser.getLicense()); + return 0; + } - QtViewFactory viewFactory; - QtNetworkFactory networkFactory; + commandLineParser.projectLoad(); - LicenseChecker checker; + return qtApp.exec(); + } + else + { + QtApplication qtApp(argc, argv); + prepare(argc,argv); + qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps); - std::shared_ptr app = Application::create(version, &viewFactory, &networkFactory); + QtViewFactory viewFactory; + QtNetworkFactory networkFactory; - checker.setApp(app.get()); + LicenseChecker checker; - commandLineParser.parseCommandline(); + utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); + std::shared_ptr app = Application::create(version, &viewFactory, &networkFactory); - return qtApp.exec(); + checker.setApp(app.get()); + + commandLineParser.projectLoad(); + + return qtApp.exec(); + } } + diff --git a/src/app/utility/commandline/CommandLineParser.cpp b/src/app/utility/commandline/CommandLineParser.cpp new file mode 100644 index 00000000..d22cb532 --- /dev/null +++ b/src/app/utility/commandline/CommandLineParser.cpp @@ -0,0 +1,186 @@ +#include "utility/commandline/CommandLineParser.h" + +#include "boost/program_options.hpp" + +#include "License.h" +#include "PublicKey.h" +#include "utility/ConfigManager.h" +#include "utility/file/FileSystem.h" +#include "utility/messaging/type/MessageLoadProject.h" +#include "utility/messaging/type/MessageStatus.h" +#include "utility/text/TextAccess.h" + +namespace po = boost::program_options; + +CommandLineParser::CommandLineParser(int argc, char** argv, const std::string& version) + : m_withoutGUI(false) + , m_quit(false) + , m_withLicense(false) + , m_force(false) +{ + std::string projectfile; + std::string projectfile_db; + std::string licensefile; + std::string licensetext; + po::options_description desc("Coati"); + desc.add_options() + ("help,h", "Print this help message") + ("version,v", "Version of Coati") + ("project,p", "Load Coati with a Coatiprojectfile") + ; + po::positional_options_description positionalOption; + positionalOption.add("project-file", 1); + + po::options_description hidden_desc("hidden commandlineflags"); + hidden_desc.add_options() + ("force,f", "Force coati to parse if database exists") + ("licenseFile,z", po::value(&licensefile), "Enter license via Licensefile") + ("license,l", po::value(&licensetext), "Enter licenes via commandline") + ("hidden", "Print this help message with hidden arguments") + ("database,d", "Start coati to parse a Coati projectfile to get a coatidatabase") + ("project-file", po::value(&projectfile), "Coati project file"); + ; + po::options_description all("Allowed options"); + all.add(desc).add(hidden_desc); + + po::variables_map vm; + po::store(po::command_line_parser(argc,argv).options(all).positional(positionalOption).run(), vm); + po::notify(vm); + + if (vm.count("help")) + { + std::cout << desc << std::endl; + m_quit = true; + } + + if (vm.count("hidden")) + { + std::cout << all << std::endl; + m_quit = true; + } + + if (vm.count("force")) + { + m_force = true; + } + + if (vm.count("license")) + { + processLicense(m_license.loadFromString(licensetext)); + } + + if (vm.count("licenseFile")) + { + std::cout << "licensefile flag" << std::endl; + if (FileSystem::exists(licensefile)) + { + std::cout << "licensefile exists" << std::endl; + processLicense(m_license.loadFromFile(licensefile)); + } + else + { + std::cout << licensefile << " not found" << std::endl; + } + } + + if (vm.count("version")) + { + std::cout << "Coati Version " << version << std::endl; + m_quit = true; + } + + if (vm.count("project-file")) + { + processProjectfile(projectfile); + if (vm.count("database")) + { + m_withoutGUI = true; + } + } + else if (vm.count("database") || vm.count("project") ) { + std::cout << "A project file is needed for this option" << std::endl; + } +} + +void CommandLineParser::processLicense(const bool isLoaded) +{ + if (!isLoaded) + { + std::cout << "Could not load License" << std::endl; + } + m_license.loadPublicKeyFromString(PublicKey); + if (!m_license.isValid()) + { + std::cout << "License is not valid" << std::endl; + } + m_withLicense = true; + m_withoutGUI = true; +} + +CommandLineParser::~CommandLineParser() +{ +} + +bool CommandLineParser::runWithoutGUI() +{ + return m_withoutGUI; +} + +bool CommandLineParser::exitApplication() +{ + return m_quit; +} + +bool CommandLineParser::startedWithLicense() +{ + return m_withLicense; +} + +void CommandLineParser::processProjectfile(const std::string& file) +{ + FilePath projectfile(file); + bool isValidProjectfile = true; + std::string errorstring = "Provided Projectfile is not valid:\n"; + std::string errorProjectfile = "\tProvided Projectfile('" + projectfile.fileName() + ") "; + if (!projectfile.exists()) + { + errorstring += errorProjectfile + " does not exist\n"; + isValidProjectfile = false; + } + + if (projectfile.extension() != ".coatiproject") + { + errorstring += errorProjectfile + " has a wrong fileending\n"; + isValidProjectfile = false; + } + + std::shared_ptr configManager = ConfigManager::createEmpty(); + if (!configManager->load(TextAccess::createFromFile(projectfile.str()))) + { + errorstring += errorProjectfile + " could not be loaded\n"; + isValidProjectfile = false; + } + + if (isValidProjectfile) + { + m_projectFile = projectfile.absolute().str(); + } + else + { + std::cout << errorstring << std::endl; + } +} + +void CommandLineParser::projectLoad() +{ + if (!m_projectFile.empty()) + { + MessageLoadProject(m_projectFile, m_force).dispatch(); + } +} + +License CommandLineParser::getLicense() +{ + return m_license; +} + diff --git a/src/app/utility/commandline/CommandLineParser.h b/src/app/utility/commandline/CommandLineParser.h new file mode 100644 index 00000000..16a322aa --- /dev/null +++ b/src/app/utility/commandline/CommandLineParser.h @@ -0,0 +1,30 @@ +#ifndef COMMANDLINEPARSER_H +#define COMMANDLINEPARSER_H + +#include +#include "Application.h" +#include "License.h" + +class CommandLineParser +{ +public: + CommandLineParser(int argc, char** argv, const std::string& version); + ~CommandLineParser(); + + bool runWithoutGUI(); + bool exitApplication(); + void projectLoad(); + bool startedWithLicense(); + License getLicense(); +private: + void processProjectfile(const std::string& file); + void processLicense(const bool isLoaded); + std::string m_projectFile; + bool m_withoutGUI; + bool m_quit; + bool m_force; + bool m_withLicense; + License m_license; +}; + +#endif //COMMANDLINEPARSER_H diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index a1328ca2..9c74105c 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -50,15 +50,31 @@ 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(false)); + + 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())); - ColorScheme::getInstance()->load(ApplicationSettings::getInstance()->getColorSchemePath()); + ColorScheme::getInstance()->load(ApplicationSettings::getInstance()->getColorSchemePath()); GraphViewStyle::loadStyleSettings(); } -Application::Application() +Application::Application(bool withGUI) + : m_hasGUI(withGUI) { } @@ -66,7 +82,15 @@ Application::~Application() { MessageQueue::getInstance()->stopMessageLoop(); TaskScheduler::getInstance()->stopSchedulerLoop(); - m_mainView->saveLayout(); + if (m_hasGUI) + { + m_mainView->saveLayout(); + } +} + +bool Application::hasGUI() +{ + return m_hasGUI; } void Application::loadProject(const FilePath& projectSettingsFilePath) @@ -76,18 +100,21 @@ void Application::loadProject(const FilePath& projectSettingsFilePath) loadSettings(); updateRecentProjects(projectSettingsFilePath); - m_mainView->setTitle( - "Coati - " + - projectSettingsFilePath.fileName()); - m_storageCache->clear(); - m_componentManager->refreshViews(); m_project = Project::create(m_storageCache.get()); m_project->load(projectSettingsFilePath); - m_mainView->updateRecentProjectMenu(); - m_mainView->hideStartScreen(); + if (m_hasGUI) + { + m_mainView->setTitle( + "Coati - " + + projectSettingsFilePath.fileName()); + + m_mainView->updateRecentProjectMenu(); + m_mainView->hideStartScreen(); + m_componentManager->refreshViews(); + } } void Application::refreshProject() @@ -95,7 +122,10 @@ void Application::refreshProject() MessageStatus("Refreshing Project").dispatch(); m_storageCache->clear(); - m_componentManager->refreshViews(); + if (m_hasGUI) + { + m_componentManager->refreshViews(); + } m_project->reload(); } @@ -110,19 +140,27 @@ void Application::saveProject(const FilePath& projectSettingsFilePath) void Application::showLicenseScreen() { - m_mainView->showLicenseScreen(); + if (m_hasGUI) + { + m_mainView->showLicenseScreen(); + } } void Application::handleMessage(MessageActivateWindow* message) { - m_mainView->activateWindow(); + if (m_hasGUI) + { + m_mainView->activateWindow(); + } } void Application::handleMessage(MessageFinishedParsing* message) { m_project->logStats(); - - MessageRefresh().refreshUiOnly().dispatch(); + if (m_hasGUI) + { + MessageRefresh().refreshUiOnly().dispatch(); + } } void Application::handleMessage(MessageLoadProject* message) @@ -180,23 +218,26 @@ void Application::startMessagingAndScheduling() void Application::updateRecentProjects(const FilePath& projectSettingsFilePath) { - ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - std::vector recentProjects = appSettings->getRecentProjects(); - if (recentProjects.size()) + if (m_hasGUI) { - std::vector::iterator it = std::find(recentProjects.begin(), recentProjects.end(), projectSettingsFilePath); - if (it != recentProjects.end()) + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + std::vector recentProjects = appSettings->getRecentProjects(); + if (recentProjects.size()) { - recentProjects.erase(it); + std::vector::iterator it = std::find(recentProjects.begin(), recentProjects.end(), projectSettingsFilePath); + if (it != recentProjects.end()) + { + recentProjects.erase(it); + } } - } - recentProjects.insert(recentProjects.begin(), projectSettingsFilePath); - if (recentProjects.size() > 7) - { - recentProjects.pop_back(); - } + recentProjects.insert(recentProjects.begin(), projectSettingsFilePath); + if (recentProjects.size() > 7) + { + recentProjects.pop_back(); + } - appSettings->setRecentProjects(recentProjects); - appSettings->save(UserPaths::getAppSettingsPath()); + appSettings->setRecentProjects(recentProjects); + appSettings->save(UserPaths::getAppSettingsPath()); + } } diff --git a/src/lib/Application.h b/src/lib/Application.h index 9c8be457..7e9423ed 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(); @@ -36,9 +37,10 @@ public: void refreshProject(); void saveProject(const FilePath& projectSettingsFilePath); void showLicenseScreen(); + bool hasGUI(); private: - Application(); + Application(bool withGUI=true); virtual void handleMessage(MessageActivateWindow* message); virtual void handleMessage(MessageFinishedParsing* message); @@ -50,6 +52,7 @@ private: void updateRecentProjects(const FilePath& projectSettingsFilePath); + bool m_hasGUI; std::shared_ptr m_project; std::shared_ptr m_storageCache; diff --git a/src/lib/utility/ResourcePaths.cpp b/src/lib/utility/ResourcePaths.cpp index d88cab8a..13f5986c 100644 --- a/src/lib/utility/ResourcePaths.cpp +++ b/src/lib/utility/ResourcePaths.cpp @@ -2,21 +2,17 @@ #include "AppPath.h" -std::string ResourcePaths::m_colorSchemesPath = AppPath::getAppPath() + "data/color_schemes/"; -std::string ResourcePaths::m_fontsPath = AppPath::getAppPath() + "data/fonts/"; -std::string ResourcePaths::m_guiPath = AppPath::getAppPath() + "data/gui/"; - std::string ResourcePaths::getColorSchemesPath() { - return m_colorSchemesPath; + return AppPath::getAppPath() + "data/color_schemes/"; } std::string ResourcePaths::getFontsPath() { - return m_fontsPath; + return AppPath::getAppPath() + "data/fonts/"; } std::string ResourcePaths::getGuiPath() { - return m_guiPath; -} \ No newline at end of file + return AppPath::getAppPath() + "data/gui/"; +} diff --git a/src/lib/utility/ResourcePaths.h b/src/lib/utility/ResourcePaths.h index 91bda322..2936ef21 100644 --- a/src/lib/utility/ResourcePaths.h +++ b/src/lib/utility/ResourcePaths.h @@ -9,11 +9,6 @@ public: static std::string getColorSchemesPath(); static std::string getFontsPath(); static std::string getGuiPath(); - -private: - static std::string m_colorSchemesPath; - static std::string m_fontsPath; - static std::string m_guiPath; }; -#endif // RESOURCE_PATHS_H \ No newline at end of file +#endif // RESOURCE_PATHS_H diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index 99bd5fff..f9fdd82e 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -6,9 +6,6 @@ add_files( platform_includes/includesMac.h platform_includes/includesWindows.h - qt/commandline/QtCommandLineParser.cpp - qt/commandline/QtCommandLineParser.h - qt/element/QtAutocompletionList.cpp qt/element/QtAutocompletionList.h qt/element/QtCodeArea.cpp @@ -148,4 +145,6 @@ add_files( qt/QtApplication.cpp qt/QtApplication.h + qt/QtCoreApplication.cpp + qt/QtCoreApplication.h ) diff --git a/src/lib_gui/qt/QtCoreApplication.cpp b/src/lib_gui/qt/QtCoreApplication.cpp new file mode 100644 index 00000000..4696f607 --- /dev/null +++ b/src/lib_gui/qt/QtCoreApplication.cpp @@ -0,0 +1,45 @@ +#include "qt/QtCoreApplication.h" + +#include + +#include "settings/ApplicationSettings.h" +#include "utility/file/FilePath.h" +#include "utility/logging/logging.h" +#include "utility/AppPath.h" +#include "utility/UserPaths.h" +#include "License.h" + +QtCoreApplication::QtCoreApplication(int argc, char **argv ) + : QCoreApplication(argc, argv) +{ +} + +QtCoreApplication::~QtCoreApplication() +{ +} + +void QtCoreApplication::handleMessage(MessageFinishedParsing* message) +{ + std::cout << "Finished parsing" << std::endl; + LOG_INFO("Finished parsing"); + this->quit(); +} + +bool QtCoreApplication::saveLicense(License license) +{ + if (license.isValid()) + { + ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); + std::string appLocation = AppPath::getAppPath(); + appSettings->setLicenseString(license.getLicenseEncodedString(appLocation)); + FilePath p(appLocation); + appSettings->setLicenseCheck(license.hashLocation(p.absolute().str())); + appSettings->save(UserPaths::getAppSettingsPath()); + return true; + } + else + { + LOG_ERROR( "The entered license key is invalid."); + return false; + } +} diff --git a/src/lib_gui/qt/QtCoreApplication.h b/src/lib_gui/qt/QtCoreApplication.h new file mode 100644 index 00000000..5e256d96 --- /dev/null +++ b/src/lib_gui/qt/QtCoreApplication.h @@ -0,0 +1,26 @@ +#ifndef QT_COREAPPLICTION_H +#define QT_COREAPPLICTION_H + +#include +#include "utility/messaging/MessageListener.h" +#include "utility/messaging/type/MessageFinishedParsing.h" + +class License; + +class QtCoreApplication + : public QCoreApplication + , public MessageListener +{ +public: + QtCoreApplication(int argc, char **argv); + virtual ~QtCoreApplication(); + bool saveLicense(License license); +signals: + void quitSignal(); +private: + virtual void handleMessage(MessageFinishedParsing* message); +}; + + +#endif // QT_COREAPPLICATION + diff --git a/src/lib_gui/qt/commandline/QtCommandLineParser.cpp b/src/lib_gui/qt/commandline/QtCommandLineParser.cpp deleted file mode 100644 index 376efd11..00000000 --- a/src/lib_gui/qt/commandline/QtCommandLineParser.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "qt/commandline/QtCommandLineParser.h" - -#include "utility/ConfigManager.h" -#include "utility/messaging/type/MessageLoadProject.h" -#include "utility/messaging/type/MessageStatus.h" -#include "utility/text/TextAccess.h" - - -QtCommandLineParser::QtCommandLineParser() -{ -} - -QtCommandLineParser::~QtCommandLineParser() -{ -} - -void QtCommandLineParser::setup() -{ - - setApplicationDescription("Coati helper"); - addVersionOption(); - addHelpOption(); - - QCommandLineOption projectOption(QStringList() << "p" << "project", - QCoreApplication::translate("main", "Load Coati with the a Coatiprojectfile ."), - QCoreApplication::translate("main", "CoatiProject")); - addOption(projectOption); -} - -void QtCommandLineParser::parseCommandline() -{ - - 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()); - } - } -} \ No newline at end of file diff --git a/src/lib_gui/qt/commandline/QtCommandLineParser.h b/src/lib_gui/qt/commandline/QtCommandLineParser.h deleted file mode 100644 index 08cd2f5f..00000000 --- a/src/lib_gui/qt/commandline/QtCommandLineParser.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef QTCOMMANDLINEPARSER_H -#define QTCOMMANDLINEPARSER_H - -#include -#include "Application.h" - -class QtCommandLineParser : public QCommandLineParser -{ -public: - QtCommandLineParser(); - ~QtCommandLineParser(); - void setup(); - void parseCommandline(); - -private: - -}; - -#endif //QTCOMMANDLINEPARSER_H