Compare commits

...

9 Commits

7 changed files with 193 additions and 14 deletions

View File

@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(GenericCore LANGUAGES CXX)
set(TARGET_APP "GenericCore")
project(${TARGET_APP} VERSION 0.0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
@ -8,23 +9,29 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core LinguistTools)
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core LinguistTools)
set(TS_FILES GenericCore_en_US.ts)
configure_file(CoreConfig.h.in CoreConfig.h)
add_library(GenericCore STATIC
set(TS_FILES ${TARGET_APP}_en_US.ts)
add_library(${TARGET_APP} STATIC
genericcore.cpp
genericcore.h
${TS_FILES}
constants.h
data/settingshandler.h data/settingshandler.cpp
)
target_link_libraries(GenericCore PRIVATE Qt${QT_VERSION_MAJOR}::Core)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(GenericCore PRIVATE GENERICCORE_LIBRARY)
target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Core)
target_compile_definitions(${TARGET_APP} PRIVATE ${TARGET_APP}_LIBRARY)
if(COMMAND qt_create_translation)
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

2
CoreConfig.h.in Normal file
View File

@ -0,0 +1,2 @@
#define CORE_NAME "${PROJECT_NAME}"
#define CORE_VERSION "${PROJECT_VERSION}"

15
constants.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <QString>
/// Platform dependent
#ifdef Q_OS_LINUX
static const QString UPDATER_EXE = "maintenancetool";
#elif defined(Q_OS_MAC)
static const QString UPDATER_EXE = "maintenancetool.app/Contents/MacOS/maintenancetool";
#elif defined(Q_OS_WIN)
static const QString UPDATER_EXE = "maintenancetool.exe";
#endif
#endif // CONSTANTS_H

43
data/settingshandler.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "settingshandler.h"
#include <QSettings>
QVariantMap SettingsHandler::getSettings(QString group) {
QSettings settings;
QVariantMap result;
if (!group.isEmpty()) {
settings.beginGroup(group);
}
foreach (QString key, settings.allKeys()) {
result.insert(key, settings.value(key));
}
if (!group.isEmpty()) {
settings.endGroup();
}
return result;
}
void SettingsHandler::saveSettings(QVariantMap settingMap, QString group) {
qInfo() << "saving settings...";
QSettings settings;
if (!group.isEmpty()) {
settings.beginGroup(group);
}
foreach (QString key, settingMap.keys()) {
// qDebug() << "saving:" << key << "-" << settingMap.value(key);
settings.setValue(key, settingMap.value(key));
}
if (!group.isEmpty()) {
settings.endGroup();
}
settings.sync();
}
SettingsHandler::SettingsHandler() {}

15
data/settingshandler.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef SETTINGSHANDLER_H
#define SETTINGSHANDLER_H
#include <QVariantMap>
class SettingsHandler {
public:
static QVariantMap getSettings(QString group = "");
static void saveSettings(QVariantMap settingMap, QString group = "");
private:
SettingsHandler();
};
#endif // SETTINGSHANDLER_H

View File

@ -1,3 +1,82 @@
#include "genericcore.h"
GenericCore::GenericCore() {}
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QProcess>
#include <QSettings>
#include <QString>
#include "../../ApplicationConfig.h"
#include "CoreConfig.h"
#include "constants.h"
using namespace std;
GenericCore::GenericCore() { qDebug() << "Creating core..."; }
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);
}
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;
}

View File

@ -1,10 +1,28 @@
#ifndef GENERICCORE_H
#define GENERICCORE_H
class GenericCore
{
public:
GenericCore();
#include <QObject>
class QString;
class GenericCore : public QObject {
Q_OBJECT
public:
GenericCore();
~GenericCore();
QString toString() const;
void sayHello() const;
bool isApplicationUpdateAvailable();
void triggerApplicationUpdate();
signals:
void displayStatusMessage(QString message);
private:
QString getMaintenanceToolFilePath() const;
};
#endif // GENERICCORE_H
#endif // GENERICCORE_H