2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Dirk Bartley, March 2007
25 #include <QAbstractEventDispatcher>
26 #include <QTableWidgetItem>
28 #include "mount/mount.h"
29 #include "label/label.h"
31 static bool working = false; /* prevent timer recursion */
34 .status storage=<storage-name> <keyword>
35 where <storage-name> is the storage name in the Director, and
36 <keyword> is one of the following:
48 * Constructor for the class
50 StorStat::StorStat(QString &storage, QTreeWidgetItem *parentTreeWidgetItem)
55 pgInitialize(tr("Storage Status %1").arg(m_storage), parentTreeWidgetItem);
56 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
57 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/status.png")));
58 m_cursor = new QTextCursor(textEditHeader->document());
60 m_timer = new QTimer(this);
70 void StorStat::getFont()
72 QFont font = textEditHeader->font();
75 m_console->getDirResName(dirname);
76 QSettings settings(dirname, "bat");
77 settings.beginGroup("Console");
78 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
79 font.setPointSize(settings.value("consolePointSize", 10).toInt());
80 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
82 textEditHeader->setFont(font);
86 * Write the m_splitter settings in the destructor
94 * Populate all tables and header widgets
96 void StorStat::populateAll()
99 populateCurrentTab(tabWidget->currentIndex());
103 * Timer is triggered, see if is current and repopulate.
105 void StorStat::timerTriggered()
107 double value = timerDisplay->value();
109 if (value <= 0 && !working) {
111 value = spinBox->value();
112 bool iscurrent = mainWin->tabWidget->currentIndex() == mainWin->tabWidget->indexOf(this);
113 if (((isDocked() && iscurrent) || (!isDocked())) && (checkBox->checkState() == Qt::Checked)) {
118 timerDisplay->display(value);
122 * Populate header text widget
124 void StorStat::populateHeader()
126 QString command = QString(".status storage=\"" + m_storage + "\" header");
127 if (mainWin->m_commandDebug)
128 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
130 textEditHeader->clear();
132 if (m_console->dir_cmd(command, results)) {
133 foreach (QString line, results) {
135 textEditHeader->insertPlainText(line);
140 void StorStat::populateWaitReservation()
142 QString command = QString(".status storage=\"" + m_storage + "\" waitreservation");
143 if (mainWin->m_commandDebug)
144 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
146 textEditWaitReservation->clear();
148 if (m_console->dir_cmd(command, results)) {
149 foreach (QString line, results) {
151 textEditWaitReservation->insertPlainText(line);
156 void StorStat::populateDevices()
158 QString command = QString(".status storage=\"" + m_storage + "\" devices");
159 if (mainWin->m_commandDebug)
160 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
162 textEditDevices->clear();
164 if (m_console->dir_cmd(command, results)) {
165 foreach (QString line, results) {
167 textEditDevices->insertPlainText(line);
172 void StorStat::populateVolumes()
174 QString command = QString(".status storage=\"" + m_storage + "\" volumes");
175 if (mainWin->m_commandDebug)
176 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
178 textEditVolumes->clear();
180 if (m_console->dir_cmd(command, results)) {
181 foreach (QString line, results) {
183 textEditVolumes->insertPlainText(line);
188 void StorStat::populateSpooling()
190 QString command = QString(".status storage=\"" + m_storage + "\" spooling");
191 if (mainWin->m_commandDebug)
192 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
194 textEditSpooling->clear();
196 if (m_console->dir_cmd(command, results)) {
197 foreach (QString line, results) {
199 textEditSpooling->insertPlainText(line);
204 void StorStat::populateRunning()
206 QString command = QString(".status storage=\"" + m_storage + "\" running");
207 if (mainWin->m_commandDebug)
208 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
210 textEditRunning->clear();
212 if (m_console->dir_cmd(command, results)) {
213 foreach (QString line, results) {
215 textEditRunning->insertPlainText(line);
221 * Populate teminated table
223 void StorStat::populateTerminated()
225 QString command = QString(".status storage=\"" + m_storage + "\" terminated");
226 if (mainWin->m_commandDebug)
227 Pmsg1(000, "sending command : %s\n",command.toUtf8().data());
229 QBrush blackBrush(Qt::black);
231 terminatedTable->clear();
232 QStringList headerlist = (QStringList()
233 << tr("Job Id") << tr("Job Level") << tr("Job Files")
234 << tr("Job Bytes") << tr("Job Status") << tr("Job Time")
236 QStringList flaglist = (QStringList()
237 << "R" << "L" << "R" << "R" << "LC"
240 terminatedTable->setColumnCount(headerlist.size());
241 terminatedTable->setHorizontalHeaderLabels(headerlist);
243 if (m_console->dir_cmd(command, results)) {
245 QTableWidgetItem* p_tableitem;
246 terminatedTable->setRowCount(results.size());
247 foreach (QString line, results) {
248 /* Iterate through the record returned from the query */
249 QStringList fieldlist = line.split("\t");
251 QString statusCode("");
252 /* Iterate through fields in the record */
253 foreach (QString field, fieldlist) {
254 field = field.trimmed(); /* strip leading & trailing spaces */
255 p_tableitem = new QTableWidgetItem(field, 1);
256 p_tableitem->setForeground(blackBrush);
257 p_tableitem->setFlags(0);
258 if (flaglist[column].contains("R"))
259 p_tableitem->setTextAlignment(Qt::AlignRight);
260 if (flaglist[column].contains("C")) {
262 p_tableitem->setBackground(Qt::green);
264 p_tableitem->setBackground(Qt::red);
266 terminatedTable->setItem(row, column, p_tableitem);
272 terminatedTable->resizeColumnsToContents();
273 terminatedTable->resizeRowsToContents();
274 terminatedTable->verticalHeader()->hide();
278 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
279 * The tree has been populated.
281 void StorStat::PgSeltreeWidgetClicked()
290 * Virtual function override of pages function which is called when this page
291 * is visible on the stack
293 void StorStat::currentStackItem()
296 timerDisplay->display(spinBox->value());
303 * Function to create connections for context sensitive menu for this and
306 void StorStat::createConnections()
308 connect(actionRefresh, SIGNAL(triggered()), this, SLOT(populateAll()));
309 connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(populateCurrentTab(int)));
310 connect(mountButton, SIGNAL(pressed()), this, SLOT(mountButtonPushed()));
311 connect(umountButton, SIGNAL(pressed()), this, SLOT(umountButtonPushed()));
312 connect(labelButton, SIGNAL(pressed()), this, SLOT(labelButtonPushed()));
313 connect(releaseButton, SIGNAL(pressed()), this, SLOT(releaseButtonPushed()));
314 terminatedTable->setContextMenuPolicy(Qt::ActionsContextMenu);
315 terminatedTable->addAction(actionRefresh);
316 connect(m_timer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
320 * Save user settings associated with this page
322 void StorStat::writeSettings()
324 QSettings settings(m_console->m_dir->name(), "bat");
325 settings.beginGroup(m_groupText);
326 settings.setValue(m_splitText, splitter->saveState());
327 settings.setValue("refreshInterval", spinBox->value());
328 settings.setValue("refreshCheck", checkBox->checkState());
331 settings.beginGroup("OpenOnExit");
332 QString toWrite = "StorageStatus_" + m_storage;
333 settings.setValue(toWrite, 1);
338 * Read and restore user settings associated with this page
340 void StorStat::readSettings()
342 m_groupText = "StorStatPage";
343 m_splitText = "splitterSizes_0";
344 QSettings settings(m_console->m_dir->name(), "bat");
345 settings.beginGroup(m_groupText);
346 if (settings.contains(m_splitText)) { splitter->restoreState(settings.value(m_splitText).toByteArray()); }
347 spinBox->setValue(settings.value("refreshInterval", 28).toInt());
348 checkBox->setCheckState((Qt::CheckState)settings.value("refreshCheck", Qt::Checked).toInt());
351 timerDisplay->display(spinBox->value());
355 * Populate the text edit window in the current tab
357 void StorStat::populateCurrentTab(int index)
362 populateWaitReservation();
374 * execute mount in console
376 void StorStat::mountButtonPushed()
380 /* Set up query QString and header QStringList */
381 QString query("SELECT AutoChanger AS Changer"
382 " FROM Storage WHERE Name='" + m_storage + "'"
386 /* This could be a log item */
387 if (mainWin->m_sqlDebug) {
388 Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data());
390 if (m_console->sql_cmd(query, results)) {
391 int resultCount = results.count();
392 if (resultCount == 1){
395 QStringList fieldlist;
396 /* there will only be one of these */
397 foreach (resultline, results) {
398 fieldlist = resultline.split("\t");
400 /* Iterate through fields in the record */
401 foreach (field, fieldlist) {
402 field = field.trimmed(); /* strip leading & trailing spaces */
403 haschanger = field.toInt();
410 Pmsg1(000, "haschanger is : %i\n", haschanger);
411 if (haschanger == 0){
412 /* no autochanger, just execute the command in the console */
413 QString cmd("mount storage=" + m_storage);
415 } else if (haschanger != 3) {
417 /* if this storage is an autochanger, lets ask for the slot */
418 new mountDialog(m_console, m_storage);
423 * execute umount in console
425 void StorStat::umountButtonPushed()
427 QString cmd("umount storage=" + m_storage);
431 /* Release a tape in the drive */
432 void StorStat::releaseButtonPushed()
434 QString cmd("release storage=");
439 /* Label Media populating current storage by default */
440 void StorStat::labelButtonPushed()
442 new labelPage(m_storage);