2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Dirk Bartley, March 2007
25 #include <QAbstractEventDispatcher>
26 #include <QTableWidgetItem>
27 #include "clientstat.h"
29 /* This probably should be on a mutex */
30 static bool working = false; /* prevent timer recursion */
33 * Constructor for the class
35 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
40 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
41 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
42 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
43 m_cursor = new QTextCursor(textEditHeader->document());
47 m_timer = new QTimer(this);
54 void ClientStat::getFont()
56 QFont font = textEditHeader->font();
59 m_console->getDirResName(dirname);
60 QSettings settings(dirname, "bat");
61 settings.beginGroup("Console");
62 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
63 font.setPointSize(settings.value("consolePointSize", 10).toInt());
64 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
66 textEditHeader->setFont(font);
70 * Write the m_splitter settings in the destructor
72 ClientStat::~ClientStat()
78 * Populate all tables and header widgets
80 void ClientStat::populateAll()
83 populateCurrentTab(tabWidget->currentIndex());
87 * Timer is triggered, see if is current and repopulate.
89 void ClientStat::timerTriggered()
91 double value = timerDisplay->value();
93 if (value <= 0 && !working) {
95 value = spinBox->value();
96 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
97 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
102 timerDisplay->display(value);
106 void ClientStat::populateCurrentTab(int index)
115 * Populate header text widget
117 void ClientStat::populateHeader()
119 QString command = QString(".status client=\"" + m_client + "\" header");
120 if (mainWin->m_commandDebug)
121 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
123 textEditHeader->clear();
125 if (m_console->dir_cmd(command, results)) {
126 foreach (QString line, results) {
128 textEditHeader->insertPlainText(line);
134 * Populate teminated table
136 void ClientStat::populateTerminated()
138 QString command = QString(".status client=\"" + m_client + "\" terminated");
139 if (mainWin->m_commandDebug)
140 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
142 QBrush blackBrush(Qt::black);
144 terminatedTable->clear();
145 QStringList headerlist = (QStringList()
146 << tr("Job Id") << tr("Job Level") << tr("Job Files")
147 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
149 QStringList flaglist = (QStringList()
150 << "R" << "L" << "R" << "R" << "LC"
153 terminatedTable->setColumnCount(headerlist.size());
154 terminatedTable->setHorizontalHeaderLabels(headerlist);
156 if (m_console->dir_cmd(command, results)) {
158 QTableWidgetItem* p_tableitem;
159 terminatedTable->setRowCount(results.size());
160 foreach (QString line, results) {
161 /* Iterate through the record returned from the query */
162 QStringList fieldlist = line.split("\t");
164 QString statusCode("");
165 /* Iterate through fields in the record */
166 foreach (QString field, fieldlist) {
167 field = field.trimmed(); /* strip leading & trailing spaces */
168 p_tableitem = new QTableWidgetItem(field, 1);
169 p_tableitem->setForeground(blackBrush);
170 p_tableitem->setFlags(0);
171 if (flaglist[column].contains("R"))
172 p_tableitem->setTextAlignment(Qt::AlignRight);
173 if (flaglist[column].contains("C")) {
175 p_tableitem->setBackground(Qt::green);
177 p_tableitem->setBackground(Qt::red);
179 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
185 terminatedTable->resizeColumnsToContents();
186 terminatedTable->resizeRowsToContents();
187 terminatedTable->verticalHeader()->hide();
191 * Populate running text
193 void ClientStat::populateRunning()
195 QString command = QString(".status client=\"" + m_client + "\" running");
196 if (mainWin->m_commandDebug)
197 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
199 textEditRunning->clear();
201 if (m_console->dir_cmd(command, results)) {
202 foreach (QString line, results) {
204 textEditRunning->insertPlainText(line);
210 * When the treeWidgetItem in the page selector tree is single clicked, Make sure
211 * The tree has been populated.
213 void ClientStat::PgSeltreeWidgetClicked()
222 * Virtual function override of pages function which is called when this page
223 * is visible on the stack
225 void ClientStat::currentStackItem()
228 timerDisplay->display(spinBox->value());
236 * Function to create connections for context sensitive menu for this and
239 void ClientStat::createConnections()
241 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
242 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
243 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
244 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
245 terminatedTable->addAction(actionRefresh);
249 * Save user settings associated with this page
251 void ClientStat::writeSettings()
253 QSettings settings(m_console->m_dir->name(), "bat");
254 settings.beginGroup(m_groupText);
255 settings.setValue(m_splitText, splitter->saveState());
256 settings.setValue("refreshInterval", spinBox->value());
257 settings.setValue("refreshCheck", checkBox->checkState());
260 settings.beginGroup("OpenOnExit");
261 QString toWrite = "ClientStatus_" + m_client;
262 settings.setValue(toWrite, 1);
267 * Read and restore user settings associated with this page
269 void ClientStat::readSettings()
271 m_groupText = "ClientStatPage";
272 m_splitText = "splitterSizes_1";
273 QSettings settings(m_console->m_dir->name(), "bat");
274 settings.beginGroup(m_groupText);
275 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
276 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
277 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
280 timerDisplay->display(spinBox->value());