2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 John Walker.
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.
34 * Dirk Bartley, March 2007
38 #include <QAbstractEventDispatcher>
42 #include "label/label.h"
43 #include "../mount/mount.h"
48 m_name = tr("Storage");
50 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
51 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/package-x-generic.png")));
53 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_storage.h */
55 m_checkcurwidget = true;
57 m_currentStorage = "";
58 /* add context sensitive menu items specific to this classto the page
59 * selector tree. m_contextActions is QList of QActions */
60 m_contextActions.append(actionRefreshStorage);
69 * The main meat of the class!! The function that querries the director and
70 * creates the widgets with appropriate values.
72 void Storage::populateTree()
74 QTreeWidgetItem *storageItem, *topItem;
76 if (!m_console->preventInUseConnect())
79 m_checkcurwidget = false;
80 mp_treeWidget->clear();
81 m_checkcurwidget = true;
83 QStringList headerlist = (QStringList() << tr("Storage Name") << tr("Storage Id")
84 << tr("Auto Changer"));
86 topItem = new QTreeWidgetItem(mp_treeWidget);
87 topItem->setText(0, tr("Storage"));
88 topItem->setData(0, Qt::UserRole, 0);
89 topItem->setExpanded(true);
91 mp_treeWidget->setColumnCount(headerlist.count());
92 mp_treeWidget->setHeaderLabels(headerlist);
94 foreach(QString storageName, m_console->storage_list){
95 storageItem = new QTreeWidgetItem(topItem);
96 storageItem->setText(0, storageName);
97 storageItem->setData(0, Qt::UserRole, 1);
98 storageItem->setExpanded(true);
100 /* Set up query QString and header QStringList */
101 QString query("SELECT StorageId AS ID, AutoChanger AS Changer"
102 " FROM Storage WHERE");
103 query += " Name='" + storageName + "'"
107 /* This could be a log item */
108 if (mainWin->m_sqlDebug) {
109 Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data());
111 if (m_console->sql_cmd(query, results)) {
112 int resultCount = results.count();
113 if (resultCount == 1){
116 QStringList fieldlist;
117 /* there will only be one of these */
118 foreach (resultline, results) {
119 fieldlist = resultline.split("\t");
121 /* Iterate through fields in the record */
122 foreach (field, fieldlist) {
123 field = field.trimmed(); /* strip leading & trailing spaces */
124 storageItem->setData(index+1, Qt::UserRole, 1);
125 /* Put media fields under the pool tree item */
126 storageItem->setData(index+1, Qt::UserRole, 1);
127 storageItem->setText(index+1, field);
134 /* Resize the columns */
135 for(int cnter=0; cnter<headerlist.size(); cnter++) {
136 mp_treeWidget->resizeColumnToContents(cnter);
141 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
142 * The tree has been populated.
144 void Storage::PgSeltreeWidgetClicked()
154 * Added to set the context menu policy based on currently active treeWidgetItem
155 * signaled by currentItemChanged
157 void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
159 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
160 if (m_checkcurwidget) {
161 /* The Previous item */
162 if (previouswidgetitem) { /* avoid a segfault if first time */
163 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
165 mp_treeWidget->removeAction(actionStatusStorageInConsole);
166 mp_treeWidget->removeAction(actionLabelStorage);
167 mp_treeWidget->removeAction(actionMountStorage);
168 mp_treeWidget->removeAction(actionUnMountStorage);
169 mp_treeWidget->removeAction(actionUpdateSlots);
170 mp_treeWidget->removeAction(actionUpdateSlotsScan);
171 mp_treeWidget->removeAction(actionRelease);
175 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
177 /* set a hold variable to the storage name in case the context sensitive
179 m_currentStorage = currentwidgetitem->text(0);
180 m_currentAutoChanger = currentwidgetitem->text(2).toInt();
181 mp_treeWidget->addAction(actionStatusStorageInConsole);
182 mp_treeWidget->addAction(actionLabelStorage);
183 mp_treeWidget->addAction(actionMountStorage);
184 mp_treeWidget->addAction(actionUnMountStorage);
185 mp_treeWidget->addAction(actionRelease);
187 text = "Status Storage \"" + m_currentStorage + "\"";
188 actionStatusStorageInConsole->setText(text);
189 text = "Label media in Storage \"" + m_currentStorage + "\"";
190 actionLabelStorage->setText(text);
191 text = "Mount media in Storage \"" + m_currentStorage + "\"";
192 actionMountStorage->setText(text);
193 text = "\"UN\" Mount media in Storage \"" + m_currentStorage + "\"";
194 actionUnMountStorage->setText(text);
195 text = "Release media in Storage \"" + m_currentStorage + "\"";
196 actionRelease->setText(text);
197 if (m_currentAutoChanger != 0) {
198 mp_treeWidget->addAction(actionUpdateSlots);
199 mp_treeWidget->addAction(actionUpdateSlotsScan);
200 text = "Barcode Scan media in Storage \"" + m_currentStorage + "\"";
201 actionUpdateSlots->setText(text);
202 text = "Mount and read scan media in Storage \"" + m_currentStorage + "\"";
203 actionUpdateSlotsScan->setText(text);
210 * Setup a context menu
211 * Made separate from populate so that it would not create context menu over and
212 * over as the tree is repopulated.
214 void Storage::createContextMenu()
216 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
217 mp_treeWidget->addAction(actionRefreshStorage);
218 connect(mp_treeWidget, SIGNAL(
219 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
220 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
221 /* connect to the action specific to this pages class */
222 connect(actionRefreshStorage, SIGNAL(triggered()), this,
223 SLOT(populateTree()));
224 connect(actionStatusStorageInConsole, SIGNAL(triggered()), this,
225 SLOT(consoleStatusStorage()));
226 connect(actionLabelStorage, SIGNAL(triggered()), this,
227 SLOT(consoleLabelStorage()));
228 connect(actionMountStorage, SIGNAL(triggered()), this,
229 SLOT(consoleMountStorage()));
230 connect(actionUnMountStorage, SIGNAL(triggered()), this,
231 SLOT(consoleUnMountStorage()));
232 connect(actionUpdateSlots, SIGNAL(triggered()), this,
233 SLOT(consoleUpdateSlots()));
234 connect(actionUpdateSlotsScan, SIGNAL(triggered()), this,
235 SLOT(consoleUpdateSlotsScan()));
236 connect(actionRelease, SIGNAL(triggered()), this,
237 SLOT(consoleRelease()));
241 * Virtual function which is called when this page is visible on the stack
243 void Storage::currentStackItem()
247 /* Create the context menu for the storage tree */
254 * Functions to respond to local context sensitive menu sending console commands
255 * If I could figure out how to make these one function passing a string, Yaaaaaa
257 void Storage::consoleStatusStorage()
259 QString cmd("status storage=");
260 cmd += m_currentStorage;
264 /* Label Media populating current storage by default */
265 void Storage::consoleLabelStorage()
267 new labelPage(m_currentStorage);
270 /* Mount currently selected storage */
271 void Storage::consoleMountStorage()
273 if (m_currentAutoChanger == 0){
274 /* no autochanger, just execute the command in the console */
275 QString cmd("mount storage=");
276 cmd += m_currentStorage;
280 /* if this storage is an autochanger, lets ask for the slot */
281 new mountDialog(m_console, m_currentStorage);
285 /* Unmount Currently selected storage */
286 void Storage::consoleUnMountStorage()
288 QString cmd("umount storage=");
289 cmd += m_currentStorage;
294 void Storage::consoleUpdateSlots()
296 QString cmd("update slots storage=");
297 cmd += m_currentStorage;
301 /* Update Slots Scan*/
302 void Storage::consoleUpdateSlotsScan()
304 QString cmd("update slots scan storage=");
305 cmd += m_currentStorage;
309 /* Release a tape in the drive */
310 void Storage::consoleRelease()
312 QString cmd("release storage=");
313 cmd += m_currentStorage;