]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/joblog/joblog.cpp
Tweak JobLog display
[bacula/bacula] / bacula / src / qt-console / joblog / joblog.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2007-2008 Free Software Foundation Europe e.V.
5
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
11    in the file LICENSE.
12
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.
17
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
21    02110-1301, USA.
22
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.
27 */
28  
29 /*
30  *   Version $Id$
31  *
32  *  JobLog Class
33  *
34  *   Dirk Bartley, March 2007
35  *
36  */ 
37
38 #include "bat.h"
39 #include "joblog.h"
40
41 JobLog::JobLog(QString &jobId, QTreeWidgetItem *parentTreeWidgetItem)
42 {
43    setupUi(this);
44    m_name = "JobLog";
45    m_closeable = true;
46    pgInitialize(parentTreeWidgetItem);
47    QTreeWidgetItem* thisitem = mainWin->getFromHash(this);
48    thisitem->setIcon(0,QIcon(QString::fromUtf8(":images/joblog.png")));
49    m_cursor = new QTextCursor(textEdit->document());
50
51    m_jobId = jobId;
52    getFont();
53    populateText();
54
55    dockPage();
56    setCurrent();
57 }
58
59 void JobLog::getFont()
60 {
61    QFont font = textEdit->font();
62
63    QString dirname;
64    m_console->getDirResName(dirname);
65    QSettings settings(dirname, "bat");
66    settings.beginGroup("Console");
67    font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
68    font.setPointSize(settings.value("consolePointSize", 10).toInt());
69    font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
70    settings.endGroup();
71    textEdit->setFont(font);
72 }
73
74 /*
75  * Populate the text in the window
76  */
77 void JobLog::populateText()
78 {
79    QString heading("<A href=\"#top\">Log records for job ");
80    heading += m_jobId + "</A><br>\n";
81    textEdit->insertHtml(heading);
82
83    if (!m_console->preventInUseConnect())
84        return;
85    
86    QString query("");
87    query = "SELECT Time,LogText FROM Log WHERE JobId='" + m_jobId + "' ORDER by Time";
88
89    QStringList results;
90    if (m_console->sql_cmd(query, results)) {
91       QString field;
92       QStringList fieldlist;
93       int resultcount = 0;
94
95       /* Iterate through the lines of results. */
96       foreach (QString resultline, results) {
97          int column = 0;
98          fieldlist = resultline.split("\t");
99          /* Iterate through fields in the record */
100          foreach (field, fieldlist) {
101             display_text(field);
102             if (column == 0) display_text(" ");
103             column++;
104          } /* foreach field */
105          resultcount++; 
106       } /* foreach resultline */
107       if (resultcount == 0) {
108          /* show a message about configuration item */
109          QMessageBox::warning(this, "Bat",
110             tr("There were no results!\n"
111 "It is possible you may need to add \"catalog = all\" to the Messages resource"
112 " for this job.\n"), QMessageBox::Ok);
113       }
114    } /* if results from query */
115    textEdit->scrollToAnchor("top");
116 }
117
118 /*
119  * Put text into the joblog window with an overload
120  */
121 void JobLog::display_text(const QString buf)
122 {
123    m_cursor->movePosition(QTextCursor::End);
124    m_cursor->insertText(buf);
125 }
126
127 void JobLog::display_text(const char *buf)
128 {
129    m_cursor->movePosition(QTextCursor::End);
130    m_cursor->insertText(buf);
131 }