]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/status/dirstat.cpp
Add preference to have the status dir screen auto refresh.
[bacula/bacula] / bacula / src / qt-console / status / dirstat.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 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 = tr("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_refreshStatusDirInterval*1000);
57 }
58
59 void DirStat::getFont()
60 {
61    QFont font = textEdit->font();
62
63    QString dirname;
64    m_console->getDirResName(dirname);
65    QSettings settings(dirname, "bat");
66    settings.beginGroup("Console");
67    font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
68    font.setPointSize(settings.value("consolePointSize", 10).toInt());
69    font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
70    settings.endGroup();
71    textEdit->setFont(font);
72 }
73
74 /*
75  * Write the m_splitter settings in the destructor
76  */
77 DirStat::~DirStat()
78 {
79    writeSettings();
80 }
81
82 /*
83  * Populate all tables and header widgets
84  */
85 void DirStat::populateAll()
86 {
87    if (!m_console->preventInUseConnect())
88        return;
89    populateHeader();
90    populateTerminated();
91    populateScheduled();
92    populateRunning();
93 }
94
95 /*
96  *  Timer is triggered, see if is current and repopulate.
97  */
98 void DirStat::timerTriggered()
99 {
100    bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
101    if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
102       if (m_console->is_ready())
103          populateAll();
104    }
105 }
106
107 /*
108  * Populate header text widget
109  */
110 void DirStat::populateHeader()
111 {
112    QString command = QString(".status dir header");
113    QStringList results;
114    textEdit->clear();
115
116    if (m_console->dir_cmd(command, results)) {
117       foreach (QString line, results) {
118          line += "\n";
119          textEdit->insertPlainText(line);
120       }
121    }
122 }
123
124 /*
125  * Populate teminated table
126  */
127 void DirStat::populateTerminated()
128 {
129    QString command = QString(".status dir terminated");
130    QStringList results;
131    QBrush blackBrush(Qt::black);
132
133    terminatedTable->clear();
134    QStringList headerlist = (QStringList()
135       << tr("Job Id") << tr("Job Level") << tr("Job Files")
136       << tr("Job Bytes") << tr("Job Status") << tr("Job Time") 
137       << tr("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       << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time") 
190       << tr("Job Name") << tr("Volume"));
191    QStringList flaglist = (QStringList()
192       << "L" << "L" << "R" << "L" << "L" << "L");
193
194    scheduledTable->setColumnCount(headerlist.size());
195    scheduledTable->setHorizontalHeaderLabels(headerlist);
196
197    if (m_console->dir_cmd(command, results)) {
198       int row = 0;
199       QTableWidgetItem* p_tableitem;
200       scheduledTable->setRowCount(results.size());
201       foreach (QString line, results) {
202          /* Iterate through the record returned from the query */
203          QStringList fieldlist = line.split("\t");
204          int column = 0;
205          QString statusCode("");
206          /* Iterate through fields in the record */
207          foreach (QString field, fieldlist) {
208             field = field.trimmed();  /* strip leading & trailing spaces */
209             p_tableitem = new QTableWidgetItem(field, 1);
210             p_tableitem->setForeground(blackBrush);
211             p_tableitem->setFlags(0);
212             scheduledTable->setItem(row, column, p_tableitem);
213             column += 1;
214          }
215          row += 1;
216       }
217    }
218    scheduledTable->resizeColumnsToContents();
219    scheduledTable->resizeRowsToContents();
220    scheduledTable->verticalHeader()->hide();
221 }
222
223 /*
224  * Populate running table
225  */
226 void DirStat::populateRunning()
227 {
228    QString command = QString(".status dir running");
229    QStringList results;
230    QBrush blackBrush(Qt::black);
231
232    runningTable->clear();
233    QStringList headerlist = (QStringList()
234       << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
235
236    runningTable->setColumnCount(headerlist.size());
237    runningTable->setHorizontalHeaderLabels(headerlist);
238
239    if (m_console->dir_cmd(command, results)) {
240       int row = 0;
241       QTableWidgetItem* p_tableitem;
242       runningTable->setRowCount(results.size());
243       foreach (QString line, results) {
244          /* Iterate through the record returned from the query */
245          QStringList fieldlist = line.split("\t");
246          int column = 0;
247          QString statusCode("");
248          /* Iterate through fields in the record */
249          foreach (QString field, fieldlist) {
250             field = field.trimmed();  /* strip leading & trailing spaces */
251             p_tableitem = new QTableWidgetItem(field, 1);
252             p_tableitem->setForeground(blackBrush);
253             p_tableitem->setFlags(0);
254             runningTable->setItem(row, column, p_tableitem);
255             column += 1;
256          }
257          row += 1;
258       }
259    }
260    runningTable->resizeColumnsToContents();
261    runningTable->resizeRowsToContents();
262    runningTable->verticalHeader()->hide();
263 }
264
265 /*
266  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
267  * The tree has been populated.
268  */
269 void DirStat::PgSeltreeWidgetClicked()
270 {
271    if (!m_populated) {
272       populateAll();
273       m_populated=true;
274    }
275 }
276
277 /*
278  *  Virtual function override of pages function which is called when this page
279  *  is visible on the stack
280  */
281 void DirStat::currentStackItem()
282 {
283    populateAll();
284    if (!m_populated) {
285       m_populated=true;
286    }
287 }
288
289 /*
290  * Function to create connections for context sensitive menu for this and
291  * the page selector
292  */
293 void DirStat::createConnections()
294 {
295 }
296
297 /*
298  * Save user settings associated with this page
299  */
300 void DirStat::writeSettings()
301 {
302    QSettings settings(m_console->m_dir->name(), "bat");
303    settings.beginGroup(m_groupText);
304    settings.setValue(m_splitText, splitter->saveState());
305    settings.endGroup();
306 }
307
308 /*
309  * Read and restore user settings associated with this page
310  */
311 void DirStat::readSettings()
312 {
313    m_groupText = "DirStatPage";
314    m_splitText = "splitterSizes_0";
315    QSettings settings(m_console->m_dir->name(), "bat");
316    settings.beginGroup(m_groupText);
317    splitter->restoreState(settings.value(m_splitText).toByteArray());
318    settings.endGroup();
319 }