This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoggingView.cpp
More file actions
160 lines (128 loc) · 4.02 KB
/
LoggingView.cpp
File metadata and controls
160 lines (128 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* MacGitver
* Copyright (C) 2012-2013 The MacGitver-Developers <dev@macgitver.org>
*
* (C) Sascha Cunz <sascha@macgitver.org>
* (C) Cunz RaD Ltd.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License (Version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if
* not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QStringBuilder>
#include <QWebView>
#include <QWebPage>
#include <QWebFrame>
#include "LoggingView.hpp"
#include "LoggingModule.hpp"
#include "libMacGitverCore/Log/LogEvent.hpp"
#include "libMacGitverCore/Config/Config.h"
LoggingView::LoggingView()
: View("Log")
{
setViewName( trUtf8( "Log" ) );
mBrowser = new QWebView;
mBrowser->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
setWidget( mBrowser );
LoggingModule::self()->setView(this);
connect(&Config::self(), SIGNAL(fontsChanged()),
this, SLOT(clearPrefixCache()));
}
LoggingView::~LoggingView()
{
LoggingModule::self()->setView(NULL);
}
QSize LoggingView::sizeHint() const
{
return QSize( 300, 110 );
}
void LoggingView::clearCache()
{
mCache.clear();
}
void LoggingView::regenerate()
{
quint64 lastId = 0;
QString html;
if (htmlPrefix.isEmpty()) {
calculatePrefix();
}
html = htmlPrefix;
Log::Event::List events = LoggingModule::self()->currentEvents();
foreach (Log::Event e, events) {
if (mHiddenChannels.contains(e.channel().name())) {
continue;
}
QString eventHtml;
if (mCache.contains(e.uniqueId())) {
eventHtml = mCache[e.uniqueId()];
}
else {
QDateTime stamp = e.timeStamp();
eventHtml =
tr("<div id=\"%3\" class=\"evt\"><span class=\"ts\">%1</span>%2</div>\n")
.arg(stamp.time().toString())
.arg(e.html())
.arg(e.uniqueId());
mCache.insert(e.uniqueId(), eventHtml);
}
html = html % eventHtml;
lastId = e.uniqueId();
}
html += htmlPostfix;
//qDebug("Setting HTML to\n%s", qPrintable(html));
mBrowser->setHtml(html);
if (lastId) {
QString anchor = QString::number(lastId);
mBrowser->page()->mainFrame()->scrollToAnchor(anchor);
}
}
void LoggingView::clearPrefixCache()
{
htmlPrefix = QString();
htmlPostfix = QString();
LoggingModule::self()->queueViewUpdate();
}
void LoggingView::calculatePrefix()
{
const char* sz =
"<html>\n"
" <head>\n"
" <style type=\"text/css\">\n"
" body {\n"
" margin: 2px;\n"
" }\n"
" div {\n"
" margin: 0px 0px 0px 72px;\n"
" padding: 1px 2px 3px 0px;\n"
" %1\n"
" }\n"
" span.ts {\n"
" text-color: blue;\n"
" padding: 0px 0px 0px 2px;\n"
" margin: 0px 7px 0px -72px;\n"
" %2\n"
" }\n"
" code {\n"
" margin: 0px;\n"
" background-color: #EEE;\n"
" border-radius: 5px;\n"
" border: 1px solid #CCC;\n"
" padding: 0px 1px 0px 1px;\n"
" %2\n"
" }\n"
" </style>\n"
" </head>\n"
" <body>\n";
htmlPrefix = QString::fromUtf8(sz)
.arg(Config::defaultFontCSS())
.arg(Config::defaultFixedFontCSS());
htmlPostfix = QLatin1String("</body></html>");
}