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 many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
17 * Dirk Bartley, March 2007
21 #include <QAbstractEventDispatcher>
22 #include <QTableWidgetItem>
23 #include "clientstat.h"
25 /* This probably should be on a mutex */
26 static bool working = false; /* prevent timer recursion */
29 * Constructor for the class
31 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
36 pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
37 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
38 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
39 m_cursor = new QTextCursor(textEditHeader->document());
43 m_timer = new QTimer(this);
50 void ClientStat::getFont()
52 QFont font = textEditHeader->font();
55 m_console->getDirResName(dirname);
56 QSettings settings(dirname, "bat");
57 settings.beginGroup("Console");
58 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
59 font.setPointSize(settings.value("consolePointSize", 10).toInt());
60 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
62 textEditHeader->setFont(font);
66 * Write the m_splitter settings in the destructor
68 ClientStat::~ClientStat()
74 * Populate all tables and header widgets
76 void ClientStat::populateAll()
79 populateCurrentTab(tabWidget->currentIndex());
83 * Timer is triggered, see if is current and repopulate.
85 void ClientStat::timerTriggered()
87 double value = timerDisplay->value();
89 if (value <= 0 && !working) {
91 value = spinBox->value();
92 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
93 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
98 timerDisplay->display(value);
102 void ClientStat::populateCurrentTab(int index)
111 * Populate header text widget
113 void ClientStat::populateHeader()
115 QString command = QString(".status client=\"" + m_client + "\" header");
116 if (mainWin->m_commandDebug)
117 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
119 textEditHeader->clear();
121 if (m_console->dir_cmd(command, results)) {
122 foreach (QString line, results) {
124 textEditHeader->insertPlainText(line);
130 * Populate teminated table
132 void ClientStat::populateTerminated()
134 QString command = QString(".status client=\"" + m_client + "\" terminated");
135 if (mainWin->m_commandDebug)
136 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
138 QBrush blackBrush(Qt::black);
140 terminatedTable->clear();
141 QStringList headerlist = (QStringList()
142 << tr("Job Id") << tr("Job Level") << tr("Job Files")
143 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
145 QStringList flaglist = (QStringList()
146 << "R" << "L" << "R" << "R" << "LC"
149 terminatedTable->setColumnCount(headerlist.size());
150 terminatedTable->setHorizontalHeaderLabels(headerlist);
152 if (m_console->dir_cmd(command, results)) {
154 QTableWidgetItem* p_tableitem;
155 terminatedTable->setRowCount(results.size());
156 foreach (QString line, results) {
157 /* Iterate through the record returned from the query */
158 QStringList fieldlist = line.split("\t");
160 QString statusCode("");
161 /* Iterate through fields in the record */
162 foreach (QString field, fieldlist) {
163 field = field.trimmed(); /* strip leading & trailing spaces */
164 p_tableitem = new QTableWidgetItem(field, 1);
165 p_tableitem->setForeground(blackBrush);
166 p_tableitem->setFlags(0);
167 if (flaglist[column].contains("R"))
168 p_tableitem->setTextAlignment(Qt::AlignRight);
169 if (flaglist[column].contains("C")) {
171 p_tableitem->setBackground(Qt::green);
173 p_tableitem->setBackground(Qt::red);
175 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
181 terminatedTable->resizeColumnsToContents();
182 terminatedTable->resizeRowsToContents();
183 terminatedTable->verticalHeader()->hide();
187 * Populate running text
189 void ClientStat::populateRunning()
191 QString command = QString(".status client=\"" + m_client + "\" running");
192 if (mainWin->m_commandDebug)
193 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
195 textEditRunning->clear();
197 if (m_console->dir_cmd(command, results)) {
198 foreach (QString line, results) {
200 textEditRunning->insertPlainText(line);
206 * When the treeWidgetItem in the page selector tree is single clicked, Make sure
207 * The tree has been populated.
209 void ClientStat::PgSeltreeWidgetClicked()
218 * Virtual function override of pages function which is called when this page
219 * is visible on the stack
221 void ClientStat::currentStackItem()
224 timerDisplay->display(spinBox->value());
232 * Function to create connections for context sensitive menu for this and
235 void ClientStat::createConnections()
237 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
238 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
239 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
240 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
241 terminatedTable->addAction(actionRefresh);
245 * Save user settings associated with this page
247 void ClientStat::writeSettings()
249 QSettings settings(m_console->m_dir->name(), "bat");
250 settings.beginGroup(m_groupText);
251 settings.setValue(m_splitText, splitter->saveState());
252 settings.setValue("refreshInterval", spinBox->value());
253 settings.setValue("refreshCheck", checkBox->checkState());
256 settings.beginGroup("OpenOnExit");
257 QString toWrite = "ClientStatus_" + m_client;
258 settings.setValue(toWrite, 1);
263 * Read and restore user settings associated with this page
265 void ClientStat::readSettings()
267 m_groupText = "ClientStatPage";
268 m_splitText = "splitterSizes_1";
269 QSettings settings(m_console->m_dir->name(), "bat");
270 settings.beginGroup(m_groupText);
271 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
272 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
273 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
276 timerDisplay->display(spinBox->value());