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.
30 * Dirk Bartley, March 2007
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
36 #include "clientstat.h"
38 /* This probably should be on a mutex */
39 static bool working = false; /* prevent timer recursion */
42 * Constructor for the class
44 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
49 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
50 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
51 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
52 m_cursor = new QTextCursor(textEditHeader->document());
56 m_timer = new QTimer(this);
63 void ClientStat::getFont()
65 QFont font = textEditHeader->font();
68 m_console->getDirResName(dirname);
69 QSettings settings(dirname, "bat");
70 settings.beginGroup("Console");
71 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
72 font.setPointSize(settings.value("consolePointSize", 10).toInt());
73 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
75 textEditHeader->setFont(font);
79 * Write the m_splitter settings in the destructor
81 ClientStat::~ClientStat()
87 * Populate all tables and header widgets
89 void ClientStat::populateAll()
92 populateCurrentTab(tabWidget->currentIndex());
96 * Timer is triggered, see if is current and repopulate.
98 void ClientStat::timerTriggered()
100 double value = timerDisplay->value();
102 if (value <= 0 && !working) {
104 value = spinBox->value();
105 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
106 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
111 timerDisplay->display(value);
115 void ClientStat::populateCurrentTab(int index)
124 * Populate header text widget
126 void ClientStat::populateHeader()
128 QString command = QString(".status client=\"" + m_client + "\" header");
129 if (mainWin->m_commandDebug)
130 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
132 textEditHeader->clear();
134 if (m_console->dir_cmd(command, results)) {
135 foreach (QString line, results) {
137 textEditHeader->insertPlainText(line);
143 * Populate teminated table
145 void ClientStat::populateTerminated()
147 QString command = QString(".status client=\"" + m_client + "\" terminated");
148 if (mainWin->m_commandDebug)
149 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
151 QBrush blackBrush(Qt::black);
153 terminatedTable->clear();
154 QStringList headerlist = (QStringList()
155 << tr("Job Id") << tr("Job Level") << tr("Job Files")
156 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
158 QStringList flaglist = (QStringList()
159 << "R" << "L" << "R" << "R" << "LC"
162 terminatedTable->setColumnCount(headerlist.size());
163 terminatedTable->setHorizontalHeaderLabels(headerlist);
165 if (m_console->dir_cmd(command, results)) {
167 QTableWidgetItem* p_tableitem;
168 terminatedTable->setRowCount(results.size());
169 foreach (QString line, results) {
170 /* Iterate through the record returned from the query */
171 QStringList fieldlist = line.split("\t");
173 QString statusCode("");
174 /* Iterate through fields in the record */
175 foreach (QString field, fieldlist) {
176 field = field.trimmed(); /* strip leading & trailing spaces */
177 p_tableitem = new QTableWidgetItem(field, 1);
178 p_tableitem->setForeground(blackBrush);
179 p_tableitem->setFlags(0);
180 if (flaglist[column].contains("R"))
181 p_tableitem->setTextAlignment(Qt::AlignRight);
182 if (flaglist[column].contains("C")) {
184 p_tableitem->setBackground(Qt::green);
186 p_tableitem->setBackground(Qt::red);
188 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
194 terminatedTable->resizeColumnsToContents();
195 terminatedTable->resizeRowsToContents();
196 terminatedTable->verticalHeader()->hide();
200 * Populate running text
202 void ClientStat::populateRunning()
204 QString command = QString(".status client=\"" + m_client + "\" running");
205 if (mainWin->m_commandDebug)
206 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
208 textEditRunning->clear();
210 if (m_console->dir_cmd(command, results)) {
211 foreach (QString line, results) {
213 textEditRunning->insertPlainText(line);
219 * When the treeWidgetItem in the page selector tree is single clicked, Make sure
220 * The tree has been populated.
222 void ClientStat::PgSeltreeWidgetClicked()
231 * Virtual function override of pages function which is called when this page
232 * is visible on the stack
234 void ClientStat::currentStackItem()
237 timerDisplay->display(spinBox->value());
245 * Function to create connections for context sensitive menu for this and
248 void ClientStat::createConnections()
250 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
251 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
252 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
253 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
254 terminatedTable->addAction(actionRefresh);
258 * Save user settings associated with this page
260 void ClientStat::writeSettings()
262 QSettings settings(m_console->m_dir->name(), "bat");
263 settings.beginGroup(m_groupText);
264 settings.setValue(m_splitText, splitter->saveState());
265 settings.setValue("refreshInterval", spinBox->value());
266 settings.setValue("refreshCheck", checkBox->checkState());
269 settings.beginGroup("OpenOnExit");
270 QString toWrite = "ClientStatus_" + m_client;
271 settings.setValue(toWrite, 1);
276 * Read and restore user settings associated with this page
278 void ClientStat::readSettings()
280 m_groupText = "ClientStatPage";
281 m_splitText = "splitterSizes_1";
282 QSettings settings(m_console->m_dir->name(), "bat");
283 settings.beginGroup(m_groupText);
284 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
285 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
286 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
289 timerDisplay->display(spinBox->value());