2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
22 * Dirk Bartley, March 2007
26 #include <QAbstractEventDispatcher>
27 #include <QTableWidgetItem>
30 static bool working = false; /* prevent timer recursion */
33 * Constructor for the class
35 DirStat::DirStat() : Pages()
38 m_name = tr("Director Status");
40 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
41 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
42 m_cursor = new QTextCursor(textEdit->document());
44 m_timer = new QTimer(this);
52 void DirStat::getFont()
54 QFont font = textEdit->font();
57 m_console->getDirResName(dirname);
58 QSettings settings(dirname, "bat");
59 settings.beginGroup("Console");
60 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
61 font.setPointSize(settings.value("consolePointSize", 10).toInt());
62 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
64 textEdit->setFont(font);
68 * Write the m_splitter settings in the destructor
76 * Populate all tables and header widgets
78 void DirStat::populateAll()
87 * Timer is triggered, see if is current and repopulate.
89 void DirStat::timerTriggered()
91 double value = timerDisplay->value();
93 if (value <= 0 && !working) {
95 value = spinBox->value();
96 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
97 if (((isDocked() && iscurrent) || ((!isDocked()) && isOnceDocked())) && (checkBox->checkState() == Qt::Checked)) {
102 timerDisplay->display(value);
106 * Populate header text widget
108 void DirStat::populateHeader()
110 QString command = QString(".status dir header");
111 if (mainWin->m_commandDebug)
112 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
116 if (m_console->dir_cmd(command, results)) {
117 foreach (QString line, results) {
119 textEdit->insertPlainText(line);
125 * Populate teminated table
127 void DirStat::populateTerminated()
129 QString command = QString(".status dir terminated");
130 if (mainWin->m_commandDebug)
131 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
133 QBrush blackBrush(Qt::black);
135 terminatedTable->clear();
136 QStringList headerlist = (QStringList()
137 << tr("Job Id") << tr("Job Level") << tr("Job Files")
138 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
140 QStringList flaglist = (QStringList()
141 << "R" << "L" << "R" << "R" << "LC"
144 terminatedTable->setColumnCount(headerlist.size());
145 terminatedTable->setHorizontalHeaderLabels(headerlist);
147 if (m_console->dir_cmd(command, results)) {
149 QTableWidgetItem* p_tableitem;
150 terminatedTable->setRowCount(results.size());
151 foreach (QString line, results) {
152 /* Iterate through the record returned from the query */
153 QStringList fieldlist = line.split("\t");
155 QString statusCode("");
156 /* Iterate through fields in the record */
157 foreach (QString field, fieldlist) {
158 field = field.trimmed(); /* strip leading & trailing spaces */
159 p_tableitem = new QTableWidgetItem(field, 1);
160 p_tableitem->setForeground(blackBrush);
161 p_tableitem->setFlags(0);
162 if (flaglist[column].contains("R"))
163 p_tableitem->setTextAlignment(Qt::AlignRight);
164 if (flaglist[column].contains("C")) {
166 p_tableitem->setBackground(Qt::green);
168 p_tableitem->setBackground(Qt::red);
170 terminatedTable->setItem(results.size() - row - 1, column, p_tableitem);
176 terminatedTable->resizeColumnsToContents();
177 terminatedTable->resizeRowsToContents();
178 terminatedTable->verticalHeader()->hide();
182 * Populate scheduled table
184 void DirStat::populateScheduled()
186 QString command = QString(".status dir scheduled");
187 if (mainWin->m_commandDebug)
188 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
190 QBrush blackBrush(Qt::black);
192 scheduledTable->clear();
193 QStringList headerlist = (QStringList()
194 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
195 << tr("Job Name") << tr("Volume"));
196 QStringList flaglist = (QStringList()
197 << "L" << "L" << "R" << "L" << "L" << "L");
199 scheduledTable->setColumnCount(headerlist.size());
200 scheduledTable->setHorizontalHeaderLabels(headerlist);
201 scheduledTable->setSelectionBehavior(QAbstractItemView::SelectRows);
202 scheduledTable->setSelectionMode(QAbstractItemView::SingleSelection);
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 scheduledTable->setItem(row, column, p_tableitem);
224 scheduledTable->resizeColumnsToContents();
225 scheduledTable->resizeRowsToContents();
226 scheduledTable->verticalHeader()->hide();
230 * Populate running table
232 void DirStat::populateRunning()
234 QString command = QString(".status dir running");
235 if (mainWin->m_commandDebug)
236 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
238 QBrush blackBrush(Qt::black);
240 runningTable->clear();
241 QStringList headerlist = (QStringList()
242 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
244 runningTable->setColumnCount(headerlist.size());
245 runningTable->setHorizontalHeaderLabels(headerlist);
246 runningTable->setSelectionBehavior(QAbstractItemView::SelectRows);
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 runningTable->setItem(row, column, p_tableitem);
268 runningTable->resizeColumnsToContents();
269 runningTable->resizeRowsToContents();
270 runningTable->verticalHeader()->hide();
274 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
275 * The tree has been populated.
277 void DirStat::PgSeltreeWidgetClicked()
283 if (!isOnceDocked()) {
289 * Virtual function override of pages function which is called when this page
290 * is visible on the stack
292 void DirStat::currentStackItem()
295 timerDisplay->display(spinBox->value());
302 * Function to create connections for context sensitive menu for this and
305 void DirStat::createConnections()
307 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
308 connect(actionCancelRunning, SIGNAL(triggered()), this, SLOT(consoleCancelJob()));
309 connect(actionDisableScheduledJob, SIGNAL(triggered()), this, SLOT(consoleDisableJob()));
310 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
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());
330 settings.setValue("refreshInterval", spinBox->value());
331 settings.setValue("refreshCheck", checkBox->checkState());
336 * Read and restore user settings associated with this page
338 void DirStat::readSettings()
340 m_groupText = "DirStatPage";
341 m_splitText = "splitterSizes_0";
342 QSettings settings(m_console->m_dir->name(), "bat");
343 settings.beginGroup(m_groupText);
344 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
345 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
346 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
349 timerDisplay->display(spinBox->value());
353 * Cancel a running job
355 void DirStat::consoleCancelJob()
358 QList<QTableWidgetItem *> sitems = runningTable->selectedItems();
359 foreach (QTableWidgetItem *sitem, sitems) {
360 int row = sitem->row();
361 if (!rowList.contains(row)) {
366 QStringList selectedJobsList;
367 foreach(int row, rowList) {
368 QTableWidgetItem * sitem = runningTable->item(row, 0);
369 selectedJobsList.append(sitem->text());
371 foreach( QString job, selectedJobsList )
373 QString cmd("cancel jobid=");
380 * Disable a scheduled Job
382 void DirStat::consoleDisableJob()
384 int currentrow = scheduledTable->currentRow();
385 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
387 QString text = item->text();
388 QString cmd("disable job=\"");