2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 two of the GNU 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 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 * Version $Id: clientstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
31 * Dirk Bartley, March 2007
35 #include <QAbstractEventDispatcher>
36 #include <QTableWidgetItem>
37 #include "clientstat.h"
40 * Constructor for the class
42 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
47 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
48 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
50 m_cursor = new QTextCursor(textEditHeader->document());
54 m_timer = new QTimer(this);
61 void ClientStat::getFont()
63 QFont font = textEditHeader->font();
66 m_console->getDirResName(dirname);
67 QSettings settings(dirname, "bat");
68 settings.beginGroup("Console");
69 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
70 font.setPointSize(settings.value("consolePointSize", 10).toInt());
71 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
73 textEditHeader->setFont(font);
77 * Write the m_splitter settings in the destructor
79 ClientStat::~ClientStat()
85 * Populate all tables and header widgets
87 void ClientStat::populateAll()
90 populateCurrentTab(tabWidget->currentIndex());
94 * Timer is triggered, see if is current and repopulate.
96 void ClientStat::timerTriggered()
98 double value = timerDisplay->value();
101 value = spinBox->value();
102 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
103 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
107 timerDisplay->display(value);
111 void ClientStat::populateCurrentTab(int index)
120 * Populate header text widget
122 void ClientStat::populateHeader()
124 QString command = QString(".status client=\"" + m_client + "\" header");
125 if (mainWin->m_commandDebug)
126 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
128 textEditHeader->clear();
130 if (m_console->dir_cmd(command, results)) {
131 foreach (QString line, results) {
133 textEditHeader->insertPlainText(line);
139 * Populate teminated table
141 void ClientStat::populateTerminated()
143 QString command = QString(".status client=\"" + m_client + "\" terminated");
144 if (mainWin->m_commandDebug)
145 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
147 QBrush blackBrush(Qt::black);
149 terminatedTable->clear();
150 QStringList headerlist = (QStringList()
151 << tr("Job Id") << tr("Job Level") << tr("Job Files")
152 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
154 QStringList flaglist = (QStringList()
155 << "R" << "L" << "R" << "R" << "LC"
158 terminatedTable->setColumnCount(headerlist.size());
159 terminatedTable->setHorizontalHeaderLabels(headerlist);
161 if (m_console->dir_cmd(command, results)) {
163 QTableWidgetItem* p_tableitem;
164 terminatedTable->setRowCount(results.size());
165 foreach (QString line, results) {
166 /* Iterate through the record returned from the query */
167 QStringList fieldlist = line.split("\t");
169 QString statusCode("");
170 /* Iterate through fields in the record */
171 foreach (QString field, fieldlist) {
172 field = field.trimmed(); /* strip leading & trailing spaces */
173 p_tableitem = new QTableWidgetItem(field, 1);
174 p_tableitem->setForeground(blackBrush);
175 p_tableitem->setFlags(0);
176 if (flaglist[column].contains("R"))
177 p_tableitem->setTextAlignment(Qt::AlignRight);
178 if (flaglist[column].contains("C")) {
180 p_tableitem->setBackground(Qt::green);
182 p_tableitem->setBackground(Qt::red);
184 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
190 terminatedTable->resizeColumnsToContents();
191 terminatedTable->resizeRowsToContents();
192 terminatedTable->verticalHeader()->hide();
196 * Populate running text
198 void ClientStat::populateRunning()
200 QString command = QString(".status client=\"" + m_client + "\" running");
201 if (mainWin->m_commandDebug)
202 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
204 textEditRunning->clear();
206 if (m_console->dir_cmd(command, results)) {
207 foreach (QString line, results) {
209 textEditRunning->insertPlainText(line);
215 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
216 * The tree has been populated.
218 void ClientStat::PgSeltreeWidgetClicked()
227 * Virtual function override of pages function which is called when this page
228 * is visible on the stack
230 void ClientStat::currentStackItem()
233 timerDisplay->display(spinBox->value());
241 * Function to create connections for context sensitive menu for this and
244 void ClientStat::createConnections()
246 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
247 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
248 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
249 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
250 terminatedTable->addAction(actionRefresh);
254 * Save user settings associated with this page
256 void ClientStat::writeSettings()
258 QSettings settings(m_console->m_dir->name(), "bat");
259 settings.beginGroup(m_groupText);
260 settings.setValue(m_splitText, splitter->saveState());
261 settings.setValue("refreshInterval", spinBox->value());
262 settings.setValue("refreshCheck", checkBox->checkState());
265 settings.beginGroup("OpenOnExit");
266 QString toWrite = "ClientStatus_" + m_client;
267 settings.setValue(toWrite, 1);
272 * Read and restore user settings associated with this page
274 void ClientStat::readSettings()
276 m_groupText = "ClientStatPage";
277 m_splitText = "splitterSizes_1";
278 QSettings settings(m_console->m_dir->name(), "bat");
279 settings.beginGroup(m_groupText);
280 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
281 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
282 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
285 timerDisplay->display(spinBox->value());