]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/qt-console/tray-monitor/tray-monitor.cpp
authorHenrique <henrique.faria@baculasystems.com>
Sat, 16 May 2020 09:41:24 +0000 (11:41 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:19 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Thu Oct 17 17:54:43 2019 -0300

    android: changed Tutorial to only be shown when tray-monitor.conf file is empty. Also, changed android FD resource to not be deletable

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Thu Oct 10 17:28:50 2019 -0300

    android: fixed Tray Monitor logs and fixed small glitch with scrollToBottom() function

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Wed Oct 9 20:07:52 2019 -0300

    android: changed default Log Level to 0 and added proper GUI to change the File Daemon Log Level

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue Oct 1 21:11:16 2019 -0300

    android: removed custom signal handler in order to not mess with android default signal handler

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue Sep 3 14:20:10 2019 -0300

    android: added popup to create / edit tray-monitor resources

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue Aug 13 21:04:53 2019 -0300

    android: created enterprise and community versions

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue Jul 2 20:48:24 2019 -0300

    android: added code to create default resources (monitor, dir, fd, sd) and to change monitor name

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Mon May 27 15:33:03 2019 -0300

    android: added GUI for editing bacula-fd.conf

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue May 21 13:26:25 2019 -0300

    android: Add log screen that shows tray-monitor trace file

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Thu May 16 22:17:55 2019 -0300

    tray-monitor: fixed trace file creation on Windows

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue Apr 9 11:13:50 2019 +0200

    PSK: Add PSK to QT's applications

    - add "TLS PSK Enable" to resources
    - update hello messages
    - rename authenticatebase.c to .cc and add the file to the QT tools
      because of a RTTI compilation problem.
      I use .cc because it works best with both bacula's CORE and QT
      to be compiled as C++ and not C
    - call init_crypto() and init_signals() in tray-monitor

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Sun Mar 3 16:47:46 2019 -0300

    tray-monitor: fixed broken desktop compilation

Author: Henrique Faria <henrique.faria@baculasystems.com>
Date:   Tue Dec 18 10:56:09 2018 +0100

    android: Port bacula tray-monitor for Android

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Feb 29 13:38:03 2016 +0100

    Add new tray monitor

bacula/src/qt-console/tray-monitor/tray-monitor.cpp

index 079c09e77f6f5a9e141bce2c06d4b5b491e53f56..a8def7778bd346a9d17d36904b15a53b27fa7fc2 100644 (file)
 #include <QInputDialog>
 #include <QDir>
 
+#ifdef Q_OS_ANDROID
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QQmlContext>
+
+#ifdef ENTERPRISE
+#include "enterprise-tray-ui-controller.h"
+#else
+#include "tray-ui-controller.h"
+#endif
+
+#include "resdetails-ui-controller.h"
+#include "respanel-ui-controller.h"
+#include "runjob-ui-controller.h"
+#include "restore-ui-controller.h"
+#include "fd-config-ui-controller.h"
+#include "android-fd-service.h"
+#include "app-boot-ui-controller.h"
+
+int64_t AndroidFD::logLevel;
+#endif
+
 /* Static variables */
 char *configfile = NULL;
 static MONITOR *monitor = NULL;
@@ -53,6 +75,14 @@ PROG_COPYRIGHT
 "\n"), 2004, BDEMO, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
 }
 
