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 many
7 others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 Bacula® is a registered trademark of Kern Sibbald.
22 * Dirk Bartley, March 2007
27 #include <QAbstractEventDispatcher>
29 #include "fileset/fileset.h"
30 #include "util/fmtwidgetitem.h"
32 FileSet::FileSet() : Pages()
35 m_name = tr("FileSets");
37 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
38 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/system-file-manager.png")));
40 /* tableWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
42 m_checkcurwidget = true;
45 /* add context sensitive menu items specific to this classto the page
46 * selector tree. m_contextActions is QList of QActions */
47 m_contextActions.append(actionRefreshFileSet);
56 * The main meat of the class!! The function that querries the director and
57 * creates the widgets with appropriate values.
59 void FileSet::populateTable()
62 Freeze frz(*tableWidget); /* disable updating*/
64 m_checkcurwidget = false;
66 m_checkcurwidget = true;
68 QStringList headerlist = (QStringList() << tr("FileSet Name") << tr("FileSet Id")
69 << tr("Create Time"));
71 tableWidget->setColumnCount(headerlist.count());
72 tableWidget->setHorizontalHeaderLabels(headerlist);
73 tableWidget->horizontalHeader()->setHighlightSections(false);
74 tableWidget->verticalHeader()->hide();
75 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
76 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
77 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
79 QString fileset_comsep("");
81 QStringList notFoundList = m_console->fileset_list;
82 foreach(QString filesetName, m_console->fileset_list) {
84 fileset_comsep += "'" + filesetName + "'";
88 fileset_comsep += ",'" + filesetName + "'";
92 tableWidget->setRowCount(m_console->fileset_list.count());
93 if (fileset_comsep != "") {
94 /* Set up query QString and header QStringList */
96 query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
98 " WHERE FileSetId IN (SELECT MAX(FileSetId) FROM FileSet WHERE";
99 query += " FileSet IN (" + fileset_comsep + ")";
100 query += " GROUP BY FileSet) ORDER BY FileSet";
103 if (mainWin->m_sqlDebug) {
104 Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data());
106 if (m_console->sql_cmd(query, results)) {
107 QStringList fieldlist;
109 /* Iterate through the record returned from the query */
110 foreach (QString resultline, results) {
111 fieldlist = resultline.split("\t");
113 /* remove this fileSet from notFoundList */
114 int indexOf = notFoundList.indexOf(fieldlist[0]);
115 if (indexOf != -1) { notFoundList.removeAt(indexOf); }
117 TableItemFormatter item(*tableWidget, row);
119 /* Iterate through fields in the record */
120 QStringListIterator fld(fieldlist);
124 item.setTextFld(col++, fld.next());
127 item.setNumericFld(col++, fld.next());
130 item.setTextFld(col++, fld.next());
136 foreach(QString filesetName, notFoundList) {
137 TableItemFormatter item(*tableWidget, row);
138 item.setTextFld(0, filesetName);
142 /* set default sorting */
143 tableWidget->sortByColumn(headerlist.indexOf(tr("FileSet Name")), Qt::AscendingOrder);
144 tableWidget->setSortingEnabled(true);
146 /* Resize rows and columns */
147 tableWidget->resizeColumnsToContents();
148 tableWidget->resizeRowsToContents();
151 int rcnt = tableWidget->rowCount();
152 int ccnt = tableWidget->columnCount();
153 for(int r=0; r < rcnt; r++) {
154 for(int c=0; c < ccnt; c++) {
155 QTableWidgetItem* item = tableWidget->item(r, c);
157 item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
165 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
166 * The tree has been populated.
168 void FileSet::PgSeltreeWidgetClicked()
174 if (!isOnceDocked()) {
180 * Added to set the context menu policy based on currently active treeWidgetItem
181 * signaled by currentItemChanged
183 void FileSet::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem)
185 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
186 if (m_checkcurwidget && currentwidgetitem) {
187 int currentRow = currentwidgetitem->row();
188 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
189 m_currentlyselected = currentrowzeroitem->text();
191 /* The Previous item */
192 if (previouswidgetitem) { /* avoid a segfault if first time */
193 tableWidget->removeAction(actionStatusFileSetInConsole);
194 tableWidget->removeAction(actionShowJobs);
197 if (m_currentlyselected.length() != 0) {
198 /* set a hold variable to the fileset name in case the context sensitive
200 tableWidget->addAction(actionStatusFileSetInConsole);
201 tableWidget->addAction(actionShowJobs);
207 * Setup a context menu
208 * Made separate from populate so that it would not create context menu over and
209 * over as the tree is repopulated.
211 void FileSet::createContextMenu()
213 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
214 tableWidget->addAction(actionRefreshFileSet);
215 connect(tableWidget, SIGNAL(
216 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
217 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
218 /* connect to the action specific to this pages class */
219 connect(actionRefreshFileSet, SIGNAL(triggered()), this,
220 SLOT(populateTable()));
221 connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
222 SLOT(consoleShowFileSet()));
223 connect(actionShowJobs, SIGNAL(triggered()), this,
228 * Function responding to actionListJobsofFileSet which calls mainwin function
229 * to create a window of a list of jobs of this fileset.
231 void FileSet::consoleShowFileSet()
233 QString cmd("show fileset=\"");
234 cmd += m_currentlyselected + "\"";
239 * Virtual function which is called when this page is visible on the stack
241 void FileSet::currentStackItem()
245 /* Create the context menu for the fileset table */
251 * Save user settings associated with this page
253 void FileSet::writeSettings()
255 QSettings settings(m_console->m_dir->name(), "bat");
256 settings.beginGroup("FileSet");
257 settings.setValue("geometry", saveGeometry());
262 * Read and restore user settings associated with this page
264 void FileSet::readSettings()
266 QSettings settings(m_console->m_dir->name(), "bat");
267 settings.beginGroup("FileSet");
268 restoreGeometry(settings.value("geometry").toByteArray());
273 * Create a JobList object pre-populating a fileset
275 void FileSet::showJobs()
277 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
278 mainWin->createPageJobList("", "", "", m_currentlyselected, parentItem);