2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
24 * Dirk Bartley, March 2007
29 #include <QAbstractEventDispatcher>
31 #include "fileset/fileset.h"
32 #include "util/fmtwidgetitem.h"
34 FileSet::FileSet() : Pages()
37 m_name = tr("FileSets");
39 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
40 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/system-file-manager.png")));
42 /* tableWidget, FileSet Tree Tree Widget inherited from ui_fileset.h */
44 m_checkcurwidget = true;
47 /* add context sensitive menu items specific to this classto the page
48 * selector tree. m_contextActions is QList of QActions */
49 m_contextActions.append(actionRefreshFileSet);
58 * The main meat of the class!! The function that querries the director and
59 * creates the widgets with appropriate values.
61 void FileSet::populateTable()
64 Freeze frz(*tableWidget); /* disable updating*/
66 m_checkcurwidget = false;
68 m_checkcurwidget = true;
70 QStringList headerlist = (QStringList() << tr("FileSet Name") << tr("FileSet Id")
71 << tr("Create Time"));
73 tableWidget->setColumnCount(headerlist.count());
74 tableWidget->setHorizontalHeaderLabels(headerlist);
75 tableWidget->horizontalHeader()->setHighlightSections(false);
76 tableWidget->verticalHeader()->hide();
77 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
78 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
79 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
81 QString fileset_comsep("");
83 QStringList notFoundList = m_console->fileset_list;
84 foreach(QString filesetName, m_console->fileset_list) {
86 fileset_comsep += "'" + filesetName + "'";
90 fileset_comsep += ",'" + filesetName + "'";
94 tableWidget->setRowCount(m_console->fileset_list.count());
95 if (fileset_comsep != "") {
96 /* Set up query QString and header QStringList */
98 query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
100 " WHERE FileSetId IN (SELECT MAX(FileSetId) FROM FileSet WHERE";
101 query += " FileSet IN (" + fileset_comsep + ")";
102 query += " GROUP BY FileSet) ORDER BY FileSet";
105 if (mainWin->m_sqlDebug) {
106 Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data());
108 if (m_console->sql_cmd(query, results)) {
109 QStringList fieldlist;
111 /* Iterate through the record returned from the query */
112 foreach (QString resultline, results) {
113 fieldlist = resultline.split("\t");
114 if (fieldlist.size() != 3) {
115 Pmsg1(000, "Unexpected line %s", resultline.toUtf8().data());
119 /* remove this fileSet from notFoundList */
120 int indexOf = notFoundList.indexOf(fieldlist[0]);
121 if (indexOf != -1) { notFoundList.removeAt(indexOf); }
123 TableItemFormatter item(*tableWidget, row);
125 /* Iterate through fields in the record */
126 QStringListIterator fld(fieldlist);
130 item.setTextFld(col++, fld.next());
133 item.setNumericFld(col++, fld.next());
136 item.setTextFld(col++, fld.next());
142 foreach(QString filesetName, notFoundList) {
143 TableItemFormatter item(*tableWidget, row);
144 item.setTextFld(0, filesetName);
148 /* set default sorting */
149 tableWidget->sortByColumn(headerlist.indexOf(tr("FileSet Name")), Qt::AscendingOrder);
150 tableWidget->setSortingEnabled(true);
152 /* Resize rows and columns */
153 tableWidget->resizeColumnsToContents();
154 tableWidget->resizeRowsToContents();
157 int rcnt = tableWidget->rowCount();
158 int ccnt = tableWidget->columnCount();
159 for(int r=0; r < rcnt; r++) {
160 for(int c=0; c < ccnt; c++) {
161 QTableWidgetItem* item = tableWidget->item(r, c);
163 item->setFlags(Qt::ItemFlags(item->flags() & (~Qt::ItemIsEditable)));
171 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
172 * The tree has been populated.
174 void FileSet::PgSeltreeWidgetClicked()
180 if (!isOnceDocked()) {
186 * Added to set the context menu policy based on currently active treeWidgetItem
187 * signaled by currentItemChanged
189 void FileSet::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem)
191 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
192 if (m_checkcurwidget && currentwidgetitem) {
193 int currentRow = currentwidgetitem->row();
194 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
195 m_currentlyselected = currentrowzeroitem->text();
197 /* The Previous item */
198 if (previouswidgetitem) { /* avoid a segfault if first time */
199 tableWidget->removeAction(actionStatusFileSetInConsole);
200 tableWidget->removeAction(actionShowJobs);
203 if (m_currentlyselected.length() != 0) {
204 /* set a hold variable to the fileset name in case the context sensitive
206 tableWidget->addAction(actionStatusFileSetInConsole);
207 tableWidget->addAction(actionShowJobs);
213 * Setup a context menu
214 * Made separate from populate so that it would not create context menu over and
215 * over as the tree is repopulated.
217 void FileSet::createContextMenu()
219 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
220 tableWidget->addAction(actionRefreshFileSet);
221 connect(tableWidget, SIGNAL(
222 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
223 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
224 /* connect to the action specific to this pages class */
225 connect(actionRefreshFileSet, SIGNAL(triggered()), this,
226 SLOT(populateTable()));
227 connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
228 SLOT(consoleShowFileSet()));
229 connect(actionShowJobs, SIGNAL(triggered()), this,
234 * Function responding to actionListJobsofFileSet which calls mainwin function
235 * to create a window of a list of jobs of this fileset.
237 void FileSet::consoleShowFileSet()
239 QString cmd("show fileset=\"");
240 cmd += m_currentlyselected + "\"";
245 * Virtual function which is called when this page is visible on the stack
247 void FileSet::currentStackItem()
251 /* Create the context menu for the fileset table */
257 * Save user settings associated with this page
259 void FileSet::writeSettings()
261 QSettings settings(m_console->m_dir->name(), "bat");
262 settings.beginGroup("FileSet");
263 settings.setValue("geometry", saveGeometry());
268 * Read and restore user settings associated with this page
270 void FileSet::readSettings()
272 QSettings settings(m_console->m_dir->name(), "bat");
273 settings.beginGroup("FileSet");
274 restoreGeometry(settings.value("geometry").toByteArray());
279 * Create a JobList object pre-populating a fileset
281 void FileSet::showJobs()
283 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
284 mainWin->createPageJobList("", "", "", m_currentlyselected, parentItem);