+void terminate_tray_monitor(int /*sig*/)
+{
+#ifdef HAVE_WIN32
+   WSACleanup();                  /* TODO: check when we have to call it */
+#endif
+   exit(0);
+}
+
 void refresh_tray(TrayUI *t)
 {
    RESMON *r;
@@ -188,13 +218,35 @@ bail_out:
  *
  */
 int main(int argc, char *argv[])
-{   
-   QApplication    app(argc, argv);
+{
    int ch;
    bool test_config = false, display_cfg = false;
+
+#ifdef Q_OS_ANDROID
+   QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+   QGuiApplication app(argc, argv);
+   QQmlApplicationEngine engine;
+   AndroidFD::install();
+#ifdef ENTERPRISE
+   qmlRegisterType<EnterpriseTrayUiController>("io.qt.bmob.traycontroller", 1, 0, "TrayUiController");
+   engine.rootContext()->setContextProperty("IS_ENTERPRISE", QVariant(true));
+#else
+   qmlRegisterType<TrayUiController>("io.qt.bmob.traycontroller", 1, 0, "TrayUiController");
+   engine.rootContext()->setContextProperty("IS_ENTERPRISE", QVariant(false));
+#endif // ENTERPRISE
+   qmlRegisterType<RestoreUiController>("io.qt.bmob.restorejobcontroller", 1, 0, "RestoreUiController");
+   qmlRegisterType<RunJobUiController>("io.qt.bmob.runjobcontroller", 1, 0, "RunJobUiController");
+   qmlRegisterType<ResDetailsUiController>("io.qt.bmob.resdetailscontroller", 1, 0, "ResDetailsUiController");
+   qmlRegisterType<ResPanelUiController>("io.qt.bmob.respanelcontroller", 1, 0, "ResPanelUiController");
+   qmlRegisterType<FdConfigUiController>("io.qt.bmob.fdconfigcontroller", 1, 0, "FdConfigUiController");
+   qmlRegisterType<BootUiController>("io.qt.bmob.bootuicontroller", 1, 0, "BootUiController");
+#else
+   QApplication    app(argc, argv);
    TrayUI tray;
+#endif
+
    TSched sched;
-   
+
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
@@ -203,12 +255,20 @@ int main(int argc, char *argv[])
    my_name_is(argc, argv, "tray-monitor");
    lmgr_init_thread();
    init_msg(NULL, NULL, NULL);
-#ifdef HAVE_WIN32
+#if defined(HAVE_WIN32)
    working_directory = getenv("TMP");
-#endif
+#elif defined(Q_OS_ANDROID)
+   debug_level = 0;
+   AndroidFD::logLevel = debug_level;
+   working_directory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+           .toLatin1()
+           .constData();
+   set_trace(true);
+#else
    if (working_directory == NULL) {
       working_directory = "/tmp";
    }
+#endif
    start_watchdog();
 
 #ifndef HAVE_WIN32
@@ -228,9 +288,11 @@ int main(int argc, char *argv[])
          configfile = bstrdup(optarg);
          break;
 
+#ifndef Q_OS_ANDROID
       case 'W':
          tray.have_systray = (atoi(optarg) != 0);
          break;
+#endif
 
       case 'T':
          set_trace(true);
@@ -261,6 +323,10 @@ int main(int argc, char *argv[])
    argc -= optind;
    //argv += optind;
 
+#ifndef Q_OS_ANDROID
+init_signals(terminate_tray_monitor);
+#endif
+
    if (argc) {
       usage();
       exit(1);
@@ -279,19 +345,35 @@ int main(int argc, char *argv[])
          configfile = bstrdup(CONFIG_FILE);
       }
    }
-   Dmsg1(50, "configfile=%s\n", configfile);
+
+#ifndef Q_OS_ANDROID
+   Dmsg1(0, "configfile=%s\n", configfile);
+#else
+   Dmsg0(0, "Opening App...\n");
+#endif
 
    // We need to initialize the scheduler before the reload() command
    scheduler = &sched;
 
-   OSDependentInit();               /* Initialize Windows path handling */ 
+   OSDependentInit();               /* Initialize Windows path handling */
    (void)WSA_Init();                /* Initialize Windows sockets */
 
+   if (init_crypto() != 0) {
+      Emsg0(M_ERROR_TERM, 0, _("Cryptography library initialization failed.\n"));
+   }
+
+#ifdef Q_OS_ANDROID
+   ConfigStorage::init(configfile);
+   engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+   if (engine.rootObjects().isEmpty())
+       return -1;
+#else
    display_cfg = reload();
 
    if (test_config) {
       exit(0);
    }
+
    /* If we have a systray, we always keep the application*/
    if (tray.have_systray) {
       app.setQuitOnLastWindowClosed(false);
@@ -302,9 +384,12 @@ int main(int argc, char *argv[])
    tray.setupUi(&tray, monitor);
    refresh_tray(&tray);
    mainwidget = &tray;
+
    if (display_cfg) {
       new Conf();
    }
+#endif
+
    app.exec();
    sched.stop();
    stop_watchdog();