2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
23 * Dirk Bartley, March 2007
30 JobLog::JobLog(QString &jobId, QTreeWidgetItem *parentTreeWidgetItem) : Pages()
33 pgInitialize(tr("JobLog"), parentTreeWidgetItem);
34 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
35 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
36 m_cursor = new QTextCursor(textEdit->document());
46 void JobLog::getFont()
48 QFont font = textEdit->font();
51 m_console->getDirResName(dirname);
52 QSettings settings(dirname, "bat");
53 settings.beginGroup("Console");
54 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
55 font.setPointSize(settings.value("consolePointSize", 10).toInt());
56 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
58 textEdit->setFont(font);
62 * Populate the text in the window
64 void JobLog::populateText()
67 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
69 /* This could be a log item */
70 if (mainWin->m_sqlDebug) {
71 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
75 if (m_console->sql_cmd(query, results)) {
77 if (!results.size()) {
78 QMessageBox::warning(this, tr("Bat"),
79 tr("There were no results!\n"
80 "It is possible you may need to add \"catalog = all\" "
81 "to the Messages resource for this job.\n"), QMessageBox::Ok);
85 QString jobstr("JobId "); /* FIXME: should this be translated ? */
88 QString htmlbuf("<html><body><b>" + tr("Log records for job %1").arg(m_jobId) );
89 htmlbuf += "</b><table>";
91 /* Iterate through the lines of results. */
93 QStringList fieldlist;
96 foreach (QString resultline, results) {
97 fieldlist = resultline.split("\t");
99 if (fieldlist.size() < 2)
104 QString curTime = fieldlist[0].trimmed();
106 field = fieldlist[1].trimmed();
107 int colon = field.indexOf(":");
109 /* string is like <service> <jobId xxxx>: ..."
110 * we split at ':' then remove the jobId xxxx string (always the same) */
111 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
112 if (curSvc == lastSvc && curTime == lastTime) {
119 htmlbuf += "<td>" + curTime + "</td>";
120 htmlbuf += "<td><p>" + curSvc + "</p></td>";
122 /* rest of string is marked as pre-formatted (here trimming should
123 * be avoided, to preserve original formatting) */
124 QString msg(field.mid(colon+2));
125 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
126 /* error msg, use a specific class */
127 htmlbuf += "<td><pre class=err>" + msg + "</pre></td>";
129 htmlbuf += "<td><pre>" + msg + "</pre></td>";
132 /* non standard string, place as-is */
133 if (curTime == lastTime) {
138 htmlbuf += "<td>" + curTime + "</td>";
139 htmlbuf += "<td><pre>" + field + "</pre></td>";
144 } /* foreach resultline */
146 htmlbuf += "</table></body></html>";
148 /* full text ready. Here a custom sheet is used to align columns */
149 QString logSheet("p,pre,.err {margin-left: 10px} .err {color:#FF0000;}");
150 textEdit->document()->setDefaultStyleSheet(logSheet);
151 textEdit->document()->setHtml(htmlbuf);
152 textEdit->moveCursor(QTextCursor::Start);
154 } /* if results from query */