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(0, "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 */
200 // Need to use the fmtwidgetitem helper instead
201 static QString convertBytesSI(qint64 qfld)
203 static const qint64 KB = Q_INT64_C(1000);
204 static const qint64 MB = (KB * KB);
205 static const qint64 GB = (MB * KB);
206 static const qint64 TB = (GB * KB);
207 static const qint64 PB = (TB * KB);
208 static const qint64 EB = (PB * KB);
210 /* note: division is integer, so to have some decimals we divide for a
211 smaller unit (e.g. GB for a TB number and so on) */
217 else if (qfld >= PB) {
221 else if (qfld >= TB) {
225 else if (qfld >= GB) {
229 else if (qfld >= MB) {
233 else if (qfld >= KB) {
234 suffix = 'k'; /* SI uses lowercase k */
237 /* plain bytes, no need to reformat */
238 return QString("%1 B").arg(qfld);
241 /* having divided for a smaller unit, now we can safely convert to double and
242 use the extra room for decimals */
243 return QString("%1 %2B").arg(qfld / 1000.0, 0, 'f', 2).arg(suffix);
247 * Populate the text in the window
249 void Job::populateForm()
254 "SELECT JobId, Job.Name, Level, Client.Name, Pool.Name, FileSet, SchedTime, StartTime, EndTime, "
255 "EndTime - StartTime AS Duration, JobBytes, JobFiles, JobErrors, JobStatus, PurgedFiles "
256 "FROM Job JOIN Client USING (ClientId) LEFT JOIN Pool USING (PoolId) "
257 "LEFT JOIN FileSet USING (FileSetId)"
258 "WHERE JobId=" + m_jobId;
260 if (m_console->sql_cmd(query, results)) {
262 QStringList fieldlist;
264 foreach (resultline, results) { // should have only one result
265 fieldlist = resultline.split("\t");
266 QStringListIterator fld(fieldlist);
267 label_JobId->setText(fld.next());
268 label_Name->setText(fld.next());
270 label_Level->setText(job_level_to_str(fld.next()[0].toAscii()));
272 label_Client->setText(fld.next());
273 label_Pool->setText(fld.next());
274 label_FileSet->setText(fld.next());
275 label_SchedTime->setText(fld.next());
276 label_StartTime->setText(fld.next());
277 label_EndTime->setText(fld.next());
278 label_Duration->setText(fld.next());
280 label_JobBytes->setText(convertBytesSI(fld.next().toULongLong()));
281 label_JobFiles->setText(fld.next());
282 label_JobErrors->setText(fld.next());
285 label_JobStatus->setPixmap(QPixmap(":/images/" + stat + ".png"));
286 jobstatus_to_ascii_gui(stat[0].toAscii(), buf, sizeof(buf));
288 label_JobStatus->setToolTip(stat);
290 chkbox_PurgedFiles->setCheckState(fld.next().toInt()?Qt::Checked:Qt::Unchecked);
295 void Job::populateVolumes()
299 "SELECT DISTINCT VolumeName, InChanger, Slot "
300 "FROM Job JOIN JobMedia USING (JobId) JOIN Media USING (MediaId) "
301 "WHERE JobId=" + m_jobId + " ORDER BY VolumeName ";
302 Pmsg1(000, "Query cmd : %s\n",query.toUtf8().data());
306 if (m_console->sql_cmd(query, results)) {
308 QStringList fieldlist;
309 list_Volume->clear();
310 foreach (resultline, results) { // should have only one result
311 fieldlist = resultline.split("\t");
312 QStringListIterator fld(fieldlist);
313 // QListWidgetItem(QIcon(":/images/inchanger" + fld.next() + ".png"),
314 // fld.next(), list_Volume);
315 list_Volume->addItem(fld.next());
320 //QListWidgetItem ( const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type )