2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2010 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 three of the GNU Affero 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 Affero 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 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.
30 * Dirk Bartley, March 2007
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
38 static bool working = false; /* prevent timer recursion */
41 * Constructor for the class
43 DirStat::DirStat() : Pages()
46 m_name = tr("Director Status");
48 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
50 m_cursor = new QTextCursor(textEdit->document());
52 m_timer = new QTimer(this);
60 void DirStat::getFont()
62 QFont font = textEdit->font();
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());
72 textEdit->setFont(font);
76 * Write the m_splitter settings in the destructor
84 * Populate all tables and header widgets
86 void DirStat::populateAll()
95 * Timer is triggered, see if is current and repopulate.
97 void DirStat::timerTriggered()
99 double value = timerDisplay->value();
101 if (value <= 0 && !working) {
103 value = spinBox->value();
104 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
105 if (((isDocked() && iscurrent) || ((!isDocked()) && isOnceDocked())) && (checkBox->checkState() == Qt::Checked)) {
110 timerDisplay->display(value);
114 * Populate header text widget
116 void DirStat::populateHeader()
118 QString command = QString(".status dir header");
119 if (mainWin->m_commandDebug)
120 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
124 if (m_console->dir_cmd(command, results)) {
125 foreach (QString line, results) {
127 textEdit->insertPlainText(line);
133 * Populate teminated table
135 void DirStat::populateTerminated()
137 QString command = QString(".status dir terminated");
138 if (mainWin->m_commandDebug)
139 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
141 QBrush blackBrush(Qt::black);
143 terminatedTable->clear();
144 QStringList headerlist = (QStringList()
145 << tr("Job Id") << tr("Job Level") << tr("Job Files")
146 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
148 QStringList flaglist = (QStringList()
149 << "R" << "L" << "R" << "R" << "LC"
152 terminatedTable->setColumnCount(headerlist.size());
153 terminatedTable->setHorizontalHeaderLabels(headerlist);
155 if (m_console->dir_cmd(command, results)) {
157 QTableWidgetItem* p_tableitem;
158 terminatedTable->setRowCount(results.size());
159 foreach (QString line, results) {
160 /* Iterate through the record returned from the query */
161 QStringList fieldlist = line.split("\t");
163 QString statusCode("");
164 /* Iterate through fields in the record */
165 foreach (QString field, fieldlist) {
166 field = field.trimmed(); /* strip leading & trailing spaces */
167 p_tableitem = new QTableWidgetItem(field, 1);
168 p_tableitem->setForeground(blackBrush);
169 p_tableitem->setFlags(0);
170 if (flaglist[column].contains("R"))
171 p_tableitem->setTextAlignment(Qt::AlignRight);
172 if (flaglist[column].contains("C")) {
174 p_tableitem->setBackground(Qt::green);
176 p_tableitem->setBackground(Qt::red);
178 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
184 terminatedTable->resizeColumnsToContents();
185 terminatedTable->resizeRowsToContents();
186 terminatedTable->verticalHeader()->hide();
190 * Populate scheduled table
192 void DirStat::populateScheduled()
194 QString command = QString(".status dir scheduled");
195 if (mainWin->m_commandDebug)
196 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
198 QBrush blackBrush(Qt::black);
200 scheduledTable->clear();
201 QStringList headerlist = (QStringList()
202 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
203 << tr("Job Name") << tr("Volume"));
204 QStringList flaglist = (QStringList()
205 << "L" << "L" << "R" << "L" << "L" << "L");
207 scheduledTable->setColumnCount(headerlist.size());
208 scheduledTable->setHorizontalHeaderLabels(headerlist);
209 scheduledTable->setSelectionBehavior(QAbstractItemView::SelectRows);
210 scheduledTable->setSelectionMode(QAbstractItemView::SingleSelection);
212 if (m_console->dir_cmd(command, results)) {
214 QTableWidgetItem* p_tableitem;
215 scheduledTable->setRowCount(results.size());
216 foreach (QString line, results) {
217 /* Iterate through the record returned from the query */
218 QStringList fieldlist = line.split("\t");
220 QString statusCode("");
221 /* Iterate through fields in the record */
222 foreach (QString field, fieldlist) {
223 field = field.trimmed(); /* strip leading & trailing spaces */
224 p_tableitem = new QTableWidgetItem(field, 1);
225 p_tableitem->setForeground(blackBrush);
226 scheduledTable->setItem(row, column, p_tableitem);
232 scheduledTable->resizeColumnsToContents();
233 scheduledTable->resizeRowsToContents();
234 scheduledTable->verticalHeader()->hide();
238 * Populate running table
240 void DirStat::populateRunning()
242 QString command = QString(".status dir running");
243 if (mainWin->m_commandDebug)
244 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
246 QBrush blackBrush(Qt::black);
248 runningTable->clear();
249 QStringList headerlist = (QStringList()
250 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
252 runningTable->setColumnCount(headerlist.size());
253 runningTable->setHorizontalHeaderLabels(headerlist);
254 runningTable->setSelectionBehavior(QAbstractItemView::SelectRows);
256 if (m_console->dir_cmd(command, results)) {
258 QTableWidgetItem* p_tableitem;
259 runningTable->setRowCount(results.size());
260 foreach (QString line, results) {
261 /* Iterate through the record returned from the query */
262 QStringList fieldlist = line.split("\t");
264 QString statusCode("");
265 /* Iterate through fields in the record */
266 foreach (QString field, fieldlist) {
267 field = field.trimmed(); /* strip leading & trailing spaces */
268 p_tableitem = new QTableWidgetItem(field, 1);
269 p_tableitem->setForeground(blackBrush);
270 runningTable->setItem(row, column, p_tableitem);
276 runningTable->resizeColumnsToContents();
277 runningTable->resizeRowsToContents();
278 runningTable->verticalHeader()->hide();
282 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
283 * The tree has been populated.
285 void DirStat::PgSeltreeWidgetClicked()
291 if (!isOnceDocked()) {
297 * Virtual function override of pages function which is called when this page
298 * is visible on the stack
300 void DirStat::currentStackItem()
303 timerDisplay->display(spinBox->value());
310 * Function to create connections for context sensitive menu for this and
313 void DirStat::createConnections()
315 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
316 connect(actionCancelRunning, SIGNAL(triggered()), this, SLOT(consoleCancelJob()));
317 connect(actionDisableScheduledJob, SIGNAL(triggered()), this, SLOT(consoleDisableJob()));
318 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
320 scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
321 scheduledTable->addAction(actionRefresh);
322 scheduledTable->addAction(actionDisableScheduledJob);
323 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
324 terminatedTable->addAction(actionRefresh);
325 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
326 runningTable->addAction(actionRefresh);
327 runningTable->addAction(actionCancelRunning);
331 * Save user settings associated with this page
333 void DirStat::writeSettings()
335 QSettings settings(m_console->m_dir->name(), "bat");
336 settings.beginGroup(m_groupText);
337 settings.setValue(m_splitText, splitter->saveState());
338 settings.setValue("refreshInterval", spinBox->value());
339 settings.setValue("refreshCheck", checkBox->checkState());
344 * Read and restore user settings associated with this page
346 void DirStat::readSettings()
348 m_groupText = "DirStatPage";
349 m_splitText = "splitterSizes_0";
350 QSettings settings(m_console->m_dir->name(), "bat");
351 settings.beginGroup(m_groupText);
352 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
353 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
354 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
357 timerDisplay->display(spinBox->value());
361 * Cancel a running job
363 void DirStat::consoleCancelJob()
366 QList<QTableWidgetItem *> sitems = runningTable->selectedItems();
367 foreach (QTableWidgetItem *sitem, sitems) {
368 int row = sitem->row();
369 if (!rowList.contains(row)) {
374 QStringList selectedJobsList;
375 foreach(int row, rowList) {
376 QTableWidgetItem * sitem = runningTable->item(row, 0);
377 selectedJobsList.append(sitem->text());
379 foreach( QString job, selectedJobsList )
381 QString cmd("cancel jobid=");
388 * Disable a scheduled Job
390 void DirStat::consoleDisableJob()
392 int currentrow = scheduledTable->currentRow();
393 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
395 QString text = item->text();
396 QString cmd("disable job=\"");