]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/status/dirstat.cpp
move tranlations to ts + minor cleanups
[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_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       << tr("Job Id") << tr("Job Level") << tr("Job Files")
137       << tr("Job Bytes") << tr("Job Status") << tr("Job Time") 
138       << tr("Job Name"));
139    QStringList flaglist = (QStringList()
140       << "R" << "L" << "R" << "R" << "LC" 
141       << "L" << "L");
142
143    terminatedTable->setColumnCount(headerlist.size());
144    terminatedTable->setHorizontalHeaderLabels(headerlist);
145
146    if (m_console->dir_cmd(command, results)) {
147       int row = 0;
148       QTableWidgetItem* p_tableitem;
149       terminatedTable->setRowCount(results.size());
150       foreach (QString line, results) {
151          /* Iterate through the record returned from the query */
152          QStringList fieldlist = line.split("\t");
153          int column = 0;
154          QString statusCode("");
155          /* Iterate through fields in the record */
156          foreach (QString field, fieldlist) {
157             field = field.trimmed();  /* strip leading & trailing spaces */
158             p_tableitem = new QTableWidgetItem(field, 1);
159             p_tableitem->setForeground(blackBrush);
160             p_tableitem->setFlags(0);
161             if (flaglist[column].contains("R"))
162                p_tableitem->setTextAlignment(Qt::AlignRight);
163             if (flaglist[column].contains("C"))
164                if (field == "OK")
165                   p_tableitem->setBackground(Qt::green);
166                else
167                   p_tableitem->setBackground(Qt::red);
168             terminatedTable->setItem(row, column, p_tableitem);
169             column += 1;
170          }
171          row += 1;
172       }
173    }
174    terminatedTable->resizeColumnsToContents();
175    terminatedTable->resizeRowsToContents();
176    terminatedTable->verticalHeader()->hide();
177 }
178
179 /*
180  * Populate scheduled table
181  */
182 void DirStat::populateScheduled()
183 {
184    QString command = QString(".status dir scheduled");
185    QStringList results;
186    QBrush blackBrush(Qt::black);
187
188    scheduledTable->clear();
189    QStringList headerlist = (QStringList()
190       << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time") 
191       << tr("Job Name") << tr("Volume"));
192    QStringList flaglist = (QStringList()
193       << "L" << "L" << "R" << "L" << "L" << "L");
194
195    scheduledTable->setColumnCount(headerlist.size());
196    scheduledTable->setHorizontalHeaderLabels(headerlist);
197
198    if (m_console->dir_cmd(command, results)) {
199       int row = 0;
200       QTableWidgetItem* p_tableitem;
201       scheduledTable->setRowCount(results.size());
202       foreach (QString line, results) {
203          /* Iterate through the record returned from the query */
204          QStringList fieldlist = line.split("\t");
205          int column = 0;
206          QString statusCode("");
207          /* Iterate through fields in the record */
208          foreach (QString field, fieldlist) {
209             field = field.trimmed();  /* strip leading & trailing spaces */
210             p_tableitem = new QTableWidgetItem(field, 1);
211             p_tableitem->setForeground(blackBrush);
212             p_tableitem->setFlags(0);
213             scheduledTable->setItem(row, column, p_tableitem);
214             column += 1;
215          }
216          row += 1;
217       }
218    }
219    scheduledTable->resizeColumnsToContents();
220    scheduledTable->resizeRowsToContents();
221    scheduledTable->verticalHeader()->hide();
222 }
223
224 /*
225  * Populate running table
226  */
227 void DirStat::populateRunning()
228 {
229    QString command = QString(".status dir running");
230    QStringList results;
231    QBrush blackBrush(Qt::black);
232
233    runningTable->clear();
234    QStringList headerlist = (QStringList()
235       << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
236
237    runningTable->setColumnCount(headerlist.size());
238    runningTable->setHorizontalHeaderLabels(headerlist);
239
240    if (m_console->dir_cmd(command, results)) {
241       int row = 0;
242       QTableWidgetItem* p_tableitem;
243       runningTable->setRowCount(results.size());
244       foreach (QString line, results) {
245          /* Iterate through the record returned from the query */
246          QStringList fieldlist = line.split("\t");
247          int column = 0;
248          QString statusCode("");
249          /* Iterate through fields in the record */
250          foreach (QString field, fieldlist) {
251             field = field.trimmed();  /* strip leading & trailing spaces */
252             p_tableitem = new QTableWidgetItem(field, 1);
253             p_tableitem->setForeground(blackBrush);
254             p_tableitem->setFlags(0);
255             runningTable->setItem(row, column, p_tableitem);
256             column += 1;
257          }
258          row += 1;
259       }
260    }
261    runningTable->resizeColumnsToContents();
262    runningTable->resizeRowsToContents();
263    runningTable->verticalHeader()->hide();
264 }
265
266 /*
267  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
268  * The tree has been populated.
269  */
270 void DirStat::PgSeltreeWidgetClicked()
271 {
272    if (!m_populated) {
273       populateAll();
274       m_populated=true;
275    }
276 }
277
278 /*
279  *  Virtual function override of pages function which is called when this page
280  *  is visible on the stack
281  */
282 void DirStat::currentStackItem()
283 {
284    populateAll();
285    if (!m_populated) {
286       m_populated=true;
287    }
288 }
289
290 /*
291  * Function to create connections for context sensitive menu for this and
292  * the page selector
293  */
294 void DirStat::createConnections()
295 {
296 }
297
298 /*
299  * Save user settings associated with this page
300  */
301 void DirStat::writeSettings()
302 {
303    QSettings settings(m_console->m_dir->name(), "bat");
304    settings.beginGroup(m_groupText);
305    settings.setValue(m_splitText, splitter->saveState());
306    settings.endGroup();
307 }
308
309 /*
310  * Read and restore user settings associated with this page
311  */
312 void DirStat::readSettings()
313 {
314    m_groupText = "DirStatPage";
315    m_splitText = "splitterSizes_0";
316    QSettings settings(m_console->m_dir->name(), "bat");
317    settings.beginGroup(m_groupText);
318    splitter->restoreState(settings.value(m_splitText).toByteArray());
319    settings.endGroup();
320 }