main.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <QApplication>
  2. #include <QObject>
  3. #include <QQmlApplicationEngine>
  4. #include <QQmlComponent>
  5. #include <QQmlContext>
  6. #include <csignal>
  7. #include <cstdio>
  8. #include <cstdlib>
  9. #include <cstring>
  10. #include <iostream>
  11. #include <sys/prctl.h>
  12. #include <sys/wait.h>
  13. #include <thread>
  14. #include <unistd.h>
  15. #include "../include/climanager.h"
  16. #include "../include/cmdmanager.h"
  17. #include "../include/jsonhandler.h"
  18. #include "../include/qmlhandler.h"
  19. using namespace std;
  20. int main(int argc, char *argv[]) {
  21. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  22. // This has to be here to fix warnings
  23. QCoreApplication::setOrganizationName("CCats");
  24. QApplication app(argc, argv);
  25. QQmlApplicationEngine engine;
  26. QMLHandler qmlHandler;
  27. CmdManager::setQmlHandler(&qmlHandler);
  28. CmdManager::init();
  29. CliManager::setQmlHandler(&qmlHandler);
  30. JsonHandler::setQmlHandler(&qmlHandler);
  31. // Set the context for the window, so that the qml files can be connected to
  32. // the qmlHandler
  33. engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
  34. // Load the main window
  35. QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/Forms/Main/main.qml")));
  36. QObject *object = component.create();
  37. // Run the main window and save the return of the application in an integer
  38. // ret This is blocking, which means it will block the main program until the
  39. // window is closed
  40. int ret = app.exec();
  41. // If we land here, the window has been closed. Properly disconnect from the
  42. // server now
  43. CliManager::onExit();
  44. if (_RESTART) {
  45. pid_t pid = 0;
  46. pid = fork();
  47. if (pid == 0) {
  48. execl("./CCats-GUI", "CCats-GUI", (char *)NULL);
  49. exit(1);
  50. }
  51. }
  52. delete object;
  53. return ret;
  54. }