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");
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");
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);
169 terminatedTable->setItem(row, column, p_tableitem);
175 terminatedTable->resizeColumnsToContents();
176 terminatedTable->resizeRowsToContents();
177 terminatedTable->verticalHeader()->hide();
181 * Populate scheduled table
183 void DirStat::populateScheduled()
185 QString command = QString(".status dir scheduled");
187 QBrush blackBrush(Qt::black);
189 scheduledTable->clear();
190 QStringList headerlist = (QStringList()
191 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
192 << tr("Job Name") << tr("Volume"));
193 QStringList flaglist = (QStringList()
194 << "L" << "L" << "R" << "L" << "L" << "L");
196 scheduledTable->setColumnCount(headerlist.size());
197 scheduledTable->setHorizontalHeaderLabels(headerlist);
199 if (m_console->dir_cmd(command, results)) {
201 QTableWidgetItem* p_tableitem;
202 scheduledTable->setRowCount(results.size());
203 foreach (QString line, results) {
204 /* Iterate through the record returned from the query */
205 QStringList fieldlist = line.split("\t");
207 QString statusCode("");
208 /* Iterate through fields in the record */
209 foreach (QString field, fieldlist) {
210 field = field.trimmed(); /* strip leading & trailing spaces */
211 p_tableitem = new QTableWidgetItem(field, 1);
212 p_tableitem->setForeground(blackBrush);
213 p_tableitem->setFlags(0);
214 scheduledTable->setItem(row, column, p_tableitem);
220 scheduledTable->resizeColumnsToContents();
221 scheduledTable->resizeRowsToContents();
222 scheduledTable->verticalHeader()->hide();
226 * Populate running table
228 void DirStat::populateRunning()
230 QString command = QString(".status dir running");
232 QBrush blackBrush(Qt::black);
234 runningTable->clear();
235 QStringList headerlist = (QStringList()
236 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
238 runningTable->setColumnCount(headerlist.size());
239 runningTable->setHorizontalHeaderLabels(headerlist);
241 if (m_console->dir_cmd(command, results)) {
243 QTableWidgetItem* p_tableitem;
244 runningTable->setRowCount(results.size());
245 foreach (QString line, results) {
246 /* Iterate through the record returned from the query */
247 QStringList fieldlist = line.split("\t");
249 QString statusCode("");
250 /* Iterate through fields in the record */
251 foreach (QString field, fieldlist) {
252 field = field.trimmed(); /* strip leading & trailing spaces */
253 p_tableitem = new QTableWidgetItem(field, 1);
254 p_tableitem->setForeground(blackBrush);
255 p_tableitem->setFlags(0);
256 runningTable->setItem(row, column, p_tableitem);
262 runningTable->resizeColumnsToContents();
263 runningTable->resizeRowsToContents();
264 runningTable->verticalHeader()->hide();
268 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
269 * The tree has been populated.
271 void DirStat::PgSeltreeWidgetClicked()
280 * Virtual function override of pages function which is called when this page
281 * is visible on the stack
283 void DirStat::currentStackItem()
292 * Function to create connections for context sensitive menu for this and
295 void DirStat::createConnections()
297 connect(actionRefresh, SIGNAL(triggered()), this,
298 SLOT(populateAll()));
299 connect(actionCancelRunning, SIGNAL(triggered()), this,
300 SLOT(consoleCancelJob()));
301 connect(actionDisableScheduledJob, SIGNAL(triggered()), this,
302 SLOT(consoleDisableJob()));
304 scheduledTable->setContextMenuPolicy(Qt::ActionsContextMenu);
305 scheduledTable->addAction(actionRefresh);
306 scheduledTable->addAction(actionDisableScheduledJob);
307 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
308 terminatedTable->addAction(actionRefresh);
309 runningTable->setContextMenuPolicy(Qt::ActionsContextMenu);
310 runningTable->addAction(actionRefresh);
311 runningTable->addAction(actionCancelRunning);
315 * Save user settings associated with this page
317 void DirStat::writeSettings()
319 QSettings settings(m_console->m_dir->name(), "bat");
320 settings.beginGroup(m_groupText);
321 settings.setValue(m_splitText, splitter->saveState());
326 * Read and restore user settings associated with this page
328 void DirStat::readSettings()
330 m_groupText = "DirStatPage";
331 m_splitText = "splitterSizes_0";
332 QSettings settings(m_console->m_dir->name(), "bat");
333 settings.beginGroup(m_groupText);
334 splitter->restoreState(settings.value(m_splitText).toByteArray());
339 * Cancel a running job
341 void DirStat::consoleCancelJob()
343 int currentrow = runningTable->currentRow();
344 QTableWidgetItem *item = runningTable->item(currentrow, 0);
346 QString text = item->text();
347 QString cmd("cancel jobid=");
354 * Disable a scheduled Job
356 void DirStat::consoleDisableJob()
358 int currentrow = scheduledTable->currentRow();
359 QTableWidgetItem *item = scheduledTable->item(currentrow, 4);
361 QString text = item->text();
362 QString cmd("disable job=\"");