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 = "";
63 * The main meat of the class!! The function that querries the director and
64 * creates the widgets with appropriate values.
66 void Storage::populateTree()
68 QTreeWidgetItem *storageItem, *topItem;
70 if (!m_console->preventInUseConnect())
73 m_checkcurwidget = false;
74 mp_treeWidget->clear();
75 m_checkcurwidget = true;
77 QStringList headerlist = (QStringList() << "Storage Name" << "Storage Id"
80 topItem = new QTreeWidgetItem(mp_treeWidget);
81 topItem->setText(0, "Storage");
82 topItem->setData(0, Qt::UserRole, 0);
83 topItem->setExpanded(true);
85 mp_treeWidget->setColumnCount(headerlist.count());
86 mp_treeWidget->setHeaderLabels(headerlist);
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 if (mainWin->m_sqlDebug) {
103 Pmsg1(000, "Storage query cmd : %s\n",query.toUtf8().data());
105 if (m_console->sql_cmd(query, results)) {
106 int resultCount = results.count();
107 if (resultCount == 1){
110 QStringList fieldlist;
111 /* there will only be one of these */
112 foreach (resultline, results) {
113 fieldlist = resultline.split("\t");
115 /* Iterate through fields in the record */
116 foreach (field, fieldlist) {
117 field = field.trimmed(); /* strip leading & trailing spaces */
118 storageItem->setData(index+1, Qt::UserRole, 1);
119 /* Put media fields under the pool tree item */
120 storageItem->setData(index+1, Qt::UserRole, 1);
121 storageItem->setText(index+1, field);
128 /* Resize the columns */
129 for(int cnter=1; cnter<headerlist.size(); cnter++) {
130 mp_treeWidget->resizeColumnToContents(cnter);
135 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
136 * The tree has been populated.
138 void Storage::PgSeltreeWidgetClicked()
148 * Added to set the context menu policy based on currently active treeWidgetItem
149 * signaled by currentItemChanged
151 void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
153 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
154 if (m_checkcurwidget) {
155 /* The Previous item */
156 if (previouswidgetitem) { /* avoid a segfault if first time */
157 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
159 mp_treeWidget->removeAction(actionStatusStorageInConsole);
160 mp_treeWidget->removeAction(actionLabelStorage);
161 mp_treeWidget->removeAction(actionMountStorage);
162 mp_treeWidget->removeAction(actionUnMountStorage);
166 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
168 /* set a hold variable to the storage name in case the context sensitive
170 m_currentStorage = currentwidgetitem->text(0);
171 m_currentAutoChanger = currentwidgetitem->text(2).toInt();
172 mp_treeWidget->addAction(actionStatusStorageInConsole);
173 mp_treeWidget->addAction(actionLabelStorage);
174 mp_treeWidget->addAction(actionMountStorage);
175 mp_treeWidget->addAction(actionUnMountStorage);
177 text = "Status Storage " + m_currentStorage;
178 actionStatusStorageInConsole->setText(text);
179 text = "Label media in Storage " + m_currentStorage;
180 actionLabelStorage->setText(text);
181 text = "Mount media in Storage " + m_currentStorage;
182 actionMountStorage->setText(text);
183 text = "\"UN\" Mount media in Storage " + m_currentStorage;
184 actionUnMountStorage->setText(text);
190 * Setup a context menu
191 * Made separate from populate so that it would not create context menu over and
192 * over as the tree is repopulated.
194 void Storage::createContextMenu()
196 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
197 mp_treeWidget->addAction(actionRefreshStorage);
198 connect(mp_treeWidget, SIGNAL(
199 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
200 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
201 /* connect to the action specific to this pages class */
202 connect(actionRefreshStorage, SIGNAL(triggered()), this,
203 SLOT(populateTree()));
204 connect(actionStatusStorageInConsole, SIGNAL(triggered()), this,
205 SLOT(consoleStatusStorage()));
206 connect(actionLabelStorage, SIGNAL(triggered()), this,
207 SLOT(consoleLabelStorage()));
208 connect(actionMountStorage, SIGNAL(triggered()), this,
209 SLOT(consoleMountStorage()));
210 connect(actionUnMountStorage, SIGNAL(triggered()), this,
211 SLOT(consoleUnMountStorage()));
215 * Virtual function which is called when this page is visible on the stack
217 void Storage::currentStackItem()
221 /* add context sensitive menu items specific to this classto the page
222 * selector tree. m_contextActions is QList of QActions, so this is
223 * only done once with the first population. */
224 m_contextActions.append(actionRefreshStorage);
225 /* Create the context menu for the storage tree */
232 * Functions to respond to local context sensitive menu sending console commands
233 * If I could figure out how to make these one function passing a string, Yaaaaaa
235 void Storage::consoleStatusStorage()
237 QString cmd("status storage=");
238 cmd += m_currentStorage;
242 /* Label Media populating current storage by default */
243 void Storage::consoleLabelStorage()
245 new labelPage(m_currentStorage);
248 /* Mount currently selected storage */
249 void Storage::consoleMountStorage()
251 if (m_currentAutoChanger == 0){
252 /* no autochanger, just execute the command in the console */
253 QString cmd("mount storage=");
254 cmd += m_currentStorage;
258 /* if this storage is an autochanger, lets ask for the slot */
259 new mountDialog(m_console, m_currentStorage);
263 /* Unmount Currently selected storage */
264 void Storage::consoleUnMountStorage()
266 QString cmd("umount storage=");
267 cmd += m_currentStorage;