2022-09-15 00:07:23 +00:00
|
|
|
#include "loggingwindow.h"
|
|
|
|
#include "ui_loggingwindow.h"
|
|
|
|
|
2022-09-23 16:11:25 +00:00
|
|
|
loggingWindow::loggingWindow(QString logFilename, QWidget *parent) :
|
2022-09-15 00:07:23 +00:00
|
|
|
QWidget(parent),
|
2022-09-23 16:18:42 +00:00
|
|
|
ui(new Ui::loggingWindow),
|
|
|
|
logFilename(logFilename)
|
2022-09-15 00:07:23 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2025-03-02 04:58:32 +00:00
|
|
|
this->setWindowTitle(tr("Log"));
|
2022-09-15 00:07:23 +00:00
|
|
|
ui->logTextDisplay->setReadOnly(true);
|
|
|
|
ui->userAnnotationText->setFocus();
|
|
|
|
ui->annotateBtn->setDefault(true);
|
|
|
|
ui->logTextDisplay->setFocusPolicy(Qt::NoFocus);
|
|
|
|
ui->annotateBtn->setFocusPolicy(Qt::NoFocus);
|
2022-09-23 15:46:33 +00:00
|
|
|
|
|
|
|
QDir d = QFileInfo(logFilename).absoluteDir();
|
|
|
|
logDirectory = d.absolutePath();
|
2022-09-15 00:07:23 +00:00
|
|
|
|
2025-01-10 17:23:47 +00:00
|
|
|
QFont font = QFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).family());
|
2022-09-15 18:52:08 +00:00
|
|
|
font.setStyleHint(QFont::TypeWriter);
|
|
|
|
ui->logTextDisplay->setFont(font);
|
|
|
|
ui->userAnnotationText->setFont(font);
|
|
|
|
|
2022-09-15 00:07:23 +00:00
|
|
|
clipboard = QApplication::clipboard();
|
|
|
|
socket = new QTcpSocket(this);
|
|
|
|
connect(socket, SIGNAL(connected()), this, SLOT(connectedToHost()));
|
|
|
|
connect(socket, SIGNAL(disconnected()), this, SLOT(disconnectedFromHost()));
|
|
|
|
connect(socket, SIGNAL(readyRead()), this, SLOT(handleDataFromLoggingHost()));
|
2023-01-15 10:34:54 +00:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
|
|
|
connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(handleLoggingHostError(QAbstractSocket::SocketError)));
|
|
|
|
#else
|
2022-09-15 00:07:23 +00:00
|
|
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(handleLoggingHostError(QAbstractSocket::SocketError)));
|
2023-01-15 10:34:54 +00:00
|
|
|
#endif
|
2022-09-15 18:52:08 +00:00
|
|
|
vertLogScroll = ui->logTextDisplay->verticalScrollBar();
|
|
|
|
horizLogScroll = ui->logTextDisplay->horizontalScrollBar();
|
|
|
|
|
|
|
|
vertLogScroll->setValue(vertLogScroll->maximum());
|
|
|
|
horizLogScroll->setValue(horizLogScroll->minimum());
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
loggingWindow::~loggingWindow()
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&textMutex);
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-09-17 22:02:21 +00:00
|
|
|
void loggingWindow::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
(void)event;
|
|
|
|
on_toBottomBtn_clicked();
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:52:08 +00:00
|
|
|
void loggingWindow::setInitialDebugState(bool debugModeEnabled)
|
|
|
|
{
|
|
|
|
ui->debugBtn->blockSignals(true);
|
|
|
|
ui->debugBtn->setChecked(debugModeEnabled);
|
|
|
|
ui->debugBtn->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
2025-03-02 04:58:32 +00:00
|
|
|
void loggingWindow::ingestSettings(preferences prefs) {
|
|
|
|
this->prefs = prefs;
|
|
|
|
havePrefs = true;
|
|
|
|
}
|
|
|
|
|
2023-11-26 16:23:16 +00:00
|
|
|
void loggingWindow::acceptLogText(QPair<QtMsgType,QString> text)
|
2022-09-15 00:07:23 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&textMutex);
|
2023-11-26 16:23:16 +00:00
|
|
|
QString colour = "white";
|
|
|
|
if (text.first == QtDebugMsg)
|
|
|
|
{
|
2024-02-12 21:36:39 +00:00
|
|
|
colour = "#ffbc11"; // orange
|
2023-11-26 16:23:16 +00:00
|
|
|
} else if (text.first == QtWarningMsg)
|
|
|
|
{
|
|
|
|
colour = "yellow";
|
|
|
|
} else if (text.first == QtCriticalMsg || text.first == QtFatalMsg)
|
|
|
|
{
|
|
|
|
colour = "red";
|
2024-01-28 13:14:47 +00:00
|
|
|
} else if (text.first == QtInfoMsg) {
|
|
|
|
colour = "white";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colour = "green";
|
2023-11-26 16:23:16 +00:00
|
|
|
}
|
2024-08-03 05:17:53 +00:00
|
|
|
QString sanitized = text.second.replace(" ", " ");
|
|
|
|
ui->logTextDisplay->appendHtml(QString("<p><span style='color:%0'>%1</span></p>").arg(colour,sanitized));
|
2022-09-15 18:59:04 +00:00
|
|
|
if(vertLogScroll->value() == vertLogScroll->maximum())
|
|
|
|
{
|
|
|
|
horizLogScroll->setValue(horizLogScroll->minimum());
|
|
|
|
}
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
2025-03-02 04:58:32 +00:00
|
|
|
void loggingWindow::sendLogToHost()
|
2022-09-15 00:07:23 +00:00
|
|
|
{
|
2025-03-02 04:58:32 +00:00
|
|
|
if(prefs.pastebinHost.isEmpty() || prefs.pastebinPort == 0 || prefs.pastebinPort > 65535) {
|
|
|
|
qInfo(logLogger()) << tr("Pastbin host and/or port is not configured correctly. Check settings.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qInfo(logLogger()).noquote().nospace() << tr("Sending data to ") << prefs.pastebinHost << ":" << prefs.pastebinPort << tr(", Standby.");
|
|
|
|
socket->connectToHost(prefs.pastebinHost, prefs.pastebinPort);
|
2022-09-15 00:07:23 +00:00
|
|
|
ui->sendToPasteBtn->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::handleDataFromLoggingHost()
|
|
|
|
{
|
2025-03-02 04:58:32 +00:00
|
|
|
qInfo(logLogger()) << tr("Receiving data from logging host.");
|
2022-09-15 00:07:23 +00:00
|
|
|
QString URL;
|
|
|
|
QByteArray data = socket->readAll();
|
|
|
|
if(data.length() < 256)
|
|
|
|
{
|
|
|
|
URL = QString(data).trimmed();
|
|
|
|
if(!URL.isEmpty())
|
|
|
|
{
|
|
|
|
clipboard->setText(URL);
|
2025-03-02 04:58:32 +00:00
|
|
|
qInfo(logLogger()) << tr("Sent log to URL: ") << URL;
|
|
|
|
qInfo(logLogger()) << tr("This address already copied to the clipboard. Please paste this URL in to your support questions.");
|
|
|
|
URLmsgBox.setText(tr("Your log has been posted, and the URL has been copied to the clipboard."));
|
2022-09-15 18:55:45 +00:00
|
|
|
URLmsgBox.setInformativeText("<b>" + URL + "</b>");
|
|
|
|
URLmsgBox.exec();
|
2025-03-02 04:58:32 +00:00
|
|
|
// For whatever reason, showing the message box hides this window.
|
2022-09-15 00:53:22 +00:00
|
|
|
this->show();
|
|
|
|
this->raise();
|
|
|
|
this->activateWindow();
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
2025-03-02 04:58:32 +00:00
|
|
|
qDebug(logLogger()) << tr("Error, return from logging host too large. Received ") << data.length() << tr(" bytes.");
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::disconnectedFromHost()
|
|
|
|
{
|
2025-03-02 04:58:32 +00:00
|
|
|
qInfo(logLogger()) << tr("Disconnected from logging host");
|
2022-09-15 00:07:23 +00:00
|
|
|
ui->sendToPasteBtn->setDisabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::connectedToHost()
|
|
|
|
{
|
2025-03-02 04:58:32 +00:00
|
|
|
qInfo(logLogger()) << tr("Connected to logging host");
|
2022-09-15 00:07:23 +00:00
|
|
|
QMutexLocker lock(&textMutex);
|
|
|
|
QTextStream outText(socket);
|
|
|
|
outText << ui->logTextDisplay->toPlainText();
|
|
|
|
outText << "\n----------\nSent from wfview version ";
|
|
|
|
outText << WFVIEW_VERSION << "\n----------\n";
|
2022-09-15 21:09:16 +00:00
|
|
|
outText.flush();
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::handleLoggingHostError(QAbstractSocket::SocketError error)
|
|
|
|
{
|
2022-09-15 00:53:22 +00:00
|
|
|
switch(error)
|
|
|
|
{
|
|
|
|
case QAbstractSocket::RemoteHostClosedError:
|
2022-09-15 21:13:14 +00:00
|
|
|
//qInfo(logLogger()) << "Disconnected from logging host.";
|
2022-09-15 00:53:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2025-03-02 04:58:32 +00:00
|
|
|
qWarning(logLogger()) << tr("Error connecting to logging host. Check internet connection. Error code: ") << error;
|
2022-12-28 03:37:12 +00:00
|
|
|
ui->sendToPasteBtn->setDisabled(false);
|
2022-09-15 00:53:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_clearDisplayBtn_clicked()
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&textMutex);
|
|
|
|
// Only clears the displayed text, not the log file.
|
|
|
|
ui->logTextDisplay->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_openDirBtn_clicked()
|
|
|
|
{
|
|
|
|
QString cmd;
|
2022-09-23 14:45:39 +00:00
|
|
|
bool rtn = false;
|
|
|
|
QStringList arg;
|
|
|
|
const QFileInfo dir(logDirectory);
|
|
|
|
|
2022-09-15 00:07:23 +00:00
|
|
|
#ifdef Q_OS_LINUX
|
2022-09-23 14:45:39 +00:00
|
|
|
cmd = "xdg-open";
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
cmd = QStandardPaths::findExecutable("explorer.exe");
|
|
|
|
if (!dir.isDir())
|
|
|
|
arg += QLatin1String("/select,");
|
|
|
|
#else
|
|
|
|
cmd = "open";
|
2022-09-15 00:07:23 +00:00
|
|
|
#endif
|
2022-09-23 14:45:39 +00:00
|
|
|
arg += QDir::toNativeSeparators(dir.canonicalFilePath());;
|
|
|
|
rtn = QProcess::startDetached(cmd, arg);
|
2022-09-23 15:49:32 +00:00
|
|
|
if(!rtn)
|
2022-09-23 14:45:39 +00:00
|
|
|
qInfo(logLogger()) << "Error, open log directory" << logDirectory << "command failed";
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_openLogFileBtn_clicked()
|
|
|
|
{
|
|
|
|
QString cmd;
|
2022-09-23 14:45:39 +00:00
|
|
|
bool rtn = false;
|
2022-09-15 00:07:23 +00:00
|
|
|
#ifdef Q_OS_LINUX
|
2022-09-23 14:45:39 +00:00
|
|
|
cmd = "xdg-open";
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
cmd = QStandardPaths::findExecutable("notepad.exe");
|
|
|
|
#else
|
|
|
|
cmd = "open";
|
2022-09-15 00:07:23 +00:00
|
|
|
#endif
|
2022-09-23 14:45:39 +00:00
|
|
|
rtn = QProcess::startDetached(cmd, { logFilename });
|
|
|
|
if(!rtn)
|
|
|
|
qInfo(logLogger()) << "Error, open log file command failed";
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_sendToPasteBtn_clicked()
|
|
|
|
{
|
2025-03-02 04:58:32 +00:00
|
|
|
sendLogToHost();
|
2022-09-15 00:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_annotateBtn_clicked()
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&textMutex);
|
|
|
|
if(ui->userAnnotationText->text().isEmpty())
|
|
|
|
return;
|
|
|
|
qInfo(logUser()) << ui->userAnnotationText->text();
|
|
|
|
ui->userAnnotationText->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_userAnnotationText_returnPressed()
|
|
|
|
{
|
|
|
|
on_annotateBtn_clicked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loggingWindow::on_copyPathBtn_clicked()
|
|
|
|
{
|
|
|
|
clipboard->setText(logFilename);
|
|
|
|
}
|
2022-09-15 16:42:19 +00:00
|
|
|
|
|
|
|
void loggingWindow::on_debugBtn_clicked(bool checked)
|
|
|
|
{
|
|
|
|
emit setDebugMode(checked);
|
|
|
|
}
|
2022-09-15 18:52:08 +00:00
|
|
|
|
2024-09-22 23:03:05 +00:00
|
|
|
void loggingWindow::on_commDebugChk_clicked(bool checked)
|
|
|
|
{
|
|
|
|
emit setInsaneLoggingMode(checked);
|
|
|
|
}
|
|
|
|
|
2024-12-29 14:59:52 +00:00
|
|
|
void loggingWindow::on_rigctlDebugChk_clicked(bool checked)
|
|
|
|
{
|
|
|
|
emit setRigctlLoggingMode(checked);
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:52:08 +00:00
|
|
|
void loggingWindow::on_toBottomBtn_clicked()
|
|
|
|
{
|
|
|
|
vertLogScroll->setValue(vertLogScroll->maximum());
|
|
|
|
horizLogScroll->setValue(horizLogScroll->minimum());
|
|
|
|
}
|