2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 two of the GNU 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 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.
29 * Version $Id: dirstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
31 * Dirk Bartley, March 2007
35 #include <QAbstractEventDispatcher>
36 #include <QTableWidgetItem>
40 * Constructor for the class
45 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();
102 value = spinBox->value();
103 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
104 if (((isDocked() && iscurrent) || ((!isDocked()) && isOnceDocked())) && (checkBox->checkState() == Qt::Checked)) {
108 timerDisplay->display(value);
112 * Populate header text widget
114 void DirStat::populateHeader()
116 QString command = QString(".status dir header");
117 if (mainWin->m_commandDebug)
118 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
122 if (m_console->dir_cmd(command, results)) {
123 foreach (QString line, results) {
125 textEdit->insertPlainText(line);
131 * Populate teminated table
133 void DirStat::populateTerminated()
135 QString command = QString(".status dir terminated");
136 if (mainWin->m_commandDebug)
137 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
139 QBrush blackBrush(Qt::black);
141 terminatedTable->clear();
142 QStringList headerlist = (QStringList()
143 << tr("Job Id") << tr("Job Level") << tr("Job Files")
144 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
146 QStringList flaglist = (QStringList()
147 << "R" << "L" << "R" << "R" << "LC"
150 terminatedTable->setColumnCount(headerlist.size());
151 terminatedTable->setHorizontalHeaderLabels(headerlist);
153 if (m_console->dir_cmd(command, results)) {
155 QTableWidgetItem* p_tableitem;
156 terminatedTable->setRowCount(results.size());
157 foreach (QString line, results) {
158 /* Iterate through the record returned from the query */
159 QStringList fieldlist = line.split("\t");
161 QString statusCode("");
162 /* Iterate through fields in the record */
163 foreach (QString field, fieldlist) {
164 field = field.trimmed(); /* strip leading & trailing spaces */
165 p_tableitem = new QTableWidgetItem(field, 1);
166 p_tableitem->setForeground(blackBrush);
167 p_tableitem->setFlags(0);
168 if (flaglist[column].contains("R"))
169 p_tableitem->setTextAlignment(Qt::AlignRight);
170 if (flaglist[column].contains("C")) {
172 p_tableitem->setBackground(Qt::green);
174 p_tableitem->setBackground(Qt::red);
176 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
182 terminatedTable->resizeColumnsToContents();
183 terminatedTable->resizeRowsToContents();
184 terminatedTable->verticalHeader()->hide();
188 * Populate scheduled table
190 void DirStat::populateScheduled()
192 QString command = QString(".status dir scheduled");
193 if (mainWin->m_commandDebug)
194 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
196 QBrush blackBrush(Qt::black);
198 scheduledTable->clear();
199 QStringList headerlist = (QStringList()
200 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
201 << tr("Job Name") << tr("Volume"));
202 QStringList flaglist = (QStringList()
203 << "L" << "L" << "R" << "L" << "L" << "L");
205 scheduledTable->setColumnCount(headerlist.size());
206 scheduledTable->setHorizontalHeaderLabels(headerlist);
207 scheduledTable->setSelectionBehavior(QAbstractItemView::SelectRows);
208 scheduledTable->setSelectionMode(QAbstractItemView::SingleSelection);
210 if (m_console->dir_cmd(command, results)) {
212 QTableWidgetItem* p_tableitem;
213 scheduledTable->setRowCount(results.size());
214 foreach (QString line, results) {
215 /* Iterate through the record returned from the query */
216 QStringList fieldlist = line.split("\t");
218 QString statusCode("");
219 /* Iterate through fields in the record */
220 foreach (QString field, fieldlist) {
221 field = field.trimmed(); /* strip leading & trailing spaces */
222 p_tableitem = new QTableWidgetItem(field, 1);
223 p_tableitem->setForeground(blackBrush);
224 scheduledTable->setItem(row, column, p_tableitem);
230 scheduledTable->resizeColumnsToContents();
231 scheduledTable->resizeRowsToContents();
232 scheduledTable->verticalHeader()->hide();
236 * Populate running table
238 void DirStat::populateRunning()
240 QString command = QString(".status dir running");
241 if (mainWin->m_commandDebug)
242 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
244 QBrush blackBrush(Qt::black);
246 runningTable->clear();
247 QStringList headerlist = (QStringList()
248 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
250 runningTable->setColumnCount(headerlist.size());
251 runningTable->setHorizontalHeaderLabels(headerlist);
252 runningTable->setSelectionBehavior(QAbstractItemView::SelectRows);
254 if (m_console->dir_cmd(command, results)) {
256 QTableWidgetItem* p_tableitem;
257 runningTable->setRowCount(results.size());
258 foreach (QString line, results) {
259 /* Iterate through the record returned from the query */
260 QStringList fieldlist = line.split("\t");
262 QString statusCode("");
263 /* Iterate through fields in the record */
264 foreach (QString field, fieldlist) {
265 field = field.trimmed(); /* strip leading & trailing spaces */
266 p_tableitem = new QTableWidgetItem(field, 1);
267 p_tableitem->setForeground(blackBrush);
268 runningTable->setItem(row, column, p_tableitem);
274 runningTable->resizeColumnsToContents();
275 runningTable->resizeRowsToContents();
276 runningTable->verticalHeader()->hide();
280 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
281 * The tree has been populated.
283 void DirStat::PgSeltreeWidgetClicked()
293 * Virtual function override of pages function which is called when this page
294 * is visible on the stack
296 void DirStat::currentStackItem()
299 timerDisplay->display(spinBox->value());
306 * Function to create connections for context sensitive menu for this and
309 void DirStat::createConnections()
311 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
312 connect(actionCancelRunning, SIGNAL(triggered()), this, SLOT(consoleCancelJob()));
313 connect(actionDisableScheduledJob, SIGNAL(triggered()), this, SLOT(consoleDisableJob()));
314 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
316 scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
317 scheduledTable->addAction(actionRefresh);
318 scheduledTable->addAction(actionDisableScheduledJob);
319 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
320 terminatedTable->addAction(actionRefresh);
321 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
322 runningTable->addAction(actionRefresh);
323 runningTable->addAction(actionCancelRunning);
327 * Save user settings associated with this page
329 void DirStat::writeSettings()
331 QSettings settings(m_console->m_dir->name(), "bat");
332 settings.beginGroup(m_groupText);
333 settings.setValue(m_splitText, splitter->saveState());
334 settings.setValue("refreshInterval", spinBox->value());
335 settings.setValue("refreshCheck", checkBox->checkState());
340 * Read and restore user settings associated with this page
342 void DirStat::readSettings()
344 m_groupText = "DirStatPage";
345 m_splitText = "splitterSizes_0";
346 QSettings settings(m_console->m_dir->name(), "bat");
347 settings.beginGroup(m_groupText);
348 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
349 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
350 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
353 timerDisplay->display(spinBox->value());
357 * Cancel a running job
359 void DirStat::consoleCancelJob()
362 QList<QTableWidgetItem *> sitems = runningTable->selectedItems();
363 foreach (QTableWidgetItem *sitem, sitems) {
364 int row = sitem->row();
365 if (!rowList.contains(row)) {
370 QStringList selectedJobsList;
371 foreach(int row, rowList) {
372 QTableWidgetItem * sitem = runningTable->item(row, 0);
373 selectedJobsList.append(sitem->text());
375 foreach( QString job, selectedJobsList )
377 QString cmd("cancel jobid=");
384 * Disable a scheduled Job
386 void DirStat::consoleDisableJob()
388 int currentrow = scheduledTable->currentRow();
389 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
391 QString text = item->text();
392 QString cmd("disable job=\"");