summaryrefslogtreecommitdiff
path: root/src/qt-console/tray-monitor/dirstatus.cpp
blob: 0e692a31ceb79692b47c14e1cd7bbb81c3ee1eb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
   Bacula(R) - The Network Backup Solution

   Copyright (C) 2000-2017 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 "dirstatus.h"
#include "../util/fmtwidgetitem.h"
#include "jcr.h"

void DIRStatus::doUpdate()
{
   if (count == 0) {
      count++;
      task *t = new task();
      status.pushButton->setEnabled(false);
      connect(t, SIGNAL(done(task *)), this, SLOT(taskDone(task *)), Qt::QueuedConnection);
      t->init(res, TASK_STATUS);
      res->wrk->queue(t);
      status.statusBar->setText(QString("Trying to connect to Director..."));
      Dmsg1(50, "doUpdate(%p)\n", res);
   }
}

void DIRStatus::taskDone(task *t)
{
   count--;
   if (!t->status) {
      status.statusBar->setText(QString(t->errmsg));

   } else {
      status.statusBar->clear();
      if (t->type == TASK_STATUS) {
         char ed1[50];
         struct s_last_job *ljob;
         struct s_running_job *rjob;
         res->mutex->lock();
         status.labelName->setText(QString(res->name));
         status.labelVersion->setText(QString(res->version));
         status.labelStarted->setText(QString(res->started));
         status.labelReloaded->setText(QString(res->reloaded));
         status.labelPlugins->setText(QString(res->plugins));
         /* Clear the table first */
         Freeze(*status.tableRunning);
         Freeze(*status.tableTerminated);
         QStringList headerlistR = (QStringList() << tr("JobId")
                                    << tr("Job")  << tr("Level") << tr("Client")
                                    << tr("Status") << tr("Storage")
                                    << tr("Files") << tr("Bytes") << tr("Errors"));
         status.tableRunning->clear();
         status.tableRunning->setRowCount(0);
         status.tableRunning->setColumnCount(headerlistR.count());
         status.tableRunning->setHorizontalHeaderLabels(headerlistR);
         status.tableRunning->setEditTriggers(QAbstractItemView::NoEditTriggers);
         status.tableRunning->verticalHeader()->hide();
         status.tableRunning->setSortingEnabled(true);

         if (res->running_jobs) {
            status.tableRunning->setRowCount(res->running_jobs->size());
            int row=0;
            foreach_alist(rjob, res->running_jobs) {
               int col=0;
               TableItemFormatter item(*status.tableRunning, row++);
               item.setNumericFld(col++, QString(edit_uint64(rjob->JobId, ed1)));
               item.setTextFld(col++, QString(rjob->Job));
               item.setJobLevelFld(col++, QString(rjob->JobLevel));
               item.setTextFld(col++, QString(rjob->Client));
               item.setJobStatusFld(col++, QString(rjob->JobStatus));
               item.setTextFld(col++, QString(rjob->Storage));
               item.setNumericFld(col++, QString(edit_uint64(rjob->JobFiles, ed1)));
               item.setBytesFld(col++, QString(edit_uint64(rjob->JobBytes, ed1)));
               item.setNumericFld(col++, QString(edit_uint64(rjob->Errors, ed1)));
            }
         } else {
            Dmsg0(0, "Strange, the list is NULL\n");
         }

         QStringList headerlistT = (QStringList() << tr("JobId")
                                    << tr("Job")  << tr("Level")
                                    << tr("Status") << tr("Files") << tr("Bytes")
                                    << tr("Errors"));

         status.tableTerminated->clear();
         status.tableTerminated->setRowCount(0);
         status.tableTerminated->setColumnCount(headerlistT.count());
         status.tableTerminated->setHorizontalHeaderLabels(headerlistT);
         status.tableTerminated->setEditTriggers(QAbstractItemView::NoEditTriggers);
         status.tableTerminated->verticalHeader()->hide();
         status.tableTerminated->setSortingEnabled(true);

         if (res->terminated_jobs) {
            status.tableTerminated->setRowCount(res->terminated_jobs->size());
            int row=0;
            foreach_dlist(ljob, res->terminated_jobs) {
               int col=0;
               TableItemFormatter item(*status.tableTerminated, row++);
               item.setNumericFld(col++, QString(edit_uint64(ljob->JobId, ed1)));
               item.setTextFld(col++, QString(ljob->Job));
               item.setJobLevelFld(col++, QString(ljob->JobLevel));
               item.setJobStatusFld(col++, QString(ljob->JobStatus));
               item.setNumericFld(col++, QString(edit_uint64(ljob->JobFiles, ed1)));
               item.setBytesFld(col++, QString(edit_uint64(ljob->JobBytes, ed1)));
               item.setNumericFld(col++, QString(edit_uint64(ljob->Errors, ed1)));
            }
         } else {
            Dmsg0(0, "Strange, the list is NULL\n");
         }
         res->mutex->unlock();
      }
      Dmsg1(50, "  Task %p OK\n", t);
   }
   t->deleteLater();
   status.pushButton->setEnabled(true);   
}