]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/dirstatus.cpp
Big backport from Enterprise
[bacula/bacula] / bacula / src / qt-console / tray-monitor / dirstatus.cpp
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19
20 #include "dirstatus.h"
21 #include "../util/fmtwidgetitem.h"
22 #include "jcr.h"
23
24 void DIRStatus::doUpdate()
25 {
26    if (count == 0) {
27       count++;
28       task *t = new task();
29       status.pushButton->setEnabled(false);
30       connect(t, SIGNAL(done(task *)), this, SLOT(taskDone(task *)), Qt::QueuedConnection);
31       t->init(res, TASK_STATUS);
32       res->wrk->queue(t);
33       status.statusBar->setText(QString("Trying to connect to Director..."));
34       Dmsg1(50, "doUpdate(%p)\n", res);
35    }
36 }
37
38 void DIRStatus::taskDone(task *t)
39 {
40    count--;
41    if (!t->status) {
42       status.statusBar->setText(QString(t->errmsg));
43
44    } else {
45       status.statusBar->clear();
46       if (t->type == TASK_STATUS) {
47          char ed1[50];
48          struct s_last_job *ljob;
49          struct s_running_job *rjob;
50          res->mutex->lock();
51          status.labelName->setText(QString(res->name));
52          status.labelVersion->setText(QString(res->version));
53          status.labelStarted->setText(QString(res->started));
54          status.labelReloaded->setText(QString(res->reloaded));
55          status.labelPlugins->setText(QString(res->plugins));
56          /* Clear the table first */
57          Freeze(*status.tableRunning);
58          Freeze(*status.tableTerminated);
59          QStringList headerlistR = (QStringList() << tr("JobId")
60                                     << tr("Job")  << tr("Level") << tr("Client")
61                                     << tr("Status") << tr("Storage")
62                                     << tr("Files") << tr("Bytes") << tr("Errors"));
63          status.tableRunning->clear();
64          status.tableRunning->setRowCount(0);
65          status.tableRunning->setColumnCount(headerlistR.count());
66          status.tableRunning->setHorizontalHeaderLabels(headerlistR);
67          status.tableRunning->setEditTriggers(QAbstractItemView::NoEditTriggers);
68          status.tableRunning->verticalHeader()->hide();
69          status.tableRunning->setSortingEnabled(true);
70
71          if (res->running_jobs) {
72             status.tableRunning->setRowCount(res->running_jobs->size());
73             int row=0;
74             foreach_alist(rjob, res->running_jobs) {
75                int col=0;
76                TableItemFormatter item(*status.tableRunning, row++);
77                item.setNumericFld(col++, QString(edit_uint64(rjob->JobId, ed1)));
78                item.setTextFld(col++, QString(rjob->Job));
79                item.setJobLevelFld(col++, QString(rjob->JobLevel));
80                item.setTextFld(col++, QString(rjob->Client));
81                item.setJobStatusFld(col++, QString(rjob->JobStatus));
82                item.setTextFld(col++, QString(rjob->Storage));
83                item.setNumericFld(col++, QString(edit_uint64(rjob->JobFiles, ed1)));
84                item.setBytesFld(col++, QString(edit_uint64(rjob->JobBytes, ed1)));
85                item.setNumericFld(col++, QString(edit_uint64(rjob->Errors, ed1)));
86             }
87          } else {
88             Dmsg0(0, "Strange, the list is NULL\n");
89          }
90
91          QStringList headerlistT = (QStringList() << tr("JobId")
92                                     << tr("Job")  << tr("Level")
93                                     << tr("Status") << tr("Files") << tr("Bytes")
94                                     << tr("Errors"));
95
96          status.tableTerminated->clear();
97          status.tableTerminated->setRowCount(0);
98          status.tableTerminated->setColumnCount(headerlistT.count());
99          status.tableTerminated->setHorizontalHeaderLabels(headerlistT);
100          status.tableTerminated->setEditTriggers(QAbstractItemView::NoEditTriggers);
101          status.tableTerminated->verticalHeader()->hide();
102          status.tableTerminated->setSortingEnabled(true);
103
104          if (res->terminated_jobs) {
105             status.tableTerminated->setRowCount(res->terminated_jobs->size());
106             int row=0;
107             foreach_dlist(ljob, res->terminated_jobs) {
108                int col=0;
109                TableItemFormatter item(*status.tableTerminated, row++);
110                item.setNumericFld(col++, QString(edit_uint64(ljob->JobId, ed1)));
111                item.setTextFld(col++, QString(ljob->Job));
112                item.setJobLevelFld(col++, QString(ljob->JobLevel));
113                item.setJobStatusFld(col++, QString(ljob->JobStatus));
114                item.setNumericFld(col++, QString(edit_uint64(ljob->JobFiles, ed1)));
115                item.setBytesFld(col++, QString(edit_uint64(ljob->JobBytes, ed1)));
116                item.setNumericFld(col++, QString(edit_uint64(ljob->Errors, ed1)));
117             }
118          } else {
119             Dmsg0(0, "Strange, the list is NULL\n");
120          }
121          res->mutex->unlock();
122       }
123       Dmsg1(50, "  Task %p OK\n", t);
124    }
125    t->deleteLater();
126    status.pushButton->setEnabled(true);   
127 }