2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2007 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 plus additions
11 that are listed in the file LICENSE.
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.
30 * Version $Id: storage.cpp 4230 2007-02-21 20:07:37Z kerns $
34 * Dirk Bartley, March 2007
38 #include <QAbstractEventDispatcher>
42 #include "label/label.h"
43 #include "../mount/mount.h"
51 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_storage.h */
53 m_checkcurwidget = true;
55 m_currentStorage = "";
64 * The main meat of the class!! The function that querries the director and
65 * creates the widgets with appropriate values.
67 void Storage::populateTree()
69 QTreeWidgetItem *storageItem, *topItem;
71 m_checkcurwidget = false;
72 mp_treeWidget->clear();
73 m_checkcurwidget = true;
75 QStringList headerlist = (QStringList() << "Storage Name" << "Storage Id"
78 topItem = new QTreeWidgetItem(mp_treeWidget);
79 topItem->setText(0, "Storage");
80 topItem->setData(0, Qt::UserRole, 0);
81 topItem->setExpanded(true);
83 mp_treeWidget->setColumnCount(headerlist.count());
84 mp_treeWidget->setHeaderLabels(headerlist);
85 /* This could be a log item */
86 //printf("In Storage::populateTree()\n");
88 foreach(QString storageName, m_console->storage_list){
89 storageItem = new QTreeWidgetItem(topItem);
90 storageItem->setText(0, storageName);
91 storageItem->setData(0, Qt::UserRole, 1);
92 storageItem->setExpanded(true);
94 /* Set up query QString and header QStringList */
95 QString query("SELECT StorageId AS ID, AutoChanger AS Changer"
96 " FROM Storage WHERE");
97 query += " Name='" + storageName + "'"
101 /* This could be a log item */
102 //printf("Storage query cmd : %s\n",query.toUtf8().data());
103 if (m_console->sql_cmd(query, results)) {
104 int resultCount = results.count();
105 if (resultCount == 1){
108 QStringList fieldlist;
109 /* there will only be one of these */
110 foreach (resultline, results) {
111 fieldlist = resultline.split("\t");
113 /* Iterate through fields in the record */
114 foreach (field, fieldlist) {
115 field = field.trimmed(); /* strip leading & trailing spaces */
116 storageItem->setData(index+1, Qt::UserRole, 1);
117 /* Put media fields under the pool tree item */
118 storageItem->setData(index+1, Qt::UserRole, 1);
119 storageItem->setText(index+1, field);
126 /* Resize the columns */
127 for(int cnter=1; cnter<headerlist.size(); cnter++) {
128 mp_treeWidget->resizeColumnToContents(cnter);
133 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
134 * The tree has been populated.
136 void Storage::PgSeltreeWidgetClicked()
146 * Added to set the context menu policy based on currently active treeWidgetItem
147 * signaled by currentItemChanged
149 void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
151 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
152 if (m_checkcurwidget) {
153 /* The Previous item */
154 if (previouswidgetitem) { /* avoid a segfault if first time */
155 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
157 mp_treeWidget->removeAction(actionStatusStorageInConsole);
158 mp_treeWidget->removeAction(actionLabelStorage);
159 mp_treeWidget->removeAction(actionMountStorage);
160 mp_treeWidget->removeAction(actionUnMountStorage);
164 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
166 /* set a hold variable to the storage name in case the context sensitive
168 m_currentStorage = currentwidgetitem->text(0);
169 m_currentAutoChanger = currentwidgetitem->text(2).toInt();
170 mp_treeWidget->addAction(actionStatusStorageInConsole);
171 mp_treeWidget->addAction(actionLabelStorage);
172 mp_treeWidget->addAction(actionMountStorage);
173 mp_treeWidget->addAction(actionUnMountStorage);
175 text = "Status Storage " + m_currentStorage;
176 actionStatusStorageInConsole->setText(text);
177 text = "Label media in Storage " + m_currentStorage;
178 actionLabelStorage->setText(text);
179 text = "Mount media in Storage " + m_currentStorage;
180 actionMountStorage->setText(text);
181 text = "\"UN\" Mount media in Storage " + m_currentStorage;
182 actionUnMountStorage->setText(text);
188 * Setup a context menu
189 * Made separate from populate so that it would not create context menu over and
190 * over as the tree is repopulated.
192 void Storage::createContextMenu()
194 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
195 mp_treeWidget->addAction(actionRefreshStorage);
196 connect(mp_treeWidget, SIGNAL(
197 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
198 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
199 /* connect to the action specific to this pages class */
200 connect(actionRefreshStorage, SIGNAL(triggered()), this,
201 SLOT(populateTree()));
202 connect(actionStatusStorageInConsole, SIGNAL(triggered()), this,
203 SLOT(consoleStatusStorage()));
204 connect(actionLabelStorage, SIGNAL(triggered()), this,
205 SLOT(consoleLabelStorage()));
206 connect(actionMountStorage, SIGNAL(triggered()), this,
207 SLOT(consoleMountStorage()));
208 connect(actionUnMountStorage, SIGNAL(triggered()), this,
209 SLOT(consoleUnMountStorage()));
213 * Virtual function which is called when this page is visible on the stack
215 void Storage::currentStackItem()
219 /* add context sensitive menu items specific to this classto the page
220 * selector tree. m_m_contextActions is QList of QActions, so this is
221 * only done once with the first population. */
222 m_contextActions.append(actionRefreshStorage);
223 /* Create the context menu for the storage tree */
230 * Functions to respond to local context sensitive menu sending console commands
231 * If I could figure out how to make these one function passing a string, Yaaaaaa
233 void Storage::consoleStatusStorage()
235 QString cmd("status storage=");
236 cmd += m_currentStorage;
240 /* Label Media populating current storage by default */
241 void Storage::consoleLabelStorage()
243 new labelDialog(m_console, m_currentStorage);
246 /* Mount currently selected storage */
247 void Storage::consoleMountStorage()
249 if (m_currentAutoChanger == 0){
250 /* no autochanger, just execute the command in the console */
251 QString cmd("mount storage=");
252 cmd += m_currentStorage;
256 /* if this storage is an autochanger, lets ask for the slot */
257 new mountDialog(m_console, m_currentStorage);
261 /* Unmount Currently selected storage */
262 void Storage::consoleUnMountStorage()
264 QString cmd("umount storage=");
265 cmd += m_currentStorage;