chore: Adjust Clang-format linter rules
120 Column Lines Block Indent for Bracket Align Custom Line Break Rules No Single Line Functions
This commit is contained in:
@ -13,16 +13,40 @@ BasedOnStyle: LLVM
|
|||||||
# Turn off LLVM default alignment of params with the opening bracket,
|
# Turn off LLVM default alignment of params with the opening bracket,
|
||||||
# which can be less readable in some cases in our code base.
|
# which can be less readable in some cases in our code base.
|
||||||
#
|
#
|
||||||
# Using `AlwaysBreak` will result in:
|
# Using `BlockIndent` will result in:
|
||||||
# void fooBarBazQuxHelloWorld(
|
# void fooBarBazQuxHelloWorld(
|
||||||
# int a,
|
# int a,
|
||||||
# int b);
|
# int b
|
||||||
|
# );
|
||||||
#
|
#
|
||||||
# Instead of:
|
# Instead of:
|
||||||
# void fooBarBazQuxHelloWorld(int a,
|
# void fooBarBazQuxHelloWorld(int a,
|
||||||
# int b);
|
# int b);
|
||||||
AlignAfterOpenBracket: AlwaysBreak
|
AlignAfterOpenBracket: BlockIndent
|
||||||
|
|
||||||
# Turn off LLVM default packing of ctor initializers.
|
# Turn off LLVM default packing of ctor initializers.
|
||||||
# This makes it easier to see which members were initialized and in what order.
|
# This makes it easier to see which members were initialized and in what order.
|
||||||
PackConstructorInitializers: CurrentLine
|
PackConstructorInitializers: CurrentLine
|
||||||
|
|
||||||
|
# up our limit to 120
|
||||||
|
ColumnLimit: 120
|
||||||
|
|
||||||
|
# Custom Breaking rules
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: true
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
AfterExternBlock: true
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
|
||||||
|
# no single line functions
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
|||||||
@ -26,27 +26,26 @@
|
|||||||
#include "arch/win32/ArchMiscWindows.h"
|
#include "arch/win32/ArchMiscWindows.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void showHelp() {
|
void showHelp()
|
||||||
std::cout << "Usage: " CORE_BINARY_NAME " <server | client> [...options]"
|
{
|
||||||
<< std::endl;
|
std::cout << "Usage: " CORE_BINARY_NAME " <server | client> [...options]" << std::endl;
|
||||||
std::cout << "server - start as a server (" << SERVER_BINARY_NAME << ")"
|
std::cout << "server - start as a server (" << SERVER_BINARY_NAME << ")" << std::endl;
|
||||||
<< std::endl;
|
std::cout << "client - start as a client (" << CLIENT_BINARY_NAME << ")" << std::endl;
|
||||||
std::cout << "client - start as a client (" << CLIENT_BINARY_NAME << ")"
|
std::cout << "use " CORE_BINARY_NAME " <server|client> --help for more information." << std::endl;
|
||||||
<< std::endl;
|
|
||||||
std::cout << "use " CORE_BINARY_NAME
|
|
||||||
" <server|client> --help for more information."
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isServer(int argc, char **argv) {
|
bool isServer(int argc, char **argv)
|
||||||
|
{
|
||||||
return (argc > 1 && argv[1] == std::string("server"));
|
return (argc > 1 && argv[1] == std::string("server"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isClient(int argc, char **argv) {
|
bool isClient(int argc, char **argv)
|
||||||
|
{
|
||||||
return (argc > 1 && argv[1] == std::string("client"));
|
return (argc > 1 && argv[1] == std::string("client"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -22,7 +22,8 @@
|
|||||||
#include "arch/win32/ArchMiscWindows.h"
|
#include "arch/win32/ArchMiscWindows.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
// record window instance for tray icon, etc
|
// record window instance for tray icon, etc
|
||||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||||
|
|||||||
@ -34,16 +34,18 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
const UINT MSWindowsClientTaskBarReceiver::s_stateToIconID[kMaxState] = {
|
const UINT MSWindowsClientTaskBarReceiver::s_stateToIconID[kMaxState] = {
|
||||||
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED,
|
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED, IDI_TASKBAR_NOT_CONNECTED,
|
||||||
IDI_TASKBAR_NOT_CONNECTED, IDI_TASKBAR_CONNECTED};
|
IDI_TASKBAR_CONNECTED
|
||||||
|
};
|
||||||
|
|
||||||
MSWindowsClientTaskBarReceiver::MSWindowsClientTaskBarReceiver(
|
MSWindowsClientTaskBarReceiver::MSWindowsClientTaskBarReceiver(
|
||||||
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer,
|
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer, IEventQueue *events
|
||||||
IEventQueue *events)
|
)
|
||||||
: ClientTaskBarReceiver(events),
|
: ClientTaskBarReceiver(events),
|
||||||
m_appInstance(appInstance),
|
m_appInstance(appInstance),
|
||||||
m_window(NULL),
|
m_window(NULL),
|
||||||
m_logBuffer(logBuffer) {
|
m_logBuffer(logBuffer)
|
||||||
|
{
|
||||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||||
m_icon[i] = loadIcon(s_stateToIconID[i]);
|
m_icon[i] = loadIcon(s_stateToIconID[i]);
|
||||||
}
|
}
|
||||||
@ -58,9 +60,13 @@ MSWindowsClientTaskBarReceiver::MSWindowsClientTaskBarReceiver(
|
|||||||
ARCH->addReceiver(this);
|
ARCH->addReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MSWindowsClientTaskBarReceiver::~MSWindowsClientTaskBarReceiver() { cleanup(); }
|
MSWindowsClientTaskBarReceiver::~MSWindowsClientTaskBarReceiver()
|
||||||
|
{
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::cleanup() {
|
void MSWindowsClientTaskBarReceiver::cleanup()
|
||||||
|
{
|
||||||
ARCH->removeReceiver(this);
|
ARCH->removeReceiver(this);
|
||||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||||
deleteIcon(m_icon[i]);
|
deleteIcon(m_icon[i]);
|
||||||
@ -69,7 +75,8 @@ void MSWindowsClientTaskBarReceiver::cleanup() {
|
|||||||
destroyWindow();
|
destroyWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::showStatus() {
|
void MSWindowsClientTaskBarReceiver::showStatus()
|
||||||
|
{
|
||||||
// create the window
|
// create the window
|
||||||
createWindow();
|
createWindow();
|
||||||
|
|
||||||
@ -126,7 +133,8 @@ void MSWindowsClientTaskBarReceiver::showStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::runMenu(int x, int y) {
|
void MSWindowsClientTaskBarReceiver::runMenu(int x, int y)
|
||||||
|
{
|
||||||
// do popup menu. we need a window to pass to TrackPopupMenu().
|
// do popup menu. we need a window to pass to TrackPopupMenu().
|
||||||
// the SetForegroundWindow() and SendMessage() calls around
|
// the SetForegroundWindow() and SendMessage() calls around
|
||||||
// TrackPopupMenu() are to get the menu to be dismissed when
|
// TrackPopupMenu() are to get the menu to be dismissed when
|
||||||
@ -137,11 +145,9 @@ void MSWindowsClientTaskBarReceiver::runMenu(int x, int y) {
|
|||||||
HMENU menu = GetSubMenu(m_menu, 0);
|
HMENU menu = GetSubMenu(m_menu, 0);
|
||||||
SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE);
|
SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE);
|
||||||
HMENU logLevelMenu = GetSubMenu(menu, 3);
|
HMENU logLevelMenu = GetSubMenu(menu, 3);
|
||||||
CheckMenuRadioItem(
|
CheckMenuRadioItem(logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
||||||
logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
int n =
|
||||||
int n = TrackPopupMenu(
|
TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x, y, 0, m_window, NULL);
|
||||||
menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x,
|
|
||||||
y, 0, m_window, NULL);
|
|
||||||
SendMessage(m_window, WM_NULL, 0, 0);
|
SendMessage(m_window, WM_NULL, 0, 0);
|
||||||
|
|
||||||
// perform the requested operation
|
// perform the requested operation
|
||||||
@ -192,19 +198,22 @@ void MSWindowsClientTaskBarReceiver::runMenu(int x, int y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::primaryAction() { showStatus(); }
|
void MSWindowsClientTaskBarReceiver::primaryAction()
|
||||||
|
{
|
||||||
|
showStatus();
|
||||||
|
}
|
||||||
|
|
||||||
const IArchTaskBarReceiver::Icon
|
const IArchTaskBarReceiver::Icon MSWindowsClientTaskBarReceiver::getIcon() const
|
||||||
MSWindowsClientTaskBarReceiver::getIcon() const {
|
{
|
||||||
return static_cast<Icon>(m_icon[getStatus()]);
|
return static_cast<Icon>(m_icon[getStatus()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::copyLog() const {
|
void MSWindowsClientTaskBarReceiver::copyLog() const
|
||||||
|
{
|
||||||
if (m_logBuffer != NULL) {
|
if (m_logBuffer != NULL) {
|
||||||
// collect log buffer
|
// collect log buffer
|
||||||
String data;
|
String data;
|
||||||
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin();
|
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin(); index != m_logBuffer->end(); ++index) {
|
||||||
index != m_logBuffer->end(); ++index) {
|
|
||||||
data += *index;
|
data += *index;
|
||||||
data += "\n";
|
data += "\n";
|
||||||
}
|
}
|
||||||
@ -220,26 +229,29 @@ void MSWindowsClientTaskBarReceiver::copyLog() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::onStatusChanged() {
|
void MSWindowsClientTaskBarReceiver::onStatusChanged()
|
||||||
|
{
|
||||||
if (IsWindowVisible(m_window)) {
|
if (IsWindowVisible(m_window)) {
|
||||||
showStatus();
|
showStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HICON
|
HICON
|
||||||
MSWindowsClientTaskBarReceiver::loadIcon(UINT id) {
|
MSWindowsClientTaskBarReceiver::loadIcon(UINT id)
|
||||||
HANDLE icon = LoadImage(
|
{
|
||||||
m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
HANDLE icon = LoadImage(m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
||||||
return static_cast<HICON>(icon);
|
return static_cast<HICON>(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::deleteIcon(HICON icon) {
|
void MSWindowsClientTaskBarReceiver::deleteIcon(HICON icon)
|
||||||
|
{
|
||||||
if (icon != NULL) {
|
if (icon != NULL) {
|
||||||
DestroyIcon(icon);
|
DestroyIcon(icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::createWindow() {
|
void MSWindowsClientTaskBarReceiver::createWindow()
|
||||||
|
{
|
||||||
// ignore if already created
|
// ignore if already created
|
||||||
if (m_window != NULL) {
|
if (m_window != NULL) {
|
||||||
return;
|
return;
|
||||||
@ -247,9 +259,9 @@ void MSWindowsClientTaskBarReceiver::createWindow() {
|
|||||||
|
|
||||||
// get the status dialog
|
// get the status dialog
|
||||||
m_window = CreateDialogParam(
|
m_window = CreateDialogParam(
|
||||||
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL,
|
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL, (DLGPROC)&MSWindowsClientTaskBarReceiver::staticDlgProc,
|
||||||
(DLGPROC)&MSWindowsClientTaskBarReceiver::staticDlgProc,
|
reinterpret_cast<LPARAM>(static_cast<void *>(this))
|
||||||
reinterpret_cast<LPARAM>(static_cast<void *>(this)));
|
);
|
||||||
|
|
||||||
// window should appear on top of everything, including (especially)
|
// window should appear on top of everything, including (especially)
|
||||||
// the task bar.
|
// the task bar.
|
||||||
@ -261,7 +273,8 @@ void MSWindowsClientTaskBarReceiver::createWindow() {
|
|||||||
ArchTaskBarWindows::addDialog(m_window);
|
ArchTaskBarWindows::addDialog(m_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsClientTaskBarReceiver::destroyWindow() {
|
void MSWindowsClientTaskBarReceiver::destroyWindow()
|
||||||
|
{
|
||||||
if (m_window != NULL) {
|
if (m_window != NULL) {
|
||||||
ArchTaskBarWindows::removeDialog(m_window);
|
ArchTaskBarWindows::removeDialog(m_window);
|
||||||
DestroyWindow(m_window);
|
DestroyWindow(m_window);
|
||||||
@ -269,8 +282,8 @@ void MSWindowsClientTaskBarReceiver::destroyWindow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL MSWindowsClientTaskBarReceiver::dlgProc(
|
BOOL MSWindowsClientTaskBarReceiver::dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
|
||||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM) {
|
{
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
// use default focus
|
// use default focus
|
||||||
@ -286,14 +299,13 @@ BOOL MSWindowsClientTaskBarReceiver::dlgProc(
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CALLBACK MSWindowsClientTaskBarReceiver::staticDlgProc(
|
BOOL CALLBACK MSWindowsClientTaskBarReceiver::staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
{
|
||||||
// if msg is WM_INITDIALOG, extract the MSWindowsClientTaskBarReceiver*
|
// if msg is WM_INITDIALOG, extract the MSWindowsClientTaskBarReceiver*
|
||||||
// and put it in the extra window data then forward the call.
|
// and put it in the extra window data then forward the call.
|
||||||
MSWindowsClientTaskBarReceiver *self = NULL;
|
MSWindowsClientTaskBarReceiver *self = NULL;
|
||||||
if (msg == WM_INITDIALOG) {
|
if (msg == WM_INITDIALOG) {
|
||||||
self = static_cast<MSWindowsClientTaskBarReceiver *>(
|
self = static_cast<MSWindowsClientTaskBarReceiver *>(reinterpret_cast<void *>(lParam));
|
||||||
reinterpret_cast<void *>(lParam));
|
|
||||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
|
||||||
} else {
|
} else {
|
||||||
// get the extra window data and forward the call
|
// get the extra window data and forward the call
|
||||||
@ -311,16 +323,12 @@ BOOL CALLBACK MSWindowsClientTaskBarReceiver::staticDlgProc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
{
|
||||||
ArchMiscWindows::setIcons(
|
ArchMiscWindows::setIcons(
|
||||||
(HICON)LoadImage(
|
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 32, 32, LR_SHARED),
|
||||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 16, 16, LR_SHARED)
|
||||||
IMAGE_ICON, 32, 32, LR_SHARED),
|
);
|
||||||
(HICON)LoadImage(
|
|
||||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
|
||||||
IMAGE_ICON, 16, 16, LR_SHARED));
|
|
||||||
|
|
||||||
return new MSWindowsClientTaskBarReceiver(
|
return new MSWindowsClientTaskBarReceiver(MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
||||||
MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,10 +27,10 @@ class BufferedLogOutputter;
|
|||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
//! Implementation of ClientTaskBarReceiver for Microsoft Windows
|
//! Implementation of ClientTaskBarReceiver for Microsoft Windows
|
||||||
class MSWindowsClientTaskBarReceiver : public ClientTaskBarReceiver {
|
class MSWindowsClientTaskBarReceiver : public ClientTaskBarReceiver
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
MSWindowsClientTaskBarReceiver(
|
MSWindowsClientTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
||||||
HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
|
||||||
virtual ~MSWindowsClientTaskBarReceiver();
|
virtual ~MSWindowsClientTaskBarReceiver();
|
||||||
|
|
||||||
// IArchTaskBarReceiver overrides
|
// IArchTaskBarReceiver overrides
|
||||||
@ -53,8 +53,7 @@ private:
|
|||||||
void destroyWindow();
|
void destroyWindow();
|
||||||
|
|
||||||
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
static BOOL CALLBACK
|
static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HINSTANCE m_appInstance;
|
HINSTANCE m_appInstance;
|
||||||
|
|||||||
@ -23,34 +23,39 @@
|
|||||||
// OSXClientTaskBarReceiver
|
// OSXClientTaskBarReceiver
|
||||||
//
|
//
|
||||||
|
|
||||||
OSXClientTaskBarReceiver::OSXClientTaskBarReceiver(
|
OSXClientTaskBarReceiver::OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||||
const BufferedLogOutputter *, IEventQueue *events)
|
: ClientTaskBarReceiver(events)
|
||||||
: ClientTaskBarReceiver(events) {
|
{
|
||||||
// add ourself to the task bar
|
// add ourself to the task bar
|
||||||
ARCH->addReceiver(this);
|
ARCH->addReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSXClientTaskBarReceiver::~OSXClientTaskBarReceiver() {
|
OSXClientTaskBarReceiver::~OSXClientTaskBarReceiver()
|
||||||
|
{
|
||||||
ARCH->removeReceiver(this);
|
ARCH->removeReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXClientTaskBarReceiver::showStatus() {
|
void OSXClientTaskBarReceiver::showStatus()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXClientTaskBarReceiver::runMenu(int, int) {
|
void OSXClientTaskBarReceiver::runMenu(int, int)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXClientTaskBarReceiver::primaryAction() {
|
void OSXClientTaskBarReceiver::primaryAction()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const IArchTaskBarReceiver::Icon OSXClientTaskBarReceiver::getIcon() const {
|
const IArchTaskBarReceiver::Icon OSXClientTaskBarReceiver::getIcon() const
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
{
|
||||||
return new OSXClientTaskBarReceiver(logBuffer, events);
|
return new OSXClientTaskBarReceiver(logBuffer, events);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,8 @@ class BufferedLogOutputter;
|
|||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
//! Implementation of ClientTaskBarReceiver for OS X
|
//! Implementation of ClientTaskBarReceiver for OS X
|
||||||
class OSXClientTaskBarReceiver : public ClientTaskBarReceiver {
|
class OSXClientTaskBarReceiver : public ClientTaskBarReceiver
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||||
virtual ~OSXClientTaskBarReceiver();
|
virtual ~OSXClientTaskBarReceiver();
|
||||||
|
|||||||
@ -23,35 +23,39 @@
|
|||||||
// CXWindowsClientTaskBarReceiver
|
// CXWindowsClientTaskBarReceiver
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsClientTaskBarReceiver::CXWindowsClientTaskBarReceiver(
|
CXWindowsClientTaskBarReceiver::CXWindowsClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||||
const BufferedLogOutputter *, IEventQueue *events)
|
: ClientTaskBarReceiver(events)
|
||||||
: ClientTaskBarReceiver(events) {
|
{
|
||||||
// add ourself to the task bar
|
// add ourself to the task bar
|
||||||
ARCH->addReceiver(this);
|
ARCH->addReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsClientTaskBarReceiver::~CXWindowsClientTaskBarReceiver() {
|
CXWindowsClientTaskBarReceiver::~CXWindowsClientTaskBarReceiver()
|
||||||
|
{
|
||||||
ARCH->removeReceiver(this);
|
ARCH->removeReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClientTaskBarReceiver::showStatus() {
|
void CXWindowsClientTaskBarReceiver::showStatus()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClientTaskBarReceiver::runMenu(int, int) {
|
void CXWindowsClientTaskBarReceiver::runMenu(int, int)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsClientTaskBarReceiver::primaryAction() {
|
void CXWindowsClientTaskBarReceiver::primaryAction()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const IArchTaskBarReceiver::Icon
|
const IArchTaskBarReceiver::Icon CXWindowsClientTaskBarReceiver::getIcon() const
|
||||||
CXWindowsClientTaskBarReceiver::getIcon() const {
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
{
|
||||||
return new CXWindowsClientTaskBarReceiver(logBuffer, events);
|
return new CXWindowsClientTaskBarReceiver(logBuffer, events);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,19 +24,16 @@ class BufferedLogOutputter;
|
|||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
//! Implementation of ClientTaskBarReceiver for X Windows
|
//! Implementation of ClientTaskBarReceiver for X Windows
|
||||||
class CXWindowsClientTaskBarReceiver : public ClientTaskBarReceiver {
|
class CXWindowsClientTaskBarReceiver : public ClientTaskBarReceiver
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
CXWindowsClientTaskBarReceiver(
|
CXWindowsClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||||
const BufferedLogOutputter *, IEventQueue *events);
|
CXWindowsClientTaskBarReceiver(const CXWindowsClientTaskBarReceiver &) = delete;
|
||||||
CXWindowsClientTaskBarReceiver(const CXWindowsClientTaskBarReceiver &) =
|
|
||||||
delete;
|
|
||||||
CXWindowsClientTaskBarReceiver(CXWindowsClientTaskBarReceiver &&) = delete;
|
CXWindowsClientTaskBarReceiver(CXWindowsClientTaskBarReceiver &&) = delete;
|
||||||
virtual ~CXWindowsClientTaskBarReceiver();
|
virtual ~CXWindowsClientTaskBarReceiver();
|
||||||
|
|
||||||
CXWindowsClientTaskBarReceiver &
|
CXWindowsClientTaskBarReceiver &operator=(const CXWindowsClientTaskBarReceiver &) = delete;
|
||||||
operator=(const CXWindowsClientTaskBarReceiver &) = delete;
|
CXWindowsClientTaskBarReceiver &operator=(CXWindowsClientTaskBarReceiver &&) = delete;
|
||||||
CXWindowsClientTaskBarReceiver &
|
|
||||||
operator=(CXWindowsClientTaskBarReceiver &&) = delete;
|
|
||||||
|
|
||||||
// IArchTaskBarReceiver overrides
|
// IArchTaskBarReceiver overrides
|
||||||
virtual void showStatus();
|
virtual void showStatus();
|
||||||
|
|||||||
@ -35,7 +35,8 @@
|
|||||||
#error Platform not supported.
|
#error Platform not supported.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
// record window instance for tray icon, etc
|
// record window instance for tray icon, etc
|
||||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||||
|
|||||||
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
#ifdef SYSAPI_UNIX
|
#ifdef SYSAPI_UNIX
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
DaemonApp app;
|
DaemonApp app;
|
||||||
return app.run(argc, argv);
|
return app.run(argc, argv);
|
||||||
}
|
}
|
||||||
@ -32,7 +33,8 @@ int main(int argc, char **argv) {
|
|||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||||
|
{
|
||||||
DaemonApp app;
|
DaemonApp app;
|
||||||
return app.run(__argc, __argv);
|
return app.run(__argc, __argv);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,17 +35,18 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
const UINT MSWindowsServerTaskBarReceiver::s_stateToIconID[kMaxState] = {
|
const UINT MSWindowsServerTaskBarReceiver::s_stateToIconID[kMaxState] = {
|
||||||
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED,
|
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED, IDI_TASKBAR_CONNECTED
|
||||||
IDI_TASKBAR_CONNECTED};
|
};
|
||||||
|
|
||||||
MSWindowsServerTaskBarReceiver::MSWindowsServerTaskBarReceiver(
|
MSWindowsServerTaskBarReceiver::MSWindowsServerTaskBarReceiver(
|
||||||
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer,
|
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer, IEventQueue *events
|
||||||
IEventQueue *events)
|
)
|
||||||
: ServerTaskBarReceiver(events),
|
: ServerTaskBarReceiver(events),
|
||||||
m_events(events),
|
m_events(events),
|
||||||
m_appInstance(appInstance),
|
m_appInstance(appInstance),
|
||||||
m_window(NULL),
|
m_window(NULL),
|
||||||
m_logBuffer(logBuffer) {
|
m_logBuffer(logBuffer)
|
||||||
|
{
|
||||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||||
m_icon[i] = loadIcon(s_stateToIconID[i]);
|
m_icon[i] = loadIcon(s_stateToIconID[i]);
|
||||||
}
|
}
|
||||||
@ -60,7 +61,8 @@ MSWindowsServerTaskBarReceiver::MSWindowsServerTaskBarReceiver(
|
|||||||
ARCH->addReceiver(this);
|
ARCH->addReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::cleanup() {
|
void MSWindowsServerTaskBarReceiver::cleanup()
|
||||||
|
{
|
||||||
ARCH->removeReceiver(this);
|
ARCH->removeReceiver(this);
|
||||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||||
deleteIcon(m_icon[i]);
|
deleteIcon(m_icon[i]);
|
||||||
@ -69,9 +71,13 @@ void MSWindowsServerTaskBarReceiver::cleanup() {
|
|||||||
destroyWindow();
|
destroyWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
MSWindowsServerTaskBarReceiver::~MSWindowsServerTaskBarReceiver() { cleanup(); }
|
MSWindowsServerTaskBarReceiver::~MSWindowsServerTaskBarReceiver()
|
||||||
|
{
|
||||||
|
cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::showStatus() {
|
void MSWindowsServerTaskBarReceiver::showStatus()
|
||||||
|
{
|
||||||
// create the window
|
// create the window
|
||||||
createWindow();
|
createWindow();
|
||||||
|
|
||||||
@ -92,8 +98,7 @@ void MSWindowsServerTaskBarReceiver::showStatus() {
|
|||||||
SendMessage(child, WM_SETTEXT, 0, (LPARAM)status.c_str());
|
SendMessage(child, WM_SETTEXT, 0, (LPARAM)status.c_str());
|
||||||
child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_CLIENTS);
|
child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_CLIENTS);
|
||||||
SendMessage(child, LB_RESETCONTENT, 0, 0);
|
SendMessage(child, LB_RESETCONTENT, 0, 0);
|
||||||
for (Clients::const_iterator index = clients.begin();
|
for (Clients::const_iterator index = clients.begin(); index != clients.end();) {
|
||||||
index != clients.end();) {
|
|
||||||
const char *client = index->c_str();
|
const char *client = index->c_str();
|
||||||
if (++index == clients.end()) {
|
if (++index == clients.end()) {
|
||||||
SendMessage(child, LB_ADDSTRING, 0, (LPARAM)client);
|
SendMessage(child, LB_ADDSTRING, 0, (LPARAM)client);
|
||||||
@ -142,7 +147,8 @@ void MSWindowsServerTaskBarReceiver::showStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::runMenu(int x, int y) {
|
void MSWindowsServerTaskBarReceiver::runMenu(int x, int y)
|
||||||
|
{
|
||||||
// do popup menu. we need a window to pass to TrackPopupMenu().
|
// do popup menu. we need a window to pass to TrackPopupMenu().
|
||||||
// the SetForegroundWindow() and SendMessage() calls around
|
// the SetForegroundWindow() and SendMessage() calls around
|
||||||
// TrackPopupMenu() are to get the menu to be dismissed when
|
// TrackPopupMenu() are to get the menu to be dismissed when
|
||||||
@ -153,11 +159,9 @@ void MSWindowsServerTaskBarReceiver::runMenu(int x, int y) {
|
|||||||
HMENU menu = GetSubMenu(m_menu, 0);
|
HMENU menu = GetSubMenu(m_menu, 0);
|
||||||
SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE);
|
SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE);
|
||||||
HMENU logLevelMenu = GetSubMenu(menu, 3);
|
HMENU logLevelMenu = GetSubMenu(menu, 3);
|
||||||
CheckMenuRadioItem(
|
CheckMenuRadioItem(logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
||||||
logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
int n =
|
||||||
int n = TrackPopupMenu(
|
TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x, y, 0, m_window, NULL);
|
||||||
menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x,
|
|
||||||
y, 0, m_window, NULL);
|
|
||||||
SendMessage(m_window, WM_NULL, 0, 0);
|
SendMessage(m_window, WM_NULL, 0, 0);
|
||||||
|
|
||||||
// perform the requested operation
|
// perform the requested operation
|
||||||
@ -175,19 +179,15 @@ void MSWindowsServerTaskBarReceiver::runMenu(int x, int y) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_RELOAD_CONFIG:
|
case IDC_RELOAD_CONFIG:
|
||||||
m_events->addEvent(Event(
|
m_events->addEvent(Event(m_events->forServerApp().reloadConfig(), m_events->getSystemTarget()));
|
||||||
m_events->forServerApp().reloadConfig(), m_events->getSystemTarget()));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_FORCE_RECONNECT:
|
case IDC_FORCE_RECONNECT:
|
||||||
m_events->addEvent(Event(
|
m_events->addEvent(Event(m_events->forServerApp().forceReconnect(), m_events->getSystemTarget()));
|
||||||
m_events->forServerApp().forceReconnect(),
|
|
||||||
m_events->getSystemTarget()));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ID_DESKFLOW_RESETSERVER:
|
case ID_DESKFLOW_RESETSERVER:
|
||||||
m_events->addEvent(Event(
|
m_events->addEvent(Event(m_events->forServerApp().resetServer(), m_events->getSystemTarget()));
|
||||||
m_events->forServerApp().resetServer(), m_events->getSystemTarget()));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_TASKBAR_LOG_LEVEL_ERROR:
|
case IDC_TASKBAR_LOG_LEVEL_ERROR:
|
||||||
@ -224,19 +224,22 @@ void MSWindowsServerTaskBarReceiver::runMenu(int x, int y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::primaryAction() { showStatus(); }
|
void MSWindowsServerTaskBarReceiver::primaryAction()
|
||||||
|
{
|
||||||
|
showStatus();
|
||||||
|
}
|
||||||
|
|
||||||
const IArchTaskBarReceiver::Icon
|
const IArchTaskBarReceiver::Icon MSWindowsServerTaskBarReceiver::getIcon() const
|
||||||
MSWindowsServerTaskBarReceiver::getIcon() const {
|
{
|
||||||
return static_cast<Icon>(m_icon[getStatus()]);
|
return static_cast<Icon>(m_icon[getStatus()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::copyLog() const {
|
void MSWindowsServerTaskBarReceiver::copyLog() const
|
||||||
|
{
|
||||||
if (m_logBuffer != NULL) {
|
if (m_logBuffer != NULL) {
|
||||||
// collect log buffer
|
// collect log buffer
|
||||||
String data;
|
String data;
|
||||||
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin();
|
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin(); index != m_logBuffer->end(); ++index) {
|
||||||
index != m_logBuffer->end(); ++index) {
|
|
||||||
data += *index;
|
data += *index;
|
||||||
data += "\n";
|
data += "\n";
|
||||||
}
|
}
|
||||||
@ -252,26 +255,29 @@ void MSWindowsServerTaskBarReceiver::copyLog() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::onStatusChanged() {
|
void MSWindowsServerTaskBarReceiver::onStatusChanged()
|
||||||
|
{
|
||||||
if (IsWindowVisible(m_window)) {
|
if (IsWindowVisible(m_window)) {
|
||||||
showStatus();
|
showStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HICON
|
HICON
|
||||||
MSWindowsServerTaskBarReceiver::loadIcon(UINT id) {
|
MSWindowsServerTaskBarReceiver::loadIcon(UINT id)
|
||||||
HANDLE icon = LoadImage(
|
{
|
||||||
m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
HANDLE icon = LoadImage(m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
||||||
return static_cast<HICON>(icon);
|
return static_cast<HICON>(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::deleteIcon(HICON icon) {
|
void MSWindowsServerTaskBarReceiver::deleteIcon(HICON icon)
|
||||||
|
{
|
||||||
if (icon != NULL) {
|
if (icon != NULL) {
|
||||||
DestroyIcon(icon);
|
DestroyIcon(icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::createWindow() {
|
void MSWindowsServerTaskBarReceiver::createWindow()
|
||||||
|
{
|
||||||
// ignore if already created
|
// ignore if already created
|
||||||
if (m_window != NULL) {
|
if (m_window != NULL) {
|
||||||
return;
|
return;
|
||||||
@ -279,9 +285,9 @@ void MSWindowsServerTaskBarReceiver::createWindow() {
|
|||||||
|
|
||||||
// get the status dialog
|
// get the status dialog
|
||||||
m_window = CreateDialogParam(
|
m_window = CreateDialogParam(
|
||||||
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL,
|
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL, (DLGPROC)&MSWindowsServerTaskBarReceiver::staticDlgProc,
|
||||||
(DLGPROC)&MSWindowsServerTaskBarReceiver::staticDlgProc,
|
reinterpret_cast<LPARAM>(static_cast<void *>(this))
|
||||||
reinterpret_cast<LPARAM>(static_cast<void *>(this)));
|
);
|
||||||
|
|
||||||
// window should appear on top of everything, including (especially)
|
// window should appear on top of everything, including (especially)
|
||||||
// the task bar.
|
// the task bar.
|
||||||
@ -293,7 +299,8 @@ void MSWindowsServerTaskBarReceiver::createWindow() {
|
|||||||
ArchTaskBarWindows::addDialog(m_window);
|
ArchTaskBarWindows::addDialog(m_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSWindowsServerTaskBarReceiver::destroyWindow() {
|
void MSWindowsServerTaskBarReceiver::destroyWindow()
|
||||||
|
{
|
||||||
if (m_window != NULL) {
|
if (m_window != NULL) {
|
||||||
ArchTaskBarWindows::removeDialog(m_window);
|
ArchTaskBarWindows::removeDialog(m_window);
|
||||||
DestroyWindow(m_window);
|
DestroyWindow(m_window);
|
||||||
@ -301,8 +308,8 @@ void MSWindowsServerTaskBarReceiver::destroyWindow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL MSWindowsServerTaskBarReceiver::dlgProc(
|
BOOL MSWindowsServerTaskBarReceiver::dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
|
||||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM) {
|
{
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
// use default focus
|
// use default focus
|
||||||
@ -318,21 +325,19 @@ BOOL MSWindowsServerTaskBarReceiver::dlgProc(
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CALLBACK MSWindowsServerTaskBarReceiver::staticDlgProc(
|
BOOL CALLBACK MSWindowsServerTaskBarReceiver::staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
{
|
||||||
// if msg is WM_INITDIALOG, extract the MSWindowsServerTaskBarReceiver*
|
// if msg is WM_INITDIALOG, extract the MSWindowsServerTaskBarReceiver*
|
||||||
// and put it in the extra window data then forward the call.
|
// and put it in the extra window data then forward the call.
|
||||||
MSWindowsServerTaskBarReceiver *self = NULL;
|
MSWindowsServerTaskBarReceiver *self = NULL;
|
||||||
if (msg == WM_INITDIALOG) {
|
if (msg == WM_INITDIALOG) {
|
||||||
self = static_cast<MSWindowsServerTaskBarReceiver *>(
|
self = static_cast<MSWindowsServerTaskBarReceiver *>(reinterpret_cast<void *>(lParam));
|
||||||
reinterpret_cast<void *>(lParam));
|
|
||||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
|
||||||
} else {
|
} else {
|
||||||
// get the extra window data and forward the call
|
// get the extra window data and forward the call
|
||||||
LONG_PTR data = GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
LONG_PTR data = GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||||
if (data != 0) {
|
if (data != 0) {
|
||||||
self = static_cast<MSWindowsServerTaskBarReceiver *>(
|
self = static_cast<MSWindowsServerTaskBarReceiver *>(reinterpret_cast<void *>(data));
|
||||||
reinterpret_cast<void *>(data));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,16 +349,12 @@ BOOL CALLBACK MSWindowsServerTaskBarReceiver::staticDlgProc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
{
|
||||||
ArchMiscWindows::setIcons(
|
ArchMiscWindows::setIcons(
|
||||||
(HICON)LoadImage(
|
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 32, 32, LR_SHARED),
|
||||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 16, 16, LR_SHARED)
|
||||||
IMAGE_ICON, 32, 32, LR_SHARED),
|
);
|
||||||
(HICON)LoadImage(
|
|
||||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
|
||||||
IMAGE_ICON, 16, 16, LR_SHARED));
|
|
||||||
|
|
||||||
return new MSWindowsServerTaskBarReceiver(
|
return new MSWindowsServerTaskBarReceiver(MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
||||||
MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,10 +27,10 @@ class BufferedLogOutputter;
|
|||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
//! Implementation of ServerTaskBarReceiver for Microsoft Windows
|
//! Implementation of ServerTaskBarReceiver for Microsoft Windows
|
||||||
class MSWindowsServerTaskBarReceiver : public ServerTaskBarReceiver {
|
class MSWindowsServerTaskBarReceiver : public ServerTaskBarReceiver
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
MSWindowsServerTaskBarReceiver(
|
MSWindowsServerTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
||||||
HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
|
||||||
virtual ~MSWindowsServerTaskBarReceiver();
|
virtual ~MSWindowsServerTaskBarReceiver();
|
||||||
|
|
||||||
// IArchTaskBarReceiver overrides
|
// IArchTaskBarReceiver overrides
|
||||||
@ -53,8 +53,7 @@ private:
|
|||||||
void destroyWindow();
|
void destroyWindow();
|
||||||
|
|
||||||
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
static BOOL CALLBACK
|
static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HINSTANCE m_appInstance;
|
HINSTANCE m_appInstance;
|
||||||
|
|||||||
@ -23,34 +23,39 @@
|
|||||||
// OSXServerTaskBarReceiver
|
// OSXServerTaskBarReceiver
|
||||||
//
|
//
|
||||||
|
|
||||||
OSXServerTaskBarReceiver::OSXServerTaskBarReceiver(
|
OSXServerTaskBarReceiver::OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||||
const BufferedLogOutputter *, IEventQueue *events)
|
: ServerTaskBarReceiver(events)
|
||||||
: ServerTaskBarReceiver(events) {
|
{
|
||||||
// add ourself to the task bar
|
// add ourself to the task bar
|
||||||
ARCH->addReceiver(this);
|
ARCH->addReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
OSXServerTaskBarReceiver::~OSXServerTaskBarReceiver() {
|
OSXServerTaskBarReceiver::~OSXServerTaskBarReceiver()
|
||||||
|
{
|
||||||
ARCH->removeReceiver(this);
|
ARCH->removeReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXServerTaskBarReceiver::showStatus() {
|
void OSXServerTaskBarReceiver::showStatus()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXServerTaskBarReceiver::runMenu(int, int) {
|
void OSXServerTaskBarReceiver::runMenu(int, int)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSXServerTaskBarReceiver::primaryAction() {
|
void OSXServerTaskBarReceiver::primaryAction()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const IArchTaskBarReceiver::Icon OSXServerTaskBarReceiver::getIcon() const {
|
const IArchTaskBarReceiver::Icon OSXServerTaskBarReceiver::getIcon() const
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
{
|
||||||
return new OSXServerTaskBarReceiver(logBuffer, events);
|
return new OSXServerTaskBarReceiver(logBuffer, events);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
class BufferedLogOutputter;
|
class BufferedLogOutputter;
|
||||||
|
|
||||||
//! Implementation of ServerTaskBarReceiver for OS X
|
//! Implementation of ServerTaskBarReceiver for OS X
|
||||||
class OSXServerTaskBarReceiver : public ServerTaskBarReceiver {
|
class OSXServerTaskBarReceiver : public ServerTaskBarReceiver
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||||
virtual ~OSXServerTaskBarReceiver();
|
virtual ~OSXServerTaskBarReceiver();
|
||||||
|
|||||||
@ -23,35 +23,39 @@
|
|||||||
// CXWindowsServerTaskBarReceiver
|
// CXWindowsServerTaskBarReceiver
|
||||||
//
|
//
|
||||||
|
|
||||||
CXWindowsServerTaskBarReceiver::CXWindowsServerTaskBarReceiver(
|
CXWindowsServerTaskBarReceiver::CXWindowsServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||||
const BufferedLogOutputter *, IEventQueue *events)
|
: ServerTaskBarReceiver(events)
|
||||||
: ServerTaskBarReceiver(events) {
|
{
|
||||||
// add ourself to the task bar
|
// add ourself to the task bar
|
||||||
ARCH->addReceiver(this);
|
ARCH->addReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CXWindowsServerTaskBarReceiver::~CXWindowsServerTaskBarReceiver() {
|
CXWindowsServerTaskBarReceiver::~CXWindowsServerTaskBarReceiver()
|
||||||
|
{
|
||||||
ARCH->removeReceiver(this);
|
ARCH->removeReceiver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsServerTaskBarReceiver::showStatus() {
|
void CXWindowsServerTaskBarReceiver::showStatus()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsServerTaskBarReceiver::runMenu(int, int) {
|
void CXWindowsServerTaskBarReceiver::runMenu(int, int)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void CXWindowsServerTaskBarReceiver::primaryAction() {
|
void CXWindowsServerTaskBarReceiver::primaryAction()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const IArchTaskBarReceiver::Icon
|
const IArchTaskBarReceiver::Icon CXWindowsServerTaskBarReceiver::getIcon() const
|
||||||
CXWindowsServerTaskBarReceiver::getIcon() const {
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
{
|
||||||
return new CXWindowsServerTaskBarReceiver(logBuffer, events);
|
return new CXWindowsServerTaskBarReceiver(logBuffer, events);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,19 +24,16 @@ class BufferedLogOutputter;
|
|||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
//! Implementation of ServerTaskBarReceiver for X Windows
|
//! Implementation of ServerTaskBarReceiver for X Windows
|
||||||
class CXWindowsServerTaskBarReceiver : public ServerTaskBarReceiver {
|
class CXWindowsServerTaskBarReceiver : public ServerTaskBarReceiver
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
CXWindowsServerTaskBarReceiver(
|
CXWindowsServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||||
const BufferedLogOutputter *, IEventQueue *events);
|
CXWindowsServerTaskBarReceiver(const CXWindowsServerTaskBarReceiver &) = delete;
|
||||||
CXWindowsServerTaskBarReceiver(const CXWindowsServerTaskBarReceiver &) =
|
|
||||||
delete;
|
|
||||||
CXWindowsServerTaskBarReceiver(CXWindowsServerTaskBarReceiver &&) = delete;
|
CXWindowsServerTaskBarReceiver(CXWindowsServerTaskBarReceiver &&) = delete;
|
||||||
virtual ~CXWindowsServerTaskBarReceiver();
|
virtual ~CXWindowsServerTaskBarReceiver();
|
||||||
|
|
||||||
CXWindowsServerTaskBarReceiver &
|
CXWindowsServerTaskBarReceiver &operator=(const CXWindowsServerTaskBarReceiver &) = delete;
|
||||||
operator=(const CXWindowsServerTaskBarReceiver &) = delete;
|
CXWindowsServerTaskBarReceiver &operator=(const CXWindowsServerTaskBarReceiver &&) = delete;
|
||||||
CXWindowsServerTaskBarReceiver &
|
|
||||||
operator=(const CXWindowsServerTaskBarReceiver &&) = delete;
|
|
||||||
|
|
||||||
// IArchTaskBarReceiver overrides
|
// IArchTaskBarReceiver overrides
|
||||||
virtual void showStatus();
|
virtual void showStatus();
|
||||||
|
|||||||
@ -35,7 +35,8 @@
|
|||||||
#error Platform not supported.
|
#error Platform not supported.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
// record window instance for tray icon, etc
|
// record window instance for tray icon, etc
|
||||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||||
|
|||||||
@ -22,11 +22,9 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
const char *Action::m_ActionTypeNames[] = {
|
const char *Action::m_ActionTypeNames[] = {
|
||||||
"keyDown", "keyUp",
|
"keyDown", "keyUp", "keystroke", "switchToScreen", "switchInDirection", "lockCursorToScreen",
|
||||||
"keystroke", "switchToScreen",
|
"restartServer", "mouseDown", "mouseUp", "mousebutton"
|
||||||
"switchInDirection", "lockCursorToScreen",
|
};
|
||||||
"restartServer", "mouseDown",
|
|
||||||
"mouseUp", "mousebutton"};
|
|
||||||
|
|
||||||
const char *Action::m_SwitchDirectionNames[] = {"left", "right", "up", "down"};
|
const char *Action::m_SwitchDirectionNames[] = {"left", "right", "up", "down"};
|
||||||
const char *Action::m_LockCursorModeNames[] = {"toggle", "on", "off"};
|
const char *Action::m_LockCursorModeNames[] = {"toggle", "on", "off"};
|
||||||
@ -39,13 +37,13 @@ Action::Action()
|
|||||||
m_SwitchDirection(switchLeft),
|
m_SwitchDirection(switchLeft),
|
||||||
m_LockCursorMode(lockCursorToggle),
|
m_LockCursorMode(lockCursorToggle),
|
||||||
m_ActiveOnRelease(false),
|
m_ActiveOnRelease(false),
|
||||||
m_HasScreens(false) {}
|
m_HasScreens(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QString Action::text() const {
|
QString Action::text() const
|
||||||
QString text =
|
{
|
||||||
QString(m_ActionTypeNames
|
QString text = QString(m_ActionTypeNames[keySequence().isMouseButton() ? type() + 6 : type()]) + "(";
|
||||||
[keySequence().isMouseButton() ? type() + 6 : type()]) +
|
|
||||||
"(";
|
|
||||||
|
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
case keyDown:
|
case keyDown:
|
||||||
@ -93,7 +91,8 @@ QString Action::text() const {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::loadSettings(QSettings &settings) {
|
void Action::loadSettings(QSettings &settings)
|
||||||
|
{
|
||||||
keySequence().loadSettings(settings);
|
keySequence().loadSettings(settings);
|
||||||
setType(settings.value("type", keyDown).toInt());
|
setType(settings.value("type", keyDown).toInt());
|
||||||
|
|
||||||
@ -107,14 +106,14 @@ void Action::loadSettings(QSettings &settings) {
|
|||||||
|
|
||||||
setSwitchScreenName(settings.value("switchScreenName").toString());
|
setSwitchScreenName(settings.value("switchScreenName").toString());
|
||||||
setSwitchDirection(settings.value("switchInDirection", switchLeft).toInt());
|
setSwitchDirection(settings.value("switchInDirection", switchLeft).toInt());
|
||||||
setLockCursorMode(
|
setLockCursorMode(settings.value("lockCursorToScreen", lockCursorToggle).toInt());
|
||||||
settings.value("lockCursorToScreen", lockCursorToggle).toInt());
|
|
||||||
setActiveOnRelease(settings.value("activeOnRelease", false).toBool());
|
setActiveOnRelease(settings.value("activeOnRelease", false).toBool());
|
||||||
setHaveScreens(settings.value("hasScreens", false).toBool());
|
setHaveScreens(settings.value("hasScreens", false).toBool());
|
||||||
setRestartServer(settings.value("restartServer", false).toBool());
|
setRestartServer(settings.value("restartServer", false).toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Action::saveSettings(QSettings &settings) const {
|
void Action::saveSettings(QSettings &settings) const
|
||||||
|
{
|
||||||
keySequence().saveSettings(settings);
|
keySequence().saveSettings(settings);
|
||||||
settings.setValue("type", type());
|
settings.setValue("type", type());
|
||||||
|
|
||||||
@ -133,17 +132,16 @@ void Action::saveSettings(QSettings &settings) const {
|
|||||||
settings.setValue("restartServer", restartServer());
|
settings.setValue("restartServer", restartServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Action::operator==(const Action &a) const {
|
bool Action::operator==(const Action &a) const
|
||||||
return m_KeySequence == a.m_KeySequence && m_Type == a.m_Type &&
|
{
|
||||||
m_TypeScreenNames == a.m_TypeScreenNames &&
|
return m_KeySequence == a.m_KeySequence && m_Type == a.m_Type && m_TypeScreenNames == a.m_TypeScreenNames &&
|
||||||
m_SwitchScreenName == a.m_SwitchScreenName &&
|
m_SwitchScreenName == a.m_SwitchScreenName && m_SwitchDirection == a.m_SwitchDirection &&
|
||||||
m_SwitchDirection == a.m_SwitchDirection &&
|
m_LockCursorMode == a.m_LockCursorMode && m_ActiveOnRelease == a.m_ActiveOnRelease &&
|
||||||
m_LockCursorMode == a.m_LockCursorMode &&
|
|
||||||
m_ActiveOnRelease == a.m_ActiveOnRelease &&
|
|
||||||
m_HasScreens == a.m_HasScreens && m_restartServer == a.m_restartServer;
|
m_HasScreens == a.m_HasScreens && m_restartServer == a.m_restartServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream &operator<<(QTextStream &outStream, const Action &action) {
|
QTextStream &operator<<(QTextStream &outStream, const Action &action)
|
||||||
|
{
|
||||||
if (action.activeOnRelease())
|
if (action.activeOnRelease())
|
||||||
outStream << ";";
|
outStream << ";";
|
||||||
|
|
||||||
|
|||||||
@ -28,12 +28,14 @@ class ActionDialog;
|
|||||||
class QSettings;
|
class QSettings;
|
||||||
class QTextStream;
|
class QTextStream;
|
||||||
|
|
||||||
class Action {
|
class Action
|
||||||
|
{
|
||||||
friend class ActionDialog;
|
friend class ActionDialog;
|
||||||
friend QTextStream &operator<<(QTextStream &outStream, const Action &action);
|
friend QTextStream &operator<<(QTextStream &outStream, const Action &action);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ActionType {
|
enum ActionType
|
||||||
|
{
|
||||||
keyDown,
|
keyDown,
|
||||||
keyUp,
|
keyUp,
|
||||||
keystroke,
|
keystroke,
|
||||||
@ -45,39 +47,107 @@ public:
|
|||||||
mouseUp,
|
mouseUp,
|
||||||
mousebutton,
|
mousebutton,
|
||||||
};
|
};
|
||||||
enum SwitchDirection { switchLeft, switchRight, switchUp, switchDown };
|
enum SwitchDirection
|
||||||
enum LockCursorMode { lockCursorToggle, lockCursonOn, lockCursorOff };
|
{
|
||||||
|
switchLeft,
|
||||||
|
switchRight,
|
||||||
|
switchUp,
|
||||||
|
switchDown
|
||||||
|
};
|
||||||
|
enum LockCursorMode
|
||||||
|
{
|
||||||
|
lockCursorToggle,
|
||||||
|
lockCursonOn,
|
||||||
|
lockCursorOff
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Action();
|
Action();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString text() const;
|
QString text() const;
|
||||||
const KeySequence &keySequence() const { return m_KeySequence; }
|
const KeySequence &keySequence() const
|
||||||
|
{
|
||||||
|
return m_KeySequence;
|
||||||
|
}
|
||||||
void loadSettings(QSettings &settings);
|
void loadSettings(QSettings &settings);
|
||||||
void saveSettings(QSettings &settings) const;
|
void saveSettings(QSettings &settings) const;
|
||||||
int type() const { return m_Type; }
|
int type() const
|
||||||
const QStringList &typeScreenNames() const { return m_TypeScreenNames; }
|
{
|
||||||
const QString &switchScreenName() const { return m_SwitchScreenName; }
|
return m_Type;
|
||||||
int switchDirection() const { return m_SwitchDirection; }
|
}
|
||||||
int lockCursorMode() const { return m_LockCursorMode; }
|
const QStringList &typeScreenNames() const
|
||||||
bool activeOnRelease() const { return m_ActiveOnRelease; }
|
{
|
||||||
bool haveScreens() const { return m_HasScreens; }
|
return m_TypeScreenNames;
|
||||||
bool restartServer() const { return m_restartServer; }
|
}
|
||||||
|
const QString &switchScreenName() const
|
||||||
|
{
|
||||||
|
return m_SwitchScreenName;
|
||||||
|
}
|
||||||
|
int switchDirection() const
|
||||||
|
{
|
||||||
|
return m_SwitchDirection;
|
||||||
|
}
|
||||||
|
int lockCursorMode() const
|
||||||
|
{
|
||||||
|
return m_LockCursorMode;
|
||||||
|
}
|
||||||
|
bool activeOnRelease() const
|
||||||
|
{
|
||||||
|
return m_ActiveOnRelease;
|
||||||
|
}
|
||||||
|
bool haveScreens() const
|
||||||
|
{
|
||||||
|
return m_HasScreens;
|
||||||
|
}
|
||||||
|
bool restartServer() const
|
||||||
|
{
|
||||||
|
return m_restartServer;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const Action &a) const;
|
bool operator==(const Action &a) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
KeySequence &keySequence() { return m_KeySequence; }
|
KeySequence &keySequence()
|
||||||
void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; }
|
{
|
||||||
void setType(int t) { m_Type = t; }
|
return m_KeySequence;
|
||||||
QStringList &typeScreenNames() { return m_TypeScreenNames; }
|
}
|
||||||
void setSwitchScreenName(const QString &n) { m_SwitchScreenName = n; }
|
void setKeySequence(const KeySequence &seq)
|
||||||
void setSwitchDirection(int d) { m_SwitchDirection = d; }
|
{
|
||||||
void setLockCursorMode(int m) { m_LockCursorMode = m; }
|
m_KeySequence = seq;
|
||||||
void setActiveOnRelease(bool b) { m_ActiveOnRelease = b; }
|
}
|
||||||
void setHaveScreens(bool b) { m_HasScreens = b; }
|
void setType(int t)
|
||||||
void setRestartServer(bool b) { m_restartServer = b; }
|
{
|
||||||
|
m_Type = t;
|
||||||
|
}
|
||||||
|
QStringList &typeScreenNames()
|
||||||
|
{
|
||||||
|
return m_TypeScreenNames;
|
||||||
|
}
|
||||||
|
void setSwitchScreenName(const QString &n)
|
||||||
|
{
|
||||||
|
m_SwitchScreenName = n;
|
||||||
|
}
|
||||||
|
void setSwitchDirection(int d)
|
||||||
|
{
|
||||||
|
m_SwitchDirection = d;
|
||||||
|
}
|
||||||
|
void setLockCursorMode(int m)
|
||||||
|
{
|
||||||
|
m_LockCursorMode = m;
|
||||||
|
}
|
||||||
|
void setActiveOnRelease(bool b)
|
||||||
|
{
|
||||||
|
m_ActiveOnRelease = b;
|
||||||
|
}
|
||||||
|
void setHaveScreens(bool b)
|
||||||
|
{
|
||||||
|
m_HasScreens = b;
|
||||||
|
}
|
||||||
|
void setRestartServer(bool b)
|
||||||
|
{
|
||||||
|
m_restartServer = b;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeySequence m_KeySequence;
|
KeySequence m_KeySequence;
|
||||||
|
|||||||
@ -27,14 +27,14 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
ActionDialog::ActionDialog(
|
ActionDialog::ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action)
|
||||||
QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action)
|
|
||||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||||
Ui::ActionDialogBase(),
|
Ui::ActionDialogBase(),
|
||||||
m_ServerConfig(config),
|
m_ServerConfig(config),
|
||||||
m_Hotkey(hotkey),
|
m_Hotkey(hotkey),
|
||||||
m_Action(action),
|
m_Action(action),
|
||||||
m_pButtonGroupType(new QButtonGroup(this)) {
|
m_pButtonGroupType(new QButtonGroup(this))
|
||||||
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
// work around Qt Designer's lack of a QButtonGroup; we need it to get
|
// work around Qt Designer's lack of a QButtonGroup; we need it to get
|
||||||
@ -46,10 +46,10 @@ ActionDialog::ActionDialog(
|
|||||||
m_pRadioSwitchToScreen,
|
m_pRadioSwitchToScreen,
|
||||||
m_pRadioSwitchInDirection,
|
m_pRadioSwitchInDirection,
|
||||||
m_pRadioLockCursorToScreen,
|
m_pRadioLockCursorToScreen,
|
||||||
m_pRadioRestartAllConnections};
|
m_pRadioRestartAllConnections
|
||||||
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]);
|
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++)
|
||||||
i++)
|
|
||||||
m_pButtonGroupType->addButton(typeButtons[i], i);
|
m_pButtonGroupType->addButton(typeButtons[i], i);
|
||||||
|
|
||||||
m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString());
|
m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString());
|
||||||
@ -81,9 +81,9 @@ ActionDialog::ActionDialog(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionDialog::accept() {
|
void ActionDialog::accept()
|
||||||
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 &&
|
{
|
||||||
m_pButtonGroupType->checkedId() < 3)
|
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 && m_pButtonGroupType->checkedId() < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_Action.setKeySequence(sequenceWidget()->keySequence());
|
m_Action.setKeySequence(sequenceWidget()->keySequence());
|
||||||
@ -103,7 +103,8 @@ void ActionDialog::accept() {
|
|||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged() {
|
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged()
|
||||||
|
{
|
||||||
if (sequenceWidget()->keySequence().isMouseButton()) {
|
if (sequenceWidget()->keySequence().isMouseButton()) {
|
||||||
m_pGroupBoxScreens->setEnabled(false);
|
m_pGroupBoxScreens->setEnabled(false);
|
||||||
m_pListScreens->setEnabled(false);
|
m_pListScreens->setEnabled(false);
|
||||||
|
|||||||
@ -28,22 +28,26 @@ class QRadioButton;
|
|||||||
class QButtonGroup;
|
class QButtonGroup;
|
||||||
class ServerConfig;
|
class ServerConfig;
|
||||||
|
|
||||||
class ActionDialog : public QDialog, public Ui::ActionDialogBase {
|
class ActionDialog : public QDialog, public Ui::ActionDialogBase
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ActionDialog(
|
ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action);
|
||||||
QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action);
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void accept();
|
void accept();
|
||||||
void on_m_pKeySequenceWidgetHotkey_keySequenceChanged();
|
void on_m_pKeySequenceWidgetHotkey_keySequenceChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const KeySequenceWidget *sequenceWidget() const {
|
const KeySequenceWidget *sequenceWidget() const
|
||||||
|
{
|
||||||
return m_pKeySequenceWidgetHotkey;
|
return m_pKeySequenceWidgetHotkey;
|
||||||
}
|
}
|
||||||
const ServerConfig &serverConfig() const { return m_ServerConfig; }
|
const ServerConfig &serverConfig() const
|
||||||
|
{
|
||||||
|
return m_ServerConfig;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ServerConfig &m_ServerConfig;
|
const ServerConfig &m_ServerConfig;
|
||||||
|
|||||||
@ -24,13 +24,15 @@
|
|||||||
AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
|
AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
|
||||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||||
Ui::AddClientDialog(),
|
Ui::AddClientDialog(),
|
||||||
m_AddResult(kAddClientIgnore) {
|
m_AddResult(kAddClientIgnore)
|
||||||
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
m_pLabelHead->setText(
|
m_pLabelHead->setText(
|
||||||
"A client wants to connect. "
|
"A client wants to connect. "
|
||||||
"Please choose a location for " +
|
"Please choose a location for " +
|
||||||
clientName + ".");
|
clientName + "."
|
||||||
|
);
|
||||||
|
|
||||||
QIcon icon(":res/icons/64x64/video-display.png");
|
QIcon icon(":res/icons/64x64/video-display.png");
|
||||||
QSize IconSize(32, 32);
|
QSize IconSize(32, 32);
|
||||||
@ -39,33 +41,25 @@ AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
|
|||||||
m_pButtonLeft->setIcon(icon);
|
m_pButtonLeft->setIcon(icon);
|
||||||
m_pButtonLeft->setIconSize(IconSize);
|
m_pButtonLeft->setIconSize(IconSize);
|
||||||
gridLayout->addWidget(m_pButtonLeft, 2, 0, 1, 1, Qt::AlignCenter);
|
gridLayout->addWidget(m_pButtonLeft, 2, 0, 1, 1, Qt::AlignCenter);
|
||||||
connect(
|
connect(m_pButtonLeft, &QPushButton::clicked, this, &AddClientDialog::handleButtonLeft);
|
||||||
m_pButtonLeft, &QPushButton::clicked, this,
|
|
||||||
&AddClientDialog::handleButtonLeft);
|
|
||||||
|
|
||||||
m_pButtonUp = new QPushButton(this);
|
m_pButtonUp = new QPushButton(this);
|
||||||
m_pButtonUp->setIcon(icon);
|
m_pButtonUp->setIcon(icon);
|
||||||
m_pButtonUp->setIconSize(IconSize);
|
m_pButtonUp->setIconSize(IconSize);
|
||||||
gridLayout->addWidget(m_pButtonUp, 1, 1, 1, 1, Qt::AlignCenter);
|
gridLayout->addWidget(m_pButtonUp, 1, 1, 1, 1, Qt::AlignCenter);
|
||||||
connect(
|
connect(m_pButtonUp, &QPushButton::clicked, this, &AddClientDialog::handleButtonUp);
|
||||||
m_pButtonUp, &QPushButton::clicked, this,
|
|
||||||
&AddClientDialog::handleButtonUp);
|
|
||||||
|
|
||||||
m_pButtonRight = new QPushButton(this);
|
m_pButtonRight = new QPushButton(this);
|
||||||
m_pButtonRight->setIcon(icon);
|
m_pButtonRight->setIcon(icon);
|
||||||
m_pButtonRight->setIconSize(IconSize);
|
m_pButtonRight->setIconSize(IconSize);
|
||||||
gridLayout->addWidget(m_pButtonRight, 2, 2, 1, 1, Qt::AlignCenter);
|
gridLayout->addWidget(m_pButtonRight, 2, 2, 1, 1, Qt::AlignCenter);
|
||||||
connect(
|
connect(m_pButtonRight, &QPushButton::clicked, this, &AddClientDialog::handleButtonRight);
|
||||||
m_pButtonRight, &QPushButton::clicked, this,
|
|
||||||
&AddClientDialog::handleButtonRight);
|
|
||||||
|
|
||||||
m_pButtonDown = new QPushButton(this);
|
m_pButtonDown = new QPushButton(this);
|
||||||
m_pButtonDown->setIcon(icon);
|
m_pButtonDown->setIcon(icon);
|
||||||
m_pButtonDown->setIconSize(IconSize);
|
m_pButtonDown->setIconSize(IconSize);
|
||||||
gridLayout->addWidget(m_pButtonDown, 3, 1, 1, 1, Qt::AlignCenter);
|
gridLayout->addWidget(m_pButtonDown, 3, 1, 1, 1, Qt::AlignCenter);
|
||||||
connect(
|
connect(m_pButtonDown, &QPushButton::clicked, this, &AddClientDialog::handleButtonDown);
|
||||||
m_pButtonDown, &QPushButton::clicked, this,
|
|
||||||
&AddClientDialog::handleButtonDown);
|
|
||||||
|
|
||||||
m_pLabelCenter = new QLabel(this);
|
m_pLabelCenter = new QLabel(this);
|
||||||
m_pLabelCenter->setPixmap(QPixmap(":res/icons/64x64/video-display.png"));
|
m_pLabelCenter->setPixmap(QPixmap(":res/icons/64x64/video-display.png"));
|
||||||
@ -75,14 +69,12 @@ AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
|
|||||||
m_pDialogButtonBox->setLayoutDirection(Qt::RightToLeft);
|
m_pDialogButtonBox->setLayoutDirection(Qt::RightToLeft);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QPushButton *advanced =
|
QPushButton *advanced = m_pDialogButtonBox->addButton("Advanced", QDialogButtonBox::HelpRole);
|
||||||
m_pDialogButtonBox->addButton("Advanced", QDialogButtonBox::HelpRole);
|
connect(advanced, &QPushButton::clicked, this, &AddClientDialog::handleButtonAdvanced);
|
||||||
connect(
|
|
||||||
advanced, &QPushButton::clicked, this,
|
|
||||||
&AddClientDialog::handleButtonAdvanced);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AddClientDialog::~AddClientDialog() {
|
AddClientDialog::~AddClientDialog()
|
||||||
|
{
|
||||||
delete m_pButtonUp;
|
delete m_pButtonUp;
|
||||||
delete m_pButtonDown;
|
delete m_pButtonDown;
|
||||||
delete m_pButtonLeft;
|
delete m_pButtonLeft;
|
||||||
@ -90,27 +82,32 @@ AddClientDialog::~AddClientDialog() {
|
|||||||
delete m_pLabelCenter;
|
delete m_pLabelCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddClientDialog::handleButtonLeft() {
|
void AddClientDialog::handleButtonLeft()
|
||||||
|
{
|
||||||
m_AddResult = kAddClientLeft;
|
m_AddResult = kAddClientLeft;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddClientDialog::handleButtonUp() {
|
void AddClientDialog::handleButtonUp()
|
||||||
|
{
|
||||||
m_AddResult = kAddClientUp;
|
m_AddResult = kAddClientUp;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddClientDialog::handleButtonRight() {
|
void AddClientDialog::handleButtonRight()
|
||||||
|
{
|
||||||
m_AddResult = kAddClientRight;
|
m_AddResult = kAddClientRight;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddClientDialog::handleButtonDown() {
|
void AddClientDialog::handleButtonDown()
|
||||||
|
{
|
||||||
m_AddResult = kAddClientDown;
|
m_AddResult = kAddClientDown;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddClientDialog::handleButtonAdvanced() {
|
void AddClientDialog::handleButtonAdvanced()
|
||||||
|
{
|
||||||
m_AddResult = kAddClientOther;
|
m_AddResult = kAddClientOther;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
kAddClientRight,
|
kAddClientRight,
|
||||||
kAddClientLeft,
|
kAddClientLeft,
|
||||||
kAddClientUp,
|
kAddClientUp,
|
||||||
@ -33,13 +34,17 @@ enum {
|
|||||||
kAddClientIgnore
|
kAddClientIgnore
|
||||||
};
|
};
|
||||||
|
|
||||||
class AddClientDialog : public QDialog, public Ui::AddClientDialog {
|
class AddClientDialog : public QDialog, public Ui::AddClientDialog
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AddClientDialog(const QString &clientName, QWidget *parent = 0);
|
AddClientDialog(const QString &clientName, QWidget *parent = 0);
|
||||||
~AddClientDialog();
|
~AddClientDialog();
|
||||||
|
|
||||||
int addResult() { return m_AddResult; }
|
int addResult()
|
||||||
|
{
|
||||||
|
return m_AddResult;
|
||||||
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleButtonLeft();
|
void handleButtonLeft();
|
||||||
|
|||||||
@ -1,21 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#if OSX_DEPLOYMENT_TARGET >= 1014
|
#if OSX_DEPLOYMENT_TARGET >= 1014
|
||||||
#import <UserNotifications/UNUserNotificationCenter.h>
|
#import <UserNotifications/UNUserNotificationCenter.h>
|
||||||
@interface AppDelegate
|
@interface AppDelegate
|
||||||
: NSObject <
|
: NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate>
|
||||||
NSApplicationDelegate, NSUserNotificationCenterDelegate,
|
|
||||||
UNUserNotificationCenterDelegate>
|
|
||||||
#else
|
#else
|
||||||
@interface AppDelegate
|
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
|
||||||
: NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,18 +17,17 @@
|
|||||||
|
|
||||||
#include "DataDownloader.h"
|
#include "DataDownloader.h"
|
||||||
|
|
||||||
DataDownloader::DataDownloader(QObject *parent)
|
DataDownloader::DataDownloader(QObject *parent) : QObject(parent), m_pReply(nullptr), m_IsFinished(false)
|
||||||
: QObject(parent),
|
{
|
||||||
m_pReply(nullptr),
|
connect(&m_NetworkManager, &QNetworkAccessManager::finished, this, &DataDownloader::complete);
|
||||||
m_IsFinished(false) {
|
|
||||||
connect(
|
|
||||||
&m_NetworkManager, &QNetworkAccessManager::finished, this,
|
|
||||||
&DataDownloader::complete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataDownloader::~DataDownloader() {}
|
DataDownloader::~DataDownloader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void DataDownloader::complete(QNetworkReply *reply) {
|
void DataDownloader::complete(QNetworkReply *reply)
|
||||||
|
{
|
||||||
m_Data = reply->readAll();
|
m_Data = reply->readAll();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
m_pReply = nullptr;
|
m_pReply = nullptr;
|
||||||
@ -39,15 +38,20 @@ void DataDownloader::complete(QNetworkReply *reply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray DataDownloader::data() const { return m_Data; }
|
QByteArray DataDownloader::data() const
|
||||||
|
{
|
||||||
|
return m_Data;
|
||||||
|
}
|
||||||
|
|
||||||
void DataDownloader::cancel() {
|
void DataDownloader::cancel()
|
||||||
|
{
|
||||||
if (m_pReply != nullptr) {
|
if (m_pReply != nullptr) {
|
||||||
m_pReply->abort();
|
m_pReply->abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataDownloader::download(QUrl url) {
|
void DataDownloader::download(QUrl url)
|
||||||
|
{
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
m_pReply = m_NetworkManager.get(request);
|
m_pReply = m_NetworkManager.get(request);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class DataDownloader : public QObject {
|
class DataDownloader : public QObject
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -33,7 +34,10 @@ public:
|
|||||||
QByteArray data() const;
|
QByteArray data() const;
|
||||||
void cancel();
|
void cancel();
|
||||||
void download(QUrl url);
|
void download(QUrl url);
|
||||||
bool isFinished() const { return m_IsFinished; }
|
bool isFinished() const
|
||||||
|
{
|
||||||
|
return m_IsFinished;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void isComplete();
|
void isComplete();
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
DeskflowApplication::DeskflowApplication(int &argc, char **argv)
|
DeskflowApplication::DeskflowApplication(int &argc, char **argv) : QApplication(argc, argv)
|
||||||
: QApplication(argc, argv) {
|
{
|
||||||
|
|
||||||
if (qEnvironmentVariable("XDG_CURRENT_DESKTOP") != QLatin1String("KDE")) {
|
if (qEnvironmentVariable("XDG_CURRENT_DESKTOP") != QLatin1String("KDE")) {
|
||||||
// causes dark mode to be used on some OS (e.g. Windows)
|
// causes dark mode to be used on some OS (e.g. Windows)
|
||||||
|
|||||||
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
class QSessionManager;
|
class QSessionManager;
|
||||||
|
|
||||||
class DeskflowApplication : public QApplication {
|
class DeskflowApplication : public QApplication
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
DeskflowApplication(int &argc, char **argv);
|
DeskflowApplication(int &argc, char **argv);
|
||||||
~DeskflowApplication() override = default;
|
~DeskflowApplication() override = default;
|
||||||
|
|||||||
@ -20,9 +20,12 @@
|
|||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
Hotkey::Hotkey() : m_KeySequence(), m_Actions() {}
|
Hotkey::Hotkey() : m_KeySequence(), m_Actions()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QString Hotkey::text() const {
|
QString Hotkey::text() const
|
||||||
|
{
|
||||||
QString text = keySequence().toString();
|
QString text = keySequence().toString();
|
||||||
|
|
||||||
if (keySequence().isMouseButton())
|
if (keySequence().isMouseButton())
|
||||||
@ -31,7 +34,8 @@ QString Hotkey::text() const {
|
|||||||
return "keystroke(" + text + ")";
|
return "keystroke(" + text + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hotkey::loadSettings(QSettings &settings) {
|
void Hotkey::loadSettings(QSettings &settings)
|
||||||
|
{
|
||||||
keySequence().loadSettings(settings);
|
keySequence().loadSettings(settings);
|
||||||
|
|
||||||
actions().clear();
|
actions().clear();
|
||||||
@ -46,7 +50,8 @@ void Hotkey::loadSettings(QSettings &settings) {
|
|||||||
settings.endArray();
|
settings.endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hotkey::saveSettings(QSettings &settings) const {
|
void Hotkey::saveSettings(QSettings &settings) const
|
||||||
|
{
|
||||||
keySequence().saveSettings(settings);
|
keySequence().saveSettings(settings);
|
||||||
|
|
||||||
settings.beginWriteArray("actions");
|
settings.beginWriteArray("actions");
|
||||||
@ -57,14 +62,15 @@ void Hotkey::saveSettings(QSettings &settings) const {
|
|||||||
settings.endArray();
|
settings.endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Hotkey::operator==(const Hotkey &hk) const {
|
bool Hotkey::operator==(const Hotkey &hk) const
|
||||||
|
{
|
||||||
return m_KeySequence == hk.m_KeySequence && m_Actions == hk.m_Actions;
|
return m_KeySequence == hk.m_KeySequence && m_Actions == hk.m_Actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey) {
|
QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey)
|
||||||
|
{
|
||||||
for (int i = 0; i < hotkey.actions().size(); i++)
|
for (int i = 0; i < hotkey.actions().size(); i++)
|
||||||
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i]
|
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i] << Qt::endl;
|
||||||
<< Qt::endl;
|
|
||||||
|
|
||||||
return outStream;
|
return outStream;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,8 @@ class HotkeyDialog;
|
|||||||
class ServerConfigDialog;
|
class ServerConfigDialog;
|
||||||
class QSettings;
|
class QSettings;
|
||||||
|
|
||||||
class Hotkey {
|
class Hotkey
|
||||||
|
{
|
||||||
friend class HotkeyDialog;
|
friend class HotkeyDialog;
|
||||||
friend class ServerConfigDialog;
|
friend class ServerConfigDialog;
|
||||||
friend QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey);
|
friend QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey);
|
||||||
@ -38,8 +39,14 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
QString text() const;
|
QString text() const;
|
||||||
const KeySequence &keySequence() const { return m_KeySequence; }
|
const KeySequence &keySequence() const
|
||||||
const ActionList &actions() const { return m_Actions; }
|
{
|
||||||
|
return m_KeySequence;
|
||||||
|
}
|
||||||
|
const ActionList &actions() const
|
||||||
|
{
|
||||||
|
return m_Actions;
|
||||||
|
}
|
||||||
|
|
||||||
void loadSettings(QSettings &settings);
|
void loadSettings(QSettings &settings);
|
||||||
void saveSettings(QSettings &settings) const;
|
void saveSettings(QSettings &settings) const;
|
||||||
@ -47,9 +54,18 @@ public:
|
|||||||
bool operator==(const Hotkey &hk) const;
|
bool operator==(const Hotkey &hk) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
KeySequence &keySequence() { return m_KeySequence; }
|
KeySequence &keySequence()
|
||||||
void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; }
|
{
|
||||||
ActionList &actions() { return m_Actions; }
|
return m_KeySequence;
|
||||||
|
}
|
||||||
|
void setKeySequence(const KeySequence &seq)
|
||||||
|
{
|
||||||
|
m_KeySequence = seq;
|
||||||
|
}
|
||||||
|
ActionList &actions()
|
||||||
|
{
|
||||||
|
return m_Actions;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeySequence m_KeySequence;
|
KeySequence m_KeySequence;
|
||||||
|
|||||||
@ -24,13 +24,15 @@
|
|||||||
HotkeyDialog::HotkeyDialog(QWidget *parent, Hotkey &hotkey)
|
HotkeyDialog::HotkeyDialog(QWidget *parent, Hotkey &hotkey)
|
||||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||||
Ui::HotkeyDialogBase(),
|
Ui::HotkeyDialogBase(),
|
||||||
m_Hotkey(hotkey) {
|
m_Hotkey(hotkey)
|
||||||
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
m_pKeySequenceWidgetHotkey->setText(m_Hotkey.text());
|
m_pKeySequenceWidgetHotkey->setText(m_Hotkey.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HotkeyDialog::accept() {
|
void HotkeyDialog::accept()
|
||||||
|
{
|
||||||
if (!sequenceWidget()->valid())
|
if (!sequenceWidget()->valid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -22,23 +22,31 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class HotkeyDialog : public QDialog, public Ui::HotkeyDialogBase {
|
class HotkeyDialog : public QDialog, public Ui::HotkeyDialogBase
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HotkeyDialog(QWidget *parent, Hotkey &hotkey);
|
HotkeyDialog(QWidget *parent, Hotkey &hotkey);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Hotkey &hotkey() const { return m_Hotkey; }
|
const Hotkey &hotkey() const
|
||||||
|
{
|
||||||
|
return m_Hotkey;
|
||||||
|
}
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void accept();
|
void accept();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const KeySequenceWidget *sequenceWidget() const {
|
const KeySequenceWidget *sequenceWidget() const
|
||||||
|
{
|
||||||
return m_pKeySequenceWidgetHotkey;
|
return m_pKeySequenceWidgetHotkey;
|
||||||
}
|
}
|
||||||
Hotkey &hotkey() { return m_Hotkey; }
|
Hotkey &hotkey()
|
||||||
|
{
|
||||||
|
return m_Hotkey;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Hotkey &m_Hotkey;
|
Hotkey &m_Hotkey;
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
// this table originally comes from Qt sources (gui/kernel/qkeysequence.cpp)
|
// this table originally comes from Qt sources (gui/kernel/qkeysequence.cpp)
|
||||||
// and is heavily modified for Deskflow
|
// and is heavily modified for Deskflow
|
||||||
static const struct {
|
static const struct
|
||||||
|
{
|
||||||
int key;
|
int key;
|
||||||
const char *name;
|
const char *name;
|
||||||
} keyname[] = {
|
} keyname[] = {
|
||||||
@ -75,15 +76,20 @@ static const struct {
|
|||||||
{Qt::Key_Launch1, "AppUser2"},
|
{Qt::Key_Launch1, "AppUser2"},
|
||||||
{Qt::Key_Select, "Select"},
|
{Qt::Key_Select, "Select"},
|
||||||
|
|
||||||
{0, 0}};
|
{0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
KeySequence::KeySequence() : m_Sequence(), m_Modifiers(0), m_IsValid(false) {}
|
KeySequence::KeySequence() : m_Sequence(), m_Modifiers(0), m_IsValid(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool KeySequence::isMouseButton() const {
|
bool KeySequence::isMouseButton() const
|
||||||
|
{
|
||||||
return !m_Sequence.isEmpty() && m_Sequence.last() < Qt::Key_Space;
|
return !m_Sequence.isEmpty() && m_Sequence.last() < Qt::Key_Space;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString KeySequence::toString() const {
|
QString KeySequence::toString() const
|
||||||
|
{
|
||||||
QString result;
|
QString result;
|
||||||
|
|
||||||
for (int i = 0; i < m_Sequence.size(); i++) {
|
for (int i = 0; i < m_Sequence.size(); i++) {
|
||||||
@ -96,9 +102,13 @@ QString KeySequence::toString() const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeySequence::appendMouseButton(int button) { return appendKey(button, 0); }
|
bool KeySequence::appendMouseButton(int button)
|
||||||
|
{
|
||||||
|
return appendKey(button, 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool KeySequence::appendKey(int key, int modifiers) {
|
bool KeySequence::appendKey(int key, int modifiers)
|
||||||
|
{
|
||||||
if (m_Sequence.size() == 4)
|
if (m_Sequence.size() == 4)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -131,7 +141,8 @@ bool KeySequence::appendKey(int key, int modifiers) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequence::loadSettings(QSettings &settings) {
|
void KeySequence::loadSettings(QSettings &settings)
|
||||||
|
{
|
||||||
sequence().clear();
|
sequence().clear();
|
||||||
int num = settings.beginReadArray("keys");
|
int num = settings.beginReadArray("keys");
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
@ -144,7 +155,8 @@ void KeySequence::loadSettings(QSettings &settings) {
|
|||||||
setValid(true);
|
setValid(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequence::saveSettings(QSettings &settings) const {
|
void KeySequence::saveSettings(QSettings &settings) const
|
||||||
|
{
|
||||||
settings.beginWriteArray("keys");
|
settings.beginWriteArray("keys");
|
||||||
for (int i = 0; i < sequence().size(); i++) {
|
for (int i = 0; i < sequence().size(); i++) {
|
||||||
settings.setArrayIndex(i);
|
settings.setArrayIndex(i);
|
||||||
@ -153,7 +165,8 @@ void KeySequence::saveSettings(QSettings &settings) const {
|
|||||||
settings.endArray();
|
settings.endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString KeySequence::keyToString(int key) {
|
QString KeySequence::keyToString(int key)
|
||||||
|
{
|
||||||
// nothing there?
|
// nothing there?
|
||||||
if (key == 0)
|
if (key == 0)
|
||||||
return "";
|
return "";
|
||||||
@ -208,14 +221,13 @@ QString KeySequence::keyToString(int key) {
|
|||||||
|
|
||||||
// representable in ucs2?
|
// representable in ucs2?
|
||||||
if (key < 0x10000)
|
if (key < 0x10000)
|
||||||
return QString("\\u%1").arg(
|
return QString("\\u%1").arg(QChar(key).toLower().unicode(), 4, 16, QChar('0'));
|
||||||
QChar(key).toLower().unicode(), 4, 16, QChar('0'));
|
|
||||||
|
|
||||||
// give up, deskflow probably won't handle this
|
// give up, deskflow probably won't handle this
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeySequence::operator==(const KeySequence &ks) const {
|
bool KeySequence::operator==(const KeySequence &ks) const
|
||||||
return m_Sequence == ks.m_Sequence && m_Modifiers == ks.m_Modifiers &&
|
{
|
||||||
m_IsValid == ks.m_IsValid;
|
return m_Sequence == ks.m_Sequence && m_Modifiers == ks.m_Modifiers && m_IsValid == ks.m_IsValid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
class QSettings;
|
class QSettings;
|
||||||
|
|
||||||
class KeySequence {
|
class KeySequence
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
KeySequence();
|
KeySequence();
|
||||||
|
|
||||||
@ -32,18 +33,36 @@ public:
|
|||||||
bool appendKey(int modifiers, int key);
|
bool appendKey(int modifiers, int key);
|
||||||
bool appendMouseButton(int button);
|
bool appendMouseButton(int button);
|
||||||
bool isMouseButton() const;
|
bool isMouseButton() const;
|
||||||
bool valid() const { return m_IsValid; }
|
bool valid() const
|
||||||
int modifiers() const { return m_Modifiers; }
|
{
|
||||||
|
return m_IsValid;
|
||||||
|
}
|
||||||
|
int modifiers() const
|
||||||
|
{
|
||||||
|
return m_Modifiers;
|
||||||
|
}
|
||||||
void saveSettings(QSettings &settings) const;
|
void saveSettings(QSettings &settings) const;
|
||||||
void loadSettings(QSettings &settings);
|
void loadSettings(QSettings &settings);
|
||||||
const QList<int> &sequence() const { return m_Sequence; }
|
const QList<int> &sequence() const
|
||||||
|
{
|
||||||
|
return m_Sequence;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const KeySequence &ks) const;
|
bool operator==(const KeySequence &ks) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setValid(bool b) { m_IsValid = b; }
|
void setValid(bool b)
|
||||||
void setModifiers(int i) { m_Modifiers = i; }
|
{
|
||||||
QList<int> &sequence() { return m_Sequence; }
|
m_IsValid = b;
|
||||||
|
}
|
||||||
|
void setModifiers(int i)
|
||||||
|
{
|
||||||
|
m_Modifiers = i;
|
||||||
|
}
|
||||||
|
QList<int> &sequence()
|
||||||
|
{
|
||||||
|
return m_Sequence;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<int> m_Sequence;
|
QList<int> m_Sequence;
|
||||||
|
|||||||
@ -29,12 +29,14 @@ KeySequenceWidget::KeySequenceWidget(QWidget *parent, const KeySequence &seq)
|
|||||||
m_MousePrefix("mousebutton("),
|
m_MousePrefix("mousebutton("),
|
||||||
m_MousePostfix(")"),
|
m_MousePostfix(")"),
|
||||||
m_KeyPrefix("keystroke("),
|
m_KeyPrefix("keystroke("),
|
||||||
m_KeyPostfix(")") {
|
m_KeyPostfix(")")
|
||||||
|
{
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
updateOutput();
|
updateOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequenceWidget::setKeySequence(const KeySequence &seq) {
|
void KeySequenceWidget::setKeySequence(const KeySequence &seq)
|
||||||
|
{
|
||||||
keySequence() = seq;
|
keySequence() = seq;
|
||||||
backupSequence() = seq;
|
backupSequence() = seq;
|
||||||
|
|
||||||
@ -42,7 +44,8 @@ void KeySequenceWidget::setKeySequence(const KeySequence &seq) {
|
|||||||
updateOutput();
|
updateOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequenceWidget::mousePressEvent(QMouseEvent *event) {
|
void KeySequenceWidget::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
||||||
if (status() == Stopped) {
|
if (status() == Stopped) {
|
||||||
@ -56,7 +59,8 @@ void KeySequenceWidget::mousePressEvent(QMouseEvent *event) {
|
|||||||
updateOutput();
|
updateOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequenceWidget::startRecording() {
|
void KeySequenceWidget::startRecording()
|
||||||
|
{
|
||||||
keySequence() = KeySequence();
|
keySequence() = KeySequence();
|
||||||
setDown(true);
|
setDown(true);
|
||||||
setFocus();
|
setFocus();
|
||||||
@ -64,7 +68,8 @@ void KeySequenceWidget::startRecording() {
|
|||||||
setStatus(Recording);
|
setStatus(Recording);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequenceWidget::stopRecording() {
|
void KeySequenceWidget::stopRecording()
|
||||||
|
{
|
||||||
if (!keySequence().valid()) {
|
if (!keySequence().valid()) {
|
||||||
keySequence() = backupSequence();
|
keySequence() = backupSequence();
|
||||||
updateOutput();
|
updateOutput();
|
||||||
@ -77,7 +82,8 @@ void KeySequenceWidget::stopRecording() {
|
|||||||
emit keySequenceChanged();
|
emit keySequenceChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeySequenceWidget::event(QEvent *event) {
|
bool KeySequenceWidget::event(QEvent *event)
|
||||||
|
{
|
||||||
if (status() == Recording) {
|
if (status() == Recording) {
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::KeyPress:
|
case QEvent::KeyPress:
|
||||||
@ -108,7 +114,8 @@ bool KeySequenceWidget::event(QEvent *event) {
|
|||||||
return QPushButton::event(event);
|
return QPushButton::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequenceWidget::keyPressEvent(QKeyEvent *event) {
|
void KeySequenceWidget::keyPressEvent(QKeyEvent *event)
|
||||||
|
{
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
||||||
if (status() == Stopped)
|
if (status() == Stopped)
|
||||||
@ -120,7 +127,8 @@ void KeySequenceWidget::keyPressEvent(QKeyEvent *event) {
|
|||||||
updateOutput();
|
updateOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeySequenceWidget::updateOutput() {
|
void KeySequenceWidget::updateOutput()
|
||||||
|
{
|
||||||
QString s;
|
QString s;
|
||||||
|
|
||||||
if (m_KeySequence.isMouseButton())
|
if (m_KeySequence.isMouseButton())
|
||||||
|
|||||||
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
#include "KeySequence.h"
|
#include "KeySequence.h"
|
||||||
|
|
||||||
class KeySequenceWidget : public QPushButton {
|
class KeySequenceWidget : public QPushButton
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -31,21 +32,54 @@ signals:
|
|||||||
void keySequenceChanged();
|
void keySequenceChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const QString &mousePrefix() const { return m_MousePrefix; }
|
const QString &mousePrefix() const
|
||||||
const QString &mousePostfix() const { return m_MousePostfix; }
|
{
|
||||||
const QString &keyPrefix() const { return m_KeyPrefix; }
|
return m_MousePrefix;
|
||||||
const QString &keyPostfix() const { return m_KeyPostfix; }
|
}
|
||||||
|
const QString &mousePostfix() const
|
||||||
|
{
|
||||||
|
return m_MousePostfix;
|
||||||
|
}
|
||||||
|
const QString &keyPrefix() const
|
||||||
|
{
|
||||||
|
return m_KeyPrefix;
|
||||||
|
}
|
||||||
|
const QString &keyPostfix() const
|
||||||
|
{
|
||||||
|
return m_KeyPostfix;
|
||||||
|
}
|
||||||
|
|
||||||
void setMousePrefix(const QString &s) { m_MousePrefix = s; }
|
void setMousePrefix(const QString &s)
|
||||||
void setMousePostfix(const QString &s) { m_MousePostfix = s; }
|
{
|
||||||
void setKeyPrefix(const QString &s) { m_KeyPrefix = s; }
|
m_MousePrefix = s;
|
||||||
void setKeyPostfix(const QString &s) { m_KeyPostfix = s; }
|
}
|
||||||
|
void setMousePostfix(const QString &s)
|
||||||
|
{
|
||||||
|
m_MousePostfix = s;
|
||||||
|
}
|
||||||
|
void setKeyPrefix(const QString &s)
|
||||||
|
{
|
||||||
|
m_KeyPrefix = s;
|
||||||
|
}
|
||||||
|
void setKeyPostfix(const QString &s)
|
||||||
|
{
|
||||||
|
m_KeyPostfix = s;
|
||||||
|
}
|
||||||
|
|
||||||
const KeySequence &keySequence() const { return m_KeySequence; }
|
const KeySequence &keySequence() const
|
||||||
const KeySequence &backupSequence() const { return m_BackupSequence; }
|
{
|
||||||
|
return m_KeySequence;
|
||||||
|
}
|
||||||
|
const KeySequence &backupSequence() const
|
||||||
|
{
|
||||||
|
return m_BackupSequence;
|
||||||
|
}
|
||||||
void setKeySequence(const KeySequence &seq);
|
void setKeySequence(const KeySequence &seq);
|
||||||
|
|
||||||
bool valid() const { return keySequence().valid(); }
|
bool valid() const
|
||||||
|
{
|
||||||
|
return keySequence().valid();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *);
|
void mousePressEvent(QMouseEvent *);
|
||||||
@ -55,13 +89,29 @@ protected:
|
|||||||
void updateOutput();
|
void updateOutput();
|
||||||
void startRecording();
|
void startRecording();
|
||||||
void stopRecording();
|
void stopRecording();
|
||||||
KeySequence &keySequence() { return m_KeySequence; }
|
KeySequence &keySequence()
|
||||||
KeySequence &backupSequence() { return m_BackupSequence; }
|
{
|
||||||
|
return m_KeySequence;
|
||||||
|
}
|
||||||
|
KeySequence &backupSequence()
|
||||||
|
{
|
||||||
|
return m_BackupSequence;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Status { Stopped, Recording };
|
enum Status
|
||||||
void setStatus(Status s) { m_Status = s; }
|
{
|
||||||
Status status() const { return m_Status; }
|
Stopped,
|
||||||
|
Recording
|
||||||
|
};
|
||||||
|
void setStatus(Status s)
|
||||||
|
{
|
||||||
|
m_Status = s;
|
||||||
|
}
|
||||||
|
Status status() const
|
||||||
|
{
|
||||||
|
return m_Status;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KeySequence m_KeySequence;
|
KeySequence m_KeySequence;
|
||||||
|
|||||||
@ -76,11 +76,11 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
|
|||||||
m_AppConfig(appConfig),
|
m_AppConfig(appConfig),
|
||||||
m_ServerConfig(appConfig, *this),
|
m_ServerConfig(appConfig, *this),
|
||||||
m_CoreProcess(appConfig, m_ServerConfig),
|
m_CoreProcess(appConfig, m_ServerConfig),
|
||||||
m_ServerConnection(
|
m_ServerConnection(this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
||||||
this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
|
||||||
m_ClientConnection(this, appConfig),
|
m_ClientConnection(this, appConfig),
|
||||||
m_TlsUtility(appConfig),
|
m_TlsUtility(appConfig),
|
||||||
m_WindowSaveTimer(this) {
|
m_WindowSaveTimer(this)
|
||||||
|
{
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
createMenuBar();
|
createMenuBar();
|
||||||
@ -91,9 +91,13 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
|
|||||||
emit created();
|
emit created();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() { m_CoreProcess.cleanup(); }
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
m_CoreProcess.cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::restoreWindow() {
|
void MainWindow::restoreWindow()
|
||||||
|
{
|
||||||
|
|
||||||
const auto &windowSize = m_AppConfig.mainWindowSize();
|
const auto &windowSize = m_AppConfig.mainWindowSize();
|
||||||
if (windowSize.has_value()) {
|
if (windowSize.has_value()) {
|
||||||
@ -118,7 +122,8 @@ void MainWindow::restoreWindow() {
|
|||||||
m_SaveWindow = true;
|
m_SaveWindow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::saveWindow() {
|
void MainWindow::saveWindow()
|
||||||
|
{
|
||||||
if (!m_SaveWindow) {
|
if (!m_SaveWindow) {
|
||||||
qDebug("not yet ready to save window size and position, skipping");
|
qDebug("not yet ready to save window size and position, skipping");
|
||||||
return;
|
return;
|
||||||
@ -130,7 +135,8 @@ void MainWindow::saveWindow() {
|
|||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setupControls() {
|
void MainWindow::setupControls()
|
||||||
|
{
|
||||||
setWindowTitle(kAppName);
|
setWindowTitle(kAppName);
|
||||||
|
|
||||||
m_pActionHelp->setText(DESKFLOW_HELP_TEXT);
|
m_pActionHelp->setText(DESKFLOW_HELP_TEXT);
|
||||||
@ -144,8 +150,7 @@ void MainWindow::setupControls() {
|
|||||||
m_pLabelNotice->setStyleSheet(kStyleNoticeLabel);
|
m_pLabelNotice->setStyleSheet(kStyleNoticeLabel);
|
||||||
m_pLabelNotice->hide();
|
m_pLabelNotice->hide();
|
||||||
|
|
||||||
m_pLabelIpAddresses->setText(
|
m_pLabelIpAddresses->setText(QString("This computer's IP addresses: %1").arg(getIPAddresses()));
|
||||||
QString("This computer's IP addresses: %1").arg(getIPAddresses()));
|
|
||||||
|
|
||||||
if (m_AppConfig.lastVersion() != DESKFLOW_VERSION) {
|
if (m_AppConfig.lastVersion() != DESKFLOW_VERSION) {
|
||||||
m_AppConfig.setLastVersion(DESKFLOW_VERSION);
|
m_AppConfig.setLastVersion(DESKFLOW_VERSION);
|
||||||
@ -166,63 +171,47 @@ void MainWindow::setupControls() {
|
|||||||
// remember: using queued connection allows the render loop to run before
|
// remember: using queued connection allows the render loop to run before
|
||||||
// executing the slot. the default is to instantly call the slot when the
|
// executing the slot. the default is to instantly call the slot when the
|
||||||
// signal is emitted from the thread that owns the receiver's object.
|
// signal is emitted from the thread that owns the receiver's object.
|
||||||
void MainWindow::connectSlots() {
|
void MainWindow::connectSlots()
|
||||||
|
{
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
&Logger::instance(), &Logger::newLine, this, //
|
&Logger::instance(), &Logger::newLine, this, //
|
||||||
[this](const QString &line) { handleLogLine(line); });
|
[this](const QString &line) { handleLogLine(line); }
|
||||||
|
);
|
||||||
|
|
||||||
connect(this, &MainWindow::created, this, &MainWindow::onCreated);
|
connect(this, &MainWindow::created, this, &MainWindow::onCreated);
|
||||||
|
|
||||||
connect(
|
connect(this, &MainWindow::shown, this, &MainWindow::onShown, Qt::QueuedConnection);
|
||||||
this, &MainWindow::shown, this, &MainWindow::onShown,
|
|
||||||
Qt::QueuedConnection);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_ConfigScopes, &ConfigScopes::saving, this, &MainWindow::onConfigScopesSaving, Qt::DirectConnection);
|
||||||
&m_ConfigScopes, &ConfigScopes::saving, this,
|
|
||||||
&MainWindow::onConfigScopesSaving, Qt::DirectConnection);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_AppConfig, &AppConfig::tlsChanged, this, &MainWindow::onAppConfigTlsChanged);
|
||||||
&m_AppConfig, &AppConfig::tlsChanged, this,
|
|
||||||
&MainWindow::onAppConfigTlsChanged);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_AppConfig, &AppConfig::screenNameChanged, this, &MainWindow::onAppConfigScreenNameChanged);
|
||||||
&m_AppConfig, &AppConfig::screenNameChanged, this,
|
|
||||||
&MainWindow::onAppConfigScreenNameChanged);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_AppConfig, &AppConfig::invertConnectionChanged, this, &MainWindow::onAppConfigInvertConnection);
|
||||||
&m_AppConfig, &AppConfig::invertConnectionChanged, this,
|
|
||||||
&MainWindow::onAppConfigInvertConnection);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_CoreProcess, &CoreProcess::starting, this, &MainWindow::onCoreProcessStarting, Qt::DirectConnection);
|
||||||
&m_CoreProcess, &CoreProcess::starting, this,
|
|
||||||
&MainWindow::onCoreProcessStarting, Qt::DirectConnection);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_CoreProcess, &CoreProcess::error, this, &MainWindow::onCoreProcessError);
|
||||||
&m_CoreProcess, &CoreProcess::error, this,
|
|
||||||
&MainWindow::onCoreProcessError);
|
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
&m_CoreProcess, &CoreProcess::logLine, //
|
&m_CoreProcess, &CoreProcess::logLine, //
|
||||||
[this](const QString &line) { handleLogLine(line); });
|
[this](const QString &line) { handleLogLine(line); }
|
||||||
|
);
|
||||||
|
|
||||||
connect(
|
connect(&m_CoreProcess, &CoreProcess::processStateChanged, this, &MainWindow::onCoreProcessStateChanged);
|
||||||
&m_CoreProcess, &CoreProcess::processStateChanged, this,
|
|
||||||
&MainWindow::onCoreProcessStateChanged);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_CoreProcess, &CoreProcess::connectionStateChanged, this, &MainWindow::onCoreConnectionStateChanged);
|
||||||
&m_CoreProcess, &CoreProcess::connectionStateChanged, this,
|
|
||||||
&MainWindow::onCoreConnectionStateChanged);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_CoreProcess, &CoreProcess::secureSocket, this, &MainWindow::onCoreProcessSecureSocket);
|
||||||
&m_CoreProcess, &CoreProcess::secureSocket, this,
|
|
||||||
&MainWindow::onCoreProcessSecureSocket);
|
|
||||||
|
|
||||||
connect(m_pActionMinimize, &QAction::triggered, this, &MainWindow::hide);
|
connect(m_pActionMinimize, &QAction::triggered, this, &MainWindow::hide);
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
m_pActionRestore, &QAction::triggered, //
|
m_pActionRestore, &QAction::triggered, //
|
||||||
[this]() { showAndActivate(); });
|
[this]() { showAndActivate(); }
|
||||||
|
);
|
||||||
|
|
||||||
connect(m_pActionQuit, &QAction::triggered, qApp, [this] {
|
connect(m_pActionQuit, &QAction::triggered, qApp, [this] {
|
||||||
qDebug("quitting application");
|
qDebug("quitting application");
|
||||||
@ -230,38 +219,30 @@ void MainWindow::connectSlots() {
|
|||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(
|
connect(&m_VersionChecker, &VersionChecker::updateFound, this, &MainWindow::onVersionCheckerUpdateFound);
|
||||||
&m_VersionChecker, &VersionChecker::updateFound, this,
|
|
||||||
&MainWindow::onVersionCheckerUpdateFound);
|
connect(&m_WindowSaveTimer, &QTimer::timeout, this, &MainWindow::onWindowSaveTimerTimeout);
|
||||||
|
|
||||||
|
connect(&m_TrayIcon, &TrayIcon::activated, this, &MainWindow::onTrayIconActivated);
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
&m_WindowSaveTimer, &QTimer::timeout, this,
|
&m_ServerConnection, &ServerConnection::configureClient, this, &MainWindow::onServerConnectionConfigureClient
|
||||||
&MainWindow::onWindowSaveTimerTimeout);
|
);
|
||||||
|
|
||||||
connect(
|
connect(&m_ServerConnection, &ServerConnection::messageShowing, this, [this]() { showAndActivate(); });
|
||||||
&m_TrayIcon, &TrayIcon::activated, this,
|
|
||||||
&MainWindow::onTrayIconActivated);
|
|
||||||
|
|
||||||
connect(
|
connect(&m_ClientConnection, &ClientConnection::messageShowing, this, [this]() { showAndActivate(); });
|
||||||
&m_ServerConnection, &ServerConnection::configureClient, this,
|
|
||||||
&MainWindow::onServerConnectionConfigureClient);
|
|
||||||
|
|
||||||
connect(
|
|
||||||
&m_ServerConnection, &ServerConnection::messageShowing, this,
|
|
||||||
[this]() { showAndActivate(); });
|
|
||||||
|
|
||||||
connect(
|
|
||||||
&m_ClientConnection, &ClientConnection::messageShowing, this,
|
|
||||||
[this]() { showAndActivate(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onAppAboutToQuit() {
|
void MainWindow::onAppAboutToQuit()
|
||||||
|
{
|
||||||
if (m_SaveOnExit) {
|
if (m_SaveOnExit) {
|
||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCreated() {
|
void MainWindow::onCreated()
|
||||||
|
{
|
||||||
|
|
||||||
setIcon();
|
setIcon();
|
||||||
|
|
||||||
@ -273,11 +254,11 @@ void MainWindow::onCreated() {
|
|||||||
applyConfig();
|
applyConfig();
|
||||||
restoreWindow();
|
restoreWindow();
|
||||||
|
|
||||||
qDebug().noquote() << "active settings path:"
|
qDebug().noquote() << "active settings path:" << m_ConfigScopes.activeFilePath();
|
||||||
<< m_ConfigScopes.activeFilePath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onShown() {
|
void MainWindow::onShown()
|
||||||
|
{
|
||||||
// if a critical error was shown just before the main window (i.e. on app
|
// if a critical error was shown just before the main window (i.e. on app
|
||||||
// load), it will be hidden behind the main window. therefore we need to raise
|
// load), it will be hidden behind the main window. therefore we need to raise
|
||||||
// it up in front of the main window.
|
// it up in front of the main window.
|
||||||
@ -286,20 +267,24 @@ void MainWindow::onShown() {
|
|||||||
// this we delay the error dialog raise by a split second. this seems a bit
|
// this we delay the error dialog raise by a split second. this seems a bit
|
||||||
// hacky and fragile, so maybe there's a better approach.
|
// hacky and fragile, so maybe there's a better approach.
|
||||||
const auto kCriticalDialogDelay = 100;
|
const auto kCriticalDialogDelay = 100;
|
||||||
QTimer::singleShot(
|
QTimer::singleShot(kCriticalDialogDelay, [] { messages::raiseCriticalDialog(); });
|
||||||
kCriticalDialogDelay, [] { messages::raiseCriticalDialog(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onConfigScopesSaving() { m_ServerConfig.commit(); }
|
void MainWindow::onConfigScopesSaving()
|
||||||
|
{
|
||||||
|
m_ServerConfig.commit();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onAppConfigTlsChanged() {
|
void MainWindow::onAppConfigTlsChanged()
|
||||||
|
{
|
||||||
updateLocalFingerprint();
|
updateLocalFingerprint();
|
||||||
if (m_TlsUtility.isEnabled()) {
|
if (m_TlsUtility.isEnabled()) {
|
||||||
m_TlsUtility.generateCertificate();
|
m_TlsUtility.generateCertificate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) {
|
void MainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||||
|
{
|
||||||
|
|
||||||
if (reason == QSystemTrayIcon::DoubleClick) {
|
if (reason == QSystemTrayIcon::DoubleClick) {
|
||||||
if (isVisible()) {
|
if (isVisible()) {
|
||||||
@ -310,54 +295,66 @@ void MainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onVersionCheckerUpdateFound(const QString &version) {
|
void MainWindow::onVersionCheckerUpdateFound(const QString &version)
|
||||||
|
{
|
||||||
const auto link = QString(kLinkDownload).arg(kUrlDownload, kColorWhite);
|
const auto link = QString(kLinkDownload).arg(kUrlDownload, kColorWhite);
|
||||||
const auto text =
|
const auto text = QString("A new version is available (v%1). %2").arg(version, link);
|
||||||
QString("A new version is available (v%1). %2").arg(version, link);
|
|
||||||
|
|
||||||
m_pLabelUpdate->show();
|
m_pLabelUpdate->show();
|
||||||
m_pLabelUpdate->setText(text);
|
m_pLabelUpdate->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onAppConfigScreenNameChanged() { updateScreenName(); }
|
void MainWindow::onAppConfigScreenNameChanged()
|
||||||
|
{
|
||||||
|
updateScreenName();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onAppConfigInvertConnection() { applyConfig(); }
|
void MainWindow::onAppConfigInvertConnection()
|
||||||
|
{
|
||||||
|
applyConfig();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onCoreProcessError(CoreProcess::Error error) {
|
void MainWindow::onCoreProcessError(CoreProcess::Error error)
|
||||||
|
{
|
||||||
if (error == CoreProcess::Error::AddressMissing) {
|
if (error == CoreProcess::Error::AddressMissing) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this, QString("Address missing"),
|
this, QString("Address missing"), QString("Please enter the hostname or IP address of the other computer.")
|
||||||
QString(
|
);
|
||||||
"Please enter the hostname or IP address of the other computer."));
|
|
||||||
} else if (error == CoreProcess::Error::StartFailed) {
|
} else if (error == CoreProcess::Error::StartFailed) {
|
||||||
show();
|
show();
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this, QString("Core cannot be started"),
|
this, QString("Core cannot be started"),
|
||||||
"The Core executable could not be successfully started, "
|
"The Core executable could not be successfully started, "
|
||||||
"although it does exist. "
|
"although it does exist. "
|
||||||
"Please check if you have sufficient permissions to run this program.");
|
"Please check if you have sufficient permissions to run this program."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionStartCore_triggered() {
|
void MainWindow::on_m_pActionStartCore_triggered()
|
||||||
|
{
|
||||||
m_ClientConnection.setShowMessage();
|
m_ClientConnection.setShowMessage();
|
||||||
m_CoreProcess.start();
|
m_CoreProcess.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionStopCore_triggered() {
|
void MainWindow::on_m_pActionStopCore_triggered()
|
||||||
|
{
|
||||||
qDebug("stopping core process");
|
qDebug("stopping core process");
|
||||||
m_CoreProcess.stop();
|
m_CoreProcess.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionTestFatalError_triggered() const {
|
void MainWindow::on_m_pActionTestFatalError_triggered() const
|
||||||
|
{
|
||||||
qFatal("test fatal error");
|
qFatal("test fatal error");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionTestCriticalError_triggered() const {
|
void MainWindow::on_m_pActionTestCriticalError_triggered() const
|
||||||
|
{
|
||||||
qCritical("test critical error");
|
qCritical("test critical error");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionClearSettings_triggered() {
|
void MainWindow::on_m_pActionClearSettings_triggered()
|
||||||
|
{
|
||||||
if (!messages::showClearSettings(this)) {
|
if (!messages::showClearSettings(this)) {
|
||||||
qDebug("clear settings cancelled");
|
qDebug("clear settings cancelled");
|
||||||
return;
|
return;
|
||||||
@ -370,32 +367,32 @@ void MainWindow::on_m_pActionClearSettings_triggered() {
|
|||||||
diagnostic::clearSettings(m_ConfigScopes, true);
|
diagnostic::clearSettings(m_ConfigScopes, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainWindow::on_m_pActionSave_triggered() {
|
bool MainWindow::on_m_pActionSave_triggered()
|
||||||
QString fileName =
|
{
|
||||||
QFileDialog::getSaveFileName(this, QString("Save configuration as..."));
|
QString fileName = QFileDialog::getSaveFileName(this, QString("Save configuration as..."));
|
||||||
|
|
||||||
if (!fileName.isEmpty() && !m_ServerConfig.save(fileName)) {
|
if (!fileName.isEmpty() && !m_ServerConfig.save(fileName)) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(this, QString("Save failed"), QString("Could not save configuration to file."));
|
||||||
this, QString("Save failed"),
|
|
||||||
QString("Could not save configuration to file."));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionAbout_triggered() {
|
void MainWindow::on_m_pActionAbout_triggered()
|
||||||
|
{
|
||||||
AboutDialog about(this);
|
AboutDialog about(this);
|
||||||
about.exec();
|
about.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionHelp_triggered() const {
|
void MainWindow::on_m_pActionHelp_triggered() const
|
||||||
|
{
|
||||||
QDesktopServices::openUrl(QUrl(kUrlHelp));
|
QDesktopServices::openUrl(QUrl(kUrlHelp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pActionSettings_triggered() {
|
void MainWindow::on_m_pActionSettings_triggered()
|
||||||
auto dialog =
|
{
|
||||||
SettingsDialog(this, m_AppConfig, m_ServerConfig, m_CoreProcess);
|
auto dialog = SettingsDialog(this, m_AppConfig, m_ServerConfig, m_CoreProcess);
|
||||||
|
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
@ -409,61 +406,78 @@ void MainWindow::on_m_pActionSettings_triggered() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pButtonConfigureServer_clicked() {
|
void MainWindow::on_m_pButtonConfigureServer_clicked()
|
||||||
|
{
|
||||||
showConfigureServer();
|
showConfigureServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pLineEditHostname_returnPressed() {
|
void MainWindow::on_m_pLineEditHostname_returnPressed()
|
||||||
|
{
|
||||||
m_pButtonConnect->click();
|
m_pButtonConnect->click();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pLineEditClientIp_returnPressed() {
|
void MainWindow::on_m_pLineEditClientIp_returnPressed()
|
||||||
|
{
|
||||||
m_pButtonConnectToClient->click();
|
m_pButtonConnectToClient->click();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pLineEditHostname_textChanged(const QString &text) {
|
void MainWindow::on_m_pLineEditHostname_textChanged(const QString &text)
|
||||||
|
{
|
||||||
m_CoreProcess.setAddress(text);
|
m_CoreProcess.setAddress(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pLineEditClientIp_textChanged(const QString &text) {
|
void MainWindow::on_m_pLineEditClientIp_textChanged(const QString &text)
|
||||||
|
{
|
||||||
m_CoreProcess.setAddress(text);
|
m_CoreProcess.setAddress(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pButtonApply_clicked() {
|
void MainWindow::on_m_pButtonApply_clicked()
|
||||||
|
{
|
||||||
m_ClientConnection.setShowMessage();
|
m_ClientConnection.setShowMessage();
|
||||||
m_CoreProcess.restart();
|
m_CoreProcess.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pLabelComputerName_linkActivated(const QString &) {
|
void MainWindow::on_m_pLabelComputerName_linkActivated(const QString &)
|
||||||
|
{
|
||||||
m_pActionSettings->trigger();
|
m_pActionSettings->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pLabelFingerprint_linkActivated(const QString &) {
|
void MainWindow::on_m_pLabelFingerprint_linkActivated(const QString &)
|
||||||
QMessageBox::information(
|
{
|
||||||
this, "TLS fingerprint", TlsFingerprint::local().readFirst());
|
QMessageBox::information(this, "TLS fingerprint", TlsFingerprint::local().readFirst());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pRadioGroupServer_clicked(bool) {
|
void MainWindow::on_m_pRadioGroupServer_clicked(bool)
|
||||||
|
{
|
||||||
enableServer(true);
|
enableServer(true);
|
||||||
enableClient(false);
|
enableClient(false);
|
||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pRadioGroupClient_clicked(bool) {
|
void MainWindow::on_m_pRadioGroupClient_clicked(bool)
|
||||||
|
{
|
||||||
enableClient(true);
|
enableClient(true);
|
||||||
enableServer(false);
|
enableServer(false);
|
||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_m_pButtonConnect_clicked() { on_m_pButtonApply_clicked(); }
|
void MainWindow::on_m_pButtonConnect_clicked()
|
||||||
|
{
|
||||||
void MainWindow::on_m_pButtonConnectToClient_clicked() {
|
|
||||||
on_m_pButtonApply_clicked();
|
on_m_pButtonApply_clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onWindowSaveTimerTimeout() { saveWindow(); }
|
void MainWindow::on_m_pButtonConnectToClient_clicked()
|
||||||
|
{
|
||||||
|
on_m_pButtonApply_clicked();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onServerConnectionConfigureClient(const QString &clientName) {
|
void MainWindow::onWindowSaveTimerTimeout()
|
||||||
|
{
|
||||||
|
saveWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onServerConnectionConfigureClient(const QString &clientName)
|
||||||
|
{
|
||||||
m_ServerConfigDialogState.setVisible(true);
|
m_ServerConfigDialogState.setVisible(true);
|
||||||
ServerConfigDialog dialog(this, m_ServerConfig, m_AppConfig);
|
ServerConfigDialog dialog(this, m_ServerConfig, m_AppConfig);
|
||||||
if (dialog.addClient(clientName) && dialog.exec() == QDialog::Accepted) {
|
if (dialog.addClient(clientName) && dialog.exec() == QDialog::Accepted) {
|
||||||
@ -476,7 +490,8 @@ void MainWindow::onServerConnectionConfigureClient(const QString &clientName) {
|
|||||||
// End slots
|
// End slots
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void MainWindow::resizeEvent(QResizeEvent *event) {
|
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
QMainWindow::resizeEvent(event);
|
QMainWindow::resizeEvent(event);
|
||||||
|
|
||||||
// postpone save so that settings are not written every delta change.
|
// postpone save so that settings are not written every delta change.
|
||||||
@ -484,7 +499,8 @@ void MainWindow::resizeEvent(QResizeEvent *event) {
|
|||||||
m_WindowSaveTimer.start(1000);
|
m_WindowSaveTimer.start(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::moveEvent(QMoveEvent *event) {
|
void MainWindow::moveEvent(QMoveEvent *event)
|
||||||
|
{
|
||||||
QMainWindow::moveEvent(event);
|
QMainWindow::moveEvent(event);
|
||||||
|
|
||||||
// postpone save so that settings are not written every delta change.
|
// postpone save so that settings are not written every delta change.
|
||||||
@ -492,11 +508,11 @@ void MainWindow::moveEvent(QMoveEvent *event) {
|
|||||||
m_WindowSaveTimer.start(1000);
|
m_WindowSaveTimer.start(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::open() {
|
void MainWindow::open()
|
||||||
|
{
|
||||||
|
|
||||||
std::vector<QAction *> trayMenu = {
|
std::vector<QAction *> trayMenu = {m_pActionStartCore, m_pActionStopCore, nullptr, m_pActionMinimize,
|
||||||
m_pActionStartCore, m_pActionStopCore, nullptr, m_pActionMinimize,
|
m_pActionRestore, nullptr, m_pActionQuit};
|
||||||
m_pActionRestore, nullptr, m_pActionQuit};
|
|
||||||
|
|
||||||
m_TrayIcon.create(trayMenu);
|
m_TrayIcon.create(trayMenu);
|
||||||
|
|
||||||
@ -521,7 +537,8 @@ void MainWindow::open() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCoreProcessStarting() {
|
void MainWindow::onCoreProcessStarting()
|
||||||
|
{
|
||||||
|
|
||||||
#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI)
|
#if defined(WINAPI_XWINDOWS) or defined(WINAPI_LIBEI)
|
||||||
if (deskflow::platform::isWayland()) {
|
if (deskflow::platform::isWayland()) {
|
||||||
@ -532,11 +549,13 @@ void MainWindow::onCoreProcessStarting() {
|
|||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setStatus(const QString &status) {
|
void MainWindow::setStatus(const QString &status)
|
||||||
|
{
|
||||||
m_pStatusLabel->setText(status);
|
m_pStatusLabel->setText(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createMenuBar() {
|
void MainWindow::createMenuBar()
|
||||||
|
{
|
||||||
m_pMenuBar = new QMenuBar(this);
|
m_pMenuBar = new QMenuBar(this);
|
||||||
m_pMenuFile = new QMenu("File", m_pMenuBar);
|
m_pMenuFile = new QMenu("File", m_pMenuBar);
|
||||||
m_pMenuEdit = new QMenu("Edit", m_pMenuBar);
|
m_pMenuEdit = new QMenu("Edit", m_pMenuBar);
|
||||||
@ -569,8 +588,7 @@ void MainWindow::createMenuBar() {
|
|||||||
|
|
||||||
m_pActionAbout->setText(QString("About %1...").arg(kAppName));
|
m_pActionAbout->setText(QString("About %1...").arg(kAppName));
|
||||||
|
|
||||||
const auto enableTestMenu =
|
const auto enableTestMenu = strToTrue(qEnvironmentVariable("DESKFLOW_TEST_MENU"));
|
||||||
strToTrue(qEnvironmentVariable("DESKFLOW_TEST_MENU"));
|
|
||||||
|
|
||||||
if (enableTestMenu || kDebugBuild) {
|
if (enableTestMenu || kDebugBuild) {
|
||||||
auto testMenu = new QMenu("Test", m_pMenuBar);
|
auto testMenu = new QMenu("Test", m_pMenuBar);
|
||||||
@ -582,7 +600,8 @@ void MainWindow::createMenuBar() {
|
|||||||
setMenuBar(m_pMenuBar);
|
setMenuBar(m_pMenuBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::applyConfig() {
|
void MainWindow::applyConfig()
|
||||||
|
{
|
||||||
enableServer(m_AppConfig.serverGroupChecked());
|
enableServer(m_AppConfig.serverGroupChecked());
|
||||||
enableClient(m_AppConfig.clientGroupChecked());
|
enableClient(m_AppConfig.clientGroupChecked());
|
||||||
|
|
||||||
@ -590,11 +609,13 @@ void MainWindow::applyConfig() {
|
|||||||
m_pLineEditClientIp->setText(m_ServerConfig.getClientAddress());
|
m_pLineEditClientIp->setText(m_ServerConfig.getClientAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::applyCloseToTray() const {
|
void MainWindow::applyCloseToTray() const
|
||||||
|
{
|
||||||
QApplication::setQuitOnLastWindowClosed(!m_AppConfig.closeToTray());
|
QApplication::setQuitOnLastWindowClosed(!m_AppConfig.closeToTray());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::saveSettings() {
|
void MainWindow::saveSettings()
|
||||||
|
{
|
||||||
m_AppConfig.setServerGroupChecked(m_pRadioGroupServer->isChecked());
|
m_AppConfig.setServerGroupChecked(m_pRadioGroupServer->isChecked());
|
||||||
m_AppConfig.setClientGroupChecked(m_pRadioGroupClient->isChecked());
|
m_AppConfig.setClientGroupChecked(m_pRadioGroupClient->isChecked());
|
||||||
m_AppConfig.setServerHostname(m_pLineEditHostname->text());
|
m_AppConfig.setServerHostname(m_pLineEditHostname->text());
|
||||||
@ -603,7 +624,8 @@ void MainWindow::saveSettings() {
|
|||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setIcon() {
|
void MainWindow::setIcon()
|
||||||
|
{
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
switch (getOSXIconsTheme()) {
|
switch (getOSXIconsTheme()) {
|
||||||
@ -626,14 +648,14 @@ void MainWindow::setIcon() {
|
|||||||
m_TrayIcon.setIcon(icon);
|
m_TrayIcon.setIcon(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::handleLogLine(const QString &line) {
|
void MainWindow::handleLogLine(const QString &line)
|
||||||
|
{
|
||||||
const int kScrollBottomThreshold = 2;
|
const int kScrollBottomThreshold = 2;
|
||||||
|
|
||||||
QScrollBar *verticalScroll = m_pLogOutput->verticalScrollBar();
|
QScrollBar *verticalScroll = m_pLogOutput->verticalScrollBar();
|
||||||
int currentScroll = verticalScroll->value();
|
int currentScroll = verticalScroll->value();
|
||||||
int maxScroll = verticalScroll->maximum();
|
int maxScroll = verticalScroll->maximum();
|
||||||
const auto scrollAtBottom =
|
const auto scrollAtBottom = qAbs(currentScroll - maxScroll) <= kScrollBottomThreshold;
|
||||||
qAbs(currentScroll - maxScroll) <= kScrollBottomThreshold;
|
|
||||||
|
|
||||||
// only trim end instead of the whole line to prevent tab-indented debug
|
// only trim end instead of the whole line to prevent tab-indented debug
|
||||||
// filenames from losing their indentation.
|
// filenames from losing their indentation.
|
||||||
@ -647,12 +669,14 @@ void MainWindow::handleLogLine(const QString &line) {
|
|||||||
updateFromLogLine(line);
|
updateFromLogLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateFromLogLine(const QString &line) {
|
void MainWindow::updateFromLogLine(const QString &line)
|
||||||
|
{
|
||||||
checkConnected(line);
|
checkConnected(line);
|
||||||
checkFingerprint(line);
|
checkFingerprint(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkConnected(const QString &line) {
|
void MainWindow::checkConnected(const QString &line)
|
||||||
|
{
|
||||||
if (m_pRadioGroupServer->isChecked()) {
|
if (m_pRadioGroupServer->isChecked()) {
|
||||||
m_ServerConnection.handleLogLine(line);
|
m_ServerConnection.handleLogLine(line);
|
||||||
m_pLabelServerState->updateServerState(line);
|
m_pLabelServerState->updateServerState(line);
|
||||||
@ -662,7 +686,8 @@ void MainWindow::checkConnected(const QString &line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::checkFingerprint(const QString &line) {
|
void MainWindow::checkFingerprint(const QString &line)
|
||||||
|
{
|
||||||
QRegularExpression re(".*server fingerprint: ([A-F0-9:]+)");
|
QRegularExpression re(".*server fingerprint: ([A-F0-9:]+)");
|
||||||
auto match = re.match(line);
|
auto match = re.match(line);
|
||||||
if (!match.hasMatch()) {
|
if (!match.hasMatch()) {
|
||||||
@ -682,17 +707,17 @@ void MainWindow::checkFingerprint(const QString &line) {
|
|||||||
messageBoxAlreadyShown = true;
|
messageBoxAlreadyShown = true;
|
||||||
QMessageBox::StandardButton fingerprintReply = QMessageBox::information(
|
QMessageBox::StandardButton fingerprintReply = QMessageBox::information(
|
||||||
this, QString("Security question"),
|
this, QString("Security question"),
|
||||||
QString(
|
QString("<p>You are connecting to a server.</p>"
|
||||||
"<p>You are connecting to a server.</p>"
|
"<p>Here is it's TLS fingerprint:</p>"
|
||||||
"<p>Here is it's TLS fingerprint:</p>"
|
"<p>%1</p>"
|
||||||
"<p>%1</p>"
|
"<p>Compare this fingerprint to the one on your server's screen. "
|
||||||
"<p>Compare this fingerprint to the one on your server's screen. "
|
"If the two don't match exactly, then it's probably not the server "
|
||||||
"If the two don't match exactly, then it's probably not the server "
|
"you're expecting (it could be a malicious user).</p>"
|
||||||
"you're expecting (it could be a malicious user).</p>"
|
"<p>Do you want to trust this fingerprint for future "
|
||||||
"<p>Do you want to trust this fingerprint for future "
|
"connections? If you don't, a connection cannot be made.</p>")
|
||||||
"connections? If you don't, a connection cannot be made.</p>")
|
|
||||||
.arg(fingerprint),
|
.arg(fingerprint),
|
||||||
QMessageBox::Yes | QMessageBox::No);
|
QMessageBox::Yes | QMessageBox::No
|
||||||
|
);
|
||||||
|
|
||||||
if (fingerprintReply == QMessageBox::Yes) {
|
if (fingerprintReply == QMessageBox::Yes) {
|
||||||
// start core process again after trusting fingerprint.
|
// start core process again after trusting fingerprint.
|
||||||
@ -704,17 +729,20 @@ void MainWindow::checkFingerprint(const QString &line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getTimeStamp() const {
|
QString MainWindow::getTimeStamp() const
|
||||||
|
{
|
||||||
QDateTime current = QDateTime::currentDateTime();
|
QDateTime current = QDateTime::currentDateTime();
|
||||||
return '[' + current.toString(Qt::ISODate) + ']';
|
return '[' + current.toString(Qt::ISODate) + ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showEvent(QShowEvent *event) {
|
void MainWindow::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
QMainWindow::showEvent(event);
|
QMainWindow::showEvent(event);
|
||||||
emit shown();
|
emit shown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
if (m_Quitting) {
|
if (m_Quitting) {
|
||||||
qDebug("skipping close event handle on quit");
|
qDebug("skipping close event handle on quit");
|
||||||
return;
|
return;
|
||||||
@ -734,7 +762,8 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
|||||||
qDebug("window should hide to tray");
|
qDebug("window should hide to tray");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showFirstConnectedMessage() {
|
void MainWindow::showFirstConnectedMessage()
|
||||||
|
{
|
||||||
if (m_AppConfig.startedBefore()) {
|
if (m_AppConfig.startedBefore()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -743,11 +772,11 @@ void MainWindow::showFirstConnectedMessage() {
|
|||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
|
|
||||||
const auto isServer = m_CoreProcess.mode() == CoreMode::Server;
|
const auto isServer = m_CoreProcess.mode() == CoreMode::Server;
|
||||||
messages::showFirstConnectedMessage(
|
messages::showFirstConnectedMessage(this, m_AppConfig.closeToTray(), m_AppConfig.enableService(), isServer);
|
||||||
this, m_AppConfig.closeToTray(), m_AppConfig.enableService(), isServer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showDevThanksMessage() {
|
void MainWindow::showDevThanksMessage()
|
||||||
|
{
|
||||||
if (!m_AppConfig.showDevThanks()) {
|
if (!m_AppConfig.showDevThanks()) {
|
||||||
qDebug("skipping dev thanks message");
|
qDebug("skipping dev thanks message");
|
||||||
return;
|
return;
|
||||||
@ -759,11 +788,13 @@ void MainWindow::showDevThanksMessage() {
|
|||||||
messages::showDevThanks(this, kAppName);
|
messages::showDevThanks(this, kAppName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCoreProcessSecureSocket(bool enabled) {
|
void MainWindow::onCoreProcessSecureSocket(bool enabled)
|
||||||
|
{
|
||||||
secureSocket(enabled);
|
secureSocket(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateStatus() {
|
void MainWindow::updateStatus()
|
||||||
|
{
|
||||||
const auto connection = m_CoreProcess.connectionState();
|
const auto connection = m_CoreProcess.connectionState();
|
||||||
const auto process = m_CoreProcess.processState();
|
const auto process = m_CoreProcess.processState();
|
||||||
|
|
||||||
@ -804,11 +835,9 @@ void MainWindow::updateStatus() {
|
|||||||
|
|
||||||
case Connected: {
|
case Connected: {
|
||||||
if (m_SecureSocket) {
|
if (m_SecureSocket) {
|
||||||
setStatus(QString("%1 is connected (with %2)")
|
setStatus(QString("%1 is connected (with %2)").arg(kAppName, m_CoreProcess.secureSocketVersion()));
|
||||||
.arg(kAppName, m_CoreProcess.secureSocketVersion()));
|
|
||||||
} else {
|
} else {
|
||||||
setStatus(
|
setStatus(QString("%1 is connected (without TLS encryption)").arg(kAppName));
|
||||||
QString("%1 is connected (without TLS encryption)").arg(kAppName));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -821,7 +850,8 @@ void MainWindow::updateStatus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
void MainWindow::onCoreProcessStateChanged(CoreProcessState state)
|
||||||
|
{
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
|
||||||
if (state == CoreProcessState::Started) {
|
if (state == CoreProcessState::Started) {
|
||||||
@ -830,15 +860,10 @@ void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
|||||||
m_ConfigScopes.save();
|
m_ConfigScopes.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == CoreProcessState::Started ||
|
if (state == CoreProcessState::Started || state == CoreProcessState::Starting ||
|
||||||
state == CoreProcessState::Starting ||
|
|
||||||
state == CoreProcessState::RetryPending) {
|
state == CoreProcessState::RetryPending) {
|
||||||
disconnect(
|
disconnect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore, &QAction::trigger);
|
||||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore,
|
connect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore, &QAction::trigger);
|
||||||
&QAction::trigger);
|
|
||||||
connect(
|
|
||||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore,
|
|
||||||
&QAction::trigger);
|
|
||||||
|
|
||||||
m_pButtonToggleStart->setText(QString("&Stop"));
|
m_pButtonToggleStart->setText(QString("&Stop"));
|
||||||
m_pButtonApply->setEnabled(true);
|
m_pButtonApply->setEnabled(true);
|
||||||
@ -847,12 +872,8 @@ void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
|||||||
m_pActionStopCore->setEnabled(true);
|
m_pActionStopCore->setEnabled(true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
disconnect(
|
disconnect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore, &QAction::trigger);
|
||||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore,
|
connect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore, &QAction::trigger);
|
||||||
&QAction::trigger);
|
|
||||||
connect(
|
|
||||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore,
|
|
||||||
&QAction::trigger);
|
|
||||||
|
|
||||||
m_pButtonToggleStart->setText(QString("&Start"));
|
m_pButtonToggleStart->setText(QString("&Start"));
|
||||||
m_pButtonApply->setEnabled(false);
|
m_pButtonApply->setEnabled(false);
|
||||||
@ -862,7 +883,8 @@ void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCoreConnectionStateChanged(CoreConnectionState state) {
|
void MainWindow::onCoreConnectionStateChanged(CoreConnectionState state)
|
||||||
|
{
|
||||||
qDebug("core connection state changed: %d", static_cast<int>(state));
|
qDebug("core connection state changed: %d", static_cast<int>(state));
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
@ -878,7 +900,8 @@ void MainWindow::onCoreConnectionStateChanged(CoreConnectionState state) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setVisible(bool visible) {
|
void MainWindow::setVisible(bool visible)
|
||||||
|
{
|
||||||
QMainWindow::setVisible(visible);
|
QMainWindow::setVisible(visible);
|
||||||
m_pActionMinimize->setEnabled(visible);
|
m_pActionMinimize->setEnabled(visible);
|
||||||
m_pActionRestore->setEnabled(!visible);
|
m_pActionRestore->setEnabled(!visible);
|
||||||
@ -897,15 +920,15 @@ void MainWindow::setVisible(bool visible) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MainWindow::getIPAddresses() const {
|
QString MainWindow::getIPAddresses() const
|
||||||
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
bool hinted = false;
|
bool hinted = false;
|
||||||
const auto localnet = QHostAddress::parseSubnet("192.168.0.0/16");
|
const auto localnet = QHostAddress::parseSubnet("192.168.0.0/16");
|
||||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
||||||
|
|
||||||
for (const auto &address : addresses) {
|
for (const auto &address : addresses) {
|
||||||
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
|
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost) &&
|
||||||
address != QHostAddress(QHostAddress::LocalHost) &&
|
|
||||||
!address.isInSubnet(QHostAddress::parseSubnet("169.254.0.0/16"))) {
|
!address.isInSubnet(QHostAddress::parseSubnet("169.254.0.0/16"))) {
|
||||||
|
|
||||||
// usually 192.168.x.x is a useful ip for the user, so indicate
|
// usually 192.168.x.x is a useful ip for the user, so indicate
|
||||||
@ -927,7 +950,8 @@ QString MainWindow::getIPAddresses() const {
|
|||||||
return result.join(", ");
|
return result.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateLocalFingerprint() {
|
void MainWindow::updateLocalFingerprint()
|
||||||
|
{
|
||||||
bool fingerprintExists = false;
|
bool fingerprintExists = false;
|
||||||
try {
|
try {
|
||||||
fingerprintExists = TlsFingerprint::local().fileExists();
|
fingerprintExists = TlsFingerprint::local().fileExists();
|
||||||
@ -936,22 +960,21 @@ void MainWindow::updateLocalFingerprint() {
|
|||||||
qFatal("failed to check if fingerprint exists");
|
qFatal("failed to check if fingerprint exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_AppConfig.tlsEnabled() && fingerprintExists &&
|
if (m_AppConfig.tlsEnabled() && fingerprintExists && m_pRadioGroupServer->isChecked()) {
|
||||||
m_pRadioGroupServer->isChecked()) {
|
|
||||||
m_pLabelFingerprint->setVisible(true);
|
m_pLabelFingerprint->setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
m_pLabelFingerprint->setVisible(false);
|
m_pLabelFingerprint->setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::autoAddScreen(const QString name) {
|
void MainWindow::autoAddScreen(const QString name)
|
||||||
|
{
|
||||||
|
|
||||||
int r = m_ServerConfig.autoAddScreen(name);
|
int r = m_ServerConfig.autoAddScreen(name);
|
||||||
if (r != kAutoAddScreenOk) {
|
if (r != kAutoAddScreenOk) {
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case kAutoAddScreenManualServer:
|
case kAutoAddScreenManualServer:
|
||||||
showConfigureServer(QString("Please add the server (%1) to the grid.")
|
showConfigureServer(QString("Please add the server (%1) to the grid.").arg(m_AppConfig.screenName()));
|
||||||
.arg(m_AppConfig.screenName()));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kAutoAddScreenManualClient:
|
case kAutoAddScreenManualClient:
|
||||||
@ -963,7 +986,8 @@ void MainWindow::autoAddScreen(const QString name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showConfigureServer(const QString &message) {
|
void MainWindow::showConfigureServer(const QString &message)
|
||||||
|
{
|
||||||
ServerConfigDialog dialog(this, serverConfig(), m_AppConfig);
|
ServerConfigDialog dialog(this, serverConfig(), m_AppConfig);
|
||||||
dialog.message(message);
|
dialog.message(message);
|
||||||
if ((dialog.exec() == QDialog::Accepted) && m_CoreProcess.isStarted()) {
|
if ((dialog.exec() == QDialog::Accepted) && m_CoreProcess.isStarted()) {
|
||||||
@ -971,7 +995,8 @@ void MainWindow::showConfigureServer(const QString &message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::secureSocket(bool secureSocket) {
|
void MainWindow::secureSocket(bool secureSocket)
|
||||||
|
{
|
||||||
m_SecureSocket = secureSocket;
|
m_SecureSocket = secureSocket;
|
||||||
if (secureSocket) {
|
if (secureSocket) {
|
||||||
m_pLabelPadlock->show();
|
m_pLabelPadlock->show();
|
||||||
@ -980,16 +1005,17 @@ void MainWindow::secureSocket(bool secureSocket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateScreenName() {
|
void MainWindow::updateScreenName()
|
||||||
m_pLabelComputerName->setText(
|
{
|
||||||
QString("This computer's name: %1 "
|
m_pLabelComputerName->setText(QString("This computer's name: %1 "
|
||||||
R"((<a href="#" style="color: %2">change</a>))")
|
R"((<a href="#" style="color: %2">change</a>))")
|
||||||
.arg(m_AppConfig.screenName())
|
.arg(m_AppConfig.screenName())
|
||||||
.arg(kColorSecondary));
|
.arg(kColorSecondary));
|
||||||
m_ServerConfig.updateServerName();
|
m_ServerConfig.updateServerName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::enableServer(bool enable) {
|
void MainWindow::enableServer(bool enable)
|
||||||
|
{
|
||||||
qDebug(enable ? "server enabled" : "server disabled");
|
qDebug(enable ? "server enabled" : "server disabled");
|
||||||
m_AppConfig.setServerGroupChecked(enable);
|
m_AppConfig.setServerGroupChecked(enable);
|
||||||
m_pRadioGroupServer->setChecked(enable);
|
m_pRadioGroupServer->setChecked(enable);
|
||||||
@ -1012,7 +1038,8 @@ void MainWindow::enableServer(bool enable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::enableClient(bool enable) {
|
void MainWindow::enableClient(bool enable)
|
||||||
|
{
|
||||||
qDebug(enable ? "client enabled" : "client disabled");
|
qDebug(enable ? "client enabled" : "client disabled");
|
||||||
m_AppConfig.setClientGroupChecked(enable);
|
m_AppConfig.setClientGroupChecked(enable);
|
||||||
m_pRadioGroupClient->setChecked(enable);
|
m_pRadioGroupClient->setChecked(enable);
|
||||||
@ -1026,7 +1053,8 @@ void MainWindow::enableClient(bool enable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showAndActivate() {
|
void MainWindow::showAndActivate()
|
||||||
|
{
|
||||||
if (!isMinimized() && !isHidden()) {
|
if (!isMinimized() && !isHidden()) {
|
||||||
qDebug("window already visible");
|
qDebug("window already visible");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -55,7 +55,8 @@ class QAbstractButton;
|
|||||||
class DeskflowApplication;
|
class DeskflowApplication;
|
||||||
class SetupWizard;
|
class SetupWizard;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow, public Ui::MainWindowBase {
|
class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||||
|
{
|
||||||
using CoreMode = deskflow::gui::CoreProcess::Mode;
|
using CoreMode = deskflow::gui::CoreProcess::Mode;
|
||||||
using CoreProcess = deskflow::gui::CoreProcess;
|
using CoreProcess = deskflow::gui::CoreProcess;
|
||||||
|
|
||||||
@ -66,18 +67,27 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase {
|
|||||||
friend class SettingsDialog;
|
friend class SettingsDialog;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class LogLevel { Error, Info };
|
enum class LogLevel
|
||||||
|
{
|
||||||
|
Error,
|
||||||
|
Info
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(
|
explicit MainWindow(deskflow::gui::ConfigScopes &configScopes, AppConfig &appConfig);
|
||||||
deskflow::gui::ConfigScopes &configScopes, AppConfig &appConfig);
|
|
||||||
~MainWindow() override;
|
~MainWindow() override;
|
||||||
|
|
||||||
void setVisible(bool visible) override;
|
void setVisible(bool visible) override;
|
||||||
CoreMode coreMode() const { return m_CoreProcess.mode(); }
|
CoreMode coreMode() const
|
||||||
|
{
|
||||||
|
return m_CoreProcess.mode();
|
||||||
|
}
|
||||||
QString address() const;
|
QString address() const;
|
||||||
void open();
|
void open();
|
||||||
ServerConfig &serverConfig() { return m_ServerConfig; }
|
ServerConfig &serverConfig()
|
||||||
|
{
|
||||||
|
return m_ServerConfig;
|
||||||
|
}
|
||||||
void autoAddScreen(const QString name);
|
void autoAddScreen(const QString name);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -133,8 +143,14 @@ private slots:
|
|||||||
void on_m_pLineEditClientIp_textChanged(const QString &text);
|
void on_m_pLineEditClientIp_textChanged(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AppConfig &appConfig() { return m_AppConfig; }
|
AppConfig &appConfig()
|
||||||
AppConfig const &appConfig() const { return m_AppConfig; }
|
{
|
||||||
|
return m_AppConfig;
|
||||||
|
}
|
||||||
|
AppConfig const &appConfig() const
|
||||||
|
{
|
||||||
|
return m_AppConfig;
|
||||||
|
}
|
||||||
void createMenuBar();
|
void createMenuBar();
|
||||||
void createStatusBar();
|
void createStatusBar();
|
||||||
void createTrayIcon();
|
void createTrayIcon();
|
||||||
@ -163,7 +179,10 @@ private:
|
|||||||
void saveSettings();
|
void saveSettings();
|
||||||
QString configFilename();
|
QString configFilename();
|
||||||
void showConfigureServer(const QString &message);
|
void showConfigureServer(const QString &message);
|
||||||
void showConfigureServer() { showConfigureServer(""); }
|
void showConfigureServer()
|
||||||
|
{
|
||||||
|
showConfigureServer("");
|
||||||
|
}
|
||||||
void restoreWindow();
|
void restoreWindow();
|
||||||
void saveWindow();
|
void saveWindow();
|
||||||
void setupControls();
|
void setupControls();
|
||||||
|
|||||||
@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
enum qProcessorArch {
|
enum qProcessorArch
|
||||||
|
{
|
||||||
kProcessorArchWin32,
|
kProcessorArchWin32,
|
||||||
kProcessorArchWin64,
|
kProcessorArchWin64,
|
||||||
kProcessorArchMac32,
|
kProcessorArchMac32,
|
||||||
|
|||||||
@ -29,7 +29,8 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData) {
|
void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData)
|
||||||
|
{
|
||||||
for (int i = 0; i < comboBox->count(); ++i) {
|
for (int i = 0; i < comboBox->count(); ++i) {
|
||||||
if (comboBox->itemData(i) == itemData) {
|
if (comboBox->itemData(i) == itemData) {
|
||||||
comboBox->setCurrentIndex(i);
|
comboBox->setCurrentIndex(i);
|
||||||
@ -38,13 +39,15 @@ void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString hash(const QString &string) {
|
QString hash(const QString &string)
|
||||||
|
{
|
||||||
QByteArray data = string.toUtf8();
|
QByteArray data = string.toUtf8();
|
||||||
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
|
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
|
||||||
return hash.toHex();
|
return hash.toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
qProcessorArch getProcessorArch() {
|
qProcessorArch getProcessorArch()
|
||||||
|
{
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
SYSTEM_INFO systemInfo;
|
SYSTEM_INFO systemInfo;
|
||||||
GetNativeSystemInfo(&systemInfo);
|
GetNativeSystemInfo(&systemInfo);
|
||||||
|
|||||||
@ -33,11 +33,11 @@ using enum ScreenConfig::Modifier;
|
|||||||
using enum ScreenConfig::SwitchCorner;
|
using enum ScreenConfig::SwitchCorner;
|
||||||
using enum ScreenConfig::Fix;
|
using enum ScreenConfig::Fix;
|
||||||
|
|
||||||
ScreenSettingsDialog::ScreenSettingsDialog(
|
ScreenSettingsDialog::ScreenSettingsDialog(QWidget *parent, Screen *pScreen, const ScreenList *pScreens)
|
||||||
QWidget *parent, Screen *pScreen, const ScreenList *pScreens)
|
|
||||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||||
Ui::ScreenSettingsDialogBase(),
|
Ui::ScreenSettingsDialogBase(),
|
||||||
m_pScreen(pScreen) {
|
m_pScreen(pScreen)
|
||||||
|
{
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
@ -46,33 +46,27 @@ ScreenSettingsDialog::ScreenSettingsDialog(
|
|||||||
|
|
||||||
m_pLineEditName->setText(m_pScreen->name());
|
m_pLineEditName->setText(m_pScreen->name());
|
||||||
m_pLineEditName->setValidator(new validators::ScreenNameValidator(
|
m_pLineEditName->setValidator(new validators::ScreenNameValidator(
|
||||||
m_pLineEditName, new validators::ValidationError(this, m_pLabelNameError),
|
m_pLineEditName, new validators::ValidationError(this, m_pLabelNameError), pScreens
|
||||||
pScreens));
|
));
|
||||||
m_pLineEditName->selectAll();
|
m_pLineEditName->selectAll();
|
||||||
|
|
||||||
m_pLineEditAlias->setValidator(new validators::AliasValidator(
|
m_pLineEditAlias->setValidator(
|
||||||
m_pLineEditAlias,
|
new validators::AliasValidator(m_pLineEditAlias, new validators::ValidationError(this, m_pLabelAliasError))
|
||||||
new validators::ValidationError(this, m_pLabelAliasError)));
|
);
|
||||||
|
|
||||||
for (int i = 0; i < m_pScreen->aliases().count(); i++)
|
for (int i = 0; i < m_pScreen->aliases().count(); i++)
|
||||||
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);
|
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);
|
||||||
|
|
||||||
m_pComboBoxShift->setCurrentIndex(
|
m_pComboBoxShift->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Shift)));
|
||||||
m_pScreen->modifier(static_cast<int>(Shift)));
|
|
||||||
m_pComboBoxCtrl->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Ctrl)));
|
m_pComboBoxCtrl->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Ctrl)));
|
||||||
m_pComboBoxAlt->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Alt)));
|
m_pComboBoxAlt->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Alt)));
|
||||||
m_pComboBoxMeta->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Meta)));
|
m_pComboBoxMeta->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Meta)));
|
||||||
m_pComboBoxSuper->setCurrentIndex(
|
m_pComboBoxSuper->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Super)));
|
||||||
m_pScreen->modifier(static_cast<int>(Super)));
|
|
||||||
|
|
||||||
m_pCheckBoxCornerTopLeft->setChecked(
|
m_pCheckBoxCornerTopLeft->setChecked(m_pScreen->switchCorner(static_cast<int>(TopLeft)));
|
||||||
m_pScreen->switchCorner(static_cast<int>(TopLeft)));
|
m_pCheckBoxCornerTopRight->setChecked(m_pScreen->switchCorner(static_cast<int>(TopRight)));
|
||||||
m_pCheckBoxCornerTopRight->setChecked(
|
m_pCheckBoxCornerBottomLeft->setChecked(m_pScreen->switchCorner(static_cast<int>(BottomLeft)));
|
||||||
m_pScreen->switchCorner(static_cast<int>(TopRight)));
|
m_pCheckBoxCornerBottomRight->setChecked(m_pScreen->switchCorner(static_cast<int>(BottomRight)));
|
||||||
m_pCheckBoxCornerBottomLeft->setChecked(
|
|
||||||
m_pScreen->switchCorner(static_cast<int>(BottomLeft)));
|
|
||||||
m_pCheckBoxCornerBottomRight->setChecked(
|
|
||||||
m_pScreen->switchCorner(static_cast<int>(BottomRight)));
|
|
||||||
m_pSpinBoxSwitchCornerSize->setValue(m_pScreen->switchCornerSize());
|
m_pSpinBoxSwitchCornerSize->setValue(m_pScreen->switchCornerSize());
|
||||||
|
|
||||||
m_pCheckBoxCapsLock->setChecked(m_pScreen->fix(CapsLock));
|
m_pCheckBoxCapsLock->setChecked(m_pScreen->fix(CapsLock));
|
||||||
@ -81,12 +75,14 @@ ScreenSettingsDialog::ScreenSettingsDialog(
|
|||||||
m_pCheckBoxXTest->setChecked(m_pScreen->fix(XTest));
|
m_pCheckBoxXTest->setChecked(m_pScreen->fix(XTest));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSettingsDialog::accept() {
|
void ScreenSettingsDialog::accept()
|
||||||
|
{
|
||||||
if (m_pLineEditName->text().isEmpty()) {
|
if (m_pLineEditName->text().isEmpty()) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this, tr("Screen name is empty"),
|
this, tr("Screen name is empty"),
|
||||||
tr("The screen name cannot be empty. "
|
tr("The screen name cannot be empty. "
|
||||||
"Please either fill in a name or cancel the dialog."));
|
"Please either fill in a name or cancel the dialog.")
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
} else if (!m_pLabelNameError->text().isEmpty()) {
|
} else if (!m_pLabelNameError->text().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -102,64 +98,56 @@ void ScreenSettingsDialog::accept() {
|
|||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
this, tr("Screen name matches alias"),
|
this, tr("Screen name matches alias"),
|
||||||
tr("The screen name cannot be the same as an alias. "
|
tr("The screen name cannot be the same as an alias. "
|
||||||
"Please either remove the alias or change the screen name."));
|
"Please either remove the alias or change the screen name.")
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_pScreen->addAlias(alias);
|
m_pScreen->addAlias(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pScreen->setModifier(
|
m_pScreen->setModifier(static_cast<int>(Shift), m_pComboBoxShift->currentIndex());
|
||||||
static_cast<int>(Shift), m_pComboBoxShift->currentIndex());
|
m_pScreen->setModifier(static_cast<int>(Ctrl), m_pComboBoxCtrl->currentIndex());
|
||||||
m_pScreen->setModifier(
|
|
||||||
static_cast<int>(Ctrl), m_pComboBoxCtrl->currentIndex());
|
|
||||||
m_pScreen->setModifier(static_cast<int>(Alt), m_pComboBoxAlt->currentIndex());
|
m_pScreen->setModifier(static_cast<int>(Alt), m_pComboBoxAlt->currentIndex());
|
||||||
m_pScreen->setModifier(
|
m_pScreen->setModifier(static_cast<int>(Meta), m_pComboBoxMeta->currentIndex());
|
||||||
static_cast<int>(Meta), m_pComboBoxMeta->currentIndex());
|
m_pScreen->setModifier(static_cast<int>(Super), m_pComboBoxSuper->currentIndex());
|
||||||
m_pScreen->setModifier(
|
|
||||||
static_cast<int>(Super), m_pComboBoxSuper->currentIndex());
|
|
||||||
|
|
||||||
m_pScreen->setSwitchCorner(
|
m_pScreen->setSwitchCorner(static_cast<int>(TopLeft), m_pCheckBoxCornerTopLeft->isChecked());
|
||||||
static_cast<int>(TopLeft), m_pCheckBoxCornerTopLeft->isChecked());
|
m_pScreen->setSwitchCorner(static_cast<int>(TopRight), m_pCheckBoxCornerTopRight->isChecked());
|
||||||
m_pScreen->setSwitchCorner(
|
m_pScreen->setSwitchCorner(static_cast<int>(BottomLeft), m_pCheckBoxCornerBottomLeft->isChecked());
|
||||||
static_cast<int>(TopRight), m_pCheckBoxCornerTopRight->isChecked());
|
m_pScreen->setSwitchCorner(static_cast<int>(BottomRight), m_pCheckBoxCornerBottomRight->isChecked());
|
||||||
m_pScreen->setSwitchCorner(
|
|
||||||
static_cast<int>(BottomLeft), m_pCheckBoxCornerBottomLeft->isChecked());
|
|
||||||
m_pScreen->setSwitchCorner(
|
|
||||||
static_cast<int>(BottomRight), m_pCheckBoxCornerBottomRight->isChecked());
|
|
||||||
m_pScreen->setSwitchCornerSize(m_pSpinBoxSwitchCornerSize->value());
|
m_pScreen->setSwitchCornerSize(m_pSpinBoxSwitchCornerSize->value());
|
||||||
|
|
||||||
m_pScreen->setFix(
|
m_pScreen->setFix(static_cast<int>(CapsLock), m_pCheckBoxCapsLock->isChecked());
|
||||||
static_cast<int>(CapsLock), m_pCheckBoxCapsLock->isChecked());
|
|
||||||
m_pScreen->setFix(static_cast<int>(NumLock), m_pCheckBoxNumLock->isChecked());
|
m_pScreen->setFix(static_cast<int>(NumLock), m_pCheckBoxNumLock->isChecked());
|
||||||
m_pScreen->setFix(
|
m_pScreen->setFix(static_cast<int>(ScrollLock), m_pCheckBoxScrollLock->isChecked());
|
||||||
static_cast<int>(ScrollLock), m_pCheckBoxScrollLock->isChecked());
|
|
||||||
m_pScreen->setFix(static_cast<int>(XTest), m_pCheckBoxXTest->isChecked());
|
m_pScreen->setFix(static_cast<int>(XTest), m_pCheckBoxXTest->isChecked());
|
||||||
|
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSettingsDialog::on_m_pButtonAddAlias_clicked() {
|
void ScreenSettingsDialog::on_m_pButtonAddAlias_clicked()
|
||||||
|
{
|
||||||
if (!m_pLineEditAlias->text().isEmpty() &&
|
if (!m_pLineEditAlias->text().isEmpty() &&
|
||||||
m_pListAliases->findItems(m_pLineEditAlias->text(), Qt::MatchFixedString)
|
m_pListAliases->findItems(m_pLineEditAlias->text(), Qt::MatchFixedString).isEmpty()) {
|
||||||
.isEmpty()) {
|
|
||||||
new QListWidgetItem(m_pLineEditAlias->text(), m_pListAliases);
|
new QListWidgetItem(m_pLineEditAlias->text(), m_pListAliases);
|
||||||
m_pLineEditAlias->clear();
|
m_pLineEditAlias->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(
|
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(const QString &text)
|
||||||
const QString &text) {
|
{
|
||||||
m_pButtonAddAlias->setEnabled(
|
m_pButtonAddAlias->setEnabled(!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
|
||||||
!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked() {
|
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked()
|
||||||
|
{
|
||||||
QList<QListWidgetItem *> items = m_pListAliases->selectedItems();
|
QList<QListWidgetItem *> items = m_pListAliases->selectedItems();
|
||||||
|
|
||||||
for (int i = 0; i < items.count(); i++)
|
for (int i = 0; i < items.count(); i++)
|
||||||
delete items[i];
|
delete items[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSettingsDialog::on_m_pListAliases_itemSelectionChanged() {
|
void ScreenSettingsDialog::on_m_pListAliases_itemSelectionChanged()
|
||||||
|
{
|
||||||
m_pButtonRemoveAlias->setEnabled(!m_pListAliases->selectedItems().isEmpty());
|
m_pButtonRemoveAlias->setEnabled(!m_pListAliases->selectedItems().isEmpty());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,14 +28,12 @@ class QString;
|
|||||||
class Screen;
|
class Screen;
|
||||||
class ScreenList;
|
class ScreenList;
|
||||||
|
|
||||||
class ScreenSettingsDialog : public QDialog,
|
class ScreenSettingsDialog : public QDialog, public Ui::ScreenSettingsDialogBase
|
||||||
public Ui::ScreenSettingsDialogBase {
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ScreenSettingsDialog(
|
ScreenSettingsDialog(QWidget *parent, Screen *pScreen = nullptr, const ScreenList *pScreens = nullptr);
|
||||||
QWidget *parent, Screen *pScreen = nullptr,
|
|
||||||
const ScreenList *pScreens = nullptr);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept();
|
void accept();
|
||||||
|
|||||||
@ -23,35 +23,30 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
const QString ScreenSetupModel::m_MimeType =
|
const QString ScreenSetupModel::m_MimeType = "application/x-" DESKFLOW_APP_ID "-screen";
|
||||||
"application/x-" DESKFLOW_APP_ID "-screen";
|
|
||||||
|
|
||||||
ScreenSetupModel::ScreenSetupModel(
|
ScreenSetupModel::ScreenSetupModel(ScreenList &screens, int numColumns, int numRows)
|
||||||
ScreenList &screens, int numColumns, int numRows)
|
|
||||||
: QAbstractTableModel(NULL),
|
: QAbstractTableModel(NULL),
|
||||||
m_Screens(screens),
|
m_Screens(screens),
|
||||||
m_NumColumns(numColumns),
|
m_NumColumns(numColumns),
|
||||||
m_NumRows(numRows) {
|
m_NumRows(numRows)
|
||||||
|
{
|
||||||
|
|
||||||
// bound rows and columns to prevent multiply overflow.
|
// bound rows and columns to prevent multiply overflow.
|
||||||
// this is unlikely to happen, as the grid size is only 3x9.
|
// this is unlikely to happen, as the grid size is only 3x9.
|
||||||
if (m_NumColumns > 100 || m_NumRows > 100) {
|
if (m_NumColumns > 100 || m_NumRows > 100) {
|
||||||
qFatal(
|
qFatal("grid size out of bounds: %d columns x %d rows", m_NumColumns, m_NumRows);
|
||||||
"grid size out of bounds: %d columns x %d rows", m_NumColumns,
|
|
||||||
m_NumRows);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_NumColumns * m_NumRows > screens.size()) {
|
if (m_NumColumns * m_NumRows > screens.size()) {
|
||||||
qFatal(
|
qFatal("scrren list (%lld) too small for %d columns x %d rows", screens.size(), m_NumColumns, m_NumRows);
|
||||||
"scrren list (%lld) too small for %d columns x %d rows", screens.size(),
|
|
||||||
m_NumColumns, m_NumRows);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ScreenSetupModel::data(const QModelIndex &index, int role) const {
|
QVariant ScreenSetupModel::data(const QModelIndex &index, int role) const
|
||||||
if (index.isValid() && index.row() < m_NumRows &&
|
{
|
||||||
index.column() < m_NumColumns) {
|
if (index.isValid() && index.row() < m_NumRows && index.column() < m_NumColumns) {
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
if (screen(index).isNull())
|
if (screen(index).isNull())
|
||||||
@ -76,27 +71,29 @@ QVariant ScreenSetupModel::data(const QModelIndex &index, int role) const {
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags ScreenSetupModel::flags(const QModelIndex &index) const {
|
Qt::ItemFlags ScreenSetupModel::flags(const QModelIndex &index) const
|
||||||
if (!index.isValid() || index.row() >= m_NumRows ||
|
{
|
||||||
index.column() >= m_NumColumns)
|
if (!index.isValid() || index.row() >= m_NumRows || index.column() >= m_NumColumns)
|
||||||
return Qt::NoItemFlags;
|
return Qt::NoItemFlags;
|
||||||
|
|
||||||
if (!screen(index).isNull())
|
if (!screen(index).isNull())
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable |
|
return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
|
||||||
Qt::ItemIsDropEnabled;
|
|
||||||
|
|
||||||
return Qt::ItemIsDropEnabled;
|
return Qt::ItemIsDropEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::DropActions ScreenSetupModel::supportedDropActions() const {
|
Qt::DropActions ScreenSetupModel::supportedDropActions() const
|
||||||
|
{
|
||||||
return Qt::MoveAction | Qt::CopyAction;
|
return Qt::MoveAction | Qt::CopyAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ScreenSetupModel::mimeTypes() const {
|
QStringList ScreenSetupModel::mimeTypes() const
|
||||||
|
{
|
||||||
return QStringList() << m_MimeType;
|
return QStringList() << m_MimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMimeData *ScreenSetupModel::mimeData(const QModelIndexList &indexes) const {
|
QMimeData *ScreenSetupModel::mimeData(const QModelIndexList &indexes) const
|
||||||
|
{
|
||||||
QMimeData *pMimeData = new QMimeData();
|
QMimeData *pMimeData = new QMimeData();
|
||||||
QByteArray encodedData;
|
QByteArray encodedData;
|
||||||
|
|
||||||
@ -112,8 +109,9 @@ QMimeData *ScreenSetupModel::mimeData(const QModelIndexList &indexes) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenSetupModel::dropMimeData(
|
bool ScreenSetupModel::dropMimeData(
|
||||||
const QMimeData *data, Qt::DropAction action, int row, int column,
|
const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent
|
||||||
const QModelIndex &parent) {
|
)
|
||||||
|
{
|
||||||
if (action == Qt::IgnoreAction)
|
if (action == Qt::IgnoreAction)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -154,15 +152,16 @@ bool ScreenSetupModel::dropMimeData(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupModel::addScreen(const Screen &newScreen) {
|
void ScreenSetupModel::addScreen(const Screen &newScreen)
|
||||||
|
{
|
||||||
m_Screens.addScreenByPriority(newScreen);
|
m_Screens.addScreenByPriority(newScreen);
|
||||||
emit screensChanged();
|
emit screensChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenSetupModel::isFull() const {
|
bool ScreenSetupModel::isFull() const
|
||||||
auto emptyScreen = std::find_if(
|
{
|
||||||
m_Screens.cbegin(), m_Screens.cend(),
|
auto emptyScreen =
|
||||||
[](const Screen &item) { return item.isNull(); });
|
std::find_if(m_Screens.cbegin(), m_Screens.cend(), [](const Screen &item) { return item.isNull(); });
|
||||||
|
|
||||||
return (emptyScreen == m_Screens.cend());
|
return (emptyScreen == m_Screens.cend());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,8 @@
|
|||||||
class ScreenSetupView;
|
class ScreenSetupView;
|
||||||
class ServerConfigDialog;
|
class ServerConfigDialog;
|
||||||
|
|
||||||
class ScreenSetupModel : public QAbstractTableModel {
|
class ScreenSetupModel : public QAbstractTableModel
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class ScreenSetupView;
|
friend class ScreenSetupView;
|
||||||
@ -38,12 +39,27 @@ public:
|
|||||||
ScreenSetupModel(ScreenList &screens, int numColumns, int numRows);
|
ScreenSetupModel(ScreenList &screens, int numColumns, int numRows);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const QString &mimeType() { return m_MimeType; }
|
static const QString &mimeType()
|
||||||
|
{
|
||||||
|
return m_MimeType;
|
||||||
|
}
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
int rowCount() const { return m_NumRows; }
|
int rowCount() const
|
||||||
int columnCount() const { return m_NumColumns; }
|
{
|
||||||
int rowCount(const QModelIndex &) const { return rowCount(); }
|
return m_NumRows;
|
||||||
int columnCount(const QModelIndex &) const { return columnCount(); }
|
}
|
||||||
|
int columnCount() const
|
||||||
|
{
|
||||||
|
return m_NumColumns;
|
||||||
|
}
|
||||||
|
int rowCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return rowCount();
|
||||||
|
}
|
||||||
|
int columnCount(const QModelIndex &) const
|
||||||
|
{
|
||||||
|
return columnCount();
|
||||||
|
}
|
||||||
Qt::DropActions supportedDropActions() const;
|
Qt::DropActions supportedDropActions() const;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
QStringList mimeTypes() const;
|
QStringList mimeTypes() const;
|
||||||
@ -54,19 +70,21 @@ signals:
|
|||||||
void screensChanged();
|
void screensChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool dropMimeData(
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||||
const QMimeData *data, Qt::DropAction action, int row, int column,
|
const Screen &screen(const QModelIndex &index) const
|
||||||
const QModelIndex &parent);
|
{
|
||||||
const Screen &screen(const QModelIndex &index) const {
|
|
||||||
return screen(index.column(), index.row());
|
return screen(index.column(), index.row());
|
||||||
}
|
}
|
||||||
Screen &screen(const QModelIndex &index) {
|
Screen &screen(const QModelIndex &index)
|
||||||
|
{
|
||||||
return screen(index.column(), index.row());
|
return screen(index.column(), index.row());
|
||||||
}
|
}
|
||||||
const Screen &screen(int column, int row) const {
|
const Screen &screen(int column, int row) const
|
||||||
|
{
|
||||||
return m_Screens[row * m_NumColumns + column];
|
return m_Screens[row * m_NumColumns + column];
|
||||||
}
|
}
|
||||||
Screen &screen(int column, int row) {
|
Screen &screen(int column, int row)
|
||||||
|
{
|
||||||
return m_Screens[row * m_NumColumns + column];
|
return m_Screens[row * m_NumColumns + column];
|
||||||
}
|
}
|
||||||
void addScreen(const Screen &newScreen);
|
void addScreen(const Screen &newScreen);
|
||||||
|
|||||||
@ -25,7 +25,8 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
ScreenSetupView::ScreenSetupView(QWidget *parent) : QTableView(parent) {
|
ScreenSetupView::ScreenSetupView(QWidget *parent) : QTableView(parent)
|
||||||
|
{
|
||||||
setDropIndicatorShown(true);
|
setDropIndicatorShown(true);
|
||||||
setDragDropMode(DragDrop);
|
setDragDropMode(DragDrop);
|
||||||
setSelectionMode(SingleSelection);
|
setSelectionMode(SingleSelection);
|
||||||
@ -38,16 +39,19 @@ ScreenSetupView::ScreenSetupView(QWidget *parent) : QTableView(parent) {
|
|||||||
verticalHeader()->hide();
|
verticalHeader()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::setModel(QAbstractItemModel *model) {
|
void ScreenSetupView::setModel(QAbstractItemModel *model)
|
||||||
|
{
|
||||||
QTableView::setModel(model);
|
QTableView::setModel(model);
|
||||||
setTableSize();
|
setTableSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenSetupModel *ScreenSetupView::model() const {
|
ScreenSetupModel *ScreenSetupView::model() const
|
||||||
|
{
|
||||||
return qobject_cast<ScreenSetupModel *>(QTableView::model());
|
return qobject_cast<ScreenSetupModel *>(QTableView::model());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::setTableSize() {
|
void ScreenSetupView::setTableSize()
|
||||||
|
{
|
||||||
for (int i = 0; i < model()->columnCount(); i++)
|
for (int i = 0; i < model()->columnCount(); i++)
|
||||||
setColumnWidth(i, width() / model()->columnCount());
|
setColumnWidth(i, width() / model()->columnCount());
|
||||||
|
|
||||||
@ -55,19 +59,20 @@ void ScreenSetupView::setTableSize() {
|
|||||||
setRowHeight(i, height() / model()->rowCount());
|
setRowHeight(i, height() / model()->rowCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::resizeEvent(QResizeEvent *event) {
|
void ScreenSetupView::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
setTableSize();
|
setTableSize();
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent *event) {
|
void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
if (event->buttons() & Qt::LeftButton) {
|
if (event->buttons() & Qt::LeftButton) {
|
||||||
int col = columnAt(event->pos().x());
|
int col = columnAt(event->pos().x());
|
||||||
int row = rowAt(event->pos().y());
|
int row = rowAt(event->pos().y());
|
||||||
|
|
||||||
if (!model()->screen(col, row).isNull()) {
|
if (!model()->screen(col, row).isNull()) {
|
||||||
ScreenSettingsDialog dlg(
|
ScreenSettingsDialog dlg(this, &model()->screen(col, row), &model()->m_Screens);
|
||||||
this, &model()->screen(col, row), &model()->m_Screens);
|
|
||||||
dlg.exec();
|
dlg.exec();
|
||||||
emit model() -> screensChanged();
|
emit model() -> screensChanged();
|
||||||
}
|
}
|
||||||
@ -75,7 +80,8 @@ void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent *event) {
|
|||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::dragEnterEvent(QDragEnterEvent *event) {
|
void ScreenSetupView::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
// we accept anything that enters us by a drag as long as the
|
// we accept anything that enters us by a drag as long as the
|
||||||
// mime type is okay. anything else is dealt with in dragMoveEvent()
|
// mime type is okay. anything else is dealt with in dragMoveEvent()
|
||||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType()))
|
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType()))
|
||||||
@ -84,7 +90,8 @@ void ScreenSetupView::dragEnterEvent(QDragEnterEvent *event) {
|
|||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::dragMoveEvent(QDragMoveEvent *event) {
|
void ScreenSetupView::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
{
|
||||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
||||||
// where does the event come from? myself or someone else?
|
// where does the event come from? myself or someone else?
|
||||||
if (event->source() == this) {
|
if (event->source() == this) {
|
||||||
@ -107,7 +114,8 @@ void ScreenSetupView::dragMoveEvent(QDragMoveEvent *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is reimplemented from QAbstractItemView::startDrag()
|
// this is reimplemented from QAbstractItemView::startDrag()
|
||||||
void ScreenSetupView::startDrag(Qt::DropActions) {
|
void ScreenSetupView::startDrag(Qt::DropActions)
|
||||||
|
{
|
||||||
QModelIndexList indexes = selectedIndexes();
|
QModelIndexList indexes = selectedIndexes();
|
||||||
|
|
||||||
if (indexes.count() != 1)
|
if (indexes.count() != 1)
|
||||||
@ -137,7 +145,8 @@ void ScreenSetupView::startDrag(Qt::DropActions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSetupView::initViewItemOption(QStyleOptionViewItem *option) const {
|
void ScreenSetupView::initViewItemOption(QStyleOptionViewItem *option) const
|
||||||
|
{
|
||||||
option->showDecorationSelected = true;
|
option->showDecorationSelected = true;
|
||||||
option->decorationPosition = QStyleOptionViewItem::Top;
|
option->decorationPosition = QStyleOptionViewItem::Top;
|
||||||
option->displayAlignment = Qt::AlignCenter;
|
option->displayAlignment = Qt::AlignCenter;
|
||||||
|
|||||||
@ -29,7 +29,8 @@ class QResizeEvent;
|
|||||||
class QDragEnterEvent;
|
class QDragEnterEvent;
|
||||||
class ScreenSetupModel;
|
class ScreenSetupModel;
|
||||||
|
|
||||||
class ScreenSetupView : public QTableView {
|
class ScreenSetupView : public QTableView
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -47,5 +48,7 @@ protected:
|
|||||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
void startDrag(Qt::DropActions supportedActions) override;
|
void startDrag(Qt::DropActions supportedActions) override;
|
||||||
void initViewItemOption(QStyleOptionViewItem *option) const override;
|
void initViewItemOption(QStyleOptionViewItem *option) const override;
|
||||||
void scrollTo(const QModelIndex &, ScrollHint) override {}
|
void scrollTo(const QModelIndex &, ScrollHint) override
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -32,7 +32,8 @@ using enum ScreenConfig::Modifier;
|
|||||||
using enum ScreenConfig::SwitchCorner;
|
using enum ScreenConfig::SwitchCorner;
|
||||||
using enum ScreenConfig::Fix;
|
using enum ScreenConfig::Fix;
|
||||||
|
|
||||||
static const struct {
|
static const struct
|
||||||
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -46,18 +47,19 @@ static const struct {
|
|||||||
|
|
||||||
const int serverDefaultIndex = 7;
|
const int serverDefaultIndex = 7;
|
||||||
|
|
||||||
ServerConfig::ServerConfig(
|
ServerConfig::ServerConfig(AppConfig &appConfig, MainWindow &mainWindow, int columns, int rows)
|
||||||
AppConfig &appConfig, MainWindow &mainWindow, int columns, int rows)
|
|
||||||
: m_pAppConfig(&appConfig),
|
: m_pAppConfig(&appConfig),
|
||||||
m_pMainWindow(&mainWindow),
|
m_pMainWindow(&mainWindow),
|
||||||
m_Screens(columns),
|
m_Screens(columns),
|
||||||
m_Columns(columns),
|
m_Columns(columns),
|
||||||
m_Rows(rows),
|
m_Rows(rows),
|
||||||
m_ClipboardSharingSize(defaultClipboardSharingSize()) {
|
m_ClipboardSharingSize(defaultClipboardSharingSize())
|
||||||
|
{
|
||||||
recall();
|
recall();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::save(const QString &fileName) const {
|
bool ServerConfig::save(const QString &fileName) const
|
||||||
|
{
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
return false;
|
return false;
|
||||||
@ -68,32 +70,28 @@ bool ServerConfig::save(const QString &fileName) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::operator==(const ServerConfig &sc) const {
|
bool ServerConfig::operator==(const ServerConfig &sc) const
|
||||||
return m_Screens == sc.m_Screens && m_Columns == sc.m_Columns &&
|
{
|
||||||
m_Rows == sc.m_Rows && m_HasHeartbeat == sc.m_HasHeartbeat &&
|
return m_Screens == sc.m_Screens && m_Columns == sc.m_Columns && m_Rows == sc.m_Rows &&
|
||||||
m_Heartbeat == sc.m_Heartbeat &&
|
m_HasHeartbeat == sc.m_HasHeartbeat && m_Heartbeat == sc.m_Heartbeat &&
|
||||||
m_RelativeMouseMoves == sc.m_RelativeMouseMoves &&
|
m_RelativeMouseMoves == sc.m_RelativeMouseMoves && m_Win32KeepForeground == sc.m_Win32KeepForeground &&
|
||||||
m_Win32KeepForeground == sc.m_Win32KeepForeground &&
|
m_HasSwitchDelay == sc.m_HasSwitchDelay && m_SwitchDelay == sc.m_SwitchDelay &&
|
||||||
m_HasSwitchDelay == sc.m_HasSwitchDelay &&
|
m_HasSwitchDoubleTap == sc.m_HasSwitchDoubleTap && m_SwitchDoubleTap == sc.m_SwitchDoubleTap &&
|
||||||
m_SwitchDelay == sc.m_SwitchDelay &&
|
m_SwitchCornerSize == sc.m_SwitchCornerSize && m_SwitchCorners == sc.m_SwitchCorners &&
|
||||||
m_HasSwitchDoubleTap == sc.m_HasSwitchDoubleTap &&
|
m_Hotkeys == sc.m_Hotkeys && m_pAppConfig == sc.m_pAppConfig &&
|
||||||
m_SwitchDoubleTap == sc.m_SwitchDoubleTap &&
|
m_EnableDragAndDrop == sc.m_EnableDragAndDrop && m_DisableLockToScreen == sc.m_DisableLockToScreen &&
|
||||||
m_SwitchCornerSize == sc.m_SwitchCornerSize &&
|
m_ClipboardSharing == sc.m_ClipboardSharing && m_ClipboardSharingSize == sc.m_ClipboardSharingSize &&
|
||||||
m_SwitchCorners == sc.m_SwitchCorners && m_Hotkeys == sc.m_Hotkeys &&
|
|
||||||
m_pAppConfig == sc.m_pAppConfig &&
|
|
||||||
m_EnableDragAndDrop == sc.m_EnableDragAndDrop &&
|
|
||||||
m_DisableLockToScreen == sc.m_DisableLockToScreen &&
|
|
||||||
m_ClipboardSharing == sc.m_ClipboardSharing &&
|
|
||||||
m_ClipboardSharingSize == sc.m_ClipboardSharingSize &&
|
|
||||||
m_pMainWindow == sc.m_pMainWindow;
|
m_pMainWindow == sc.m_pMainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::save(QFile &file) const {
|
void ServerConfig::save(QFile &file) const
|
||||||
|
{
|
||||||
QTextStream outStream(&file);
|
QTextStream outStream(&file);
|
||||||
outStream << *this;
|
outStream << *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::setupScreens() {
|
void ServerConfig::setupScreens()
|
||||||
|
{
|
||||||
switchCorners().clear();
|
switchCorners().clear();
|
||||||
screens().clear();
|
screens().clear();
|
||||||
hotkeys().clear();
|
hotkeys().clear();
|
||||||
@ -108,7 +106,8 @@ void ServerConfig::setupScreens() {
|
|||||||
addScreen(Screen());
|
addScreen(Screen());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::commit() {
|
void ServerConfig::commit()
|
||||||
|
{
|
||||||
qDebug("committing server config");
|
qDebug("committing server config");
|
||||||
|
|
||||||
settings().beginGroup("internalConfig");
|
settings().beginGroup("internalConfig");
|
||||||
@ -129,8 +128,7 @@ void ServerConfig::commit() {
|
|||||||
settings().setValue("disableLockToScreen", disableLockToScreen());
|
settings().setValue("disableLockToScreen", disableLockToScreen());
|
||||||
settings().setValue("enableDragAndDrop", enableDragAndDrop());
|
settings().setValue("enableDragAndDrop", enableDragAndDrop());
|
||||||
settings().setValue("clipboardSharing", clipboardSharing());
|
settings().setValue("clipboardSharing", clipboardSharing());
|
||||||
settings().setValue(
|
settings().setValue("clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
|
||||||
"clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
|
|
||||||
|
|
||||||
if (!getClientAddress().isEmpty()) {
|
if (!getClientAddress().isEmpty()) {
|
||||||
settings().setValue("clientAddress", getClientAddress());
|
settings().setValue("clientAddress", getClientAddress());
|
||||||
@ -159,7 +157,8 @@ void ServerConfig::commit() {
|
|||||||
settings().endGroup();
|
settings().endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::recall() {
|
void ServerConfig::recall()
|
||||||
|
{
|
||||||
qDebug("recalling server config");
|
qDebug("recalling server config");
|
||||||
|
|
||||||
settings().beginGroup("internalConfig");
|
settings().beginGroup("internalConfig");
|
||||||
@ -174,28 +173,21 @@ void ServerConfig::recall() {
|
|||||||
haveHeartbeat(settings().value("hasHeartbeat", false).toBool());
|
haveHeartbeat(settings().value("hasHeartbeat", false).toBool());
|
||||||
setHeartbeat(settings().value("heartbeat", 5000).toInt());
|
setHeartbeat(settings().value("heartbeat", 5000).toInt());
|
||||||
setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool());
|
setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool());
|
||||||
setWin32KeepForeground(
|
setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool());
|
||||||
settings().value("win32KeepForeground", false).toBool());
|
|
||||||
haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool());
|
haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool());
|
||||||
setSwitchDelay(settings().value("switchDelay", 250).toInt());
|
setSwitchDelay(settings().value("switchDelay", 250).toInt());
|
||||||
haveSwitchDoubleTap(settings().value("hasSwitchDoubleTap", false).toBool());
|
haveSwitchDoubleTap(settings().value("hasSwitchDoubleTap", false).toBool());
|
||||||
setSwitchDoubleTap(settings().value("switchDoubleTap", 250).toInt());
|
setSwitchDoubleTap(settings().value("switchDoubleTap", 250).toInt());
|
||||||
setSwitchCornerSize(settings().value("switchCornerSize").toInt());
|
setSwitchCornerSize(settings().value("switchCornerSize").toInt());
|
||||||
setDisableLockToScreen(
|
setDisableLockToScreen(settings().value("disableLockToScreen", false).toBool());
|
||||||
settings().value("disableLockToScreen", false).toBool());
|
|
||||||
setEnableDragAndDrop(settings().value("enableDragAndDrop", false).toBool());
|
setEnableDragAndDrop(settings().value("enableDragAndDrop", false).toBool());
|
||||||
setClipboardSharingSize(
|
setClipboardSharingSize(
|
||||||
settings()
|
settings().value("clipboardSharingSize", (int)ServerConfig::defaultClipboardSharingSize()).toULongLong()
|
||||||
.value(
|
);
|
||||||
"clipboardSharingSize",
|
|
||||||
(int)ServerConfig::defaultClipboardSharingSize())
|
|
||||||
.toULongLong());
|
|
||||||
setClipboardSharing(settings().value("clipboardSharing", true).toBool());
|
setClipboardSharing(settings().value("clipboardSharing", true).toBool());
|
||||||
setClientAddress(settings().value("clientAddress", "").toString());
|
setClientAddress(settings().value("clientAddress", "").toString());
|
||||||
|
|
||||||
readSettings(
|
readSettings(settings(), switchCorners(), "switchCorner", 0, static_cast<int>(NumSwitchCorners));
|
||||||
settings(), switchCorners(), "switchCorner", 0,
|
|
||||||
static_cast<int>(NumSwitchCorners));
|
|
||||||
|
|
||||||
int numScreens = settings().beginReadArray("screens");
|
int numScreens = settings().beginReadArray("screens");
|
||||||
Q_ASSERT(numScreens <= screens().size());
|
Q_ASSERT(numScreens <= screens().size());
|
||||||
@ -220,15 +212,14 @@ void ServerConfig::recall() {
|
|||||||
settings().endGroup();
|
settings().endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerConfig::adjacentScreenIndex(
|
int ServerConfig::adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const
|
||||||
int idx, int deltaColumn, int deltaRow) const {
|
{
|
||||||
if (screens()[idx].isNull())
|
if (screens()[idx].isNull())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// if we're at the left or right end of the table, don't find results going
|
// if we're at the left or right end of the table, don't find results going
|
||||||
// further left or right
|
// further left or right
|
||||||
if ((deltaColumn > 0 && (idx + 1) % numColumns() == 0) ||
|
if ((deltaColumn > 0 && (idx + 1) % numColumns() == 0) || (deltaColumn < 0 && idx % numColumns() == 0))
|
||||||
(deltaColumn < 0 && idx % numColumns() == 0))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int arrayPos = idx + deltaColumn + deltaRow * numColumns();
|
int arrayPos = idx + deltaColumn + deltaRow * numColumns();
|
||||||
@ -239,7 +230,8 @@ int ServerConfig::adjacentScreenIndex(
|
|||||||
return arrayPos;
|
return arrayPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config)
|
||||||
|
{
|
||||||
outStream << "section: screens" << Qt::endl;
|
outStream << "section: screens" << Qt::endl;
|
||||||
|
|
||||||
foreach (const Screen &s, config.screens())
|
foreach (const Screen &s, config.screens())
|
||||||
@ -262,13 +254,10 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
|||||||
if (!config.screens()[i].isNull()) {
|
if (!config.screens()[i].isNull()) {
|
||||||
outStream << "\t" << config.screens()[i].name() << ":" << Qt::endl;
|
outStream << "\t" << config.screens()[i].name() << ":" << Qt::endl;
|
||||||
|
|
||||||
for (unsigned int j = 0;
|
for (unsigned int j = 0; j < sizeof(neighbourDirs) / sizeof(neighbourDirs[0]); j++) {
|
||||||
j < sizeof(neighbourDirs) / sizeof(neighbourDirs[0]); j++) {
|
int idx = config.adjacentScreenIndex(i, neighbourDirs[j].x, neighbourDirs[j].y);
|
||||||
int idx = config.adjacentScreenIndex(
|
|
||||||
i, neighbourDirs[j].x, neighbourDirs[j].y);
|
|
||||||
if (idx != -1 && !config.screens()[idx].isNull())
|
if (idx != -1 && !config.screens()[idx].isNull())
|
||||||
outStream << "\t\t" << neighbourDirs[j].name << " = "
|
outStream << "\t\t" << neighbourDirs[j].name << " = " << config.screens()[idx].name() << Qt::endl;
|
||||||
<< config.screens()[idx].name() << Qt::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,20 +270,15 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
|||||||
<< "heartbeat = " << config.heartbeat() << Qt::endl;
|
<< "heartbeat = " << config.heartbeat() << Qt::endl;
|
||||||
|
|
||||||
outStream << "\t"
|
outStream << "\t"
|
||||||
<< "relativeMouseMoves = "
|
<< "relativeMouseMoves = " << (config.relativeMouseMoves() ? "true" : "false") << Qt::endl;
|
||||||
<< (config.relativeMouseMoves() ? "true" : "false") << Qt::endl;
|
|
||||||
outStream << "\t"
|
outStream << "\t"
|
||||||
<< "win32KeepForeground = "
|
<< "win32KeepForeground = " << (config.win32KeepForeground() ? "true" : "false") << Qt::endl;
|
||||||
<< (config.win32KeepForeground() ? "true" : "false") << Qt::endl;
|
|
||||||
outStream << "\t"
|
outStream << "\t"
|
||||||
<< "disableLockToScreen = "
|
<< "disableLockToScreen = " << (config.disableLockToScreen() ? "true" : "false") << Qt::endl;
|
||||||
<< (config.disableLockToScreen() ? "true" : "false") << Qt::endl;
|
|
||||||
outStream << "\t"
|
outStream << "\t"
|
||||||
<< "clipboardSharing = "
|
<< "clipboardSharing = " << (config.clipboardSharing() ? "true" : "false") << Qt::endl;
|
||||||
<< (config.clipboardSharing() ? "true" : "false") << Qt::endl;
|
|
||||||
outStream << "\t"
|
outStream << "\t"
|
||||||
<< "clipboardSharingSize = " << config.clipboardSharingSize()
|
<< "clipboardSharingSize = " << config.clipboardSharingSize() << Qt::endl;
|
||||||
<< Qt::endl;
|
|
||||||
|
|
||||||
if (!config.getClientAddress().isEmpty()) {
|
if (!config.getClientAddress().isEmpty()) {
|
||||||
outStream << "\t"
|
outStream << "\t"
|
||||||
@ -327,7 +311,8 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
|||||||
return outStream;
|
return outStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerConfig::numScreens() const {
|
int ServerConfig::numScreens() const
|
||||||
|
{
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
|
|
||||||
foreach (const Screen &s, screens())
|
foreach (const Screen &s, screens())
|
||||||
@ -337,7 +322,8 @@ int ServerConfig::numScreens() const {
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerConfig::autoAddScreen(const QString name) {
|
int ServerConfig::autoAddScreen(const QString name)
|
||||||
|
{
|
||||||
int serverIndex = -1;
|
int serverIndex = -1;
|
||||||
int targetIndex = -1;
|
int targetIndex = -1;
|
||||||
if (!findScreenName(m_pAppConfig->screenName(), serverIndex) &&
|
if (!findScreenName(m_pAppConfig->screenName(), serverIndex) &&
|
||||||
@ -377,8 +363,7 @@ int ServerConfig::autoAddScreen(const QString name) {
|
|||||||
dirIndex = 3;
|
dirIndex = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = adjacentScreenIndex(
|
int idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
||||||
startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
|
||||||
while (idx != -1) {
|
while (idx != -1) {
|
||||||
if (screens()[idx].isNull()) {
|
if (screens()[idx].isNull()) {
|
||||||
m_Screens[idx].setName(name);
|
m_Screens[idx].setName(name);
|
||||||
@ -387,8 +372,7 @@ int ServerConfig::autoAddScreen(const QString name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startIndex += offset;
|
startIndex += offset;
|
||||||
idx = adjacentScreenIndex(
|
idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
||||||
startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@ -399,11 +383,13 @@ int ServerConfig::autoAddScreen(const QString name) {
|
|||||||
return kAutoAddScreenOk;
|
return kAutoAddScreenOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &ServerConfig::getServerName() const {
|
const QString &ServerConfig::getServerName() const
|
||||||
|
{
|
||||||
return m_pAppConfig->screenName();
|
return m_pAppConfig->screenName();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::updateServerName() {
|
void ServerConfig::updateServerName()
|
||||||
|
{
|
||||||
for (auto &screen : screens()) {
|
for (auto &screen : screens()) {
|
||||||
if (screen.isServer()) {
|
if (screen.isServer()) {
|
||||||
screen.setName(m_pAppConfig->screenName());
|
screen.setName(m_pAppConfig->screenName());
|
||||||
@ -412,15 +398,18 @@ void ServerConfig::updateServerName() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &ServerConfig::configFile() const {
|
const QString &ServerConfig::configFile() const
|
||||||
|
{
|
||||||
return m_pAppConfig->configFile();
|
return m_pAppConfig->configFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::useExternalConfig() const {
|
bool ServerConfig::useExternalConfig() const
|
||||||
|
{
|
||||||
return m_pAppConfig->useExternalConfig();
|
return m_pAppConfig->useExternalConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::isFull() const {
|
bool ServerConfig::isFull() const
|
||||||
|
{
|
||||||
bool isFull = true;
|
bool isFull = true;
|
||||||
|
|
||||||
for (const auto &screen : screens()) {
|
for (const auto &screen : screens()) {
|
||||||
@ -433,7 +422,8 @@ bool ServerConfig::isFull() const {
|
|||||||
return isFull;
|
return isFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::screenExists(const QString &screenName) const {
|
bool ServerConfig::screenExists(const QString &screenName) const
|
||||||
|
{
|
||||||
bool isExists = false;
|
bool isExists = false;
|
||||||
|
|
||||||
for (const auto &screen : screens()) {
|
for (const auto &screen : screens()) {
|
||||||
@ -446,7 +436,8 @@ bool ServerConfig::screenExists(const QString &screenName) const {
|
|||||||
return isExists;
|
return isExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::addClient(const QString &clientName) {
|
void ServerConfig::addClient(const QString &clientName)
|
||||||
|
{
|
||||||
int serverIndex = -1;
|
int serverIndex = -1;
|
||||||
|
|
||||||
if (findScreenName(m_pAppConfig->screenName(), serverIndex)) {
|
if (findScreenName(m_pAppConfig->screenName(), serverIndex)) {
|
||||||
@ -458,15 +449,18 @@ void ServerConfig::addClient(const QString &clientName) {
|
|||||||
m_Screens.addScreenByPriority(Screen(clientName));
|
m_Screens.addScreenByPriority(Screen(clientName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::setConfigFile(const QString &configFile) {
|
void ServerConfig::setConfigFile(const QString &configFile)
|
||||||
|
{
|
||||||
m_pAppConfig->setConfigFile(configFile);
|
m_pAppConfig->setConfigFile(configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::setUseExternalConfig(bool useExternalConfig) {
|
void ServerConfig::setUseExternalConfig(bool useExternalConfig)
|
||||||
|
{
|
||||||
m_pAppConfig->setUseExternalConfig(useExternalConfig);
|
m_pAppConfig->setUseExternalConfig(useExternalConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::findScreenName(const QString &name, int &index) {
|
bool ServerConfig::findScreenName(const QString &name, int &index)
|
||||||
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int i = 0; i < screens().size(); i++) {
|
for (int i = 0; i < screens().size(); i++) {
|
||||||
if (!screens()[i].isNull() && screens()[i].name().compare(name) == 0) {
|
if (!screens()[i].isNull() && screens()[i].name().compare(name) == 0) {
|
||||||
@ -478,7 +472,8 @@ bool ServerConfig::findScreenName(const QString &name, int &index) {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfig::fixNoServer(const QString &name, int &index) {
|
bool ServerConfig::fixNoServer(const QString &name, int &index)
|
||||||
|
{
|
||||||
bool fixed = false;
|
bool fixed = false;
|
||||||
if (screens()[serverDefaultIndex].isNull()) {
|
if (screens()[serverDefaultIndex].isNull()) {
|
||||||
m_Screens[serverDefaultIndex].setName(name);
|
m_Screens[serverDefaultIndex].setName(name);
|
||||||
@ -490,7 +485,8 @@ bool ServerConfig::fixNoServer(const QString &name, int &index) {
|
|||||||
return fixed;
|
return fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerConfig::showAddClientDialog(const QString &clientName) {
|
int ServerConfig::showAddClientDialog(const QString &clientName)
|
||||||
|
{
|
||||||
int result = kAddClientIgnore;
|
int result = kAddClientIgnore;
|
||||||
|
|
||||||
if (!m_pMainWindow->isActiveWindow()) {
|
if (!m_pMainWindow->isActiveWindow()) {
|
||||||
@ -505,7 +501,8 @@ int ServerConfig::showAddClientDialog(const QString &clientName) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ::ServerConfig::addToFirstEmptyGrid(const QString &clientName) {
|
void ::ServerConfig::addToFirstEmptyGrid(const QString &clientName)
|
||||||
|
{
|
||||||
for (int i = 0; i < screens().size(); i++) {
|
for (int i = 0; i < screens().size(); i++) {
|
||||||
if (screens()[i].isNull()) {
|
if (screens()[i].isNull()) {
|
||||||
m_Screens[i].setName(clientName);
|
m_Screens[i].setName(clientName);
|
||||||
@ -514,11 +511,13 @@ void ::ServerConfig::addToFirstEmptyGrid(const QString &clientName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ServerConfig::defaultClipboardSharingSize() {
|
size_t ServerConfig::defaultClipboardSharingSize()
|
||||||
|
{
|
||||||
return 3 * 1024; // 3 MiB
|
return 3 * 1024; // 3 MiB
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ServerConfig::setClipboardSharingSize(size_t size) {
|
size_t ServerConfig::setClipboardSharingSize(size_t size)
|
||||||
|
{
|
||||||
if (size) {
|
if (size) {
|
||||||
size += 512; // Round up to the nearest megabyte
|
size += 512; // Round up to the nearest megabyte
|
||||||
size /= 1024;
|
size /= 1024;
|
||||||
@ -532,13 +531,15 @@ size_t ServerConfig::setClipboardSharingSize(size_t size) {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfig::setClientAddress(const QString &address) {
|
void ServerConfig::setClientAddress(const QString &address)
|
||||||
|
{
|
||||||
if (m_pAppConfig->invertConnection()) {
|
if (m_pAppConfig->invertConnection()) {
|
||||||
m_ClientAddress = address;
|
m_ClientAddress = address;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ServerConfig::getClientAddress() const {
|
QString ServerConfig::getClientAddress() const
|
||||||
|
{
|
||||||
QString clientAddress;
|
QString clientAddress;
|
||||||
|
|
||||||
if (m_pAppConfig->invertConnection()) {
|
if (m_pAppConfig->invertConnection()) {
|
||||||
@ -548,6 +549,7 @@ QString ServerConfig::getClientAddress() const {
|
|||||||
return clientAddress;
|
return clientAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettingsProxy &ServerConfig::settings() {
|
QSettingsProxy &ServerConfig::settings()
|
||||||
|
{
|
||||||
return m_pAppConfig->scopes().activeSettings();
|
return m_pAppConfig->scopes().activeSettings();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,17 +36,15 @@ class ServerConfigDialog;
|
|||||||
class MainWindow;
|
class MainWindow;
|
||||||
class AppConfig;
|
class AppConfig;
|
||||||
|
|
||||||
class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig {
|
class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig
|
||||||
|
{
|
||||||
using QSettingsProxy = deskflow::gui::proxy::QSettingsProxy;
|
using QSettingsProxy = deskflow::gui::proxy::QSettingsProxy;
|
||||||
|
|
||||||
friend class ServerConfigDialog;
|
friend class ServerConfigDialog;
|
||||||
friend QTextStream &
|
friend QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
|
||||||
operator<<(QTextStream &outStream, const ServerConfig &config);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerConfig(
|
ServerConfig(AppConfig &appConfig, MainWindow &mainWindow, int columns = kDefaultColumns, int rows = kDefaultRows);
|
||||||
AppConfig &appConfig, MainWindow &mainWindow,
|
|
||||||
int columns = kDefaultColumns, int rows = kDefaultRows);
|
|
||||||
~ServerConfig() override = default;
|
~ServerConfig() override = default;
|
||||||
|
|
||||||
bool operator==(const ServerConfig &sc) const;
|
bool operator==(const ServerConfig &sc) const;
|
||||||
@ -54,29 +52,86 @@ public:
|
|||||||
//
|
//
|
||||||
// Overrides
|
// Overrides
|
||||||
//
|
//
|
||||||
const ScreenList &screens() const override { return m_Screens; }
|
const ScreenList &screens() const override
|
||||||
bool enableDragAndDrop() const override { return m_EnableDragAndDrop; }
|
{
|
||||||
|
return m_Screens;
|
||||||
|
}
|
||||||
|
bool enableDragAndDrop() const override
|
||||||
|
{
|
||||||
|
return m_EnableDragAndDrop;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// New methods
|
// New methods
|
||||||
//
|
//
|
||||||
int numColumns() const { return m_Columns; }
|
int numColumns() const
|
||||||
int numRows() const { return m_Rows; }
|
{
|
||||||
bool hasHeartbeat() const { return m_HasHeartbeat; }
|
return m_Columns;
|
||||||
int heartbeat() const { return m_Heartbeat; }
|
}
|
||||||
bool relativeMouseMoves() const { return m_RelativeMouseMoves; }
|
int numRows() const
|
||||||
bool win32KeepForeground() const { return m_Win32KeepForeground; }
|
{
|
||||||
bool hasSwitchDelay() const { return m_HasSwitchDelay; }
|
return m_Rows;
|
||||||
int switchDelay() const { return m_SwitchDelay; }
|
}
|
||||||
bool hasSwitchDoubleTap() const { return m_HasSwitchDoubleTap; }
|
bool hasHeartbeat() const
|
||||||
int switchDoubleTap() const { return m_SwitchDoubleTap; }
|
{
|
||||||
bool switchCorner(int c) const { return m_SwitchCorners[c]; }
|
return m_HasHeartbeat;
|
||||||
int switchCornerSize() const { return m_SwitchCornerSize; }
|
}
|
||||||
const QList<bool> &switchCorners() const { return m_SwitchCorners; }
|
int heartbeat() const
|
||||||
const HotkeyList &hotkeys() const { return m_Hotkeys; }
|
{
|
||||||
bool disableLockToScreen() const { return m_DisableLockToScreen; }
|
return m_Heartbeat;
|
||||||
bool clipboardSharing() const { return m_ClipboardSharing; }
|
}
|
||||||
size_t clipboardSharingSize() const { return m_ClipboardSharingSize; }
|
bool relativeMouseMoves() const
|
||||||
|
{
|
||||||
|
return m_RelativeMouseMoves;
|
||||||
|
}
|
||||||
|
bool win32KeepForeground() const
|
||||||
|
{
|
||||||
|
return m_Win32KeepForeground;
|
||||||
|
}
|
||||||
|
bool hasSwitchDelay() const
|
||||||
|
{
|
||||||
|
return m_HasSwitchDelay;
|
||||||
|
}
|
||||||
|
int switchDelay() const
|
||||||
|
{
|
||||||
|
return m_SwitchDelay;
|
||||||
|
}
|
||||||
|
bool hasSwitchDoubleTap() const
|
||||||
|
{
|
||||||
|
return m_HasSwitchDoubleTap;
|
||||||
|
}
|
||||||
|
int switchDoubleTap() const
|
||||||
|
{
|
||||||
|
return m_SwitchDoubleTap;
|
||||||
|
}
|
||||||
|
bool switchCorner(int c) const
|
||||||
|
{
|
||||||
|
return m_SwitchCorners[c];
|
||||||
|
}
|
||||||
|
int switchCornerSize() const
|
||||||
|
{
|
||||||
|
return m_SwitchCornerSize;
|
||||||
|
}
|
||||||
|
const QList<bool> &switchCorners() const
|
||||||
|
{
|
||||||
|
return m_SwitchCorners;
|
||||||
|
}
|
||||||
|
const HotkeyList &hotkeys() const
|
||||||
|
{
|
||||||
|
return m_Hotkeys;
|
||||||
|
}
|
||||||
|
bool disableLockToScreen() const
|
||||||
|
{
|
||||||
|
return m_DisableLockToScreen;
|
||||||
|
}
|
||||||
|
bool clipboardSharing() const
|
||||||
|
{
|
||||||
|
return m_ClipboardSharing;
|
||||||
|
}
|
||||||
|
size_t clipboardSharingSize() const
|
||||||
|
{
|
||||||
|
return m_ClipboardSharingSize;
|
||||||
|
}
|
||||||
static size_t defaultClipboardSharingSize();
|
static size_t defaultClipboardSharingSize();
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -105,29 +160,89 @@ private:
|
|||||||
void recall();
|
void recall();
|
||||||
void setupScreens();
|
void setupScreens();
|
||||||
QSettingsProxy &settings();
|
QSettingsProxy &settings();
|
||||||
ScreenList &screens() { return m_Screens; }
|
ScreenList &screens()
|
||||||
void setScreens(const ScreenList &screens) { m_Screens = screens; }
|
{
|
||||||
void addScreen(const Screen &screen) { m_Screens.append(screen); }
|
return m_Screens;
|
||||||
void setNumColumns(int n) { m_Columns = n; }
|
}
|
||||||
void setNumRows(int n) { m_Rows = n; }
|
void setScreens(const ScreenList &screens)
|
||||||
void haveHeartbeat(bool on) { m_HasHeartbeat = on; }
|
{
|
||||||
void setHeartbeat(int val) { m_Heartbeat = val; }
|
m_Screens = screens;
|
||||||
void setRelativeMouseMoves(bool on) { m_RelativeMouseMoves = on; }
|
}
|
||||||
void setWin32KeepForeground(bool on) { m_Win32KeepForeground = on; }
|
void addScreen(const Screen &screen)
|
||||||
void haveSwitchDelay(bool on) { m_HasSwitchDelay = on; }
|
{
|
||||||
void setSwitchDelay(int val) { m_SwitchDelay = val; }
|
m_Screens.append(screen);
|
||||||
void haveSwitchDoubleTap(bool on) { m_HasSwitchDoubleTap = on; }
|
}
|
||||||
void setSwitchDoubleTap(int val) { m_SwitchDoubleTap = val; }
|
void setNumColumns(int n)
|
||||||
void setSwitchCorner(int c, bool on) { m_SwitchCorners[c] = on; }
|
{
|
||||||
void setSwitchCornerSize(int val) { m_SwitchCornerSize = val; }
|
m_Columns = n;
|
||||||
void setEnableDragAndDrop(bool on) { m_EnableDragAndDrop = on; }
|
}
|
||||||
void setDisableLockToScreen(bool on) { m_DisableLockToScreen = on; }
|
void setNumRows(int n)
|
||||||
void setClipboardSharing(bool on) { m_ClipboardSharing = on; }
|
{
|
||||||
|
m_Rows = n;
|
||||||
|
}
|
||||||
|
void haveHeartbeat(bool on)
|
||||||
|
{
|
||||||
|
m_HasHeartbeat = on;
|
||||||
|
}
|
||||||
|
void setHeartbeat(int val)
|
||||||
|
{
|
||||||
|
m_Heartbeat = val;
|
||||||
|
}
|
||||||
|
void setRelativeMouseMoves(bool on)
|
||||||
|
{
|
||||||
|
m_RelativeMouseMoves = on;
|
||||||
|
}
|
||||||
|
void setWin32KeepForeground(bool on)
|
||||||
|
{
|
||||||
|
m_Win32KeepForeground = on;
|
||||||
|
}
|
||||||
|
void haveSwitchDelay(bool on)
|
||||||
|
{
|
||||||
|
m_HasSwitchDelay = on;
|
||||||
|
}
|
||||||
|
void setSwitchDelay(int val)
|
||||||
|
{
|
||||||
|
m_SwitchDelay = val;
|
||||||
|
}
|
||||||
|
void haveSwitchDoubleTap(bool on)
|
||||||
|
{
|
||||||
|
m_HasSwitchDoubleTap = on;
|
||||||
|
}
|
||||||
|
void setSwitchDoubleTap(int val)
|
||||||
|
{
|
||||||
|
m_SwitchDoubleTap = val;
|
||||||
|
}
|
||||||
|
void setSwitchCorner(int c, bool on)
|
||||||
|
{
|
||||||
|
m_SwitchCorners[c] = on;
|
||||||
|
}
|
||||||
|
void setSwitchCornerSize(int val)
|
||||||
|
{
|
||||||
|
m_SwitchCornerSize = val;
|
||||||
|
}
|
||||||
|
void setEnableDragAndDrop(bool on)
|
||||||
|
{
|
||||||
|
m_EnableDragAndDrop = on;
|
||||||
|
}
|
||||||
|
void setDisableLockToScreen(bool on)
|
||||||
|
{
|
||||||
|
m_DisableLockToScreen = on;
|
||||||
|
}
|
||||||
|
void setClipboardSharing(bool on)
|
||||||
|
{
|
||||||
|
m_ClipboardSharing = on;
|
||||||
|
}
|
||||||
void setConfigFile(const QString &configFile);
|
void setConfigFile(const QString &configFile);
|
||||||
void setUseExternalConfig(bool useExternalConfig);
|
void setUseExternalConfig(bool useExternalConfig);
|
||||||
size_t setClipboardSharingSize(size_t size);
|
size_t setClipboardSharingSize(size_t size);
|
||||||
QList<bool> &switchCorners() { return m_SwitchCorners; }
|
QList<bool> &switchCorners()
|
||||||
HotkeyList &hotkeys() { return m_Hotkeys; }
|
{
|
||||||
|
return m_SwitchCorners;
|
||||||
|
}
|
||||||
|
HotkeyList &hotkeys()
|
||||||
|
{
|
||||||
|
return m_Hotkeys;
|
||||||
|
}
|
||||||
int adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const;
|
int adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const;
|
||||||
bool findScreenName(const QString &name, int &index);
|
bool findScreenName(const QString &name, int &index);
|
||||||
bool fixNoServer(const QString &name, int &index);
|
bool fixNoServer(const QString &name, int &index);
|
||||||
@ -161,7 +276,8 @@ private:
|
|||||||
|
|
||||||
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
|
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
kAutoAddScreenOk,
|
kAutoAddScreenOk,
|
||||||
kAutoAddScreenManualServer,
|
kAutoAddScreenManualServer,
|
||||||
kAutoAddScreenManualClient,
|
kAutoAddScreenManualClient,
|
||||||
|
|||||||
@ -30,19 +30,17 @@
|
|||||||
|
|
||||||
using enum ScreenConfig::SwitchCorner;
|
using enum ScreenConfig::SwitchCorner;
|
||||||
|
|
||||||
ServerConfigDialog::ServerConfigDialog(
|
ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig)
|
||||||
QWidget *parent, ServerConfig &config, AppConfig &appConfig)
|
|
||||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||||
Ui::ServerConfigDialogBase(),
|
Ui::ServerConfigDialogBase(),
|
||||||
m_OriginalServerConfig(config),
|
m_OriginalServerConfig(config),
|
||||||
m_OriginalServerConfigIsExternal(config.useExternalConfig()),
|
m_OriginalServerConfigIsExternal(config.useExternalConfig()),
|
||||||
m_OriginalServerConfigUsesExternalFile(config.configFile()),
|
m_OriginalServerConfigUsesExternalFile(config.configFile()),
|
||||||
m_ServerConfig(config),
|
m_ServerConfig(config),
|
||||||
m_ScreenSetupModel(
|
m_ScreenSetupModel(serverConfig().screens(), serverConfig().numColumns(), serverConfig().numRows()),
|
||||||
serverConfig().screens(), serverConfig().numColumns(),
|
|
||||||
serverConfig().numRows()),
|
|
||||||
m_Message(""),
|
m_Message(""),
|
||||||
m_appConfig(appConfig) {
|
m_appConfig(appConfig)
|
||||||
|
{
|
||||||
|
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
@ -55,10 +53,8 @@ ServerConfigDialog::ServerConfigDialog(
|
|||||||
m_pCheckBoxHeartbeat->setChecked(serverConfig().hasHeartbeat());
|
m_pCheckBoxHeartbeat->setChecked(serverConfig().hasHeartbeat());
|
||||||
m_pSpinBoxHeartbeat->setValue(serverConfig().heartbeat());
|
m_pSpinBoxHeartbeat->setValue(serverConfig().heartbeat());
|
||||||
|
|
||||||
m_pCheckBoxRelativeMouseMoves->setChecked(
|
m_pCheckBoxRelativeMouseMoves->setChecked(serverConfig().relativeMouseMoves());
|
||||||
serverConfig().relativeMouseMoves());
|
m_pCheckBoxWin32KeepForeground->setChecked(serverConfig().win32KeepForeground());
|
||||||
m_pCheckBoxWin32KeepForeground->setChecked(
|
|
||||||
serverConfig().win32KeepForeground());
|
|
||||||
|
|
||||||
m_pCheckBoxSwitchDelay->setChecked(serverConfig().hasSwitchDelay());
|
m_pCheckBoxSwitchDelay->setChecked(serverConfig().hasSwitchDelay());
|
||||||
m_pSpinBoxSwitchDelay->setValue(serverConfig().switchDelay());
|
m_pSpinBoxSwitchDelay->setValue(serverConfig().switchDelay());
|
||||||
@ -66,21 +62,15 @@ ServerConfigDialog::ServerConfigDialog(
|
|||||||
m_pCheckBoxSwitchDoubleTap->setChecked(serverConfig().hasSwitchDoubleTap());
|
m_pCheckBoxSwitchDoubleTap->setChecked(serverConfig().hasSwitchDoubleTap());
|
||||||
m_pSpinBoxSwitchDoubleTap->setValue(serverConfig().switchDoubleTap());
|
m_pSpinBoxSwitchDoubleTap->setValue(serverConfig().switchDoubleTap());
|
||||||
|
|
||||||
m_pCheckBoxCornerTopLeft->setChecked(
|
m_pCheckBoxCornerTopLeft->setChecked(serverConfig().switchCorner(static_cast<int>(TopLeft)));
|
||||||
serverConfig().switchCorner(static_cast<int>(TopLeft)));
|
m_pCheckBoxCornerTopRight->setChecked(serverConfig().switchCorner(static_cast<int>(TopRight)));
|
||||||
m_pCheckBoxCornerTopRight->setChecked(
|
m_pCheckBoxCornerBottomLeft->setChecked(serverConfig().switchCorner(static_cast<int>(BottomLeft)));
|
||||||
serverConfig().switchCorner(static_cast<int>(TopRight)));
|
m_pCheckBoxCornerBottomRight->setChecked(serverConfig().switchCorner(static_cast<int>(BottomRight)));
|
||||||
m_pCheckBoxCornerBottomLeft->setChecked(
|
|
||||||
serverConfig().switchCorner(static_cast<int>(BottomLeft)));
|
|
||||||
m_pCheckBoxCornerBottomRight->setChecked(
|
|
||||||
serverConfig().switchCorner(static_cast<int>(BottomRight)));
|
|
||||||
m_pSpinBoxSwitchCornerSize->setValue(serverConfig().switchCornerSize());
|
m_pSpinBoxSwitchCornerSize->setValue(serverConfig().switchCornerSize());
|
||||||
m_pCheckBoxDisableLockToScreen->setChecked(
|
m_pCheckBoxDisableLockToScreen->setChecked(serverConfig().disableLockToScreen());
|
||||||
serverConfig().disableLockToScreen());
|
|
||||||
|
|
||||||
m_pCheckBoxEnableClipboard->setChecked(serverConfig().clipboardSharing());
|
m_pCheckBoxEnableClipboard->setChecked(serverConfig().clipboardSharing());
|
||||||
int clipboardSharingSizeM =
|
int clipboardSharingSizeM = static_cast<int>(serverConfig().clipboardSharingSize() / 1024);
|
||||||
static_cast<int>(serverConfig().clipboardSharingSize() / 1024);
|
|
||||||
m_pSpinBoxClipboardSizeLimit->setValue(clipboardSharingSizeM);
|
m_pSpinBoxClipboardSizeLimit->setValue(clipboardSharingSizeM);
|
||||||
m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing());
|
m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing());
|
||||||
|
|
||||||
@ -90,223 +80,164 @@ ServerConfigDialog::ServerConfigDialog(
|
|||||||
m_pScreenSetupView->setModel(&m_ScreenSetupModel);
|
m_pScreenSetupView->setModel(&m_ScreenSetupModel);
|
||||||
|
|
||||||
auto &screens = serverConfig().screens();
|
auto &screens = serverConfig().screens();
|
||||||
auto server = std::find_if(
|
auto server = std::find_if(screens.begin(), screens.end(), [this](const Screen &screen) {
|
||||||
screens.begin(), screens.end(), [this](const Screen &screen) {
|
return (screen.name() == serverConfig().getServerName());
|
||||||
return (screen.name() == serverConfig().getServerName());
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (server == screens.end()) {
|
if (server == screens.end()) {
|
||||||
Screen serverScreen(serverConfig().getServerName());
|
Screen serverScreen(serverConfig().getServerName());
|
||||||
serverScreen.markAsServer();
|
serverScreen.markAsServer();
|
||||||
model().screen(
|
model().screen(serverConfig().numColumns() / 2, serverConfig().numRows() / 2) = serverScreen;
|
||||||
serverConfig().numColumns() / 2, serverConfig().numRows() / 2) =
|
|
||||||
serverScreen;
|
|
||||||
} else {
|
} else {
|
||||||
server->markAsServer();
|
server->markAsServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pButtonAddComputer->setEnabled(!model().isFull());
|
m_pButtonAddComputer->setEnabled(!model().isFull());
|
||||||
connect(
|
connect(m_pTrashScreenWidget, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved);
|
||||||
m_pTrashScreenWidget, &TrashScreenWidget::screenRemoved, this,
|
|
||||||
&ServerConfigDialog::onScreenRemoved);
|
|
||||||
|
|
||||||
onChange();
|
onChange();
|
||||||
|
|
||||||
// computers
|
// computers
|
||||||
connect(
|
connect(&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
|
||||||
&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this,
|
|
||||||
&ServerConfigDialog::onChange);
|
|
||||||
|
|
||||||
#if QT_VERSION <= QT_VERSION_CHECK(6, 7, 0)
|
#if QT_VERSION <= QT_VERSION_CHECK(6, 7, 0)
|
||||||
// advanced
|
// advanced
|
||||||
connect(
|
connect(m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged, this,
|
serverConfig().haveSwitchDelay(v);
|
||||||
[this](const int &v) {
|
onChange();
|
||||||
serverConfig().haveSwitchDelay(v);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
});
|
serverConfig().haveSwitchDoubleTap(v);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged, this,
|
});
|
||||||
[this](const int &v) {
|
connect(m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
serverConfig().haveSwitchDoubleTap(v);
|
serverConfig().setClipboardSharing(v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
});
|
||||||
connect(
|
connect(m_pCheckBoxHeartbeat, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged, this,
|
serverConfig().haveHeartbeat(v);
|
||||||
[this](const int &v) {
|
onChange();
|
||||||
serverConfig().setClipboardSharing(v);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
});
|
serverConfig().setRelativeMouseMoves(v);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxHeartbeat, &QCheckBox::stateChanged, this,
|
});
|
||||||
[this](const int &v) {
|
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
serverConfig().haveHeartbeat(v);
|
serverConfig().setWin32KeepForeground(v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
});
|
||||||
connect(
|
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged, this,
|
serverConfig().setDisableLockToScreen(v);
|
||||||
[this](const int &v) {
|
onChange();
|
||||||
serverConfig().setRelativeMouseMoves(v);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxCornerTopLeft, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
});
|
serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged, this,
|
});
|
||||||
[this](const int &v) {
|
connect(m_pCheckBoxCornerTopRight, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
serverConfig().setWin32KeepForeground(v);
|
serverConfig().setSwitchCorner(static_cast<int>(TopRight), v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
});
|
||||||
connect(
|
connect(m_pCheckBoxCornerBottomLeft, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged, this,
|
serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v);
|
||||||
[this](const int &v) {
|
onChange();
|
||||||
serverConfig().setDisableLockToScreen(v);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxCornerBottomRight, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
});
|
serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxCornerTopLeft, &QCheckBox::stateChanged, this,
|
});
|
||||||
[this](const int &v) {
|
|
||||||
serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
connect(
|
|
||||||
m_pCheckBoxCornerTopRight, &QCheckBox::stateChanged, this,
|
|
||||||
[this](const int &v) {
|
|
||||||
serverConfig().setSwitchCorner(static_cast<int>(TopRight), v);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
connect(
|
|
||||||
m_pCheckBoxCornerBottomLeft, &QCheckBox::stateChanged, this,
|
|
||||||
[this](const int &v) {
|
|
||||||
serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
connect(
|
|
||||||
m_pCheckBoxCornerBottomRight, &QCheckBox::stateChanged, this,
|
|
||||||
[this](const int &v) {
|
|
||||||
serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
// config
|
// config
|
||||||
connect(
|
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||||
m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged, this,
|
serverConfig().setUseExternalConfig(v);
|
||||||
[this](const int &v) {
|
onChange();
|
||||||
serverConfig().setUseExternalConfig(v);
|
});
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
#else
|
#else
|
||||||
connect(
|
connect(m_pCheckBoxSwitchDelay, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
m_pCheckBoxSwitchDelay, &QCheckBox::checkStateChanged, this,
|
serverConfig().haveSwitchDelay(v == Qt::Checked);
|
||||||
[this](const Qt::CheckState &v) {
|
onChange();
|
||||||
serverConfig().haveSwitchDelay(v == Qt::Checked);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
});
|
serverConfig().haveSwitchDoubleTap(v == Qt::Checked);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxSwitchDoubleTap, &QCheckBox::checkStateChanged, this,
|
});
|
||||||
[this](const Qt::CheckState &v) {
|
connect(m_pCheckBoxEnableClipboard, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
serverConfig().haveSwitchDoubleTap(v == Qt::Checked);
|
serverConfig().setClipboardSharing(v == Qt::Checked);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
});
|
||||||
connect(
|
connect(m_pCheckBoxHeartbeat, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
m_pCheckBoxEnableClipboard, &QCheckBox::checkStateChanged, this,
|
serverConfig().haveHeartbeat(v == Qt::Checked);
|
||||||
[this](const Qt::CheckState &v) {
|
onChange();
|
||||||
serverConfig().setClipboardSharing(v == Qt::Checked);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
});
|
serverConfig().setRelativeMouseMoves(v == Qt::Checked);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxHeartbeat, &QCheckBox::checkStateChanged, this,
|
});
|
||||||
[this](const Qt::CheckState &v) {
|
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
serverConfig().haveHeartbeat(v == Qt::Checked);
|
serverConfig().setWin32KeepForeground(v == Qt::Checked);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
});
|
||||||
connect(
|
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
m_pCheckBoxRelativeMouseMoves, &QCheckBox::checkStateChanged, this,
|
serverConfig().setDisableLockToScreen(v == Qt::Checked);
|
||||||
[this](const Qt::CheckState &v) {
|
onChange();
|
||||||
serverConfig().setRelativeMouseMoves(v == Qt::Checked);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxCornerTopLeft, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
});
|
serverConfig().setSwitchCorner(static_cast<int>(TopLeft), v == Qt::Checked);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxWin32KeepForeground, &QCheckBox::checkStateChanged, this,
|
});
|
||||||
[this](const Qt::CheckState &v) {
|
connect(m_pCheckBoxCornerTopRight, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
serverConfig().setWin32KeepForeground(v == Qt::Checked);
|
serverConfig().setSwitchCorner(static_cast<int>(TopRight), v == Qt::Checked);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
});
|
||||||
connect(
|
connect(m_pCheckBoxCornerBottomLeft, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
m_pCheckBoxDisableLockToScreen, &QCheckBox::checkStateChanged, this,
|
serverConfig().setSwitchCorner(static_cast<int>(BottomLeft), v == Qt::Checked);
|
||||||
[this](const Qt::CheckState &v) {
|
onChange();
|
||||||
serverConfig().setDisableLockToScreen(v == Qt::Checked);
|
});
|
||||||
onChange();
|
connect(m_pCheckBoxCornerBottomRight, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
});
|
serverConfig().setSwitchCorner(static_cast<int>(BottomRight), v == Qt::Checked);
|
||||||
connect(
|
onChange();
|
||||||
m_pCheckBoxCornerTopLeft, &QCheckBox::checkStateChanged, this,
|
});
|
||||||
[this](const Qt::CheckState &v) {
|
|
||||||
serverConfig().setSwitchCorner(
|
|
||||||
static_cast<int>(TopLeft), v == Qt::Checked);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
connect(
|
|
||||||
m_pCheckBoxCornerTopRight, &QCheckBox::checkStateChanged, this,
|
|
||||||
[this](const Qt::CheckState &v) {
|
|
||||||
serverConfig().setSwitchCorner(
|
|
||||||
static_cast<int>(TopRight), v == Qt::Checked);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
connect(
|
|
||||||
m_pCheckBoxCornerBottomLeft, &QCheckBox::checkStateChanged, this,
|
|
||||||
[this](const Qt::CheckState &v) {
|
|
||||||
serverConfig().setSwitchCorner(
|
|
||||||
static_cast<int>(BottomLeft), v == Qt::Checked);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
connect(
|
|
||||||
m_pCheckBoxCornerBottomRight, &QCheckBox::checkStateChanged, this,
|
|
||||||
[this](const Qt::CheckState &v) {
|
|
||||||
serverConfig().setSwitchCorner(
|
|
||||||
static_cast<int>(BottomRight), v == Qt::Checked);
|
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
// config
|
// config
|
||||||
connect(
|
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||||
m_pCheckBoxUseExternalConfig, &QCheckBox::checkStateChanged, this,
|
serverConfig().setUseExternalConfig(v == Qt::Checked);
|
||||||
[this](const Qt::CheckState &v) {
|
onChange();
|
||||||
serverConfig().setUseExternalConfig(v == Qt::Checked);
|
});
|
||||||
onChange();
|
|
||||||
});
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(
|
connect(
|
||||||
m_pSpinBoxSwitchDelay,
|
m_pSpinBoxSwitchDelay, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
|
||||||
[this](const int &v) {
|
[this](const int &v) {
|
||||||
serverConfig().setSwitchDelay(v);
|
serverConfig().setSwitchDelay(v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
connect(
|
connect(
|
||||||
m_pSpinBoxSwitchDoubleTap,
|
m_pSpinBoxSwitchDoubleTap, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
|
||||||
[this](const int &v) {
|
[this](const int &v) {
|
||||||
serverConfig().setSwitchDoubleTap(v);
|
serverConfig().setSwitchDoubleTap(v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
connect(
|
connect(
|
||||||
m_pSpinBoxClipboardSizeLimit,
|
m_pSpinBoxClipboardSizeLimit, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
|
||||||
[this](const int &v) {
|
[this](const int &v) {
|
||||||
serverConfig().setClipboardSharingSize(v * 1024);
|
serverConfig().setClipboardSharingSize(v * 1024);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
connect(
|
connect(
|
||||||
m_pSpinBoxHeartbeat,
|
m_pSpinBoxHeartbeat, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
|
||||||
[this](const int &v) {
|
[this](const int &v) {
|
||||||
serverConfig().setHeartbeat(v);
|
serverConfig().setHeartbeat(v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
connect(
|
connect(
|
||||||
m_pSpinBoxSwitchCornerSize,
|
m_pSpinBoxSwitchCornerSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
|
||||||
[this](const int &v) {
|
[this](const int &v) {
|
||||||
serverConfig().setSwitchCornerSize(v);
|
serverConfig().setSwitchCornerSize(v);
|
||||||
onChange();
|
onChange();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
connect(m_pEditConfigFile, &QLineEdit::textChanged, this, [this]() {
|
connect(m_pEditConfigFile, &QLineEdit::textChanged, this, [this]() {
|
||||||
serverConfig().setConfigFile(m_pEditConfigFile->text());
|
serverConfig().setConfigFile(m_pEditConfigFile->text());
|
||||||
@ -314,11 +245,13 @@ ServerConfigDialog::ServerConfigDialog(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfigDialog::addClient(const QString &clientName) {
|
bool ServerConfigDialog::addClient(const QString &clientName)
|
||||||
|
{
|
||||||
return addComputer(clientName, true);
|
return addComputer(clientName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::showEvent(QShowEvent *event) {
|
void ServerConfigDialog::showEvent(QShowEvent *event)
|
||||||
|
{
|
||||||
QDialog::show();
|
QDialog::show();
|
||||||
|
|
||||||
if (!m_Message.isEmpty()) {
|
if (!m_Message.isEmpty()) {
|
||||||
@ -327,16 +260,15 @@ void ServerConfigDialog::showEvent(QShowEvent *event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::accept() {
|
void ServerConfigDialog::accept()
|
||||||
if (m_pCheckBoxUseExternalConfig->isChecked() &&
|
{
|
||||||
!QFile::exists(m_pEditConfigFile->text())) {
|
if (m_pCheckBoxUseExternalConfig->isChecked() && !QFile::exists(m_pEditConfigFile->text())) {
|
||||||
|
|
||||||
auto selectedButton = QMessageBox::warning(
|
auto selectedButton = QMessageBox::warning(
|
||||||
this, "Filename invalid", "Please select a valid configuration file.",
|
this, "Filename invalid", "Please select a valid configuration file.", QMessageBox::Ok | QMessageBox::Ignore
|
||||||
QMessageBox::Ok | QMessageBox::Ignore);
|
);
|
||||||
|
|
||||||
if (selectedButton != QMessageBox::Ok ||
|
if (selectedButton != QMessageBox::Ok || !on_m_pButtonBrowseConfigFile_clicked()) {
|
||||||
!on_m_pButtonBrowseConfigFile_clicked()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,14 +280,16 @@ void ServerConfigDialog::accept() {
|
|||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::reject() {
|
void ServerConfigDialog::reject()
|
||||||
|
{
|
||||||
serverConfig().setUseExternalConfig(m_OriginalServerConfigIsExternal);
|
serverConfig().setUseExternalConfig(m_OriginalServerConfigIsExternal);
|
||||||
serverConfig().setConfigFile(m_OriginalServerConfigUsesExternalFile);
|
serverConfig().setConfigFile(m_OriginalServerConfigUsesExternalFile);
|
||||||
|
|
||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked() {
|
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked()
|
||||||
|
{
|
||||||
Hotkey hotkey;
|
Hotkey hotkey;
|
||||||
HotkeyDialog dlg(this, hotkey);
|
HotkeyDialog dlg(this, hotkey);
|
||||||
if (dlg.exec() == QDialog::Accepted) {
|
if (dlg.exec() == QDialog::Accepted) {
|
||||||
@ -365,7 +299,8 @@ void ServerConfigDialog::on_m_pButtonNewHotkey_clicked() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonEditHotkey_clicked() {
|
void ServerConfigDialog::on_m_pButtonEditHotkey_clicked()
|
||||||
|
{
|
||||||
int idx = m_pListHotkeys->currentRow();
|
int idx = m_pListHotkeys->currentRow();
|
||||||
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
||||||
Hotkey &hotkey = serverConfig().hotkeys()[idx];
|
Hotkey &hotkey = serverConfig().hotkeys()[idx];
|
||||||
@ -376,7 +311,8 @@ void ServerConfigDialog::on_m_pButtonEditHotkey_clicked() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked() {
|
void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked()
|
||||||
|
{
|
||||||
int idx = m_pListHotkeys->currentRow();
|
int idx = m_pListHotkeys->currentRow();
|
||||||
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
||||||
serverConfig().hotkeys().removeAt(idx);
|
serverConfig().hotkeys().removeAt(idx);
|
||||||
@ -385,7 +321,8 @@ void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked() {
|
|||||||
onChange();
|
onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged() {
|
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged()
|
||||||
|
{
|
||||||
bool itemsSelected = !m_pListHotkeys->selectedItems().isEmpty();
|
bool itemsSelected = !m_pListHotkeys->selectedItems().isEmpty();
|
||||||
m_pButtonEditHotkey->setEnabled(itemsSelected);
|
m_pButtonEditHotkey->setEnabled(itemsSelected);
|
||||||
m_pButtonRemoveHotkey->setEnabled(itemsSelected);
|
m_pButtonRemoveHotkey->setEnabled(itemsSelected);
|
||||||
@ -413,7 +350,8 @@ void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonNewAction_clicked() {
|
void ServerConfigDialog::on_m_pButtonNewAction_clicked()
|
||||||
|
{
|
||||||
int idx = m_pListHotkeys->currentRow();
|
int idx = m_pListHotkeys->currentRow();
|
||||||
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
||||||
Hotkey &hotkey = serverConfig().hotkeys()[idx];
|
Hotkey &hotkey = serverConfig().hotkeys()[idx];
|
||||||
@ -427,7 +365,8 @@ void ServerConfigDialog::on_m_pButtonNewAction_clicked() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonEditAction_clicked() {
|
void ServerConfigDialog::on_m_pButtonEditAction_clicked()
|
||||||
|
{
|
||||||
int idxHotkey = m_pListHotkeys->currentRow();
|
int idxHotkey = m_pListHotkeys->currentRow();
|
||||||
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
|
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
|
||||||
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
|
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
|
||||||
@ -443,7 +382,8 @@ void ServerConfigDialog::on_m_pButtonEditAction_clicked() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() {
|
void ServerConfigDialog::on_m_pButtonRemoveAction_clicked()
|
||||||
|
{
|
||||||
int idxHotkey = m_pListHotkeys->currentRow();
|
int idxHotkey = m_pListHotkeys->currentRow();
|
||||||
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
|
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
|
||||||
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
|
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
|
||||||
@ -456,31 +396,34 @@ void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() {
|
|||||||
onChange();
|
onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(
|
void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(int const state)
|
||||||
int const state) {
|
{
|
||||||
m_pSpinBoxClipboardSizeLimit->setEnabled(state == Qt::Checked);
|
m_pSpinBoxClipboardSizeLimit->setEnabled(state == Qt::Checked);
|
||||||
if ((state == Qt::Checked) && (!m_pSpinBoxClipboardSizeLimit->value())) {
|
if ((state == Qt::Checked) && (!m_pSpinBoxClipboardSizeLimit->value())) {
|
||||||
int size = static_cast<int>(
|
int size = static_cast<int>((serverConfig().defaultClipboardSharingSize() + 512) / 1024);
|
||||||
(serverConfig().defaultClipboardSharingSize() + 512) / 1024);
|
|
||||||
m_pSpinBoxClipboardSizeLimit->setValue(size ? size : 1);
|
m_pSpinBoxClipboardSizeLimit->setValue(size ? size : 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pListActions_itemSelectionChanged() {
|
void ServerConfigDialog::on_m_pListActions_itemSelectionChanged()
|
||||||
|
{
|
||||||
m_pButtonEditAction->setEnabled(!m_pListActions->selectedItems().isEmpty());
|
m_pButtonEditAction->setEnabled(!m_pListActions->selectedItems().isEmpty());
|
||||||
m_pButtonRemoveAction->setEnabled(!m_pListActions->selectedItems().isEmpty());
|
m_pButtonRemoveAction->setEnabled(!m_pListActions->selectedItems().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pButtonAddComputer_clicked() {
|
void ServerConfigDialog::on_m_pButtonAddComputer_clicked()
|
||||||
|
{
|
||||||
addComputer("", false);
|
addComputer("", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::onScreenRemoved() {
|
void ServerConfigDialog::onScreenRemoved()
|
||||||
|
{
|
||||||
m_pButtonAddComputer->setEnabled(true);
|
m_pButtonAddComputer->setEnabled(true);
|
||||||
onChange();
|
onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked) {
|
void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked)
|
||||||
|
{
|
||||||
m_pLabelConfigFile->setEnabled(checked);
|
m_pLabelConfigFile->setEnabled(checked);
|
||||||
m_pEditConfigFile->setEnabled(checked);
|
m_pEditConfigFile->setEnabled(checked);
|
||||||
m_pButtonBrowseConfigFile->setEnabled(checked);
|
m_pButtonBrowseConfigFile->setEnabled(checked);
|
||||||
@ -490,19 +433,15 @@ void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked) {
|
|||||||
m_pTabWidget->setTabEnabled(2, !checked);
|
m_pTabWidget->setTabEnabled(2, !checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked() {
|
bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked()
|
||||||
|
{
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
const QString deskflowConfigFilter(
|
const QString deskflowConfigFilter(QString("%1 Configurations (*.sgc);;All files (*.*)").arg(DESKFLOW_APP_NAME));
|
||||||
QString("%1 Configurations (*.sgc);;All files (*.*)")
|
|
||||||
.arg(DESKFLOW_APP_NAME));
|
|
||||||
#else
|
#else
|
||||||
const QString deskflowConfigFilter(
|
const QString deskflowConfigFilter(QString("%1 Configurations (*.conf);;All files (*.*)").arg(DESKFLOW_APP_NAME));
|
||||||
QString("%1 Configurations (*.conf);;All files (*.*)")
|
|
||||||
.arg(DESKFLOW_APP_NAME));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString fileName = QFileDialog::getOpenFileName(
|
QString fileName = QFileDialog::getOpenFileName(this, "Browse for a config file", "", deskflowConfigFilter);
|
||||||
this, "Browse for a config file", "", deskflowConfigFilter);
|
|
||||||
|
|
||||||
if (!fileName.isEmpty()) {
|
if (!fileName.isEmpty()) {
|
||||||
m_pEditConfigFile->setText(fileName);
|
m_pEditConfigFile->setText(fileName);
|
||||||
@ -512,7 +451,8 @@ bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent) {
|
bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent)
|
||||||
|
{
|
||||||
bool isAccepted = false;
|
bool isAccepted = false;
|
||||||
Screen newScreen(clientName);
|
Screen newScreen(clientName);
|
||||||
|
|
||||||
@ -526,11 +466,10 @@ bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent) {
|
|||||||
return isAccepted;
|
return isAccepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerConfigDialog::onChange() {
|
void ServerConfigDialog::onChange()
|
||||||
bool isAppConfigDataEqual =
|
{
|
||||||
m_OriginalServerConfigIsExternal == serverConfig().useExternalConfig() &&
|
bool isAppConfigDataEqual = m_OriginalServerConfigIsExternal == serverConfig().useExternalConfig() &&
|
||||||
m_OriginalServerConfigUsesExternalFile == serverConfig().configFile();
|
m_OriginalServerConfigUsesExternalFile == serverConfig().configFile();
|
||||||
m_pButtonBox->button(QDialogButtonBox::Ok)
|
m_pButtonBox->button(QDialogButtonBox::Ok)
|
||||||
->setEnabled(
|
->setEnabled(!isAppConfigDataEqual || !(m_OriginalServerConfig == m_ServerConfig));
|
||||||
!isAppConfigDataEqual || !(m_OriginalServerConfig == m_ServerConfig));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,19 +25,22 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase {
|
class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ServerConfigDialog(
|
ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig);
|
||||||
QWidget *parent, ServerConfig &config, AppConfig &appConfig);
|
|
||||||
bool addClient(const QString &clientName);
|
bool addClient(const QString &clientName);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
void reject() override;
|
void reject() override;
|
||||||
void showEvent(QShowEvent *event) override;
|
void showEvent(QShowEvent *event) override;
|
||||||
void message(const QString &message) { m_Message = message; }
|
void message(const QString &message)
|
||||||
|
{
|
||||||
|
m_Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_m_pButtonNewHotkey_clicked();
|
void on_m_pButtonNewHotkey_clicked();
|
||||||
@ -57,12 +60,22 @@ protected slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool addComputer(const QString &clientName, bool doSilent);
|
bool addComputer(const QString &clientName, bool doSilent);
|
||||||
ServerConfig &serverConfig() { return m_ServerConfig; }
|
ServerConfig &serverConfig()
|
||||||
void setOriginalServerConfig(const ServerConfig &s) {
|
{
|
||||||
|
return m_ServerConfig;
|
||||||
|
}
|
||||||
|
void setOriginalServerConfig(const ServerConfig &s)
|
||||||
|
{
|
||||||
m_OriginalServerConfig = s;
|
m_OriginalServerConfig = s;
|
||||||
}
|
}
|
||||||
ScreenSetupModel &model() { return m_ScreenSetupModel; }
|
ScreenSetupModel &model()
|
||||||
AppConfig &appConfig() { return m_appConfig; }
|
{
|
||||||
|
return m_ScreenSetupModel;
|
||||||
|
}
|
||||||
|
AppConfig &appConfig()
|
||||||
|
{
|
||||||
|
return m_appConfig;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ServerConfig &m_OriginalServerConfig;
|
ServerConfig &m_OriginalServerConfig;
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
using namespace deskflow::gui;
|
using namespace deskflow::gui;
|
||||||
|
|
||||||
SetupWizard::SetupWizard(AppConfig &appConfig) : m_appConfig(appConfig) {
|
SetupWizard::SetupWizard(AppConfig &appConfig) : m_appConfig(appConfig)
|
||||||
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
setWindowTitle(QString("Setup %1").arg(DESKFLOW_APP_NAME));
|
setWindowTitle(QString("Setup %1").arg(DESKFLOW_APP_NAME));
|
||||||
@ -31,26 +32,28 @@ SetupWizard::SetupWizard(AppConfig &appConfig) : m_appConfig(appConfig) {
|
|||||||
m_pLabelError->setStyleSheet(kStyleErrorActiveLabel);
|
m_pLabelError->setStyleSheet(kStyleErrorActiveLabel);
|
||||||
|
|
||||||
m_pLineEditName->setText(appConfig.screenName());
|
m_pLineEditName->setText(appConfig.screenName());
|
||||||
m_pLineEditName->setValidator(new validators::ScreenNameValidator(
|
m_pLineEditName->setValidator(
|
||||||
m_pLineEditName, new validators::ValidationError(this, m_pLabelError)));
|
new validators::ScreenNameValidator(m_pLineEditName, new validators::ValidationError(this, m_pLabelError))
|
||||||
|
);
|
||||||
|
|
||||||
connect(m_pButtonApply, &QPushButton::clicked, this, &SetupWizard::accept);
|
connect(m_pButtonApply, &QPushButton::clicked, this, &SetupWizard::accept);
|
||||||
connect(
|
connect(m_pLineEditName, &QLineEdit::textChanged, this, &SetupWizard::onLineEditNameChanged);
|
||||||
m_pLineEditName, &QLineEdit::textChanged, this,
|
|
||||||
&SetupWizard::onLineEditNameChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupWizard::accept() {
|
void SetupWizard::accept()
|
||||||
|
{
|
||||||
m_appConfig.setWizardHasRun();
|
m_appConfig.setWizardHasRun();
|
||||||
m_appConfig.setScreenName(m_pLineEditName->text());
|
m_appConfig.setScreenName(m_pLineEditName->text());
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupWizard::onLineEditNameChanged(const QString &error) {
|
void SetupWizard::onLineEditNameChanged(const QString &error)
|
||||||
|
{
|
||||||
m_pButtonApply->setEnabled(m_pLineEditName->hasAcceptableInput());
|
m_pButtonApply->setEnabled(m_pLineEditName->hasAcceptableInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupWizard::reject() {
|
void SetupWizard::reject()
|
||||||
|
{
|
||||||
QDialog::reject();
|
QDialog::reject();
|
||||||
QApplication::exit();
|
QApplication::exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,8 @@
|
|||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
class SetupWizard : public QDialog, public Ui::SetupWizardBase {
|
class SetupWizard : public QDialog, public Ui::SetupWizardBase
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -22,7 +22,8 @@
|
|||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
void TrashScreenWidget::dragEnterEvent(QDragEnterEvent *event) {
|
void TrashScreenWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
||||||
event->setDropAction(Qt::MoveAction);
|
event->setDropAction(Qt::MoveAction);
|
||||||
event->accept();
|
event->accept();
|
||||||
@ -30,7 +31,8 @@ void TrashScreenWidget::dragEnterEvent(QDragEnterEvent *event) {
|
|||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrashScreenWidget::dropEvent(QDropEvent *event) {
|
void TrashScreenWidget::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
emit screenRemoved();
|
emit screenRemoved();
|
||||||
|
|||||||
@ -23,11 +23,14 @@ class QWidget;
|
|||||||
class QDragEnterEvent;
|
class QDragEnterEvent;
|
||||||
class QDropEvent;
|
class QDropEvent;
|
||||||
|
|
||||||
class TrashScreenWidget : public QLabel {
|
class TrashScreenWidget : public QLabel
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TrashScreenWidget(QWidget *parent) : QLabel(parent) {}
|
TrashScreenWidget(QWidget *parent) : QLabel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void dragEnterEvent(QDragEnterEvent *event);
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
|||||||
@ -51,21 +51,26 @@
|
|||||||
|
|
||||||
using namespace deskflow::gui;
|
using namespace deskflow::gui;
|
||||||
|
|
||||||
class QThreadImpl : public QThread {
|
class QThreadImpl : public QThread
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
static void msleep(unsigned long msecs) { QThread::msleep(msecs); }
|
static void msleep(unsigned long msecs)
|
||||||
|
{
|
||||||
|
QThread::msleep(msecs);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
bool checkMacAssistiveDevices();
|
bool checkMacAssistiveDevices();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool hasArg(const QString &arg, const QStringList &args) {
|
bool hasArg(const QString &arg, const QStringList &args)
|
||||||
return std::ranges::any_of(
|
{
|
||||||
args, [&arg](const QString &a) { return a == arg; });
|
return std::ranges::any_of(args, [&arg](const QString &a) { return a == arg; });
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
/* Workaround for QTBUG-40332 - "High ping when QNetworkAccessManager is
|
/* Workaround for QTBUG-40332 - "High ping when QNetworkAccessManager is
|
||||||
@ -95,7 +100,8 @@ int main(int argc, char *argv[]) {
|
|||||||
QMessageBox::information(
|
QMessageBox::information(
|
||||||
NULL, DESKFLOW_APP_NAME,
|
NULL, DESKFLOW_APP_NAME,
|
||||||
"Please drag " DESKFLOW_APP_NAME " to the Applications folder, "
|
"Please drag " DESKFLOW_APP_NAME " to the Applications folder, "
|
||||||
"and open it from there.");
|
"and open it from there."
|
||||||
|
);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +115,7 @@ int main(int argc, char *argv[]) {
|
|||||||
// --no-reset
|
// --no-reset
|
||||||
QStringList arguments = QCoreApplication::arguments();
|
QStringList arguments = QCoreApplication::arguments();
|
||||||
const auto noReset = hasArg("--no-reset", arguments);
|
const auto noReset = hasArg("--no-reset", arguments);
|
||||||
const auto resetEnvVar =
|
const auto resetEnvVar = strToTrue(qEnvironmentVariable("DESKFLOW_RESET_ALL"));
|
||||||
strToTrue(qEnvironmentVariable("DESKFLOW_RESET_ALL"));
|
|
||||||
if (resetEnvVar && !noReset) {
|
if (resetEnvVar && !noReset) {
|
||||||
diagnostic::clearSettings(configScopes, false);
|
diagnostic::clearSettings(configScopes, false);
|
||||||
}
|
}
|
||||||
@ -118,8 +123,8 @@ int main(int argc, char *argv[]) {
|
|||||||
AppConfig appConfig(configScopes);
|
AppConfig appConfig(configScopes);
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&configScopes, &ConfigScopes::saving, &appConfig,
|
&configScopes, &ConfigScopes::saving, &appConfig, [&appConfig]() { appConfig.commit(); }, Qt::DirectConnection
|
||||||
[&appConfig]() { appConfig.commit(); }, Qt::DirectConnection);
|
);
|
||||||
|
|
||||||
if (appConfig.wizardShouldRun()) {
|
if (appConfig.wizardShouldRun()) {
|
||||||
SetupWizard wizard(appConfig);
|
SetupWizard wizard(appConfig);
|
||||||
@ -134,9 +139,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
MainWindow mainWindow(configScopes, appConfig);
|
MainWindow mainWindow(configScopes, appConfig);
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(&app, &DeskflowApplication::aboutToQuit, &mainWindow, &MainWindow::onAppAboutToQuit);
|
||||||
&app, &DeskflowApplication::aboutToQuit, &mainWindow,
|
|
||||||
&MainWindow::onAppAboutToQuit);
|
|
||||||
|
|
||||||
mainWindow.open();
|
mainWindow.open();
|
||||||
|
|
||||||
@ -148,7 +151,8 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_MAC)
|
#if defined(Q_OS_MAC)
|
||||||
bool checkMacAssistiveDevices() {
|
bool checkMacAssistiveDevices()
|
||||||
|
{
|
||||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 // mavericks
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 // mavericks
|
||||||
|
|
||||||
// new in mavericks, applications are trusted individually
|
// new in mavericks, applications are trusted individually
|
||||||
@ -163,8 +167,7 @@ bool checkMacAssistiveDevices() {
|
|||||||
|
|
||||||
const void *keys[] = {kAXTrustedCheckOptionPrompt};
|
const void *keys[] = {kAXTrustedCheckOptionPrompt};
|
||||||
const void *trueValue[] = {kCFBooleanTrue};
|
const void *trueValue[] = {kCFBooleanTrue};
|
||||||
CFDictionaryRef options =
|
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
|
||||||
CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
|
|
||||||
|
|
||||||
bool result = AXIsProcessTrustedWithOptions(options);
|
bool result = AXIsProcessTrustedWithOptions(options);
|
||||||
CFRelease(options);
|
CFRelease(options);
|
||||||
@ -179,7 +182,8 @@ bool checkMacAssistiveDevices() {
|
|||||||
NULL, DESKFLOW_APP_NAME,
|
NULL, DESKFLOW_APP_NAME,
|
||||||
"Please enable access to assistive devices "
|
"Please enable access to assistive devices "
|
||||||
"System Preferences -> Security & Privacy -> "
|
"System Preferences -> Security & Privacy -> "
|
||||||
"Privacy -> Accessibility, then re-open " DESKFLOW_APP_NAME ".");
|
"Privacy -> Accessibility, then re-open " DESKFLOW_APP_NAME "."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|||||||
@ -28,20 +28,26 @@
|
|||||||
|
|
||||||
Arch *Arch::s_instance = NULL;
|
Arch *Arch::s_instance = NULL;
|
||||||
|
|
||||||
Arch::Arch() {
|
Arch::Arch()
|
||||||
|
{
|
||||||
assert(s_instance == NULL);
|
assert(s_instance == NULL);
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arch::Arch(Arch *arch) { s_instance = arch; }
|
Arch::Arch(Arch *arch)
|
||||||
|
{
|
||||||
|
s_instance = arch;
|
||||||
|
}
|
||||||
|
|
||||||
Arch::~Arch() {
|
Arch::~Arch()
|
||||||
|
{
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
ArchMiscWindows::cleanup();
|
ArchMiscWindows::cleanup();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Arch::init() {
|
void Arch::init()
|
||||||
|
{
|
||||||
ARCH_NETWORK::init();
|
ARCH_NETWORK::init();
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
ARCH_TASKBAR::init();
|
ARCH_TASKBAR::init();
|
||||||
@ -49,7 +55,8 @@ void Arch::init() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Arch *Arch::getInstance() {
|
Arch *Arch::getInstance()
|
||||||
|
{
|
||||||
assert(s_instance != NULL);
|
assert(s_instance != NULL);
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -96,7 +96,8 @@ class Arch : public ARCH_CONSOLE,
|
|||||||
public ARCH_STRING,
|
public ARCH_STRING,
|
||||||
public ARCH_SYSTEM,
|
public ARCH_SYSTEM,
|
||||||
public ARCH_TASKBAR,
|
public ARCH_TASKBAR,
|
||||||
public ARCH_TIME {
|
public ARCH_TIME
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Arch();
|
Arch();
|
||||||
Arch(Arch *arch);
|
Arch(Arch *arch);
|
||||||
@ -120,19 +121,29 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Arch *getInstance();
|
static Arch *getInstance();
|
||||||
|
|
||||||
static void setInstance(Arch *s) { s_instance = s; }
|
static void setInstance(Arch *s)
|
||||||
|
{
|
||||||
|
s_instance = s;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Arch *s_instance;
|
static Arch *s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Convenience object to lock/unlock an arch mutex
|
//! Convenience object to lock/unlock an arch mutex
|
||||||
class ArchMutexLock {
|
class ArchMutexLock
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchMutexLock(ArchMutex mutex) : m_mutex(mutex) { ARCH->lockMutex(m_mutex); }
|
ArchMutexLock(ArchMutex mutex) : m_mutex(mutex)
|
||||||
|
{
|
||||||
|
ARCH->lockMutex(m_mutex);
|
||||||
|
}
|
||||||
ArchMutexLock(ArchMutexLock const &) = delete;
|
ArchMutexLock(ArchMutexLock const &) = delete;
|
||||||
ArchMutexLock(ArchMutexLock &&) = delete;
|
ArchMutexLock(ArchMutexLock &&) = delete;
|
||||||
~ArchMutexLock() { ARCH->unlockMutex(m_mutex); }
|
~ArchMutexLock()
|
||||||
|
{
|
||||||
|
ARCH->unlockMutex(m_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
ArchMutexLock &operator=(ArchMutexLock const &) = delete;
|
ArchMutexLock &operator=(ArchMutexLock const &) = delete;
|
||||||
ArchMutexLock &operator=(ArchMutexLock &&) = delete;
|
ArchMutexLock &operator=(ArchMutexLock &&) = delete;
|
||||||
|
|||||||
@ -21,7 +21,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void ArchConsoleStd::writeConsole(ELevel level, const char *str) {
|
void ArchConsoleStd::writeConsole(ELevel level, const char *str)
|
||||||
|
{
|
||||||
if ((level >= kFATAL) && (level <= kWARNING))
|
if ((level >= kFATAL) && (level <= kWARNING))
|
||||||
std::cerr << str << std::endl;
|
std::cerr << str << std::endl;
|
||||||
else
|
else
|
||||||
|
|||||||
@ -21,14 +21,25 @@
|
|||||||
#include "arch/IArchConsole.h"
|
#include "arch/IArchConsole.h"
|
||||||
|
|
||||||
//! Cross platform implementation of IArchConsole
|
//! Cross platform implementation of IArchConsole
|
||||||
class ArchConsoleStd : public IArchConsole {
|
class ArchConsoleStd : public IArchConsole
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchConsoleStd() {}
|
ArchConsoleStd()
|
||||||
virtual ~ArchConsoleStd() {}
|
{
|
||||||
|
}
|
||||||
|
virtual ~ArchConsoleStd()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// IArchConsole overrides
|
// IArchConsole overrides
|
||||||
virtual void openConsole(const char *title) {}
|
virtual void openConsole(const char *title)
|
||||||
virtual void closeConsole() {}
|
{
|
||||||
virtual void showConsole(bool) {}
|
}
|
||||||
|
virtual void closeConsole()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual void showConsole(bool)
|
||||||
|
{
|
||||||
|
}
|
||||||
virtual void writeConsole(ELevel level, const char *);
|
virtual void writeConsole(ELevel level, const char *);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -22,35 +22,52 @@
|
|||||||
// ArchDaemonNone
|
// ArchDaemonNone
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchDaemonNone::ArchDaemonNone() {
|
ArchDaemonNone::ArchDaemonNone()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchDaemonNone::~ArchDaemonNone() {
|
ArchDaemonNone::~ArchDaemonNone()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchDaemonNone::installDaemon(
|
void ArchDaemonNone::installDaemon(const char *, const char *, const char *, const char *, const char *)
|
||||||
const char *, const char *, const char *, const char *, const char *) {
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchDaemonNone::uninstallDaemon(const char *) {
|
void ArchDaemonNone::uninstallDaemon(const char *)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArchDaemonNone::daemonize(const char *name, DaemonFunc func) {
|
int ArchDaemonNone::daemonize(const char *name, DaemonFunc func)
|
||||||
|
{
|
||||||
// simply forward the call to func. obviously, this doesn't
|
// simply forward the call to func. obviously, this doesn't
|
||||||
// do any daemonizing.
|
// do any daemonizing.
|
||||||
return func(1, &name);
|
return func(1, &name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchDaemonNone::canInstallDaemon(const char *) { return false; }
|
bool ArchDaemonNone::canInstallDaemon(const char *)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ArchDaemonNone::isDaemonInstalled(const char *) { return false; }
|
bool ArchDaemonNone::isDaemonInstalled(const char *)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ArchDaemonNone::installDaemon() {}
|
void ArchDaemonNone::installDaemon()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ArchDaemonNone::uninstallDaemon() {}
|
void ArchDaemonNone::uninstallDaemon()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
std::string ArchDaemonNone::commandLine() const { return ""; }
|
std::string ArchDaemonNone::commandLine() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|||||||
@ -29,15 +29,16 @@ daemons. The install and uninstall functions do nothing, the query
|
|||||||
functions return false, and \c daemonize() simply calls the passed
|
functions return false, and \c daemonize() simply calls the passed
|
||||||
function and returns its result.
|
function and returns its result.
|
||||||
*/
|
*/
|
||||||
class ArchDaemonNone : public IArchDaemon {
|
class ArchDaemonNone : public IArchDaemon
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchDaemonNone();
|
ArchDaemonNone();
|
||||||
virtual ~ArchDaemonNone();
|
virtual ~ArchDaemonNone();
|
||||||
|
|
||||||
// IArchDaemon overrides
|
// IArchDaemon overrides
|
||||||
virtual void installDaemon(
|
virtual void installDaemon(
|
||||||
const char *name, const char *description, const char *pathname,
|
const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies
|
||||||
const char *commandLine, const char *dependencies);
|
);
|
||||||
virtual void uninstallDaemon(const char *name);
|
virtual void uninstallDaemon(const char *name);
|
||||||
virtual int daemonize(const char *name, DaemonFunc func);
|
virtual int daemonize(const char *name, DaemonFunc func);
|
||||||
virtual bool canInstallDaemon(const char *name);
|
virtual bool canInstallDaemon(const char *name);
|
||||||
|
|||||||
@ -26,7 +26,8 @@
|
|||||||
This interface defines the console operations required by
|
This interface defines the console operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchConsole : public IInterface {
|
class IArchConsole : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
|
|||||||
@ -27,7 +27,8 @@ This interface defines the operations required by deskflow for installing
|
|||||||
uninstalling daeamons and daemonizing a process. Each architecture must
|
uninstalling daeamons and daemonizing a process. Each architecture must
|
||||||
implement this interface.
|
implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchDaemon : public IInterface {
|
class IArchDaemon : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
typedef int (*DaemonFunc)(int argc, const char **argv);
|
typedef int (*DaemonFunc)(int argc, const char **argv);
|
||||||
|
|
||||||
@ -48,8 +49,8 @@ public:
|
|||||||
the listed daemons. Throws an \c XArchDaemon exception on failure.
|
the listed daemons. Throws an \c XArchDaemon exception on failure.
|
||||||
*/
|
*/
|
||||||
virtual void installDaemon(
|
virtual void installDaemon(
|
||||||
const char *name, const char *description, const char *pathname,
|
const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies
|
||||||
const char *commandLine, const char *dependencies) = 0;
|
) = 0;
|
||||||
|
|
||||||
//! Uninstall daemon
|
//! Uninstall daemon
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@ -27,7 +27,8 @@
|
|||||||
This interface defines the file system operations required by
|
This interface defines the file system operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchFile : public IInterface {
|
class IArchFile : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
@ -85,8 +86,7 @@ public:
|
|||||||
is longer than allowed by the system; we'll rely on the
|
is longer than allowed by the system; we'll rely on the
|
||||||
system calls to tell us that.
|
system calls to tell us that.
|
||||||
*/
|
*/
|
||||||
virtual std::string
|
virtual std::string concatPath(const std::string &prefix, const std::string &suffix) = 0;
|
||||||
concatPath(const std::string &prefix, const std::string &suffix) = 0;
|
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
//! Set the user's profile directory
|
//! Set the user's profile directory
|
||||||
|
|||||||
@ -26,7 +26,8 @@
|
|||||||
This interface defines the logging operations required by
|
This interface defines the logging operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchLog : public IInterface {
|
class IArchLog : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
|
|||||||
@ -68,7 +68,8 @@ typedef ArchThreadImpl *ArchThread;
|
|||||||
This interface defines the multithreading operations required by
|
This interface defines the multithreading operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchMultithread : public IInterface {
|
class IArchMultithread : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! Type of thread entry point
|
//! Type of thread entry point
|
||||||
typedef void *(*ThreadFunc)(void *);
|
typedef void *(*ThreadFunc)(void *);
|
||||||
@ -79,7 +80,8 @@ public:
|
|||||||
Not all platforms support all signals. Unsupported signals are
|
Not all platforms support all signals. Unsupported signals are
|
||||||
ignored.
|
ignored.
|
||||||
*/
|
*/
|
||||||
enum ESignal {
|
enum ESignal
|
||||||
|
{
|
||||||
kINTERRUPT, //!< Interrupt (e.g. Ctrl+C)
|
kINTERRUPT, //!< Interrupt (e.g. Ctrl+C)
|
||||||
kTERMINATE, //!< Terminate (e.g. Ctrl+Break)
|
kTERMINATE, //!< Terminate (e.g. Ctrl+Break)
|
||||||
kHANGUP, //!< Hangup (SIGHUP)
|
kHANGUP, //!< Hangup (SIGHUP)
|
||||||
|
|||||||
@ -60,24 +60,31 @@ typedef ArchNetAddressImpl *ArchNetAddress;
|
|||||||
This interface defines the networking operations required by
|
This interface defines the networking operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchNetwork : public IInterface {
|
class IArchNetwork : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! Supported address families
|
//! Supported address families
|
||||||
enum EAddressFamily {
|
enum EAddressFamily
|
||||||
|
{
|
||||||
kUNKNOWN,
|
kUNKNOWN,
|
||||||
kINET,
|
kINET,
|
||||||
kINET6,
|
kINET6,
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Supported socket types
|
//! Supported socket types
|
||||||
enum ESocketType { kDGRAM, kSTREAM };
|
enum ESocketType
|
||||||
|
{
|
||||||
|
kDGRAM,
|
||||||
|
kSTREAM
|
||||||
|
};
|
||||||
|
|
||||||
//! Events for \c poll()
|
//! Events for \c poll()
|
||||||
/*!
|
/*!
|
||||||
Events for \c poll() are bitmasks and can be combined using the
|
Events for \c poll() are bitmasks and can be combined using the
|
||||||
bitwise operators.
|
bitwise operators.
|
||||||
*/
|
*/
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
kPOLLIN = 1, //!< Socket is readable
|
kPOLLIN = 1, //!< Socket is readable
|
||||||
kPOLLOUT = 2, //!< Socket is writable
|
kPOLLOUT = 2, //!< Socket is writable
|
||||||
kPOLLERR = 4, //!< The socket is in an error state
|
kPOLLERR = 4, //!< The socket is in an error state
|
||||||
@ -85,7 +92,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! A socket query for \c poll()
|
//! A socket query for \c poll()
|
||||||
class PollEntry {
|
class PollEntry
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! The socket to query
|
//! The socket to query
|
||||||
ArchSocket m_socket;
|
ArchSocket m_socket;
|
||||||
|
|||||||
@ -25,7 +25,8 @@
|
|||||||
This interface defines the sleep operations required by
|
This interface defines the sleep operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchSleep : public IInterface {
|
class IArchSleep : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
|
|||||||
@ -30,15 +30,16 @@ static ArchMutex s_mutex = NULL;
|
|||||||
// use C library non-reentrant multibyte conversion with mutex
|
// use C library non-reentrant multibyte conversion with mutex
|
||||||
//
|
//
|
||||||
|
|
||||||
IArchString::~IArchString() {
|
IArchString::~IArchString()
|
||||||
|
{
|
||||||
if (s_mutex != NULL) {
|
if (s_mutex != NULL) {
|
||||||
ARCH->closeMutex(s_mutex);
|
ARCH->closeMutex(s_mutex);
|
||||||
s_mutex = NULL;
|
s_mutex = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int IArchString::convStringWCToMB(
|
int IArchString::convStringWCToMB(char *dst, const wchar_t *src, UInt32 n, bool *errors)
|
||||||
char *dst, const wchar_t *src, UInt32 n, bool *errors) {
|
{
|
||||||
ptrdiff_t len = 0;
|
ptrdiff_t len = 0;
|
||||||
|
|
||||||
bool dummyErrors;
|
bool dummyErrors;
|
||||||
@ -94,8 +95,8 @@ int IArchString::convStringWCToMB(
|
|||||||
return static_cast<int>(len);
|
return static_cast<int>(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int IArchString::convStringMBToWC(
|
int IArchString::convStringMBToWC(wchar_t *dst, const char *src, UInt32 n, bool *errors)
|
||||||
wchar_t *dst, const char *src, UInt32 n, bool *errors) {
|
{
|
||||||
ptrdiff_t len = 0;
|
ptrdiff_t len = 0;
|
||||||
wchar_t dummy;
|
wchar_t dummy;
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,8 @@
|
|||||||
This interface defines the string operations required by
|
This interface defines the string operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchString : public IInterface {
|
class IArchString : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
IArchString() = default;
|
IArchString() = default;
|
||||||
IArchString(const IArchString &) = delete;
|
IArchString(const IArchString &) = delete;
|
||||||
@ -42,7 +43,8 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
The known wide character encodings
|
The known wide character encodings
|
||||||
*/
|
*/
|
||||||
enum EWideCharEncoding {
|
enum EWideCharEncoding
|
||||||
|
{
|
||||||
kUCS2, //!< The UCS-2 encoding
|
kUCS2, //!< The UCS-2 encoding
|
||||||
kUCS4, //!< The UCS-4 encoding
|
kUCS4, //!< The UCS-4 encoding
|
||||||
kUTF16, //!< The UTF-16 encoding
|
kUTF16, //!< The UTF-16 encoding
|
||||||
|
|||||||
@ -25,7 +25,8 @@
|
|||||||
/*!
|
/*!
|
||||||
This interface defines operations for querying system info.
|
This interface defines operations for querying system info.
|
||||||
*/
|
*/
|
||||||
class IArchSystem : public IInterface {
|
class IArchSystem : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name accessors
|
//! @name accessors
|
||||||
//@{
|
//@{
|
||||||
@ -54,7 +55,6 @@ public:
|
|||||||
/*!
|
/*!
|
||||||
Writes a Deskflow setting from the system.
|
Writes a Deskflow setting from the system.
|
||||||
*/
|
*/
|
||||||
virtual void setting(
|
virtual void setting(const std::string &valueName, const std::string &valueString) const = 0;
|
||||||
const std::string &valueName, const std::string &valueString) const = 0;
|
|
||||||
//@}
|
//@}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,7 +28,8 @@ This interface defines the task bar icon operations required
|
|||||||
by deskflow. Each architecture must implement this interface
|
by deskflow. Each architecture must implement this interface
|
||||||
though each operation can be a no-op.
|
though each operation can be a no-op.
|
||||||
*/
|
*/
|
||||||
class IArchTaskBar : public IInterface {
|
class IArchTaskBar : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
|
|||||||
@ -30,7 +30,8 @@ This interface defines the task bar icon event handlers required
|
|||||||
by deskflow. Each architecture must implement this interface
|
by deskflow. Each architecture must implement this interface
|
||||||
though each operation can be a no-op.
|
though each operation can be a no-op.
|
||||||
*/
|
*/
|
||||||
class IArchTaskBarReceiver : public IInterface {
|
class IArchTaskBarReceiver : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
// Icon data is architecture dependent
|
// Icon data is architecture dependent
|
||||||
typedef void *Icon;
|
typedef void *Icon;
|
||||||
@ -92,7 +93,9 @@ public:
|
|||||||
|
|
||||||
virtual void updateStatus(INode *, const String &errorMsg) = 0;
|
virtual void updateStatus(INode *, const String &errorMsg) = 0;
|
||||||
|
|
||||||
virtual void cleanup() {}
|
virtual void cleanup()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -25,7 +25,8 @@
|
|||||||
This interface defines the time operations required by
|
This interface defines the time operations required by
|
||||||
deskflow. Each architecture must implement this interface.
|
deskflow. Each architecture must implement this interface.
|
||||||
*/
|
*/
|
||||||
class IArchTime : public IInterface {
|
class IArchTime : public IInterface
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
|
|||||||
@ -28,14 +28,18 @@ Exceptions derived from this class are used by the multithreading
|
|||||||
library to perform stack unwinding when a thread terminates. These
|
library to perform stack unwinding when a thread terminates. These
|
||||||
exceptions must always be rethrown by clients when caught.
|
exceptions must always be rethrown by clients when caught.
|
||||||
*/
|
*/
|
||||||
class XThread {};
|
class XThread
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
//! Thread exception to cancel
|
//! Thread exception to cancel
|
||||||
/*!
|
/*!
|
||||||
Thrown to cancel a thread. Clients must not throw this type, but
|
Thrown to cancel a thread. Clients must not throw this type, but
|
||||||
must rethrow it if caught (by XThreadCancel, XThread, or ...).
|
must rethrow it if caught (by XThreadCancel, XThread, or ...).
|
||||||
*/
|
*/
|
||||||
class XThreadCancel : public XThread {};
|
class XThreadCancel : public XThread
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\def RETHROW_XTHREAD
|
\def RETHROW_XTHREAD
|
||||||
@ -43,12 +47,12 @@ Convenience macro to rethrow an XThread exception but ignore other
|
|||||||
exceptions. Put this in your catch (...) handler after necessary
|
exceptions. Put this in your catch (...) handler after necessary
|
||||||
cleanup but before leaving or returning from the handler.
|
cleanup but before leaving or returning from the handler.
|
||||||
*/
|
*/
|
||||||
#define RETHROW_XTHREAD \
|
#define RETHROW_XTHREAD \
|
||||||
try { \
|
try { \
|
||||||
throw; \
|
throw; \
|
||||||
} catch (XThread &) { \
|
} catch (XThread &) { \
|
||||||
throw; \
|
throw; \
|
||||||
} catch (...) { \
|
} catch (...) { \
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Lazy error message string evaluation
|
//! Lazy error message string evaluation
|
||||||
@ -58,30 +62,46 @@ Platforms subclass this type, taking an appropriate error code
|
|||||||
type in the c'tor and overriding eval() to return the error
|
type in the c'tor and overriding eval() to return the error
|
||||||
string for that error code.
|
string for that error code.
|
||||||
*/
|
*/
|
||||||
class XArchEval {
|
class XArchEval
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
XArchEval() {}
|
XArchEval()
|
||||||
virtual ~XArchEval() _NOEXCEPT {}
|
{
|
||||||
|
}
|
||||||
|
virtual ~XArchEval() _NOEXCEPT
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
virtual std::string eval() const = 0;
|
virtual std::string eval() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Generic exception architecture dependent library
|
//! Generic exception architecture dependent library
|
||||||
class XArch : public std::runtime_error {
|
class XArch : public std::runtime_error
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
XArch(XArchEval *adopted) : std::runtime_error(adopted->eval()) {
|
XArch(XArchEval *adopted) : std::runtime_error(adopted->eval())
|
||||||
|
{
|
||||||
delete adopted;
|
delete adopted;
|
||||||
}
|
}
|
||||||
XArch(const std::string &msg) : std::runtime_error(msg) {}
|
XArch(const std::string &msg) : std::runtime_error(msg)
|
||||||
virtual ~XArch() _NOEXCEPT {}
|
{
|
||||||
|
}
|
||||||
|
virtual ~XArch() _NOEXCEPT
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Macro to declare XArch derived types
|
// Macro to declare XArch derived types
|
||||||
#define XARCH_SUBCLASS(name_, super_) \
|
#define XARCH_SUBCLASS(name_, super_) \
|
||||||
class name_ : public super_ { \
|
class name_ : public super_ \
|
||||||
public: \
|
{ \
|
||||||
name_(XArchEval *adoptedEvaluator) : super_(adoptedEvaluator) {} \
|
public: \
|
||||||
name_(const std::string &msg) : super_(msg) {} \
|
name_(XArchEval *adoptedEvaluator) : super_(adoptedEvaluator) \
|
||||||
|
{ \
|
||||||
|
} \
|
||||||
|
name_(const std::string &msg) : super_(msg) \
|
||||||
|
{ \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Generic network exception
|
//! Generic network exception
|
||||||
|
|||||||
@ -37,12 +37,14 @@
|
|||||||
// implementations. hopefully at least the C++ compiler has
|
// implementations. hopefully at least the C++ compiler has
|
||||||
// a built-in wchar_t type.
|
// a built-in wchar_t type.
|
||||||
|
|
||||||
static inline int mbtowc(wchar_t *dst, const char *src, int n) {
|
static inline int mbtowc(wchar_t *dst, const char *src, int n)
|
||||||
|
{
|
||||||
*dst = static_cast<wchar_t>(*src);
|
*dst = static_cast<wchar_t>(*src);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int wctomb(char *dst, wchar_t src) {
|
static inline int wctomb(char *dst, wchar_t src)
|
||||||
|
{
|
||||||
*dst = static_cast<char>(src);
|
*dst = static_cast<char>(src);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
#include "arch/unix/ArchConsoleUnix.h"
|
#include "arch/unix/ArchConsoleUnix.h"
|
||||||
|
|
||||||
ArchConsoleUnix::ArchConsoleUnix() {}
|
ArchConsoleUnix::ArchConsoleUnix()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ArchConsoleUnix::~ArchConsoleUnix() {}
|
ArchConsoleUnix::~ArchConsoleUnix()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
#define ARCH_CONSOLE ArchConsoleUnix
|
#define ARCH_CONSOLE ArchConsoleUnix
|
||||||
|
|
||||||
class ArchConsoleUnix : public ArchConsoleStd {
|
class ArchConsoleUnix : public ArchConsoleStd
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchConsoleUnix();
|
ArchConsoleUnix();
|
||||||
virtual ~ArchConsoleUnix();
|
virtual ~ArchConsoleUnix();
|
||||||
|
|||||||
@ -32,11 +32,13 @@
|
|||||||
// ArchDaemonUnix
|
// ArchDaemonUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchDaemonUnix::ArchDaemonUnix() {
|
ArchDaemonUnix::ArchDaemonUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchDaemonUnix::~ArchDaemonUnix() {
|
ArchDaemonUnix::~ArchDaemonUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +47,8 @@ ArchDaemonUnix::~ArchDaemonUnix() {
|
|||||||
// In Mac OS X, fork()'d child processes can't use most APIs (the frameworks
|
// In Mac OS X, fork()'d child processes can't use most APIs (the frameworks
|
||||||
// that Deskflow uses in fact prevent it and make the process just up and die),
|
// that Deskflow uses in fact prevent it and make the process just up and die),
|
||||||
// so need to exec a copy of the program that doesn't fork so isn't limited.
|
// so need to exec a copy of the program that doesn't fork so isn't limited.
|
||||||
int execSelfNonDaemonized() {
|
int execSelfNonDaemonized()
|
||||||
|
{
|
||||||
extern char **NXArgv;
|
extern char **NXArgv;
|
||||||
char **selfArgv = NXArgv;
|
char **selfArgv = NXArgv;
|
||||||
|
|
||||||
@ -55,11 +58,15 @@ int execSelfNonDaemonized() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alreadyDaemonized() { return getenv("_DESKFLOW_DAEMONIZED") != NULL; }
|
bool alreadyDaemonized()
|
||||||
|
{
|
||||||
|
return getenv("_DESKFLOW_DAEMONIZED") != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ArchDaemonUnix::daemonize(const char *name, DaemonFunc func) {
|
int ArchDaemonUnix::daemonize(const char *name, DaemonFunc func)
|
||||||
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (alreadyDaemonized())
|
if (alreadyDaemonized())
|
||||||
return func(1, &name);
|
return func(1, &name);
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
#define ARCH_DAEMON ArchDaemonUnix
|
#define ARCH_DAEMON ArchDaemonUnix
|
||||||
|
|
||||||
//! Unix implementation of IArchDaemon
|
//! Unix implementation of IArchDaemon
|
||||||
class ArchDaemonUnix : public ArchDaemonNone {
|
class ArchDaemonUnix : public ArchDaemonNone
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchDaemonUnix();
|
ArchDaemonUnix();
|
||||||
virtual ~ArchDaemonUnix();
|
virtual ~ArchDaemonUnix();
|
||||||
|
|||||||
@ -29,15 +29,18 @@
|
|||||||
// ArchFileUnix
|
// ArchFileUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchFileUnix::ArchFileUnix() {
|
ArchFileUnix::ArchFileUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchFileUnix::~ArchFileUnix() {
|
ArchFileUnix::~ArchFileUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ArchFileUnix::getBasename(const char *pathname) {
|
const char *ArchFileUnix::getBasename(const char *pathname)
|
||||||
|
{
|
||||||
if (pathname == NULL) {
|
if (pathname == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -50,7 +53,8 @@ const char *ArchFileUnix::getBasename(const char *pathname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchFileUnix::getUserDirectory() {
|
std::string ArchFileUnix::getUserDirectory()
|
||||||
|
{
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
std::string dir;
|
std::string dir;
|
||||||
#if HAVE_GETPWUID_R
|
#if HAVE_GETPWUID_R
|
||||||
@ -76,9 +80,13 @@ std::string ArchFileUnix::getUserDirectory() {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchFileUnix::getSystemDirectory() { return "/etc"; }
|
std::string ArchFileUnix::getSystemDirectory()
|
||||||
|
{
|
||||||
|
return "/etc";
|
||||||
|
}
|
||||||
|
|
||||||
std::string ArchFileUnix::getInstalledDirectory() {
|
std::string ArchFileUnix::getInstalledDirectory()
|
||||||
|
{
|
||||||
#if WINAPI_XWINDOWS
|
#if WINAPI_XWINDOWS
|
||||||
return "/usr/bin";
|
return "/usr/bin";
|
||||||
#else
|
#else
|
||||||
@ -86,9 +94,13 @@ std::string ArchFileUnix::getInstalledDirectory() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchFileUnix::getLogDirectory() { return "/var/log"; }
|
std::string ArchFileUnix::getLogDirectory()
|
||||||
|
{
|
||||||
|
return "/var/log";
|
||||||
|
}
|
||||||
|
|
||||||
std::string ArchFileUnix::getPluginDirectory() {
|
std::string ArchFileUnix::getPluginDirectory()
|
||||||
|
{
|
||||||
if (!m_pluginDirectory.empty()) {
|
if (!m_pluginDirectory.empty()) {
|
||||||
return m_pluginDirectory;
|
return m_pluginDirectory;
|
||||||
}
|
}
|
||||||
@ -100,7 +112,8 @@ std::string ArchFileUnix::getPluginDirectory() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchFileUnix::getProfileDirectory() {
|
std::string ArchFileUnix::getProfileDirectory()
|
||||||
|
{
|
||||||
if (!m_profileDirectory.empty()) {
|
if (!m_profileDirectory.empty()) {
|
||||||
return m_profileDirectory;
|
return m_profileDirectory;
|
||||||
} else {
|
} else {
|
||||||
@ -118,8 +131,8 @@ std::string ArchFileUnix::getProfileDirectory() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string ArchFileUnix::concatPath(const std::string &prefix, const std::string &suffix)
|
||||||
ArchFileUnix::concatPath(const std::string &prefix, const std::string &suffix) {
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
path.reserve(prefix.size() + 1 + suffix.size());
|
path.reserve(prefix.size() + 1 + suffix.size());
|
||||||
path += prefix;
|
path += prefix;
|
||||||
@ -130,10 +143,12 @@ ArchFileUnix::concatPath(const std::string &prefix, const std::string &suffix) {
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchFileUnix::setProfileDirectory(const String &s) {
|
void ArchFileUnix::setProfileDirectory(const String &s)
|
||||||
|
{
|
||||||
m_profileDirectory = s;
|
m_profileDirectory = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchFileUnix::setPluginDirectory(const String &s) {
|
void ArchFileUnix::setPluginDirectory(const String &s)
|
||||||
|
{
|
||||||
m_pluginDirectory = s;
|
m_pluginDirectory = s;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_FILE ArchFileUnix
|
#define ARCH_FILE ArchFileUnix
|
||||||
|
|
||||||
//! Unix implementation of IArchFile
|
//! Unix implementation of IArchFile
|
||||||
class ArchFileUnix : public IArchFile {
|
class ArchFileUnix : public IArchFile
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchFileUnix();
|
ArchFileUnix();
|
||||||
virtual ~ArchFileUnix();
|
virtual ~ArchFileUnix();
|
||||||
@ -36,8 +37,7 @@ public:
|
|||||||
virtual std::string getLogDirectory();
|
virtual std::string getLogDirectory();
|
||||||
virtual std::string getPluginDirectory();
|
virtual std::string getPluginDirectory();
|
||||||
virtual std::string getProfileDirectory();
|
virtual std::string getProfileDirectory();
|
||||||
virtual std::string
|
virtual std::string concatPath(const std::string &prefix, const std::string &suffix);
|
||||||
concatPath(const std::string &prefix, const std::string &suffix);
|
|
||||||
virtual void setProfileDirectory(const String &s);
|
virtual void setProfileDirectory(const String &s);
|
||||||
virtual void setPluginDirectory(const String &s);
|
virtual void setPluginDirectory(const String &s);
|
||||||
|
|
||||||
|
|||||||
@ -24,23 +24,33 @@
|
|||||||
// ArchLogUnix
|
// ArchLogUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchLogUnix::ArchLogUnix() {
|
ArchLogUnix::ArchLogUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchLogUnix::~ArchLogUnix() {
|
ArchLogUnix::~ArchLogUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchLogUnix::openLog(const char *name) { openlog(name, 0, LOG_DAEMON); }
|
void ArchLogUnix::openLog(const char *name)
|
||||||
|
{
|
||||||
|
openlog(name, 0, LOG_DAEMON);
|
||||||
|
}
|
||||||
|
|
||||||
void ArchLogUnix::closeLog() { closelog(); }
|
void ArchLogUnix::closeLog()
|
||||||
|
{
|
||||||
|
closelog();
|
||||||
|
}
|
||||||
|
|
||||||
void ArchLogUnix::showLog(bool) {
|
void ArchLogUnix::showLog(bool)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchLogUnix::writeLog(ELevel level, const char *msg) {
|
void ArchLogUnix::writeLog(ELevel level, const char *msg)
|
||||||
|
{
|
||||||
// convert level
|
// convert level
|
||||||
int priority;
|
int priority;
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_LOG ArchLogUnix
|
#define ARCH_LOG ArchLogUnix
|
||||||
|
|
||||||
//! Unix implementation of IArchLog
|
//! Unix implementation of IArchLog
|
||||||
class ArchLogUnix : public IArchLog {
|
class ArchLogUnix : public IArchLog
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchLogUnix();
|
ArchLogUnix();
|
||||||
virtual ~ArchLogUnix();
|
virtual ~ArchLogUnix();
|
||||||
|
|||||||
@ -47,7 +47,8 @@
|
|||||||
#define HAVE_POSIX_SIGWAIT 1
|
#define HAVE_POSIX_SIGWAIT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void setSignalSet(sigset_t *sigset) {
|
static void setSignalSet(sigset_t *sigset)
|
||||||
|
{
|
||||||
sigemptyset(sigset);
|
sigemptyset(sigset);
|
||||||
sigaddset(sigset, SIGHUP);
|
sigaddset(sigset, SIGHUP);
|
||||||
sigaddset(sigset, SIGINT);
|
sigaddset(sigset, SIGINT);
|
||||||
@ -59,7 +60,8 @@ static void setSignalSet(sigset_t *sigset) {
|
|||||||
// ArchThreadImpl
|
// ArchThreadImpl
|
||||||
//
|
//
|
||||||
|
|
||||||
class ArchThreadImpl {
|
class ArchThreadImpl
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchThreadImpl();
|
ArchThreadImpl();
|
||||||
|
|
||||||
@ -85,7 +87,8 @@ ArchThreadImpl::ArchThreadImpl()
|
|||||||
m_cancelling(false),
|
m_cancelling(false),
|
||||||
m_exited(false),
|
m_exited(false),
|
||||||
m_result(NULL),
|
m_result(NULL),
|
||||||
m_networkData(NULL) {
|
m_networkData(NULL)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,9 +98,8 @@ ArchThreadImpl::ArchThreadImpl()
|
|||||||
|
|
||||||
ArchMultithreadPosix *ArchMultithreadPosix::s_instance = NULL;
|
ArchMultithreadPosix *ArchMultithreadPosix::s_instance = NULL;
|
||||||
|
|
||||||
ArchMultithreadPosix::ArchMultithreadPosix()
|
ArchMultithreadPosix::ArchMultithreadPosix() : m_newThreadCalled(false), m_nextID(0)
|
||||||
: m_newThreadCalled(false),
|
{
|
||||||
m_nextID(0) {
|
|
||||||
assert(s_instance == NULL);
|
assert(s_instance == NULL);
|
||||||
|
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
@ -143,30 +145,37 @@ ArchMultithreadPosix::ArchMultithreadPosix()
|
|||||||
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
|
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchMultithreadPosix::~ArchMultithreadPosix() {
|
ArchMultithreadPosix::~ArchMultithreadPosix()
|
||||||
|
{
|
||||||
assert(s_instance != NULL);
|
assert(s_instance != NULL);
|
||||||
|
|
||||||
closeMutex(m_threadMutex);
|
closeMutex(m_threadMutex);
|
||||||
s_instance = NULL;
|
s_instance = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data) {
|
void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data)
|
||||||
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
ArchThreadImpl *thread = find(pthread_self());
|
ArchThreadImpl *thread = find(pthread_self());
|
||||||
thread->m_networkData = data;
|
thread->m_networkData = data;
|
||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ArchMultithreadPosix::getNetworkDataForThread(ArchThread thread) {
|
void *ArchMultithreadPosix::getNetworkDataForThread(ArchThread thread)
|
||||||
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
void *data = thread->m_networkData;
|
void *data = thread->m_networkData;
|
||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchMultithreadPosix *ArchMultithreadPosix::getInstance() { return s_instance; }
|
ArchMultithreadPosix *ArchMultithreadPosix::getInstance()
|
||||||
|
{
|
||||||
|
return s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
ArchCond ArchMultithreadPosix::newCondVar() {
|
ArchCond ArchMultithreadPosix::newCondVar()
|
||||||
|
{
|
||||||
ArchCondImpl *cond = new ArchCondImpl;
|
ArchCondImpl *cond = new ArchCondImpl;
|
||||||
int status = pthread_cond_init(&cond->m_cond, NULL);
|
int status = pthread_cond_init(&cond->m_cond, NULL);
|
||||||
(void)status;
|
(void)status;
|
||||||
@ -174,27 +183,30 @@ ArchCond ArchMultithreadPosix::newCondVar() {
|
|||||||
return cond;
|
return cond;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::closeCondVar(ArchCond cond) {
|
void ArchMultithreadPosix::closeCondVar(ArchCond cond)
|
||||||
|
{
|
||||||
int status = pthread_cond_destroy(&cond->m_cond);
|
int status = pthread_cond_destroy(&cond->m_cond);
|
||||||
(void)status;
|
(void)status;
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
delete cond;
|
delete cond;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::signalCondVar(ArchCond cond) {
|
void ArchMultithreadPosix::signalCondVar(ArchCond cond)
|
||||||
|
{
|
||||||
int status = pthread_cond_signal(&cond->m_cond);
|
int status = pthread_cond_signal(&cond->m_cond);
|
||||||
(void)status;
|
(void)status;
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::broadcastCondVar(ArchCond cond) {
|
void ArchMultithreadPosix::broadcastCondVar(ArchCond cond)
|
||||||
|
{
|
||||||
int status = pthread_cond_broadcast(&cond->m_cond);
|
int status = pthread_cond_broadcast(&cond->m_cond);
|
||||||
(void)status;
|
(void)status;
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchMultithreadPosix::waitCondVar(
|
bool ArchMultithreadPosix::waitCondVar(ArchCond cond, ArchMutex mutex, double timeout)
|
||||||
ArchCond cond, ArchMutex mutex, double timeout) {
|
{
|
||||||
// we can't wait on a condition variable and also wake it up for
|
// we can't wait on a condition variable and also wake it up for
|
||||||
// cancellation since we don't use posix cancellation. so we
|
// cancellation since we don't use posix cancellation. so we
|
||||||
// must wake up periodically to check for cancellation. we
|
// must wake up periodically to check for cancellation. we
|
||||||
@ -227,8 +239,7 @@ bool ArchMultithreadPosix::waitCondVar(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wait
|
// wait
|
||||||
int status =
|
int status = pthread_cond_timedwait(&cond->m_cond, &mutex->m_mutex, &finalTime);
|
||||||
pthread_cond_timedwait(&cond->m_cond, &mutex->m_mutex, &finalTime);
|
|
||||||
|
|
||||||
// check for cancel again
|
// check for cancel again
|
||||||
testCancelThread();
|
testCancelThread();
|
||||||
@ -247,7 +258,8 @@ bool ArchMultithreadPosix::waitCondVar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchMutex ArchMultithreadPosix::newMutex() {
|
ArchMutex ArchMultithreadPosix::newMutex()
|
||||||
|
{
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
int status = pthread_mutexattr_init(&attr);
|
int status = pthread_mutexattr_init(&attr);
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
@ -257,14 +269,16 @@ ArchMutex ArchMultithreadPosix::newMutex() {
|
|||||||
return mutex;
|
return mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::closeMutex(ArchMutex mutex) {
|
void ArchMultithreadPosix::closeMutex(ArchMutex mutex)
|
||||||
|
{
|
||||||
int status = pthread_mutex_destroy(&mutex->m_mutex);
|
int status = pthread_mutex_destroy(&mutex->m_mutex);
|
||||||
(void)status;
|
(void)status;
|
||||||
assert(status == 0);
|
assert(status == 0);
|
||||||
delete mutex;
|
delete mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::lockMutex(ArchMutex mutex) {
|
void ArchMultithreadPosix::lockMutex(ArchMutex mutex)
|
||||||
|
{
|
||||||
int status = pthread_mutex_lock(&mutex->m_mutex);
|
int status = pthread_mutex_lock(&mutex->m_mutex);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@ -286,7 +300,8 @@ void ArchMultithreadPosix::lockMutex(ArchMutex mutex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::unlockMutex(ArchMutex mutex) {
|
void ArchMultithreadPosix::unlockMutex(ArchMutex mutex)
|
||||||
|
{
|
||||||
// TODO: S1-1767, we should use raii c++17 mutex instead of archaeic pthread
|
// TODO: S1-1767, we should use raii c++17 mutex instead of archaeic pthread
|
||||||
// to solve possible lock order reversal.
|
// to solve possible lock order reversal.
|
||||||
int status = pthread_mutex_unlock(&mutex->m_mutex);
|
int status = pthread_mutex_unlock(&mutex->m_mutex);
|
||||||
@ -306,7 +321,8 @@ void ArchMultithreadPosix::unlockMutex(ArchMutex mutex) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) {
|
ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data)
|
||||||
|
{
|
||||||
assert(func != NULL);
|
assert(func != NULL);
|
||||||
|
|
||||||
// initialize signal handler. we do this here instead of the
|
// initialize signal handler. we do this here instead of the
|
||||||
@ -335,8 +351,7 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) {
|
|||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
int status = pthread_attr_init(&attr);
|
int status = pthread_attr_init(&attr);
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
status = pthread_create(
|
status = pthread_create(&thread->m_thread, &attr, &ArchMultithreadPosix::threadFunc, thread);
|
||||||
&thread->m_thread, &attr, &ArchMultithreadPosix::threadFunc, thread);
|
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +374,8 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) {
|
|||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchThread ArchMultithreadPosix::newCurrentThread() {
|
ArchThread ArchMultithreadPosix::newCurrentThread()
|
||||||
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
ArchThreadImpl *thread = find(pthread_self());
|
ArchThreadImpl *thread = find(pthread_self());
|
||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
@ -367,7 +383,8 @@ ArchThread ArchMultithreadPosix::newCurrentThread() {
|
|||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::closeThread(ArchThread thread) {
|
void ArchMultithreadPosix::closeThread(ArchThread thread)
|
||||||
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
// decrement ref count and clean up thread if no more references
|
// decrement ref count and clean up thread if no more references
|
||||||
@ -388,12 +405,14 @@ void ArchMultithreadPosix::closeThread(ArchThread thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchThread ArchMultithreadPosix::copyThread(ArchThread thread) {
|
ArchThread ArchMultithreadPosix::copyThread(ArchThread thread)
|
||||||
|
{
|
||||||
refThread(thread);
|
refThread(thread);
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::cancelThread(ArchThread thread) {
|
void ArchMultithreadPosix::cancelThread(ArchThread thread)
|
||||||
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
// set cancel and wakeup flags if thread can be cancelled
|
// set cancel and wakeup flags if thread can be cancelled
|
||||||
@ -411,13 +430,15 @@ void ArchMultithreadPosix::cancelThread(ArchThread thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::setPriorityOfThread(ArchThread thread, int /*n*/) {
|
void ArchMultithreadPosix::setPriorityOfThread(ArchThread thread, int /*n*/)
|
||||||
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::testCancelThread() {
|
void ArchMultithreadPosix::testCancelThread()
|
||||||
|
{
|
||||||
// find current thread
|
// find current thread
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
ArchThreadImpl *thread = findNoRef(pthread_self());
|
ArchThreadImpl *thread = findNoRef(pthread_self());
|
||||||
@ -427,7 +448,8 @@ void ArchMultithreadPosix::testCancelThread() {
|
|||||||
testCancelThreadImpl(thread);
|
testCancelThreadImpl(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchMultithreadPosix::wait(ArchThread target, double timeout) {
|
bool ArchMultithreadPosix::wait(ArchThread target, double timeout)
|
||||||
|
{
|
||||||
assert(target != NULL);
|
assert(target != NULL);
|
||||||
|
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
@ -480,39 +502,42 @@ bool ArchMultithreadPosix::wait(ArchThread target, double timeout) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchMultithreadPosix::isSameThread(
|
bool ArchMultithreadPosix::isSameThread(ArchThread thread1, ArchThread thread2)
|
||||||
ArchThread thread1, ArchThread thread2) {
|
{
|
||||||
return (thread1 == thread2);
|
return (thread1 == thread2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchMultithreadPosix::isExitedThread(ArchThread thread) {
|
bool ArchMultithreadPosix::isExitedThread(ArchThread thread)
|
||||||
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
bool exited = thread->m_exited;
|
bool exited = thread->m_exited;
|
||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
return exited;
|
return exited;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ArchMultithreadPosix::getResultOfThread(ArchThread thread) {
|
void *ArchMultithreadPosix::getResultOfThread(ArchThread thread)
|
||||||
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
void *result = thread->m_result;
|
void *result = thread->m_result;
|
||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchMultithread::ThreadID
|
IArchMultithread::ThreadID ArchMultithreadPosix::getIDOfThread(ArchThread thread)
|
||||||
ArchMultithreadPosix::getIDOfThread(ArchThread thread) {
|
{
|
||||||
return thread->m_id;
|
return thread->m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::setSignalHandler(
|
void ArchMultithreadPosix::setSignalHandler(ESignal signal, SignalFunc func, void *userData)
|
||||||
ESignal signal, SignalFunc func, void *userData) {
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
m_signalFunc[signal] = func;
|
m_signalFunc[signal] = func;
|
||||||
m_signalUserData[signal] = userData;
|
m_signalUserData[signal] = userData;
|
||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::raiseSignal(ESignal signal) {
|
void ArchMultithreadPosix::raiseSignal(ESignal signal)
|
||||||
|
{
|
||||||
lockMutex(m_threadMutex);
|
lockMutex(m_threadMutex);
|
||||||
if (m_signalFunc[signal] != NULL) {
|
if (m_signalFunc[signal] != NULL) {
|
||||||
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
||||||
@ -523,7 +548,8 @@ void ArchMultithreadPosix::raiseSignal(ESignal signal) {
|
|||||||
unlockMutex(m_threadMutex);
|
unlockMutex(m_threadMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::startSignalHandler() {
|
void ArchMultithreadPosix::startSignalHandler()
|
||||||
|
{
|
||||||
// set signal mask. the main thread blocks these signals and
|
// set signal mask. the main thread blocks these signals and
|
||||||
// the signal handler thread will listen for them.
|
// the signal handler thread will listen for them.
|
||||||
sigset_t sigset, oldsigset;
|
sigset_t sigset, oldsigset;
|
||||||
@ -537,9 +563,7 @@ void ArchMultithreadPosix::startSignalHandler() {
|
|||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
int status = pthread_attr_init(&attr);
|
int status = pthread_attr_init(&attr);
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
status = pthread_create(
|
status = pthread_create(&m_signalThread, &attr, &ArchMultithreadPosix::threadSignalHandler, NULL);
|
||||||
&m_signalThread, &attr, &ArchMultithreadPosix::threadSignalHandler,
|
|
||||||
NULL);
|
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
}
|
}
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
@ -549,7 +573,8 @@ void ArchMultithreadPosix::startSignalHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchThreadImpl *ArchMultithreadPosix::find(pthread_t thread) {
|
ArchThreadImpl *ArchMultithreadPosix::find(pthread_t thread)
|
||||||
|
{
|
||||||
ArchThreadImpl *impl = findNoRef(thread);
|
ArchThreadImpl *impl = findNoRef(thread);
|
||||||
if (impl != NULL) {
|
if (impl != NULL) {
|
||||||
refThread(impl);
|
refThread(impl);
|
||||||
@ -557,10 +582,10 @@ ArchThreadImpl *ArchMultithreadPosix::find(pthread_t thread) {
|
|||||||
return impl;
|
return impl;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread) {
|
ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread)
|
||||||
|
{
|
||||||
// linear search
|
// linear search
|
||||||
for (ThreadList::const_iterator index = m_threadList.begin();
|
for (ThreadList::const_iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
||||||
index != m_threadList.end(); ++index) {
|
|
||||||
if ((*index)->m_thread == thread) {
|
if ((*index)->m_thread == thread) {
|
||||||
return *index;
|
return *index;
|
||||||
}
|
}
|
||||||
@ -568,7 +593,8 @@ ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::insert(ArchThreadImpl *thread) {
|
void ArchMultithreadPosix::insert(ArchThreadImpl *thread)
|
||||||
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
// thread shouldn't already be on the list
|
// thread shouldn't already be on the list
|
||||||
@ -584,9 +610,9 @@ void ArchMultithreadPosix::insert(ArchThreadImpl *thread) {
|
|||||||
m_threadList.push_back(thread);
|
m_threadList.push_back(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::erase(ArchThreadImpl *thread) {
|
void ArchMultithreadPosix::erase(ArchThreadImpl *thread)
|
||||||
for (ThreadList::iterator index = m_threadList.begin();
|
{
|
||||||
index != m_threadList.end(); ++index) {
|
for (ThreadList::iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
||||||
if (*index == thread) {
|
if (*index == thread) {
|
||||||
m_threadList.erase(index);
|
m_threadList.erase(index);
|
||||||
break;
|
break;
|
||||||
@ -594,13 +620,15 @@ void ArchMultithreadPosix::erase(ArchThreadImpl *thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::refThread(ArchThreadImpl *thread) {
|
void ArchMultithreadPosix::refThread(ArchThreadImpl *thread)
|
||||||
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
assert(findNoRef(thread->m_thread) != NULL);
|
assert(findNoRef(thread->m_thread) != NULL);
|
||||||
++thread->m_refCount;
|
++thread->m_refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread) {
|
void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread)
|
||||||
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
// update cancel state
|
// update cancel state
|
||||||
@ -619,7 +647,8 @@ void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ArchMultithreadPosix::threadFunc(void *vrep) {
|
void *ArchMultithreadPosix::threadFunc(void *vrep)
|
||||||
|
{
|
||||||
// get the thread
|
// get the thread
|
||||||
ArchThreadImpl *thread = static_cast<ArchThreadImpl *>(vrep);
|
ArchThreadImpl *thread = static_cast<ArchThreadImpl *>(vrep);
|
||||||
|
|
||||||
@ -634,7 +663,8 @@ void *ArchMultithreadPosix::threadFunc(void *vrep) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::doThreadFunc(ArchThread thread) {
|
void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||||
|
{
|
||||||
// default priority is slightly below normal
|
// default priority is slightly below normal
|
||||||
setPriorityOfThread(thread, 1);
|
setPriorityOfThread(thread, 1);
|
||||||
|
|
||||||
@ -671,11 +701,13 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread) {
|
|||||||
closeThread(thread);
|
closeThread(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchMultithreadPosix::threadCancel(int) {
|
void ArchMultithreadPosix::threadCancel(int)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ArchMultithreadPosix::threadSignalHandler(void *) {
|
void *ArchMultithreadPosix::threadSignalHandler(void *)
|
||||||
|
{
|
||||||
// detach
|
// detach
|
||||||
pthread_detach(pthread_self());
|
pthread_detach(pthread_self());
|
||||||
|
|
||||||
|
|||||||
@ -25,18 +25,21 @@
|
|||||||
|
|
||||||
#define ARCH_MULTITHREAD ArchMultithreadPosix
|
#define ARCH_MULTITHREAD ArchMultithreadPosix
|
||||||
|
|
||||||
class ArchCondImpl {
|
class ArchCondImpl
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
pthread_cond_t m_cond;
|
pthread_cond_t m_cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArchMutexImpl {
|
class ArchMutexImpl
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
pthread_mutex_t m_mutex;
|
pthread_mutex_t m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Posix implementation of IArchMultithread
|
//! Posix implementation of IArchMultithread
|
||||||
class ArchMultithreadPosix : public IArchMultithread {
|
class ArchMultithreadPosix : public IArchMultithread
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchMultithreadPosix();
|
ArchMultithreadPosix();
|
||||||
ArchMultithreadPosix(ArchMultithreadPosix const &) = delete;
|
ArchMultithreadPosix(ArchMultithreadPosix const &) = delete;
|
||||||
|
|||||||
@ -52,7 +52,8 @@ static const int s_type[] = {SOCK_DGRAM, SOCK_STREAM};
|
|||||||
#if !HAVE_INET_ATON
|
#if !HAVE_INET_ATON
|
||||||
// parse dotted quad addresses. we don't bother with the weird BSD'ism
|
// parse dotted quad addresses. we don't bother with the weird BSD'ism
|
||||||
// of handling octal and hex and partial forms.
|
// of handling octal and hex and partial forms.
|
||||||
static in_addr_t inet_aton(const char *cp, struct in_addr *inp) {
|
static in_addr_t inet_aton(const char *cp, struct in_addr *inp)
|
||||||
|
{
|
||||||
unsigned int a, b, c, d;
|
unsigned int a, b, c, d;
|
||||||
if (sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
|
if (sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -73,44 +74,53 @@ static in_addr_t inet_aton(const char *cp, struct in_addr *inp) {
|
|||||||
// ArchNetworkBSD::Deps
|
// ArchNetworkBSD::Deps
|
||||||
//
|
//
|
||||||
|
|
||||||
void ArchNetworkBSD::Deps::sleep(double seconds) {
|
void ArchNetworkBSD::Deps::sleep(double seconds)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
ARCH->sleep(seconds);
|
ARCH->sleep(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArchNetworkBSD::Deps::poll(struct pollfd *fds, nfds_t nfds, int timeout) {
|
int ArchNetworkBSD::Deps::poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||||
|
{
|
||||||
return ::poll(fds, nfds, timeout);
|
return ::poll(fds, nfds, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<struct pollfd[]> ArchNetworkBSD::Deps::makePollFD(nfds_t n) {
|
std::shared_ptr<struct pollfd[]> ArchNetworkBSD::Deps::makePollFD(nfds_t n)
|
||||||
|
{
|
||||||
// C++20 supports std::make_shared<struct pollfd[]>(n) but this is not
|
// C++20 supports std::make_shared<struct pollfd[]>(n) but this is not
|
||||||
// implemented on the compiler that comes with Ubuntu 22 and a few other
|
// implemented on the compiler that comes with Ubuntu 22 and a few other
|
||||||
// distros, so use the manual new and delete until we drop those distros.
|
// distros, so use the manual new and delete until we drop those distros.
|
||||||
return std::shared_ptr<struct pollfd[]>(
|
return std::shared_ptr<struct pollfd[]>(new struct pollfd[n], std::default_delete<struct pollfd[]>());
|
||||||
new struct pollfd[n], std::default_delete<struct pollfd[]>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ArchNetworkBSD::Deps::read(int fd, void *buf, size_t len) {
|
ssize_t ArchNetworkBSD::Deps::read(int fd, void *buf, size_t len)
|
||||||
|
{
|
||||||
return ::read(fd, buf, len);
|
return ::read(fd, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::Deps::testCancelThread() { ARCH->testCancelThread(); }
|
void ArchNetworkBSD::Deps::testCancelThread()
|
||||||
|
{
|
||||||
|
ARCH->testCancelThread();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// ArchNetworkBSD
|
// ArchNetworkBSD
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchNetworkBSD::~ArchNetworkBSD() {
|
ArchNetworkBSD::~ArchNetworkBSD()
|
||||||
|
{
|
||||||
if (m_mutex)
|
if (m_mutex)
|
||||||
ARCH->closeMutex(m_mutex);
|
ARCH->closeMutex(m_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::init() {
|
void ArchNetworkBSD::init()
|
||||||
|
{
|
||||||
// create mutex to make some calls thread safe
|
// create mutex to make some calls thread safe
|
||||||
m_mutex = ARCH->newMutex();
|
m_mutex = ARCH->newMutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type) {
|
ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type)
|
||||||
|
{
|
||||||
// create socket
|
// create socket
|
||||||
int fd = socket(s_family[family], s_type[type], 0);
|
int fd = socket(s_family[family], s_type[type], 0);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
@ -130,7 +140,8 @@ ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type) {
|
|||||||
return newSocket;
|
return newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSocket ArchNetworkBSD::copySocket(ArchSocket s) {
|
ArchSocket ArchNetworkBSD::copySocket(ArchSocket s)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// ref the socket and return it
|
// ref the socket and return it
|
||||||
@ -140,7 +151,8 @@ ArchSocket ArchNetworkBSD::copySocket(ArchSocket s) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::closeSocket(ArchSocket s) {
|
void ArchNetworkBSD::closeSocket(ArchSocket s)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// unref the socket and note if it should be released
|
// unref the socket and note if it should be released
|
||||||
@ -162,7 +174,8 @@ void ArchNetworkBSD::closeSocket(ArchSocket s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::closeSocketForRead(ArchSocket s) {
|
void ArchNetworkBSD::closeSocketForRead(ArchSocket s)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
if (shutdown(s->m_fd, 0) == -1) {
|
if (shutdown(s->m_fd, 0) == -1) {
|
||||||
@ -172,7 +185,8 @@ void ArchNetworkBSD::closeSocketForRead(ArchSocket s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::closeSocketForWrite(ArchSocket s) {
|
void ArchNetworkBSD::closeSocketForWrite(ArchSocket s)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
if (shutdown(s->m_fd, 1) == -1) {
|
if (shutdown(s->m_fd, 1) == -1) {
|
||||||
@ -182,7 +196,8 @@ void ArchNetworkBSD::closeSocketForWrite(ArchSocket s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::bindSocket(ArchSocket s, ArchNetAddress addr) {
|
void ArchNetworkBSD::bindSocket(ArchSocket s, ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
@ -191,7 +206,8 @@ void ArchNetworkBSD::bindSocket(ArchSocket s, ArchNetAddress addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::listenOnSocket(ArchSocket s) {
|
void ArchNetworkBSD::listenOnSocket(ArchSocket s)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// hardcoding backlog
|
// hardcoding backlog
|
||||||
@ -200,7 +216,8 @@ void ArchNetworkBSD::listenOnSocket(ArchSocket s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSocket ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress *addr) {
|
ArchSocket ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress *addr)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// if user passed NULL in addr then use scratch space
|
// if user passed NULL in addr then use scratch space
|
||||||
@ -250,7 +267,8 @@ ArchSocket ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress *addr) {
|
|||||||
return newSocket;
|
return newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr) {
|
bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
@ -266,7 +284,8 @@ bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout) {
|
int ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout)
|
||||||
|
{
|
||||||
assert((pe != nullptr && num > 0) || num == 0);
|
assert((pe != nullptr && num > 0) || num == 0);
|
||||||
|
|
||||||
// return if nothing to do
|
// return if nothing to do
|
||||||
@ -351,7 +370,8 @@ int ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::unblockPollSocket(ArchThread thread) {
|
void ArchNetworkBSD::unblockPollSocket(ArchThread thread)
|
||||||
|
{
|
||||||
const int *unblockPipe = getUnblockPipeForThread(thread);
|
const int *unblockPipe = getUnblockPipeForThread(thread);
|
||||||
if (unblockPipe != nullptr) {
|
if (unblockPipe != nullptr) {
|
||||||
char dummy = 0;
|
char dummy = 0;
|
||||||
@ -361,7 +381,8 @@ void ArchNetworkBSD::unblockPollSocket(ArchThread thread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ArchNetworkBSD::readSocket(ArchSocket s, void *buf, size_t len) {
|
size_t ArchNetworkBSD::readSocket(ArchSocket s, void *buf, size_t len)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
ssize_t n = read(s->m_fd, buf, len);
|
ssize_t n = read(s->m_fd, buf, len);
|
||||||
@ -374,7 +395,8 @@ size_t ArchNetworkBSD::readSocket(ArchSocket s, void *buf, size_t len) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ArchNetworkBSD::writeSocket(ArchSocket s, const void *buf, size_t len) {
|
size_t ArchNetworkBSD::writeSocket(ArchSocket s, const void *buf, size_t len)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
ssize_t n = write(s->m_fd, buf, len);
|
ssize_t n = write(s->m_fd, buf, len);
|
||||||
@ -387,15 +409,14 @@ size_t ArchNetworkBSD::writeSocket(ArchSocket s, const void *buf, size_t len) {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s) {
|
void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// get the error from the socket layer
|
// get the error from the socket layer
|
||||||
int err = 0;
|
int err = 0;
|
||||||
auto size = static_cast<socklen_t>(sizeof(err));
|
auto size = static_cast<socklen_t>(sizeof(err));
|
||||||
if (getsockopt(
|
if (getsockopt(s->m_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<optval_t *>(&err), &size) == -1) {
|
||||||
s->m_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<optval_t *>(&err),
|
|
||||||
&size) == -1) {
|
|
||||||
err = errno;
|
err = errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +426,8 @@ void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::setBlockingOnSocket(int fd, bool blocking) {
|
void ArchNetworkBSD::setBlockingOnSocket(int fd, bool blocking)
|
||||||
|
{
|
||||||
assert(fd != -1);
|
assert(fd != -1);
|
||||||
|
|
||||||
int mode = fcntl(fd, F_GETFL, 0);
|
int mode = fcntl(fd, F_GETFL, 0);
|
||||||
@ -422,53 +444,48 @@ void ArchNetworkBSD::setBlockingOnSocket(int fd, bool blocking) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchNetworkBSD::setNoDelayOnSocket(ArchSocket s, bool noDelay) {
|
bool ArchNetworkBSD::setNoDelayOnSocket(ArchSocket s, bool noDelay)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// get old state
|
// get old state
|
||||||
int oflag;
|
int oflag;
|
||||||
auto size = static_cast<socklen_t>(sizeof(oflag));
|
auto size = static_cast<socklen_t>(sizeof(oflag));
|
||||||
if (getsockopt(
|
if (getsockopt(s->m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
||||||
s->m_fd, IPPROTO_TCP, TCP_NODELAY,
|
|
||||||
reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
|
||||||
throwError(errno);
|
throwError(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
int flag = noDelay ? 1 : 0;
|
int flag = noDelay ? 1 : 0;
|
||||||
size = static_cast<socklen_t>(sizeof(flag));
|
size = static_cast<socklen_t>(sizeof(flag));
|
||||||
if (setsockopt(
|
if (setsockopt(s->m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
||||||
s->m_fd, IPPROTO_TCP, TCP_NODELAY,
|
|
||||||
reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
|
||||||
throwError(errno);
|
throwError(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (oflag != 0);
|
return (oflag != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchNetworkBSD::setReuseAddrOnSocket(ArchSocket s, bool reuse) {
|
bool ArchNetworkBSD::setReuseAddrOnSocket(ArchSocket s, bool reuse)
|
||||||
|
{
|
||||||
assert(s != NULL);
|
assert(s != NULL);
|
||||||
|
|
||||||
// get old state
|
// get old state
|
||||||
int oflag;
|
int oflag;
|
||||||
auto size = static_cast<socklen_t>(sizeof(oflag));
|
auto size = static_cast<socklen_t>(sizeof(oflag));
|
||||||
if (getsockopt(
|
if (getsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
||||||
s->m_fd, SOL_SOCKET, SO_REUSEADDR,
|
|
||||||
reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
|
||||||
throwError(errno);
|
throwError(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
int flag = reuse ? 1 : 0;
|
int flag = reuse ? 1 : 0;
|
||||||
size = static_cast<socklen_t>(sizeof(flag));
|
size = static_cast<socklen_t>(sizeof(flag));
|
||||||
if (setsockopt(
|
if (setsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
||||||
s->m_fd, SOL_SOCKET, SO_REUSEADDR,
|
|
||||||
reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
|
||||||
throwError(errno);
|
throwError(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (oflag != 0);
|
return (oflag != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchNetworkBSD::getHostName() {
|
std::string ArchNetworkBSD::getHostName()
|
||||||
|
{
|
||||||
char name[256];
|
char name[256];
|
||||||
if (gethostname(name, sizeof(name)) == -1) {
|
if (gethostname(name, sizeof(name)) == -1) {
|
||||||
name[0] = '\0';
|
name[0] = '\0';
|
||||||
@ -478,7 +495,8 @@ std::string ArchNetworkBSD::getHostName() {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family) {
|
ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family)
|
||||||
|
{
|
||||||
// allocate address
|
// allocate address
|
||||||
auto *addr = new ArchNetAddressImpl;
|
auto *addr = new ArchNetAddressImpl;
|
||||||
|
|
||||||
@ -509,15 +527,16 @@ ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family) {
|
|||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchNetAddress ArchNetworkBSD::copyAddr(ArchNetAddress addr) {
|
ArchNetAddress ArchNetworkBSD::copyAddr(ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
// allocate and copy address
|
// allocate and copy address
|
||||||
return new ArchNetAddressImpl(*addr);
|
return new ArchNetAddressImpl(*addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ArchNetAddress>
|
std::vector<ArchNetAddress> ArchNetworkBSD::nameToAddr(const std::string &name)
|
||||||
ArchNetworkBSD::nameToAddr(const std::string &name) {
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct in6_addr serveraddr;
|
struct in6_addr serveraddr;
|
||||||
|
|
||||||
@ -553,8 +572,7 @@ ArchNetworkBSD::nameToAddr(const std::string &name) {
|
|||||||
addresses.back()->m_len = (socklen_t)sizeof(struct sockaddr_in6);
|
addresses.back()->m_len = (socklen_t)sizeof(struct sockaddr_in6);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(
|
memcpy(&addresses.back()->m_addr, address->ai_addr, addresses.back()->m_len);
|
||||||
&addresses.back()->m_addr, address->ai_addr, addresses.back()->m_len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(pResult);
|
freeaddrinfo(pResult);
|
||||||
@ -563,22 +581,23 @@ ArchNetworkBSD::nameToAddr(const std::string &name) {
|
|||||||
return addresses;
|
return addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::closeAddr(ArchNetAddress addr) {
|
void ArchNetworkBSD::closeAddr(ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
delete addr;
|
delete addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchNetworkBSD::addrToName(ArchNetAddress addr) {
|
std::string ArchNetworkBSD::addrToName(ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
// mutexed name lookup (ugh)
|
// mutexed name lookup (ugh)
|
||||||
ARCH->lockMutex(m_mutex);
|
ARCH->lockMutex(m_mutex);
|
||||||
char host[1024];
|
char host[1024];
|
||||||
char service[20];
|
char service[20];
|
||||||
int ret = getnameinfo(
|
int ret =
|
||||||
TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host),
|
getnameinfo(TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host), service, sizeof(service), 0);
|
||||||
service, sizeof(service), 0);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ARCH->unlockMutex(m_mutex);
|
ARCH->unlockMutex(m_mutex);
|
||||||
throwNameError(ret);
|
throwNameError(ret);
|
||||||
@ -593,7 +612,8 @@ std::string ArchNetworkBSD::addrToName(ArchNetAddress addr) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchNetworkBSD::addrToString(ArchNetAddress addr) {
|
std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
switch (getAddrFamily(addr)) {
|
switch (getAddrFamily(addr)) {
|
||||||
@ -620,8 +640,8 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IArchNetwork::EAddressFamily
|
IArchNetwork::EAddressFamily ArchNetworkBSD::getAddrFamily(ArchNetAddress addr)
|
||||||
ArchNetworkBSD::getAddrFamily(ArchNetAddress addr) {
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
switch (addr->m_addr.ss_family) {
|
switch (addr->m_addr.ss_family) {
|
||||||
@ -635,7 +655,8 @@ ArchNetworkBSD::getAddrFamily(ArchNetAddress addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port) {
|
void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
switch (getAddrFamily(addr)) {
|
switch (getAddrFamily(addr)) {
|
||||||
@ -657,7 +678,8 @@ void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ArchNetworkBSD::getAddrPort(ArchNetAddress addr) {
|
int ArchNetworkBSD::getAddrPort(ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
switch (getAddrFamily(addr)) {
|
switch (getAddrFamily(addr)) {
|
||||||
@ -677,15 +699,14 @@ int ArchNetworkBSD::getAddrPort(ArchNetAddress addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr) {
|
bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr)
|
||||||
|
{
|
||||||
assert(addr != NULL);
|
assert(addr != NULL);
|
||||||
|
|
||||||
switch (getAddrFamily(addr)) {
|
switch (getAddrFamily(addr)) {
|
||||||
case kINET: {
|
case kINET: {
|
||||||
auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||||
return (
|
return (ipAddr->sin_addr.s_addr == INADDR_ANY && addr->m_len == static_cast<socklen_t>(sizeof(struct sockaddr_in)));
|
||||||
ipAddr->sin_addr.s_addr == INADDR_ANY &&
|
|
||||||
addr->m_len == static_cast<socklen_t>(sizeof(struct sockaddr_in)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case kINET6: {
|
case kINET6: {
|
||||||
@ -693,8 +714,9 @@ bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr) {
|
|||||||
return (
|
return (
|
||||||
addr->m_len == (socklen_t)sizeof(struct sockaddr_in6) &&
|
addr->m_len == (socklen_t)sizeof(struct sockaddr_in6) &&
|
||||||
memcmp(
|
memcmp(
|
||||||
static_cast<const void *>(&ipAddr->sin6_addr),
|
static_cast<const void *>(&ipAddr->sin6_addr), static_cast<const void *>(&in6addr_any), sizeof(in6_addr)
|
||||||
static_cast<const void *>(&in6addr_any), sizeof(in6_addr)) == 0);
|
) == 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -703,12 +725,13 @@ bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArchNetworkBSD::isEqualAddr(ArchNetAddress a, ArchNetAddress b) {
|
bool ArchNetworkBSD::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
|
||||||
return (
|
{
|
||||||
a->m_len == b->m_len && memcmp(&a->m_addr, &b->m_addr, a->m_len) == 0);
|
return (a->m_len == b->m_len && memcmp(&a->m_addr, &b->m_addr, a->m_len) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int *ArchNetworkBSD::getUnblockPipe() {
|
const int *ArchNetworkBSD::getUnblockPipe()
|
||||||
|
{
|
||||||
ArchMultithreadPosix *mt = ArchMultithreadPosix::getInstance();
|
ArchMultithreadPosix *mt = ArchMultithreadPosix::getInstance();
|
||||||
ArchThread thread = mt->newCurrentThread();
|
ArchThread thread = mt->newCurrentThread();
|
||||||
const int *p = getUnblockPipeForThread(thread);
|
const int *p = getUnblockPipeForThread(thread);
|
||||||
@ -716,7 +739,8 @@ const int *ArchNetworkBSD::getUnblockPipe() {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread) {
|
const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
|
||||||
|
{
|
||||||
ArchMultithreadPosix *mt = ArchMultithreadPosix::getInstance();
|
ArchMultithreadPosix *mt = ArchMultithreadPosix::getInstance();
|
||||||
auto *unblockPipe = static_cast<int *>(mt->getNetworkDataForThread(thread));
|
auto *unblockPipe = static_cast<int *>(mt->getNetworkDataForThread(thread));
|
||||||
if (unblockPipe == nullptr) {
|
if (unblockPipe == nullptr) {
|
||||||
@ -737,7 +761,8 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread) {
|
|||||||
return unblockPipe;
|
return unblockPipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::throwError(int err) {
|
void ArchNetworkBSD::throwError(int err)
|
||||||
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
ARCH->testCancelThread();
|
ARCH->testCancelThread();
|
||||||
@ -807,13 +832,13 @@ void ArchNetworkBSD::throwError(int err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchNetworkBSD::throwNameError(int err) {
|
void ArchNetworkBSD::throwNameError(int err)
|
||||||
|
{
|
||||||
static const char *s_msg[] = {
|
static const char *s_msg[] = {
|
||||||
"The specified host is unknown",
|
"The specified host is unknown", "The requested name is valid but does not have an IP address",
|
||||||
"The requested name is valid but does not have an IP address",
|
"A non-recoverable name server error occurred", "A temporary error occurred on an authoritative name server",
|
||||||
"A non-recoverable name server error occurred",
|
"An unknown name server error occurred"
|
||||||
"A temporary error occurred on an authoritative name server",
|
};
|
||||||
"An unknown name server error occurred"};
|
|
||||||
|
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case HOST_NOT_FOUND:
|
case HOST_NOT_FOUND:
|
||||||
|
|||||||
@ -30,7 +30,8 @@
|
|||||||
#if HAVE_SYS_SOCKET_H
|
#if HAVE_SYS_SOCKET_H
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#else
|
#else
|
||||||
struct sockaddr_storage {
|
struct sockaddr_storage
|
||||||
|
{
|
||||||
unsigned char ss_len; /* address length */
|
unsigned char ss_len; /* address length */
|
||||||
unsigned char ss_family; /* [XSI] address family */
|
unsigned char ss_family; /* [XSI] address family */
|
||||||
char __ss_pad1[_SS_PAD1SIZE];
|
char __ss_pad1[_SS_PAD1SIZE];
|
||||||
@ -53,15 +54,19 @@ typedef int socklen_t;
|
|||||||
// compatible so we always use it.
|
// compatible so we always use it.
|
||||||
typedef char optval_t;
|
typedef char optval_t;
|
||||||
|
|
||||||
class ArchSocketImpl {
|
class ArchSocketImpl
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
int m_fd;
|
int m_fd;
|
||||||
int m_refCount;
|
int m_refCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ArchNetAddressImpl {
|
class ArchNetAddressImpl
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchNetAddressImpl() : m_len(sizeof(m_addr)) {}
|
ArchNetAddressImpl() : m_len(sizeof(m_addr))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct sockaddr_storage m_addr;
|
struct sockaddr_storage m_addr;
|
||||||
@ -69,10 +74,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! Berkeley (BSD) sockets implementation of IArchNetwork
|
//! Berkeley (BSD) sockets implementation of IArchNetwork
|
||||||
class ArchNetworkBSD : public IArchNetwork {
|
class ArchNetworkBSD : public IArchNetwork
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Deps {
|
struct Deps
|
||||||
|
{
|
||||||
virtual ~Deps() = default;
|
virtual ~Deps() = default;
|
||||||
virtual void sleep(double);
|
virtual void sleep(double);
|
||||||
virtual int poll(struct pollfd *, nfds_t, int);
|
virtual int poll(struct pollfd *, nfds_t, int);
|
||||||
@ -81,8 +88,9 @@ public:
|
|||||||
virtual void testCancelThread();
|
virtual void testCancelThread();
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ArchNetworkBSD(std::shared_ptr<Deps> deps = std::make_shared<Deps>())
|
explicit ArchNetworkBSD(std::shared_ptr<Deps> deps = std::make_shared<Deps>()) : m_pDeps(deps)
|
||||||
: m_pDeps(deps) {}
|
{
|
||||||
|
}
|
||||||
ArchNetworkBSD(ArchNetworkBSD const &) = delete;
|
ArchNetworkBSD(ArchNetworkBSD const &) = delete;
|
||||||
ArchNetworkBSD(ArchNetworkBSD &&) = delete;
|
ArchNetworkBSD(ArchNetworkBSD &&) = delete;
|
||||||
~ArchNetworkBSD() override;
|
~ArchNetworkBSD() override;
|
||||||
|
|||||||
@ -46,15 +46,18 @@
|
|||||||
// ArchSleepUnix
|
// ArchSleepUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchSleepUnix::ArchSleepUnix() {
|
ArchSleepUnix::ArchSleepUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSleepUnix::~ArchSleepUnix() {
|
ArchSleepUnix::~ArchSleepUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchSleepUnix::sleep(double timeout) {
|
void ArchSleepUnix::sleep(double timeout)
|
||||||
|
{
|
||||||
ARCH->testCancelThread();
|
ARCH->testCancelThread();
|
||||||
if (timeout < 0.0) {
|
if (timeout < 0.0) {
|
||||||
return;
|
return;
|
||||||
@ -78,8 +81,9 @@ void ArchSleepUnix::sleep(double timeout) {
|
|||||||
timeout2.tv_sec = static_cast<int>(timeLeft);
|
timeout2.tv_sec = static_cast<int>(timeLeft);
|
||||||
timeout2.tv_usec = static_cast<int>(1.0e+6 * (timeLeft - timeout2.tv_sec));
|
timeout2.tv_usec = static_cast<int>(1.0e+6 * (timeLeft - timeout2.tv_sec));
|
||||||
select(
|
select(
|
||||||
(SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL,
|
(SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL,
|
||||||
SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG5 & timeout2);
|
SELECT_TYPE_ARG5 & timeout2
|
||||||
|
);
|
||||||
ARCH->testCancelThread();
|
ARCH->testCancelThread();
|
||||||
timeLeft = timeout - (ARCH->time() - startTime);
|
timeLeft = timeout - (ARCH->time() - startTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_SLEEP ArchSleepUnix
|
#define ARCH_SLEEP ArchSleepUnix
|
||||||
|
|
||||||
//! Unix implementation of IArchSleep
|
//! Unix implementation of IArchSleep
|
||||||
class ArchSleepUnix : public IArchSleep {
|
class ArchSleepUnix : public IArchSleep
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchSleepUnix();
|
ArchSleepUnix();
|
||||||
virtual ~ArchSleepUnix();
|
virtual ~ArchSleepUnix();
|
||||||
|
|||||||
@ -27,10 +27,15 @@
|
|||||||
#include "arch/multibyte.h"
|
#include "arch/multibyte.h"
|
||||||
#include "arch/vsnprintf.h"
|
#include "arch/vsnprintf.h"
|
||||||
|
|
||||||
ArchStringUnix::ArchStringUnix() {}
|
ArchStringUnix::ArchStringUnix()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ArchStringUnix::~ArchStringUnix() {}
|
ArchStringUnix::~ArchStringUnix()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding() {
|
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding()
|
||||||
|
{
|
||||||
return kUCS4;
|
return kUCS4;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_STRING ArchStringUnix
|
#define ARCH_STRING ArchStringUnix
|
||||||
|
|
||||||
//! Unix implementation of IArchString
|
//! Unix implementation of IArchString
|
||||||
class ArchStringUnix : public IArchString {
|
class ArchStringUnix : public IArchString
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchStringUnix();
|
ArchStringUnix();
|
||||||
virtual ~ArchStringUnix();
|
virtual ~ArchStringUnix();
|
||||||
|
|||||||
@ -28,15 +28,18 @@
|
|||||||
// ArchSystemUnix
|
// ArchSystemUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchSystemUnix::ArchSystemUnix() {
|
ArchSystemUnix::ArchSystemUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchSystemUnix::~ArchSystemUnix() {
|
ArchSystemUnix::~ArchSystemUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchSystemUnix::getOSName() const {
|
std::string ArchSystemUnix::getOSName() const
|
||||||
|
{
|
||||||
#if defined(HAVE_SYS_UTSNAME_H)
|
#if defined(HAVE_SYS_UTSNAME_H)
|
||||||
struct utsname info;
|
struct utsname info;
|
||||||
if (uname(&info) == 0) {
|
if (uname(&info) == 0) {
|
||||||
@ -50,7 +53,8 @@ std::string ArchSystemUnix::getOSName() const {
|
|||||||
return "Unix";
|
return "Unix";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchSystemUnix::getPlatformName() const {
|
std::string ArchSystemUnix::getPlatformName() const
|
||||||
|
{
|
||||||
#if defined(HAVE_SYS_UTSNAME_H)
|
#if defined(HAVE_SYS_UTSNAME_H)
|
||||||
struct utsname info;
|
struct utsname info;
|
||||||
if (uname(&info) == 0) {
|
if (uname(&info) == 0) {
|
||||||
@ -60,22 +64,26 @@ std::string ArchSystemUnix::getPlatformName() const {
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ArchSystemUnix::setting(const std::string &) const { return ""; }
|
std::string ArchSystemUnix::setting(const std::string &) const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
void ArchSystemUnix::setting(const std::string &, const std::string &) const {}
|
void ArchSystemUnix::setting(const std::string &, const std::string &) const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
std::string ArchSystemUnix::getLibsUsed(void) const {
|
std::string ArchSystemUnix::getLibsUsed(void) const
|
||||||
|
{
|
||||||
return "not implemented.\nuse lsof on shell";
|
return "not implemented.\nuse lsof on shell";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
bool ArchSystemUnix::DBusInhibitScreenCall(
|
bool ArchSystemUnix::DBusInhibitScreenCall(InhibitScreenServices serviceID, bool state, std::string &error)
|
||||||
InhibitScreenServices serviceID, bool state, std::string &error) {
|
{
|
||||||
error = "";
|
error = "";
|
||||||
static const std::array<QString, 2> services = {
|
static const std::array<QString, 2> services = {"org.freedesktop.ScreenSaver", "org.gnome.SessionManager"};
|
||||||
"org.freedesktop.ScreenSaver", "org.gnome.SessionManager"};
|
static const std::array<QString, 2> paths = {"/org/freedesktop/ScreenSaver", "/org/gnome/SessionManager"};
|
||||||
static const std::array<QString, 2> paths = {
|
|
||||||
"/org/freedesktop/ScreenSaver", "/org/gnome/SessionManager"};
|
|
||||||
static std::array<uint, 2> cookies;
|
static std::array<uint, 2> cookies;
|
||||||
|
|
||||||
auto serviceNum = static_cast<uint8_t>(serviceID);
|
auto serviceNum = static_cast<uint8_t>(serviceID);
|
||||||
@ -86,8 +94,7 @@ bool ArchSystemUnix::DBusInhibitScreenCall(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDBusInterface screenSaverInterface(
|
QDBusInterface screenSaverInterface(services[serviceNum], paths[serviceNum], services[serviceNum], bus);
|
||||||
services[serviceNum], paths[serviceNum], services[serviceNum], bus);
|
|
||||||
|
|
||||||
if (!screenSaverInterface.isValid()) {
|
if (!screenSaverInterface.isValid()) {
|
||||||
error = "screen saver interface failed to initialize";
|
error = "screen saver interface failed to initialize";
|
||||||
@ -102,8 +109,8 @@ bool ArchSystemUnix::DBusInhibitScreenCall(
|
|||||||
}
|
}
|
||||||
|
|
||||||
reply = screenSaverInterface.call(
|
reply = screenSaverInterface.call(
|
||||||
"Inhibit", DESKFLOW_APP_NAME,
|
"Inhibit", DESKFLOW_APP_NAME, "Sleep is manually prevented by the " DESKFLOW_APP_NAME " preferences"
|
||||||
"Sleep is manually prevented by the " DESKFLOW_APP_NAME " preferences");
|
);
|
||||||
if (reply.isValid())
|
if (reply.isValid())
|
||||||
cookies[serviceNum] = reply.value();
|
cookies[serviceNum] = reply.value();
|
||||||
} else {
|
} else {
|
||||||
@ -117,8 +124,7 @@ bool ArchSystemUnix::DBusInhibitScreenCall(
|
|||||||
|
|
||||||
if (!reply.isValid()) {
|
if (!reply.isValid()) {
|
||||||
QDBusError qerror = reply.error();
|
QDBusError qerror = reply.error();
|
||||||
error =
|
error = qerror.name().toStdString() + " : " + qerror.message().toStdString();
|
||||||
qerror.name().toStdString() + " : " + qerror.message().toStdString();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_SYSTEM ArchSystemUnix
|
#define ARCH_SYSTEM ArchSystemUnix
|
||||||
|
|
||||||
//! Unix implementation of IArchString
|
//! Unix implementation of IArchString
|
||||||
class ArchSystemUnix : public IArchSystem {
|
class ArchSystemUnix : public IArchSystem
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchSystemUnix();
|
ArchSystemUnix();
|
||||||
virtual ~ArchSystemUnix();
|
virtual ~ArchSystemUnix();
|
||||||
@ -36,8 +37,11 @@ public:
|
|||||||
virtual std::string getLibsUsed(void) const;
|
virtual std::string getLibsUsed(void) const;
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
enum class InhibitScreenServices { kScreenSaver, kSessionManager };
|
enum class InhibitScreenServices
|
||||||
static bool DBusInhibitScreenCall(
|
{
|
||||||
InhibitScreenServices serviceID, bool state, std::string &error);
|
kScreenSaver,
|
||||||
|
kSessionManager
|
||||||
|
};
|
||||||
|
static bool DBusInhibitScreenCall(InhibitScreenServices serviceID, bool state, std::string &error);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|||||||
@ -22,22 +22,27 @@
|
|||||||
// ArchTaskBarXWindows
|
// ArchTaskBarXWindows
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchTaskBarXWindows::ArchTaskBarXWindows() {
|
ArchTaskBarXWindows::ArchTaskBarXWindows()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchTaskBarXWindows::~ArchTaskBarXWindows() {
|
ArchTaskBarXWindows::~ArchTaskBarXWindows()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchTaskBarXWindows::addReceiver(IArchTaskBarReceiver * /*receiver*/) {
|
void ArchTaskBarXWindows::addReceiver(IArchTaskBarReceiver * /*receiver*/)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchTaskBarXWindows::removeReceiver(IArchTaskBarReceiver * /*receiver*/) {
|
void ArchTaskBarXWindows::removeReceiver(IArchTaskBarReceiver * /*receiver*/)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArchTaskBarXWindows::updateReceiver(IArchTaskBarReceiver * /*receiver*/) {
|
void ArchTaskBarXWindows::updateReceiver(IArchTaskBarReceiver * /*receiver*/)
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_TASKBAR ArchTaskBarXWindows
|
#define ARCH_TASKBAR ArchTaskBarXWindows
|
||||||
|
|
||||||
//! X11 implementation of IArchTaskBar
|
//! X11 implementation of IArchTaskBar
|
||||||
class ArchTaskBarXWindows : public IArchTaskBar {
|
class ArchTaskBarXWindows : public IArchTaskBar
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchTaskBarXWindows();
|
ArchTaskBarXWindows();
|
||||||
virtual ~ArchTaskBarXWindows();
|
virtual ~ArchTaskBarXWindows();
|
||||||
|
|||||||
@ -33,15 +33,18 @@
|
|||||||
// ArchTimeUnix
|
// ArchTimeUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
ArchTimeUnix::ArchTimeUnix() {
|
ArchTimeUnix::ArchTimeUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchTimeUnix::~ArchTimeUnix() {
|
ArchTimeUnix::~ArchTimeUnix()
|
||||||
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
double ArchTimeUnix::time() {
|
double ArchTimeUnix::time()
|
||||||
|
{
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
||||||
return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
|
return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
|
||||||
|
|||||||
@ -23,7 +23,8 @@
|
|||||||
#define ARCH_TIME ArchTimeUnix
|
#define ARCH_TIME ArchTimeUnix
|
||||||
|
|
||||||
//! Generic Unix implementation of IArchTime
|
//! Generic Unix implementation of IArchTime
|
||||||
class ArchTimeUnix : public IArchTime {
|
class ArchTimeUnix : public IArchTime
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ArchTimeUnix();
|
ArchTimeUnix();
|
||||||
virtual ~ArchTimeUnix();
|
virtual ~ArchTimeUnix();
|
||||||
|
|||||||
@ -24,7 +24,8 @@
|
|||||||
// XArchEvalUnix
|
// XArchEvalUnix
|
||||||
//
|
//
|
||||||
|
|
||||||
std::string XArchEvalUnix::eval() const {
|
std::string XArchEvalUnix::eval() const
|
||||||
|
{
|
||||||
// FIXME -- not thread safe
|
// FIXME -- not thread safe
|
||||||
return strerror(m_error);
|
return strerror(m_error);
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user