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
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 #include <QAbstractEventDispatcher>
33 #include "label/label.h"
34 #include "mediainfo/mediainfo.h"
35 #include "mount/mount.h"
36 #include "util/fmtwidgetitem.h"
37 #include "status/storstat.h"
41 // List drives in autochanger
42 // use user selection to add slot= argument
45 Content::Content(QString storage, QTreeWidgetItem *parentWidget) : Pages()
48 pgInitialize(storage, parentWidget);
49 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
50 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
53 m_firstpopulation = true;
54 m_checkcurwidget = true;
55 m_currentStorage = storage;
57 connect(pbUpdate, SIGNAL(clicked()), this,
58 SLOT(consoleUpdateSlots()));
60 connect(pbLabel, SIGNAL(clicked()), this,
61 SLOT(consoleLabelStorage()));
63 connect(pbMount, SIGNAL(clicked()), this,
64 SLOT(consoleMountStorage()));
66 connect(pbUnmount, SIGNAL(clicked()), this,
67 SLOT(consoleUnMountStorage()));
69 connect(pbStatus, SIGNAL(clicked()), this,
70 SLOT(statusStorageWindow()));
72 connect(pbRelease, SIGNAL(clicked()), this,
73 SLOT(consoleRelease()));
75 connect(tableContent, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this,
76 SLOT(showMediaInfo(QTableWidgetItem *)));
84 * Subroutine to call class to show the log in the database from that job
86 void Content::showMediaInfo(QTableWidgetItem * item)
88 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
89 int row = item->row();
90 QString vol = tableContent->item(row, 1)->text();
92 new MediaInfo(pageSelectorTreeWidgetItem, vol);
96 void table_get_selection(QTableWidget *table, QString &sel)
98 QTableWidgetItem *item;
101 /* The QT selection returns each cell, so you
102 * have x times the same row number...
103 * We take only one instance
105 int s = table->rowCount();
106 bool *tab = (bool *)malloc(s * sizeof(bool));
109 foreach (item, table->selectedItems()) {
110 current = item->row();
116 for(int i=0; i<s; i++) {
118 sel += table->item(i, 0)->text();
122 sel.chop(1); // remove trailing , or useless =
126 /* Label Media populating current storage by default */
127 void Content::consoleLabelStorage()
130 table_get_selection(tableContent, sel);
132 new labelPage(m_currentStorage);
134 QString cmd = "label barcodes slots";
136 cmd += " storage=" + m_currentStorage;
141 /* Mount currently selected storage */
142 void Content::consoleMountStorage()
145 /* if this storage is an autochanger, lets ask for the slot */
146 new mountDialog(m_console, m_currentStorage);
149 /* Unmount Currently selected storage */
150 void Content::consoleUnMountStorage()
152 QString cmd("umount storage=");
153 cmd += m_currentStorage;
157 void Content::statusStorageWindow()
159 /* if one exists, then just set it current */
161 foreach(Pages *page, mainWin->m_pagehash) {
162 if (mainWin->currentConsole() == page->console()) {
163 if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
170 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
171 new StorStat(m_currentStorage, parentItem);
176 * The main meat of the class!! The function that querries the director and
177 * creates the widgets with appropriate values.
179 void Content::populateContent()
185 QStringList results_all;
186 QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
187 m_console->dir_cmd(cmd, results_all);
189 Freeze frz(*tableContent); /* disable updating*/
190 Freeze frz2(*tableTray);
191 Freeze frz3(*tableDrive);
193 tableContent->clearContents();
194 tableTray->clearContents();
195 tableTray->clearContents();
197 // take only valid records, TODO: Add D to get drive status
198 QStringList results = results_all.filter(QRegExp("^[IS]\\|[0-9]+\\|"));
199 tableContent->setRowCount(results.size());
201 QStringList io_results = results_all.filter(QRegExp("^I\\|[0-9]+\\|"));
202 tableTray->setRowCount(io_results.size());
205 QStringList fieldlist;
206 int row = 0, row_io=0;
208 foreach (resultline, results) {
209 fieldlist = resultline.split("|");
210 if (fieldlist.size() < 10) {
211 Pmsg1(0, "Discarding %s\n", resultline.data());
212 continue; /* some fields missing, ignore row */
216 QStringListIterator fld(fieldlist);
217 TableItemFormatter slotitem(*tableContent, row);
220 if (fld.next() == "I") {
221 TableItemFormatter ioitem(*tableTray, row_io++);
222 ioitem.setNumericFld(0, fieldlist[1]);
223 ioitem.setTextFld(1, fieldlist[3]);
227 slotitem.setNumericFld(index++, fld.next());
230 if (fld.next() != "") {
233 slotitem.setTextFld(index++, fld.next());
236 slotitem.setBytesFld(index++, fld.next());
239 slotitem.setVolStatusFld(index++, fld.next());
242 slotitem.setTextFld(index++, fld.next());
245 slotitem.setTextFld(index++, fld.next());
247 tim = fld.next().toInt();
250 localtime_r(&tim, &tm);
251 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
252 slotitem.setTextFld(index++, QString(buf));
255 tim = fld.next().toInt();
256 localtime_r(&tim, &tm);
257 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
258 slotitem.setTextFld(index++, QString(buf));
264 tableContent->verticalHeader()->hide();
265 tableContent->sortByColumn(0, Qt::AscendingOrder);
266 tableContent->setSortingEnabled(true);
267 tableContent->resizeColumnsToContents();
268 tableContent->resizeRowsToContents();
270 tableContent->setEditTriggers(QAbstractItemView::NoEditTriggers);
273 tableTray->verticalHeader()->hide();
274 tableTray->setEditTriggers(QAbstractItemView::NoEditTriggers);
276 tableDrive->verticalHeader()->hide();
277 QStringList drives = results_all.filter(QRegExp("^D\\|[0-9]+\\|"));
278 tableDrive->setRowCount(drives.size());
281 foreach (resultline, drives) {
282 fieldlist = resultline.split("|");
283 if (fieldlist.size() < 4) {
284 Pmsg1(0, "Discarding %s\n", resultline.data());
285 continue; /* some fields missing, ignore row */
289 QStringListIterator fld(fieldlist);
290 TableItemFormatter slotitem(*tableDrive, row);
296 slotitem.setNumericFld(index++, fld.next());
302 slotitem.setTextFld(index++, fld.next());
307 tableDrive->resizeRowsToContents();
308 tableDrive->setEditTriggers(QAbstractItemView::NoEditTriggers);
312 * Virtual function which is called when this page is visible on the stack
314 void Content::currentStackItem()
321 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
327 void Content::consoleUpdateSlots()
330 table_get_selection(tableContent, sel);
332 QString cmd("update slots");
336 cmd += " drive=0 storage=" + m_currentStorage;
338 Pmsg1(0, "cmd=%s\n", cmd.toUtf8().data());
344 /* Release a tape in the drive */
345 void Content::consoleRelease()
347 QString cmd("release storage=");
348 cmd += m_currentStorage;