From: Henrique Date: Sat, 16 May 2020 09:39:10 +0000 (+0200) Subject: BEE Backport bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp X-Git-Tag: Release-11.3.2~1541 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7cf9bcbbe5bc1883b15d95c2a3cc1a3f7e2f055;p=thirdparty%2Fbacula.git BEE Backport bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp This commit is the result of the squash of the following main commits: Author: Henrique Date: Mon Oct 28 23:25:34 2019 -0300 android: added loading animation to all network interactions Author: Henrique 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 Date: Wed Sep 4 00:30:37 2019 -0300 android: redesigned ResourceDetailsPage Author: Henrique 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 Date: Tue Aug 13 16:07:23 2019 -0300 android: moved QR Code feature to FD screen Author: Henrique Date: Tue Aug 13 10:45:16 2019 -0300 android: added tweak registration wizard Author: Henrique Date: Mon Aug 12 20:35:09 2019 -0300 android: added integration with registration wizard Author: Henrique 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 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 Date: Tue Dec 18 10:56:09 2018 +0100 android: Port bacula tray-monitor for Android --- 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 index 0000000000..1d95b62ace --- /dev/null +++ b/bacula/src/qt-console/tray-monitor/resdetails-ui-controller.cpp @@ -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 *tJobs = new QList(); + 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 *rJobs = new QList(); + 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() {}