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: storstat.cpp 5880 2007-11-09 01:20:40Z bartleyd2 $
31 * Dirk Bartley, March 2007
35 #include <QAbstractEventDispatcher>
36 #include <QTableWidgetItem>
38 #include "mount/mount.h"
41 .status storage=<storage-name> <keyword>
42 where <storage-name> is the storage name in the Director, and
43 <keyword> is one of the following:
55 * Constructor for the class
57 StorStat::StorStat(QString &storage, QTreeWidgetItem *parentTreeWidgetItem)
62 pgInitialize(tr("Storage Status %1").arg(m_storage), parentTreeWidgetItem);
63 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
64 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
65 m_cursor = new QTextCursor(textEditHeader->document());
67 m_timer = new QTimer(this);
70 QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
76 void StorStat::getFont()
78 QFont font = textEditHeader->font();
81 m_console->getDirResName(dirname);
82 QSettings settings(dirname, "bat");
83 settings.beginGroup("Console");
84 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
85 font.setPointSize(settings.value("consolePointSize", 10).toInt());
86 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
88 textEditHeader->setFont(font);
92 * Write the m_splitter settings in the destructor
100 * Populate all tables and header widgets
102 void StorStat::populateAll()
104 populateTerminated();
105 populateCurrentTab(tabWidget->currentIndex());
109 * Timer is triggered, see if is current and repopulate.
111 void StorStat::timerTriggered()
113 bool iscurrent = mainWin->stackedWidget->currentIndex() == mainWin->stackedWidget->indexOf(this);
114 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
120 * Populate header text widget
122 void StorStat::populateHeader()
124 QString command = QString(".status storage=\"" + m_storage + "\" header");
125 if (mainWin->m_commandDebug)
126 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
128 textEditHeader->clear();
130 if (m_console->dir_cmd(command, results)) {
131 foreach (QString line, results) {
133 textEditHeader->insertPlainText(line);
138 void StorStat::populateWaitReservation()
140 QString command = QString(".status storage=\"" + m_storage + "\" waitreservation");
141 if (mainWin->m_commandDebug)
142 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
144 textEditWaitReservation->clear();
146 if (m_console->dir_cmd(command, results)) {
147 foreach (QString line, results) {
149 textEditWaitReservation->insertPlainText(line);
154 void StorStat::populateDevices()
156 QString command = QString(".status storage=\"" + m_storage + "\" devices");
157 if (mainWin->m_commandDebug)
158 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
160 textEditDevices->clear();
162 if (m_console->dir_cmd(command, results)) {
163 foreach (QString line, results) {
165 textEditDevices->insertPlainText(line);
170 void StorStat::populateVolumes()
172 QString command = QString(".status storage=\"" + m_storage + "\" volumes");
173 if (mainWin->m_commandDebug)
174 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
176 textEditVolumes->clear();
178 if (m_console->dir_cmd(command, results)) {
179 foreach (QString line, results) {
181 textEditVolumes->insertPlainText(line);
186 void StorStat::populateSpooling()
188 QString command = QString(".status storage=\"" + m_storage + "\" spooling");
189 if (mainWin->m_commandDebug)
190 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
192 textEditSpooling->clear();
194 if (m_console->dir_cmd(command, results)) {
195 foreach (QString line, results) {
197 textEditSpooling->insertPlainText(line);
202 void StorStat::populateRunning()
204 QString command = QString(".status storage=\"" + m_storage + "\" running");
205 if (mainWin->m_commandDebug)
206 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
208 textEditRunning->clear();
210 if (m_console->dir_cmd(command, results)) {
211 foreach (QString line, results) {
213 textEditRunning->insertPlainText(line);
219 * Populate teminated table
221 void StorStat::populateTerminated()
223 QString command = QString(".status storage=\"" + m_storage + "\" terminated");
224 if (mainWin->m_commandDebug)
225 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
227 QBrush blackBrush(Qt::black);
229 terminatedTable->clear();
230 QStringList headerlist = (QStringList()
231 << tr("Job Id") << tr("Job Level") << tr("Job Files")
232 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
234 QStringList flaglist = (QStringList()
235 << "R" << "L" << "R" << "R" << "LC"
238 terminatedTable->setColumnCount(headerlist.size());
239 terminatedTable->setHorizontalHeaderLabels(headerlist);
241 if (m_console->dir_cmd(command, results)) {
243 QTableWidgetItem* p_tableitem;
244 terminatedTable->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 if (flaglist[column].contains("R"))
257 p_tableitem->setTextAlignment(Qt::AlignRight);
258 if (flaglist[column].contains("C")) {
260 p_tableitem->setBackground(Qt::green);
262 p_tableitem->setBackground(Qt::red);
264 terminatedTable->setItem(row, column, p_tableitem);
270 terminatedTable->resizeColumnsToContents();
271 terminatedTable->resizeRowsToContents();
272 terminatedTable->verticalHeader()->hide();
276 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
277 * The tree has been populated.
279 void StorStat::PgSeltreeWidgetClicked()
288 * Virtual function override of pages function which is called when this page
289 * is visible on the stack
291 void StorStat::currentStackItem()
300 * Function to create connections for context sensitive menu for this and
303 void StorStat::createConnections()
305 connect(actionRefresh, SIGNAL(triggered()), this,
306 SLOT(populateAll()));
307 connect(tabWidget, SIGNAL(currentChanged(int)), this,
308 SLOT(populateCurrentTab(int)));
309 connect(spinBox, SIGNAL(valueChanged(int)), this,
310 SLOT(spinBoxValueChanged(int)));
311 connect(mountButton, SIGNAL(pressed()), this, SLOT(mountButtonPushed()));
312 connect(umountButton, SIGNAL(pressed()), this, SLOT(umountButtonPushed()));
313 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
314 terminatedTable->addAction(actionRefresh);
318 * Save user settings associated with this page
320 void StorStat::writeSettings()
322 QSettings settings(m_console->m_dir->name(), "bat");
323 settings.beginGroup(m_groupText);
324 settings.setValue(m_splitText, splitter->saveState());
325 settings.setValue("refreshInterval", spinBox->value());
326 settings.setValue("refreshCheck", checkBox->checkState());
331 * Read and restore user settings associated with this page
333 void StorStat::readSettings()
335 m_groupText = "StorStatPage";
336 m_splitText = "splitterSizes_0";
337 QSettings settings(m_console->m_dir->name(), "bat");
338 settings.beginGroup(m_groupText);
339 splitter->restoreState(settings.value(m_splitText).toByteArray());
340 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
341 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
344 m_timer->start(spinBox->value()*1000);
348 * Populate the text edit window in the current tab
350 void StorStat::populateCurrentTab(int index)
355 populateWaitReservation();
367 * Set the timer when changed
369 void StorStat::spinBoxValueChanged(int newval)
371 m_timer->setInterval(newval*1000);
375 * execute mount in console
377 void StorStat::mountButtonPushed()
381 /* Set up query QString and header QStringList */
382 QString query("SELECT AutoChanger AS Changer"
383 " FROM Storage WHERE Name='" + m_storage + "'"
387 /* This could be a log item */
388 if (mainWin->m_sqlDebug) {
389 Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data());
391 if (m_console->sql_cmd(query, results)) {
392 int resultCount = results.count();
393 if (resultCount == 1){
396 QStringList fieldlist;
397 /* there will only be one of these */
398 foreach (resultline, results) {
399 fieldlist = resultline.split("\t");
401 /* Iterate through fields in the record */
402 foreach (field, fieldlist) {
403 field = field.trimmed(); /* strip leading & trailing spaces */
404 haschanger = field.toInt();
411 Pmsg1(000, "haschanger is : %i\n", haschanger);
412 if (haschanger == 0){
413 /* no autochanger, just execute the command in the console */
414 QString cmd("mount storage=" + m_storage);
416 } else if (haschanger != 3) {
418 /* if this storage is an autochanger, lets ask for the slot */
419 new mountDialog(m_console, m_storage);
424 * execute umount in console
426 void StorStat::umountButtonPushed()
428 QString cmd("umount storage=" + m_storage);