2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2009 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 and included
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 Kern Sibbald.
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.
31 #include "util/fmtwidgetitem.h"
32 #include "mediainfo/mediainfo.h"
35 Job::Job(QString &jobId, QTreeWidgetItem *parentTreeWidgetItem)
38 pgInitialize(tr("Job"), parentTreeWidgetItem);
39 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
40 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
41 m_cursor = new QTextCursor(textJobLog->document());
46 connect(pbRefresh, SIGNAL(clicked()), this, SLOT(populateAll()));
47 connect(pbDelete, SIGNAL(clicked()), this, SLOT(deleteJob()));
48 connect(pbRun, SIGNAL(clicked()), this, SLOT(rerun()));
49 connect(list_Volume, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showInfoVolume(QListWidgetItem *)));
58 new runPage(label_Name->text(),
61 QString(""), // storage
63 label_FileSet->text());
66 void Job::showInfoVolume(QListWidgetItem *item)
68 QString s= item->text();
69 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
71 MediaInfo *m = new MediaInfo(pageSelectorTreeWidgetItem, s);
72 connect(m, SIGNAL(destroyed()), this, SLOT(populateTree()));
77 if (QMessageBox::warning(this, "Bat",
78 tr("Are you sure you want to delete?? !!!.\n"
79 "This delete command is used to delete a Job record and all associated catalog"
80 " records that were created. This command operates only on the Catalog"
81 " database and has no effect on the actual data written to a Volume. This"
82 " command can be dangerous and we strongly recommend that you do not use"
83 " it unless you know what you are doing. The Job and all its associated"
84 " records (File and JobMedia) will be deleted from the catalog."
85 "Press OK to proceed with delete operation.?"),
86 QMessageBox::Ok | QMessageBox::Cancel)
87 == QMessageBox::Cancel) { return; }
89 QString cmd("delete job jobid=");
91 consoleCommand(cmd, false);
97 QFont font = textJobLog->font();
100 m_console->getDirResName(dirname);
101 QSettings settings(dirname, "bat");
102 settings.beginGroup("Console");
103 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
104 font.setPointSize(settings.value("consolePointSize", 10).toInt());
105 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
107 textJobLog->setFont(font);
110 void Job::populateAll()
112 // Pmsg0(50, "populateAll()\n");
119 * Populate the text in the window
121 void Job::populateText()
125 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
127 /* This could be a log item */
128 if (mainWin->m_sqlDebug) {
129 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
133 if (m_console->sql_cmd(query, results)) {
135 if (!results.size()) {
136 QMessageBox::warning(this, tr("Bat"),
137 tr("There were no results!\n"
138 "It is possible you may need to add \"catalog = all\" "
139 "to the Messages resource for this job.\n"), QMessageBox::Ok);
143 QString jobstr("JobId "); /* FIXME: should this be translated ? */
146 QString htmlbuf("<html><body><pre>");
148 /* Iterate through the lines of results. */
150 QStringList fieldlist;
153 foreach (QString resultline, results) {
154 fieldlist = resultline.split("\t");
156 if (fieldlist.size() < 2)
159 QString curTime = fieldlist[0].trimmed();
161 field = fieldlist[1].trimmed();
162 int colon = field.indexOf(":");
164 /* string is like <service> <jobId xxxx>: ..."
165 * we split at ':' then remove the jobId xxxx string (always the same) */
166 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
167 if (curSvc == lastSvc && curTime == lastTime) {
174 // htmlbuf += "<td>" + curTime + "</td>";
175 htmlbuf += "\n" + curSvc + " ";
177 /* rest of string is marked as pre-formatted (here trimming should
178 * be avoided, to preserve original formatting) */
179 QString msg(field.mid(colon+2));
180 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
181 /* error msg, use a specific class */
182 htmlbuf += "</pre><pre class=err>" + msg + "</pre><pre>";
187 /* non standard string, place as-is */
188 if (curTime == lastTime) {
193 // htmlbuf += "<td>" + curTime + "</td>";
194 htmlbuf += "\n" + field ;
197 } /* foreach resultline */
199 htmlbuf += "</pre></body></html>";
201 /* full text ready. Here a custom sheet is used to align columns */
202 QString logSheet(".err {color:#FF0000;}");
203 textJobLog->document()->setDefaultStyleSheet(logSheet);
204 textJobLog->document()->setHtml(htmlbuf);
205 textJobLog->moveCursor(QTextCursor::Start);
207 } /* if results from query */
212 * Populate the text in the window
214 void Job::populateForm()
219 "SELECT JobId, Job.Name, Level, Client.Name, Pool.Name, FileSet, SchedTime, StartTime, EndTime, "
220 "EndTime-StartTime AS Duration, JobBytes, JobFiles, JobErrors, JobStatus, PurgedFiles "
221 "FROM Job JOIN Client USING (ClientId) LEFT JOIN Pool ON (Job.PoolId = Pool.PoolId) "
222 "LEFT JOIN FileSet ON (Job.FileSetId = FileSet.FileSetId)"
223 "WHERE JobId=" + m_jobId;
225 if (m_console->sql_cmd(query, results)) {
227 QStringList fieldlist;
229 foreach (resultline, results) { // should have only one result
230 fieldlist = resultline.split("\t");
231 QStringListIterator fld(fieldlist);
232 label_JobId->setText(fld.next());
233 label_Name->setText(fld.next());
235 label_Level->setText(job_level_to_str(fld.next()[0].toAscii()));
237 label_Client->setText(fld.next());
238 label_Pool->setText(fld.next());
239 label_FileSet->setText(fld.next());
240 label_SchedTime->setText(fld.next());
241 label_StartTime->setText(fld.next());
242 label_EndTime->setText(fld.next());
243 label_Duration->setText(fld.next());
245 label_JobBytes->setText(convertBytesSI(fld.next().toULongLong()));
246 label_JobFiles->setText(fld.next());
248 label_JobErrors->setText(err);
251 if (stat == "T" && err.toInt() > 0) {
254 label_JobStatus->setPixmap(QPixmap(":/images/" + stat + ".png"));
255 jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));
257 label_JobStatus->setToolTip(stat);
259 chkbox_PurgedFiles->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
264 void Job::populateVolumes()
268 "SELECT DISTINCT VolumeName, InChanger, Slot "
269 "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
270 "WHERE JobId=" + m_jobId + " ORDER BY VolumeName ";
271 if (mainWin->m_sqlDebug) Pmsg1(0, "Query cmd : %s\n",query.toUtf8().data());
275 if (m_console->sql_cmd(query, results)) {
277 QStringList fieldlist;
278 list_Volume->clear();
279 foreach (resultline, results) { // should have only one result
280 fieldlist = resultline.split("\t");
281 QStringListIterator fld(fieldlist);
282 // QListWidgetItem(QIcon(":/images/inchanger" + fld.next() + ".png"),
283 // fld.next(), list_Volume);
284 list_Volume->addItem(fld.next());
289 //QListWidgetItem ( const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type )