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);
102 jobComboBox->addItem("Any");
103 jobComboBox->addItems(m_console->job_list);
104 levelComboBox->addItem("Any");
105 levelComboBox->addItems( QStringList() << "F" << "D" << "I");
106 statusComboBox->addItem("Any");
107 statusComboBox->addItems( QStringList() << "T");
108 purgedComboBox->addItem("Any");
109 purgedComboBox->addItems( QStringList() << "0" << "1");
112 /* Set up query QString and header QStringList */
114 query += "SELECT DISTINCT Job.Jobid AS Id, Job.Name AS JobName, Client.Name AS Client,"
115 " Job.Starttime AS JobStart, Job.Type AS JobType,"
116 " Job.Level AS BackupLevel, Job.Jobfiles AS FileCount,"
117 " Job.JobBytes AS Bytes, Job.JobStatus AS Status,"
118 " Job.PurgedFiles AS Purged"
119 " FROM Job, JobMedia, Media, Client"
120 " WHERE JobMedia.JobId=Job.JobId and JobMedia.MediaId=Media.MediaId"
121 " and Client.ClientId=Job.ClientId";
122 int volumeIndex = volumeComboBox->currentIndex();
123 if (volumeIndex != -1)
124 m_mediaName = volumeComboBox->itemText(volumeIndex);
125 if (m_mediaName != "") {
126 query += " AND Media.VolumeName='" + m_mediaName + "'";
129 int clientIndex = clientsComboBox->currentIndex();
130 if (clientIndex != -1)
131 m_clientName = clientsComboBox->itemText(clientIndex);
132 if (m_clientName != "") {
133 query += " AND Client.Name='" + m_clientName + "'";
136 int jobIndex = jobComboBox->currentIndex();
137 if ((jobIndex != -1) && (jobComboBox->itemText(jobIndex) != "Any")) {
138 query += " AND Job.Name='" + jobComboBox->itemText(jobIndex) + "'";
140 int levelIndex = levelComboBox->currentIndex();
141 if ((levelIndex != -1) && (levelComboBox->itemText(levelIndex) != "Any")) {
142 query += " AND Job.Level='" + levelComboBox->itemText(levelIndex) + "'";
144 int statusIndex = statusComboBox->currentIndex();
145 if ((statusIndex != -1) && (statusComboBox->itemText(statusIndex) != "Any")) {
146 query += " AND Job.JobStatus='" + statusComboBox->itemText(statusIndex) + "'";
148 int purgedIndex = purgedComboBox->currentIndex();
149 if ((purgedIndex != -1) && (purgedComboBox->itemText(purgedIndex) != "Any")) {
150 query += " AND Job.PurgedFiles='" + purgedComboBox->itemText(purgedIndex) + "'";
152 /* If Limit check box For limit by days is checked */
153 if (daysCheckBox->checkState() == Qt::Checked) {
154 QDateTime stamp = QDateTime::currentDateTime().addDays(-daysSpinBox->value());
155 QString since = stamp.toString(Qt::ISODate);
156 query += " AND Job.Starttime>'" + since + "'";
159 query += " ORDER BY Job.Starttime DESC";
160 /* If Limit check box for limit records returned is checked */
161 if (limitCheckBox->checkState() == Qt::Checked) {
163 limit.setNum(limitSpinBox->value());
164 query += " LIMIT " + limit;
166 QStringList headerlist = (QStringList()
167 << "Job Id" << "Job Name" << "Client" << "Job Starttime" << "Job Type"
168 << "Job Level" << "Job Files" << "Job Bytes" << "Job Status" << "Purged" );
169 m_purgedIndex = headerlist.indexOf("Purged");
171 /* Initialize the QTableWidget */
172 m_checkCurrentWidget = false;
173 mp_tableWidget->clear();
174 m_checkCurrentWidget = true;
175 mp_tableWidget->setColumnCount(headerlist.size());
176 mp_tableWidget->setHorizontalHeaderLabels(headerlist);
178 /* This could be a user preference debug message?? */
179 //printf("Query cmd : %s\n",query.toUtf8().data());
180 if (m_console->sql_cmd(query, results)) {
181 m_resultCount = results.count();
183 QTableWidgetItem* p_tableitem;
185 QStringList fieldlist;
186 mp_tableWidget->setRowCount(results.size());
189 /* Iterate through the record returned from the query */
190 foreach (resultline, results) {
191 fieldlist = resultline.split("\t");
193 /* Iterate through fields in the record */
194 foreach (field, fieldlist) {
195 field = field.trimmed(); /* strip leading & trailing spaces */
196 p_tableitem = new QTableWidgetItem(field,1);
197 p_tableitem->setFlags(0);
198 p_tableitem->setForeground(blackBrush);
199 mp_tableWidget->setItem(row, column, p_tableitem);
205 /* Resize the columns */
206 mp_tableWidget->resizeColumnsToContents();
207 mp_tableWidget->resizeRowsToContents();
208 mp_tableWidget->verticalHeader()->hide();
209 if ((m_mediaName != "") && (m_resultCount == 0)){
210 /* for context sensitive searches, let the user know if there were no
212 QMessageBox::warning(this, tr("Bat"),
213 tr("The Jobs query returned no results.\n"
214 "Press OK to continue?"), QMessageBox::Ok );
219 * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
220 * The tree has been populated.
222 void JobList::PgSeltreeWidgetClicked()
231 * Virtual function override of pages function which is called when this page
232 * is visible on the stack
234 void JobList::currentStackItem()
238 m_contextActions.append(actionRefreshJobList);
244 * Virtual Function to return the name for the medialist tree widget
246 void JobList::treeWidgetName(QString &desc)
248 if ((m_mediaName == "") && (m_clientName == "")) {
252 if (m_mediaName != "" ) {
253 desc += "on Volume " + m_mediaName;
255 if (m_clientName != "" ) {
256 desc += "of Client " + m_clientName;
262 * This functions much line tableItemChanged for trees like the page selector,
263 * but I will do much less here
265 void JobList::tableItemChanged(QTableWidgetItem *currentItem, QTableWidgetItem * /*previousItem*/)
267 if (m_checkCurrentWidget) {
268 int row = currentItem->row();
269 QTableWidgetItem* jobitem = mp_tableWidget->item(row, 0);
270 m_currentJob = jobitem->text();
271 jobitem = mp_tableWidget->item(row, m_purgedIndex);
272 QString purged = jobitem->text();
273 mp_tableWidget->removeAction(actionPurgeFiles);
275 mp_tableWidget->addAction(actionPurgeFiles);
281 * Function to create connections for context sensitive menu for this and
284 void JobList::createConnections()
286 /* connect to the action specific to this pages class that shows up in the
287 * page selector tree */
288 connect(actionRefreshJobList, SIGNAL(triggered()), this,
289 SLOT(populateTable()));
290 connect(refreshButton, SIGNAL(pressed()), this, SLOT(populateTable()));
291 /* for the tableItemChanged to maintain m_currentJob */
292 connect(mp_tableWidget, SIGNAL(
293 currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
294 this, SLOT(tableItemChanged(QTableWidgetItem *, QTableWidgetItem *)));
296 /* Do what is required for the local context sensitive menu */
299 /* setContextMenuPolicy is required */
300 mp_tableWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
303 mp_tableWidget->addAction(actionRefreshJobList);
304 mp_tableWidget->addAction(actionLongListJob);
305 mp_tableWidget->addAction(actionListJobid);
306 mp_tableWidget->addAction(actionListFilesOnJob);
307 mp_tableWidget->addAction(actionListJobMedia);
308 mp_tableWidget->addAction(actionListVolumes);
309 mp_tableWidget->addAction(actionDeleteJob);
310 mp_tableWidget->addAction(actionPurgeFiles);
311 mp_tableWidget->addAction(actionRestoreFromJob);
312 mp_tableWidget->addAction(actionRestoreFromTime);
314 /* Make Connections */
315 connect(actionLongListJob, SIGNAL(triggered()), this,
316 SLOT(consoleLongListJob()));
317 connect(actionListJobid, SIGNAL(triggered()), this,
318 SLOT(consoleListJobid()));
319 connect(actionListFilesOnJob, SIGNAL(triggered()), this,
320 SLOT(consoleListFilesOnJob()));
321 connect(actionListJobMedia, SIGNAL(triggered()), this,
322 SLOT(consoleListJobMedia()));
323 connect(actionListVolumes, SIGNAL(triggered()), this,
324 SLOT(consoleListVolumes()));
325 connect(actionDeleteJob, SIGNAL(triggered()), this,
326 SLOT(consoleDeleteJob()));
327 connect(actionPurgeFiles, SIGNAL(triggered()), this,
328 SLOT(consolePurgeFiles()));
329 connect(actionRestoreFromJob, SIGNAL(triggered()), this,
330 SLOT(preRestoreFromJob()));
331 connect(actionRestoreFromTime, SIGNAL(triggered()), this,
332 SLOT(preRestoreFromTime()));
336 * Functions to respond to local context sensitive menu sending console commands
337 * If I could figure out how to make these one function passing a string, Yaaaaaa
339 void JobList::consoleLongListJob()
341 QString cmd("llist jobid=");
345 void JobList::consoleListJobid()
347 QString cmd("list jobid=");
351 void JobList::consoleListFilesOnJob()
353 QString cmd("list files jobid=");
357 void JobList::consoleListJobMedia()
359 QString cmd("list jobmedia jobid=");
363 void JobList::consoleListVolumes()
365 QString cmd("list volumes jobid=");
369 void JobList::consoleDeleteJob()
371 if (QMessageBox::warning(this, tr("Bat"),
372 tr("Are you sure you want to delete?? !!!.\n"
373 "This delete command is used to delete a Job record and all associated catalog"
374 " records that were created. This command operates only on the Catalog"
375 " database and has no effect on the actual data written to a Volume. This"
376 " command can be dangerous and we strongly recommend that you do not use"
377 " it unless you know what you are doing. The Job and all its associated"
378 " records (File and JobMedia) will be deleted from the catalog."
379 "Press OK to proceed with delete operation.?"),
380 QMessageBox::Ok | QMessageBox::Cancel)
381 == QMessageBox::Cancel) { return; }
383 QString cmd("delete job jobid=");
387 void JobList::consolePurgeFiles()
389 if (QMessageBox::warning(this, tr("Bat"),
390 tr("Are you sure you want to purge ?? !!!.\n"
391 "The Purge command will delete associated Catalog database records from Jobs and"
392 " Volumes without considering the retention period. Purge works only on the"
393 " Catalog database and does not affect data written to Volumes. This command can"
394 " be dangerous because you can delete catalog records associated with current"
395 " backups of files, and we recommend that you do not use it unless you know what"
397 "Press OK to proceed with the purge operation?"),
398 QMessageBox::Ok | QMessageBox::Cancel)
399 == QMessageBox::Cancel) { return; }
401 QString cmd("purge files jobid=");
407 * Subroutine to call preRestore to restore from a select job
409 void JobList::preRestoreFromJob()
411 new prerestorePage(m_currentJob, R_JOBIDLIST);
415 * Subroutine to call preRestore to restore from a select job
417 void JobList::preRestoreFromTime()
419 new prerestorePage(m_currentJob, R_JOBDATETIME);