2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
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.
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.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Dirk Bartley, March 2007
24 #include <QAbstractEventDispatcher>
25 #include <QTableWidgetItem>
26 #include "clientstat.h"
28 /* This probably should be on a mutex */
29 static bool working = false; /* prevent timer recursion */
32 * Constructor for the class
34 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
39 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
40 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
41 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
42 m_cursor = new QTextCursor(textEditHeader->document());
46 m_timer = new QTimer(this);
53 void ClientStat::getFont()
55 QFont font = textEditHeader->font();
58 m_console->getDirResName(dirname);
59 QSettings settings(dirname, "bat");
60 settings.beginGroup("Console");
61 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
62 font.setPointSize(settings.value("consolePointSize", 10).toInt());
63 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
65 textEditHeader->setFont(font);
69 * Write the m_splitter settings in the destructor
71 ClientStat::~ClientStat()
77 * Populate all tables and header widgets
79 void ClientStat::populateAll()
82 populateCurrentTab(tabWidget->currentIndex());
86 * Timer is triggered, see if is current and repopulate.
88 void ClientStat::timerTriggered()
90 double value = timerDisplay->value();
92 if (value <= 0 && !working) {
94 value = spinBox->value();
95 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
96 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
101 timerDisplay->display(value);
105 void ClientStat::populateCurrentTab(int index)
114 * Populate header text widget
116 void ClientStat::populateHeader()
118 QString command = QString(".status client=\"" + m_client + "\" header");
119 if (mainWin->m_commandDebug)
120 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
122 textEditHeader->clear();
124 if (m_console->dir_cmd(command, results)) {
125 foreach (QString line, results) {
127 textEditHeader->insertPlainText(line);
133 * Populate teminated table
135 void ClientStat::populateTerminated()
137 QString command = QString(".status client=\"" + m_client + "\" terminated");
138 if (mainWin->m_commandDebug)
139 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
141 QBrush blackBrush(Qt::black);
143 terminatedTable->clear();
144 QStringList headerlist = (QStringList()
145 << tr("Job Id") << tr("Job Level") << tr("Job Files")
146 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
148 QStringList flaglist = (QStringList()
149 << "R" << "L" << "R" << "R" << "LC"
152 terminatedTable->setColumnCount(headerlist.size());
153 terminatedTable->setHorizontalHeaderLabels(headerlist);
155 if (m_console->dir_cmd(command, results)) {
157 QTableWidgetItem* p_tableitem;
158 terminatedTable->setRowCount(results.size());
159 foreach (QString line, results) {
160 /* Iterate through the record returned from the query */
161 QStringList fieldlist = line.split("\t");
163 QString statusCode("");
164 /* Iterate through fields in the record */
165 foreach (QString field, fieldlist) {
166 field = field.trimmed(); /* strip leading & trailing spaces */
167 p_tableitem = new QTableWidgetItem(field, 1);
168 p_tableitem->setForeground(blackBrush);
169 p_tableitem->setFlags(0);
170 if (flaglist[column].contains("R"))
171 p_tableitem->setTextAlignment(Qt::AlignRight);
172 if (flaglist[column].contains("C")) {
174 p_tableitem->setBackground(Qt::green);
176 p_tableitem->setBackground(Qt::red);
178 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
184 terminatedTable->resizeColumnsToContents();
185 terminatedTable->resizeRowsToContents();
186 terminatedTable->verticalHeader()->hide();
190 * Populate running text
192 void ClientStat::populateRunning()
194 QString command = QString(".status client=\"" + m_client + "\" running");
195 if (mainWin->m_commandDebug)
196 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
198 textEditRunning->clear();
200 if (m_console->dir_cmd(command, results)) {
201 foreach (QString line, results) {
203 textEditRunning->insertPlainText(line);
209 * When the treeWidgetItem in the page selector tree is single clicked, Make sure
210 * The tree has been populated.
212 void ClientStat::PgSeltreeWidgetClicked()
221 * Virtual function override of pages function which is called when this page
222 * is visible on the stack
224 void ClientStat::currentStackItem()
227 timerDisplay->display(spinBox->value());
235 * Function to create connections for context sensitive menu for this and
238 void ClientStat::createConnections()
240 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
241 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
242 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
243 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
244 terminatedTable->addAction(actionRefresh);
248 * Save user settings associated with this page
250 void ClientStat::writeSettings()
252 QSettings settings(m_console->m_dir->name(), "bat");
253 settings.beginGroup(m_groupText);
254 settings.setValue(m_splitText, splitter->saveState());
255 settings.setValue("refreshInterval", spinBox->value());
256 settings.setValue("refreshCheck", checkBox->checkState());
259 settings.beginGroup("OpenOnExit");
260 QString toWrite = "ClientStatus_" + m_client;
261 settings.setValue(toWrite, 1);
266 * Read and restore user settings associated with this page
268 void ClientStat::readSettings()
270 m_groupText = "ClientStatPage";
271 m_splitText = "splitterSizes_1";
272 QSettings settings(m_console->m_dir->name(), "bat");
273 settings.beginGroup(m_groupText);
274 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
275 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
276 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
279 timerDisplay->display(spinBox->value());