]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp
authorHenrique <henrique.faria@baculasystems.com>
Sat, 16 May 2020 09:39:10 +0000 (11:39 +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:   Mon Oct 28 23:25:34 2019 -0300

    android: added loading animation to all network interactions

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Mon Oct 14 21:10:25 2019 -0300

    android: added automatic File Daemon startup when the App tries to connect with it

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Wed Sep 4 00:30:37 2019 -0300

    android: redesigned ResourceDetailsPage

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Mon Aug 26 16:13:49 2019 -0300

    android: ResourceStatusPage:

    1) Added BusyIndicator animation when the App is connecting with a resource
    2) Refactor (Identation, comments)

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue Aug 13 16:07:23 2019 -0300

    android: moved QR Code feature to FD screen

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Tue Aug 13 10:45:16 2019 -0300

    android: added tweak registration wizard

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Mon Aug 12 20:35:09 2019 -0300

    android: added integration with registration wizard

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Fri Aug 9 13:11:29 2019 -0300

    android: added code to fetch QR Code data from the java component into the cpp component

Author: Henrique <henrique.faria@baculasystems.com>
Date:   Wed Jun 26 12:03:27 2019 -0300

    android: added missing license and a few comments on src files. FD debug level reduced to 50

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

    android: Port bacula tray-monitor for Android

bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp [new file with mode: 0644]

diff --git a/bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp b/bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp
new file mode 100644 (file)
index 0000000..1d95b62
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2020 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
+
+#include "resdetails-ui-controller.h"
+
+ResDetailsUiController::ResDetailsUiController(QObject *parent):
+    QObject(parent)
+{
+    m_storage = &ConfigStorage::getInstance();
+}
+
+void ResDetailsUiController::connectToResource()
+{
+    if(m_res == NULL) {
+        return;
+    }
+
+    if (!isConnecting()) {
+        setIsConnecting(true);
+
+        if (m_res->managed) {
+            AndroidFD::start();
+        }
+
+        task *t = new task();
+        connect(t, SIGNAL(done(task *)), this, SLOT(connectCallback(task *)), Qt::QueuedConnection);
+
+        //We get a version of the Resource that contains an encoded password
+        m_storage->reloadResources(true);
+        m_res = m_storage->getResourceByName(m_res->code, m_res->hdr.name);
+        m_storage->reloadResources();
+
+        t->init(m_res, TASK_STATUS);
+        m_res->wrk->queue(t);
+        emit connectionStarted();
+   }
+}
+
+void ResDetailsUiController::connectCallback(task *t)
+{
+
+    if (!t->status) {
+        setConnectionError(t->errmsg);
+    } else {
+        emit connectionSuccess();
+        setStartedDate(m_res->started);
+        setResourceVersion(m_res->version);
+        setResourcePlugins(m_res->plugins);
+        setBandwidthLimit(QString::number(m_res->bwlimit));
+
+        QList<QObject *> *tJobs = new QList<QObject*>();
+        struct s_last_job *job;
+
+        foreach_dlist(job, m_res->terminated_jobs) {
+            JobModel *model = new JobModel();
+            model->setData(job);
+            tJobs->append(model);
+        }
+
+        setTerminatedJobs(tJobs);
+
+        QList<QObject *> *rJobs = new QList<QObject*>();
+        struct s_running_job *rjob;
+
+        foreach_alist(rjob, m_res->running_jobs) {
+            JobModel *model = new JobModel();
+            model->setData(rjob);
+            rJobs->append(model);
+        }
+
+        setRunningJobs(rJobs);
+    }
+
+    t->deleteLater();
+    setIsConnecting(false);
+}
+
+void ResDetailsUiController::createRunJobModel() {
+    if (!isConnecting()) {
+        setIsConnecting(true);
+        task *t = new task();
+        connect(t, SIGNAL(done(task *)), this, SLOT(createBackupModelCallback(task *)), Qt::QueuedConnection);
+        t->init(m_res, TASK_RESOURCES);
+        m_res->wrk->queue(t);
+    }
+}
+
+void ResDetailsUiController::createBackupModelCallback(task *t) {
+    RunJobModel *model = new RunJobModel();
+    model->setDirector(t->res);
+    t->deleteLater();
+    setIsConnecting(false);
+    emit runJobModelCreated(model);
+}
+
+void ResDetailsUiController::createRestoreJobModel() {
+    if (!isConnecting()) {
+        setIsConnecting(true);
+        task *t = new task();
+        connect(t, SIGNAL(done(task *)), this, SLOT(createRestoreModelCallback(task *)), Qt::QueuedConnection);
+        t->init(m_res, TASK_RESOURCES);
+        m_res->wrk->queue(t);
+    }
+}
+
+void ResDetailsUiController::createRestoreModelCallback(task *t) {
+    RestoreJobModel *model = new RestoreJobModel();
+    model->setDirector(t->res);
+    t->deleteLater();
+    setIsConnecting(false);
+    emit restoreModelCreated(model);
+}
+
+ResDetailsUiController::~ResDetailsUiController() {}