move log output into its own window; add some keyboard shortcuts for menu items

This commit is contained in:
walker0643 2018-02-25 20:00:32 -05:00
parent b55fe3237a
commit c351d450ae
7 changed files with 246 additions and 73 deletions

72
src/gui/src/LogWindow.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "LogWindow.h"
#include <QDateTime>
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();
}

46
src/gui/src/LogWindow.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#if !defined(LOGWINDOW__H)
#define LOGWINDOW__H
#include <QDialog>
#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

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LogWindowBase</class>
<widget class="QDialog" name="LogWindowBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>371</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Log - Barrier</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextEdit" name="m_pLogOutput">
<property name="font">
<font>
<family>Courier</family>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_pButtonClearLog">
<property name="text">
<string>&amp;Clear Log</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_pButtonHide">
<property name="text">
<string>&amp;Hide</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</ui>

View File

@ -93,7 +93,8 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) :
m_BonjourInstall(NULL), m_BonjourInstall(NULL),
m_SuppressEmptyServerWarning(false), m_SuppressEmptyServerWarning(false),
m_ExpectedRunningState(kStopped), m_ExpectedRunningState(kStopped),
m_pSslCertificate(NULL) m_pSslCertificate(NULL),
m_pLogWindow(new LogWindow(nullptr))
{ {
setupUi(this); setupUi(this);
@ -147,6 +148,13 @@ MainWindow::~MainWindow()
delete m_DownloadMessageBox; delete m_DownloadMessageBox;
delete m_BonjourInstall; delete m_BonjourInstall;
delete m_pSslCertificate; 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() void MainWindow::open()
@ -184,6 +192,7 @@ void MainWindow::createTrayIcon()
m_pTrayIconMenu->addAction(m_pActionStartBarrier); m_pTrayIconMenu->addAction(m_pActionStartBarrier);
m_pTrayIconMenu->addAction(m_pActionStopBarrier); m_pTrayIconMenu->addAction(m_pActionStopBarrier);
m_pTrayIconMenu->addAction(m_pActionShowLog);
m_pTrayIconMenu->addSeparator(); m_pTrayIconMenu->addSeparator();
m_pTrayIconMenu->addAction(m_pActionMinimize); m_pTrayIconMenu->addAction(m_pActionMinimize);
@ -219,10 +228,11 @@ void MainWindow::createMenuBar()
m_pMenuBar->addAction(m_pMenuBarrier->menuAction()); m_pMenuBar->addAction(m_pMenuBarrier->menuAction());
m_pMenuBar->addAction(m_pMenuHelp->menuAction()); m_pMenuBar->addAction(m_pMenuHelp->menuAction());
m_pMenuBarrier->addAction(m_pActionSave); m_pMenuBarrier->addAction(m_pActionShowLog);
m_pMenuBarrier->addSeparator();
m_pMenuBarrier->addAction(m_pActionSettings); m_pMenuBarrier->addAction(m_pActionSettings);
m_pMenuBarrier->addSeparator(); m_pMenuBarrier->addSeparator();
m_pMenuBarrier->addAction(m_pActionSave);
m_pMenuBarrier->addSeparator();
m_pMenuBarrier->addAction(m_pActionQuit); m_pMenuBarrier->addAction(m_pActionQuit);
m_pMenuHelp->addAction(m_pActionAbout); m_pMenuHelp->addAction(m_pActionAbout);
@ -248,6 +258,7 @@ void MainWindow::initConnections()
connect(m_pActionRestore, SIGNAL(triggered()), this, SLOT(showNormal())); connect(m_pActionRestore, SIGNAL(triggered()), this, SLOT(showNormal()));
connect(m_pActionStartBarrier, SIGNAL(triggered()), this, SLOT(startBarrier())); connect(m_pActionStartBarrier, SIGNAL(triggered()), this, SLOT(startBarrier()));
connect(m_pActionStopBarrier, SIGNAL(triggered()), this, SLOT(stopBarrier())); connect(m_pActionStopBarrier, SIGNAL(triggered()), this, SLOT(stopBarrier()));
connect(m_pActionShowLog, SIGNAL(triggered()), this, SLOT(showLogWindow()));
connect(m_pActionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); connect(m_pActionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));
} }
@ -314,25 +325,25 @@ void MainWindow::logError()
void MainWindow::appendLogInfo(const QString& text) void MainWindow::appendLogInfo(const QString& text)
{ {
appendLogRaw(getTimeStamp() + " INFO: " + text); m_pLogWindow->appendInfo(text);
} }
void MainWindow::appendLogDebug(const QString& text) { void MainWindow::appendLogDebug(const QString& text) {
if (appConfig().logLevel() >= 4) { if (appConfig().logLevel() >= 4) {
appendLogRaw(getTimeStamp() + " DEBUG: " + text); m_pLogWindow->appendDebug(text);
} }
} }
void MainWindow::appendLogError(const QString& text) void MainWindow::appendLogError(const QString& text)
{ {
appendLogRaw(getTimeStamp() + " ERROR: " + text); m_pLogWindow->appendError(text);
} }
void MainWindow::appendLogRaw(const QString& text) void MainWindow::appendLogRaw(const QString& text)
{ {
foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) { foreach(QString line, text.split(QRegExp("\r|\n|\r\n"))) {
if (!line.isEmpty()) { if (!line.isEmpty()) {
m_pLogOutput->append(line); m_pLogWindow->appendRaw(line);
updateFromLogLine(line); updateFromLogLine(line);
} }
} }
@ -350,7 +361,7 @@ void MainWindow::checkConnected(const QString& line)
// TODO: implement ipc connection state messages to replace this hack. // TODO: implement ipc connection state messages to replace this hack.
if (line.contains("started server") || if (line.contains("started server") ||
line.contains("connected to server") || line.contains("connected to server") ||
line.contains("watchdog status: ok")) line.contains("server status: active"))
{ {
setBarrierState(barrierConnected); 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() void MainWindow::restartBarrier()
{ {
stopBarrier(); stopBarrier();
@ -429,11 +434,6 @@ void MainWindow::proofreadInfo()
setBarrierState((qBarrierState)oldState); setBarrierState((qBarrierState)oldState);
} }
void MainWindow::clearLog()
{
m_pLogOutput->clear();
}
void MainWindow::startBarrier() void MainWindow::startBarrier()
{ {
bool desktopMode = appConfig().processMode() == Desktop; bool desktopMode = appConfig().processMode() == Desktop;
@ -510,9 +510,7 @@ void MainWindow::startBarrier()
connect(barrierProcess(), SIGNAL(readyReadStandardError()), this, SLOT(logError())); connect(barrierProcess(), SIGNAL(readyReadStandardError()), this, SLOT(logError()));
} }
// put a space between last log output and new instance. m_pLogWindow->startNewInstance();
if (!m_pLogOutput->toPlainText().isEmpty())
appendLogRaw("");
appendLogInfo("starting " + QString(barrierType() == barrierServer ? "server" : "client")); appendLogInfo("starting " + QString(barrierType() == barrierServer ? "server" : "client"));
@ -1264,3 +1262,8 @@ void MainWindow::windowStateChanged()
if (windowState() == Qt::WindowMinimized && appConfig().getMinimizeToTray()) if (windowState() == Qt::WindowMinimized && appConfig().getMinimizeToTray())
hide(); hide();
} }
void MainWindow::showLogWindow()
{
m_pLogWindow->show();
}

View File

@ -33,6 +33,7 @@
#include "VersionChecker.h" #include "VersionChecker.h"
#include "IpcClient.h" #include "IpcClient.h"
#include "Ipc.h" #include "Ipc.h"
#include "LogWindow.h"
#include <QMutex> #include <QMutex>
@ -104,7 +105,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
QString address(); QString address();
QString appPath(const QString& name); QString appPath(const QString& name);
void open(); void open();
void clearLog();
VersionChecker& versionChecker() { return m_VersionChecker; } VersionChecker& versionChecker() { return m_VersionChecker; }
QString getScreenName(); QString getScreenName();
ServerConfig& serverConfig() { return m_ServerConfig; } ServerConfig& serverConfig() { return m_ServerConfig; }
@ -135,6 +135,7 @@ public slots:
void logOutput(); void logOutput();
void logError(); void logError();
void bonjourInstallFinished(); void bonjourInstallFinished();
void showLogWindow();
protected: protected:
QSettings& settings() { return m_Settings; } QSettings& settings() { return m_Settings; }
@ -168,7 +169,6 @@ public slots:
QString getProfileRootForArg(); QString getProfileRootForArg();
void checkConnected(const QString& line); void checkConnected(const QString& line);
void checkFingerprint(const QString& line); void checkFingerprint(const QString& line);
QString getTimeStamp();
void restartBarrier(); void restartBarrier();
void proofreadInfo(); void proofreadInfo();
void windowStateChanged(); void windowStateChanged();
@ -201,6 +201,7 @@ public slots:
QMutex m_StopDesktopMutex; QMutex m_StopDesktopMutex;
SslCertificate* m_pSslCertificate; SslCertificate* m_pSslCertificate;
QStringList m_PendingClientNames; QStringList m_PendingClientNames;
LogWindow *m_pLogWindow;
private slots: private slots:
void on_m_pCheckBoxAutoConfig_toggled(bool checked); void on_m_pCheckBoxAutoConfig_toggled(bool checked);

View File

@ -239,42 +239,6 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="m_pGroupLog">
<property name="title">
<string>Log</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="m_pLogOutput">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier</family>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint"> <property name="sizeConstraint">
@ -378,14 +342,6 @@
<string notr="true">Ctrl+T</string> <string notr="true">Ctrl+T</string>
</property> </property>
</action> </action>
<action name="actionShowStatus">
<property name="text">
<string>S&amp;how Status</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+H</string>
</property>
</action>
<action name="m_pActionMinimize"> <action name="m_pActionMinimize">
<property name="text"> <property name="text">
<string>&amp;Hide</string> <string>&amp;Hide</string>
@ -410,7 +366,7 @@
</action> </action>
<action name="m_pActionSave"> <action name="m_pActionSave">
<property name="text"> <property name="text">
<string>Save configuration &amp;as...</string> <string>S&amp;ave configuration</string>
</property> </property>
<property name="statusTip"> <property name="statusTip">
<string>Save the interactively generated server configuration to a file.</string> <string>Save the interactively generated server configuration to a file.</string>
@ -421,13 +377,24 @@
</action> </action>
<action name="m_pActionSettings"> <action name="m_pActionSettings">
<property name="text"> <property name="text">
<string>Settings</string> <string>Change &amp;Settings</string>
</property> </property>
<property name="statusTip"> <property name="statusTip">
<string>Edit settings</string> <string>Edit settings</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string notr="true"/> <string notr="true">F4</string>
</property>
</action>
<action name="m_pActionShowLog">
<property name="text">
<string>Show &amp;Log</string>
</property>
<property name="toolTip">
<string>Show Log</string>
</property>
<property name="shortcut">
<string notr="true">F2</string>
</property> </property>
</action> </action>
</widget> </widget>

View File

@ -84,9 +84,7 @@ int main(int argc, char* argv[])
return -1; return -1;
} }
#ifndef Q_OS_WIN
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
#endif
QSettings settings; QSettings settings;
AppConfig appConfig (&settings); AppConfig appConfig (&settings);