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"
34 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(list_Volume, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showInfoVolume(QListWidgetItem *)));
55 void Job::showInfoVolume(QListWidgetItem *item)
57 QString s= item->text();
58 QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
60 MediaInfo *m = new MediaInfo(pageSelectorTreeWidgetItem, s);
61 connect(m, SIGNAL(destroyed()), this, SLOT(populateTree()));
66 if (QMessageBox::warning(this, "Bat",
67 tr("Are you sure you want to delete?? !!!.\n"
68 "This delete command is used to delete a Job record and all associated catalog"
69 " records that were created. This command operates only on the Catalog"
70 " database and has no effect on the actual data written to a Volume. This"
71 " command can be dangerous and we strongly recommend that you do not use"
72 " it unless you know what you are doing. The Job and all its associated"
73 " records (File and JobMedia) will be deleted from the catalog."
74 "Press OK to proceed with delete operation.?"),
75 QMessageBox::Ok | QMessageBox::Cancel)
76 == QMessageBox::Cancel) { return; }
78 QString cmd("delete job jobid=");
80 consoleCommand(cmd, false);
86 QFont font = textJobLog->font();
89 m_console->getDirResName(dirname);
90 QSettings settings(dirname, "bat");
91 settings.beginGroup("Console");
92 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
93 font.setPointSize(settings.value("consolePointSize", 10).toInt());
94 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
96 textJobLog->setFont(font);
99 void Job::populateAll()
101 // Pmsg0(50, "populateAll()\n");
108 * Populate the text in the window
110 void Job::populateText()
114 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
116 /* This could be a log item */
117 if (mainWin->m_sqlDebug) {
118 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
122 if (m_console->sql_cmd(query, results)) {
124 if (!results.size()) {
125 QMessageBox::warning(this, tr("Bat"),
126 tr("There were no results!\n"
127 "It is possible you may need to add \"catalog = all\" "
128 "to the Messages resource for this job.\n"), QMessageBox::Ok);
132 QString jobstr("JobId "); /* FIXME: should this be translated ? */
135 QString htmlbuf("<html><body><pre>");
137 /* Iterate through the lines of results. */
139 QStringList fieldlist;
142 foreach (QString resultline, results) {
143 fieldlist = resultline.split("\t");
145 if (fieldlist.size() < 2)
148 QString curTime = fieldlist[0].trimmed();
150 field = fieldlist[1].trimmed();
151 int colon = field.indexOf(":");
153 /* string is like <service> <jobId xxxx>: ..."
154 * we split at ':' then remove the jobId xxxx string (always the same) */
155 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
156 if (curSvc == lastSvc && curTime == lastTime) {
163 // htmlbuf += "<td>" + curTime + "</td>";
164 htmlbuf += "\n" + curSvc + " ";
166 /* rest of string is marked as pre-formatted (here trimming should
167 * be avoided, to preserve original formatting) */
168 QString msg(field.mid(colon+2));
169 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
170 /* error msg, use a specific class */
171 htmlbuf += "</pre><pre class=err>" + msg + "</pre><pre>";
176 /* non standard string, place as-is */
177 if (curTime == lastTime) {
182 // htmlbuf += "<td>" + curTime + "</td>";
183 htmlbuf += "\n" + field ;
186 } /* foreach resultline */
188 htmlbuf += "</pre></body></html>";
190 /* full text ready. Here a custom sheet is used to align columns */
191 QString logSheet(".err {color:#FF0000;}");
192 textJobLog->document()->setDefaultStyleSheet(logSheet);
193 textJobLog->document()->setHtml(htmlbuf);
194 textJobLog->moveCursor(QTextCursor::Start);
196 } /* if results from query */
201 * Populate the text in the window
203 void Job::populateForm()
208 "SELECT JobId, Job.Name, Level, Client.Name, Pool.Name, FileSet, SchedTime, StartTime, EndTime, "
209 "EndTime - StartTime AS Duration, JobBytes, JobFiles, JobErrors, JobStatus, PurgedFiles "
210 "FROM Job JOIN Client USING (ClientId) LEFT JOIN Pool USING (PoolId) "
211 "LEFT JOIN FileSet USING (FileSetId)"
212 "WHERE JobId=" + m_jobId;
214 if (m_console->sql_cmd(query, results)) {
216 QStringList fieldlist;
218 foreach (resultline, results) { // should have only one result
219 fieldlist = resultline.split("\t");
220 QStringListIterator fld(fieldlist);
221 label_JobId->setText(fld.next());
222 label_Name->setText(fld.next());
224 label_Level->setText(job_level_to_str(fld.next()[0].toAscii()));
226 label_Client->setText(fld.next());
227 label_Pool->setText(fld.next());
228 label_FileSet->setText(fld.next());
229 label_SchedTime->setText(fld.next());
230 label_StartTime->setText(fld.next());
231 label_EndTime->setText(fld.next());
232 label_Duration->setText(fld.next());
234 label_JobBytes->setText(convertBytesSI(fld.next().toULongLong()));
235 label_JobFiles->setText(fld.next());
237 label_JobErrors->setText(err);
240 if (stat == "T" && err.toInt() > 0) {
243 label_JobStatus->setPixmap(QPixmap(":/images/" + stat + ".png"));
244 jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));
246 label_JobStatus->setToolTip(stat);
248 chkbox_PurgedFiles->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
253 void Job::populateVolumes()
257 "SELECT DISTINCT VolumeName, InChanger, Slot "
258 "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
259 "WHERE JobId=" + m_jobId + " ORDER BY VolumeName ";
260 if (mainWin->m_sqlDebug) Pmsg1(0, "Query cmd : %s\n",query.toUtf8().data());
264 if (m_console->sql_cmd(query, results)) {
266 QStringList fieldlist;
267 list_Volume->clear();
268 foreach (resultline, results) { // should have only one result
269 fieldlist = resultline.split("\t");
270 QStringListIterator fld(fieldlist);
271 // QListWidgetItem(QIcon(":/images/inchanger" + fld.next() + ".png"),
272 // fld.next(), list_Volume);
273 list_Volume->addItem(fld.next());
278 //QListWidgetItem ( const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type )