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>
41 #include "storage/storage.h"
48 /* mp_treeWidget, Storage Tree Tree Widget inherited from ui_storage.h */
50 m_checkcurwidget = true;
59 * The main meat of the class!! The function that querries the director and
60 * creates the widgets with appropriate values.
62 void Storage::populateTree()
64 QTreeWidgetItem *storageItem, *topItem;
66 m_checkcurwidget = false;
67 mp_treeWidget->clear();
68 m_checkcurwidget = true;
70 QStringList headerlist = (QStringList() << "Storage Name" << "Storage Id"
73 topItem = new QTreeWidgetItem(mp_treeWidget);
74 topItem->setText(0, "Storage");
75 topItem->setData(0, Qt::UserRole, 0);
76 topItem->setExpanded(true);
78 mp_treeWidget->setColumnCount(headerlist.count());
79 mp_treeWidget->setHeaderLabels(headerlist);
80 /* This could be a log item */
81 //printf("In Storage::populateTree()\n");
83 foreach(QString storageName, m_console->storage_list){
84 storageItem = new QTreeWidgetItem(topItem);
85 storageItem->setText(0, storageName);
86 storageItem->setData(0, Qt::UserRole, 1);
87 storageItem->setExpanded(true);
89 /* Set up query QString and header QStringList */
91 query += "SELECT Name AS StorageName, StorageId AS ID, AutoChanger"
94 query += " Name='" + storageName + "'";
95 query += " ORDER BY Name";
98 /* This could be a log item */
99 //printf("Storage query cmd : %s\n",query.toUtf8().data());
100 if (m_console->sql_cmd(query, results)) {
101 int resultCount = results.count();
102 if (resultCount == 1){
105 QStringList fieldlist;
106 /* there will only be one of these */
107 foreach (resultline, results) {
108 fieldlist = resultline.split("\t");
110 /* Iterate through fields in the record */
111 foreach (field, fieldlist) {
112 field = field.trimmed(); /* strip leading & trailing spaces */
113 storageItem->setData(index+1, Qt::UserRole, 1);
114 /* Put media fields under the pool tree item */
115 storageItem->setData(index+1, Qt::UserRole, 1);
116 storageItem->setText(index+1, field);
126 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
127 * The tree has been populated.
129 void Storage::PgSeltreeWidgetClicked()
139 * Added to set the context menu policy based on currently active treeWidgetItem
140 * signaled by currentItemChanged
142 void Storage::treeItemChanged(QTreeWidgetItem *currentwidgetitem, QTreeWidgetItem *previouswidgetitem )
144 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
145 if (m_checkcurwidget) {
146 /* The Previous item */
147 if (previouswidgetitem) { /* avoid a segfault if first time */
148 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
150 mp_treeWidget->removeAction(actionStatusStorageInConsole);
154 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
156 /* set a hold variable to the storage name in case the context sensitive
158 m_currentlyselected=currentwidgetitem->text(0);
159 mp_treeWidget->addAction(actionStatusStorageInConsole);
165 * Setup a context menu
166 * Made separate from populate so that it would not create context menu over and
167 * over as the tree is repopulated.
169 void Storage::createContextMenu()
171 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
172 mp_treeWidget->addAction(actionRefreshStorage);
173 connect(mp_treeWidget, SIGNAL(
174 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
175 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
176 /* connect to the action specific to this pages class */
177 connect(actionRefreshStorage, SIGNAL(triggered()), this,
178 SLOT(populateTree()));
179 connect(actionStatusStorageInConsole, SIGNAL(triggered()), this,
180 SLOT(consoleStatusStorage()));
184 * Function responding to actionListJobsofStorage which calls mainwin function
185 * to create a window of a list of jobs of this storage.
187 void Storage::consoleStatusStorage()
189 QString cmd("status storage=");
190 cmd += m_currentlyselected += "\n";
192 // m_console->write_dir(cmd.toUtf8().data());
193 // m_console->displayToPrompt();
194 /* Bring this directors console to the front of the stack */
195 // mainWin->treeWidget->setCurrentItem(mainWin->getFromHash(m_console));
199 * Virtual function which is called when this page is visible on the stack
201 void Storage::currentStackItem()
205 /* add context sensitive menu items specific to this classto the page
206 * selector tree. m_m_contextActions is QList of QActions, so this is
207 * only done once with the first population. */
208 m_contextActions.append(actionRefreshStorage);
209 /* Create the context menu for the storage tree */
216 * Virtual Function to return the name for the medialist tree widget
218 void Storage::treeWidgetName(QString &name)