-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathdebugviewer.cpp
More file actions
137 lines (116 loc) Β· 4.05 KB
/
debugviewer.cpp
File metadata and controls
137 lines (116 loc) Β· 4.05 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
// This file is part of Qt Bitcoin Trader
// https://github.com/JulyIGHOR/QtBitcoinTrader
// Copyright (C) 2013-2023 July Ighor <julyighor@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// 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 "debugviewer.h"
#include "main.h"
#include "timesync.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QScrollBar>
#include <QSysInfo>
DebugViewer::DebugViewer() : QWidget()
{
savingFile = false;
ui.setupUi(this);
ui.checkEnabled->setChecked(true);
setWindowFlags(Qt::Window);
setAttribute(Qt::WA_DeleteOnClose, true);
if (baseValues.logThread_)
{
delete baseValues.logThread_;
baseValues.logThread_ = nullptr;
}
logThread = new LogThread(false);
connect(logThread, &LogThread::sendLogSignal, this, &DebugViewer::sendLogSlot, Qt::QueuedConnection);
debugLevel = 2;
show();
}
DebugViewer::~DebugViewer()
{
debugLevel = 0;
if (logThread)
{
delete baseValues.logThread_;
baseValues.logThread_ = nullptr;
}
}
void DebugViewer::on_buttonSaveAs_clicked()
{
savingFile = true;
QString fileName =
QFileDialog::getSaveFileName(this,
"Save Debug Information",
QDateTime::fromSecsSinceEpoch(TimeSync::getTimeT()).toUTC().toString("yyyy-MM-dd HH.mm.ss") + ".log",
"Log file (*.log)");
if (fileName.isEmpty())
{
savingFile = false;
return;
}
QFile writeLog(fileName);
if (writeLog.open(QIODevice::WriteOnly))
{
writeLog.write("Qt Bitcoin Trader " + baseValues.appVerStr + "\r\n");
QByteArray osLine;
#ifdef Q_OS_WIN
osLine = "OS: Windows ";
#endif
#ifdef Q_OS_MAC
osLine = "OS: Mac OS ";
#else
#endif
if (osLine.isEmpty())
osLine = "OS: Linux\r\n";
osLine += QSysInfo::productVersion().toLatin1() + "\r\n";
writeLog.write(osLine);
writeLog.write(ui.debugText->toPlainText().toLatin1());
writeLog.close();
}
else
QMessageBox::critical(this, windowTitle(), "Cannot save log file");
savingFile = false;
}
void DebugViewer::sendLogSlot(QByteArray text)
{
QStringList filterData(QString(text).split("\r\n"));
for (int n = 0; n < filterData.size(); n++)
if (filterData.at(n).startsWith("Cookie", Qt::CaseInsensitive))
filterData[n] = "Cookie: THERE_WAS_A_COOKIE";
if (!savingFile && ui.checkEnabled->isChecked())
ui.debugText->appendPlainText(filterData.join("\n"));
}
void DebugViewer::on_radioDebug_toggled(bool debugEnabled)
{
if (debugEnabled)
debugLevel = 1;
else
debugLevel = 2;
ui.debugText->setPlainText("");
}