2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2007-2009 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
24 * Dirk Bartley, March 2007
31 JobLog::JobLog(QString &jobId, QTreeWidgetItem *parentTreeWidgetItem) : Pages()
34 pgInitialize(tr("JobLog"), parentTreeWidgetItem);
35 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
36 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
37 m_cursor = new QTextCursor(textEdit->document());
47 void JobLog::getFont()
49 QFont font = textEdit->font();
52 m_console->getDirResName(dirname);
53 QSettings settings(dirname, "bat");
54 settings.beginGroup("Console");
55 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
56 font.setPointSize(settings.value("consolePointSize", 10).toInt());
57 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
59 textEdit->setFont(font);
63 * Populate the text in the window
65 void JobLog::populateText()
68 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
70 /* This could be a log item */
71 if (mainWin->m_sqlDebug) {
72 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
76 if (m_console->sql_cmd(query, results)) {
78 if (!results.size()) {
79 QMessageBox::warning(this, tr("Bat"),
80 tr("There were no results!\n"
81 "It is possible you may need to add \"catalog = all\" "
82 "to the Messages resource for this job.\n"), QMessageBox::Ok);
86 QString jobstr("JobId "); /* FIXME: should this be translated ? */
89 QString htmlbuf("<html><body><b>" + tr("Log records for job %1").arg(m_jobId) );
90 htmlbuf += "</b><table>";
92 /* Iterate through the lines of results. */
94 QStringList fieldlist;
97 foreach (QString resultline, results) {
98 fieldlist = resultline.split("\t");
100 if (fieldlist.size() < 2)
105 QString curTime = fieldlist[0].trimmed();
107 field = fieldlist[1].trimmed();
108 int colon = field.indexOf(":");
110 /* string is like <service> <jobId xxxx>: ..."
111 * we split at ':' then remove the jobId xxxx string (always the same) */
112 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
113 if (curSvc == lastSvc && curTime == lastTime) {
120 htmlbuf += "<td>" + curTime + "</td>";
121 htmlbuf += "<td><p>" + curSvc + "</p></td>";
123 /* rest of string is marked as pre-formatted (here trimming should
124 * be avoided, to preserve original formatting) */
125 QString msg(field.mid(colon+2));
126 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
127 /* error msg, use a specific class */
128 htmlbuf += "<td><pre class=err>" + msg + "</pre></td>";
130 htmlbuf += "<td><pre>" + msg + "</pre></td>";
133 /* non standard string, place as-is */
134 if (curTime == lastTime) {
139 htmlbuf += "<td>" + curTime + "</td>";
140 htmlbuf += "<td><pre>" + field + "</pre></td>";
145 } /* foreach resultline */
147 htmlbuf += "</table></body></html>";
149 /* full text ready. Here a custom sheet is used to align columns */
150 QString logSheet("p,pre,.err {margin-left: 10px} .err {color:#FF0000;}");
151 textEdit->document()->setDefaultStyleSheet(logSheet);
152 textEdit->document()->setHtml(htmlbuf);
153 textEdit->moveCursor(QTextCursor::Start);
155 } /* if results from query */