From 11bf62c7c3251fd7dddd89ff9d020cd6683f5cfe Mon Sep 17 00:00:00 2001 From: Dirk H Bartley Date: Sat, 31 Mar 2007 15:27:37 +0000 Subject: [PATCH] dhb turn joblist from a dummy class to a working class querying the database for jobs on a specific media. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4477 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/qt-console/joblist/joblist.cpp | 66 ++++++++++++++++++--- bacula/src/qt-console/joblist/joblist.h | 6 +- bacula/src/qt-console/joblist/joblist.ui | 2 +- bacula/src/qt-console/medialist/medialist.h | 2 +- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/bacula/src/qt-console/joblist/joblist.cpp b/bacula/src/qt-console/joblist/joblist.cpp index fab223fd01..96c863376c 100644 --- a/bacula/src/qt-console/joblist/joblist.cpp +++ b/bacula/src/qt-console/joblist/joblist.cpp @@ -36,14 +36,66 @@ #include "bat.h" #include "joblist.h" + +/* + * Constructor for the class + */ JobList::JobList(Console *console, QString &medianame) { - printf("Listing Jobs on Media %s\n", medianame.toUtf8().data()); setupUi(this); - m_console = console; - tableWidget->clear(); - tableWidget->setColumnCount(2); - tableWidget->setRowCount(5); - QTableWidgetItem* item = new QTableWidgetItem(medianame,1); - tableWidget->setItem(1, 1, item); + /* Store passed variables in member variables */ + mp_console = console; + m_medianame = medianame; + + populateTable(); +} + +/* + * The Meat of the class. + * This function will populate the QTableWidget, mp_tablewidget, with + * QTableWidgetItems representing the results of a query for what jobs exist on + * the media name passed from the constructor stored in m_medianame. + */ +void JobList::populateTable() +{ + QStringList results; + QString resultline; + + /* Set up query QString and header QStringList */ + QString query(""); + query += "SELECT j.jobid,j.name,j.starttime,j.type,j.level,j.jobfiles," + "j.jobstatus" + " FROM job j, jobmedia jm, media m" + " WHERE jm.jobid=j.jobid and jm.mediaid=m.mediaid and m.VolumeName='"; + query += m_medianame + "' ORDER BY j.starttime"; + QStringList headerlist = (QStringList() + << "Job Id" << "Job Name" << "Job Starttime" << "Job Type" << "Job Level" + << "Job Files" << "Job Status"); + + /* Initialize the QTableWidget */ + mp_tableWidget->clear(); + mp_tableWidget->setColumnCount(headerlist.size()); + mp_tableWidget->setHorizontalHeaderLabels(headerlist); + + if (mp_console->sql_cmd(query, results)) { + QTableWidgetItem* p_tableitem; + QString field; + QStringList fieldlist; + mp_tableWidget->setRowCount(results.size()); + + int row = 0; + /* Iterate through the record returned from the query */ + foreach (resultline, results) { + fieldlist = resultline.split("\t"); + int column = 0; + /* Iterate through fields in the record */ + foreach (field, fieldlist) { + field = field.trimmed(); /* strip leading & trailing spaces */ + p_tableitem = new QTableWidgetItem(field,1); + mp_tableWidget->setItem(row, column, p_tableitem); + column++; + } + row++; + } + } } diff --git a/bacula/src/qt-console/joblist/joblist.h b/bacula/src/qt-console/joblist/joblist.h index cddee16de3..ee7a0341aa 100644 --- a/bacula/src/qt-console/joblist/joblist.h +++ b/bacula/src/qt-console/joblist/joblist.h @@ -47,7 +47,11 @@ public: public slots: private: - Console *m_console; + void populateTable(); + +private: + Console *mp_console; + QString m_medianame; }; #endif /* _JOBLIST_H_ */ diff --git a/bacula/src/qt-console/joblist/joblist.ui b/bacula/src/qt-console/joblist/joblist.ui index e7a9142963..86f820a6e0 100644 --- a/bacula/src/qt-console/joblist/joblist.ui +++ b/bacula/src/qt-console/joblist/joblist.ui @@ -20,7 +20,7 @@ 6 - + diff --git a/bacula/src/qt-console/medialist/medialist.h b/bacula/src/qt-console/medialist/medialist.h index ce933fcff7..a1154307f9 100644 --- a/bacula/src/qt-console/medialist/medialist.h +++ b/bacula/src/qt-console/medialist/medialist.h @@ -57,12 +57,12 @@ public slots: private: void createConnections(); + void populateTree(); private: Console *mp_console; QString m_currentlyselected; bool m_populated; - void populateTree(); }; #endif /* _MEDIALIST_H_ */ -- 2.39.5