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/joblog.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);
59 void DirStat::getFont()
61 QFont font = textEdit->font();
64 m_console->getDirResName(dirname);
65 QSettings settings(dirname, "bat");
66 settings.beginGroup("Console");
67 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
68 font.setPointSize(settings.value("consolePointSize", 10).toInt());
69 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
71 textEdit->setFont(font);
75 * Write the m_splitter settings in the destructor
83 * Populate all tables and header widgets
85 void DirStat::populateAll()
87 if (!m_console->preventInUseConnect())
96 * Timer is triggered, see if is current and repopulate.
98 void DirStat::timerTriggered()
100 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
101 if (((isDocked() && iscurrent) || (!isDocked())) && mainWin->m_refreshStatusDir) {
102 if (m_console->is_ready())
108 * Populate header text widget
110 void DirStat::populateHeader()
112 QString command = QString(".status dir header");
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");
131 QBrush blackBrush(Qt::black);
133 terminatedTable->clear();
134 QStringList headerlist = (QStringList()
135 << tr("Job Id") << tr("Job Level") << tr("Job Files")
136 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
138 QStringList flaglist = (QStringList()
139 << "R" << "L" << "R" << "R" << "LC"
142 terminatedTable->setColumnCount(headerlist.size());
143 terminatedTable->setHorizontalHeaderLabels(headerlist);
145 if (m_console->dir_cmd(command, results)) {
147 QTableWidgetItem* p_tableitem;
148 terminatedTable->setRowCount(results.size());
149 foreach (QString line, results) {
150 /* Iterate through the record returned from the query */
151 QStringList fieldlist = line.split("\t");
153 QString statusCode("");
154 /* Iterate through fields in the record */
155 foreach (QString field, fieldlist) {
156 field = field.trimmed(); /* strip leading & trailing spaces */
157 p_tableitem = new QTableWidgetItem(field, 1);
158 p_tableitem->setForeground(blackBrush);
159 p_tableitem->setFlags(0);
160 if (flaglist[column].contains("R"))
161 p_tableitem->setTextAlignment(Qt::AlignRight);
162 if (flaglist[column].contains("C"))
164 p_tableitem->setBackground(Qt::green);
166 p_tableitem->setBackground(Qt::red);
167 terminatedTable->setItem(row, column, p_tableitem);
173 terminatedTable->resizeColumnsToContents();
174 terminatedTable->resizeRowsToContents();
175 terminatedTable->verticalHeader()->hide();
179 * Populate scheduled table
181 void DirStat::populateScheduled()
183 QString command = QString(".status dir scheduled");
185 QBrush blackBrush(Qt::black);
187 scheduledTable->clear();
188 QStringList headerlist = (QStringList()
189 << tr("Job Level") << tr("Job Type") << tr("Priority") << tr("Job Time")
190 << tr("Job Name") << tr("Volume"));
191 QStringList flaglist = (QStringList()
192 << "L" << "L" << "R" << "L" << "L" << "L");
194 scheduledTable->setColumnCount(headerlist.size());
195 scheduledTable->setHorizontalHeaderLabels(headerlist);
197 if (m_console->dir_cmd(command, results)) {
199 QTableWidgetItem* p_tableitem;
200 scheduledTable->setRowCount(results.size());
201 foreach (QString line, results) {
202 /* Iterate through the record returned from the query */
203 QStringList fieldlist = line.split("\t");
205 QString statusCode("");
206 /* Iterate through fields in the record */
207 foreach (QString field, fieldlist) {
208 field = field.trimmed(); /* strip leading & trailing spaces */
209 p_tableitem = new QTableWidgetItem(field, 1);
210 p_tableitem->setForeground(blackBrush);
211 p_tableitem->setFlags(0);
212 scheduledTable->setItem(row, column, p_tableitem);
218 scheduledTable->resizeColumnsToContents();
219 scheduledTable->resizeRowsToContents();
220 scheduledTable->verticalHeader()->hide();
224 * Populate running table
226 void DirStat::populateRunning()
228 QString command = QString(".status dir running");
230 QBrush blackBrush(Qt::black);
232 runningTable->clear();
233 QStringList headerlist = (QStringList()
234 << tr("Job Id") << tr("Job Level") << tr("Job Data") << tr("Job Info"));
236 runningTable->setColumnCount(headerlist.size());
237 runningTable->setHorizontalHeaderLabels(headerlist);
239 if (m_console->dir_cmd(command, results)) {
241 QTableWidgetItem* p_tableitem;
242 runningTable->setRowCount(results.size());
243 foreach (QString line, results) {
244 /* Iterate through the record returned from the query */
245 QStringList fieldlist = line.split("\t");
247 QString statusCode("");
248 /* Iterate through fields in the record */
249 foreach (QString field, fieldlist) {
250 field = field.trimmed(); /* strip leading & trailing spaces */
251 p_tableitem = new QTableWidgetItem(field, 1);
252 p_tableitem->setForeground(blackBrush);
253 p_tableitem->setFlags(0);
254 runningTable->setItem(row, column, p_tableitem);
260 runningTable->resizeColumnsToContents();
261 runningTable->resizeRowsToContents();
262 runningTable->verticalHeader()->hide();
266 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
267 * The tree has been populated.
269 void DirStat::PgSeltreeWidgetClicked()
278 * Virtual function override of pages function which is called when this page
279 * is visible on the stack
281 void DirStat::currentStackItem()
290 * Function to create connections for context sensitive menu for this and
293 void DirStat::createConnections()
298 * Save user settings associated with this page
300 void DirStat::writeSettings()
302 QSettings settings(m_console->m_dir->name(), "bat");
303 settings.beginGroup(m_groupText);
304 settings.setValue(m_splitText, splitter->saveState());
309 * Read and restore user settings associated with this page
311 void DirStat::readSettings()
313 m_groupText = "DirStatPage";
314 m_splitText = "splitterSizes_0";
315 QSettings settings(m_console->m_dir->name(), "bat");
316 settings.beginGroup(m_groupText);
317 splitter->restoreState(settings.value(m_splitText).toByteArray());