#include "genericcore.h" #include #include #include #include #include #include #include "../../ApplicationConfig.h" #include "CoreConfig.h" #include "constants.h" #include "model/tablemodel.h" #include using namespace std; GenericCore::GenericCore() { qDebug() << "Creating core..."; // TODO let the model own its undo stack (& use TableModel::getUndoStack() if necessary) m_modelUndoStack = new QUndoStack(this); setupModels(); } GenericCore::~GenericCore() { qDebug() << "Destroying core..."; } QString GenericCore::toString() const { return QString("%1 (Version %2)").arg(CORE_NAME).arg(CORE_VERSION); } void GenericCore::sayHello() const { qDebug() << "Hello from the core!"; } bool GenericCore::isApplicationUpdateAvailable() { QProcess process; const QString programmString = getMaintenanceToolFilePath(); const QStringList checkArgs("--checkupdates"); process.start(programmString, checkArgs); process.waitForFinished(); const int exitCode = process.exitCode(); if (process.error() != QProcess::UnknownError) { qDebug() << "Error checking for updates"; emit displayStatusMessage("Error checking for updates"); return false; } QByteArray data = process.readAllStandardOutput(); QSettings settings; settings.beginGroup("Application"); settings.setValue("lastCheckForUpdate", QDateTime::currentDateTimeUtc()); settings.endGroup(); settings.sync(); if (data.isEmpty() || data.contains("currently no updates")) { qInfo() << "No updates available"; emit displayStatusMessage("No updates available."); return false; } return true; } void GenericCore::triggerApplicationUpdate() { // TODO include cleaness of undo stack // if (!m_undoStack->isClean()) { // saveItems(); // } // QStringList args("update componentA componentB"); QStringList args("--start-updater"); QString toolFilePath = getMaintenanceToolFilePath(); QProcess::startDetached(toolFilePath, args); } QUndoStack* GenericCore::getModelUndoStack() const { return m_modelUndoStack; } std::shared_ptr GenericCore::getModel() const { return m_mainModel; } void GenericCore::setupModels() { m_mainModel = make_shared(m_modelUndoStack, this); // TODO add QAbstractItemModelTester } QString GenericCore::getMaintenanceToolFilePath() const { QString applicationDirPath = QCoreApplication::applicationDirPath(); /// setting the applicationDirPath hard coded to test update feature from IDE #ifdef QT_DEBUG applicationDirPath = QString("/opt/%1").arg(APPLICATION_NAME); #endif #ifdef Q_OS_MAC applicationDirPath.append("/../../.."); #endif const QString filePath = applicationDirPath + "/" + UPDATER_EXE; return filePath; }