2 Bacula® - The Network Backup Solution
4 Copyright (C) 2000-2007 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 plus additions
11 that are listed in the file LICENSE.
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 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.
29 * Version $Id: joblist.h 4230 2007-02-21 20:07:37Z kerns $
31 * Dirk Bartley, March 2007
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
41 * Constructor for the class
43 JobList::JobList(QString &mediaName, QString &clientname,
44 QTreeWidgetItem *parentTreeWidgetItem)
48 m_mediaName = mediaName;
49 m_clientName = clientname;
50 pgInitialize(parentTreeWidgetItem);
54 m_checkCurrentWidget = true;
57 /* Set Defaults for check and spin for limits */
58 limitCheckBox->setCheckState(Qt::Checked);
59 limitSpinBox->setValue(150);
60 daysCheckBox->setCheckState(Qt::Unchecked);
61 daysSpinBox->setValue(30);
65 * The Meat of the class.
66 * This function will populate the QTableWidget, mp_tablewidget, with
67 * QTableWidgetItems representing the results of a query for what jobs exist on
68 * the media name passed from the constructor stored in m_mediaName.
70 void JobList::populateTable()
74 QBrush blackBrush(Qt::black);
76 /* Can't do this in constructor because not neccesarily conected in constructor */
78 clientsComboBox->addItem("");
79 clientsComboBox->addItems(m_console->client_list);
80 int clientIndex = clientsComboBox->findText(m_clientName, Qt::MatchExactly);
81 if (clientIndex != -1)
82 clientsComboBox->setCurrentIndex(clientIndex);
84 /* Not m_console->volume_list will query database */
85 QString query("SELECT VolumeName AS Media FROM Media ORDER BY Media");
86 QStringList results, volumeList;
87 if (m_console->sql_cmd(query, results)) {
89 QStringList fieldlist;
90 /* Iterate through the lines of results. */
91 foreach (QString resultline, results) {
92 fieldlist = resultline.split("\t");
93 volumeList.append(fieldlist[0]);
94 } /* foreach resultline */
95 } /* if results from query */
96 volumeComboBox->addItem("");
97 volumeComboBox->addItems(volumeList);
98 int volumeIndex = volumeComboBox->findText(m_mediaName, Qt::MatchExactly);
99 if (volumeIndex != -1) {
100 volumeComboBox->setCurrentIndex(volumeIndex);
104 /* Set up query QString and header QStringList */
106 query += "SELECT DISTINCT Job.Jobid AS Id, Job.Name AS JobName, Client.Name AS Client,"
107 " Job.Starttime AS JobStart, Job.Type AS JobType,"
108 " Job.Level AS BackupLevel, Job.Jobfiles AS FileCount,"
109 " Job.JobBytes AS Bytes, Job.JobStatus AS Status"
110 " FROM Job, JobMedia, Media, Client"
111 " WHERE JobMedia.JobId=Job.JobId and JobMedia.MediaId=Media.MediaId"
112 " and Client.ClientId=Job.ClientId";
113 int volumeIndex = volumeComboBox->currentIndex();
114 if (volumeIndex != -1)
115 m_mediaName = volumeComboBox->itemText(volumeIndex);
116 if (m_mediaName != "") {
117 query += " AND Media.VolumeName='" + m_mediaName + "'";
120 int clientIndex = clientsComboBox->currentIndex();
121 if (clientIndex != -1)
122 m_clientName = clientsComboBox->itemText(clientIndex);
123 if (m_clientName != "") {
124 query += " AND Client.Name='" + m_clientName + "'";
127 /* If Limit check box For limit by days is checked */
128 if (daysCheckBox->checkState() == Qt::Checked) {
129 QDateTime stamp = QDateTime::currentDateTime().addDays(-daysSpinBox->value());
130 QString since = stamp.toString(Qt::ISODate);
131 query += " AND Job.Starttime>'" + since + "'";
134 query += " ORDER BY Job.Starttime DESC";
135 /* If Limit check box for limit records returned is checked */
136 if (limitCheckBox->checkState() == Qt::Checked) {
138 limit.setNum(limitSpinBox->value());
139 query += " LIMIT " + limit;
141 QStringList headerlist = (QStringList()
142 << "Job Id" << "Job Name" << "Client" << "Job Starttime" << "Job Type"
143 << "Job Level" << "Job Files" << "Job Bytes" << "Job Status" );
145 /* Initialize the QTableWidget */
146 m_checkCurrentWidget = false;
147 mp_tableWidget->clear();
148 m_checkCurrentWidget = true;
149 mp_tableWidget->setColumnCount(headerlist.size());
150 mp_tableWidget->setHorizontalHeaderLabels(headerlist);
152 /* This could be a user preference debug message?? */
153 //printf("Query cmd : %s\n",query.toUtf8().data());
154 if (m_console->sql_cmd(query, results)) {
155 m_resultCount = results.count();
157 QTableWidgetItem* p_tableitem;
159 QStringList fieldlist;
160 mp_tableWidget->setRowCount(results.size());
163 /* Iterate through the record returned from the query */
164 foreach (resultline, results) {
165 fieldlist = resultline.split("\t");
167 /* Iterate through fields in the record */
168 foreach (field, fieldlist) {
169 field = field.trimmed(); /* strip leading & trailing spaces */
170 p_tableitem = new QTableWidgetItem(field,1);
171 p_tableitem->setFlags(0);
172 p_tableitem->setForeground(blackBrush);
173 mp_tableWidget->setItem(row, column, p_tableitem);
179 /* Resize the columns */
180 mp_tableWidget->resizeColumnsToContents();
181 mp_tableWidget->resizeRowsToContents();
182 mp_tableWidget->verticalHeader()->hide();
183 if ((m_mediaName != "") && (m_resultCount == 0)){
184 /* for context sensitive searches, let the user know if there were no
186 QMessageBox::warning(this, tr("Bat"),
187 tr("The Jobs query returned no results.\n"
188 "Press OK to continue?"), QMessageBox::Ok );
193 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
194 * The tree has been populated.
196 void JobList::PgSeltreeWidgetClicked()
205 * Virtual function override of pages function which is called when this page
206 * is visible on the stack
208 void JobList::currentStackItem()
212 m_contextActions.append(actionRefreshJobList);
218 * Virtual Function to return the name for the medialist tree widget
220 void JobList::treeWidgetName(QString &desc)
222 if ((m_mediaName == "") && (m_clientName == "")) {
226 if (m_mediaName != "" ) {
227 desc += "on Volume " + m_mediaName;
229 if (m_clientName != "" ) {
230 desc += "of Client " + m_clientName;
236 * This functions much line tableItemChanged for trees like the page selector,
237 * but I will do much less here
239 void JobList::tableItemChanged(QTableWidgetItem *currentItem, QTableWidgetItem * /*previousItem*/)
241 if (m_checkCurrentWidget) {
242 int row = currentItem->row();
243 QTableWidgetItem* jobitem = mp_tableWidget->item(row, 0);
244 m_currentJob = jobitem->text();
249 * Function to create connections for context sensitive menu for this and
252 void JobList::createConnections()
254 /* connect to the action specific to this pages class that shows up in the
255 * page selector tree */
256 connect(actionRefreshJobList, SIGNAL(triggered()), this,
257 SLOT(populateTable()));
258 connect(refreshButton, SIGNAL(pressed()), this, SLOT(populateTable()));
259 /* for the tableItemChanged to maintain m_currentJob */
260 connect(mp_tableWidget, SIGNAL(
261 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
262 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
264 /* Do what is required for the local context sensitive menu */
267 /* setContextMenuPolicy is required */
268 mp_tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
271 mp_tableWidget->addAction(actionRefreshJobList);
272 mp_tableWidget->addAction(actionLongListJob);
273 mp_tableWidget->addAction(actionListJobid);
274 mp_tableWidget->addAction(actionListFilesOnJob);
275 mp_tableWidget->addAction(actionListJobMedia);
276 mp_tableWidget->addAction(actionListVolumes);
277 mp_tableWidget->addAction(actionDeleteJob);
278 mp_tableWidget->addAction(actionPurgeFiles);
279 mp_tableWidget->addAction(actionRestoreFromJob);
281 /* Make Connections */
282 connect(actionLongListJob, SIGNAL(triggered()), this,
283 SLOT(consoleLongListJob()));
284 connect(actionListJobid, SIGNAL(triggered()), this,
285 SLOT(consoleListJobid()));
286 connect(actionListFilesOnJob, SIGNAL(triggered()), this,
287 SLOT(consoleListFilesOnJob()));
288 connect(actionListJobMedia, SIGNAL(triggered()), this,
289 SLOT(consoleListJobMedia()));
290 connect(actionListVolumes, SIGNAL(triggered()), this,
291 SLOT(consoleListVolumes()));
292 connect(actionDeleteJob, SIGNAL(triggered()), this,
293 SLOT(consoleDeleteJob()));
294 connect(actionPurgeFiles, SIGNAL(triggered()), this,
295 SLOT(consolePurgeFiles()));
296 connect(actionRestoreFromJob, SIGNAL(triggered()), this,
297 SLOT(preRestoreFromJob()));
301 * Functions to respond to local context sensitive menu sending console commands
302 * If I could figure out how to make these one function passing a string, Yaaaaaa
304 void JobList::consoleLongListJob()
306 QString cmd("llist jobid=");
310 void JobList::consoleListJobid()
312 QString cmd("list jobid=");
316 void JobList::consoleListFilesOnJob()
318 QString cmd("list files jobid=");
322 void JobList::consoleListJobMedia()
324 QString cmd("list jobmedia jobid=");
328 void JobList::consoleListVolumes()
330 QString cmd("list volumes jobid=");
334 void JobList::consoleDeleteJob()
336 QString cmd("delete job jobid=");
340 void JobList::consolePurgeFiles()
342 QString cmd("purge files jobid=");
348 * Subroutine to call preRestore to restore from a select job
350 void JobList::preRestoreFromJob()
352 new prerestorePage(m_currentJob);