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());
54 m_timer = new QTimer(this);
55 QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
56 m_timer->start(mainWin->m_refreshStatusDirInterval*1000);
62 void DirStat::getFont()
64 QFont font = textEdit->font();
67 m_console->getDirResName(dirname);
68 QSettings settings(dirname, "bat");
69 settings.beginGroup("Console");
70 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
71 font.setPointSize(settings.value("consolePointSize", 10).toInt());
72 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
74 textEdit->setFont(font);
78 * Write the m_splitter settings in the destructor
86 * Populate all tables and header widgets
88 void DirStat::populateAll()
97 * Timer is triggered, see if is current and repopulate.
99 void DirStat::timerTriggered()
101 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
102 if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
108 * Populate header text widget
110 void DirStat::populateHeader()
112 QString command = QString(".status dir header");
113 if (mainWin->m_commandDebug)
114 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
118 if (m_console->dir_cmd(command, results)) {
119 foreach (QString line, results) {
121 textEdit->insertPlainText(line);
127 * Populate teminated table
129 void DirStat::populateTerminated()
131 QString command = QString(".status dir terminated");
132 if (mainWin->m_commandDebug)
133 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
135 QBrush blackBrush(Qt::black);
137 terminatedTable->clear();
138 QStringList headerlist = (QStringList()
139 << tr("Job Id") << tr("Job Level") << tr("Job Files")
140 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
142 QStringList flaglist = (QStringList()
143 << "R" << "L" << "R" << "R" << "LC"
146 terminatedTable->setColumnCount(headerlist.size());
147 terminatedTable->setHorizontalHeaderLabels(headerlist);
149 if (m_console->dir_cmd(command, results)) {
151 QTableWidgetItem* p_tableitem;
152 terminatedTable->setRowCount(results.size());
153 foreach (QString line, results) {
154 /* Iterate through the record returned from the query */
155 QStringList fieldlist = line.split("\t");
157 QString statusCode("");
158 /* Iterate through fields in the record */
159 foreach (QString field, fieldlist) {
160 field = field.trimmed(); /* strip leading & trailing spaces */
161 p_tableitem = new QTableWidgetItem(field, 1);
162 p_tableitem->setForeground(blackBrush);
163 p_tableitem->setFlags(0);
164 if (flaglist[column].contains("R"))
165 p_tableitem->setTextAlignment(Qt::AlignRight);
166 if (flaglist[column].contains("C")) {
168 p_tableitem->setBackground(Qt::green);
170 p_tableitem->setBackground(Qt::red);
172 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
178 terminatedTable->resizeColumnsToContents();
179 terminatedTable->resizeRowsToContents();
180 terminatedTable->verticalHeader()->hide();
184 * Populate scheduled table
186 void DirStat::populateScheduled()
188 QString command = QString(".status dir scheduled");
189 if (mainWin->m_commandDebug)
190 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
192 QBrush blackBrush(Qt::black);
194 scheduledTable->clear();
195 QStringList headerlist = (QStringList()
196 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
197 << tr("Job Name") << tr("Volume"));
198 QStringList flaglist = (QStringList()
199 << "L" << "L" << "R" << "L" << "L" << "L");
201 scheduledTable->setColumnCount(headerlist.size());
202 scheduledTable->setHorizontalHeaderLabels(headerlist);
204 if (m_console->dir_cmd(command, results)) {
206 QTableWidgetItem* p_tableitem;
207 scheduledTable->setRowCount(results.size());
208 foreach (QString line, results) {
209 /* Iterate through the record returned from the query */
210 QStringList fieldlist = line.split("\t");
212 QString statusCode("");
213 /* Iterate through fields in the record */
214 foreach (QString field, fieldlist) {
215 field = field.trimmed(); /* strip leading & trailing spaces */
216 p_tableitem = new QTableWidgetItem(field, 1);
217 p_tableitem->setForeground(blackBrush);
218 p_tableitem->setFlags(0);
219 scheduledTable->setItem(row, column, p_tableitem);
225 scheduledTable->resizeColumnsToContents();
226 scheduledTable->resizeRowsToContents();
227 scheduledTable->verticalHeader()->hide();
231 * Populate running table
233 void DirStat::populateRunning()
235 QString command = QString(".status dir running");
236 if (mainWin->m_commandDebug)
237 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
239 QBrush blackBrush(Qt::black);
241 runningTable->clear();
242 QStringList headerlist = (QStringList()
243 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
245 runningTable->setColumnCount(headerlist.size());
246 runningTable->setHorizontalHeaderLabels(headerlist);
248 if (m_console->dir_cmd(command, results)) {
250 QTableWidgetItem* p_tableitem;
251 runningTable->setRowCount(results.size());
252 foreach (QString line, results) {
253 /* Iterate through the record returned from the query */
254 QStringList fieldlist = line.split("\t");
256 QString statusCode("");
257 /* Iterate through fields in the record */
258 foreach (QString field, fieldlist) {
259 field = field.trimmed(); /* strip leading & trailing spaces */
260 p_tableitem = new QTableWidgetItem(field, 1);
261 p_tableitem->setForeground(blackBrush);
262 p_tableitem->setFlags(Qt::ItemIsSelectable);
263 runningTable->setItem(row, column, p_tableitem);
269 runningTable->resizeColumnsToContents();
270 runningTable->resizeRowsToContents();
271 runningTable->verticalHeader()->hide();
275 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
276 * The tree has been populated.
278 void DirStat::PgSeltreeWidgetClicked()
287 * Virtual function override of pages function which is called when this page
288 * is visible on the stack
290 void DirStat::currentStackItem()
299 * Function to create connections for context sensitive menu for this and
302 void DirStat::createConnections()
304 connect(actionRefresh, SIGNAL(triggered()), this,
305 SLOT(populateAll()));
306 connect(actionCancelRunning, SIGNAL(triggered()), this,
307 SLOT(consoleCancelJob()));
308 connect(actionDisableScheduledJob, SIGNAL(triggered()), this,
309 SLOT(consoleDisableJob()));
311 scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
312 scheduledTable->addAction(actionRefresh);
313 scheduledTable->addAction(actionDisableScheduledJob);
314 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
315 terminatedTable->addAction(actionRefresh);
316 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
317 runningTable->addAction(actionRefresh);
318 runningTable->addAction(actionCancelRunning);
322 * Save user settings associated with this page
324 void DirStat::writeSettings()
326 QSettings settings(m_console->m_dir->name(), "bat");
327 settings.beginGroup(m_groupText);
328 settings.setValue(m_splitText, splitter->saveState());
333 * Read and restore user settings associated with this page
335 void DirStat::readSettings()
337 m_groupText = "DirStatPage";
338 m_splitText = "splitterSizes_0";
339 QSettings settings(m_console->m_dir->name(), "bat");
340 settings.beginGroup(m_groupText);
341 splitter->restoreState(settings.value(m_splitText).toByteArray());
346 * Cancel a running job
348 void DirStat::consoleCancelJob()
351 QList<QTableWidgetItem *> sitems = runningTable->selectedItems();
352 foreach (QTableWidgetItem *sitem, sitems) {
353 int row = sitem->row();
354 if (!rowList.contains(row)) {
359 QStringList selectedJobsList;
360 foreach(int row, rowList) {
361 QTableWidgetItem * sitem = runningTable->item(row, 0);
362 selectedJobsList.append(sitem->text());
364 foreach( QString job, selectedJobsList )
366 QString cmd("cancel jobid=");
373 * Disable a scheduled Job
375 void DirStat::consoleDisableJob()
377 int currentrow = scheduledTable->currentRow();
378 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
380 QString text = item->text();
381 QString cmd("disable job=\"");