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 #include <QAbstractEventDispatcher>
24 #include "label/label.h"
25 #include "mediainfo/mediainfo.h"
26 #include "mount/mount.h"
27 #include "util/fmtwidgetitem.h"
28 #include "status/storstat.h"
32 // List drives in autochanger
33 // use user selection to add slot= argument
36 Content::Content(QString storage, QTreeWidgetItem *parentWidget) : Pages()
39 pgInitialize(storage, parentWidget);
40 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
41 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
44 m_firstpopulation = true;
45 m_checkcurwidget = true;
46 m_currentStorage = storage;
48 connect(pbUpdate, SIGNAL(clicked()), this,
49 SLOT(consoleUpdateSlots()));
51 connect(pbLabel, SIGNAL(clicked()), this,
52 SLOT(consoleLabelStorage()));
54 connect(pbMount, SIGNAL(clicked()), this,
55 SLOT(consoleMountStorage()));
57 connect(pbUnmount, SIGNAL(clicked()), this,
58 SLOT(consoleUnMountStorage()));
60 connect(pbStatus, SIGNAL(clicked()), this,
61 SLOT(statusStorageWindow()));
63 connect(pbRelease, SIGNAL(clicked()), this,
64 SLOT(consoleRelease()));
66 connect(tableContent, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this,
67 SLOT(showMediaInfo(QTableWidgetItem *)));
75 * Subroutine to call class to show the log in the database from that job
77 void Content::showMediaInfo(QTableWidgetItem * item)
79 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
80 int row = item->row();
81 QString vol = tableContent->item(row, 1)->text();
83 new MediaInfo(pageSelectorTreeWidgetItem, vol);
87 void table_get_selection(QTableWidget *table, QString &sel)
89 QTableWidgetItem *item;
92 /* The QT selection returns each cell, so you
93 * have x times the same row number...
94 * We take only one instance
96 int s = table->rowCount();
101 bool *tab = (bool *)malloc(s * sizeof(bool));
104 foreach (item, table->selectedItems()) {
105 current = item->row();
111 for(int i=0; i<s; i++) {
113 sel += table->item(i, 0)->text();
117 sel.chop(1); // remove trailing , or useless =
121 /* Label Media populating current storage by default */
122 void Content::consoleLabelStorage()
125 table_get_selection(tableContent, sel);
127 new labelPage(m_currentStorage);
129 QString cmd = "label barcodes slots";
131 cmd += " storage=" + m_currentStorage;
136 /* Mount currently selected storage */
137 void Content::consoleMountStorage()
140 /* if this storage is an autochanger, lets ask for the slot */
141 new mountDialog(m_console, m_currentStorage);
144 /* Unmount Currently selected storage */
145 void Content::consoleUnMountStorage()
147 QString cmd("umount storage=");
148 cmd += m_currentStorage;
152 void Content::statusStorageWindow()
154 /* if one exists, then just set it current */
156 foreach(Pages *page, mainWin->m_pagehash) {
157 if (mainWin->currentConsole() == page->console()) {
158 if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
165 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
166 new StorStat(m_currentStorage, parentItem);
171 * The main meat of the class!! The function that querries the director and
172 * creates the widgets with appropriate values.
174 void Content::populateContent()
180 QStringList results_all;
181 QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
182 m_console->dir_cmd(cmd, results_all);
184 Freeze frz(*tableContent); /* disable updating*/
185 Freeze frz2(*tableTray);
186 Freeze frz3(*tableDrive);
188 tableContent->clearContents();
189 tableTray->clearContents();
190 tableTray->clearContents();
192 // take only valid records, TODO: Add D to get drive status
193 QStringList results = results_all.filter(QRegExp("^[IS]\\|[0-9]+\\|"));
194 tableContent->setRowCount(results.size());
196 QStringList io_results = results_all.filter(QRegExp("^I\\|[0-9]+\\|"));
197 tableTray->setRowCount(io_results.size());
200 QStringList fieldlist;
201 int row = 0, row_io=0;
203 foreach (resultline, results) {
204 fieldlist = resultline.split("|");
205 if (fieldlist.size() < 10) {
206 Pmsg1(0, "Discarding %s\n", resultline.data());
207 continue; /* some fields missing, ignore row */
211 QStringListIterator fld(fieldlist);
212 TableItemFormatter slotitem(*tableContent, row);
215 if (fld.next() == "I") {
216 TableItemFormatter ioitem(*tableTray, row_io++);
217 ioitem.setNumericFld(0, fieldlist[1]);
218 ioitem.setTextFld(1, fieldlist[3]);
222 slotitem.setNumericFld(index++, fld.next());
225 if (fld.next() != "") {
228 slotitem.setTextFld(index++, fld.next());
231 slotitem.setBytesFld(index++, fld.next());
234 slotitem.setVolStatusFld(index++, fld.next());
237 slotitem.setTextFld(index++, fld.next());
240 slotitem.setTextFld(index++, fld.next());
242 tim = fld.next().toInt();
245 localtime_r(&tim, &tm);
246 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
247 slotitem.setTextFld(index++, QString(buf));
250 tim = fld.next().toInt();
251 localtime_r(&tim, &tm);
252 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
253 slotitem.setTextFld(index++, QString(buf));
260 tableContent->verticalHeader()->hide();
261 tableContent->sortByColumn(0, Qt::AscendingOrder);
262 tableContent->setSortingEnabled(true);
263 tableContent->resizeColumnsToContents();
264 tableContent->resizeRowsToContents();
266 tableContent->setEditTriggers(QAbstractItemView::NoEditTriggers);
269 tableTray->verticalHeader()->hide();
270 tableTray->setEditTriggers(QAbstractItemView::NoEditTriggers);
272 tableDrive->verticalHeader()->hide();
273 /* Get count of rows needed (Drives) */
274 QStringList drives = results_all.filter(QRegExp("^D\\|[0-9]+\\|"));
275 /* Ensure we have sufficient rows for Drive display */
276 tableDrive->setRowCount(drives.size());
278 foreach (resultline, drives) {
279 fieldlist = resultline.split("|");
280 if (fieldlist.size() < 4) {
281 continue; /* some fields missing, ignore row */
284 QStringListIterator fld(fieldlist);
285 TableItemFormatter slotitem(*tableDrive, row);
291 slotitem.setNumericFld(index++, fld.next());
297 slotitem.setTextFld(index++, fld.next());
302 tableDrive->resizeRowsToContents();
303 tableDrive->setEditTriggers(QAbstractItemView::NoEditTriggers);
307 * Virtual function which is called when this page is visible on the stack
309 void Content::currentStackItem()
316 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
322 void Content::consoleUpdateSlots()
325 table_get_selection(tableContent, sel);
327 QString cmd("update slots");
331 cmd += " drive=0 storage=" + m_currentStorage;
333 Pmsg1(0, "cmd=%s\n", cmd.toUtf8().data());
339 /* Release a tape in the drive */
340 void Content::consoleRelease()
342 QString cmd("release storage=");
343 cmd += m_currentStorage;