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 * Constructor for the class
42 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
46 m_name = tr("Client Status");
48 pgInitialize(parentTreeWidgetItem);
49 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
50 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
51 m_cursor = new QTextCursor(textEditHeader->document());
55 m_timer = new QTimer(this);
56 QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
57 m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
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()
91 if (!m_console->preventInUseConnect())
99 * Timer is triggered, see if is current and repopulate.
101 void ClientStat::timerTriggered()
103 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
104 if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
105 if (m_console->is_ready())
111 * Populate header text widget
113 void ClientStat::populateHeader()
115 QString command = QString(".status client=\"" + m_client + "\" header");
117 textEditHeader->clear();
119 if (m_console->dir_cmd(command, results)) {
120 foreach (QString line, results) {
122 textEditHeader->insertPlainText(line);
128 * Populate teminated table
130 void ClientStat::populateTerminated()
132 QString command = QString(".status client=\"" + m_client + "\" terminated");
134 QBrush blackBrush(Qt::black);
136 terminatedTable->clear();
137 QStringList headerlist = (QStringList()
138 << tr("Job Id") << tr("Job Level") << tr("Job Files")
139 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
141 QStringList flaglist = (QStringList()
142 << "R" << "L" << "R" << "R" << "LC"
145 terminatedTable->setColumnCount(headerlist.size());
146 terminatedTable->setHorizontalHeaderLabels(headerlist);
148 if (m_console->dir_cmd(command, results)) {
150 QTableWidgetItem* p_tableitem;
151 terminatedTable->setRowCount(results.size());
152 foreach (QString line, results) {
153 /* Iterate through the record returned from the query */
154 QStringList fieldlist = line.split("\t");
156 QString statusCode("");
157 /* Iterate through fields in the record */
158 foreach (QString field, fieldlist) {
159 field = field.trimmed(); /* strip leading & trailing spaces */
160 p_tableitem = new QTableWidgetItem(field, 1);
161 p_tableitem->setForeground(blackBrush);
162 p_tableitem->setFlags(0);
163 if (flaglist[column].contains("R"))
164 p_tableitem->setTextAlignment(Qt::AlignRight);
165 if (flaglist[column].contains("C"))
167 p_tableitem->setBackground(Qt::green);
169 p_tableitem->setBackground(Qt::red);
170 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
176 terminatedTable->resizeColumnsToContents();
177 terminatedTable->resizeRowsToContents();
178 terminatedTable->verticalHeader()->hide();
182 * Populate running text
184 void ClientStat::populateRunning()
186 QString command = QString(".status client=\"" + m_client + "\" running");
187 Pmsg1(100, "Clients running cmd : %s\n",command.toUtf8().data());
189 textEditRunning->clear();
191 if (m_console->dir_cmd(command, results)) {
192 foreach (QString line, results) {
194 textEditRunning->insertPlainText(line);
200 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
201 * The tree has been populated.
203 void ClientStat::PgSeltreeWidgetClicked()
212 * Virtual function override of pages function which is called when this page
213 * is visible on the stack
215 void ClientStat::currentStackItem()
224 * Function to create connections for context sensitive menu for this and
227 void ClientStat::createConnections()
229 connect(actionRefresh, SIGNAL(triggered()), this,
230 SLOT(populateAll()));
234 * Save user settings associated with this page
236 void ClientStat::writeSettings()
238 QSettings settings(m_console->m_dir->name(), "bat");
239 settings.beginGroup(m_groupText);
240 settings.setValue(m_splitText, splitter->saveState());
245 * Read and restore user settings associated with this page
247 void ClientStat::readSettings()
249 m_groupText = "ClientStatPage";
250 m_splitText = "splitterSizes_1";
251 QSettings settings(m_console->m_dir->name(), "bat");
252 settings.beginGroup(m_groupText);
253 splitter->restoreState(settings.value(m_splitText).toByteArray());