2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 and included
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 Kern Sibbald.
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.
34 * Dirk Bartley, March 2007
39 #include <QAbstractEventDispatcher>
41 #include "fileset/fileset.h"
42 #include "util/fmtwidgetitem.h"
47 m_name = tr("FileSets");
49 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
50 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/system-file-manager.png")));
52 /* tableWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
54 m_checkcurwidget = true;
57 /* add context sensitive menu items specific to this classto the page
58 * selector tree. m_contextActions is QList of QActions */
59 m_contextActions.append(actionRefreshFileSet);
68 * The main meat of the class!! The function that querries the director and
69 * creates the widgets with appropriate values.
71 void FileSet::populateTable()
75 Freeze frz(*tableWidget); /* disable updating*/
77 m_checkcurwidget = false;
79 m_checkcurwidget = true;
81 QStringList headerlist = (QStringList() << tr("FileSet Name") << tr("FileSet Id")
82 << tr("Create Time"));
84 tableWidget->setColumnCount(headerlist.count());
85 tableWidget->setHorizontalHeaderLabels(headerlist);
86 tableWidget->horizontalHeader()->setHighlightSections(false);
87 tableWidget->verticalHeader()->hide();
88 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
89 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
90 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
92 QString fileset_comsep("");
94 QStringList notFoundList = m_console->fileset_list;
95 foreach(QString filesetName, m_console->fileset_list) {
97 fileset_comsep += "'" + filesetName + "'";
101 fileset_comsep += ",'" + filesetName + "'";
105 tableWidget->setRowCount(m_console->fileset_list.count());
106 if (fileset_comsep != "") {
107 /* Set up query QString and header QStringList */
109 query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
111 " WHERE FileSetId IN (SELECT MAX(FileSetId) FROM FileSet WHERE";
112 query += " FileSet IN (" + fileset_comsep + ")";
113 query += " GROUP BY FileSet) ORDER BY FileSet";
116 if (mainWin->m_sqlDebug) {
117 Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data());
119 if (m_console->sql_cmd(query, results)) {
120 QStringList fieldlist;
122 /* Iterate through the record returned from the query */
123 foreach (QString resultline, results) {
124 fieldlist = resultline.split("\t");
126 /* remove this fileSet from notFoundList */
127 int indexOf = notFoundList.indexOf(fieldlist[0]);
128 if (indexOf != -1) { notFoundList.removeAt(indexOf); }
130 TableItemFormatter item(*tableWidget, row);
132 /* Iterate through fields in the record */
133 QStringListIterator fld(fieldlist);
137 item.setTextFld(col++, fld.next());
140 item.setNumericFld(col++, fld.next());
143 item.setTextFld(col++, fld.next());
149 foreach(QString filesetName, notFoundList) {
150 TableItemFormatter item(*tableWidget, row);
151 item.setTextFld(0, filesetName);
155 /* set default sorting */
156 tableWidget->sortByColumn(headerlist.indexOf(tr("FileSet Name")), Qt::AscendingOrder);
157 tableWidget->setSortingEnabled(true);
159 /* Resize rows and columns */
160 tableWidget->resizeColumnsToContents();
161 tableWidget->resizeRowsToContents();
164 int rcnt = tableWidget->rowCount();
165 int ccnt = tableWidget->columnCount();
166 for(int r=0; r < rcnt; r++) {
167 for(int c=0; c < ccnt; c++) {
168 QTableWidgetItem* item = tableWidget->item(r, c);
170 item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
177 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
178 * The tree has been populated.
180 void FileSet::PgSeltreeWidgetClicked()
190 * Added to set the context menu policy based on currently active treeWidgetItem
191 * signaled by currentItemChanged
193 void FileSet::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem)
195 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
196 if (m_checkcurwidget) {
197 int currentRow = currentwidgetitem->row();
198 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
199 m_currentlyselected = currentrowzeroitem->text();
201 /* The Previous item */
202 if (previouswidgetitem) { /* avoid a segfault if first time */
203 tableWidget->removeAction(actionStatusFileSetInConsole);
204 tableWidget->removeAction(actionShowJobs);
207 if (m_currentlyselected.length() != 0) {
208 /* set a hold variable to the fileset name in case the context sensitive
210 tableWidget->addAction(actionStatusFileSetInConsole);
211 tableWidget->addAction(actionShowJobs);
217 * Setup a context menu
218 * Made separate from populate so that it would not create context menu over and
219 * over as the tree is repopulated.
221 void FileSet::createContextMenu()
223 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
224 tableWidget->addAction(actionRefreshFileSet);
225 connect(tableWidget, SIGNAL(
226 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
227 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
228 /* connect to the action specific to this pages class */
229 connect(actionRefreshFileSet, SIGNAL(triggered()), this,
230 SLOT(populateTable()));
231 connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
232 SLOT(consoleShowFileSet()));
233 connect(actionShowJobs, SIGNAL(triggered()), this,
238 * Function responding to actionListJobsofFileSet which calls mainwin function
239 * to create a window of a list of jobs of this fileset.
241 void FileSet::consoleShowFileSet()
243 QString cmd("show fileset=\"");
244 cmd += m_currentlyselected + "\"";
249 * Virtual function which is called when this page is visible on the stack
251 void FileSet::currentStackItem()
255 /* Create the context menu for the fileset table */
261 * Save user settings associated with this page
263 void FileSet::writeSettings()
265 QSettings settings(m_console->m_dir->name(), "bat");
266 settings.beginGroup("FileSet");
267 settings.setValue("geometry", saveGeometry());
272 * Read and restore user settings associated with this page
274 void FileSet::readSettings()
276 QSettings settings(m_console->m_dir->name(), "bat");
277 settings.beginGroup("FileSet");
278 restoreGeometry(settings.value("geometry").toByteArray());
283 * Create a JobList object pre-populating a fileset
285 void FileSet::showJobs()
287 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
288 mainWin->createPageJobList("", "", "", m_currentlyselected, parentItem);