]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/joblist/joblist.cpp
Multiple directors are working. Still more todo. See TODO file.
[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(QString &medianame, QString &clientname)
44 {
45    setupUi(this);
46    m_medianame = medianame;
47    m_clientname = clientname;
48    pgInitialize();
49    m_resultCount = 0;
50    m_populated = false;
51    m_closeable = false;
52    /* connect to the action specific to this pages class */
53    connect(actionRefreshJobList, SIGNAL(triggered()), this,
54                 SLOT(populateTable()));
55 }
56
57 /*
58  * The Meat of the class.
59  * This function will populate the QTableWidget, mp_tablewidget, with
60  * QTableWidgetItems representing the results of a query for what jobs exist on
61  * the media name passed from the constructor stored in m_medianame.
62  */
63 void JobList::populateTable()
64 {
65    QStringList results;
66    QString resultline;
67
68    /* Set up query QString and header QStringList */
69    QString query("");
70    query += "SELECT Job.Jobid AS Id, Job.Name AS JobName, Client.Name AS Client,"
71             " Job.Starttime AS JobStart, Job.Type AS JobType,"
72             " Job.Level AS BackupLevel, Job.Jobfiles AS FileCount,"
73             " Job.JobBytes AS Bytes, Job.JobStatus AS Status"
74             " FROM Job, JobMedia, Media, Client"
75             " WHERE JobMedia.JobId=Job.JobId and JobMedia.MediaId=Media.MediaId"
76             " and Client.ClientId=Job.ClientId";
77    if (m_medianame != "") {
78       query += " and Media.VolumeName='" + m_medianame + "'";
79       m_closeable=true;
80    }
81    if (m_clientname != "") {
82       query += " and Client.Name='" + m_clientname + "'";
83       m_closeable=true;
84    }
85    query += " ORDER BY Job.Starttime";
86    QStringList headerlist = (QStringList()
87       << "Job Id" << "Job Name" << "Client" << "Job Starttime" << "Job Type" 
88       << "Job Level" << "Job Files" << "Job Bytes" << "Job Status"  );
89
90    /* Initialize the QTableWidget */
91    mp_tableWidget->clear();
92    mp_tableWidget->setColumnCount(headerlist.size());
93    mp_tableWidget->setHorizontalHeaderLabels(headerlist);
94
95     /*  This could be a user preference debug message?? */
96     printf("Query cmd : %s\n",query.toUtf8().data());
97    if (m_console->sql_cmd(query, results)) {
98       m_resultCount = results.count();
99
100       QTableWidgetItem* p_tableitem;
101       QString field;
102       QStringList fieldlist;
103       mp_tableWidget->setRowCount(results.size());
104
105       int row = 0;
106       /* Iterate through the record returned from the query */
107       foreach (resultline, results) {
108          fieldlist = resultline.split("\t");
109          int column = 0;
110          /* Iterate through fields in the record */
111          foreach (field, fieldlist) {
112             field = field.trimmed();  /* strip leading & trailing spaces */
113             p_tableitem = new QTableWidgetItem(field,1);
114             p_tableitem->setFlags(0);
115             mp_tableWidget->setItem(row, column, p_tableitem);
116             column++;
117          }
118          row++;
119       }
120    } 
121    if ((m_medianame != "") && (m_resultCount == 0)){
122       /* for context sensitive searches, let the user know if there were no
123        * results */
124       QMessageBox::warning(this, tr("Bat"),
125           tr("The Jobs query returned no results.\n"
126          "Press OK to continue?"), QMessageBox::Ok );
127    }
128 }
129
130 /*
131  * When the treeWidgetItem in the page selector tree is singleclicked, Make sure
132  * The tree has been populated.
133  */
134 void JobList::PgSeltreeWidgetClicked()
135 {
136    if (!m_populated) {
137       populateTable();
138       m_populated=true;
139    }
140 }
141
142 /*
143  *  Virtual function override of pages function which is called when this page
144  *  is visible on the stack
145  */
146 void JobList::currentStackItem()
147 {
148    if (!m_populated) {
149       populateTable();
150       m_contextActions.append(actionRefreshJobList);
151       m_populated=true;
152    }
153 }
154
155 /*
156  * Virtual Function to return the name for the medialist tree widget
157  */
158 void JobList::treeWidgetName(QString &desc)
159 {
160    if ((m_medianame == "") && (m_clientname == "")) {
161       desc = "All Jobs";
162    } else {
163       desc = "Jobs ";
164       if (m_medianame != "" ) {
165          desc += "on Volume " + m_medianame;
166       }
167       if (m_clientname != "" ) {
168          desc += "of Client " + m_clientname;
169       }
170    }
171 }