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)
46 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
47 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
48 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
49 m_cursor = new QTextCursor(textEditHeader->document());
53 m_timer = new QTimer(this);
60 void ClientStat::getFont()
62 QFont font = textEditHeader->font();
65 m_console->getDirResName(dirname);
66 QSettings settings(dirname, "bat");
67 settings.beginGroup("Console");
68 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
69 font.setPointSize(settings.value("consolePointSize", 10).toInt());
70 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
72 textEditHeader->setFont(font);
76 * Write the m_splitter settings in the destructor
78 ClientStat::~ClientStat()
84 * Populate all tables and header widgets
86 void ClientStat::populateAll()
89 populateCurrentTab(tabWidget->currentIndex());
93 * Timer is triggered, see if is current and repopulate.
95 void ClientStat::timerTriggered()
97 double value = timerDisplay->value();
100 value = spinBox->value();
101 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
102 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
106 timerDisplay->display(value);
110 void ClientStat::populateCurrentTab(int index)
119 * Populate header text widget
121 void ClientStat::populateHeader()
123 QString command = QString(".status client=\"" + m_client + "\" header");
124 if (mainWin->m_commandDebug)
125 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
127 textEditHeader->clear();
129 if (m_console->dir_cmd(command, results)) {
130 foreach (QString line, results) {
132 textEditHeader->insertPlainText(line);
138 * Populate teminated table
140 void ClientStat::populateTerminated()
142 QString command = QString(".status client=\"" + m_client + "\" terminated");
143 if (mainWin->m_commandDebug)
144 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
146 QBrush blackBrush(Qt::black);
148 terminatedTable->clear();
149 QStringList headerlist = (QStringList()
150 << tr("Job Id") << tr("Job Level") << tr("Job Files")
151 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
153 QStringList flaglist = (QStringList()
154 << "R" << "L" << "R" << "R" << "LC"
157 terminatedTable->setColumnCount(headerlist.size());
158 terminatedTable->setHorizontalHeaderLabels(headerlist);
160 if (m_console->dir_cmd(command, results)) {
162 QTableWidgetItem* p_tableitem;
163 terminatedTable->setRowCount(results.size());
164 foreach (QString line, results) {
165 /* Iterate through the record returned from the query */
166 QStringList fieldlist = line.split("\t");
168 QString statusCode("");
169 /* Iterate through fields in the record */
170 foreach (QString field, fieldlist) {
171 field = field.trimmed(); /* strip leading & trailing spaces */
172 p_tableitem = new QTableWidgetItem(field, 1);
173 p_tableitem->setForeground(blackBrush);
174 p_tableitem->setFlags(0);
175 if (flaglist[column].contains("R"))
176 p_tableitem->setTextAlignment(Qt::AlignRight);
177 if (flaglist[column].contains("C")) {
179 p_tableitem->setBackground(Qt::green);
181 p_tableitem->setBackground(Qt::red);
183 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
189 terminatedTable->resizeColumnsToContents();
190 terminatedTable->resizeRowsToContents();
191 terminatedTable->verticalHeader()->hide();
195 * Populate running text
197 void ClientStat::populateRunning()
199 QString command = QString(".status client=\"" + m_client + "\" running");
200 if (mainWin->m_commandDebug)
201 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
203 textEditRunning->clear();
205 if (m_console->dir_cmd(command, results)) {
206 foreach (QString line, results) {
208 textEditRunning->insertPlainText(line);
214 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
215 * The tree has been populated.
217 void ClientStat::PgSeltreeWidgetClicked()
226 * Virtual function override of pages function which is called when this page
227 * is visible on the stack
229 void ClientStat::currentStackItem()
232 timerDisplay->display(spinBox->value());
240 * Function to create connections for context sensitive menu for this and
243 void ClientStat::createConnections()
245 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
246 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
247 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
248 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
249 terminatedTable->addAction(actionRefresh);
253 * Save user settings associated with this page
255 void ClientStat::writeSettings()
257 QSettings settings(m_console->m_dir->name(), "bat");
258 settings.beginGroup(m_groupText);
259 settings.setValue(m_splitText, splitter->saveState());
260 settings.setValue("refreshInterval", spinBox->value());
261 settings.setValue("refreshCheck", checkBox->checkState());
264 settings.beginGroup("OpenOnExit");
265 QString toWrite = "ClientStatus_" + m_client;
266 settings.setValue(toWrite, 1);
271 * Read and restore user settings associated with this page
273 void ClientStat::readSettings()
275 m_groupText = "ClientStatPage";
276 m_splitText = "splitterSizes_1";
277 QSettings settings(m_console->m_dir->name(), "bat");
278 settings.beginGroup(m_groupText);
279 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
280 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
281 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
284 timerDisplay->display(spinBox->value());