2 Bacula® - The Network Backup Solution
4 Copyright (C) 2007-2008 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 John Walker.
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.
34 * Dirk Bartley, March 2007
41 JobLog::JobLog(QString &jobId, QTreeWidgetItem *parentTreeWidgetItem)
45 pgInitialize(tr("JobLog"), parentTreeWidgetItem);
46 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
47 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
48 m_cursor = new QTextCursor(textEdit->document());
58 void JobLog::getFont()
60 QFont font = textEdit->font();
63 m_console->getDirResName(dirname);
64 QSettings settings(dirname, "bat");
65 settings.beginGroup("Console");
66 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
67 font.setPointSize(settings.value("consolePointSize", 10).toInt());
68 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
70 textEdit->setFont(font);
74 * Populate the text in the window
76 void JobLog::populateText()
78 if (!m_console->preventInUseConnect())
82 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
84 /* This could be a log item */
85 if (mainWin->m_sqlDebug) {
86 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
90 if (m_console->sql_cmd(query, results)) {
92 if (!results.size()) {
93 QMessageBox::warning(this, tr("Bat"),
94 tr("There were no results!\n"
95 "It is possible you may need to add \"catalog = all\" "
96 "to the Messages resource for this job.\n"), QMessageBox::Ok);
100 QString jobstr("JobId "); /* FIXME: should this be translated ? */
103 QString htmlbuf("<html><body><b>" + tr("Log records for job %1").arg(m_jobId) );
104 htmlbuf += "</b><table>";
106 /* Iterate through the lines of results. */
108 QStringList fieldlist;
111 foreach (QString resultline, results) {
112 fieldlist = resultline.split("\t");
114 if (fieldlist.size() < 2)
119 QString curTime = fieldlist[0].trimmed();
121 field = fieldlist[1].trimmed();
122 int colon = field.indexOf(":");
124 /* string is like <service> <jobId xxxx>: ..."
125 * we split at ':' then remove the jobId xxxx string (always the same) */
126 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
127 if (curSvc == lastSvc && curTime == lastTime) {
134 htmlbuf += "<td>" + curTime + "</td>";
135 htmlbuf += "<td><p>" + curSvc + "</p></td>";
137 /* rest of string is marked as pre-formatted (here trimming should
138 * be avoided, to preserve original formatting) */
139 QString msg(field.mid(colon+2));
140 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
141 /* error msg, use a specific class */
142 htmlbuf += "<td><pre class=err>" + msg + "</pre></td>";
144 htmlbuf += "<td><pre>" + msg + "</pre></td>";
147 /* non standard string, place as-is */
148 if (curTime == lastTime) {
153 htmlbuf += "<td>" + curTime + "</td>";
154 htmlbuf += "<td><pre>" + field + "</pre></td>";
159 } /* foreach resultline */
161 htmlbuf += "</table></body></html>";
163 /* full text ready. Here a custom sheet is used to align columns */
164 QString logSheet("p,pre,.err {margin-left: 10px} .err {color:#FF0000;}");
165 textEdit->document()->setDefaultStyleSheet(logSheet);
166 textEdit->document()->setHtml(htmlbuf);
167 textEdit->moveCursor(QTextCursor::Start);
169 } /* if results from query */