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 two of the GNU 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 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 "mount/mount.h"
35 #include "util/fmtwidgetitem.h"
36 #include "status/storstat.h"
40 // List drives in autochanger
41 // use user selection to add slot= argument
44 Content::Content(QString storage, QTreeWidgetItem *parentWidget)
47 pgInitialize(storage, parentWidget);
48 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
52 m_firstpopulation = true;
53 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()));
79 void table_get_selection(QTableWidget *table, QString &sel)
81 QTableWidgetItem *item;
84 /* The QT selection returns each cell, so you
85 * have x times the same row number...
86 * We take only one instance
88 int s = table->rowCount();
89 bool *tab = (bool *)malloc(s * sizeof(bool));
92 foreach (item, table->selectedItems()) {
93 current = item->row();
99 for(int i=0; i<s; i++) {
101 sel += table->item(i, 0)->text();
105 sel.chop(1); // remove trailing , or useless =
109 /* Label Media populating current storage by default */
110 void Content::consoleLabelStorage()
113 table_get_selection(tableContent, sel);
115 new labelPage(m_currentStorage);
117 QString cmd = "label barcodes slots";
119 cmd += " storage=" + m_currentStorage;
124 /* Mount currently selected storage */
125 void Content::consoleMountStorage()
128 /* if this storage is an autochanger, lets ask for the slot */
129 new mountDialog(m_console, m_currentStorage);
132 /* Unmount Currently selected storage */
133 void Content::consoleUnMountStorage()
135 QString cmd("umount storage=");
136 cmd += m_currentStorage;
140 void Content::statusStorageWindow()
142 /* if one exists, then just set it current */
144 foreach(Pages *page, mainWin->m_pagehash) {
145 if (mainWin->currentConsole() == page->console()) {
146 if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
153 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
154 new StorStat(m_currentStorage, parentItem);
159 * The main meat of the class!! The function that querries the director and
160 * creates the widgets with appropriate values.
162 void Content::populateContent()
168 QStringList results_all;
169 QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
170 m_console->dir_cmd(cmd, results_all);
172 Freeze frz(*tableContent); /* disable updating*/
173 tableContent->clearContents();
175 // take only valid records
176 QStringList results = results_all.filter(QRegExp("^[0-9]+\\|"));
177 tableContent->setRowCount(results.size());
180 QStringList fieldlist;
183 foreach (resultline, results) {
184 fieldlist = resultline.split("|");
185 if (fieldlist.size() < 9)
186 continue; /* some fields missing, ignore row */
189 QStringListIterator fld(fieldlist);
190 TableItemFormatter slotitem(*tableContent, row);
193 slotitem.setNumericFld(index++, fld.next());
196 if (fld.next() != "") {
199 slotitem.setTextFld(index++, fld.next());
202 slotitem.setBytesFld(index++, fld.next());
205 slotitem.setVolStatusFld(index++, fld.next());
208 slotitem.setTextFld(index++, fld.next());
211 slotitem.setTextFld(index++, fld.next());
213 t = fld.next().toInt();
216 localtime_r(&t, &tm);
217 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
218 slotitem.setTextFld(index++, QString(buf));
221 t = fld.next().toInt();
222 localtime_r(&t, &tm);
223 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
224 slotitem.setTextFld(index++, QString(buf));
231 tableContent->verticalHeader()->hide();
232 tableContent->sortByColumn(0, Qt::AscendingOrder);
233 tableContent->setSortingEnabled(true);
234 tableContent->resizeColumnsToContents();
235 tableContent->resizeRowsToContents();
238 int rcnt = tableContent->rowCount();
239 int ccnt = tableContent->columnCount();
240 for(int r=0; r < rcnt; r++) {
241 for(int c=0; c < ccnt; c++) {
242 QTableWidgetItem* item = tableContent->item(r, c);
244 item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
250 tableTray->verticalHeader()->hide();
251 tableDrive->verticalHeader()->hide();
255 * Virtual function which is called when this page is visible on the stack
257 void Content::currentStackItem()
264 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
270 void Content::consoleUpdateSlots()
273 table_get_selection(tableContent, sel);
275 QString cmd("update slots");
279 cmd += " drive=0 storage=" + m_currentStorage;
281 Pmsg1(0, "cmd=%s\n", cmd.toUtf8().data());
287 /* Release a tape in the drive */
288 void Content::consoleRelease()
290 QString cmd("release storage=");
291 cmd += m_currentStorage;