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);
61 void DirStat::getFont()
63 QFont font = textEdit->font();
66 m_console->getDirResName(dirname);
67 QSettings settings(dirname, "bat");
68 settings.beginGroup("Console");
69 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
70 font.setPointSize(settings.value("consolePointSize", 10).toInt());
71 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
73 textEdit->setFont(font);
77 * Write the m_splitter settings in the destructor
85 * Populate all tables and header widgets
87 void DirStat::populateAll()
96 * Timer is triggered, see if is current and repopulate.
98 void DirStat::timerTriggered()
100 double value = timerDisplay->value();
103 value = spinBox->value();
104 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
105 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
109 timerDisplay->display(value);
113 * Populate header text widget
115 void DirStat::populateHeader()
117 QString command = QString(".status dir header");
118 if (mainWin->m_commandDebug)
119 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
123 if (m_console->dir_cmd(command, results)) {
124 foreach (QString line, results) {
126 textEdit->insertPlainText(line);
132 * Populate teminated table
134 void DirStat::populateTerminated()
136 QString command = QString(".status dir terminated");
137 if (mainWin->m_commandDebug)
138 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
140 QBrush blackBrush(Qt::black);
142 terminatedTable->clear();
143 QStringList headerlist = (QStringList()
144 << tr("Job Id") << tr("Job Level") << tr("Job Files")
145 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
147 QStringList flaglist = (QStringList()
148 << "R" << "L" << "R" << "R" << "LC"
151 terminatedTable->setColumnCount(headerlist.size());
152 terminatedTable->setHorizontalHeaderLabels(headerlist);
154 if (m_console->dir_cmd(command, results)) {
156 QTableWidgetItem* p_tableitem;
157 terminatedTable->setRowCount(results.size());
158 foreach (QString line, results) {
159 /* Iterate through the record returned from the query */
160 QStringList fieldlist = line.split("\t");
162 QString statusCode("");
163 /* Iterate through fields in the record */
164 foreach (QString field, fieldlist) {
165 field = field.trimmed(); /* strip leading & trailing spaces */
166 p_tableitem = new QTableWidgetItem(field, 1);
167 p_tableitem->setForeground(blackBrush);
168 p_tableitem->setFlags(0);
169 if (flaglist[column].contains("R"))
170 p_tableitem->setTextAlignment(Qt::AlignRight);
171 if (flaglist[column].contains("C")) {
173 p_tableitem->setBackground(Qt::green);
175 p_tableitem->setBackground(Qt::red);
177 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
183 terminatedTable->resizeColumnsToContents();
184 terminatedTable->resizeRowsToContents();
185 terminatedTable->verticalHeader()->hide();
189 * Populate scheduled table
191 void DirStat::populateScheduled()
193 QString command = QString(".status dir scheduled");
194 if (mainWin->m_commandDebug)
195 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
197 QBrush blackBrush(Qt::black);
199 scheduledTable->clear();
200 QStringList headerlist = (QStringList()
201 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
202 << tr("Job Name") << tr("Volume"));
203 QStringList flaglist = (QStringList()
204 << "L" << "L" << "R" << "L" << "L" << "L");
206 scheduledTable->setColumnCount(headerlist.size());
207 scheduledTable->setHorizontalHeaderLabels(headerlist);
209 if (m_console->dir_cmd(command, results)) {
211 QTableWidgetItem* p_tableitem;
212 scheduledTable->setRowCount(results.size());
213 foreach (QString line, results) {
214 /* Iterate through the record returned from the query */
215 QStringList fieldlist = line.split("\t");
217 QString statusCode("");
218 /* Iterate through fields in the record */
219 foreach (QString field, fieldlist) {
220 field = field.trimmed(); /* strip leading & trailing spaces */
221 p_tableitem = new QTableWidgetItem(field, 1);
222 p_tableitem->setForeground(blackBrush);
223 p_tableitem->setFlags(0);
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);
253 if (m_console->dir_cmd(command, results)) {
255 QTableWidgetItem* p_tableitem;
256 runningTable->setRowCount(results.size());
257 foreach (QString line, results) {
258 /* Iterate through the record returned from the query */
259 QStringList fieldlist = line.split("\t");
261 QString statusCode("");
262 /* Iterate through fields in the record */
263 foreach (QString field, fieldlist) {
264 field = field.trimmed(); /* strip leading & trailing spaces */
265 p_tableitem = new QTableWidgetItem(field, 1);
266 p_tableitem->setForeground(blackBrush);
267 p_tableitem->setFlags(Qt::ItemIsSelectable);
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()
292 * Virtual function override of pages function which is called when this page
293 * is visible on the stack
295 void DirStat::currentStackItem()
298 timerDisplay->display(spinBox->value());
305 * Function to create connections for context sensitive menu for this and
308 void DirStat::createConnections()
310 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
311 connect(actionCancelRunning, SIGNAL(triggered()), this, SLOT(consoleCancelJob()));
312 connect(actionDisableScheduledJob, SIGNAL(triggered()), this, SLOT(consoleDisableJob()));
313 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
315 scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
316 scheduledTable->addAction(actionRefresh);
317 scheduledTable->addAction(actionDisableScheduledJob);
318 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
319 terminatedTable->addAction(actionRefresh);
320 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
321 runningTable->addAction(actionRefresh);
322 runningTable->addAction(actionCancelRunning);
326 * Save user settings associated with this page
328 void DirStat::writeSettings()
330 QSettings settings(m_console->m_dir->name(), "bat");
331 settings.beginGroup(m_groupText);
332 settings.setValue(m_splitText, splitter->saveState());
333 settings.setValue("refreshInterval", spinBox->value());
334 settings.setValue("refreshCheck", checkBox->checkState());
339 * Read and restore user settings associated with this page
341 void DirStat::readSettings()
343 m_groupText = "DirStatPage";
344 m_splitText = "splitterSizes_0";
345 QSettings settings(m_console->m_dir->name(), "bat");
346 settings.beginGroup(m_groupText);
347 splitter->restoreState(settings.value(m_splitText).toByteArray());
348 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
349 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
352 timerDisplay->display(spinBox->value());
356 * Cancel a running job
358 void DirStat::consoleCancelJob()
361 QList<QTableWidgetItem *> sitems = runningTable->selectedItems();
362 foreach (QTableWidgetItem *sitem, sitems) {
363 int row = sitem->row();
364 if (!rowList.contains(row)) {
369 QStringList selectedJobsList;
370 foreach(int row, rowList) {
371 QTableWidgetItem * sitem = runningTable->item(row, 0);
372 selectedJobsList.append(sitem->text());
374 foreach( QString job, selectedJobsList )
376 QString cmd("cancel jobid=");
383 * Disable a scheduled Job
385 void DirStat::consoleDisableJob()
387 int currentrow = scheduledTable->currentRow();
388 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
390 QString text = item->text();
391 QString cmd("disable job=\"");