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: fileset.cpp 4230 2007-02-21 20:07:37Z kerns $
34 * Dirk Bartley, March 2007
38 #include <QAbstractEventDispatcher>
41 #include "fileset/fileset.h"
49 /* mp_treeWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
51 m_checkcurwidget = true;
60 * The main meat of the class!! The function that querries the director and
61 * creates the widgets with appropriate values.
63 void FileSet::populateTree()
65 QTreeWidgetItem *filesetItem, *topItem;
67 if (!m_console->preventInUseConnect())
70 m_checkcurwidget = false;
71 mp_treeWidget->clear();
72 m_checkcurwidget = true;
74 QStringList headerlist = (QStringList() << "FileSet Name" << "FileSet Id"
77 topItem = new QTreeWidgetItem(mp_treeWidget);
78 topItem->setText(0, "FileSet");
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 FileSet::populateTree()\n");
87 foreach(QString filesetName, m_console->fileset_list) {
88 filesetItem = new QTreeWidgetItem(topItem);
89 filesetItem->setText(0, filesetName);
90 filesetItem->setData(0, Qt::UserRole, 1);
91 filesetItem->setExpanded(true);
93 /* Set up query QString and header QStringList */
95 query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
98 query += " FileSet='" + filesetName + "'";
99 query += " ORDER BY FileSet";
102 /* This could be a log item */
103 //printf("FileSet query cmd : %s\n",query.toUtf8().data());
104 if (m_console->sql_cmd(query, results)) {
105 int resultCount = results.count();
106 if (resultCount == 1){
109 QStringList fieldlist;
110 /* there will only be one of these */
111 foreach (resultline, results) {
112 fieldlist = resultline.split("\t");
114 /* Iterate through fields in the record */
115 foreach (field, fieldlist) {
116 field = field.trimmed(); /* strip leading & trailing spaces */
117 filesetItem->setData(index, Qt::UserRole, 1);
118 /* Put media fields under the pool tree item */
119 filesetItem->setData(index, Qt::UserRole, 1);
120 filesetItem->setText(index, field);
127 /* Resize the columns */
128 for(int cnter=1; cnter<headerlist.size(); cnter++) {
129 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 FileSet::PgSeltreeWidgetClicked()
148 * Added to set the context menu policy based on currently active treeWidgetItem
149 * signaled by currentItemChanged
151 void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem,
152 QTreeWidgetItem *previouswidgetitem )
154 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
155 if (m_checkcurwidget) {
156 /* The Previous item */
157 if (previouswidgetitem) { /* avoid a segfault if first time */
158 int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
159 if (treedepth == 1) {
160 mp_treeWidget->removeAction(actionStatusFileSetInConsole);
164 int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
166 /* set a hold variable to the fileset name in case the context sensitive
168 m_currentlyselected=currentwidgetitem->text(0);
169 mp_treeWidget->addAction(actionStatusFileSetInConsole);
175 * Setup a context menu
176 * Made separate from populate so that it would not create context menu over and
177 * over as the tree is repopulated.
179 void FileSet::createContextMenu()
181 mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
182 mp_treeWidget->addAction(actionRefreshFileSet);
183 connect(mp_treeWidget, SIGNAL(
184 currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
185 this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
186 /* connect to the action specific to this pages class */
187 connect(actionRefreshFileSet, SIGNAL(triggered()), this,
188 SLOT(populateTree()));
189 connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
190 SLOT(consoleStatusFileSet()));
194 * Function responding to actionListJobsofFileSet which calls mainwin function
195 * to create a window of a list of jobs of this fileset.
197 void FileSet::consoleStatusFileSet()
199 QString cmd("status fileset=");
200 cmd += m_currentlyselected;
205 * Virtual function which is called when this page is visible on the stack
207 void FileSet::currentStackItem()
211 /* add context sensitive menu items specific to this classto the page
212 * selector tree. m_m_contextActions is QList of QActions, so this is
213 * only done once with the first population. */
214 m_contextActions.append(actionRefreshFileSet);
215 /* Create the context menu for the fileset tree */