From 8b688548c20aaad0916712be616bc75bb239741a Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Wed, 14 Sep 2022 17:53:22 -0700 Subject: [PATCH] Keep the logging window up after the message box. Added "log" logging category. --- logcategories.cpp | 1 + logcategories.h | 1 + loggingwindow.cpp | 31 ++++++++++++++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/logcategories.cpp b/logcategories.cpp index 3b9e0cd..c5a7bdc 100644 --- a/logcategories.cpp +++ b/logcategories.cpp @@ -3,6 +3,7 @@ Q_LOGGING_CATEGORY(logSystem, "system") Q_LOGGING_CATEGORY(logSerial, "serial") Q_LOGGING_CATEGORY(logGui, "gui") +Q_LOGGING_CATEGORY(logLogger, "log") Q_LOGGING_CATEGORY(logUser, "user") Q_LOGGING_CATEGORY(logRig, "rig") Q_LOGGING_CATEGORY(logAudio, "audio") diff --git a/logcategories.h b/logcategories.h index 82cca61..3fbfae3 100644 --- a/logcategories.h +++ b/logcategories.h @@ -6,6 +6,7 @@ Q_DECLARE_LOGGING_CATEGORY(logSystem) Q_DECLARE_LOGGING_CATEGORY(logSerial) Q_DECLARE_LOGGING_CATEGORY(logGui) +Q_DECLARE_LOGGING_CATEGORY(logLogger) Q_DECLARE_LOGGING_CATEGORY(logUser) Q_DECLARE_LOGGING_CATEGORY(logRig) Q_DECLARE_LOGGING_CATEGORY(logAudio) diff --git a/loggingwindow.cpp b/loggingwindow.cpp index 9903d1b..10eeea3 100644 --- a/loggingwindow.cpp +++ b/loggingwindow.cpp @@ -6,6 +6,7 @@ loggingWindow::loggingWindow(QWidget *parent) : ui(new Ui::loggingWindow) { ui->setupUi(this); + this->setWindowTitle("Log"); ui->logTextDisplay->setReadOnly(true); ui->userAnnotationText->setFocus(); ui->annotateBtn->setDefault(true); @@ -25,7 +26,6 @@ loggingWindow::loggingWindow(QWidget *parent) : connect(socket, SIGNAL(connected()), this, SLOT(connectedToHost())); connect(socket, SIGNAL(disconnected()), this, SLOT(disconnectedFromHost())); connect(socket, SIGNAL(readyRead()), this, SLOT(handleDataFromLoggingHost())); - connect(socket, SIGNAL(hostFound()), this, SLOT(handleLoggingHostError())); connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(handleLoggingHostError(QAbstractSocket::SocketError))); } @@ -43,14 +43,14 @@ void loggingWindow::acceptLogText(QString text) void loggingWindow::sendToTermbin() { - qInfo(logGui()) << "Sending data to termbin.com. Standby."; + qInfo(logLogger()) << "Sending data to termbin.com. Standby."; socket->connectToHost("termbin.com", 9999); ui->sendToPasteBtn->setDisabled(true); } void loggingWindow::handleDataFromLoggingHost() { - qInfo(logGui()) << "Receiving data from logging host."; + qInfo(logLogger()) << "Receiving data from logging host."; QString URL; QByteArray data = socket->readAll(); if(data.length() < 256) @@ -59,25 +59,29 @@ void loggingWindow::handleDataFromLoggingHost() if(!URL.isEmpty()) { clipboard->setText(URL); - qInfo(logGui()) << "Sent log to URL: " << URL; + qInfo(logLogger()) << "Sent log to URL: " << URL; msgBox.setText("Your log has been posted, and the URL has been copied to the clipboard."); - msgBox.setInformativeText(URL); + msgBox.setInformativeText("" + URL + ""); msgBox.exec(); + // For whatever reason, showing the message box hides this window. + this->show(); + this->raise(); + this->activateWindow(); } } else { - qDebug(logGui()) << "Error, return from logging host too large. Received " << data.length() << " bytes."; + qDebug(logLogger()) << "Error, return from logging host too large. Received " << data.length() << " bytes."; } } void loggingWindow::disconnectedFromHost() { - qInfo(logGui()) << "Disconnected from logging host"; + qInfo(logLogger()) << "Disconnected from logging host"; ui->sendToPasteBtn->setDisabled(false); } void loggingWindow::connectedToHost() { - qInfo(logGui()) << "Connected to logging host"; + qInfo(logLogger()) << "Connected to logging host"; QMutexLocker lock(&textMutex); QTextStream outText(socket); outText << ui->logTextDisplay->toPlainText(); @@ -87,7 +91,16 @@ void loggingWindow::connectedToHost() void loggingWindow::handleLoggingHostError(QAbstractSocket::SocketError error) { - qInfo(logGui()) << "Error connecting to logging host. Check internet connection. Error code: " << error; + switch(error) + { + case QAbstractSocket::RemoteHostClosedError: + qInfo(logLogger()) << "Disconnected from logging host."; + break; + + default: + qInfo(logLogger()) << "Error connecting to logging host. Check internet connection. Error code: " << error; + break; + } } void loggingWindow::on_clearDisplayBtn_clicked()