main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. qmlHandler.setConfigExists(Config::loadFile());
  28. CmdManager::setQmlHandler(&qmlHandler);
  29. CmdManager::init();
  30. CliManager::setQmlHandler(&qmlHandler);
  31. JsonHandler::setQmlHandler(&qmlHandler);
  32. // Set the context for the window, so that the qml files can be connected to
  33. // the qmlHandler
  34. engine.rootContext()->setContextProperty("_qmlHandler", &qmlHandler);
  35. // Load the main window
  36. QQmlComponent component(&engine, QUrl(QStringLiteral("qrc:/Forms/Main/main.qml")));
  37. QObject *object = component.create();
  38. // Run the main window and save the return of the application in an integer
  39. // ret This is blocking, which means it will block the main program until the
  40. // window is closed
  41. int ret = app.exec();
  42. // If we land here, the window has been closed. Properly disconnect from the
  43. // server now
  44. CliManager::onExit();
  45. if (_RESTART) {
  46. pid_t pid = 0;
  47. pid = fork();
  48. if (pid == 0) {
  49. execl("./CCats-GUI", "CCats-GUI", (char *)NULL);
  50. exit(1);
  51. }
  52. }
  53. delete object;
  54. return ret;
  55. }