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 many
7 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 Bacula® is a registered trademark of Kern Sibbald.
22 * Dirk Bartley, March 2007
29 JobLog::JobLog(QString &jobId, QTreeWidgetItem *parentTreeWidgetItem) : Pages()
32 pgInitialize(tr("JobLog"), parentTreeWidgetItem);
33 QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
34 thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
35 m_cursor = new QTextCursor(textEdit->document());
45 void JobLog::getFont()
47 QFont font = textEdit->font();
50 m_console->getDirResName(dirname);
51 QSettings settings(dirname, "bat");
52 settings.beginGroup("Console");
53 font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
54 font.setPointSize(settings.value("consolePointSize", 10).toInt());
55 font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
57 textEdit->setFont(font);
61 * Populate the text in the window
63 void JobLog::populateText()
66 query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "' order by Time";
68 /* This could be a log item */
69 if (mainWin->m_sqlDebug) {
70 Pmsg1(000, "Log query cmd : %s\n", query.toUtf8().data());
74 if (m_console->sql_cmd(query, results)) {
76 if (!results.size()) {
77 QMessageBox::warning(this, tr("Bat"),
78 tr("There were no results!\n"
79 "It is possible you may need to add \"catalog = all\" "
80 "to the Messages resource for this job.\n"), QMessageBox::Ok);
84 QString jobstr("JobId "); /* FIXME: should this be translated ? */
87 QString htmlbuf("<html><body><b>" + tr("Log records for job %1").arg(m_jobId) );
88 htmlbuf += "</b><table>";
90 /* Iterate through the lines of results. */
92 QStringList fieldlist;
95 foreach (QString resultline, results) {
96 fieldlist = resultline.split("\t");
98 if (fieldlist.size() < 2)
103 QString curTime = fieldlist[0].trimmed();
105 field = fieldlist[1].trimmed();
106 int colon = field.indexOf(":");
108 /* string is like <service> <jobId xxxx>: ..."
109 * we split at ':' then remove the jobId xxxx string (always the same) */
110 QString curSvc(field.left(colon).replace(jobstr,"").trimmed());
111 if (curSvc == lastSvc && curTime == lastTime) {
118 htmlbuf += "<td>" + curTime + "</td>";
119 htmlbuf += "<td><p>" + curSvc + "</p></td>";
121 /* rest of string is marked as pre-formatted (here trimming should
122 * be avoided, to preserve original formatting) */
123 QString msg(field.mid(colon+2));
124 if (msg.startsWith( tr("Error:")) ) { /* FIXME: should really be translated ? */
125 /* error msg, use a specific class */
126 htmlbuf += "<td><pre class=err>" + msg + "</pre></td>";
128 htmlbuf += "<td><pre>" + msg + "</pre></td>";
131 /* non standard string, place as-is */
132 if (curTime == lastTime) {
137 htmlbuf += "<td>" + curTime + "</td>";
138 htmlbuf += "<td><pre>" + field + "</pre></td>";
143 } /* foreach resultline */
145 htmlbuf += "</table></body></html>";
147 /* full text ready. Here a custom sheet is used to align columns */
148 QString logSheet("p,pre,.err {margin-left: 10px} .err {color:#FF0000;}");
149 textEdit->document()->setDefaultStyleSheet(logSheet);
150 textEdit->document()->setHtml(htmlbuf);
151 textEdit->moveCursor(QTextCursor::Start);
153 } /* if results from query */