]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/joblist/joblist.cpp
dhb Added a clients page to the stack. Do some name changing to be more
[bacula/bacula] / bacula / src / qt-console / joblist / joblist.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
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.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28 /*
29  *   Version $Id: joblist.h 4230 2007-02-21 20:07:37Z kerns $
30  *
31  *   Dirk Bartley, March 2007
32  */
33  
34 #include <QAbstractEventDispatcher>
35 #include <QTableWidgetItem>
36 #include "bat.h"
37 #include "joblist.h"
38
39
40 /*
41  * Constructor for the class
42  */
43 JobList::JobList(QStackedWidget *parent, Console *console, QString &medianame)
44 {
45    setupUi(this);
46    /* Store passed variables in member variables */
47    mp_console = console;
48    m_parent = parent;
49    m_medianame = medianame;
50    m_resultCount = 0;
51    m_populated = false;
52    m_closeable = false;
53    /* connect to the action specific to this pages class */
54    connect(actionRefreshJobList, SIGNAL(triggered()), this,
55                 SLOT(populateTable()));
56 }
57
58 /*
59  * The Meat of the class.
60  * This function will populate the QTableWidget, mp_tablewidget, with
61  * QTableWidgetItems representing the results of a query for what jobs exist on
62  * the media name passed from the constructor stored in m_medianame.
63  */
64 void JobList::populateTable()
65 {
66    QStringList results;
67    QString resultline;
68
69    /* Set up query QString and header QStringList */
70    QString query("");
71    query += "SELECT j.Jobid,j.Name,j.Starttime,j.Type,j.Level,j.Jobfiles,"
72            "j.JobBytes,j.JobStatus"
73            " FROM job j, jobmedia jm, media m"
74            " WHERE jm.jobid=j.jobid and jm.mediaid=m.mediaid";
75    if (m_medianame != "") {
76       query += " and m.VolumeName='" + m_medianame + "'";
77       m_closeable=true;
78    }
79    query += " ORDER BY j.Starttime";
80    QStringList headerlist = (QStringList()
81       << "Job Id" << "Job Name" << "Job Starttime" << "Job Type" << "Job Level"
82       << "Job Files" << "Job Bytes" << "Job Status");
83
84    /* Initialize the QTableWidget */
85    mp_tableWidget->clear();
86    mp_tableWidget->setColumnCount(headerlist.size());
87    mp_tableWidget->setHorizontalHeaderLabels(headerlist);
88
89     /*  This could be a debug message?? */
90     /* printf("Query cmd : %s\n",query.toUtf8().data()); */
91    if (mp_console->sql_cmd(query, results)) {
92       m_resultCount = results.count();
93
94       QTableWidgetItem* p_tableitem;
95       QString field;
96       QStringList fieldlist;
97       mp_tableWidget->setRowCount(results.size());
98
99       int row = 0;
100       /* Iterate through the record returned from the query */
101       foreach (resultline, results) {
102          fieldlist = resultline.split("\t");
103          int column = 0;
104          /* Iterate through fields in the record */
105          foreach (field, fieldlist) {
106             field = field.trimmed();  /* strip leading & trailing spaces */
107             p_tableitem = new QTableWidgetItem(field,1);
108             p_tableitem->setFlags(0);
109             mp_tableWidget->setItem(row, column, p_tableitem);
110             column++;
111          }
112          row++;
113       }
114    } 
115    if ((m_medianame != "") && (m_resultCount == 0)){
116       /* for context sensitive searches, let the user know if there were no results */
117       QMessageBox::warning(this, tr("Bat"), tr("The Jobs query returned no results.\n"
118          "Press OK to continue?"), QMessageBox::Ok );
119    }
120 }
121
122 /*
123  *  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
124  *  * The tree has been populated.
125  *  */
126 void JobList::PgSeltreeWidgetClicked()
127 {
128    if (!m_populated) {
129       populateTable();
130       m_populated=true;
131    }
132 }
133
134 /*
135  *  Virtual function which is called when this page is visible on the stack
136  */
137 void JobList::currentStackItem()
138 {
139    if (!m_populated) {
140       populateTable();
141       m_contextActions.append(actionRefreshJobList);
142       m_populated=true;
143    }
144 }