1 /* Copyright (c) 2015  Gerald Knizia
2  *
3  * This file is part of the IboView program (see: http://www.iboview.org)
4  *
5  * IboView is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, version 3.
8  *
9  * IboView is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with bfint (LICENSE). If not, see http://www.gnu.org/licenses/
16  *
17  * Please see IboView documentation in README.txt for:
18  * -- A list of included external software and their licenses. The included
19  *    external software's copyright is not touched by this agreement.
20  * -- Notes on re-distribution and contributions to/further development of
21  *    the IboView software
22  */
23 
24 #include <QMessageBox>
25 #include <QApplication>
26 #include "IvLog.h"
27 
28 
FLogQt(QObject * parent)29 FLogQt::FLogQt(QObject *parent)
30    : QObject(parent), m_AbortSignalled(false)
31 {
32 }
33 
~FLogQt()34 FLogQt::~FLogQt()
35 {
36 }
37 
Flush()38 void FLogQt::Flush()
39 {
40    if (w.size() != 0) {
41       emit textEmitted(QString(w.c_str()));
42       w.clear();
43    }
44 }
45 
46 // tell the running process to emit an abort signal the next time
47 // CheckStatus() is called.
emitAbortSignal()48 void FLogQt::emitAbortSignal()
49 {
50    m_AbortSignalled = true;
51 }
52 
GetStatus()53 ct::FLog::FRunStatus FLogQt::GetStatus()
54 {
55    if (m_AbortSignalled)
56       return STATUS_AbortSignalled;
57    else
58       return STATUS_Okay;
59 }
60 
endSection()61 void FLogQt::endSection()
62 {
63    emit sectionEnded();
64 }
65 
endReport()66 void FLogQt::endReport()
67 {
68    emit reportEnded(QString());
69 }
70 
71 
FMemoryLogQt(QObject * parent)72 FMemoryLogQt::FMemoryLogQt(QObject *parent)
73    : FLogQt(parent), m_LogText(""), m_LogStream(&m_LogText)
74 {
75 }
76 
GetText()77 QString const &FMemoryLogQt::GetText()
78 {
79    return m_LogText;
80 }
81 
Clear()82 void FMemoryLogQt::Clear()
83 {
84    m_LogText.clear();
85 }
86 
Flush()87 void FMemoryLogQt::Flush()
88 {
89    if (w.size() != 0) {
90       QString
91          s(w.c_str());
92       emit textEmitted(s);
93       m_LogStream << s;
94       w.clear();
95    }
96 }
97 
appendText(QString s)98 void FMemoryLogQt::appendText(QString s)
99 {
100 //    w << q2s(s);
101 //    Flush();
102    Flush();
103    m_LogStream << s;
104 }
105 
106 
~FMemoryLogQt()107 FMemoryLogQt::~FMemoryLogQt()
108 {
109 }
110 
endReport()111 void FMemoryLogQt::endReport()
112 {
113    Flush();
114    emit reportEnded("<html><pre>" + m_LogText + "</pre></html>");
115 }
116