2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 John Walker.
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
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
37 #include "clientstat.h"
40 * .status client=XXX header
41 * .status client=XXX running
42 * .status client=XXX terminated
46 * Constructor for the class
48 ClientStat::ClientStat(QString &client)
52 m_name = tr("Director Status");
55 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
56 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
57 m_cursor = new QTextCursor(textEdit->document());
61 m_timer = new QTimer(this);
62 QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
63 m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
68 void ClientStat::getFont()
70 QFont font = textEdit->font();
73 m_console->getDirResName(dirname);
74 QSettings settings(dirname, "bat");
75 settings.beginGroup("Console");
76 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
77 font.setPointSize(settings.value("consolePointSize", 10).toInt());
78 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
80 textEdit->setFont(font);
84 * Write the m_splitter settings in the destructor
86 ClientStat::~ClientStat()
92 * Populate all tables and header widgets
94 void ClientStat::populateAll()
96 if (!m_console->preventInUseConnect())
104 * Timer is triggered, see if is current and repopulate.
106 void ClientStat::timerTriggered()
108 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
109 if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
110 if (m_console->is_ready())
116 * Populate header text widget
118 void ClientStat::populateHeader()
120 QString command = QString(".status client=\"" + m_client + "\" header");
124 if (m_console->dir_cmd(command, results)) {
125 foreach (QString line, results) {
127 textEdit->insertPlainText(line);
133 * Populate teminated table
135 void ClientStat::populateTerminated()
137 QString command = QString(".status client=\"" + m_client + "\" terminated");
139 QBrush blackBrush(Qt::black);
141 terminatedTable->clear();
142 QStringList headerlist = (QStringList()
143 << tr("Job Id") << tr("Job Level") << tr("Job Files")
144 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
146 QStringList flaglist = (QStringList()
147 << "R" << "L" << "R" << "R" << "LC"
150 terminatedTable->setColumnCount(headerlist.size());
151 terminatedTable->setHorizontalHeaderLabels(headerlist);
153 if (m_console->dir_cmd(command, results)) {
155 QTableWidgetItem* p_tableitem;
156 terminatedTable->setRowCount(results.size());
157 foreach (QString line, results) {
158 /* Iterate through the record returned from the query */
159 QStringList fieldlist = line.split("\t");
161 QString statusCode("");
162 /* Iterate through fields in the record */
163 foreach (QString field, fieldlist) {
164 field = field.trimmed(); /* strip leading & trailing spaces */
165 p_tableitem = new QTableWidgetItem(field, 1);
166 p_tableitem->setForeground(blackBrush);
167 p_tableitem->setFlags(0);
168 if (flaglist[column].contains("R"))
169 p_tableitem->setTextAlignment(Qt::AlignRight);
170 if (flaglist[column].contains("C"))
172 p_tableitem->setBackground(Qt::green);
174 p_tableitem->setBackground(Qt::red);
175 terminatedTable->setItem(row, column, p_tableitem);
181 terminatedTable->resizeColumnsToContents();
182 terminatedTable->resizeRowsToContents();
183 terminatedTable->verticalHeader()->hide();
187 * Populate running table
189 void ClientStat::populateRunning()
191 QString command = QString(".status client=\"" + m_client + "\" running");
192 Pmsg1(000, "Clients running cmd : %s\n",command.toUtf8().data());
194 QBrush blackBrush(Qt::black);
196 runningTable->clear();
197 QStringList headerlist = (QStringList()
198 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
200 runningTable->setColumnCount(headerlist.size());
201 runningTable->setHorizontalHeaderLabels(headerlist);
203 if (m_console->dir_cmd(command, results)) {
205 QTableWidgetItem* p_tableitem;
206 runningTable->setRowCount(results.size());
207 foreach (QString line, results) {
208 /* Iterate through the record returned from the query */
209 QStringList fieldlist = line.split("\t");
211 QString statusCode("");
212 /* Iterate through fields in the record */
213 foreach (QString field, fieldlist) {
214 field = field.trimmed(); /* strip leading & trailing spaces */
215 p_tableitem = new QTableWidgetItem(field, 1);
216 p_tableitem->setForeground(blackBrush);
217 p_tableitem->setFlags(0);
218 runningTable->setItem(row, column, p_tableitem);
224 runningTable->resizeColumnsToContents();
225 runningTable->resizeRowsToContents();
226 runningTable->verticalHeader()->hide();
230 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
231 * The tree has been populated.
233 void ClientStat::PgSeltreeWidgetClicked()
242 * Virtual function override of pages function which is called when this page
243 * is visible on the stack
245 void ClientStat::currentStackItem()
254 * Function to create connections for context sensitive menu for this and
257 void ClientStat::createConnections()
259 connect(actionRefresh, SIGNAL(triggered()), this,
260 SLOT(populateAll()));
261 connect(actionCancelRunning, SIGNAL(triggered()), this,
262 SLOT(consoleCancelJob()));
264 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
265 runningTable->addAction(actionRefresh);
266 runningTable->addAction(actionCancelRunning);
270 * Save user settings associated with this page
272 void ClientStat::writeSettings()
274 QSettings settings(m_console->m_dir->name(), "bat");
275 settings.beginGroup(m_groupText);
276 settings.setValue(m_splitText, splitter->saveState());
281 * Read and restore user settings associated with this page
283 void ClientStat::readSettings()
285 m_groupText = "ClientStatPage";
286 m_splitText = "splitterSizes_0";
287 QSettings settings(m_console->m_dir->name(), "bat");
288 settings.beginGroup(m_groupText);
289 splitter->restoreState(settings.value(m_splitText).toByteArray());
294 * Cancel a running job
296 void ClientStat::consoleCancelJob()
298 int currentrow = runningTable->currentRow();
299 QTableWidgetItem *item = runningTable->item(currentrow, 0);
301 QString text = item->text();
302 QString cmd("cancel jobid=");