2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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);
69 * The main meat of the class!! The function that querries the director and
70 * creates the widgets with appropriate values.
72 void FileSet::populateTable()
76 Freeze frz(*tableWidget); /* disable updating*/
78 m_checkcurwidget = false;
80 m_checkcurwidget = true;
82 QStringList headerlist = (QStringList() << tr("FileSet Name") << tr("FileSet Id")
83 << tr("Create Time"));
85 tableWidget->setColumnCount(headerlist.count());
86 tableWidget->setHorizontalHeaderLabels(headerlist);
87 tableWidget->horizontalHeader()->setHighlightSections(false);
88 tableWidget->setRowCount(m_console->fileset_list.count());
89 tableWidget->verticalHeader()->hide();
90 tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
91 tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
92 tableWidget->setSortingEnabled(false); /* rows move on insert if sorting enabled */
95 foreach(QString filesetName, m_console->fileset_list) {
97 /* Set up query QString and header QStringList */
99 query += "SELECT FileSet AS Name, FileSetId AS Id, CreateTime"
102 query += " FileSet='" + filesetName + "'";
103 query += " ORDER BY CreateTime DESC LIMIT 1";
106 if (mainWin->m_sqlDebug) {
107 Pmsg1(000, "FileSet query cmd : %s\n",query.toUtf8().data());
109 if (m_console->sql_cmd(query, results)) {
110 int resultCount = results.count();
112 /* only use the last one */
113 QString resultline = results[resultCount - 1];
114 QStringList fieldlist = resultline.split("\t");
116 TableItemFormatter item(*tableWidget, row);
118 /* Iterate through fields in the record */
119 QStringListIterator fld(fieldlist);
123 item.setTextFld(col++, fld.next());
126 item.setNumericFld(col++, fld.next());
129 item.setTextFld(col++, fld.next());
135 /* set default sorting */
136 tableWidget->sortByColumn(headerlist.indexOf(tr("Create Time")), Qt::DescendingOrder);
137 tableWidget->setSortingEnabled(true);
139 /* Resize rows and columns */
140 tableWidget->resizeColumnsToContents();
141 tableWidget->resizeRowsToContents();
145 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
146 * The tree has been populated.
148 void FileSet::PgSeltreeWidgetClicked()
157 * Added to set the context menu policy based on currently active treeWidgetItem
158 * signaled by currentItemChanged
160 void FileSet::tableItemChanged(QTableWidgetItem *currentwidgetitem, QTableWidgetItem *previouswidgetitem)
162 /* m_checkcurwidget checks to see if this is during a refresh, which will segfault */
163 if (m_checkcurwidget) {
164 int currentRow = currentwidgetitem->row();
165 QTableWidgetItem *currentrowzeroitem = tableWidget->item(currentRow, 0);
166 m_currentlyselected = currentrowzeroitem->text();
168 /* The Previous item */
169 if (previouswidgetitem) { /* avoid a segfault if first time */
170 tableWidget->removeAction(actionStatusFileSetInConsole);
171 tableWidget->removeAction(actionShowJobs);
174 if (m_currentlyselected.length() != 0) {
175 /* set a hold variable to the fileset name in case the context sensitive
177 tableWidget->addAction(actionStatusFileSetInConsole);
178 tableWidget->addAction(actionShowJobs);
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.
188 void FileSet::createContextMenu()
190 tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
191 tableWidget->addAction(actionRefreshFileSet);
192 connect(tableWidget, SIGNAL(
193 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
194 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
195 /* connect to the action specific to this pages class */
196 connect(actionRefreshFileSet, SIGNAL(triggered()), this,
197 SLOT(populateTable()));
198 connect(actionStatusFileSetInConsole, SIGNAL(triggered()), this,
199 SLOT(consoleStatusFileSet()));
200 connect(actionShowJobs, SIGNAL(triggered()), this,
205 * Function responding to actionListJobsofFileSet which calls mainwin function
206 * to create a window of a list of jobs of this fileset.
208 void FileSet::consoleStatusFileSet()
210 QString cmd("status fileset=");
211 cmd += m_currentlyselected;
216 * Virtual function which is called when this page is visible on the stack
218 void FileSet::currentStackItem()
222 /* Create the context menu for the fileset table */
228 * Save user settings associated with this page
230 void FileSet::writeSettings()
232 QSettings settings(m_console->m_dir->name(), "bat");
233 settings.beginGroup("FileSet");
234 settings.setValue("geometry", saveGeometry());
239 * Read and restore user settings associated with this page
241 void FileSet::readSettings()
243 QSettings settings(m_console->m_dir->name(), "bat");
244 settings.beginGroup("FileSet");
245 restoreGeometry(settings.value("geometry").toByteArray());
250 * Create a JobList object pre-populating a fileset
252 void FileSet::showJobs()
254 QTreeWidgetItem *parentItem = mainWin->getFromHash(this);
255 mainWin->createPageJobList("", "", "", m_currentlyselected, parentItem);