]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/status/dirstat.cpp
Changes to add a status dir page. Still need to add some context sensitive
[bacula/bacula] / bacula / src / qt-console / status / dirstat.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2007 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 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.
27 */
28 /*
29  *   Version $Id: dirstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
30  *
31  *   Dirk Bartley, March 2007
32  */
33  
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
36 #include "bat.h"
37 #include "dirstat.h"
38
39 /*
40  * Constructor for the class
41  */
42 DirStat::DirStat()
43 {
44    setupUi(this);
45    m_name = "Director Status";
46    m_closeable = true;
47    pgInitialize();
48    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
50    m_cursor = new QTextCursor(textEdit->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_checkMessagesInterval*1000);
57    m_timer->start(10*1000);
58 }
59
60 void DirStat::getFont()
61 {
62    QFont font = textEdit->font();
63
64    QString dirname;
65    m_console->getDirResName(dirname);
66    QSettings settings(dirname, "bat");
67    settings.beginGroup("Console");
68    font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
69    font.setPointSize(settings.value("consolePointSize", 10).toInt());
70    font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
71    settings.endGroup();
72    textEdit->setFont(font);
73 }
74
75 /*
76  * Write the m_splitter settings in the destructor
77  */
78 DirStat::~DirStat()
79 {
80    writeSettings();
81 }
82
83 /*
84  * Populate all tables and header widgets
85  */
86 void DirStat::populateAll()
87 {
88    if (!m_console->preventInUseConnect())
89        return;
90    populateHeader();
91    populateTerminated();
92    populateScheduled();
93    populateRunning();
94 }
95
96 /*
97  *  Timer is triggered, see if is current and repopulate.
98  */
99 void DirStat::timerTriggered()
100 {
101    bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
102    if ((isDocked() && iscurrent) || (!isDocked())) {
103       if (m_console->is_ready())
104          populateAll();
105    }
106 }
107
108 /*
109  * Populate header text widget
110  */
111 void DirStat::populateHeader()
112 {
113    QString command = QString(".status dir header");
114    QStringList results;
115    textEdit->clear();
116
117    if (m_console->dir_cmd(command, results)) {
118       foreach (QString line, results) {
119          line += "\n";
120          textEdit->insertPlainText(line);
121       }
122    }
123 }
124
125 /*
126  * Populate teminated table
127  */
128 void DirStat::populateTerminated()
129 {
130    QString command = QString(".status dir terminated");
131    QStringList results;
132    QBrush blackBrush(Qt::black);
133
134    terminatedTable->clear();
135    QStringList headerlist = (QStringList()
136       << "Job Id" << "Job Level" << "Job Files" << "Job Bytes" << "Job Status"
137       << "Job Time" << "Job Name");
138    QStringList flaglist = (QStringList()
139       << "R" << "L" << "R" << "R" << "LC" 
140       << "L" << "L");
141
142    terminatedTable->setColumnCount(headerlist.size());
143    terminatedTable->setHorizontalHeaderLabels(headerlist);
144
145    if (m_console->dir_cmd(command, results)) {
146       int row = 0;
147       QTableWidgetItem* p_tableitem;
148       terminatedTable->setRowCount(results.size());
149       foreach (QString line, results) {
150          /* Iterate through the record returned from the query */
151          QStringList fieldlist = line.split("\t");
152          int column = 0;
153          QString statusCode("");
154          /* Iterate through fields in the record */
155          foreach (QString field, fieldlist) {
156             field = field.trimmed();  /* strip leading & trailing spaces */
157             p_tableitem = new QTableWidgetItem(field, 1);
158             p_tableitem->setForeground(blackBrush);
159             p_tableitem->setFlags(0);
160             if (flaglist[column].contains("R"))
161                p_tableitem->setTextAlignment(Qt::AlignRight);
162             if (flaglist[column].contains("C"))
163                if (field == "OK")
164                   p_tableitem->setBackground(Qt::green);
165                else
166                   p_tableitem->setBackground(Qt::red);
167             terminatedTable->setItem(row, column, p_tableitem);
168             column += 1;
169          }
170          row += 1;
171       }
172    }
173    terminatedTable->resizeColumnsToContents();
174    terminatedTable->resizeRowsToContents();
175    terminatedTable->verticalHeader()->hide();
176 }
177
178 /*
179  * Populate scheduled table
180  */
181 void DirStat::populateScheduled()
182 {
183    QString command = QString(".status dir scheduled");
184    QStringList results;
185    QBrush blackBrush(Qt::black);
186
187    scheduledTable->clear();
188    QStringList headerlist = (QStringList()
189       << "Job Level" << "Job Type" << "Priority" << "Job Time" << "Job Name" << "Volume");
190    QStringList flaglist = (QStringList()
191       << "L" << "L" << "R" << "L" << "L" << "L");
192
193    scheduledTable->setColumnCount(headerlist.size());
194    scheduledTable->setHorizontalHeaderLabels(headerlist);
195
196    if (m_console->dir_cmd(command, results)) {
197       int row = 0;
198       QTableWidgetItem* p_tableitem;
199       scheduledTable->setRowCount(results.size());
200       foreach (QString line, results) {
201          /* Iterate through the record returned from the query */
202          QStringList fieldlist = line.split("\t");
203          int column = 0;
204          QString statusCode("");
205          /* Iterate through fields in the record */
206          foreach (QString field, fieldlist) {
207             field = field.trimmed();  /* strip leading & trailing spaces */
208             p_tableitem = new QTableWidgetItem(field, 1);
209             p_tableitem->setForeground(blackBrush);
210             p_tableitem->setFlags(0);
211             scheduledTable->setItem(row, column, p_tableitem);
212             column += 1;
213          }
214          row += 1;
215       }
216    }
217    scheduledTable->resizeColumnsToContents();
218    scheduledTable->resizeRowsToContents();
219    scheduledTable->verticalHeader()->hide();
220 }
221
222 /*
223  * Populate running table
224  */
225 void DirStat::populateRunning()
226 {
227    QString command = QString(".status dir running");
228    QStringList results;
229    QBrush blackBrush(Qt::black);
230
231    runningTable->clear();
232    QStringList headerlist = (QStringList()
233       << "Job Id" << "Job Level" << "Job Data" << "Job Info");
234
235    runningTable->setColumnCount(headerlist.size());
236    runningTable->setHorizontalHeaderLabels(headerlist);
237
238    if (m_console->dir_cmd(command, results)) {
239       int row = 0;
240       QTableWidgetItem* p_tableitem;
241       runningTable->setRowCount(results.size());
242       foreach (QString line, results) {
243          /* Iterate through the record returned from the query */
244          QStringList fieldlist = line.split("\t");
245          int column = 0;
246          QString statusCode("");
247          /* Iterate through fields in the record */
248          foreach (QString field, fieldlist) {
249             field = field.trimmed();  /* strip leading & trailing spaces */
250             p_tableitem = new QTableWidgetItem(field, 1);
251             p_tableitem->setForeground(blackBrush);
252             p_tableitem->setFlags(0);
253             runningTable->setItem(row, column, p_tableitem);
254             column += 1;
255          }
256          row += 1;
257       }
258    }
259    runningTable->resizeColumnsToContents();
260    runningTable->resizeRowsToContents();
261    runningTable->verticalHeader()->hide();
262 }
263
264 /*
265  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
266  * The tree has been populated.
267  */
268 void DirStat::PgSeltreeWidgetClicked()
269 {
270    if (!m_populated) {
271       populateAll();
272       m_populated=true;
273    }
274 }
275
276 /*
277  *  Virtual function override of pages function which is called when this page
278  *  is visible on the stack
279  */
280 void DirStat::currentStackItem()
281 {
282    populateAll();
283    if (!m_populated) {
284       m_populated=true;
285    }
286 }
287
288 /*
289  * Function to create connections for context sensitive menu for this and
290  * the page selector
291  */
292 void DirStat::createConnections()
293 {
294 }
295
296 /*
297  * Save user settings associated with this page
298  */
299 void DirStat::writeSettings()
300 {
301    QSettings settings(m_console->m_dir->name(), "bat");
302    settings.beginGroup(m_groupText);
303    settings.setValue(m_splitText, splitter->saveState());
304    settings.endGroup();
305 }
306
307 /*
308  * Read and restore user settings associated with this page
309  */
310 void DirStat::readSettings()
311 {
312    m_groupText = "DirStatPage";
313    m_splitText = "splitterSizes_0";
314    QSettings settings(m_console->m_dir->name(), "bat");
315    settings.beginGroup(m_groupText);
316    splitter->restoreState(settings.value(m_splitText).toByteArray());
317    settings.endGroup();
318 }