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 m_checkcurwidget = false;
71 mp_treeWidget->clear();
72 m_checkcurwidget = true;
74 QStringList headerlist = (QStringList() << "Storage Name" << "Storage Id"
77 topItem = new QTreeWidgetItem(mp_treeWidget);
78 topItem->setText(0, "Storage");
79 topItem->setData(0, Qt::UserRole, 0);
80 topItem->setExpanded(true);
82 mp_treeWidget->setColumnCount(headerlist.count());
83 mp_treeWidget->setHeaderLabels(headerlist);
84 /* This could be a log item */
85 //printf("In Storage::populateTree()\n");
87 foreach(QString storageName, m_console->storage_list){
88 storageItem = new QTreeWidgetItem(topItem);
89 storageItem->setText(0, storageName);
90 storageItem->setData(0, Qt::UserRole, 1);
91 storageItem->setExpanded(true);
93 /* Set up query QString and header QStringList */
94 QString query("SELECT StorageId AS ID, AutoChanger AS Changer"
95 " FROM Storage WHERE");
96 query += " Name='" + storageName + "'"
100 /* This could be a log item */
101 //printf("Storage query cmd : %s\n",query.toUtf8().data());
102 if (m_console->sql_cmd(query, results)) {
103 int resultCount = results.count();
104 if (resultCount == 1){
107 QStringList fieldlist;
108 /* there will only be one of these */
109 foreach (resultline, results) {
110 fieldlist = resultline.split("\t");
112 /* Iterate through fields in the record */
113 foreach (field, fieldlist) {
114 field = field.trimmed(); /* strip leading & trailing spaces */
115 storageItem->setData(index+1, Qt::UserRole, 1);
116 /* Put media fields under the pool tree item */
117 storageItem->setData(index+1, Qt::UserRole, 1);
118 storageItem->setText(index+1, field);
125 /* Resize the columns */
126 for(int cnter=1; cnter<headerlist.size(); cnter++) {
127 mp_treeWidget->resizeColumnToContents(cnter);
132 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
133 * The tree has been populated.
135 void Storage::PgSeltreeWidgetClicked()
145 * Added to set the context menu policy based on currently active treeWidgetItem
146 * signaled by currentItemChanged
148 void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
150 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
151 if (m_checkcurwidget) {
152 /* The Previous item */
153 if (previouswidgetitem) { /* avoid a segfault if first time */
154 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
156 mp_treeWidget->removeAction(actionStatusStorageInConsole);
157 mp_treeWidget->removeAction(actionLabelStorage);
158 mp_treeWidget->removeAction(actionMountStorage);
159 mp_treeWidget->removeAction(actionUnMountStorage);
163 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
165 /* set a hold variable to the storage name in case the context sensitive
167 m_currentStorage = currentwidgetitem->text(0);
168 m_currentAutoChanger = currentwidgetitem->text(2).toInt();
169 mp_treeWidget->addAction(actionStatusStorageInConsole);
170 mp_treeWidget->addAction(actionLabelStorage);
171 mp_treeWidget->addAction(actionMountStorage);
172 mp_treeWidget->addAction(actionUnMountStorage);
174 text = "Status Storage " + m_currentStorage;
175 actionStatusStorageInConsole->setText(text);
176 text = "Label media in Storage " + m_currentStorage;
177 actionLabelStorage->setText(text);
178 text = "Mount media in Storage " + m_currentStorage;
179 actionMountStorage->setText(text);
180 text = "\"UN\" Mount media in Storage " + m_currentStorage;
181 actionUnMountStorage->setText(text);
187 * Setup a context menu
188 * Made separate from populate so that it would not create context menu over and
189 * over as the tree is repopulated.
191 void Storage::createContextMenu()
193 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
194 mp_treeWidget->addAction(actionRefreshStorage);
195 connect(mp_treeWidget, SIGNAL(
196 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
197 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
198 /* connect to the action specific to this pages class */
199 connect(actionRefreshStorage, SIGNAL(triggered()), this,
200 SLOT(populateTree()));
201 connect(actionStatusStorageInConsole, SIGNAL(triggered()), this,
202 SLOT(consoleStatusStorage()));
203 connect(actionLabelStorage, SIGNAL(triggered()), this,
204 SLOT(consoleLabelStorage()));
205 connect(actionMountStorage, SIGNAL(triggered()), this,
206 SLOT(consoleMountStorage()));
207 connect(actionUnMountStorage, SIGNAL(triggered()), this,
208 SLOT(consoleUnMountStorage()));
212 * Virtual function which is called when this page is visible on the stack
214 void Storage::currentStackItem()
218 /* add context sensitive menu items specific to this classto the page
219 * selector tree. m_m_contextActions is QList of QActions, so this is
220 * only done once with the first population. */
221 m_contextActions.append(actionRefreshStorage);
222 /* Create the context menu for the storage tree */
229 * Functions to respond to local context sensitive menu sending console commands
230 * If I could figure out how to make these one function passing a string, Yaaaaaa
232 void Storage::consoleStatusStorage()
234 QString cmd("status storage=");
235 cmd += m_currentStorage;
239 /* Label Media populating current storage by default */
240 void Storage::consoleLabelStorage()
242 new labelDialog(m_console, m_currentStorage);
245 /* Mount currently selected storage */
246 void Storage::consoleMountStorage()
248 if (m_currentAutoChanger == 0){
249 /* no autochanger, just execute the command in the console */
250 QString cmd("mount storage=");
251 cmd += m_currentStorage;
255 /* if this storage is an autochanger, lets ask for the slot */
256 new mountDialog(m_console, m_currentStorage);
260 /* Unmount Currently selected storage */
261 void Storage::consoleUnMountStorage()
263 QString cmd("umount storage=");
264 cmd += m_currentStorage;