2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 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.
29 * Version $Id: dirstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
31 * Dirk Bartley, March 2007
34 #include <QAbstractEventDispatcher>
35 #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());
54 m_timer = new QTimer(this);
55 QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
56 m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
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()
89 if (!m_console->preventInUseConnect())
98 * Timer is triggered, see if is current and repopulate.
100 void DirStat::timerTriggered()
102 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
103 if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
104 if (m_console->is_ready())
110 * Populate header text widget
112 void DirStat::populateHeader()
114 QString command = QString(".status dir header");
115 if (mainWin->m_commandDebug)
116 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
120 if (m_console->dir_cmd(command, results)) {
121 foreach (QString line, results) {
123 textEdit->insertPlainText(line);
129 * Populate teminated table
131 void DirStat::populateTerminated()
133 QString command = QString(".status dir terminated");
134 if (mainWin->m_commandDebug)
135 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
137 QBrush blackBrush(Qt::black);
139 terminatedTable->clear();
140 QStringList headerlist = (QStringList()
141 << tr("Job Id") << tr("Job Level") << tr("Job Files")
142 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
144 QStringList flaglist = (QStringList()
145 << "R" << "L" << "R" << "R" << "LC"
148 terminatedTable->setColumnCount(headerlist.size());
149 terminatedTable->setHorizontalHeaderLabels(headerlist);
151 if (m_console->dir_cmd(command, results)) {
153 QTableWidgetItem* p_tableitem;
154 terminatedTable->setRowCount(results.size());
155 foreach (QString line, results) {
156 /* Iterate through the record returned from the query */
157 QStringList fieldlist = line.split("\t");
159 QString statusCode("");
160 /* Iterate through fields in the record */
161 foreach (QString field, fieldlist) {
162 field = field.trimmed(); /* strip leading & trailing spaces */
163 p_tableitem = new QTableWidgetItem(field, 1);
164 p_tableitem->setForeground(blackBrush);
165 p_tableitem->setFlags(0);
166 if (flaglist[column].contains("R"))
167 p_tableitem->setTextAlignment(Qt::AlignRight);
168 if (flaglist[column].contains("C"))
170 p_tableitem->setBackground(Qt::green);
172 p_tableitem->setBackground(Qt::red);
173 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
179 terminatedTable->resizeColumnsToContents();
180 terminatedTable->resizeRowsToContents();
181 terminatedTable->verticalHeader()->hide();
185 * Populate scheduled table
187 void DirStat::populateScheduled()
189 QString command = QString(".status dir scheduled");
190 if (mainWin->m_commandDebug)
191 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
193 QBrush blackBrush(Qt::black);
195 scheduledTable->clear();
196 QStringList headerlist = (QStringList()
197 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
198 << tr("Job Name") << tr("Volume"));
199 QStringList flaglist = (QStringList()
200 << "L" << "L" << "R" << "L" << "L" << "L");
202 scheduledTable->setColumnCount(headerlist.size());
203 scheduledTable->setHorizontalHeaderLabels(headerlist);
205 if (m_console->dir_cmd(command, results)) {
207 QTableWidgetItem* p_tableitem;
208 scheduledTable->setRowCount(results.size());
209 foreach (QString line, results) {
210 /* Iterate through the record returned from the query */
211 QStringList fieldlist = line.split("\t");
213 QString statusCode("");
214 /* Iterate through fields in the record */
215 foreach (QString field, fieldlist) {
216 field = field.trimmed(); /* strip leading & trailing spaces */
217 p_tableitem = new QTableWidgetItem(field, 1);
218 p_tableitem->setForeground(blackBrush);
219 p_tableitem->setFlags(0);
220 scheduledTable->setItem(row, column, p_tableitem);
226 scheduledTable->resizeColumnsToContents();
227 scheduledTable->resizeRowsToContents();
228 scheduledTable->verticalHeader()->hide();
232 * Populate running table
234 void DirStat::populateRunning()
236 QString command = QString(".status dir running");
237 if (mainWin->m_commandDebug)
238 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
240 QBrush blackBrush(Qt::black);
242 runningTable->clear();
243 QStringList headerlist = (QStringList()
244 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
246 runningTable->setColumnCount(headerlist.size());
247 runningTable->setHorizontalHeaderLabels(headerlist);
249 if (m_console->dir_cmd(command, results)) {
251 QTableWidgetItem* p_tableitem;
252 runningTable->setRowCount(results.size());
253 foreach (QString line, results) {
254 /* Iterate through the record returned from the query */
255 QStringList fieldlist = line.split("\t");
257 QString statusCode("");
258 /* Iterate through fields in the record */
259 foreach (QString field, fieldlist) {
260 field = field.trimmed(); /* strip leading & trailing spaces */
261 p_tableitem = new QTableWidgetItem(field, 1);
262 p_tableitem->setForeground(blackBrush);
263 p_tableitem->setFlags(0);
264 runningTable->setItem(row, column, p_tableitem);
270 runningTable->resizeColumnsToContents();
271 runningTable->resizeRowsToContents();
272 runningTable->verticalHeader()->hide();
276 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
277 * The tree has been populated.
279 void DirStat::PgSeltreeWidgetClicked()
288 * Virtual function override of pages function which is called when this page
289 * is visible on the stack
291 void DirStat::currentStackItem()
300 * Function to create connections for context sensitive menu for this and
303 void DirStat::createConnections()
305 connect(actionRefresh, SIGNAL(triggered()), this,
306 SLOT(populateAll()));
307 connect(actionCancelRunning, SIGNAL(triggered()), this,
308 SLOT(consoleCancelJob()));
309 connect(actionDisableScheduledJob, SIGNAL(triggered()), this,
310 SLOT(consoleDisableJob()));
312 scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
313 scheduledTable->addAction(actionRefresh);
314 scheduledTable->addAction(actionDisableScheduledJob);
315 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
316 terminatedTable->addAction(actionRefresh);
317 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
318 runningTable->addAction(actionRefresh);
319 runningTable->addAction(actionCancelRunning);
323 * Save user settings associated with this page
325 void DirStat::writeSettings()
327 QSettings settings(m_console->m_dir->name(), "bat");
328 settings.beginGroup(m_groupText);
329 settings.setValue(m_splitText, splitter->saveState());
334 * Read and restore user settings associated with this page
336 void DirStat::readSettings()
338 m_groupText = "DirStatPage";
339 m_splitText = "splitterSizes_0";
340 QSettings settings(m_console->m_dir->name(), "bat");
341 settings.beginGroup(m_groupText);
342 splitter->restoreState(settings.value(m_splitText).toByteArray());
347 * Cancel a running job
349 void DirStat::consoleCancelJob()
351 int currentrow = runningTable->currentRow();
352 QTableWidgetItem *item = runningTable->item(currentrow, 0);
354 QString text = item->text();
355 QString cmd("cancel jobid=");
362 * Disable a scheduled Job
364 void DirStat::consoleDisableJob()
366 int currentrow = scheduledTable->currentRow();
367 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
369 QString text = item->text();
370 QString cmd("disable job=\"");