]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/joblog/joblog.cpp
Add some comments, a little cleanup. Show a message if no log message found
[bacula/bacula] / bacula / src / qt-console / joblog / joblog.cpp
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 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 plus additions
11    that are listed 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: joblog.cpp 4230 2007-02-21 20:07:37Z kerns $
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    m_cursor = new QTextCursor(textEdit->document());
48
49    m_jobId = jobId;
50    getFont();
51    populateText();
52
53    dockPage();
54    setCurrent();
55 }
56
57 void JobLog::getFont()
58 {
59    QFont font = textEdit->font();
60
61    QString dirname;
62    m_console->getDirResName(dirname);
63    QSettings settings(dirname, "bat");
64    settings.beginGroup("Console");
65    font.setFamily(settings.value("consoleFont", "Courier").value<QString>());
66    font.setPointSize(settings.value("consolePointSize", 10).toInt());
67    font.setFixedPitch(settings.value("consoleFixedPitch", true).toBool());
68    settings.endGroup();
69    textEdit->setFont(font);
70 }
71
72 /*
73  * Populate the text in the window
74  */
75 void JobLog::populateText()
76 {
77    QString heading("<A href=\"#top\">Log records for job ");
78    heading += m_jobId + "</A>\n";
79    textEdit->insertHtml(heading);
80    
81    QString query("");
82    query = "SELECT Time, LogText FROM Log WHERE JobId='" + m_jobId + "'";
83
84    QStringList results;
85    if (m_console->sql_cmd(query, results)) {
86       QString field;
87       QStringList fieldlist;
88       int resultcount = 0;
89
90       /* Iterate through the lines of results. */
91       foreach (QString resultline, results) {
92          fieldlist = resultline.split("\t");
93
94          int column = 0;
95          /* Iterate through fields in the record */
96          foreach (field, fieldlist) {
97             display_text(field);
98             if (column <= 1) display_text("\n");
99             column += 1;
100          } /* foreach field */
101          resultcount += 1;
102       } /* foreach resultline */
103       if (resultcount == 0) {
104          /* show a message about configuration item */
105          printf("go here\n");
106          QMessageBox::warning(this, tr("Bat"),
107             tr("There were no results ??  !!!.\n"
108 "It is possible you may need to add \"catalog = all\" to the Messages stanza"
109 " for this job.\n"), QMessageBox::Ok);
110       }
111    } /* if results from query */
112    textEdit->scrollToAnchor("top");
113 }
114
115 /*
116  * Put text into the joblog window with an overload
117  */
118 void JobLog::display_text(const QString buf)
119 {
120    m_cursor->movePosition(QTextCursor::End);
121    m_cursor->insertText(buf);
122 }
123
124 void JobLog::display_text(const char *buf)
125 {
126    m_cursor->movePosition(QTextCursor::End);
127    m_cursor->insertText(buf);
128 }