]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/sdstatus.cpp
Add new tray-monitor files that were omitted in the backport from Enterprise
[bacula/bacula] / bacula / src / qt-console / tray-monitor / sdstatus.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 "sdstatus.h"
21 #include "../util/fmtwidgetitem.h"
22 #include "jcr.h"
23
24 void SDStatus::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 Storage..."));
34       Dmsg1(50, "doUpdate(%p)\n", res);
35    }
36 }
37
38 void SDStatus::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.labelPlugins->setText(QString(res->plugins));
55          /* Clear the table first */
56          Freeze(*status.tableRunning);
57          Freeze(*status.tableTerminated);
58          QStringList headerlistR = (QStringList() << tr("JobId")
59                                     << tr("Job")  << tr("Level") << tr("Client")
60                                     << tr("Storage")
61                                     << tr("Files") << tr("Bytes") << tr("Errors"));
62          status.tableRunning->clear();
63          status.tableRunning->setRowCount(0);
64          status.tableRunning->setColumnCount(headerlistR.count());
65          status.tableRunning->setHorizontalHeaderLabels(headerlistR);
66          status.tableRunning->setEditTriggers(QAbstractItemView::NoEditTriggers);
67          status.tableRunning->verticalHeader()->hide();
68          status.tableRunning->setSortingEnabled(true);
69
70          if (res->running_jobs) {
71             status.tableRunning->setRowCount(res->running_jobs->size());
72             int row=0;
73             foreach_alist(rjob, res->running_jobs) {
74                int col=0;
75                TableItemFormatter item(*status.tableRunning, row++);
76                item.setNumericFld(col++, QString(edit_uint64(rjob->JobId, ed1)));
77                item.setTextFld(col++, QString(rjob->Job));
78                item.setJobLevelFld(col++, QString(rjob->JobLevel));
79                item.setTextFld(col++, QString(rjob->Client));
80                item.setTextFld(col++, QString(rjob->Storage));
81                item.setNumericFld(col++, QString(edit_uint64(rjob->JobFiles, ed1)));
82                item.setBytesFld(col++, QString(edit_uint64(rjob->JobBytes, ed1)));
83                item.setNumericFld(col++, QString(edit_uint64(rjob->Errors, ed1)));
84             }
85          } else {
86             Dmsg0(0, "Strange, the list is NULL\n");
87          }
88
89          QStringList headerlistT = (QStringList() << tr("JobId")
90                                     << tr("Job")  << tr("Level")
91                                     << tr("Status") << tr("Files") << tr("Bytes")
92                                     << tr("Errors"));
93
94          status.tableTerminated->clear();
95          status.tableTerminated->setRowCount(0);
96          status.tableTerminated->setColumnCount(headerlistT.count());
97          status.tableTerminated->setHorizontalHeaderLabels(headerlistT);
98          status.tableTerminated->setEditTriggers(QAbstractItemView::NoEditTriggers);
99          status.tableTerminated->verticalHeader()->hide();
100          status.tableTerminated->setSortingEnabled(true);
101
102          if (res->terminated_jobs) {
103             status.tableTerminated->setRowCount(res->terminated_jobs->size());
104             int row=0;
105             foreach_dlist(ljob, res->terminated_jobs) {
106                int col=0;
107                TableItemFormatter item(*status.tableTerminated, row++);
108                item.setNumericFld(col++, QString(edit_uint64(ljob->JobId, ed1)));
109                item.setTextFld(col++, QString(ljob->Job));
110                item.setJobLevelFld(col++, QString(ljob->JobLevel));
111                item.setJobStatusFld(col++, QString(ljob->JobStatus));
112                item.setNumericFld(col++, QString(edit_uint64(ljob->JobFiles, ed1)));
113                item.setBytesFld(col++, QString(edit_uint64(ljob->JobBytes, ed1)));
114                item.setNumericFld(col++, QString(edit_uint64(ljob->Errors, ed1)));
115             }
116          } else {
117             Dmsg0(0, "Strange, the list is NULL\n");
118          }
119          res->mutex->unlock();
120       }
121       Dmsg1(50, "  Task %p OK\n", t);
122    }
123    t->deleteLater();
124    status.pushButton->setEnabled(true);   
125 }