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)
39 pgInitialize(tr("Job"), parentTreeWidgetItem);
40 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
41 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
42 m_cursor = new QTextCursor(textJobLog->document());
47 connect(pbRefresh, SIGNAL(clicked()), this, SLOT(populateAll()));
48 connect(pbDelete, SIGNAL(clicked()), this, SLOT(deleteJob()));
49 connect(pbRun, SIGNAL(clicked()), this, SLOT(rerun()));
50 connect(list_Volume, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showInfoVolume(QListWidgetItem *)));
59 new runPage(label_Name->text(),
62 QString(""), // storage
64 label_FileSet->text());
67 void Job::showInfoVolume(QListWidgetItem *item)
69 QString s= item->text();
70 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
72 MediaInfo *m = new MediaInfo(pageSelectorTreeWidgetItem, s);
73 connect(m, SIGNAL(destroyed()), this, SLOT(populateTree()));
78 if (QMessageBox::warning(this, "Bat",
79 tr("Are you sure you want to delete?? !!!.\n"
80 "This delete command is used to delete a Job record and all associated catalog"
81 " records that were created. This command operates only on the Catalog"
82 " database and has no effect on the actual data written to a Volume. This"
83 " command can be dangerous and we strongly recommend that you do not use"
84 " it unless you know what you are doing. The Job and all its associated"
85 " records (File and JobMedia) will be deleted from the catalog."
86 "Press OK to proceed with delete operation.?"),
87 QMessageBox::Ok | QMessageBox::Cancel)
88 == QMessageBox::Cancel) { return; }
90 QString cmd("delete job jobid=");
92 consoleCommand(cmd, false);
98 QFont font = textJobLog->font();
101 m_console->getDirResName(dirname);
102 QSettings settings(dirname, "bat");
103 settings.beginGroup("Console");
104 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
105 font.setPointSize(settings.value("consolePointSize", 10).toInt());
106 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
108 textJobLog->setFont(font);
111 void Job::populateAll()
113 // Pmsg0(50, "populateAll()\n");
120 * Populate the text in the window
122 void Job::populateText()
126 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
128 /* This could be a log item */
129 if (mainWin->m_sqlDebug) {
130 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
134 if (m_console->sql_cmd(query, results)) {
136 if (!results.size()) {
137 QMessageBox::warning(this, tr("Bat"),
138 tr("There were no results!\n"
139 "It is possible you may need to add \"catalog = all\" "
140 "to the Messages resource for this job.\n"), QMessageBox::Ok);
144 QString jobstr("JobId "); /* FIXME: should this be translated ? */
147 QString htmlbuf("<html><body><pre>");
149 /* Iterate through the lines of results. */
151 QStringList fieldlist;
154 foreach (QString resultline, results) {
155 fieldlist = resultline.split("\t");
157 if (fieldlist.size() < 2)
160 QString curTime = fieldlist[0].trimmed();
162 field = fieldlist[1].trimmed();
163 int colon = field.indexOf(":");
165 /* string is like <service> <jobId xxxx>: ..."
166 * we split at ':' then remove the jobId xxxx string (always the same) */
167 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
168 if (curSvc == lastSvc && curTime == lastTime) {
175 // htmlbuf += "<td>" + curTime + "</td>";
176 htmlbuf += "\n" + curSvc + " ";
178 /* rest of string is marked as pre-formatted (here trimming should
179 * be avoided, to preserve original formatting) */
180 QString msg(field.mid(colon+2));
181 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
182 /* error msg, use a specific class */
183 htmlbuf += "</pre><pre class=err>" + msg + "</pre><pre>";
188 /* non standard string, place as-is */
189 if (curTime == lastTime) {
194 // htmlbuf += "<td>" + curTime + "</td>";
195 htmlbuf += "\n" + field ;
198 } /* foreach resultline */
200 htmlbuf += "</pre></body></html>";
202 /* full text ready. Here a custom sheet is used to align columns */
203 QString logSheet(".err {color:#FF0000;}");
204 textJobLog->document()->setDefaultStyleSheet(logSheet);
205 textJobLog->document()->setHtml(htmlbuf);
206 textJobLog->moveCursor(QTextCursor::Start);
208 } /* if results from query */
213 * Populate the text in the window
215 void Job::populateForm()
220 "SELECT JobId, Job.Name, Level, Client.Name, Pool.Name, FileSet, SchedTime, StartTime, EndTime, "
221 "EndTime - StartTime AS Duration, JobBytes, JobFiles, JobErrors, JobStatus, PurgedFiles "
222 "FROM Job JOIN Client USING (ClientId) LEFT JOIN Pool USING (PoolId) "
223 "LEFT JOIN FileSet USING (FileSetId)"
224 "WHERE JobId=" + m_jobId;
226 if (m_console->sql_cmd(query, results)) {
228 QStringList fieldlist;
230 foreach (resultline, results) { // should have only one result
231 fieldlist = resultline.split("\t");
232 QStringListIterator fld(fieldlist);
233 label_JobId->setText(fld.next());
234 label_Name->setText(fld.next());
236 label_Level->setText(job_level_to_str(fld.next()[0].toAscii()));
238 label_Client->setText(fld.next());
239 label_Pool->setText(fld.next());
240 label_FileSet->setText(fld.next());
241 label_SchedTime->setText(fld.next());
242 label_StartTime->setText(fld.next());
243 label_EndTime->setText(fld.next());
244 label_Duration->setText(fld.next());
246 label_JobBytes->setText(convertBytesSI(fld.next().toULongLong()));
247 label_JobFiles->setText(fld.next());
249 label_JobErrors->setText(err);
252 if (stat == "T" && err.toInt() > 0) {
255 label_JobStatus->setPixmap(QPixmap(":/images/" + stat + ".png"));
256 jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));
258 label_JobStatus->setToolTip(stat);
260 chkbox_PurgedFiles->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
265 void Job::populateVolumes()
269 "SELECT DISTINCT VolumeName, InChanger, Slot "
270 "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
271 "WHERE JobId=" + m_jobId + " ORDER BY VolumeName ";
272 if (mainWin->m_sqlDebug) Pmsg1(0, "Query cmd : %s\n",query.toUtf8().data());
276 if (m_console->sql_cmd(query, results)) {
278 QStringList fieldlist;
279 list_Volume->clear();
280 foreach (resultline, results) { // should have only one result
281 fieldlist = resultline.split("\t");
282 QStringListIterator fld(fieldlist);
283 // QListWidgetItem(QIcon(":/images/inchanger" + fld.next() + ".png"),
284 // fld.next(), list_Volume);
285 list_Volume->addItem(fld.next());
290 //QListWidgetItem ( const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type )