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 many
7 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 Bacula® is a registered trademark of Kern Sibbald.
18 #include <QAbstractEventDispatcher>
21 #include "label/label.h"
22 #include "mediainfo/mediainfo.h"
23 #include "mount/mount.h"
24 #include "util/fmtwidgetitem.h"
25 #include "status/storstat.h"
29 // List drives in autochanger
30 // use user selection to add slot= argument
33 Content::Content(QString storage, QTreeWidgetItem *parentWidget) : Pages()
36 pgInitialize(storage, parentWidget);
37 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
38 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
41 m_firstpopulation = true;
42 m_checkcurwidget = true;
43 m_currentStorage = storage;
45 connect(pbUpdate, SIGNAL(clicked()), this,
46 SLOT(consoleUpdateSlots()));
48 connect(pbLabel, SIGNAL(clicked()), this,
49 SLOT(consoleLabelStorage()));
51 connect(pbMount, SIGNAL(clicked()), this,
52 SLOT(consoleMountStorage()));
54 connect(pbUnmount, SIGNAL(clicked()), this,
55 SLOT(consoleUnMountStorage()));
57 connect(pbStatus, SIGNAL(clicked()), this,
58 SLOT(statusStorageWindow()));
60 connect(pbRelease, SIGNAL(clicked()), this,
61 SLOT(consoleRelease()));
63 connect(tableContent, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this,
64 SLOT(showMediaInfo(QTableWidgetItem *)));
72 * Subroutine to call class to show the log in the database from that job
74 void Content::showMediaInfo(QTableWidgetItem * item)
76 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
77 int row = item->row();
78 QString vol = tableContent->item(row, 1)->text();
80 new MediaInfo(pageSelectorTreeWidgetItem, vol);
84 void table_get_selection(QTableWidget *table, QString &sel)
86 QTableWidgetItem *item;
89 /* The QT selection returns each cell, so you
90 * have x times the same row number...
91 * We take only one instance
93 int s = table->rowCount();
94 bool *tab = (bool *)malloc(s * sizeof(bool));
97 foreach (item, table->selectedItems()) {
98 current = item->row();
104 for(int i=0; i<s; i++) {
106 sel += table->item(i, 0)->text();
110 sel.chop(1); // remove trailing , or useless =
114 /* Label Media populating current storage by default */
115 void Content::consoleLabelStorage()
118 table_get_selection(tableContent, sel);
120 new labelPage(m_currentStorage);
122 QString cmd = "label barcodes slots";
124 cmd += " storage=" + m_currentStorage;
129 /* Mount currently selected storage */
130 void Content::consoleMountStorage()
133 /* if this storage is an autochanger, lets ask for the slot */
134 new mountDialog(m_console, m_currentStorage);
137 /* Unmount Currently selected storage */
138 void Content::consoleUnMountStorage()
140 QString cmd("umount storage=");
141 cmd += m_currentStorage;
145 void Content::statusStorageWindow()
147 /* if one exists, then just set it current */
149 foreach(Pages *page, mainWin->m_pagehash) {
150 if (mainWin->currentConsole() == page->console()) {
151 if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
158 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
159 new StorStat(m_currentStorage, parentItem);
164 * The main meat of the class!! The function that querries the director and
165 * creates the widgets with appropriate values.
167 void Content::populateContent()
173 QStringList results_all;
174 QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
175 m_console->dir_cmd(cmd, results_all);
177 Freeze frz(*tableContent); /* disable updating*/
178 Freeze frz2(*tableTray);
179 Freeze frz3(*tableDrive);
181 tableContent->clearContents();
182 tableTray->clearContents();
183 tableTray->clearContents();
185 // take only valid records, TODO: Add D to get drive status
186 QStringList results = results_all.filter(QRegExp("^[IS]\\|[0-9]+\\|"));
187 tableContent->setRowCount(results.size());
189 QStringList io_results = results_all.filter(QRegExp("^I\\|[0-9]+\\|"));
190 tableTray->setRowCount(io_results.size());
193 QStringList fieldlist;
194 int row = 0, row_io=0;
196 foreach (resultline, results) {
197 fieldlist = resultline.split("|");
198 if (fieldlist.size() < 10) {
199 Pmsg1(0, "Discarding %s\n", resultline.data());
200 continue; /* some fields missing, ignore row */
204 QStringListIterator fld(fieldlist);
205 TableItemFormatter slotitem(*tableContent, row);
208 if (fld.next() == "I") {
209 TableItemFormatter ioitem(*tableTray, row_io++);
210 ioitem.setNumericFld(0, fieldlist[1]);
211 ioitem.setTextFld(1, fieldlist[3]);
215 slotitem.setNumericFld(index++, fld.next());
218 if (fld.next() != "") {
221 slotitem.setTextFld(index++, fld.next());
224 slotitem.setBytesFld(index++, fld.next());
227 slotitem.setVolStatusFld(index++, fld.next());
230 slotitem.setTextFld(index++, fld.next());
233 slotitem.setTextFld(index++, fld.next());
235 tim = fld.next().toInt();
238 localtime_r(&tim, &tm);
239 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
240 slotitem.setTextFld(index++, QString(buf));
243 tim = fld.next().toInt();
244 localtime_r(&tim, &tm);
245 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
246 slotitem.setTextFld(index++, QString(buf));
252 tableContent->verticalHeader()->hide();
253 tableContent->sortByColumn(0, Qt::AscendingOrder);
254 tableContent->setSortingEnabled(true);
255 tableContent->resizeColumnsToContents();
256 tableContent->resizeRowsToContents();
258 tableContent->setEditTriggers(QAbstractItemView::NoEditTriggers);
261 tableTray->verticalHeader()->hide();
262 tableTray->setEditTriggers(QAbstractItemView::NoEditTriggers);
264 tableDrive->verticalHeader()->hide();
265 QStringList drives = results_all.filter(QRegExp("^D\\|[0-9]+\\|"));
266 tableDrive->setRowCount(drives.size());
269 foreach (resultline, drives) {
270 fieldlist = resultline.split("|");
271 if (fieldlist.size() < 4) {
272 Pmsg1(0, "Discarding %s\n", resultline.data());
273 continue; /* some fields missing, ignore row */
277 QStringListIterator fld(fieldlist);
278 TableItemFormatter slotitem(*tableDrive, row);
284 slotitem.setNumericFld(index++, fld.next());
290 slotitem.setTextFld(index++, fld.next());
295 tableDrive->resizeRowsToContents();
296 tableDrive->setEditTriggers(QAbstractItemView::NoEditTriggers);
300 * Virtual function which is called when this page is visible on the stack
302 void Content::currentStackItem()
309 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
315 void Content::consoleUpdateSlots()
318 table_get_selection(tableContent, sel);
320 QString cmd("update slots");
324 cmd += " drive=0 storage=" + m_currentStorage;
326 Pmsg1(0, "cmd=%s\n", cmd.toUtf8().data());
332 /* Release a tape in the drive */
333 void Content::consoleRelease()
335 QString cmd("release storage=");
336 cmd += m_currentStorage;