2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Dirk Bartley, March 2007
33 #include <QAbstractEventDispatcher>
34 #include <QTableWidgetItem>
35 #include "clientstat.h"
37 /* This probably should be on a mutex */
38 static bool working = false; /* prevent timer recursion */
41 * Constructor for the class
43 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
48 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
49 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
50 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
51 m_cursor = new QTextCursor(textEditHeader->document());
55 m_timer = new QTimer(this);
62 void ClientStat::getFont()
64 QFont font = textEditHeader->font();
67 m_console->getDirResName(dirname);
68 QSettings settings(dirname, "bat");
69 settings.beginGroup("Console");
70 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
71 font.setPointSize(settings.value("consolePointSize", 10).toInt());
72 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
74 textEditHeader->setFont(font);
78 * Write the m_splitter settings in the destructor
80 ClientStat::~ClientStat()
86 * Populate all tables and header widgets
88 void ClientStat::populateAll()
91 populateCurrentTab(tabWidget->currentIndex());
95 * Timer is triggered, see if is current and repopulate.
97 void ClientStat::timerTriggered()
99 double value = timerDisplay->value();
101 if (value <= 0 && !working) {
103 value = spinBox->value();
104 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
105 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
110 timerDisplay->display(value);
114 void ClientStat::populateCurrentTab(int index)
123 * Populate header text widget
125 void ClientStat::populateHeader()
127 QString command = QString(".status client=\"" + m_client + "\" header");
128 if (mainWin->m_commandDebug)
129 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
131 textEditHeader->clear();
133 if (m_console->dir_cmd(command, results)) {
134 foreach (QString line, results) {
136 textEditHeader->insertPlainText(line);
142 * Populate teminated table
144 void ClientStat::populateTerminated()
146 QString command = QString(".status client=\"" + m_client + "\" terminated");
147 if (mainWin->m_commandDebug)
148 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
150 QBrush blackBrush(Qt::black);
152 terminatedTable->clear();
153 QStringList headerlist = (QStringList()
154 << tr("Job Id") << tr("Job Level") << tr("Job Files")
155 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
157 QStringList flaglist = (QStringList()
158 << "R" << "L" << "R" << "R" << "LC"
161 terminatedTable->setColumnCount(headerlist.size());
162 terminatedTable->setHorizontalHeaderLabels(headerlist);
164 if (m_console->dir_cmd(command, results)) {
166 QTableWidgetItem* p_tableitem;
167 terminatedTable->setRowCount(results.size());
168 foreach (QString line, results) {
169 /* Iterate through the record returned from the query */
170 QStringList fieldlist = line.split("\t");
172 QString statusCode("");
173 /* Iterate through fields in the record */
174 foreach (QString field, fieldlist) {
175 field = field.trimmed(); /* strip leading & trailing spaces */
176 p_tableitem = new QTableWidgetItem(field, 1);
177 p_tableitem->setForeground(blackBrush);
178 p_tableitem->setFlags(0);
179 if (flaglist[column].contains("R"))
180 p_tableitem->setTextAlignment(Qt::AlignRight);
181 if (flaglist[column].contains("C")) {
183 p_tableitem->setBackground(Qt::green);
185 p_tableitem->setBackground(Qt::red);
187 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
193 terminatedTable->resizeColumnsToContents();
194 terminatedTable->resizeRowsToContents();
195 terminatedTable->verticalHeader()->hide();
199 * Populate running text
201 void ClientStat::populateRunning()
203 QString command = QString(".status client=\"" + m_client + "\" running");
204 if (mainWin->m_commandDebug)
205 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
207 textEditRunning->clear();
209 if (m_console->dir_cmd(command, results)) {
210 foreach (QString line, results) {
212 textEditRunning->insertPlainText(line);
218 * When the treeWidgetItem in the page selector tree is single clicked, Make sure
219 * The tree has been populated.
221 void ClientStat::PgSeltreeWidgetClicked()
230 * Virtual function override of pages function which is called when this page
231 * is visible on the stack
233 void ClientStat::currentStackItem()
236 timerDisplay->display(spinBox->value());
244 * Function to create connections for context sensitive menu for this and
247 void ClientStat::createConnections()
249 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
250 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
251 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
252 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
253 terminatedTable->addAction(actionRefresh);
257 * Save user settings associated with this page
259 void ClientStat::writeSettings()
261 QSettings settings(m_console->m_dir->name(), "bat");
262 settings.beginGroup(m_groupText);
263 settings.setValue(m_splitText, splitter->saveState());
264 settings.setValue("refreshInterval", spinBox->value());
265 settings.setValue("refreshCheck", checkBox->checkState());
268 settings.beginGroup("OpenOnExit");
269 QString toWrite = "ClientStatus_" + m_client;
270 settings.setValue(toWrite, 1);
275 * Read and restore user settings associated with this page
277 void ClientStat::readSettings()
279 m_groupText = "ClientStatPage";
280 m_splitText = "splitterSizes_1";
281 QSettings settings(m_console->m_dir->name(), "bat");
282 settings.beginGroup(m_groupText);
283 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
284 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
285 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
288 timerDisplay->display(spinBox->value());