2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2010 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 three of the GNU Affero 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 Affero 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.
30 * Dirk Bartley, March 2007
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
37 #include "mount/mount.h"
38 #include "label/label.h"
40 static bool working = false; /* prevent timer recursion */
43 .status storage=<storage-name> <keyword>
44 where <storage-name> is the storage name in the Director, and
45 <keyword> is one of the following:
57 * Constructor for the class
59 StorStat::StorStat(QString &storage, QTreeWidgetItem *parentTreeWidgetItem)
64 pgInitialize(tr("Storage Status %1").arg(m_storage), parentTreeWidgetItem);
65 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
66 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
67 m_cursor = new QTextCursor(textEditHeader->document());
69 m_timer = new QTimer(this);
79 void StorStat::getFont()
81 QFont font = textEditHeader->font();
84 m_console->getDirResName(dirname);
85 QSettings settings(dirname, "bat");
86 settings.beginGroup("Console");
87 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
88 font.setPointSize(settings.value("consolePointSize", 10).toInt());
89 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
91 textEditHeader->setFont(font);
95 * Write the m_splitter settings in the destructor
103 * Populate all tables and header widgets
105 void StorStat::populateAll()
107 populateTerminated();
108 populateCurrentTab(tabWidget->currentIndex());
112 * Timer is triggered, see if is current and repopulate.
114 void StorStat::timerTriggered()
116 double value = timerDisplay->value();
118 if (value <= 0 && !working) {
120 value = spinBox->value();
121 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
122 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
127 timerDisplay->display(value);
131 * Populate header text widget
133 void StorStat::populateHeader()
135 QString command = QString(".status storage=\"" + m_storage + "\" header");
136 if (mainWin->m_commandDebug)
137 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
139 textEditHeader->clear();
141 if (m_console->dir_cmd(command, results)) {
142 foreach (QString line, results) {
144 textEditHeader->insertPlainText(line);
149 void StorStat::populateWaitReservation()
151 QString command = QString(".status storage=\"" + m_storage + "\" waitreservation");
152 if (mainWin->m_commandDebug)
153 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
155 textEditWaitReservation->clear();
157 if (m_console->dir_cmd(command, results)) {
158 foreach (QString line, results) {
160 textEditWaitReservation->insertPlainText(line);
165 void StorStat::populateDevices()
167 QString command = QString(".status storage=\"" + m_storage + "\" devices");
168 if (mainWin->m_commandDebug)
169 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
171 textEditDevices->clear();
173 if (m_console->dir_cmd(command, results)) {
174 foreach (QString line, results) {
176 textEditDevices->insertPlainText(line);
181 void StorStat::populateVolumes()
183 QString command = QString(".status storage=\"" + m_storage + "\" volumes");
184 if (mainWin->m_commandDebug)
185 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
187 textEditVolumes->clear();
189 if (m_console->dir_cmd(command, results)) {
190 foreach (QString line, results) {
192 textEditVolumes->insertPlainText(line);
197 void StorStat::populateSpooling()
199 QString command = QString(".status storage=\"" + m_storage + "\" spooling");
200 if (mainWin->m_commandDebug)
201 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
203 textEditSpooling->clear();
205 if (m_console->dir_cmd(command, results)) {
206 foreach (QString line, results) {
208 textEditSpooling->insertPlainText(line);
213 void StorStat::populateRunning()
215 QString command = QString(".status storage=\"" + m_storage + "\" running");
216 if (mainWin->m_commandDebug)
217 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
219 textEditRunning->clear();
221 if (m_console->dir_cmd(command, results)) {
222 foreach (QString line, results) {
224 textEditRunning->insertPlainText(line);
230 * Populate teminated table
232 void StorStat::populateTerminated()
234 QString command = QString(".status storage=\"" + m_storage + "\" terminated");
235 if (mainWin->m_commandDebug)
236 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
238 QBrush blackBrush(Qt::black);
240 terminatedTable->clear();
241 QStringList headerlist = (QStringList()
242 << tr("Job Id") << tr("Job Level") << tr("Job Files")
243 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
245 QStringList flaglist = (QStringList()
246 << "R" << "L" << "R" << "R" << "LC"
249 terminatedTable->setColumnCount(headerlist.size());
250 terminatedTable->setHorizontalHeaderLabels(headerlist);
252 if (m_console->dir_cmd(command, results)) {
254 QTableWidgetItem* p_tableitem;
255 terminatedTable->setRowCount(results.size());
256 foreach (QString line, results) {
257 /* Iterate through the record returned from the query */
258 QStringList fieldlist = line.split("\t");
260 QString statusCode("");
261 /* Iterate through fields in the record */
262 foreach (QString field, fieldlist) {
263 field = field.trimmed(); /* strip leading & trailing spaces */
264 p_tableitem = new QTableWidgetItem(field, 1);
265 p_tableitem->setForeground(blackBrush);
266 p_tableitem->setFlags(0);
267 if (flaglist[column].contains("R"))
268 p_tableitem->setTextAlignment(Qt::AlignRight);
269 if (flaglist[column].contains("C")) {
271 p_tableitem->setBackground(Qt::green);
273 p_tableitem->setBackground(Qt::red);
275 terminatedTable->setItem(row, column, p_tableitem);
281 terminatedTable->resizeColumnsToContents();
282 terminatedTable->resizeRowsToContents();
283 terminatedTable->verticalHeader()->hide();
287 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
288 * The tree has been populated.
290 void StorStat::PgSeltreeWidgetClicked()
299 * Virtual function override of pages function which is called when this page
300 * is visible on the stack
302 void StorStat::currentStackItem()
305 timerDisplay->display(spinBox->value());
312 * Function to create connections for context sensitive menu for this and
315 void StorStat::createConnections()
317 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
318 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
319 connect(mountButton, SIGNAL(pressed()), this, SLOT(mountButtonPushed()));
320 connect(umountButton, SIGNAL(pressed()), this, SLOT(umountButtonPushed()));
321 connect(labelButton, SIGNAL(pressed()), this, SLOT(labelButtonPushed()));
322 connect(releaseButton, SIGNAL(pressed()), this, SLOT(releaseButtonPushed()));
323 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
324 terminatedTable->addAction(actionRefresh);
325 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
329 * Save user settings associated with this page
331 void StorStat::writeSettings()
333 QSettings settings(m_console->m_dir->name(), "bat");
334 settings.beginGroup(m_groupText);
335 settings.setValue(m_splitText, splitter->saveState());
336 settings.setValue("refreshInterval", spinBox->value());
337 settings.setValue("refreshCheck", checkBox->checkState());
340 settings.beginGroup("OpenOnExit");
341 QString toWrite = "StorageStatus_" + m_storage;
342 settings.setValue(toWrite, 1);
347 * Read and restore user settings associated with this page
349 void StorStat::readSettings()
351 m_groupText = "StorStatPage";
352 m_splitText = "splitterSizes_0";
353 QSettings settings(m_console->m_dir->name(), "bat");
354 settings.beginGroup(m_groupText);
355 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
356 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
357 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
360 timerDisplay->display(spinBox->value());
364 * Populate the text edit window in the current tab
366 void StorStat::populateCurrentTab(int index)
371 populateWaitReservation();
383 * execute mount in console
385 void StorStat::mountButtonPushed()
389 /* Set up query QString and header QStringList */
390 QString query("SELECT AutoChanger AS Changer"
391 " FROM Storage WHERE Name='" + m_storage + "'"
395 /* This could be a log item */
396 if (mainWin->m_sqlDebug) {
397 Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data());
399 if (m_console->sql_cmd(query, results)) {
400 int resultCount = results.count();
401 if (resultCount == 1){
404 QStringList fieldlist;
405 /* there will only be one of these */
406 foreach (resultline, results) {
407 fieldlist = resultline.split("\t");
409 /* Iterate through fields in the record */
410 foreach (field, fieldlist) {
411 field = field.trimmed(); /* strip leading & trailing spaces */
412 haschanger = field.toInt();
419 Pmsg1(000, "haschanger is : %i\n", haschanger);
420 if (haschanger == 0){
421 /* no autochanger, just execute the command in the console */
422 QString cmd("mount storage=" + m_storage);
424 } else if (haschanger != 3) {
426 /* if this storage is an autochanger, lets ask for the slot */
427 new mountDialog(m_console, m_storage);
432 * execute umount in console
434 void StorStat::umountButtonPushed()
436 QString cmd("umount storage=" + m_storage);
440 /* Release a tape in the drive */
441 void StorStat::releaseButtonPushed()
443 QString cmd("release storage=");
448 /* Label Media populating current storage by default */
449 void StorStat::labelButtonPushed()
451 new labelPage(m_storage);