]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/fileset/fileset.cpp
Only use the svg files for the generation of the png files.
[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 and included
11    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$
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    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
49    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/system-file-manager.png")));
50
51    /* mp_treeWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
52    m_populated = false;
53    m_checkcurwidget = true;
54    m_closeable = false;
55    readSettings();
56    /* add context sensitive menu items specific to this classto the page
57     * selector tree. m_contextActions is QList of QActions */
58    m_contextActions.append(actionRefreshFileSet);
59    dockPage();
60 }
61
62 FileSet::~FileSet()
63 {
64    writeSettings();
65 }
66
67 /*
68  * The main meat of the class!!  The function that querries the director and 
69  * creates the widgets with appropriate values.
70  */
71 void FileSet::populateTree()
72 {
73    QTreeWidgetItem *filesetItem, *topItem;
74
75    if (!m_console->preventInUseConnect())
76        return;
77
78    m_checkcurwidget = false;
79    mp_treeWidget->clear();
80    m_checkcurwidget = true;
81
82    QStringList headerlist = (QStringList() << "  FileSet Name  " << "FileSet Id"
83        << "Create Time");
84
85    topItem = new QTreeWidgetItem(mp_treeWidget);
86    topItem->setText(0, "FileSet");
87    topItem->setData(0, Qt::UserRole, 0);
88    topItem->setExpanded(true);
89
90    mp_treeWidget->setColumnCount(headerlist.count());
91    mp_treeWidget->setHeaderLabels(headerlist);
92
93    foreach(QString filesetName, m_console->fileset_list) {
94       filesetItem = new QTreeWidgetItem(topItem);
95       filesetItem->setText(0, filesetName);
96       filesetItem->setData(0, Qt::UserRole, 1);
97       filesetItem->setExpanded(true);
98
99       /* Set up query QString and header QStringList */
100       QString query("");
101       query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
102            " FROM FileSet"
103            " WHERE ";
104       query += " FileSet='" + filesetName + "'";
105       query += " ORDER BY FileSet";
106
107       QStringList results;
108       if (mainWin->m_sqlDebug) {
109          Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data());
110       }
111       if (m_console->sql_cmd(query, results)) {
112          int resultCount = results.count();
113          if (resultCount == 1){
114             QString resultline;
115             QString field;
116             QStringList fieldlist;
117             /* there will only be one of these */
118             foreach (resultline, results) {
119                fieldlist = resultline.split("\t");
120                int index = 0;
121                /* Iterate through fields in the record */
122                foreach (field, fieldlist) {
123                   field = field.trimmed();  /* strip leading & trailing spaces */
124                   filesetItem->setData(index, Qt::UserRole, 1);
125                   /* Put media fields under the pool tree item */
126                   filesetItem->setData(index, Qt::UserRole, 1);
127                   filesetItem->setText(index, field);
128                   index++;
129                }
130             }
131          }
132       }
133    }
134    /* Resize the columns */
135    for (int cnter=1; cnter<headerlist.size(); cnter++) {
136       mp_treeWidget->resizeColumnToContents(cnter);
137    }
138
139 }
140
141 /*
142  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
143  * The tree has been populated.
144  */
145 void FileSet::PgSeltreeWidgetClicked()
146 {
147    if (!m_populated) {
148       populateTree();
149       createContextMenu();
150       m_populated = true;
151    }
152 }
153
154 /*
155  * Added to set the context menu policy based on currently active treeWidgetItem
156  * signaled by currentItemChanged
157  */
158 void FileSet::treeItemChanged(QTreeWidgetItem *currentwidgetitem, 
159                               QTreeWidgetItem *previouswidgetitem )
160 {
161    /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
162    if (m_checkcurwidget) {
163       /* The Previous item */
164       if (previouswidgetitem) { /* avoid a segfault if first time */
165          int treedepth = previouswidgetitem->data(0, Qt::UserRole).toInt();
166          if (treedepth == 1) {
167             mp_treeWidget->removeAction(actionStatusFileSetInConsole);
168             mp_treeWidget->removeAction(actionShowJobs);
169          }
170       }
171
172       int treedepth = currentwidgetitem->data(0, Qt::UserRole).toInt();
173       if (treedepth == 1){
174          /* set a hold variable to the fileset name in case the context sensitive
175           * menu is used */
176          m_currentlyselected=currentwidgetitem->text(0);
177          mp_treeWidget->addAction(actionStatusFileSetInConsole);
178          mp_treeWidget->addAction(actionShowJobs);
179       }
180    }
181 }
182
183 /* 
184  * Setup a context menu 
185  * Made separate from populate so that it would not create context menu over and
186  * over as the tree is repopulated.
187  */
188 void FileSet::createContextMenu()
189 {
190    mp_treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
191    mp_treeWidget->addAction(actionRefreshFileSet);
192    connect(mp_treeWidget, SIGNAL(
193            currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
194            this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)));
195    /* connect to the action specific to this pages class */
196    connect(actionRefreshFileSet, SIGNAL(triggered()), this,
197                 SLOT(populateTree()));
198    connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
199                 SLOT(consoleStatusFileSet()));
200    connect(actionShowJobs, SIGNAL(triggered()), this,
201                 SLOT(showJobs()));
202 }
203
204 /*
205  * Function responding to actionListJobsofFileSet which calls mainwin function
206  * to create a window of a list of jobs of this fileset.
207  */
208 void FileSet::consoleStatusFileSet()
209 {
210    QString cmd("status fileset=");
211    cmd += m_currentlyselected;
212    consoleCommand(cmd);
213 }
214
215 /*
216  * Virtual function which is called when this page is visible on the stack
217  */
218 void FileSet::currentStackItem()
219 {
220    if(!m_populated) {
221       populateTree();
222       /* Create the context menu for the fileset tree */
223       createContextMenu();
224       m_populated=true;
225    }
226 }
227
228 /*
229  * Save user settings associated with this page
230  */
231 void FileSet::writeSettings()
232 {
233    QSettings settings(m_console->m_dir->name(), "bat");
234    settings.beginGroup("FileSet");
235    settings.setValue("geometry", saveGeometry());
236    settings.endGroup();
237 }
238
239 /*
240  * Read and restore user settings associated with this page
241  */
242 void FileSet::readSettings()
243
244    QSettings settings(m_console->m_dir->name(), "bat");
245    settings.beginGroup("FileSet");
246    restoreGeometry(settings.value("geometry").toByteArray());
247    settings.endGroup();
248 }
249
250 /*
251  * Create a JobList object pre-populating a fileset
252  */
253 void FileSet::showJobs()
254 {
255    QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
256    mainWin->createPageJobList("", "", "", m_currentlyselected, parentItem);
257 }