]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/status/clientstat.cpp
kes Reduce bconsole help to fit in 80 columns
[bacula/bacula] / bacula / src / qt-console / status / clientstat.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
5
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
11    in the file LICENSE.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28 /*
29  *   Version $Id: clientstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
30  *
31  *   Dirk Bartley, March 2007
32  */
33  
34 #include "bat.h"
35 #include <QAbstractEventDispatcher>
36 #include <QTableWidgetItem>
37 #include "clientstat.h"
38
39 /*
40  * Constructor for the class
41  */
42 ClientStat::ClientStat(QString &client, QTreeWidgetItem *parentTreeWidgetItem)
43 {
44    m_client = client;
45    setupUi(this);
46    m_closeable = true;
47    pgInitialize(tr("Client Status %1").arg(m_client), parentTreeWidgetItem);
48    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
50    m_cursor = new QTextCursor(textEditHeader->document());
51
52    readSettings();
53    dockPage();
54    m_timer = new QTimer(this);
55    QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
56    m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
57
58    createConnections();
59    setCurrent();
60 }
61
62 void ClientStat::getFont()
63 {
64    QFont font = textEditHeader->font();
65
66    QString dirname;
67    m_console->getDirResName(dirname);
68    QSettings settings(dirname, "bat");
69    settings.beginGroup("Console");
70    font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
71    font.setPointSize(settings.value("consolePointSize", 10).toInt());
72    font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
73    settings.endGroup();
74    textEditHeader->setFont(font);
75 }
76
77 /*
78  * Write the m_splitter settings in the destructor
79  */
80 ClientStat::~ClientStat()
81 {
82    writeSettings();
83 }
84
85 /*
86  * Populate all tables and header widgets
87  */
88 void ClientStat::populateAll()
89 {
90    populateHeader();
91    populateTerminated();
92    populateRunning();
93 }
94
95 /*
96  *  Timer is triggered, see if is current and repopulate.
97  */
98 void ClientStat::timerTriggered()
99 {
100    bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
101    if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
102       populateAll();
103    }
104 }
105
106 /*
107  * Populate header text widget
108  */
109 void ClientStat::populateHeader()
110 {
111    QString command = QString(".status client=\"" + m_client + "\" header");
112    if (mainWin->m_commandDebug)
113       Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
114    QStringList results;
115    textEditHeader->clear();
116
117    if (m_console->dir_cmd(command, results)) {
118       foreach (QString line, results) {
119          line += "\n";
120          textEditHeader->insertPlainText(line);
121       }
122    }
123 }
124
125 /*
126  * Populate teminated table
127  */
128 void ClientStat::populateTerminated()
129 {
130    QString command = QString(".status client=\"" + m_client + "\" terminated");
131    if (mainWin->m_commandDebug)
132       Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
133    QStringList results;
134    QBrush blackBrush(Qt::black);
135
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")
140       << tr("Job Name"));
141    QStringList flaglist = (QStringList()
142       << "R" << "L" << "R" << "R" << "LC"
143       << "L" << "L");
144
145    terminatedTable->setColumnCount(headerlist.size());
146    terminatedTable->setHorizontalHeaderLabels(headerlist);
147
148    if (m_console->dir_cmd(command, results)) {
149       int row = 0;
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");
155          int column = 0;
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")) {
166                if (field == "OK")
167                   p_tableitem->setBackground(Qt::green);
168                else
169                  p_tableitem->setBackground(Qt::red);
170             }
171             terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
172             column += 1;
173          }
174          row += 1;
175       }
176    }
177    terminatedTable->resizeColumnsToContents();
178    terminatedTable->resizeRowsToContents();
179    terminatedTable->verticalHeader()->hide();
180 }
181
182 /*
183  * Populate running text
184  */
185 void ClientStat::populateRunning()
186 {
187    QString command = QString(".status client=\"" + m_client + "\" running");
188    if (mainWin->m_commandDebug)
189       Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
190    QStringList results;
191    textEditRunning->clear();
192
193    if (m_console->dir_cmd(command, results)) {
194       foreach (QString line, results) {
195          line += "\n";
196          textEditRunning->insertPlainText(line);
197       }
198    }
199 }
200
201 /*
202  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
203  * The tree has been populated.
204  */
205 void ClientStat::PgSeltreeWidgetClicked()
206 {
207    if (!m_populated) {
208       populateAll();
209       m_populated=true;
210    }
211 }
212
213 /*
214  *  Virtual function override of pages function which is called when this page
215  *  is visible on the stack
216  */
217 void ClientStat::currentStackItem()
218 {
219    populateAll();
220    if (!m_populated) {
221       m_populated=true;
222    }
223 }
224
225 /*
226  * Function to create connections for context sensitive menu for this and
227  * the page selector
228  */
229 void ClientStat::createConnections()
230 {
231    connect(actionRefresh, SIGNAL(triggered()), this,
232                    SLOT(populateAll()));
233 }
234
235 /*
236  * Save user settings associated with this page
237  */
238 void ClientStat::writeSettings()
239 {
240    QSettings settings(m_console->m_dir->name(), "bat");
241    settings.beginGroup(m_groupText);
242    settings.setValue(m_splitText, splitter->saveState());
243    settings.endGroup();
244 }
245
246 /*
247  * Read and restore user settings associated with this page
248  */
249 void ClientStat::readSettings()
250 {
251    m_groupText = "ClientStatPage";
252    m_splitText = "splitterSizes_1";
253    QSettings settings(m_console->m_dir->name(), "bat");
254    settings.beginGroup(m_groupText);
255    splitter->restoreState(settings.value(m_splitText).toByteArray());
256    settings.endGroup();
257 }