diff --git a/src/gui/src/LogWindow.cpp b/src/gui/src/LogWindow.cpp new file mode 100644 index 00000000..6aee096a --- /dev/null +++ b/src/gui/src/LogWindow.cpp @@ -0,0 +1,72 @@ +/* +* barrier -- mouse and keyboard sharing utility +* Copyright (C) 2018 Debauchee Open Source Group +* +* This package is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* found in the file LICENSE that should have accompanied this file. +* +* This package 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 . +*/ + +#include "LogWindow.h" + +#include + +static QString getTimeStamp() +{ + QDateTime current = QDateTime::currentDateTime(); + return '[' + current.toString(Qt::ISODate) + ']'; +} + +LogWindow::LogWindow(QWidget *parent) : + QDialog(parent) +{ + // explicitly unset DeleteOnClose so the log window can be show and hidden + // repeatedly until Barrier is finished + setAttribute(Qt::WA_DeleteOnClose, false); + setupUi(this); +} + +void LogWindow::startNewInstance() +{ + // put a space between last log output and new instance. + if (!m_pLogOutput->toPlainText().isEmpty()) + appendRaw(""); +} + +void LogWindow::appendInfo(const QString& text) +{ + appendRaw(getTimeStamp() + " INFO: " + text); +} + +void LogWindow::appendDebug(const QString& text) +{ + appendRaw(getTimeStamp() + " DEBUG: " + text); +} + +void LogWindow::appendError(const QString& text) +{ + appendRaw(getTimeStamp() + " ERROR: " + text); +} + +void LogWindow::appendRaw(const QString& text) +{ + m_pLogOutput->append(text); +} + +void LogWindow::on_m_pButtonHide_clicked() +{ + hide(); +} + +void LogWindow::on_m_pButtonClearLog_clicked() +{ + m_pLogOutput->clear(); +} diff --git a/src/gui/src/LogWindow.h b/src/gui/src/LogWindow.h new file mode 100644 index 00000000..af230307 --- /dev/null +++ b/src/gui/src/LogWindow.h @@ -0,0 +1,46 @@ +/* + * barrier -- mouse and keyboard sharing utility + * Copyright (C) 2018 Debauchee Open Source Group + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package 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 . + */ + +#if !defined(LOGWINDOW__H) + +#define LOGWINDOW__H + +#include + +#include "ui_LogWindowBase.h" + +class LogWindow : public QDialog, public Ui::LogWindowBase +{ + Q_OBJECT + + public: + LogWindow(QWidget *parent); + + void startNewInstance(); + + void appendRaw(const QString& text); + void appendInfo(const QString& text); + void appendDebug(const QString& text); + void appendError(const QString& text); + + private slots: + void on_m_pButtonHide_clicked(); + void on_m_pButtonClearLog_clicked(); + +}; + +#endif // LOGWINDOW__H diff --git a/src/gui/src/LogWindowBase.ui b/src/gui/src/LogWindowBase.ui new file mode 100644 index 00000000..c7272a70 --- /dev/null +++ b/src/gui/src/LogWindowBase.ui @@ -0,0 +1,86 @@ + + + LogWindowBase + + + + 0 + 0 + 600 + 371 + + + + + 0 + 0 + + + + + 400 + 0 + + + + Log - Barrier + + + + + + + Courier + + + + false + + + false + + + QTextEdit::NoWrap + + + true + + + + + + + QLayout::SetDefaultConstraint + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Clear Log + + + + + + + &Hide + + + + + + + + diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 2f2decda..59b1d556 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -93,7 +93,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : m_BonjourInstall(NULL), m_SuppressEmptyServerWarning(false), m_ExpectedRunningState(kStopped), - m_pSslCertificate(NULL) + m_pSslCertificate(NULL), + m_pLogWindow(new LogWindow(nullptr)) { setupUi(this); @@ -147,6 +148,13 @@ MainWindow::~MainWindow() delete m_DownloadMessageBox; delete m_BonjourInstall; delete m_pSslCertificate; + + // LogWindow is created as a sibling of the MainWindow rather than a child + // so that the main window can be hidden without hiding the log. because of + // this it does not get properly cleaned up by the QObject system. also by + // the time this destructor is called the event loop will no longer be able + // to clean up the LogWindow so ->deleteLater() will not work + delete m_pLogWindow; } void MainWindow::open() @@ -184,6 +192,7 @@ void MainWindow::createTrayIcon() m_pTrayIconMenu->addAction(m_pActionStartBarrier); m_pTrayIconMenu->addAction(m_pActionStopBarrier); + m_pTrayIconMenu->addAction(m_pActionShowLog); m_pTrayIconMenu->addSeparator(); m_pTrayIconMenu->addAction(m_pActionMinimize); @@ -219,10 +228,11 @@ void MainWindow::createMenuBar() m_pMenuBar->addAction(m_pMenuBarrier->menuAction()); m_pMenuBar->addAction(m_pMenuHelp->menuAction()); - m_pMenuBarrier->addAction(m_pActionSave); - m_pMenuBarrier->addSeparator(); + m_pMenuBarrier->addAction(m_pActionShowLog); m_pMenuBarrier->addAction(m_pActionSettings); m_pMenuBarrier->addSeparator(); + m_pMenuBarrier->addAction(m_pActionSave); + m_pMenuBarrier->addSeparator(); m_pMenuBarrier->addAction(m_pActionQuit); m_pMenuHelp->addAction(m_pActionAbout); @@ -248,6 +258,7 @@ void MainWindow::initConnections() connect(m_pActionRestore, SIGNAL(triggered()), this, SLOT(showNormal())); connect(m_pActionStartBarrier, SIGNAL(triggered()), this, SLOT(startBarrier())); connect(m_pActionStopBarrier, SIGNAL(triggered()), this, SLOT(stopBarrier())); + connect(m_pActionShowLog, SIGNAL(triggered()), this, SLOT(showLogWindow())); connect(m_pActionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); } @@ -314,25 +325,25 @@ void MainWindow::logError() void MainWindow::appendLogInfo(const QString& text) { - appendLogRaw(getTimeStamp() + " INFO: " + text); + m_pLogWindow->appendInfo(text); } void MainWindow::appendLogDebug(const QString& text) { if (appConfig().logLevel() >= 4) { - appendLogRaw(getTimeStamp() + " DEBUG: " + text); + m_pLogWindow->appendDebug(text); } } void MainWindow::appendLogError(const QString& text) { - appendLogRaw(getTimeStamp() + " ERROR: " + text); + m_pLogWindow->appendError(text); } void MainWindow::appendLogRaw(const QString& text) { foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) { if (!line.isEmpty()) { - m_pLogOutput->append(line); + m_pLogWindow->appendRaw(line); updateFromLogLine(line); } } @@ -350,7 +361,7 @@ void MainWindow::checkConnected(const QString& line) // TODO: implement ipc connection state messages to replace this hack. if (line.contains("started server") || line.contains("connected to server") || - line.contains("watchdog status: ok")) + line.contains("server status: active")) { setBarrierState(barrierConnected); @@ -410,12 +421,6 @@ void MainWindow::checkFingerprint(const QString& line) } } -QString MainWindow::getTimeStamp() -{ - QDateTime current = QDateTime::currentDateTime(); - return '[' + current.toString(Qt::ISODate) + ']'; -} - void MainWindow::restartBarrier() { stopBarrier(); @@ -429,11 +434,6 @@ void MainWindow::proofreadInfo() setBarrierState((qBarrierState)oldState); } -void MainWindow::clearLog() -{ - m_pLogOutput->clear(); -} - void MainWindow::startBarrier() { bool desktopMode = appConfig().processMode() == Desktop; @@ -510,9 +510,7 @@ void MainWindow::startBarrier() connect(barrierProcess(), SIGNAL(readyReadStandardError()), this, SLOT(logError())); } - // put a space between last log output and new instance. - if (!m_pLogOutput->toPlainText().isEmpty()) - appendLogRaw(""); + m_pLogWindow->startNewInstance(); appendLogInfo("starting " + QString(barrierType() == barrierServer ? "server" : "client")); @@ -1264,3 +1262,8 @@ void MainWindow::windowStateChanged() if (windowState() == Qt::WindowMinimized && appConfig().getMinimizeToTray()) hide(); } + +void MainWindow::showLogWindow() +{ + m_pLogWindow->show(); +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index a85ca32b..27b30d11 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -33,6 +33,7 @@ #include "VersionChecker.h" #include "IpcClient.h" #include "Ipc.h" +#include "LogWindow.h" #include @@ -104,7 +105,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase QString address(); QString appPath(const QString& name); void open(); - void clearLog(); VersionChecker& versionChecker() { return m_VersionChecker; } QString getScreenName(); ServerConfig& serverConfig() { return m_ServerConfig; } @@ -135,6 +135,7 @@ public slots: void logOutput(); void logError(); void bonjourInstallFinished(); + void showLogWindow(); protected: QSettings& settings() { return m_Settings; } @@ -168,7 +169,6 @@ public slots: QString getProfileRootForArg(); void checkConnected(const QString& line); void checkFingerprint(const QString& line); - QString getTimeStamp(); void restartBarrier(); void proofreadInfo(); void windowStateChanged(); @@ -201,6 +201,7 @@ public slots: QMutex m_StopDesktopMutex; SslCertificate* m_pSslCertificate; QStringList m_PendingClientNames; + LogWindow *m_pLogWindow; private slots: void on_m_pCheckBoxAutoConfig_toggled(bool checked); diff --git a/src/gui/src/MainWindowBase.ui b/src/gui/src/MainWindowBase.ui index eb9b7ef9..e478339a 100644 --- a/src/gui/src/MainWindowBase.ui +++ b/src/gui/src/MainWindowBase.ui @@ -239,42 +239,6 @@ - - - - Log - - - - - - - 0 - 0 - - - - - Courier - - - - false - - - false - - - QTextEdit::NoWrap - - - true - - - - - - @@ -378,14 +342,6 @@ Ctrl+T - - - S&how Status - - - Ctrl+H - - &Hide @@ -410,7 +366,7 @@ - Save configuration &as... + S&ave configuration Save the interactively generated server configuration to a file. @@ -421,13 +377,24 @@ - Settings + Change &Settings Edit settings - + F4 + + + + + Show &Log + + + Show Log + + + F2 diff --git a/src/gui/src/main.cpp b/src/gui/src/main.cpp index 2433e9f0..1dbd53ab 100644 --- a/src/gui/src/main.cpp +++ b/src/gui/src/main.cpp @@ -84,9 +84,7 @@ int main(int argc, char* argv[]) return -1; } -#ifndef Q_OS_WIN QApplication::setQuitOnLastWindowClosed(false); -#endif QSettings settings; AppConfig appConfig (&settings);