diff --git a/src/app/main.cpp b/src/app/main.cpp index 993a20a8..05b6fa3c 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -13,7 +13,6 @@ #include "project/SourceGroupFactoryModuleCpp.h" #include "project/SourceGroupFactoryModuleJava.h" #include "qt/network/QtNetworkFactory.h" -#include #include "qt/QtApplication.h" #include "qt/QtCoreApplication.h" #include "qt/utility/utilityQt.h" @@ -26,6 +25,7 @@ #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" #include "utility/ResourcePaths.h" @@ -36,17 +36,10 @@ #include "utility/Version.h" #include "version.h" -void signalHandler( int signum ) +void signalHandler(int signum) { - std::string s; - std::cout << "interrupt are you sure(Y/n):" << std::flush; - std::cin >> s; - std::cout << "\n*******\n" << s << "\n*******\n" << std::endl; - if (s == "Y" || s == "y") - { - std::cout << "quit()" << std::endl; - QCoreApplication::quit(); - } + std::cout << "interrupt running tasks" << std::endl; + MessageInterruptTasks().dispatch(); } void setupLogging() @@ -232,11 +225,10 @@ int main(int argc, char *argv[]) if (commandLineParser.runWithoutGUI()) { - commandLineParser.parse(); if (commandLineParser.startedWithLicense()) { - qobject_cast(qtApp.data())->saveLicense(commandLineParser.getLicense()); + utility::saveLicense(commandLineParser.getLicensePtr()); } if (commandLineParser.exitApplication()) { @@ -285,14 +277,13 @@ int main(int argc, char *argv[]) #else struct sigaction sa; sa.sa_handler = signalHandler; - sa.sa_flags = 0; - ::sigemptyset(&sa.sa_mask); + sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; - if(::sigaction(SIGINT, &sa, NULL)) + if (sigaction(SIGINT, &sa, NULL)) { std::cout << "Cant install SIGINT handler" << std::endl; } - if(::sigaction(SIGHUP, &sa, NULL)) + if (sigaction(SIGHUP, &sa, NULL)) { std::cout << "Cant install SIGHUP handler" << std::endl; } @@ -318,9 +309,7 @@ int main(int argc, char *argv[]) ).dispatch(); } - int exitcode = qtApp->exec(); return exitcode; - } diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 40f8bdfa..56b12759 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -231,10 +231,6 @@ void Application::refreshProject(bool force) m_componentManager->refreshViews(); } } - else if (!m_hasGUI) - { - MessageQuitApplication().dispatch(); - } } } @@ -263,6 +259,10 @@ void Application::handleMessage(MessageFinishedParsing* message) { MessageRefresh().refreshUiOnly().dispatch(); } + else + { + MessageQuitApplication().dispatch(); + } } void Application::handleMessage(MessageLoadProject* message) @@ -275,17 +275,27 @@ void Application::handleMessage(MessageLoadProject* message) return; } - if (!m_project || projectSettingsFilePath != m_project->getProjectSettingsFilePath()) + if (m_project && projectSettingsFilePath == m_project->getProjectSettingsFilePath()) { - createAndLoadProject(projectSettingsFilePath); + if (message->forceRefresh && m_hasGUI) + { + m_project->setStateSettingsUpdated(); + refreshProject(false); + } + + return; } + createAndLoadProject(projectSettingsFilePath); + if (message->forceRefresh) { - m_project->setStateSettingsUpdated(); + refreshProject(true); + } + else if (!m_hasGUI) + { refreshProject(false); } - } void Application::handleMessage(MessageRefresh* message) diff --git a/src/lib/data/TaskFinishParsing.cpp b/src/lib/data/TaskFinishParsing.cpp index f6b6762a..1eeac33f 100644 --- a/src/lib/data/TaskFinishParsing.cpp +++ b/src/lib/data/TaskFinishParsing.cpp @@ -3,7 +3,6 @@ #include "component/view/DialogView.h" #include "data/storage/PersistentStorage.h" #include "utility/messaging/type/MessageFinishedParsing.h" -#include "utility/messaging/type/MessageQuitApplication.h" #include "utility/messaging/type/MessageStatus.h" #include "utility/scheduling/Blackboard.h" #include "utility/utility.h" @@ -42,11 +41,6 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr blackboa dialogView->hideUnknownProgressDialog(); MessageFinishedParsing().dispatch(); - if (!Application::getInstance()->hasGUI()) - { - MessageQuitApplication().dispatch(); - } - float time = utility::duration(start); if (blackboard->exists("clear_time")) @@ -104,9 +98,4 @@ void TaskFinishParsing::terminate() MessageStatus("An unknown exception was thrown during indexing.", true, false).dispatch(); MessageFinishedParsing().dispatch(); - - if (!Application::getInstance()->hasGUI()) - { - MessageQuitApplication().dispatch(); - } } diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 45d92934..b04c1bd0 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -260,20 +260,16 @@ void Project::load() m_storage->buildCaches(); m_storageAccessProxy->setSubject(m_storage.get()); - MessageFinishedParsing().dispatch(); + if (Application::getInstance()->hasGUI()) + { + MessageFinishedParsing().dispatch(); + } MessageStatus("Finished Loading", false, false).dispatch(); } else { MessageStatus("Project not loaded", false, false).dispatch(); } - - // refresh always on headless - // since just opening a project in headless does not make sense - if (m_state != PROJECT_STATE_LOADED || !Application::getInstance()->hasGUI()) - { - MessageRefresh().dispatch(); - } } bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) @@ -396,6 +392,11 @@ bool Project::requestIndex(bool forceRefresh, bool needsFullRefresh) if (!filesToClean.size() && !filesToIndex.size()) { + if (!Application::getInstance()->hasGUI()) + { + MessageFinishedParsing().dispatch(); + } + MessageStatus("Nothing to refresh, all files are up-to-date.").dispatch(); return false; } diff --git a/src/lib_gui/qt/QtCoreApplication.cpp b/src/lib_gui/qt/QtCoreApplication.cpp index c922690b..86afe59f 100644 --- a/src/lib_gui/qt/QtCoreApplication.cpp +++ b/src/lib_gui/qt/QtCoreApplication.cpp @@ -2,19 +2,9 @@ #include -#include "settings/ApplicationSettings.h" -#include "utility/file/FilePath.h" -#include "utility/logging/logging.h" -#include "utility/AppPath.h" -#include "utility/UserPaths.h" -#include "utility/utilityApp.h" -#include "License.h" - QtCoreApplication::QtCoreApplication(int argc, char **argv ) : QCoreApplication(argc, argv) { - - } QtCoreApplication::~QtCoreApplication() @@ -23,6 +13,7 @@ QtCoreApplication::~QtCoreApplication() void QtCoreApplication::handleMessage(MessageQuitApplication* message) { + std::cout << "quit" << std::endl; emit quit(); } @@ -30,8 +21,3 @@ void QtCoreApplication::handleMessage(MessageStatus* message) { std::cout << message->status << std::endl; } - -bool QtCoreApplication::saveLicense(License license) -{ - return utility::saveLicense(&license); -} diff --git a/src/lib_gui/qt/QtCoreApplication.h b/src/lib_gui/qt/QtCoreApplication.h index f146eea9..05860b5a 100644 --- a/src/lib_gui/qt/QtCoreApplication.h +++ b/src/lib_gui/qt/QtCoreApplication.h @@ -2,30 +2,25 @@ #define QT_COREAPPLICTION_H #include + #include "utility/messaging/MessageListener.h" #include "utility/messaging/type/MessageQuitApplication.h" #include "utility/messaging/type/MessageStatus.h" -class License; -class UnixSignalWatcher; - class QtCoreApplication : public QCoreApplication , public MessageListener , public MessageListener { Q_OBJECT + public: QtCoreApplication(int argc, char **argv); virtual ~QtCoreApplication(); - bool saveLicense(License license); -signals: - void quitSignal(); + private: virtual void handleMessage(MessageQuitApplication* message); virtual void handleMessage(MessageStatus* message); }; - #endif // QT_COREAPPLICATION - diff --git a/src/lib_gui/utility/utilityApp.cpp b/src/lib_gui/utility/utilityApp.cpp index 14152ee3..b00b01a7 100644 --- a/src/lib_gui/utility/utilityApp.cpp +++ b/src/lib_gui/utility/utilityApp.cpp @@ -104,16 +104,17 @@ int utility::getIdealThreadCount() return QThread::idealThreadCount(); } -bool utility::saveLicense(License* license) +bool utility::saveLicense(const License* license) { if (license == nullptr) { return false; } + if (license->isValid()) { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); - if (appSettings == NULL) + if (appSettings == nullptr) { LOG_ERROR_STREAM(<< "Unable to retrieve app settings"); return false; @@ -121,10 +122,8 @@ bool utility::saveLicense(License* license) std::string appLocation = AppPath::getAppPath(); appSettings->setLicenseString(license->getLicenseEncodedString(appLocation)); - FilePath p(appLocation); - appSettings->setLicenseCheck(license->hashLocation(p.absolute().str())); - appSettings->save(UserPaths::getAppSettingsPath()); - + appSettings->setLicenseCheck(license->hashLocation(FilePath(appLocation).absolute().str())); + appSettings->save(); return true; } else diff --git a/src/lib_gui/utility/utilityApp.h b/src/lib_gui/utility/utilityApp.h index 80a33ce3..fe9f9894 100644 --- a/src/lib_gui/utility/utilityApp.h +++ b/src/lib_gui/utility/utilityApp.h @@ -19,7 +19,8 @@ namespace utility int getIdealThreadCount(); OsType getOsType(); - bool saveLicense(License* license); + + bool saveLicense(const License* license); } #endif // UTILITY_APP_H diff --git a/src/lib_license/License.cpp b/src/lib_license/License.cpp index 4fe641bd..f575c832 100644 --- a/src/lib_license/License.cpp +++ b/src/lib_license/License.cpp @@ -491,7 +491,7 @@ std::string License::getLicenseString() const return license; } -std::string License::hashLocation(const std::string& location) +std::string License::hashLocation(const std::string& location) const { if (m_rng == NULL || location.size() <= 0) { diff --git a/src/lib_license/License.h b/src/lib_license/License.h index 84640e43..10db96f8 100644 --- a/src/lib_license/License.h +++ b/src/lib_license/License.h @@ -100,7 +100,7 @@ public: void print(); - std::string hashLocation(const std::string&); + std::string hashLocation(const std::string&) const; static bool checkLocation(const std::string&, const std::string&); private: