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)
47 pgInitialize(tr("Storage Content"));
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 /* Label Media populating current storage by default */
80 void Content::consoleLabelStorage()
82 new labelPage(m_currentStorage);
85 /* Mount currently selected storage */
86 void Content::consoleMountStorage()
89 /* if this storage is an autochanger, lets ask for the slot */
90 new mountDialog(m_console, m_currentStorage);
93 /* Unmount Currently selected storage */
94 void Content::consoleUnMountStorage()
96 QString cmd("umount storage=");
97 cmd += m_currentStorage;
101 void Content::statusStorageWindow()
103 /* if one exists, then just set it current */
105 foreach(Pages *page, mainWin->m_pagehash) {
106 if (mainWin->currentConsole() == page->console()) {
107 if (page->name() == tr("Storage Status %1").arg(m_currentStorage)) {
114 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
115 new StorStat(m_currentStorage, parentItem);
120 * The main meat of the class!! The function that querries the director and
121 * creates the widgets with appropriate values.
123 void Content::populateContent()
129 QStringList results_all;
130 QString cmd("status slots drive=0 storage=\"" + m_currentStorage + "\"");
131 m_console->dir_cmd(cmd, results_all);
133 Freeze frz(*tableContent); /* disable updating*/
134 tableContent->clearContents();
136 // take only valid records
137 QStringList results = results_all.filter(QRegExp("^[0-9]+\\|"));
138 tableContent->setRowCount(results.size());
141 QStringList fieldlist;
144 foreach (resultline, results) {
145 fieldlist = resultline.split("|");
146 if (fieldlist.size() < 9)
147 continue; /* some fields missing, ignore row */
150 QStringListIterator fld(fieldlist);
151 TableItemFormatter slotitem(*tableContent, row);
154 slotitem.setNumericFld(index++, fld.next());
157 if (fld.next() != "") {
160 slotitem.setTextFld(index++, fld.next());
163 slotitem.setBytesFld(index++, fld.next());
166 slotitem.setVolStatusFld(index++, fld.next());
169 slotitem.setTextFld(index++, fld.next());
172 slotitem.setTextFld(index++, fld.next());
174 t = fld.next().toInt();
177 localtime_r(&t, &tm);
178 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
179 slotitem.setTextFld(index++, QString(buf));
182 t = fld.next().toInt();
183 localtime_r(&t, &tm);
184 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
185 slotitem.setTextFld(index++, QString(buf));
192 tableContent->verticalHeader()->hide();
193 tableContent->sortByColumn(0, Qt::AscendingOrder);
194 tableContent->setSortingEnabled(true);
195 tableContent->resizeColumnsToContents();
196 tableContent->resizeRowsToContents();
199 int rcnt = tableContent->rowCount();
200 int ccnt = tableContent->columnCount();
201 for(int r=0; r < rcnt; r++) {
202 for(int c=0; c < ccnt; c++) {
203 QTableWidgetItem* item = tableContent->item(r, c);
205 item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
211 tableTray->verticalHeader()->hide();
212 tableDrive->verticalHeader()->hide();
216 * Virtual function which is called when this page is visible on the stack
218 void Content::currentStackItem()
225 void Content::treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
231 void Content::consoleUpdateSlots()
233 // TODO: get selected slots
234 QString cmd("update slots storage=");
235 cmd += m_currentStorage;
239 /* Release a tape in the drive */
240 void Content::consoleRelease()
242 QString cmd("release storage=");
243 cmd += m_currentStorage;