From 0f6269cbaaff075b9a03e9322611b15b8c302c9c Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Tue, 15 Jan 2008 03:05:37 +0000 Subject: [PATCH] Allow table items to be selectable. If items are selected, then check to see if two are selected, set value to be used if deleting jobs so that more than one job can be deleted at a time. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6290 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/joblist/joblist.cpp | 39 +++++++++++++++++++++-- bacula/src/qt-console/joblist/joblist.h | 4 +++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/bacula/src/qt-console/joblist/joblist.cpp b/bacula/src/qt-console/joblist/joblist.cpp index 4664cd552c..2157970ba6 100644 --- a/bacula/src/qt-console/joblist/joblist.cpp +++ b/bacula/src/qt-console/joblist/joblist.cpp @@ -231,6 +231,7 @@ void JobList::populateTable() QStringList headerlist = (QStringList() << "Job Id" << "Job Name" << "Client" << "Job Starttime" << "Job Type" << "Job Level" << "Job Files" << "Job Bytes" << "Job Status" << "Purged" << "File Set" ); + m_jobIdIndex = headerlist.indexOf("Job Id"); m_purgedIndex = headerlist.indexOf("Purged"); m_typeIndex = headerlist.indexOf("Job Type"); m_statusIndex = headerlist.indexOf("Job Status"); @@ -270,8 +271,8 @@ void JobList::populateTable() m_statusIndexDone = true; statusCode = field; } else { - p_tableitem = new QTableWidgetItem(field,1); - p_tableitem->setFlags(0); + p_tableitem = new QTableWidgetItem(field, 1); + p_tableitem->setFlags(Qt::ItemIsSelectable); p_tableitem->setForeground(blackBrush); mp_tableWidget->setItem(row, column, p_tableitem); if (column == m_statusIndex) @@ -367,6 +368,7 @@ void JobList::tableItemChanged(QTableWidgetItem *currentItem, QTableWidgetItem * int row = currentItem->row(); QTableWidgetItem* jobitem = mp_tableWidget->item(row, 0); m_currentJob = jobitem->text(); + selectedJobsGet(); /* include purged action or not */ jobitem = mp_tableWidget->item(row, m_purgedIndex); @@ -510,7 +512,7 @@ void JobList::consoleDeleteJob() == QMessageBox::Cancel) { return; } QString cmd("delete job jobid="); - cmd += m_currentJob; + cmd += m_selectedJobs; consoleCommand(cmd); } void JobList::consolePurgeFiles() @@ -611,3 +613,34 @@ void JobList::readSettings() m_splitter->restoreState(settings.value(m_splitText).toByteArray()); settings.endGroup(); } + +/* + * Function to fill m_selectedJobsCount and m_selectedJobs with selected values + */ +void JobList::selectedJobsGet() +{ + QList rowList; + QList sitems = mp_tableWidget->selectedItems(); + foreach (QTableWidgetItem *sitem, sitems) { + int row = sitem->row(); + if (!rowList.contains(row)) { + rowList.append(row); + } + } + + m_selectedJobs = ""; + bool first = true; + foreach(int row, rowList) { + QTableWidgetItem * sitem = mp_tableWidget->item(row, m_jobIdIndex); + if (!first) m_selectedJobs.append(","); + else first = false; + m_selectedJobs.append(sitem->text()); + } + m_selectedJobsCount = rowList.count(); + if (m_selectedJobsCount > 1) { + QString text = QString("Delete list of %1 Jobs").arg(m_selectedJobsCount); + actionDeleteJob->setText(text); + } else { + actionDeleteJob->setText("Delete Single Job"); + } +} diff --git a/bacula/src/qt-console/joblist/joblist.h b/bacula/src/qt-console/joblist/joblist.h index f16fbd9e02..15ec02c28d 100644 --- a/bacula/src/qt-console/joblist/joblist.h +++ b/bacula/src/qt-console/joblist/joblist.h @@ -74,6 +74,7 @@ private: void setStatusColor(QTableWidgetItem *item, QString &field); void writeSettings(); void readSettings(); + void selectedJobsGet(); QSplitter *m_splitter; QString m_groupText; QString m_splitText; @@ -84,12 +85,15 @@ private: QString m_currentJob; bool m_populated; bool m_checkCurrentWidget; + int m_jobIdIndex; int m_purgedIndex; int m_typeIndex; int m_statusIndex; int m_startIndex; int m_bytesIndex; int m_filesIndex; + int m_selectedJobsCount; + QString m_selectedJobs; }; #endif /* _JOBLIST_H_ */ -- 2.39.5