Basically like in this tutorial: https://doc.qt.io/qt-6/modelview.html#2-1-a-read-only-table
92 lines
2.5 KiB
C++
92 lines
2.5 KiB
C++
#include "genericcore.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QDateTime>
|
|
#include <QDebug>
|
|
#include <QProcess>
|
|
#include <QSettings>
|
|
#include <QString>
|
|
|
|
#include "../../ApplicationConfig.h"
|
|
#include "CoreConfig.h"
|
|
#include "constants.h"
|
|
#include "model/tablemodel.h"
|
|
|
|
using namespace std;
|
|
|
|
GenericCore::GenericCore() {
|
|
qDebug() << "Creating core...";
|
|
|
|
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);
|
|
}
|
|
|
|
std::shared_ptr<QAbstractItemModel> GenericCore::getModel() const { return m_mainModel; }
|
|
|
|
void GenericCore::setupModels() { m_mainModel = make_shared<TableModel>(this); }
|
|
|
|
QString GenericCore::getMaintenanceToolFilePath() const {
|
|
QString applicationDirPath = QCoreApplication::applicationDirPath();
|
|
|
|
/// setting the applicationDirPath hard coded to test update feature from IDE
|
|
#ifdef QT_DEBUG
|
|
// REFACTOR retrieve application name automatically instead of using hard coded name
|
|
applicationDirPath = QString("/opt/%1").arg(APPLICATION_NAME);
|
|
#endif
|
|
|
|
#ifdef Q_OS_MAC
|
|
applicationDirPath.append("/../../..");
|
|
#endif
|
|
const QString filePath = applicationDirPath + "/" + UPDATER_EXE;
|
|
return filePath;
|
|
}
|