mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-03 14:04:19 +08:00
Added menu item on win32 tray icon to copy the last 1000 lines from
the log to the clipboard.
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "CMSWindowsClientTaskBarReceiver.h"
|
||||
#include "CClient.h"
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "LogOutputters.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "CArch.h"
|
||||
#include "CArchTaskBarWindows.h"
|
||||
@@ -32,10 +34,11 @@ static const UINT g_stateToIconID[CMSWindowsClientTaskBarReceiver::kMaxState] =
|
||||
//
|
||||
|
||||
CMSWindowsClientTaskBarReceiver::CMSWindowsClientTaskBarReceiver(
|
||||
HINSTANCE appInstance) :
|
||||
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer) :
|
||||
CClientTaskBarReceiver(),
|
||||
m_appInstance(appInstance),
|
||||
m_window(NULL)
|
||||
m_window(NULL),
|
||||
m_logBuffer(logBuffer)
|
||||
{
|
||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||
m_icon[i] = loadIcon(g_stateToIconID[i]);
|
||||
@@ -149,6 +152,10 @@ CMSWindowsClientTaskBarReceiver::runMenu(int x, int y)
|
||||
showStatus();
|
||||
break;
|
||||
|
||||
case IDC_TASKBAR_LOG:
|
||||
copyLog();
|
||||
break;
|
||||
|
||||
case IDC_TASKBAR_QUIT:
|
||||
quit();
|
||||
break;
|
||||
@@ -167,6 +174,29 @@ CMSWindowsClientTaskBarReceiver::getIcon() const
|
||||
return reinterpret_cast<Icon>(m_icon[getState()]);
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsClientTaskBarReceiver::copyLog() const
|
||||
{
|
||||
if (m_logBuffer != NULL) {
|
||||
// collect log buffer
|
||||
CString data;
|
||||
for (CBufferedLogOutputter::const_iterator index = m_logBuffer->begin();
|
||||
index != m_logBuffer->end(); ++index) {
|
||||
data += *index;
|
||||
data += "\n";
|
||||
}
|
||||
|
||||
// copy log to clipboard
|
||||
if (!data.empty()) {
|
||||
CMSWindowsClipboard clipboard(m_window);
|
||||
clipboard.open(0);
|
||||
clipboard.empty();
|
||||
clipboard.add(IClipboard::kText, data);
|
||||
clipboard.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsClientTaskBarReceiver::onStatusChanged()
|
||||
{
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
#include "CClientTaskBarReceiver.h"
|
||||
#include <windows.h>
|
||||
|
||||
class CBufferedLogOutputter;
|
||||
|
||||
//! Implementation of CClientTaskBarReceiver for Microsoft Windows
|
||||
class CMSWindowsClientTaskBarReceiver : public CClientTaskBarReceiver {
|
||||
public:
|
||||
CMSWindowsClientTaskBarReceiver(HINSTANCE);
|
||||
CMSWindowsClientTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*);
|
||||
virtual ~CMSWindowsClientTaskBarReceiver();
|
||||
|
||||
// IArchTaskBarReceiver overrides
|
||||
@@ -33,6 +35,8 @@ public:
|
||||
virtual const Icon getIcon() const;
|
||||
|
||||
protected:
|
||||
void copyLog() const;
|
||||
|
||||
// CClientTaskBarReceiver overrides
|
||||
virtual void onStatusChanged();
|
||||
|
||||
@@ -53,6 +57,7 @@ private:
|
||||
HWND m_window;
|
||||
HMENU m_menu;
|
||||
HICON m_icon[kMaxState];
|
||||
const CBufferedLogOutputter* m_logBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define IDC_TASKBAR_STATUS_STATUS 1000
|
||||
#define IDC_TASKBAR_QUIT 40003
|
||||
#define IDC_TASKBAR_STATUS 40004
|
||||
#define IDC_TASKBAR_LOG 40005
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
|
||||
@@ -649,9 +649,14 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
// send PRINT and FATAL output to a message box
|
||||
CLOG->insert(new CMessageBoxOutputter);
|
||||
|
||||
// save log messages
|
||||
CBufferedLogOutputter logBuffer(1000);
|
||||
CLOG->insert(&logBuffer, true);
|
||||
|
||||
// make the task bar receiver. the user can control this app
|
||||
// through the task bar.
|
||||
s_taskBarReceiver = new CMSWindowsClientTaskBarReceiver(instance);
|
||||
s_taskBarReceiver = new CMSWindowsClientTaskBarReceiver(instance,
|
||||
&logBuffer);
|
||||
s_taskBarReceiver->setQuitJob(new CQuitJob(CThread::getCurrentThread()));
|
||||
|
||||
int result;
|
||||
@@ -670,6 +675,9 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
// done with task bar receiver
|
||||
delete s_taskBarReceiver;
|
||||
|
||||
// done with log buffer
|
||||
CLOG->remove(&logBuffer);
|
||||
|
||||
// let user examine any messages if we're running as a backend
|
||||
// by putting up a dialog box before exiting.
|
||||
if (ARG->m_backend && s_hasImportantLogMessages) {
|
||||
|
||||
@@ -84,6 +84,7 @@ BEGIN
|
||||
POPUP "Synergy"
|
||||
BEGIN
|
||||
MENUITEM "Show Status", IDC_TASKBAR_STATUS
|
||||
MENUITEM "Copy Log To Clipboard", IDC_TASKBAR_LOG
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Quit", IDC_TASKBAR_QUIT
|
||||
END
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "CMSWindowsServerTaskBarReceiver.h"
|
||||
#include "CServer.h"
|
||||
#include "CMSWindowsClipboard.h"
|
||||
#include "LogOutputters.h"
|
||||
#include "BasicTypes.h"
|
||||
#include "CArch.h"
|
||||
#include "CArchTaskBarWindows.h"
|
||||
@@ -32,10 +34,11 @@ static const UINT g_stateToIconID[CMSWindowsServerTaskBarReceiver::kMaxState] =
|
||||
//
|
||||
|
||||
CMSWindowsServerTaskBarReceiver::CMSWindowsServerTaskBarReceiver(
|
||||
HINSTANCE appInstance) :
|
||||
HINSTANCE appInstance, const CBufferedLogOutputter* logBuffer) :
|
||||
CServerTaskBarReceiver(),
|
||||
m_appInstance(appInstance),
|
||||
m_window(NULL)
|
||||
m_window(NULL),
|
||||
m_logBuffer(logBuffer)
|
||||
{
|
||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||
m_icon[i] = loadIcon(g_stateToIconID[i]);
|
||||
@@ -169,6 +172,10 @@ CMSWindowsServerTaskBarReceiver::runMenu(int x, int y)
|
||||
showStatus();
|
||||
break;
|
||||
|
||||
case IDC_TASKBAR_LOG:
|
||||
copyLog();
|
||||
break;
|
||||
|
||||
case IDC_TASKBAR_QUIT:
|
||||
quit();
|
||||
break;
|
||||
@@ -187,6 +194,29 @@ CMSWindowsServerTaskBarReceiver::getIcon() const
|
||||
return reinterpret_cast<Icon>(m_icon[getState()]);
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsServerTaskBarReceiver::copyLog() const
|
||||
{
|
||||
if (m_logBuffer != NULL) {
|
||||
// collect log buffer
|
||||
CString data;
|
||||
for (CBufferedLogOutputter::const_iterator index = m_logBuffer->begin();
|
||||
index != m_logBuffer->end(); ++index) {
|
||||
data += *index;
|
||||
data += "\n";
|
||||
}
|
||||
|
||||
// copy log to clipboard
|
||||
if (!data.empty()) {
|
||||
CMSWindowsClipboard clipboard(m_window);
|
||||
clipboard.open(0);
|
||||
clipboard.empty();
|
||||
clipboard.add(IClipboard::kText, data);
|
||||
clipboard.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CMSWindowsServerTaskBarReceiver::onStatusChanged()
|
||||
{
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
#include "CServerTaskBarReceiver.h"
|
||||
#include <windows.h>
|
||||
|
||||
class CBufferedLogOutputter;
|
||||
|
||||
//! Implementation of CServerTaskBarReceiver for Microsoft Windows
|
||||
class CMSWindowsServerTaskBarReceiver : public CServerTaskBarReceiver {
|
||||
public:
|
||||
CMSWindowsServerTaskBarReceiver(HINSTANCE);
|
||||
CMSWindowsServerTaskBarReceiver(HINSTANCE, const CBufferedLogOutputter*);
|
||||
virtual ~CMSWindowsServerTaskBarReceiver();
|
||||
|
||||
// IArchTaskBarReceiver overrides
|
||||
@@ -33,6 +35,8 @@ public:
|
||||
virtual const Icon getIcon() const;
|
||||
|
||||
protected:
|
||||
void copyLog() const;
|
||||
|
||||
// CServerTaskBarReceiver overrides
|
||||
virtual void onStatusChanged();
|
||||
|
||||
@@ -53,6 +57,7 @@ private:
|
||||
HWND m_window;
|
||||
HMENU m_menu;
|
||||
HICON m_icon[kMaxState];
|
||||
const CBufferedLogOutputter* m_logBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
#define IDC_TASKBAR_STATUS_CLIENTS 1001
|
||||
#define IDC_TASKBAR_QUIT 40003
|
||||
#define IDC_TASKBAR_STATUS 40004
|
||||
#define IDC_TASKBAR_LOG 40005
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 109
|
||||
#define _APS_NEXT_COMMAND_VALUE 40005
|
||||
#define _APS_NEXT_COMMAND_VALUE 40006
|
||||
#define _APS_NEXT_CONTROL_VALUE 1003
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
|
||||
@@ -782,9 +782,14 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
// send PRINT and FATAL output to a message box
|
||||
CLOG->insert(new CMessageBoxOutputter);
|
||||
|
||||
// save log messages
|
||||
CBufferedLogOutputter logBuffer(1000);
|
||||
CLOG->insert(&logBuffer, true);
|
||||
|
||||
// make the task bar receiver. the user can control this app
|
||||
// through the task bar.
|
||||
s_taskBarReceiver = new CMSWindowsServerTaskBarReceiver(instance);
|
||||
s_taskBarReceiver = new CMSWindowsServerTaskBarReceiver(instance,
|
||||
&logBuffer);
|
||||
s_taskBarReceiver->setQuitJob(new CQuitJob(CThread::getCurrentThread()));
|
||||
|
||||
int result;
|
||||
@@ -803,6 +808,9 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int)
|
||||
// done with task bar receiver
|
||||
delete s_taskBarReceiver;
|
||||
|
||||
// done with log buffer
|
||||
CLOG->remove(&logBuffer);
|
||||
|
||||
// let user examine any messages if we're running as a backend
|
||||
// by putting up a dialog box before exiting.
|
||||
if (ARG->m_backend && s_hasImportantLogMessages) {
|
||||
|
||||
@@ -70,6 +70,7 @@ BEGIN
|
||||
POPUP "Synergy"
|
||||
BEGIN
|
||||
MENUITEM "Show Status", IDC_TASKBAR_STATUS
|
||||
MENUITEM "Copy Log To Clipboard", IDC_TASKBAR_LOG
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "Quit", IDC_TASKBAR_QUIT
|
||||
END
|
||||
|
||||
Reference in New Issue
Block a user