2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
22 #include <QAbstractEventDispatcher>
25 #include "label/label.h"
26 #include "mediainfo/mediainfo.h"
27 #include "mount/mount.h"
28 #include "util/fmtwidgetitem.h"
29 #include "status/storstat.h"
33 // List drives in autochanger
34 // use user selection to add slot= argument
37 Content::Content(QString storage, QTreeWidgetItem *parentWidget) : Pages()
40 pgInitialize(storage, parentWidget);
41 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
42 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
45 m_firstpopulation = true;
46 m_checkcurwidget = true;
47 m_currentStorage = storage;
49 connect(pbUpdate, SIGNAL(clicked()), this,
50 SLOT(consoleUpdateSlots()));
52 connect(pbLabel, SIGNAL(clicked()), this,
53 SLOT(consoleLabelStorage()));
55 connect(pbMount, SIGNAL(clicked()), this,
56 SLOT(consoleMountStorage()));
58 connect(pbUnmount, SIGNAL(clicked()), this,
59 SLOT(consoleUnMountStorage()));
61 connect(pbStatus, SIGNAL(clicked()), this,
62 SLOT(statusStorageWindow()));
64 connect(pbRelease, SIGNAL(clicked()), this,
65 SLOT(consoleRelease()));
67 connect(tableContent, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this,
68 SLOT(showMediaInfo(QTableWidgetItem *)));
76 * Subroutine to call class to show the log in the database from that job
78 void Content::showMediaInfo(QTableWidgetItem * item)
80 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
81 int row = item->row();
82 QString vol = tableContent->item(row, 1)->text();
84 new MediaInfo(pageSelectorTreeWidgetItem, vol);
88 void table_get_selection(QTableWidget *table, QString &sel)
90 QTableWidgetItem *item;
93 /* The QT selection returns each cell, so you
94 * have x times the same row number...
95 * We take only one instance
97 int s = table->rowCount();
102 bool *tab = (bool *)malloc(s * sizeof(bool));
105 foreach (item, table->selectedItems()) {
106 current = item->row();
112 for(int i=0; i<s; i++) {
114 sel += table->item(i, 0)->text();
118 sel.chop(1); // remove trailing , or useless =
122 /* Label Media populating current storage by default */
123 void Content::consoleLabelStorage()
126 table_get_selection(tableContent, sel);
128 new labelPage(m_currentStorage);
130 QString cmd = "label barcodes slots";
132 cmd += " storage=" + m_currentStorage;
137 /* Mount currently selected storage */
138 void Content::consoleMountStorage()
141 /* if this storage is an autochanger, lets ask for the slot */
142 new mountDialog(m_console, m_currentStorage);
145 /* Unmount Currently selected storage */
146 void Content::consoleUnMountStorage()
148 QString cmd("umount storage=");
149 cmd += m_currentStorage;
153 void Content::statusStorageWindow()
155 /* if one exists, then just set it current */
157 foreach(Pages *page, mainWin->m_pagehash) {
158 if (mainWin->currentConsole() == page->console()) {
159 if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
166 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
167 new StorStat(m_currentStorage, parentItem);
172 * The main meat of the class!! The function that querries the director and
173 * creates the widgets with appropriate values.
175 void Content::populateContent()
181 QStringList results_all;
182 QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
183 m_console->dir_cmd(cmd, results_all);
185 Freeze frz(*tableContent); /* disable updating*/
186 Freeze frz2(*tableTray);
187 Freeze frz3(*tableDrive);
189 tableContent->clearContents();
190 tableTray->clearContents();
191 tableTray->clearContents();
193 // take only valid records, TODO: Add D to get drive status
194 QStringList results = results_all.filter(QRegExp("^[IS]\\|[0-9]+\\|"));
195 tableContent->setRowCount(results.size());
197 QStringList io_results = results_all.filter(QRegExp("^I\\|[0-9]+\\|"));
198 tableTray->setRowCount(io_results.size());
201 QStringList fieldlist;
202 int row = 0, row_io=0;
204 foreach (resultline, results) {
205 fieldlist = resultline.split("|");
206 if (fieldlist.size() < 10) {
207 Pmsg1(0, "Discarding %s\n", resultline.data());
208 continue; /* some fields missing, ignore row */
212 QStringListIterator fld(fieldlist);
213 TableItemFormatter slotitem(*tableContent, row);
216 if (fld.next() == "I") {
217 TableItemFormatter ioitem(*tableTray, row_io++);
218 ioitem.setNumericFld(0, fieldlist[1]);
219 ioitem.setTextFld(1, fieldlist[3]);
223 slotitem.setNumericFld(index++, fld.next());
226 if (fld.next() != "") {
229 slotitem.setTextFld(index++, fld.next());
232 slotitem.setBytesFld(index++, fld.next());
235 slotitem.setVolStatusFld(index++, fld.next());
238 slotitem.setTextFld(index++, fld.next());
241 slotitem.setTextFld(index++, fld.next());
243 tim = fld.next().toInt();
246 localtime_r(&tim, &tm);
247 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
248 slotitem.setTextFld(index++, QString(buf));
251 tim = fld.next().toInt();
252 localtime_r(&tim, &tm);
253 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
254 slotitem.setTextFld(index++, QString(buf));
261 tableContent->verticalHeader()->hide();
262 tableContent->sortByColumn(0, Qt::AscendingOrder);
263 tableContent->setSortingEnabled(true);
264 tableContent->resizeColumnsToContents();
265 tableContent->resizeRowsToContents();
267 tableContent->setEditTriggers(QAbstractItemView::NoEditTriggers);
270 tableTray->verticalHeader()->hide();
271 tableTray->setEditTriggers(QAbstractItemView::NoEditTriggers);
273 tableDrive->verticalHeader()->hide();
274 /* Get count of rows needed (Drives) */
275 QStringList drives = results_all.filter(QRegExp("^D\\|[0-9]+\\|"));
276 /* Ensure we have sufficient rows for Drive display */
277 tableDrive->setRowCount(drives.size());
279 foreach (resultline, drives) {
280 fieldlist = resultline.split("|");
281 if (fieldlist.size() < 4) {
282 continue; /* some fields missing, ignore row */
285 QStringListIterator fld(fieldlist);
286 TableItemFormatter slotitem(*tableDrive, row);
292 slotitem.setNumericFld(index++, fld.next());
298 slotitem.setTextFld(index++, fld.next());
303 tableDrive->resizeRowsToContents();
304 tableDrive->setEditTriggers(QAbstractItemView::NoEditTriggers);
308 * Virtual function which is called when this page is visible on the stack
310 void Content::currentStackItem()
317 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
323 void Content::consoleUpdateSlots()
326 table_get_selection(tableContent, sel);
328 QString cmd("update slots");
332 cmd += " drive=0 storage=" + m_currentStorage;
334 Pmsg1(0, "cmd=%s\n", cmd.toUtf8().data());
340 /* Release a tape in the drive */
341 void Content::consoleRelease()
343 QString cmd("release storage=");
344 cmd += m_currentStorage;