diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2020-07-27 17:09:49 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2020-07-27 17:13:25 +0200 |
commit | 7411d37db68911c59016472e3aead0634cf555ae (patch) | |
tree | 72238bf0774ad15a1ac5326ba4607f6caeb7f48f /src/main.cpp | |
parent | 77eefb1b2364737d824cc4cbefbe4b7bb1fd55b9 (diff) | |
download | RWA.Support.DesktopApp-7411d37db68911c59016472e3aead0634cf555ae.tar.gz RWA.Support.DesktopApp-7411d37db68911c59016472e3aead0634cf555ae.tar.bz2 RWA.Support.DesktopApp-7411d37db68911c59016472e3aead0634cf555ae.zip |
Move sources to src/ && lots of features
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..a1b1b9f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,66 @@ +#include <QApplication> +#include <QQmlApplicationEngine> +#include <QQmlComponent> +#include <QQmlProperty> +#include <QQuickItem> +#include <QObject> +#include <QTranslator> +#include <QDebug> +#include <QQmlContext> +#include <QQuickStyle> +#include <signal.h> + +#include "RWADBusAdaptor.cpp" +#include "session.h" + +int main(int argc, char *argv[]) { + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication app(argc, argv); + + QQuickStyle::setStyle("Material"); + + QTranslator translator; + qDebug() << "Loading locale: qrc:/locales/bin/" + QLocale::system().name(); + if(translator.load(":/locales/bin/" + QLocale::system().name())) { + app.installTranslator(&translator); + qDebug() << "Loaded: " + QLocale::system().name() + " locale!"; + } else { + qDebug() << "Unable to load translation"; + } + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + QScopedPointer<MainQMLAdaptor> main_gui (new MainQMLAdaptor(&app, &engine)); + //MainQMLAdaptor *main_gui = new MainQMLAdaptor(&app, &engine); + // Make mainqmladaptor available to QML + engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data()); + + QScopedPointer<Session> session (new Session(&app, &engine, main_gui.data())); + //Session *session = new Session(&app, &engine, main_gui); + // Make 'session' available to QML + engine.rootContext()->setContextProperty("session", session.data()); + + // We don't want users to have multiple instances of this app running + QString tmpDirPath = QDir::tempPath() + "/rwa"; + QString tmpFilePath = tmpDirPath + "/remote-support-desktop-application-prevent-multiple-instances.lock"; + QDir tmpDir(tmpDirPath); + if (!tmpDir.exists()) { + // Ensure that the path exists + tmpDir.mkpath("."); + } + QLockFile lockFile(tmpFilePath); + qDebug() << "Checking for a lockfile at: " + tmpFilePath; + + if(!lockFile.tryLock(100)){ + qDebug() << QObject::tr("You already have this app running."); + qDebug() << QObject::tr("Only one instance is allowed."); + qDebug() << QObject::tr("Closing application now with an error."); + + return 1; + } + + return app.exec(); +} |