]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/fileset/fileset.cpp
This commit puts prefences for debuggin output and prefences for the joblist
[bacula/bacula] / bacula / src / qt-console / fileset / fileset.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
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.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28  
29 /*
30  *   Version $Id: fileset.cpp 4230 2007-02-21 20:07:37Z kerns $
31  *
32  *  FileSet Class
33  *
34  *   Dirk Bartley, March 2007
35  *
36  */ 
37
38 #include <QAbstractEventDispatcher>
39 #include <QMenu>
40 #include "bat.h"
41 #include "fileset/fileset.h"
42
43 FileSet::FileSet()
44 {
45    setupUi(this);
46    m_name = "FileSets";
47    pgInitialize();
48
49    /* mp_treeWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
50    m_populated = false;
51    m_checkcurwidget = true;
52    m_closeable = false;
53 }
54
55 FileSet::~FileSet()
56 {
57 }
58
59 /*
60  * The main meat of the class!!  The function that querries the director and 
61  * creates the widgets with appropriate values.
62  */
63 void FileSet::populateTree()
64 {
65    QTreeWidgetItem *filesetItem, *topItem;
66
67    if (!m_console->preventInUseConnect())
68        return;
69
70    m_checkcurwidget = false;
71    mp_treeWidget->clear();
72    m_checkcurwidget = true;
73
74    QStringList headerlist = (QStringList() << "FileSet Name" << "FileSet Id"
75        << "Create Time");
76
77    topItem = new QTreeWidgetItem(mp_treeWidget);
78    topItem->setText(0, "FileSet");
79    topItem->setData(0, Qt::UserRole, 0);
80    topItem->setExpanded(true);
81
82    mp_treeWidget->setColumnCount(headerlist.count());
83    mp_treeWidget->setHeaderLabels(headerlist);
84
85    foreach(QString filesetName, m_console->fileset_list) {
86       filesetItem = new QTreeWidgetItem(topItem);
87       filesetItem->setText(0, filesetName);
88       filesetItem->setData(0, Qt::UserRole, 1);
89       filesetItem->setExpanded(true);
90
91       /* Set up query QString and header QStringList */
92       QString query("");
93       query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
94            " FROM FileSet"
95            " WHERE ";
96       query += " FileSet='" + filesetName + "'";
97       query += " ORDER BY FileSet";
98
99       QStringList results;
100       if (mainWin->m_sqlDebug) {
101          Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data());
102       }
103       if (m_console->sql_cmd(query, results)) {
104          int resultCount = results.count();
105          if (resultCount == 1){
106             QString resultline;
107             QString field;
108             QStringList fieldlist;
109             /* there will only be one of these */
110             foreach (resultline, results) {
111                fieldlist = resultline.split("\t");
112                int index = 0;
113                /* Iterate through fields in the record */
114                foreach (field, fieldlist) {
115                   field = field.trimmed();  /* strip leading & trailing spaces */
116                   filesetItem->setData(index, Qt::UserRole, 1);
117                   /* Put media fields under the pool tree item */
118                   filesetItem->setData(index, Qt::UserRole, 1);
119                   filesetItem->setText(index, field);
120                   index++;
121                }
122             }
123          }
124       }
125    }
126    /* Resize the columns */
127    for(int cnter=1; cnter<headerlist.size(); cnter++) {
128       mp_treeWidget->resizeColumnToContents(cnter);
129    }
130
131 }
132
133 /*
134  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
135  * The tree has been populated.
136  */
137 void FileSet::PgSeltreeWidgetClicked()
138 {
139    if (!m_populated) {
140       populateTree();
141       createContextMenu();
142       m_populated = true;
143    }
144 }
145
146 /*
147  * Added to set the context menu policy based on currently active treeWidgetItem
148  * signaled by currentItemChanged
149  */
150 void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem, 
151                               QTreeWidgetItem *previouswidgetitem )
152 {
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();
158          if (treedepth == 1) {
159             mp_treeWidget->removeAction(actionStatusFileSetInConsole);
160          }
161       }
162
163       int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
164       if (treedepth == 1){
165          /* set a hold variable to the fileset name in case the context sensitive
166           * menu is used */
167          m_currentlyselected=currentwidgetitem->text(0);
168          mp_treeWidget->addAction(actionStatusFileSetInConsole);
169       }
170    }
171 }
172
173 /* 
174  * Setup a context menu 
175  * Made separate from populate so that it would not create context menu over and
176  * over as the tree is repopulated.
177  */
178 void FileSet::createContextMenu()
179 {
180    mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
181    mp_treeWidget->addAction(actionRefreshFileSet);
182    connect(mp_treeWidget, SIGNAL(
183            currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
184            this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
185    /* connect to the action specific to this pages class */
186    connect(actionRefreshFileSet, SIGNAL(triggered()), this,
187                 SLOT(populateTree()));
188    connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
189                 SLOT(consoleStatusFileSet()));
190 }
191
192 /*
193  * Function responding to actionListJobsofFileSet which calls mainwin function
194  * to create a window of a list of jobs of this fileset.
195  */
196 void FileSet::consoleStatusFileSet()
197 {
198    QString cmd("status fileset=");
199    cmd += m_currentlyselected;
200    consoleCommand(cmd);
201 }
202
203 /*
204  * Virtual function which is called when this page is visible on the stack
205  */
206 void FileSet::currentStackItem()
207 {
208    if(!m_populated) {
209       populateTree();
210       /* add context sensitive menu items specific to this classto the page
211        * selector tree. m_m_contextActions is QList of QActions, so this is 
212        * only done once with the first population. */
213       m_contextActions.append(actionRefreshFileSet);
214       /* Create the context menu for the fileset tree */
215       createContextMenu();
216       m_populated=true;
217    }
218 }