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,
|
||||
# which can be less readable in some cases in our code base.
|
||||
#
|
||||
# Using `AlwaysBreak` will result in:
|
||||
# Using `BlockIndent` will result in:
|
||||
# void fooBarBazQuxHelloWorld(
|
||||
# int a,
|
||||
# int b);
|
||||
# int b
|
||||
# );
|
||||
#
|
||||
# Instead of:
|
||||
# void fooBarBazQuxHelloWorld(int a,
|
||||
# int b);
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
|
||||
# Turn off LLVM default packing of ctor initializers.
|
||||
# This makes it easier to see which members were initialized and in what order.
|
||||
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"
|
||||
#endif
|
||||
|
||||
void showHelp() {
|
||||
std::cout << "Usage: " CORE_BINARY_NAME " <server | client> [...options]"
|
||||
<< std::endl;
|
||||
std::cout << "server - start as a server (" << SERVER_BINARY_NAME << ")"
|
||||
<< std::endl;
|
||||
std::cout << "client - start as a client (" << CLIENT_BINARY_NAME << ")"
|
||||
<< std::endl;
|
||||
std::cout << "use " CORE_BINARY_NAME
|
||||
" <server|client> --help for more information."
|
||||
<< std::endl;
|
||||
void showHelp()
|
||||
{
|
||||
std::cout << "Usage: " CORE_BINARY_NAME " <server | client> [...options]" << std::endl;
|
||||
std::cout << "server - start as a server (" << SERVER_BINARY_NAME << ")" << std::endl;
|
||||
std::cout << "client - start as a client (" << CLIENT_BINARY_NAME << ")" << 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"));
|
||||
}
|
||||
|
||||
bool isClient(int argc, char **argv) {
|
||||
bool isClient(int argc, char **argv)
|
||||
{
|
||||
return (argc > 1 && argv[1] == std::string("client"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if SYSAPI_WIN32
|
||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||
#endif
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
#include "arch/win32/ArchMiscWindows.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if SYSAPI_WIN32
|
||||
// record window instance for tray icon, etc
|
||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||
|
||||
@ -34,16 +34,18 @@
|
||||
//
|
||||
|
||||
const UINT MSWindowsClientTaskBarReceiver::s_stateToIconID[kMaxState] = {
|
||||
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED,
|
||||
IDI_TASKBAR_NOT_CONNECTED, IDI_TASKBAR_CONNECTED};
|
||||
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED, IDI_TASKBAR_NOT_CONNECTED,
|
||||
IDI_TASKBAR_CONNECTED
|
||||
};
|
||||
|
||||
MSWindowsClientTaskBarReceiver::MSWindowsClientTaskBarReceiver(
|
||||
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer,
|
||||
IEventQueue *events)
|
||||
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer, IEventQueue *events
|
||||
)
|
||||
: ClientTaskBarReceiver(events),
|
||||
m_appInstance(appInstance),
|
||||
m_window(NULL),
|
||||
m_logBuffer(logBuffer) {
|
||||
m_logBuffer(logBuffer)
|
||||
{
|
||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||
m_icon[i] = loadIcon(s_stateToIconID[i]);
|
||||
}
|
||||
@ -58,9 +60,13 @@ MSWindowsClientTaskBarReceiver::MSWindowsClientTaskBarReceiver(
|
||||
ARCH->addReceiver(this);
|
||||
}
|
||||
|
||||
MSWindowsClientTaskBarReceiver::~MSWindowsClientTaskBarReceiver() { cleanup(); }
|
||||
MSWindowsClientTaskBarReceiver::~MSWindowsClientTaskBarReceiver()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::cleanup() {
|
||||
void MSWindowsClientTaskBarReceiver::cleanup()
|
||||
{
|
||||
ARCH->removeReceiver(this);
|
||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||
deleteIcon(m_icon[i]);
|
||||
@ -69,7 +75,8 @@ void MSWindowsClientTaskBarReceiver::cleanup() {
|
||||
destroyWindow();
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::showStatus() {
|
||||
void MSWindowsClientTaskBarReceiver::showStatus()
|
||||
{
|
||||
// create the window
|
||||
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().
|
||||
// the SetForegroundWindow() and SendMessage() calls around
|
||||
// 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);
|
||||
SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE);
|
||||
HMENU logLevelMenu = GetSubMenu(menu, 3);
|
||||
CheckMenuRadioItem(
|
||||
logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
||||
int n = TrackPopupMenu(
|
||||
menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x,
|
||||
y, 0, m_window, NULL);
|
||||
CheckMenuRadioItem(logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
||||
int n =
|
||||
TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x, y, 0, m_window, NULL);
|
||||
SendMessage(m_window, WM_NULL, 0, 0);
|
||||
|
||||
// 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
|
||||
MSWindowsClientTaskBarReceiver::getIcon() const {
|
||||
const IArchTaskBarReceiver::Icon MSWindowsClientTaskBarReceiver::getIcon() const
|
||||
{
|
||||
return static_cast<Icon>(m_icon[getStatus()]);
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::copyLog() const {
|
||||
void MSWindowsClientTaskBarReceiver::copyLog() const
|
||||
{
|
||||
if (m_logBuffer != NULL) {
|
||||
// collect log buffer
|
||||
String data;
|
||||
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin();
|
||||
index != m_logBuffer->end(); ++index) {
|
||||
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin(); index != m_logBuffer->end(); ++index) {
|
||||
data += *index;
|
||||
data += "\n";
|
||||
}
|
||||
@ -220,26 +229,29 @@ void MSWindowsClientTaskBarReceiver::copyLog() const {
|
||||
}
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::onStatusChanged() {
|
||||
void MSWindowsClientTaskBarReceiver::onStatusChanged()
|
||||
{
|
||||
if (IsWindowVisible(m_window)) {
|
||||
showStatus();
|
||||
}
|
||||
}
|
||||
|
||||
HICON
|
||||
MSWindowsClientTaskBarReceiver::loadIcon(UINT id) {
|
||||
HANDLE icon = LoadImage(
|
||||
m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
||||
MSWindowsClientTaskBarReceiver::loadIcon(UINT id)
|
||||
{
|
||||
HANDLE icon = LoadImage(m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
||||
return static_cast<HICON>(icon);
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::deleteIcon(HICON icon) {
|
||||
void MSWindowsClientTaskBarReceiver::deleteIcon(HICON icon)
|
||||
{
|
||||
if (icon != NULL) {
|
||||
DestroyIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::createWindow() {
|
||||
void MSWindowsClientTaskBarReceiver::createWindow()
|
||||
{
|
||||
// ignore if already created
|
||||
if (m_window != NULL) {
|
||||
return;
|
||||
@ -247,9 +259,9 @@ void MSWindowsClientTaskBarReceiver::createWindow() {
|
||||
|
||||
// get the status dialog
|
||||
m_window = CreateDialogParam(
|
||||
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL,
|
||||
(DLGPROC)&MSWindowsClientTaskBarReceiver::staticDlgProc,
|
||||
reinterpret_cast<LPARAM>(static_cast<void *>(this)));
|
||||
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL, (DLGPROC)&MSWindowsClientTaskBarReceiver::staticDlgProc,
|
||||
reinterpret_cast<LPARAM>(static_cast<void *>(this))
|
||||
);
|
||||
|
||||
// window should appear on top of everything, including (especially)
|
||||
// the task bar.
|
||||
@ -261,7 +273,8 @@ void MSWindowsClientTaskBarReceiver::createWindow() {
|
||||
ArchTaskBarWindows::addDialog(m_window);
|
||||
}
|
||||
|
||||
void MSWindowsClientTaskBarReceiver::destroyWindow() {
|
||||
void MSWindowsClientTaskBarReceiver::destroyWindow()
|
||||
{
|
||||
if (m_window != NULL) {
|
||||
ArchTaskBarWindows::removeDialog(m_window);
|
||||
DestroyWindow(m_window);
|
||||
@ -269,8 +282,8 @@ void MSWindowsClientTaskBarReceiver::destroyWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
BOOL MSWindowsClientTaskBarReceiver::dlgProc(
|
||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM) {
|
||||
BOOL MSWindowsClientTaskBarReceiver::dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_INITDIALOG:
|
||||
// use default focus
|
||||
@ -286,14 +299,13 @@ BOOL MSWindowsClientTaskBarReceiver::dlgProc(
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CALLBACK MSWindowsClientTaskBarReceiver::staticDlgProc(
|
||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
BOOL CALLBACK MSWindowsClientTaskBarReceiver::staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// if msg is WM_INITDIALOG, extract the MSWindowsClientTaskBarReceiver*
|
||||
// and put it in the extra window data then forward the call.
|
||||
MSWindowsClientTaskBarReceiver *self = NULL;
|
||||
if (msg == WM_INITDIALOG) {
|
||||
self = static_cast<MSWindowsClientTaskBarReceiver *>(
|
||||
reinterpret_cast<void *>(lParam));
|
||||
self = static_cast<MSWindowsClientTaskBarReceiver *>(reinterpret_cast<void *>(lParam));
|
||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
|
||||
} else {
|
||||
// get the extra window data and forward the call
|
||||
@ -311,16 +323,12 @@ BOOL CALLBACK MSWindowsClientTaskBarReceiver::staticDlgProc(
|
||||
}
|
||||
}
|
||||
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||
{
|
||||
ArchMiscWindows::setIcons(
|
||||
(HICON)LoadImage(
|
||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
||||
IMAGE_ICON, 32, 32, LR_SHARED),
|
||||
(HICON)LoadImage(
|
||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
||||
IMAGE_ICON, 16, 16, LR_SHARED));
|
||||
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 32, 32, LR_SHARED),
|
||||
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 16, 16, LR_SHARED)
|
||||
);
|
||||
|
||||
return new MSWindowsClientTaskBarReceiver(
|
||||
MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
||||
return new MSWindowsClientTaskBarReceiver(MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
||||
}
|
||||
|
||||
@ -27,10 +27,10 @@ class BufferedLogOutputter;
|
||||
class IEventQueue;
|
||||
|
||||
//! Implementation of ClientTaskBarReceiver for Microsoft Windows
|
||||
class MSWindowsClientTaskBarReceiver : public ClientTaskBarReceiver {
|
||||
class MSWindowsClientTaskBarReceiver : public ClientTaskBarReceiver
|
||||
{
|
||||
public:
|
||||
MSWindowsClientTaskBarReceiver(
|
||||
HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
||||
MSWindowsClientTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
||||
virtual ~MSWindowsClientTaskBarReceiver();
|
||||
|
||||
// IArchTaskBarReceiver overrides
|
||||
@ -53,8 +53,7 @@ private:
|
||||
void destroyWindow();
|
||||
|
||||
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static BOOL CALLBACK
|
||||
staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
private:
|
||||
HINSTANCE m_appInstance;
|
||||
|
||||
@ -23,34 +23,39 @@
|
||||
// OSXClientTaskBarReceiver
|
||||
//
|
||||
|
||||
OSXClientTaskBarReceiver::OSXClientTaskBarReceiver(
|
||||
const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ClientTaskBarReceiver(events) {
|
||||
OSXClientTaskBarReceiver::OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ClientTaskBarReceiver(events)
|
||||
{
|
||||
// add ourself to the task bar
|
||||
ARCH->addReceiver(this);
|
||||
}
|
||||
|
||||
OSXClientTaskBarReceiver::~OSXClientTaskBarReceiver() {
|
||||
OSXClientTaskBarReceiver::~OSXClientTaskBarReceiver()
|
||||
{
|
||||
ARCH->removeReceiver(this);
|
||||
}
|
||||
|
||||
void OSXClientTaskBarReceiver::showStatus() {
|
||||
void OSXClientTaskBarReceiver::showStatus()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void OSXClientTaskBarReceiver::runMenu(int, int) {
|
||||
void OSXClientTaskBarReceiver::runMenu(int, int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void OSXClientTaskBarReceiver::primaryAction() {
|
||||
void OSXClientTaskBarReceiver::primaryAction()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const IArchTaskBarReceiver::Icon OSXClientTaskBarReceiver::getIcon() const {
|
||||
const IArchTaskBarReceiver::Icon OSXClientTaskBarReceiver::getIcon() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||
{
|
||||
return new OSXClientTaskBarReceiver(logBuffer, events);
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@ class BufferedLogOutputter;
|
||||
class IEventQueue;
|
||||
|
||||
//! Implementation of ClientTaskBarReceiver for OS X
|
||||
class OSXClientTaskBarReceiver : public ClientTaskBarReceiver {
|
||||
class OSXClientTaskBarReceiver : public ClientTaskBarReceiver
|
||||
{
|
||||
public:
|
||||
OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||
virtual ~OSXClientTaskBarReceiver();
|
||||
|
||||
@ -23,35 +23,39 @@
|
||||
// CXWindowsClientTaskBarReceiver
|
||||
//
|
||||
|
||||
CXWindowsClientTaskBarReceiver::CXWindowsClientTaskBarReceiver(
|
||||
const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ClientTaskBarReceiver(events) {
|
||||
CXWindowsClientTaskBarReceiver::CXWindowsClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ClientTaskBarReceiver(events)
|
||||
{
|
||||
// add ourself to the task bar
|
||||
ARCH->addReceiver(this);
|
||||
}
|
||||
|
||||
CXWindowsClientTaskBarReceiver::~CXWindowsClientTaskBarReceiver() {
|
||||
CXWindowsClientTaskBarReceiver::~CXWindowsClientTaskBarReceiver()
|
||||
{
|
||||
ARCH->removeReceiver(this);
|
||||
}
|
||||
|
||||
void CXWindowsClientTaskBarReceiver::showStatus() {
|
||||
void CXWindowsClientTaskBarReceiver::showStatus()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CXWindowsClientTaskBarReceiver::runMenu(int, int) {
|
||||
void CXWindowsClientTaskBarReceiver::runMenu(int, int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CXWindowsClientTaskBarReceiver::primaryAction() {
|
||||
void CXWindowsClientTaskBarReceiver::primaryAction()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const IArchTaskBarReceiver::Icon
|
||||
CXWindowsClientTaskBarReceiver::getIcon() const {
|
||||
const IArchTaskBarReceiver::Icon CXWindowsClientTaskBarReceiver::getIcon() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||
{
|
||||
return new CXWindowsClientTaskBarReceiver(logBuffer, events);
|
||||
}
|
||||
|
||||
@ -24,19 +24,16 @@ class BufferedLogOutputter;
|
||||
class IEventQueue;
|
||||
|
||||
//! Implementation of ClientTaskBarReceiver for X Windows
|
||||
class CXWindowsClientTaskBarReceiver : public ClientTaskBarReceiver {
|
||||
class CXWindowsClientTaskBarReceiver : public ClientTaskBarReceiver
|
||||
{
|
||||
public:
|
||||
CXWindowsClientTaskBarReceiver(
|
||||
const BufferedLogOutputter *, IEventQueue *events);
|
||||
CXWindowsClientTaskBarReceiver(const CXWindowsClientTaskBarReceiver &) =
|
||||
delete;
|
||||
CXWindowsClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||
CXWindowsClientTaskBarReceiver(const CXWindowsClientTaskBarReceiver &) = delete;
|
||||
CXWindowsClientTaskBarReceiver(CXWindowsClientTaskBarReceiver &&) = delete;
|
||||
virtual ~CXWindowsClientTaskBarReceiver();
|
||||
|
||||
CXWindowsClientTaskBarReceiver &
|
||||
operator=(const CXWindowsClientTaskBarReceiver &) = delete;
|
||||
CXWindowsClientTaskBarReceiver &
|
||||
operator=(CXWindowsClientTaskBarReceiver &&) = delete;
|
||||
CXWindowsClientTaskBarReceiver &operator=(const CXWindowsClientTaskBarReceiver &) = delete;
|
||||
CXWindowsClientTaskBarReceiver &operator=(CXWindowsClientTaskBarReceiver &&) = delete;
|
||||
|
||||
// IArchTaskBarReceiver overrides
|
||||
virtual void showStatus();
|
||||
|
||||
@ -35,7 +35,8 @@
|
||||
#error Platform not supported.
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if SYSAPI_WIN32
|
||||
// record window instance for tray icon, etc
|
||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
|
||||
#ifdef SYSAPI_UNIX
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DaemonApp app;
|
||||
return app.run(argc, argv);
|
||||
}
|
||||
@ -32,7 +33,8 @@ int main(int argc, char **argv) {
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
|
||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||
{
|
||||
DaemonApp app;
|
||||
return app.run(__argc, __argv);
|
||||
}
|
||||
|
||||
@ -35,17 +35,18 @@
|
||||
//
|
||||
|
||||
const UINT MSWindowsServerTaskBarReceiver::s_stateToIconID[kMaxState] = {
|
||||
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED,
|
||||
IDI_TASKBAR_CONNECTED};
|
||||
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED, IDI_TASKBAR_CONNECTED
|
||||
};
|
||||
|
||||
MSWindowsServerTaskBarReceiver::MSWindowsServerTaskBarReceiver(
|
||||
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer,
|
||||
IEventQueue *events)
|
||||
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer, IEventQueue *events
|
||||
)
|
||||
: ServerTaskBarReceiver(events),
|
||||
m_events(events),
|
||||
m_appInstance(appInstance),
|
||||
m_window(NULL),
|
||||
m_logBuffer(logBuffer) {
|
||||
m_logBuffer(logBuffer)
|
||||
{
|
||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||
m_icon[i] = loadIcon(s_stateToIconID[i]);
|
||||
}
|
||||
@ -60,7 +61,8 @@ MSWindowsServerTaskBarReceiver::MSWindowsServerTaskBarReceiver(
|
||||
ARCH->addReceiver(this);
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::cleanup() {
|
||||
void MSWindowsServerTaskBarReceiver::cleanup()
|
||||
{
|
||||
ARCH->removeReceiver(this);
|
||||
for (UInt32 i = 0; i < kMaxState; ++i) {
|
||||
deleteIcon(m_icon[i]);
|
||||
@ -69,9 +71,13 @@ void MSWindowsServerTaskBarReceiver::cleanup() {
|
||||
destroyWindow();
|
||||
}
|
||||
|
||||
MSWindowsServerTaskBarReceiver::~MSWindowsServerTaskBarReceiver() { cleanup(); }
|
||||
MSWindowsServerTaskBarReceiver::~MSWindowsServerTaskBarReceiver()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::showStatus() {
|
||||
void MSWindowsServerTaskBarReceiver::showStatus()
|
||||
{
|
||||
// create the window
|
||||
createWindow();
|
||||
|
||||
@ -92,8 +98,7 @@ void MSWindowsServerTaskBarReceiver::showStatus() {
|
||||
SendMessage(child, WM_SETTEXT, 0, (LPARAM)status.c_str());
|
||||
child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_CLIENTS);
|
||||
SendMessage(child, LB_RESETCONTENT, 0, 0);
|
||||
for (Clients::const_iterator index = clients.begin();
|
||||
index != clients.end();) {
|
||||
for (Clients::const_iterator index = clients.begin(); index != clients.end();) {
|
||||
const char *client = index->c_str();
|
||||
if (++index == clients.end()) {
|
||||
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().
|
||||
// the SetForegroundWindow() and SendMessage() calls around
|
||||
// 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);
|
||||
SetMenuDefaultItem(menu, IDC_TASKBAR_STATUS, FALSE);
|
||||
HMENU logLevelMenu = GetSubMenu(menu, 3);
|
||||
CheckMenuRadioItem(
|
||||
logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
||||
int n = TrackPopupMenu(
|
||||
menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x,
|
||||
y, 0, m_window, NULL);
|
||||
CheckMenuRadioItem(logLevelMenu, 0, 6, CLOG->getFilter() - kERROR, MF_BYPOSITION);
|
||||
int n =
|
||||
TrackPopupMenu(menu, TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, x, y, 0, m_window, NULL);
|
||||
SendMessage(m_window, WM_NULL, 0, 0);
|
||||
|
||||
// perform the requested operation
|
||||
@ -175,19 +179,15 @@ void MSWindowsServerTaskBarReceiver::runMenu(int x, int y) {
|
||||
break;
|
||||
|
||||
case IDC_RELOAD_CONFIG:
|
||||
m_events->addEvent(Event(
|
||||
m_events->forServerApp().reloadConfig(), m_events->getSystemTarget()));
|
||||
m_events->addEvent(Event(m_events->forServerApp().reloadConfig(), m_events->getSystemTarget()));
|
||||
break;
|
||||
|
||||
case IDC_FORCE_RECONNECT:
|
||||
m_events->addEvent(Event(
|
||||
m_events->forServerApp().forceReconnect(),
|
||||
m_events->getSystemTarget()));
|
||||
m_events->addEvent(Event(m_events->forServerApp().forceReconnect(), m_events->getSystemTarget()));
|
||||
break;
|
||||
|
||||
case ID_DESKFLOW_RESETSERVER:
|
||||
m_events->addEvent(Event(
|
||||
m_events->forServerApp().resetServer(), m_events->getSystemTarget()));
|
||||
m_events->addEvent(Event(m_events->forServerApp().resetServer(), m_events->getSystemTarget()));
|
||||
break;
|
||||
|
||||
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
|
||||
MSWindowsServerTaskBarReceiver::getIcon() const {
|
||||
const IArchTaskBarReceiver::Icon MSWindowsServerTaskBarReceiver::getIcon() const
|
||||
{
|
||||
return static_cast<Icon>(m_icon[getStatus()]);
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::copyLog() const {
|
||||
void MSWindowsServerTaskBarReceiver::copyLog() const
|
||||
{
|
||||
if (m_logBuffer != NULL) {
|
||||
// collect log buffer
|
||||
String data;
|
||||
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin();
|
||||
index != m_logBuffer->end(); ++index) {
|
||||
for (BufferedLogOutputter::const_iterator index = m_logBuffer->begin(); index != m_logBuffer->end(); ++index) {
|
||||
data += *index;
|
||||
data += "\n";
|
||||
}
|
||||
@ -252,26 +255,29 @@ void MSWindowsServerTaskBarReceiver::copyLog() const {
|
||||
}
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::onStatusChanged() {
|
||||
void MSWindowsServerTaskBarReceiver::onStatusChanged()
|
||||
{
|
||||
if (IsWindowVisible(m_window)) {
|
||||
showStatus();
|
||||
}
|
||||
}
|
||||
|
||||
HICON
|
||||
MSWindowsServerTaskBarReceiver::loadIcon(UINT id) {
|
||||
HANDLE icon = LoadImage(
|
||||
m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
||||
MSWindowsServerTaskBarReceiver::loadIcon(UINT id)
|
||||
{
|
||||
HANDLE icon = LoadImage(m_appInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
|
||||
return static_cast<HICON>(icon);
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::deleteIcon(HICON icon) {
|
||||
void MSWindowsServerTaskBarReceiver::deleteIcon(HICON icon)
|
||||
{
|
||||
if (icon != NULL) {
|
||||
DestroyIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::createWindow() {
|
||||
void MSWindowsServerTaskBarReceiver::createWindow()
|
||||
{
|
||||
// ignore if already created
|
||||
if (m_window != NULL) {
|
||||
return;
|
||||
@ -279,9 +285,9 @@ void MSWindowsServerTaskBarReceiver::createWindow() {
|
||||
|
||||
// get the status dialog
|
||||
m_window = CreateDialogParam(
|
||||
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL,
|
||||
(DLGPROC)&MSWindowsServerTaskBarReceiver::staticDlgProc,
|
||||
reinterpret_cast<LPARAM>(static_cast<void *>(this)));
|
||||
m_appInstance, MAKEINTRESOURCE(IDD_TASKBAR_STATUS), NULL, (DLGPROC)&MSWindowsServerTaskBarReceiver::staticDlgProc,
|
||||
reinterpret_cast<LPARAM>(static_cast<void *>(this))
|
||||
);
|
||||
|
||||
// window should appear on top of everything, including (especially)
|
||||
// the task bar.
|
||||
@ -293,7 +299,8 @@ void MSWindowsServerTaskBarReceiver::createWindow() {
|
||||
ArchTaskBarWindows::addDialog(m_window);
|
||||
}
|
||||
|
||||
void MSWindowsServerTaskBarReceiver::destroyWindow() {
|
||||
void MSWindowsServerTaskBarReceiver::destroyWindow()
|
||||
{
|
||||
if (m_window != NULL) {
|
||||
ArchTaskBarWindows::removeDialog(m_window);
|
||||
DestroyWindow(m_window);
|
||||
@ -301,8 +308,8 @@ void MSWindowsServerTaskBarReceiver::destroyWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
BOOL MSWindowsServerTaskBarReceiver::dlgProc(
|
||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM) {
|
||||
BOOL MSWindowsServerTaskBarReceiver::dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
|
||||
{
|
||||
switch (msg) {
|
||||
case WM_INITDIALOG:
|
||||
// use default focus
|
||||
@ -318,21 +325,19 @@ BOOL MSWindowsServerTaskBarReceiver::dlgProc(
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CALLBACK MSWindowsServerTaskBarReceiver::staticDlgProc(
|
||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
BOOL CALLBACK MSWindowsServerTaskBarReceiver::staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
// if msg is WM_INITDIALOG, extract the MSWindowsServerTaskBarReceiver*
|
||||
// and put it in the extra window data then forward the call.
|
||||
MSWindowsServerTaskBarReceiver *self = NULL;
|
||||
if (msg == WM_INITDIALOG) {
|
||||
self = static_cast<MSWindowsServerTaskBarReceiver *>(
|
||||
reinterpret_cast<void *>(lParam));
|
||||
self = static_cast<MSWindowsServerTaskBarReceiver *>(reinterpret_cast<void *>(lParam));
|
||||
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
|
||||
} else {
|
||||
// get the extra window data and forward the call
|
||||
LONG_PTR data = GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
if (data != 0) {
|
||||
self = static_cast<MSWindowsServerTaskBarReceiver *>(
|
||||
reinterpret_cast<void *>(data));
|
||||
self = static_cast<MSWindowsServerTaskBarReceiver *>(reinterpret_cast<void *>(data));
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,16 +349,12 @@ BOOL CALLBACK MSWindowsServerTaskBarReceiver::staticDlgProc(
|
||||
}
|
||||
}
|
||||
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||
{
|
||||
ArchMiscWindows::setIcons(
|
||||
(HICON)LoadImage(
|
||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
||||
IMAGE_ICON, 32, 32, LR_SHARED),
|
||||
(HICON)LoadImage(
|
||||
ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW),
|
||||
IMAGE_ICON, 16, 16, LR_SHARED));
|
||||
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 32, 32, LR_SHARED),
|
||||
(HICON)LoadImage(ArchMiscWindows::instanceWin32(), MAKEINTRESOURCE(IDI_DESKFLOW), IMAGE_ICON, 16, 16, LR_SHARED)
|
||||
);
|
||||
|
||||
return new MSWindowsServerTaskBarReceiver(
|
||||
MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
||||
return new MSWindowsServerTaskBarReceiver(MSWindowsScreen::getWindowInstance(), logBuffer, events);
|
||||
}
|
||||
|
||||
@ -27,10 +27,10 @@ class BufferedLogOutputter;
|
||||
class IEventQueue;
|
||||
|
||||
//! Implementation of ServerTaskBarReceiver for Microsoft Windows
|
||||
class MSWindowsServerTaskBarReceiver : public ServerTaskBarReceiver {
|
||||
class MSWindowsServerTaskBarReceiver : public ServerTaskBarReceiver
|
||||
{
|
||||
public:
|
||||
MSWindowsServerTaskBarReceiver(
|
||||
HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
||||
MSWindowsServerTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *, IEventQueue *events);
|
||||
virtual ~MSWindowsServerTaskBarReceiver();
|
||||
|
||||
// IArchTaskBarReceiver overrides
|
||||
@ -53,8 +53,7 @@ private:
|
||||
void destroyWindow();
|
||||
|
||||
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static BOOL CALLBACK
|
||||
staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
private:
|
||||
HINSTANCE m_appInstance;
|
||||
|
||||
@ -23,34 +23,39 @@
|
||||
// OSXServerTaskBarReceiver
|
||||
//
|
||||
|
||||
OSXServerTaskBarReceiver::OSXServerTaskBarReceiver(
|
||||
const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ServerTaskBarReceiver(events) {
|
||||
OSXServerTaskBarReceiver::OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ServerTaskBarReceiver(events)
|
||||
{
|
||||
// add ourself to the task bar
|
||||
ARCH->addReceiver(this);
|
||||
}
|
||||
|
||||
OSXServerTaskBarReceiver::~OSXServerTaskBarReceiver() {
|
||||
OSXServerTaskBarReceiver::~OSXServerTaskBarReceiver()
|
||||
{
|
||||
ARCH->removeReceiver(this);
|
||||
}
|
||||
|
||||
void OSXServerTaskBarReceiver::showStatus() {
|
||||
void OSXServerTaskBarReceiver::showStatus()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void OSXServerTaskBarReceiver::runMenu(int, int) {
|
||||
void OSXServerTaskBarReceiver::runMenu(int, int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void OSXServerTaskBarReceiver::primaryAction() {
|
||||
void OSXServerTaskBarReceiver::primaryAction()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const IArchTaskBarReceiver::Icon OSXServerTaskBarReceiver::getIcon() const {
|
||||
const IArchTaskBarReceiver::Icon OSXServerTaskBarReceiver::getIcon() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||
{
|
||||
return new OSXServerTaskBarReceiver(logBuffer, events);
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
class BufferedLogOutputter;
|
||||
|
||||
//! Implementation of ServerTaskBarReceiver for OS X
|
||||
class OSXServerTaskBarReceiver : public ServerTaskBarReceiver {
|
||||
class OSXServerTaskBarReceiver : public ServerTaskBarReceiver
|
||||
{
|
||||
public:
|
||||
OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||
virtual ~OSXServerTaskBarReceiver();
|
||||
|
||||
@ -23,35 +23,39 @@
|
||||
// CXWindowsServerTaskBarReceiver
|
||||
//
|
||||
|
||||
CXWindowsServerTaskBarReceiver::CXWindowsServerTaskBarReceiver(
|
||||
const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ServerTaskBarReceiver(events) {
|
||||
CXWindowsServerTaskBarReceiver::CXWindowsServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events)
|
||||
: ServerTaskBarReceiver(events)
|
||||
{
|
||||
// add ourself to the task bar
|
||||
ARCH->addReceiver(this);
|
||||
}
|
||||
|
||||
CXWindowsServerTaskBarReceiver::~CXWindowsServerTaskBarReceiver() {
|
||||
CXWindowsServerTaskBarReceiver::~CXWindowsServerTaskBarReceiver()
|
||||
{
|
||||
ARCH->removeReceiver(this);
|
||||
}
|
||||
|
||||
void CXWindowsServerTaskBarReceiver::showStatus() {
|
||||
void CXWindowsServerTaskBarReceiver::showStatus()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CXWindowsServerTaskBarReceiver::runMenu(int, int) {
|
||||
void CXWindowsServerTaskBarReceiver::runMenu(int, int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void CXWindowsServerTaskBarReceiver::primaryAction() {
|
||||
void CXWindowsServerTaskBarReceiver::primaryAction()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const IArchTaskBarReceiver::Icon
|
||||
CXWindowsServerTaskBarReceiver::getIcon() const {
|
||||
const IArchTaskBarReceiver::Icon CXWindowsServerTaskBarReceiver::getIcon() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(
|
||||
const BufferedLogOutputter *logBuffer, IEventQueue *events) {
|
||||
IArchTaskBarReceiver *createTaskBarReceiver(const BufferedLogOutputter *logBuffer, IEventQueue *events)
|
||||
{
|
||||
return new CXWindowsServerTaskBarReceiver(logBuffer, events);
|
||||
}
|
||||
|
||||
@ -24,19 +24,16 @@ class BufferedLogOutputter;
|
||||
class IEventQueue;
|
||||
|
||||
//! Implementation of ServerTaskBarReceiver for X Windows
|
||||
class CXWindowsServerTaskBarReceiver : public ServerTaskBarReceiver {
|
||||
class CXWindowsServerTaskBarReceiver : public ServerTaskBarReceiver
|
||||
{
|
||||
public:
|
||||
CXWindowsServerTaskBarReceiver(
|
||||
const BufferedLogOutputter *, IEventQueue *events);
|
||||
CXWindowsServerTaskBarReceiver(const CXWindowsServerTaskBarReceiver &) =
|
||||
delete;
|
||||
CXWindowsServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
|
||||
CXWindowsServerTaskBarReceiver(const CXWindowsServerTaskBarReceiver &) = delete;
|
||||
CXWindowsServerTaskBarReceiver(CXWindowsServerTaskBarReceiver &&) = delete;
|
||||
virtual ~CXWindowsServerTaskBarReceiver();
|
||||
|
||||
CXWindowsServerTaskBarReceiver &
|
||||
operator=(const CXWindowsServerTaskBarReceiver &) = delete;
|
||||
CXWindowsServerTaskBarReceiver &
|
||||
operator=(const CXWindowsServerTaskBarReceiver &&) = delete;
|
||||
CXWindowsServerTaskBarReceiver &operator=(const CXWindowsServerTaskBarReceiver &) = delete;
|
||||
CXWindowsServerTaskBarReceiver &operator=(const CXWindowsServerTaskBarReceiver &&) = delete;
|
||||
|
||||
// IArchTaskBarReceiver overrides
|
||||
virtual void showStatus();
|
||||
|
||||
@ -35,7 +35,8 @@
|
||||
#error Platform not supported.
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#if SYSAPI_WIN32
|
||||
// record window instance for tray icon, etc
|
||||
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
|
||||
|
||||
@ -22,11 +22,9 @@
|
||||
#include <QTextStream>
|
||||
|
||||
const char *Action::m_ActionTypeNames[] = {
|
||||
"keyDown", "keyUp",
|
||||
"keystroke", "switchToScreen",
|
||||
"switchInDirection", "lockCursorToScreen",
|
||||
"restartServer", "mouseDown",
|
||||
"mouseUp", "mousebutton"};
|
||||
"keyDown", "keyUp", "keystroke", "switchToScreen", "switchInDirection", "lockCursorToScreen",
|
||||
"restartServer", "mouseDown", "mouseUp", "mousebutton"
|
||||
};
|
||||
|
||||
const char *Action::m_SwitchDirectionNames[] = {"left", "right", "up", "down"};
|
||||
const char *Action::m_LockCursorModeNames[] = {"toggle", "on", "off"};
|
||||
@ -39,13 +37,13 @@ Action::Action()
|
||||
m_SwitchDirection(switchLeft),
|
||||
m_LockCursorMode(lockCursorToggle),
|
||||
m_ActiveOnRelease(false),
|
||||
m_HasScreens(false) {}
|
||||
m_HasScreens(false)
|
||||
{
|
||||
}
|
||||
|
||||
QString Action::text() const {
|
||||
QString text =
|
||||
QString(m_ActionTypeNames
|
||||
[keySequence().isMouseButton() ? type() + 6 : type()]) +
|
||||
"(";
|
||||
QString Action::text() const
|
||||
{
|
||||
QString text = QString(m_ActionTypeNames[keySequence().isMouseButton() ? type() + 6 : type()]) + "(";
|
||||
|
||||
switch (type()) {
|
||||
case keyDown:
|
||||
@ -93,7 +91,8 @@ QString Action::text() const {
|
||||
return text;
|
||||
}
|
||||
|
||||
void Action::loadSettings(QSettings &settings) {
|
||||
void Action::loadSettings(QSettings &settings)
|
||||
{
|
||||
keySequence().loadSettings(settings);
|
||||
setType(settings.value("type", keyDown).toInt());
|
||||
|
||||
@ -107,14 +106,14 @@ void Action::loadSettings(QSettings &settings) {
|
||||
|
||||
setSwitchScreenName(settings.value("switchScreenName").toString());
|
||||
setSwitchDirection(settings.value("switchInDirection", switchLeft).toInt());
|
||||
setLockCursorMode(
|
||||
settings.value("lockCursorToScreen", lockCursorToggle).toInt());
|
||||
setLockCursorMode(settings.value("lockCursorToScreen", lockCursorToggle).toInt());
|
||||
setActiveOnRelease(settings.value("activeOnRelease", false).toBool());
|
||||
setHaveScreens(settings.value("hasScreens", false).toBool());
|
||||
setRestartServer(settings.value("restartServer", false).toBool());
|
||||
}
|
||||
|
||||
void Action::saveSettings(QSettings &settings) const {
|
||||
void Action::saveSettings(QSettings &settings) const
|
||||
{
|
||||
keySequence().saveSettings(settings);
|
||||
settings.setValue("type", type());
|
||||
|
||||
@ -133,17 +132,16 @@ void Action::saveSettings(QSettings &settings) const {
|
||||
settings.setValue("restartServer", restartServer());
|
||||
}
|
||||
|
||||
bool Action::operator==(const Action &a) const {
|
||||
return m_KeySequence == a.m_KeySequence && m_Type == a.m_Type &&
|
||||
m_TypeScreenNames == a.m_TypeScreenNames &&
|
||||
m_SwitchScreenName == a.m_SwitchScreenName &&
|
||||
m_SwitchDirection == a.m_SwitchDirection &&
|
||||
m_LockCursorMode == a.m_LockCursorMode &&
|
||||
m_ActiveOnRelease == a.m_ActiveOnRelease &&
|
||||
bool Action::operator==(const Action &a) const
|
||||
{
|
||||
return m_KeySequence == a.m_KeySequence && m_Type == a.m_Type && m_TypeScreenNames == a.m_TypeScreenNames &&
|
||||
m_SwitchScreenName == a.m_SwitchScreenName && m_SwitchDirection == a.m_SwitchDirection &&
|
||||
m_LockCursorMode == a.m_LockCursorMode && m_ActiveOnRelease == a.m_ActiveOnRelease &&
|
||||
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())
|
||||
outStream << ";";
|
||||
|
||||
|
||||
@ -28,12 +28,14 @@ class ActionDialog;
|
||||
class QSettings;
|
||||
class QTextStream;
|
||||
|
||||
class Action {
|
||||
class Action
|
||||
{
|
||||
friend class ActionDialog;
|
||||
friend QTextStream &operator<<(QTextStream &outStream, const Action &action);
|
||||
|
||||
public:
|
||||
enum ActionType {
|
||||
enum ActionType
|
||||
{
|
||||
keyDown,
|
||||
keyUp,
|
||||
keystroke,
|
||||
@ -45,39 +47,107 @@ public:
|
||||
mouseUp,
|
||||
mousebutton,
|
||||
};
|
||||
enum SwitchDirection { switchLeft, switchRight, switchUp, switchDown };
|
||||
enum LockCursorMode { lockCursorToggle, lockCursonOn, lockCursorOff };
|
||||
enum SwitchDirection
|
||||
{
|
||||
switchLeft,
|
||||
switchRight,
|
||||
switchUp,
|
||||
switchDown
|
||||
};
|
||||
enum LockCursorMode
|
||||
{
|
||||
lockCursorToggle,
|
||||
lockCursonOn,
|
||||
lockCursorOff
|
||||
};
|
||||
|
||||
public:
|
||||
Action();
|
||||
|
||||
public:
|
||||
QString text() const;
|
||||
const KeySequence &keySequence() const { return m_KeySequence; }
|
||||
const KeySequence &keySequence() const
|
||||
{
|
||||
return m_KeySequence;
|
||||
}
|
||||
void loadSettings(QSettings &settings);
|
||||
void saveSettings(QSettings &settings) const;
|
||||
int type() const { return m_Type; }
|
||||
const QStringList &typeScreenNames() const { return m_TypeScreenNames; }
|
||||
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; }
|
||||
int type() const
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
const QStringList &typeScreenNames() const
|
||||
{
|
||||
return m_TypeScreenNames;
|
||||
}
|
||||
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;
|
||||
|
||||
protected:
|
||||
KeySequence &keySequence() { return m_KeySequence; }
|
||||
void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; }
|
||||
void setType(int t) { 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; }
|
||||
KeySequence &keySequence()
|
||||
{
|
||||
return m_KeySequence;
|
||||
}
|
||||
void setKeySequence(const KeySequence &seq)
|
||||
{
|
||||
m_KeySequence = seq;
|
||||
}
|
||||
void setType(int t)
|
||||
{
|
||||
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:
|
||||
KeySequence m_KeySequence;
|
||||
|
||||
@ -27,14 +27,14 @@
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
ActionDialog::ActionDialog(
|
||||
QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action)
|
||||
ActionDialog::ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
Ui::ActionDialogBase(),
|
||||
m_ServerConfig(config),
|
||||
m_Hotkey(hotkey),
|
||||
m_Action(action),
|
||||
m_pButtonGroupType(new QButtonGroup(this)) {
|
||||
m_pButtonGroupType(new QButtonGroup(this))
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
// work around Qt Designer's lack of a QButtonGroup; we need it to get
|
||||
@ -46,10 +46,10 @@ ActionDialog::ActionDialog(
|
||||
m_pRadioSwitchToScreen,
|
||||
m_pRadioSwitchInDirection,
|
||||
m_pRadioLockCursorToScreen,
|
||||
m_pRadioRestartAllConnections};
|
||||
m_pRadioRestartAllConnections
|
||||
};
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]);
|
||||
i++)
|
||||
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++)
|
||||
m_pButtonGroupType->addButton(typeButtons[i], i);
|
||||
|
||||
m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString());
|
||||
@ -81,9 +81,9 @@ ActionDialog::ActionDialog(
|
||||
}
|
||||
}
|
||||
|
||||
void ActionDialog::accept() {
|
||||
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 &&
|
||||
m_pButtonGroupType->checkedId() < 3)
|
||||
void ActionDialog::accept()
|
||||
{
|
||||
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 && m_pButtonGroupType->checkedId() < 3)
|
||||
return;
|
||||
|
||||
m_Action.setKeySequence(sequenceWidget()->keySequence());
|
||||
@ -103,7 +103,8 @@ void ActionDialog::accept() {
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged() {
|
||||
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged()
|
||||
{
|
||||
if (sequenceWidget()->keySequence().isMouseButton()) {
|
||||
m_pGroupBoxScreens->setEnabled(false);
|
||||
m_pListScreens->setEnabled(false);
|
||||
|
||||
@ -28,22 +28,26 @@ class QRadioButton;
|
||||
class QButtonGroup;
|
||||
class ServerConfig;
|
||||
|
||||
class ActionDialog : public QDialog, public Ui::ActionDialogBase {
|
||||
class ActionDialog : public QDialog, public Ui::ActionDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ActionDialog(
|
||||
QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action);
|
||||
ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey, Action &action);
|
||||
|
||||
protected slots:
|
||||
void accept();
|
||||
void on_m_pKeySequenceWidgetHotkey_keySequenceChanged();
|
||||
|
||||
protected:
|
||||
const KeySequenceWidget *sequenceWidget() const {
|
||||
const KeySequenceWidget *sequenceWidget() const
|
||||
{
|
||||
return m_pKeySequenceWidgetHotkey;
|
||||
}
|
||||
const ServerConfig &serverConfig() const { return m_ServerConfig; }
|
||||
const ServerConfig &serverConfig() const
|
||||
{
|
||||
return m_ServerConfig;
|
||||
}
|
||||
|
||||
private:
|
||||
const ServerConfig &m_ServerConfig;
|
||||
|
||||
@ -24,13 +24,15 @@
|
||||
AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
Ui::AddClientDialog(),
|
||||
m_AddResult(kAddClientIgnore) {
|
||||
m_AddResult(kAddClientIgnore)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
m_pLabelHead->setText(
|
||||
"A client wants to connect. "
|
||||
"Please choose a location for " +
|
||||
clientName + ".");
|
||||
clientName + "."
|
||||
);
|
||||
|
||||
QIcon icon(":res/icons/64x64/video-display.png");
|
||||
QSize IconSize(32, 32);
|
||||
@ -39,33 +41,25 @@ AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
|
||||
m_pButtonLeft->setIcon(icon);
|
||||
m_pButtonLeft->setIconSize(IconSize);
|
||||
gridLayout->addWidget(m_pButtonLeft, 2, 0, 1, 1, Qt::AlignCenter);
|
||||
connect(
|
||||
m_pButtonLeft, &QPushButton::clicked, this,
|
||||
&AddClientDialog::handleButtonLeft);
|
||||
connect(m_pButtonLeft, &QPushButton::clicked, this, &AddClientDialog::handleButtonLeft);
|
||||
|
||||
m_pButtonUp = new QPushButton(this);
|
||||
m_pButtonUp->setIcon(icon);
|
||||
m_pButtonUp->setIconSize(IconSize);
|
||||
gridLayout->addWidget(m_pButtonUp, 1, 1, 1, 1, Qt::AlignCenter);
|
||||
connect(
|
||||
m_pButtonUp, &QPushButton::clicked, this,
|
||||
&AddClientDialog::handleButtonUp);
|
||||
connect(m_pButtonUp, &QPushButton::clicked, this, &AddClientDialog::handleButtonUp);
|
||||
|
||||
m_pButtonRight = new QPushButton(this);
|
||||
m_pButtonRight->setIcon(icon);
|
||||
m_pButtonRight->setIconSize(IconSize);
|
||||
gridLayout->addWidget(m_pButtonRight, 2, 2, 1, 1, Qt::AlignCenter);
|
||||
connect(
|
||||
m_pButtonRight, &QPushButton::clicked, this,
|
||||
&AddClientDialog::handleButtonRight);
|
||||
connect(m_pButtonRight, &QPushButton::clicked, this, &AddClientDialog::handleButtonRight);
|
||||
|
||||
m_pButtonDown = new QPushButton(this);
|
||||
m_pButtonDown->setIcon(icon);
|
||||
m_pButtonDown->setIconSize(IconSize);
|
||||
gridLayout->addWidget(m_pButtonDown, 3, 1, 1, 1, Qt::AlignCenter);
|
||||
connect(
|
||||
m_pButtonDown, &QPushButton::clicked, this,
|
||||
&AddClientDialog::handleButtonDown);
|
||||
connect(m_pButtonDown, &QPushButton::clicked, this, &AddClientDialog::handleButtonDown);
|
||||
|
||||
m_pLabelCenter = new QLabel(this);
|
||||
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);
|
||||
#endif
|
||||
|
||||
QPushButton *advanced =
|
||||
m_pDialogButtonBox->addButton("Advanced", QDialogButtonBox::HelpRole);
|
||||
connect(
|
||||
advanced, &QPushButton::clicked, this,
|
||||
&AddClientDialog::handleButtonAdvanced);
|
||||
QPushButton *advanced = m_pDialogButtonBox->addButton("Advanced", QDialogButtonBox::HelpRole);
|
||||
connect(advanced, &QPushButton::clicked, this, &AddClientDialog::handleButtonAdvanced);
|
||||
}
|
||||
|
||||
AddClientDialog::~AddClientDialog() {
|
||||
AddClientDialog::~AddClientDialog()
|
||||
{
|
||||
delete m_pButtonUp;
|
||||
delete m_pButtonDown;
|
||||
delete m_pButtonLeft;
|
||||
@ -90,27 +82,32 @@ AddClientDialog::~AddClientDialog() {
|
||||
delete m_pLabelCenter;
|
||||
}
|
||||
|
||||
void AddClientDialog::handleButtonLeft() {
|
||||
void AddClientDialog::handleButtonLeft()
|
||||
{
|
||||
m_AddResult = kAddClientLeft;
|
||||
close();
|
||||
}
|
||||
|
||||
void AddClientDialog::handleButtonUp() {
|
||||
void AddClientDialog::handleButtonUp()
|
||||
{
|
||||
m_AddResult = kAddClientUp;
|
||||
close();
|
||||
}
|
||||
|
||||
void AddClientDialog::handleButtonRight() {
|
||||
void AddClientDialog::handleButtonRight()
|
||||
{
|
||||
m_AddResult = kAddClientRight;
|
||||
close();
|
||||
}
|
||||
|
||||
void AddClientDialog::handleButtonDown() {
|
||||
void AddClientDialog::handleButtonDown()
|
||||
{
|
||||
m_AddResult = kAddClientDown;
|
||||
close();
|
||||
}
|
||||
|
||||
void AddClientDialog::handleButtonAdvanced() {
|
||||
void AddClientDialog::handleButtonAdvanced()
|
||||
{
|
||||
m_AddResult = kAddClientOther;
|
||||
close();
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@
|
||||
class QPushButton;
|
||||
class QLabel;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
kAddClientRight,
|
||||
kAddClientLeft,
|
||||
kAddClientUp,
|
||||
@ -33,13 +34,17 @@ enum {
|
||||
kAddClientIgnore
|
||||
};
|
||||
|
||||
class AddClientDialog : public QDialog, public Ui::AddClientDialog {
|
||||
class AddClientDialog : public QDialog, public Ui::AddClientDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AddClientDialog(const QString &clientName, QWidget *parent = 0);
|
||||
~AddClientDialog();
|
||||
|
||||
int addResult() { return m_AddResult; }
|
||||
int addResult()
|
||||
{
|
||||
return m_AddResult;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void handleButtonLeft();
|
||||
|
||||
@ -1,21 +1,19 @@
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#if OSX_DEPLOYMENT_TARGET >= 1014
|
||||
#import <UserNotifications/UNUserNotificationCenter.h>
|
||||
@interface AppDelegate
|
||||
: NSObject <
|
||||
NSApplicationDelegate, NSUserNotificationCenterDelegate,
|
||||
UNUserNotificationCenterDelegate>
|
||||
@interface AppDelegate
|
||||
: NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate, UNUserNotificationCenterDelegate>
|
||||
#else
|
||||
@interface AppDelegate
|
||||
: NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
|
||||
#endif
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -17,18 +17,17 @@
|
||||
|
||||
#include "DataDownloader.h"
|
||||
|
||||
DataDownloader::DataDownloader(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_pReply(nullptr),
|
||||
m_IsFinished(false) {
|
||||
connect(
|
||||
&m_NetworkManager, &QNetworkAccessManager::finished, this,
|
||||
&DataDownloader::complete);
|
||||
DataDownloader::DataDownloader(QObject *parent) : QObject(parent), m_pReply(nullptr), 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();
|
||||
reply->deleteLater();
|
||||
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) {
|
||||
m_pReply->abort();
|
||||
}
|
||||
}
|
||||
|
||||
void DataDownloader::download(QUrl url) {
|
||||
void DataDownloader::download(QUrl url)
|
||||
{
|
||||
QNetworkRequest request(url);
|
||||
m_pReply = m_NetworkManager.get(request);
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#include <QNetworkRequest>
|
||||
#include <QObject>
|
||||
|
||||
class DataDownloader : public QObject {
|
||||
class DataDownloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -33,7 +34,10 @@ public:
|
||||
QByteArray data() const;
|
||||
void cancel();
|
||||
void download(QUrl url);
|
||||
bool isFinished() const { return m_IsFinished; }
|
||||
bool isFinished() const
|
||||
{
|
||||
return m_IsFinished;
|
||||
}
|
||||
|
||||
signals:
|
||||
void isComplete();
|
||||
|
||||
@ -23,8 +23,8 @@
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
DeskflowApplication::DeskflowApplication(int &argc, char **argv)
|
||||
: QApplication(argc, argv) {
|
||||
DeskflowApplication::DeskflowApplication(int &argc, char **argv) : QApplication(argc, argv)
|
||||
{
|
||||
|
||||
if (qEnvironmentVariable("XDG_CURRENT_DESKTOP") != QLatin1String("KDE")) {
|
||||
// causes dark mode to be used on some OS (e.g. Windows)
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
|
||||
class QSessionManager;
|
||||
|
||||
class DeskflowApplication : public QApplication {
|
||||
class DeskflowApplication : public QApplication
|
||||
{
|
||||
public:
|
||||
DeskflowApplication(int &argc, char **argv);
|
||||
~DeskflowApplication() override = default;
|
||||
|
||||
@ -20,9 +20,12 @@
|
||||
|
||||
#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();
|
||||
|
||||
if (keySequence().isMouseButton())
|
||||
@ -31,7 +34,8 @@ QString Hotkey::text() const {
|
||||
return "keystroke(" + text + ")";
|
||||
}
|
||||
|
||||
void Hotkey::loadSettings(QSettings &settings) {
|
||||
void Hotkey::loadSettings(QSettings &settings)
|
||||
{
|
||||
keySequence().loadSettings(settings);
|
||||
|
||||
actions().clear();
|
||||
@ -46,7 +50,8 @@ void Hotkey::loadSettings(QSettings &settings) {
|
||||
settings.endArray();
|
||||
}
|
||||
|
||||
void Hotkey::saveSettings(QSettings &settings) const {
|
||||
void Hotkey::saveSettings(QSettings &settings) const
|
||||
{
|
||||
keySequence().saveSettings(settings);
|
||||
|
||||
settings.beginWriteArray("actions");
|
||||
@ -57,14 +62,15 @@ void Hotkey::saveSettings(QSettings &settings) const {
|
||||
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;
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey) {
|
||||
QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey)
|
||||
{
|
||||
for (int i = 0; i < hotkey.actions().size(); i++)
|
||||
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i]
|
||||
<< Qt::endl;
|
||||
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i] << Qt::endl;
|
||||
|
||||
return outStream;
|
||||
}
|
||||
|
||||
@ -28,7 +28,8 @@ class HotkeyDialog;
|
||||
class ServerConfigDialog;
|
||||
class QSettings;
|
||||
|
||||
class Hotkey {
|
||||
class Hotkey
|
||||
{
|
||||
friend class HotkeyDialog;
|
||||
friend class ServerConfigDialog;
|
||||
friend QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey);
|
||||
@ -38,8 +39,14 @@ public:
|
||||
|
||||
public:
|
||||
QString text() const;
|
||||
const KeySequence &keySequence() const { return m_KeySequence; }
|
||||
const ActionList &actions() const { return m_Actions; }
|
||||
const KeySequence &keySequence() const
|
||||
{
|
||||
return m_KeySequence;
|
||||
}
|
||||
const ActionList &actions() const
|
||||
{
|
||||
return m_Actions;
|
||||
}
|
||||
|
||||
void loadSettings(QSettings &settings);
|
||||
void saveSettings(QSettings &settings) const;
|
||||
@ -47,9 +54,18 @@ public:
|
||||
bool operator==(const Hotkey &hk) const;
|
||||
|
||||
protected:
|
||||
KeySequence &keySequence() { return m_KeySequence; }
|
||||
void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; }
|
||||
ActionList &actions() { return m_Actions; }
|
||||
KeySequence &keySequence()
|
||||
{
|
||||
return m_KeySequence;
|
||||
}
|
||||
void setKeySequence(const KeySequence &seq)
|
||||
{
|
||||
m_KeySequence = seq;
|
||||
}
|
||||
ActionList &actions()
|
||||
{
|
||||
return m_Actions;
|
||||
}
|
||||
|
||||
private:
|
||||
KeySequence m_KeySequence;
|
||||
|
||||
@ -24,13 +24,15 @@
|
||||
HotkeyDialog::HotkeyDialog(QWidget *parent, Hotkey &hotkey)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
Ui::HotkeyDialogBase(),
|
||||
m_Hotkey(hotkey) {
|
||||
m_Hotkey(hotkey)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
m_pKeySequenceWidgetHotkey->setText(m_Hotkey.text());
|
||||
}
|
||||
|
||||
void HotkeyDialog::accept() {
|
||||
void HotkeyDialog::accept()
|
||||
{
|
||||
if (!sequenceWidget()->valid())
|
||||
return;
|
||||
|
||||
|
||||
@ -22,23 +22,31 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class HotkeyDialog : public QDialog, public Ui::HotkeyDialogBase {
|
||||
class HotkeyDialog : public QDialog, public Ui::HotkeyDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HotkeyDialog(QWidget *parent, Hotkey &hotkey);
|
||||
|
||||
public:
|
||||
const Hotkey &hotkey() const { return m_Hotkey; }
|
||||
const Hotkey &hotkey() const
|
||||
{
|
||||
return m_Hotkey;
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void accept();
|
||||
|
||||
protected:
|
||||
const KeySequenceWidget *sequenceWidget() const {
|
||||
const KeySequenceWidget *sequenceWidget() const
|
||||
{
|
||||
return m_pKeySequenceWidgetHotkey;
|
||||
}
|
||||
Hotkey &hotkey() { return m_Hotkey; }
|
||||
Hotkey &hotkey()
|
||||
{
|
||||
return m_Hotkey;
|
||||
}
|
||||
|
||||
private:
|
||||
Hotkey &m_Hotkey;
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
|
||||
// this table originally comes from Qt sources (gui/kernel/qkeysequence.cpp)
|
||||
// and is heavily modified for Deskflow
|
||||
static const struct {
|
||||
static const struct
|
||||
{
|
||||
int key;
|
||||
const char *name;
|
||||
} keyname[] = {
|
||||
@ -75,15 +76,20 @@ static const struct {
|
||||
{Qt::Key_Launch1, "AppUser2"},
|
||||
{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;
|
||||
}
|
||||
|
||||
QString KeySequence::toString() const {
|
||||
QString KeySequence::toString() const
|
||||
{
|
||||
QString result;
|
||||
|
||||
for (int i = 0; i < m_Sequence.size(); i++) {
|
||||
@ -96,9 +102,13 @@ QString KeySequence::toString() const {
|
||||
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)
|
||||
return true;
|
||||
|
||||
@ -131,7 +141,8 @@ bool KeySequence::appendKey(int key, int modifiers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void KeySequence::loadSettings(QSettings &settings) {
|
||||
void KeySequence::loadSettings(QSettings &settings)
|
||||
{
|
||||
sequence().clear();
|
||||
int num = settings.beginReadArray("keys");
|
||||
for (int i = 0; i < num; i++) {
|
||||
@ -144,7 +155,8 @@ void KeySequence::loadSettings(QSettings &settings) {
|
||||
setValid(true);
|
||||
}
|
||||
|
||||
void KeySequence::saveSettings(QSettings &settings) const {
|
||||
void KeySequence::saveSettings(QSettings &settings) const
|
||||
{
|
||||
settings.beginWriteArray("keys");
|
||||
for (int i = 0; i < sequence().size(); i++) {
|
||||
settings.setArrayIndex(i);
|
||||
@ -153,7 +165,8 @@ void KeySequence::saveSettings(QSettings &settings) const {
|
||||
settings.endArray();
|
||||
}
|
||||
|
||||
QString KeySequence::keyToString(int key) {
|
||||
QString KeySequence::keyToString(int key)
|
||||
{
|
||||
// nothing there?
|
||||
if (key == 0)
|
||||
return "";
|
||||
@ -208,14 +221,13 @@ QString KeySequence::keyToString(int key) {
|
||||
|
||||
// representable in ucs2?
|
||||
if (key < 0x10000)
|
||||
return QString("\\u%1").arg(
|
||||
QChar(key).toLower().unicode(), 4, 16, QChar('0'));
|
||||
return QString("\\u%1").arg(QChar(key).toLower().unicode(), 4, 16, QChar('0'));
|
||||
|
||||
// give up, deskflow probably won't handle this
|
||||
return "";
|
||||
}
|
||||
|
||||
bool KeySequence::operator==(const KeySequence &ks) const {
|
||||
return m_Sequence == ks.m_Sequence && m_Modifiers == ks.m_Modifiers &&
|
||||
m_IsValid == ks.m_IsValid;
|
||||
bool KeySequence::operator==(const KeySequence &ks) const
|
||||
{
|
||||
return m_Sequence == ks.m_Sequence && m_Modifiers == ks.m_Modifiers && m_IsValid == ks.m_IsValid;
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
|
||||
class QSettings;
|
||||
|
||||
class KeySequence {
|
||||
class KeySequence
|
||||
{
|
||||
public:
|
||||
KeySequence();
|
||||
|
||||
@ -32,18 +33,36 @@ public:
|
||||
bool appendKey(int modifiers, int key);
|
||||
bool appendMouseButton(int button);
|
||||
bool isMouseButton() const;
|
||||
bool valid() const { return m_IsValid; }
|
||||
int modifiers() const { return m_Modifiers; }
|
||||
bool valid() const
|
||||
{
|
||||
return m_IsValid;
|
||||
}
|
||||
int modifiers() const
|
||||
{
|
||||
return m_Modifiers;
|
||||
}
|
||||
void saveSettings(QSettings &settings) const;
|
||||
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;
|
||||
|
||||
private:
|
||||
void setValid(bool b) { m_IsValid = b; }
|
||||
void setModifiers(int i) { m_Modifiers = i; }
|
||||
QList<int> &sequence() { return m_Sequence; }
|
||||
void setValid(bool b)
|
||||
{
|
||||
m_IsValid = b;
|
||||
}
|
||||
void setModifiers(int i)
|
||||
{
|
||||
m_Modifiers = i;
|
||||
}
|
||||
QList<int> &sequence()
|
||||
{
|
||||
return m_Sequence;
|
||||
}
|
||||
|
||||
private:
|
||||
QList<int> m_Sequence;
|
||||
|
||||
@ -29,12 +29,14 @@ KeySequenceWidget::KeySequenceWidget(QWidget *parent, const KeySequence &seq)
|
||||
m_MousePrefix("mousebutton("),
|
||||
m_MousePostfix(")"),
|
||||
m_KeyPrefix("keystroke("),
|
||||
m_KeyPostfix(")") {
|
||||
m_KeyPostfix(")")
|
||||
{
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
void KeySequenceWidget::setKeySequence(const KeySequence &seq) {
|
||||
void KeySequenceWidget::setKeySequence(const KeySequence &seq)
|
||||
{
|
||||
keySequence() = seq;
|
||||
backupSequence() = seq;
|
||||
|
||||
@ -42,7 +44,8 @@ void KeySequenceWidget::setKeySequence(const KeySequence &seq) {
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
void KeySequenceWidget::mousePressEvent(QMouseEvent *event) {
|
||||
void KeySequenceWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
if (status() == Stopped) {
|
||||
@ -56,7 +59,8 @@ void KeySequenceWidget::mousePressEvent(QMouseEvent *event) {
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
void KeySequenceWidget::startRecording() {
|
||||
void KeySequenceWidget::startRecording()
|
||||
{
|
||||
keySequence() = KeySequence();
|
||||
setDown(true);
|
||||
setFocus();
|
||||
@ -64,7 +68,8 @@ void KeySequenceWidget::startRecording() {
|
||||
setStatus(Recording);
|
||||
}
|
||||
|
||||
void KeySequenceWidget::stopRecording() {
|
||||
void KeySequenceWidget::stopRecording()
|
||||
{
|
||||
if (!keySequence().valid()) {
|
||||
keySequence() = backupSequence();
|
||||
updateOutput();
|
||||
@ -77,7 +82,8 @@ void KeySequenceWidget::stopRecording() {
|
||||
emit keySequenceChanged();
|
||||
}
|
||||
|
||||
bool KeySequenceWidget::event(QEvent *event) {
|
||||
bool KeySequenceWidget::event(QEvent *event)
|
||||
{
|
||||
if (status() == Recording) {
|
||||
switch (event->type()) {
|
||||
case QEvent::KeyPress:
|
||||
@ -108,7 +114,8 @@ bool KeySequenceWidget::event(QEvent *event) {
|
||||
return QPushButton::event(event);
|
||||
}
|
||||
|
||||
void KeySequenceWidget::keyPressEvent(QKeyEvent *event) {
|
||||
void KeySequenceWidget::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
if (status() == Stopped)
|
||||
@ -120,7 +127,8 @@ void KeySequenceWidget::keyPressEvent(QKeyEvent *event) {
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
void KeySequenceWidget::updateOutput() {
|
||||
void KeySequenceWidget::updateOutput()
|
||||
{
|
||||
QString s;
|
||||
|
||||
if (m_KeySequence.isMouseButton())
|
||||
|
||||
@ -21,7 +21,8 @@
|
||||
|
||||
#include "KeySequence.h"
|
||||
|
||||
class KeySequenceWidget : public QPushButton {
|
||||
class KeySequenceWidget : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -31,21 +32,54 @@ signals:
|
||||
void keySequenceChanged();
|
||||
|
||||
public:
|
||||
const QString &mousePrefix() const { return m_MousePrefix; }
|
||||
const QString &mousePostfix() const { return m_MousePostfix; }
|
||||
const QString &keyPrefix() const { return m_KeyPrefix; }
|
||||
const QString &keyPostfix() const { return m_KeyPostfix; }
|
||||
const QString &mousePrefix() const
|
||||
{
|
||||
return m_MousePrefix;
|
||||
}
|
||||
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 setMousePostfix(const QString &s) { m_MousePostfix = s; }
|
||||
void setKeyPrefix(const QString &s) { m_KeyPrefix = s; }
|
||||
void setKeyPostfix(const QString &s) { m_KeyPostfix = s; }
|
||||
void setMousePrefix(const QString &s)
|
||||
{
|
||||
m_MousePrefix = 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 &backupSequence() const { return m_BackupSequence; }
|
||||
const KeySequence &keySequence() const
|
||||
{
|
||||
return m_KeySequence;
|
||||
}
|
||||
const KeySequence &backupSequence() const
|
||||
{
|
||||
return m_BackupSequence;
|
||||
}
|
||||
void setKeySequence(const KeySequence &seq);
|
||||
|
||||
bool valid() const { return keySequence().valid(); }
|
||||
bool valid() const
|
||||
{
|
||||
return keySequence().valid();
|
||||
}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
@ -55,13 +89,29 @@ protected:
|
||||
void updateOutput();
|
||||
void startRecording();
|
||||
void stopRecording();
|
||||
KeySequence &keySequence() { return m_KeySequence; }
|
||||
KeySequence &backupSequence() { return m_BackupSequence; }
|
||||
KeySequence &keySequence()
|
||||
{
|
||||
return m_KeySequence;
|
||||
}
|
||||
KeySequence &backupSequence()
|
||||
{
|
||||
return m_BackupSequence;
|
||||
}
|
||||
|
||||
private:
|
||||
enum Status { Stopped, Recording };
|
||||
void setStatus(Status s) { m_Status = s; }
|
||||
Status status() const { return m_Status; }
|
||||
enum Status
|
||||
{
|
||||
Stopped,
|
||||
Recording
|
||||
};
|
||||
void setStatus(Status s)
|
||||
{
|
||||
m_Status = s;
|
||||
}
|
||||
Status status() const
|
||||
{
|
||||
return m_Status;
|
||||
}
|
||||
|
||||
private:
|
||||
KeySequence m_KeySequence;
|
||||
|
||||
@ -76,11 +76,11 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
|
||||
m_AppConfig(appConfig),
|
||||
m_ServerConfig(appConfig, *this),
|
||||
m_CoreProcess(appConfig, m_ServerConfig),
|
||||
m_ServerConnection(
|
||||
this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
||||
m_ServerConnection(this, appConfig, m_ServerConfig, m_ServerConfigDialogState),
|
||||
m_ClientConnection(this, appConfig),
|
||||
m_TlsUtility(appConfig),
|
||||
m_WindowSaveTimer(this) {
|
||||
m_WindowSaveTimer(this)
|
||||
{
|
||||
|
||||
setupUi(this);
|
||||
createMenuBar();
|
||||
@ -91,9 +91,13 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig)
|
||||
emit created();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() { m_CoreProcess.cleanup(); }
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
m_CoreProcess.cleanup();
|
||||
}
|
||||
|
||||
void MainWindow::restoreWindow() {
|
||||
void MainWindow::restoreWindow()
|
||||
{
|
||||
|
||||
const auto &windowSize = m_AppConfig.mainWindowSize();
|
||||
if (windowSize.has_value()) {
|
||||
@ -118,7 +122,8 @@ void MainWindow::restoreWindow() {
|
||||
m_SaveWindow = true;
|
||||
}
|
||||
|
||||
void MainWindow::saveWindow() {
|
||||
void MainWindow::saveWindow()
|
||||
{
|
||||
if (!m_SaveWindow) {
|
||||
qDebug("not yet ready to save window size and position, skipping");
|
||||
return;
|
||||
@ -130,7 +135,8 @@ void MainWindow::saveWindow() {
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
void MainWindow::setupControls() {
|
||||
void MainWindow::setupControls()
|
||||
{
|
||||
setWindowTitle(kAppName);
|
||||
|
||||
m_pActionHelp->setText(DESKFLOW_HELP_TEXT);
|
||||
@ -144,8 +150,7 @@ void MainWindow::setupControls() {
|
||||
m_pLabelNotice->setStyleSheet(kStyleNoticeLabel);
|
||||
m_pLabelNotice->hide();
|
||||
|
||||
m_pLabelIpAddresses->setText(
|
||||
QString("This computer's IP addresses: %1").arg(getIPAddresses()));
|
||||
m_pLabelIpAddresses->setText(QString("This computer's IP addresses: %1").arg(getIPAddresses()));
|
||||
|
||||
if (m_AppConfig.lastVersion() != 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
|
||||
// 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.
|
||||
void MainWindow::connectSlots() {
|
||||
void MainWindow::connectSlots()
|
||||
{
|
||||
|
||||
connect(
|
||||
&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::shown, this, &MainWindow::onShown,
|
||||
Qt::QueuedConnection);
|
||||
connect(this, &MainWindow::shown, this, &MainWindow::onShown, Qt::QueuedConnection);
|
||||
|
||||
connect(
|
||||
&m_ConfigScopes, &ConfigScopes::saving, this,
|
||||
&MainWindow::onConfigScopesSaving, Qt::DirectConnection);
|
||||
connect(&m_ConfigScopes, &ConfigScopes::saving, this, &MainWindow::onConfigScopesSaving, Qt::DirectConnection);
|
||||
|
||||
connect(
|
||||
&m_AppConfig, &AppConfig::tlsChanged, this,
|
||||
&MainWindow::onAppConfigTlsChanged);
|
||||
connect(&m_AppConfig, &AppConfig::tlsChanged, this, &MainWindow::onAppConfigTlsChanged);
|
||||
|
||||
connect(
|
||||
&m_AppConfig, &AppConfig::screenNameChanged, this,
|
||||
&MainWindow::onAppConfigScreenNameChanged);
|
||||
connect(&m_AppConfig, &AppConfig::screenNameChanged, this, &MainWindow::onAppConfigScreenNameChanged);
|
||||
|
||||
connect(
|
||||
&m_AppConfig, &AppConfig::invertConnectionChanged, this,
|
||||
&MainWindow::onAppConfigInvertConnection);
|
||||
connect(&m_AppConfig, &AppConfig::invertConnectionChanged, this, &MainWindow::onAppConfigInvertConnection);
|
||||
|
||||
connect(
|
||||
&m_CoreProcess, &CoreProcess::starting, this,
|
||||
&MainWindow::onCoreProcessStarting, Qt::DirectConnection);
|
||||
connect(&m_CoreProcess, &CoreProcess::starting, this, &MainWindow::onCoreProcessStarting, Qt::DirectConnection);
|
||||
|
||||
connect(
|
||||
&m_CoreProcess, &CoreProcess::error, this,
|
||||
&MainWindow::onCoreProcessError);
|
||||
connect(&m_CoreProcess, &CoreProcess::error, this, &MainWindow::onCoreProcessError);
|
||||
|
||||
connect(
|
||||
&m_CoreProcess, &CoreProcess::logLine, //
|
||||
[this](const QString &line) { handleLogLine(line); });
|
||||
[this](const QString &line) { handleLogLine(line); }
|
||||
);
|
||||
|
||||
connect(
|
||||
&m_CoreProcess, &CoreProcess::processStateChanged, this,
|
||||
&MainWindow::onCoreProcessStateChanged);
|
||||
connect(&m_CoreProcess, &CoreProcess::processStateChanged, this, &MainWindow::onCoreProcessStateChanged);
|
||||
|
||||
connect(
|
||||
&m_CoreProcess, &CoreProcess::connectionStateChanged, this,
|
||||
&MainWindow::onCoreConnectionStateChanged);
|
||||
connect(&m_CoreProcess, &CoreProcess::connectionStateChanged, this, &MainWindow::onCoreConnectionStateChanged);
|
||||
|
||||
connect(
|
||||
&m_CoreProcess, &CoreProcess::secureSocket, this,
|
||||
&MainWindow::onCoreProcessSecureSocket);
|
||||
connect(&m_CoreProcess, &CoreProcess::secureSocket, this, &MainWindow::onCoreProcessSecureSocket);
|
||||
|
||||
connect(m_pActionMinimize, &QAction::triggered, this, &MainWindow::hide);
|
||||
|
||||
connect(
|
||||
m_pActionRestore, &QAction::triggered, //
|
||||
[this]() { showAndActivate(); });
|
||||
[this]() { showAndActivate(); }
|
||||
);
|
||||
|
||||
connect(m_pActionQuit, &QAction::triggered, qApp, [this] {
|
||||
qDebug("quitting application");
|
||||
@ -230,38 +219,30 @@ void MainWindow::connectSlots() {
|
||||
QApplication::quit();
|
||||
});
|
||||
|
||||
connect(
|
||||
&m_VersionChecker, &VersionChecker::updateFound, this,
|
||||
&MainWindow::onVersionCheckerUpdateFound);
|
||||
connect(&m_VersionChecker, &VersionChecker::updateFound, this, &MainWindow::onVersionCheckerUpdateFound);
|
||||
|
||||
connect(&m_WindowSaveTimer, &QTimer::timeout, this, &MainWindow::onWindowSaveTimerTimeout);
|
||||
|
||||
connect(&m_TrayIcon, &TrayIcon::activated, this, &MainWindow::onTrayIconActivated);
|
||||
|
||||
connect(
|
||||
&m_WindowSaveTimer, &QTimer::timeout, this,
|
||||
&MainWindow::onWindowSaveTimerTimeout);
|
||||
&m_ServerConnection, &ServerConnection::configureClient, this, &MainWindow::onServerConnectionConfigureClient
|
||||
);
|
||||
|
||||
connect(
|
||||
&m_TrayIcon, &TrayIcon::activated, this,
|
||||
&MainWindow::onTrayIconActivated);
|
||||
connect(&m_ServerConnection, &ServerConnection::messageShowing, this, [this]() { showAndActivate(); });
|
||||
|
||||
connect(
|
||||
&m_ServerConnection, &ServerConnection::configureClient, this,
|
||||
&MainWindow::onServerConnectionConfigureClient);
|
||||
|
||||
connect(
|
||||
&m_ServerConnection, &ServerConnection::messageShowing, this,
|
||||
[this]() { showAndActivate(); });
|
||||
|
||||
connect(
|
||||
&m_ClientConnection, &ClientConnection::messageShowing, this,
|
||||
[this]() { showAndActivate(); });
|
||||
connect(&m_ClientConnection, &ClientConnection::messageShowing, this, [this]() { showAndActivate(); });
|
||||
}
|
||||
|
||||
void MainWindow::onAppAboutToQuit() {
|
||||
void MainWindow::onAppAboutToQuit()
|
||||
{
|
||||
if (m_SaveOnExit) {
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onCreated() {
|
||||
void MainWindow::onCreated()
|
||||
{
|
||||
|
||||
setIcon();
|
||||
|
||||
@ -273,11 +254,11 @@ void MainWindow::onCreated() {
|
||||
applyConfig();
|
||||
restoreWindow();
|
||||
|
||||
qDebug().noquote() << "active settings path:"
|
||||
<< m_ConfigScopes.activeFilePath();
|
||||
qDebug().noquote() << "active settings path:" << m_ConfigScopes.activeFilePath();
|
||||
}
|
||||
|
||||
void MainWindow::onShown() {
|
||||
void MainWindow::onShown()
|
||||
{
|
||||
// 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
|
||||
// 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
|
||||
// hacky and fragile, so maybe there's a better approach.
|
||||
const auto kCriticalDialogDelay = 100;
|
||||
QTimer::singleShot(
|
||||
kCriticalDialogDelay, [] { messages::raiseCriticalDialog(); });
|
||||
QTimer::singleShot(kCriticalDialogDelay, [] { messages::raiseCriticalDialog(); });
|
||||
}
|
||||
|
||||
void MainWindow::onConfigScopesSaving() { m_ServerConfig.commit(); }
|
||||
void MainWindow::onConfigScopesSaving()
|
||||
{
|
||||
m_ServerConfig.commit();
|
||||
}
|
||||
|
||||
void MainWindow::onAppConfigTlsChanged() {
|
||||
void MainWindow::onAppConfigTlsChanged()
|
||||
{
|
||||
updateLocalFingerprint();
|
||||
if (m_TlsUtility.isEnabled()) {
|
||||
m_TlsUtility.generateCertificate();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) {
|
||||
void MainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
|
||||
if (reason == QSystemTrayIcon::DoubleClick) {
|
||||
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 text =
|
||||
QString("A new version is available (v%1). %2").arg(version, link);
|
||||
const auto text = QString("A new version is available (v%1). %2").arg(version, link);
|
||||
|
||||
m_pLabelUpdate->show();
|
||||
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) {
|
||||
QMessageBox::warning(
|
||||
this, QString("Address missing"),
|
||||
QString(
|
||||
"Please enter the hostname or IP address of the other computer."));
|
||||
this, QString("Address missing"), QString("Please enter the hostname or IP address of the other computer.")
|
||||
);
|
||||
} else if (error == CoreProcess::Error::StartFailed) {
|
||||
show();
|
||||
QMessageBox::warning(
|
||||
this, QString("Core cannot be started"),
|
||||
"The Core executable could not be successfully started, "
|
||||
"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_CoreProcess.start();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionStopCore_triggered() {
|
||||
void MainWindow::on_m_pActionStopCore_triggered()
|
||||
{
|
||||
qDebug("stopping core process");
|
||||
m_CoreProcess.stop();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionTestFatalError_triggered() const {
|
||||
void MainWindow::on_m_pActionTestFatalError_triggered() const
|
||||
{
|
||||
qFatal("test fatal error");
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionTestCriticalError_triggered() const {
|
||||
void MainWindow::on_m_pActionTestCriticalError_triggered() const
|
||||
{
|
||||
qCritical("test critical error");
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionClearSettings_triggered() {
|
||||
void MainWindow::on_m_pActionClearSettings_triggered()
|
||||
{
|
||||
if (!messages::showClearSettings(this)) {
|
||||
qDebug("clear settings cancelled");
|
||||
return;
|
||||
@ -370,32 +367,32 @@ void MainWindow::on_m_pActionClearSettings_triggered() {
|
||||
diagnostic::clearSettings(m_ConfigScopes, true);
|
||||
}
|
||||
|
||||
bool MainWindow::on_m_pActionSave_triggered() {
|
||||
QString fileName =
|
||||
QFileDialog::getSaveFileName(this, QString("Save configuration as..."));
|
||||
bool MainWindow::on_m_pActionSave_triggered()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, QString("Save configuration as..."));
|
||||
|
||||
if (!fileName.isEmpty() && !m_ServerConfig.save(fileName)) {
|
||||
QMessageBox::warning(
|
||||
this, QString("Save failed"),
|
||||
QString("Could not save configuration to file."));
|
||||
QMessageBox::warning(this, QString("Save failed"), QString("Could not save configuration to file."));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionAbout_triggered() {
|
||||
void MainWindow::on_m_pActionAbout_triggered()
|
||||
{
|
||||
AboutDialog about(this);
|
||||
about.exec();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionHelp_triggered() const {
|
||||
void MainWindow::on_m_pActionHelp_triggered() const
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl(kUrlHelp));
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pActionSettings_triggered() {
|
||||
auto dialog =
|
||||
SettingsDialog(this, m_AppConfig, m_ServerConfig, m_CoreProcess);
|
||||
void MainWindow::on_m_pActionSettings_triggered()
|
||||
{
|
||||
auto dialog = SettingsDialog(this, m_AppConfig, m_ServerConfig, m_CoreProcess);
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
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();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pLineEditHostname_returnPressed() {
|
||||
void MainWindow::on_m_pLineEditHostname_returnPressed()
|
||||
{
|
||||
m_pButtonConnect->click();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pLineEditClientIp_returnPressed() {
|
||||
void MainWindow::on_m_pLineEditClientIp_returnPressed()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pLineEditClientIp_textChanged(const QString &text) {
|
||||
void MainWindow::on_m_pLineEditClientIp_textChanged(const QString &text)
|
||||
{
|
||||
m_CoreProcess.setAddress(text);
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pButtonApply_clicked() {
|
||||
void MainWindow::on_m_pButtonApply_clicked()
|
||||
{
|
||||
m_ClientConnection.setShowMessage();
|
||||
m_CoreProcess.restart();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pLabelComputerName_linkActivated(const QString &) {
|
||||
void MainWindow::on_m_pLabelComputerName_linkActivated(const QString &)
|
||||
{
|
||||
m_pActionSettings->trigger();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pLabelFingerprint_linkActivated(const QString &) {
|
||||
QMessageBox::information(
|
||||
this, "TLS fingerprint", TlsFingerprint::local().readFirst());
|
||||
void MainWindow::on_m_pLabelFingerprint_linkActivated(const QString &)
|
||||
{
|
||||
QMessageBox::information(this, "TLS fingerprint", TlsFingerprint::local().readFirst());
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pRadioGroupServer_clicked(bool) {
|
||||
void MainWindow::on_m_pRadioGroupServer_clicked(bool)
|
||||
{
|
||||
enableServer(true);
|
||||
enableClient(false);
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pRadioGroupClient_clicked(bool) {
|
||||
void MainWindow::on_m_pRadioGroupClient_clicked(bool)
|
||||
{
|
||||
enableClient(true);
|
||||
enableServer(false);
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
void MainWindow::on_m_pButtonConnect_clicked() { on_m_pButtonApply_clicked(); }
|
||||
|
||||
void MainWindow::on_m_pButtonConnectToClient_clicked() {
|
||||
void MainWindow::on_m_pButtonConnect_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);
|
||||
ServerConfigDialog dialog(this, m_ServerConfig, m_AppConfig);
|
||||
if (dialog.addClient(clientName) && dialog.exec() == QDialog::Accepted) {
|
||||
@ -476,7 +490,8 @@ void MainWindow::onServerConnectionConfigureClient(const QString &clientName) {
|
||||
// End slots
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *event) {
|
||||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QMainWindow::resizeEvent(event);
|
||||
|
||||
// postpone save so that settings are not written every delta change.
|
||||
@ -484,7 +499,8 @@ void MainWindow::resizeEvent(QResizeEvent *event) {
|
||||
m_WindowSaveTimer.start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::moveEvent(QMoveEvent *event) {
|
||||
void MainWindow::moveEvent(QMoveEvent *event)
|
||||
{
|
||||
QMainWindow::moveEvent(event);
|
||||
|
||||
// postpone save so that settings are not written every delta change.
|
||||
@ -492,11 +508,11 @@ void MainWindow::moveEvent(QMoveEvent *event) {
|
||||
m_WindowSaveTimer.start(1000);
|
||||
}
|
||||
|
||||
void MainWindow::open() {
|
||||
void MainWindow::open()
|
||||
{
|
||||
|
||||
std::vector<QAction *> trayMenu = {
|
||||
m_pActionStartCore, m_pActionStopCore, nullptr, m_pActionMinimize,
|
||||
m_pActionRestore, nullptr, m_pActionQuit};
|
||||
std::vector<QAction *> trayMenu = {m_pActionStartCore, m_pActionStopCore, nullptr, m_pActionMinimize,
|
||||
m_pActionRestore, nullptr, m_pActionQuit};
|
||||
|
||||
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 (deskflow::platform::isWayland()) {
|
||||
@ -532,11 +549,13 @@ void MainWindow::onCoreProcessStarting() {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
void MainWindow::setStatus(const QString &status) {
|
||||
void MainWindow::setStatus(const QString &status)
|
||||
{
|
||||
m_pStatusLabel->setText(status);
|
||||
}
|
||||
|
||||
void MainWindow::createMenuBar() {
|
||||
void MainWindow::createMenuBar()
|
||||
{
|
||||
m_pMenuBar = new QMenuBar(this);
|
||||
m_pMenuFile = new QMenu("File", m_pMenuBar);
|
||||
m_pMenuEdit = new QMenu("Edit", m_pMenuBar);
|
||||
@ -569,8 +588,7 @@ void MainWindow::createMenuBar() {
|
||||
|
||||
m_pActionAbout->setText(QString("About %1...").arg(kAppName));
|
||||
|
||||
const auto enableTestMenu =
|
||||
strToTrue(qEnvironmentVariable("DESKFLOW_TEST_MENU"));
|
||||
const auto enableTestMenu = strToTrue(qEnvironmentVariable("DESKFLOW_TEST_MENU"));
|
||||
|
||||
if (enableTestMenu || kDebugBuild) {
|
||||
auto testMenu = new QMenu("Test", m_pMenuBar);
|
||||
@ -582,7 +600,8 @@ void MainWindow::createMenuBar() {
|
||||
setMenuBar(m_pMenuBar);
|
||||
}
|
||||
|
||||
void MainWindow::applyConfig() {
|
||||
void MainWindow::applyConfig()
|
||||
{
|
||||
enableServer(m_AppConfig.serverGroupChecked());
|
||||
enableClient(m_AppConfig.clientGroupChecked());
|
||||
|
||||
@ -590,11 +609,13 @@ void MainWindow::applyConfig() {
|
||||
m_pLineEditClientIp->setText(m_ServerConfig.getClientAddress());
|
||||
}
|
||||
|
||||
void MainWindow::applyCloseToTray() const {
|
||||
void MainWindow::applyCloseToTray() const
|
||||
{
|
||||
QApplication::setQuitOnLastWindowClosed(!m_AppConfig.closeToTray());
|
||||
}
|
||||
|
||||
void MainWindow::saveSettings() {
|
||||
void MainWindow::saveSettings()
|
||||
{
|
||||
m_AppConfig.setServerGroupChecked(m_pRadioGroupServer->isChecked());
|
||||
m_AppConfig.setClientGroupChecked(m_pRadioGroupClient->isChecked());
|
||||
m_AppConfig.setServerHostname(m_pLineEditHostname->text());
|
||||
@ -603,7 +624,8 @@ void MainWindow::saveSettings() {
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
void MainWindow::setIcon() {
|
||||
void MainWindow::setIcon()
|
||||
{
|
||||
QIcon icon;
|
||||
#ifdef Q_OS_MAC
|
||||
switch (getOSXIconsTheme()) {
|
||||
@ -626,14 +648,14 @@ void MainWindow::setIcon() {
|
||||
m_TrayIcon.setIcon(icon);
|
||||
}
|
||||
|
||||
void MainWindow::handleLogLine(const QString &line) {
|
||||
void MainWindow::handleLogLine(const QString &line)
|
||||
{
|
||||
const int kScrollBottomThreshold = 2;
|
||||
|
||||
QScrollBar *verticalScroll = m_pLogOutput->verticalScrollBar();
|
||||
int currentScroll = verticalScroll->value();
|
||||
int maxScroll = verticalScroll->maximum();
|
||||
const auto scrollAtBottom =
|
||||
qAbs(currentScroll - maxScroll) <= kScrollBottomThreshold;
|
||||
const auto scrollAtBottom = qAbs(currentScroll - maxScroll) <= kScrollBottomThreshold;
|
||||
|
||||
// only trim end instead of the whole line to prevent tab-indented debug
|
||||
// filenames from losing their indentation.
|
||||
@ -647,12 +669,14 @@ void MainWindow::handleLogLine(const QString &line) {
|
||||
updateFromLogLine(line);
|
||||
}
|
||||
|
||||
void MainWindow::updateFromLogLine(const QString &line) {
|
||||
void MainWindow::updateFromLogLine(const QString &line)
|
||||
{
|
||||
checkConnected(line);
|
||||
checkFingerprint(line);
|
||||
}
|
||||
|
||||
void MainWindow::checkConnected(const QString &line) {
|
||||
void MainWindow::checkConnected(const QString &line)
|
||||
{
|
||||
if (m_pRadioGroupServer->isChecked()) {
|
||||
m_ServerConnection.handleLogLine(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:]+)");
|
||||
auto match = re.match(line);
|
||||
if (!match.hasMatch()) {
|
||||
@ -682,17 +707,17 @@ void MainWindow::checkFingerprint(const QString &line) {
|
||||
messageBoxAlreadyShown = true;
|
||||
QMessageBox::StandardButton fingerprintReply = QMessageBox::information(
|
||||
this, QString("Security question"),
|
||||
QString(
|
||||
"<p>You are connecting to a server.</p>"
|
||||
"<p>Here is it's TLS fingerprint:</p>"
|
||||
"<p>%1</p>"
|
||||
"<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 "
|
||||
"you're expecting (it could be a malicious user).</p>"
|
||||
"<p>Do you want to trust this fingerprint for future "
|
||||
"connections? If you don't, a connection cannot be made.</p>")
|
||||
QString("<p>You are connecting to a server.</p>"
|
||||
"<p>Here is it's TLS fingerprint:</p>"
|
||||
"<p>%1</p>"
|
||||
"<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 "
|
||||
"you're expecting (it could be a malicious user).</p>"
|
||||
"<p>Do you want to trust this fingerprint for future "
|
||||
"connections? If you don't, a connection cannot be made.</p>")
|
||||
.arg(fingerprint),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
QMessageBox::Yes | QMessageBox::No
|
||||
);
|
||||
|
||||
if (fingerprintReply == QMessageBox::Yes) {
|
||||
// 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();
|
||||
return '[' + current.toString(Qt::ISODate) + ']';
|
||||
}
|
||||
|
||||
void MainWindow::showEvent(QShowEvent *event) {
|
||||
void MainWindow::showEvent(QShowEvent *event)
|
||||
{
|
||||
QMainWindow::showEvent(event);
|
||||
emit shown();
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (m_Quitting) {
|
||||
qDebug("skipping close event handle on quit");
|
||||
return;
|
||||
@ -734,7 +762,8 @@ void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
qDebug("window should hide to tray");
|
||||
}
|
||||
|
||||
void MainWindow::showFirstConnectedMessage() {
|
||||
void MainWindow::showFirstConnectedMessage()
|
||||
{
|
||||
if (m_AppConfig.startedBefore()) {
|
||||
return;
|
||||
}
|
||||
@ -743,11 +772,11 @@ void MainWindow::showFirstConnectedMessage() {
|
||||
m_ConfigScopes.save();
|
||||
|
||||
const auto isServer = m_CoreProcess.mode() == CoreMode::Server;
|
||||
messages::showFirstConnectedMessage(
|
||||
this, m_AppConfig.closeToTray(), m_AppConfig.enableService(), isServer);
|
||||
messages::showFirstConnectedMessage(this, m_AppConfig.closeToTray(), m_AppConfig.enableService(), isServer);
|
||||
}
|
||||
|
||||
void MainWindow::showDevThanksMessage() {
|
||||
void MainWindow::showDevThanksMessage()
|
||||
{
|
||||
if (!m_AppConfig.showDevThanks()) {
|
||||
qDebug("skipping dev thanks message");
|
||||
return;
|
||||
@ -759,11 +788,13 @@ void MainWindow::showDevThanksMessage() {
|
||||
messages::showDevThanks(this, kAppName);
|
||||
}
|
||||
|
||||
void MainWindow::onCoreProcessSecureSocket(bool enabled) {
|
||||
void MainWindow::onCoreProcessSecureSocket(bool enabled)
|
||||
{
|
||||
secureSocket(enabled);
|
||||
}
|
||||
|
||||
void MainWindow::updateStatus() {
|
||||
void MainWindow::updateStatus()
|
||||
{
|
||||
const auto connection = m_CoreProcess.connectionState();
|
||||
const auto process = m_CoreProcess.processState();
|
||||
|
||||
@ -804,11 +835,9 @@ void MainWindow::updateStatus() {
|
||||
|
||||
case Connected: {
|
||||
if (m_SecureSocket) {
|
||||
setStatus(QString("%1 is connected (with %2)")
|
||||
.arg(kAppName, m_CoreProcess.secureSocketVersion()));
|
||||
setStatus(QString("%1 is connected (with %2)").arg(kAppName, m_CoreProcess.secureSocketVersion()));
|
||||
} else {
|
||||
setStatus(
|
||||
QString("%1 is connected (without TLS encryption)").arg(kAppName));
|
||||
setStatus(QString("%1 is connected (without TLS encryption)").arg(kAppName));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -821,7 +850,8 @@ void MainWindow::updateStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
||||
void MainWindow::onCoreProcessStateChanged(CoreProcessState state)
|
||||
{
|
||||
updateStatus();
|
||||
|
||||
if (state == CoreProcessState::Started) {
|
||||
@ -830,15 +860,10 @@ void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
||||
m_ConfigScopes.save();
|
||||
}
|
||||
|
||||
if (state == CoreProcessState::Started ||
|
||||
state == CoreProcessState::Starting ||
|
||||
if (state == CoreProcessState::Started || state == CoreProcessState::Starting ||
|
||||
state == CoreProcessState::RetryPending) {
|
||||
disconnect(
|
||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore,
|
||||
&QAction::trigger);
|
||||
connect(
|
||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore,
|
||||
&QAction::trigger);
|
||||
disconnect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore, &QAction::trigger);
|
||||
connect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore, &QAction::trigger);
|
||||
|
||||
m_pButtonToggleStart->setText(QString("&Stop"));
|
||||
m_pButtonApply->setEnabled(true);
|
||||
@ -847,12 +872,8 @@ void MainWindow::onCoreProcessStateChanged(CoreProcessState state) {
|
||||
m_pActionStopCore->setEnabled(true);
|
||||
|
||||
} else {
|
||||
disconnect(
|
||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore,
|
||||
&QAction::trigger);
|
||||
connect(
|
||||
m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore,
|
||||
&QAction::trigger);
|
||||
disconnect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStopCore, &QAction::trigger);
|
||||
connect(m_pButtonToggleStart, &QPushButton::clicked, m_pActionStartCore, &QAction::trigger);
|
||||
|
||||
m_pButtonToggleStart->setText(QString("&Start"));
|
||||
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));
|
||||
|
||||
updateStatus();
|
||||
@ -878,7 +900,8 @@ void MainWindow::onCoreConnectionStateChanged(CoreConnectionState state) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setVisible(bool visible) {
|
||||
void MainWindow::setVisible(bool visible)
|
||||
{
|
||||
QMainWindow::setVisible(visible);
|
||||
m_pActionMinimize->setEnabled(visible);
|
||||
m_pActionRestore->setEnabled(!visible);
|
||||
@ -897,15 +920,15 @@ void MainWindow::setVisible(bool visible) {
|
||||
#endif
|
||||
}
|
||||
|
||||
QString MainWindow::getIPAddresses() const {
|
||||
QString MainWindow::getIPAddresses() const
|
||||
{
|
||||
QStringList result;
|
||||
bool hinted = false;
|
||||
const auto localnet = QHostAddress::parseSubnet("192.168.0.0/16");
|
||||
const QList<QHostAddress> addresses = QNetworkInterface::allAddresses();
|
||||
|
||||
for (const auto &address : addresses) {
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
|
||||
address != QHostAddress(QHostAddress::LocalHost) &&
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost) &&
|
||||
!address.isInSubnet(QHostAddress::parseSubnet("169.254.0.0/16"))) {
|
||||
|
||||
// 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(", ");
|
||||
}
|
||||
|
||||
void MainWindow::updateLocalFingerprint() {
|
||||
void MainWindow::updateLocalFingerprint()
|
||||
{
|
||||
bool fingerprintExists = false;
|
||||
try {
|
||||
fingerprintExists = TlsFingerprint::local().fileExists();
|
||||
@ -936,22 +960,21 @@ void MainWindow::updateLocalFingerprint() {
|
||||
qFatal("failed to check if fingerprint exists");
|
||||
}
|
||||
|
||||
if (m_AppConfig.tlsEnabled() && fingerprintExists &&
|
||||
m_pRadioGroupServer->isChecked()) {
|
||||
if (m_AppConfig.tlsEnabled() && fingerprintExists && m_pRadioGroupServer->isChecked()) {
|
||||
m_pLabelFingerprint->setVisible(true);
|
||||
} else {
|
||||
m_pLabelFingerprint->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::autoAddScreen(const QString name) {
|
||||
void MainWindow::autoAddScreen(const QString name)
|
||||
{
|
||||
|
||||
int r = m_ServerConfig.autoAddScreen(name);
|
||||
if (r != kAutoAddScreenOk) {
|
||||
switch (r) {
|
||||
case kAutoAddScreenManualServer:
|
||||
showConfigureServer(QString("Please add the server (%1) to the grid.")
|
||||
.arg(m_AppConfig.screenName()));
|
||||
showConfigureServer(QString("Please add the server (%1) to the grid.").arg(m_AppConfig.screenName()));
|
||||
break;
|
||||
|
||||
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);
|
||||
dialog.message(message);
|
||||
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;
|
||||
if (secureSocket) {
|
||||
m_pLabelPadlock->show();
|
||||
@ -980,16 +1005,17 @@ void MainWindow::secureSocket(bool secureSocket) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateScreenName() {
|
||||
m_pLabelComputerName->setText(
|
||||
QString("This computer's name: %1 "
|
||||
R"((<a href="#" style="color: %2">change</a>))")
|
||||
.arg(m_AppConfig.screenName())
|
||||
.arg(kColorSecondary));
|
||||
void MainWindow::updateScreenName()
|
||||
{
|
||||
m_pLabelComputerName->setText(QString("This computer's name: %1 "
|
||||
R"((<a href="#" style="color: %2">change</a>))")
|
||||
.arg(m_AppConfig.screenName())
|
||||
.arg(kColorSecondary));
|
||||
m_ServerConfig.updateServerName();
|
||||
}
|
||||
|
||||
void MainWindow::enableServer(bool enable) {
|
||||
void MainWindow::enableServer(bool enable)
|
||||
{
|
||||
qDebug(enable ? "server enabled" : "server disabled");
|
||||
m_AppConfig.setServerGroupChecked(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");
|
||||
m_AppConfig.setClientGroupChecked(enable);
|
||||
m_pRadioGroupClient->setChecked(enable);
|
||||
@ -1026,7 +1053,8 @@ void MainWindow::enableClient(bool enable) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::showAndActivate() {
|
||||
void MainWindow::showAndActivate()
|
||||
{
|
||||
if (!isMinimized() && !isHidden()) {
|
||||
qDebug("window already visible");
|
||||
return;
|
||||
|
||||
@ -55,7 +55,8 @@ class QAbstractButton;
|
||||
class DeskflowApplication;
|
||||
class SetupWizard;
|
||||
|
||||
class MainWindow : public QMainWindow, public Ui::MainWindowBase {
|
||||
class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
||||
{
|
||||
using CoreMode = deskflow::gui::CoreProcess::Mode;
|
||||
using CoreProcess = deskflow::gui::CoreProcess;
|
||||
|
||||
@ -66,18 +67,27 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase {
|
||||
friend class SettingsDialog;
|
||||
|
||||
public:
|
||||
enum class LogLevel { Error, Info };
|
||||
enum class LogLevel
|
||||
{
|
||||
Error,
|
||||
Info
|
||||
};
|
||||
|
||||
public:
|
||||
explicit MainWindow(
|
||||
deskflow::gui::ConfigScopes &configScopes, AppConfig &appConfig);
|
||||
explicit MainWindow(deskflow::gui::ConfigScopes &configScopes, AppConfig &appConfig);
|
||||
~MainWindow() override;
|
||||
|
||||
void setVisible(bool visible) override;
|
||||
CoreMode coreMode() const { return m_CoreProcess.mode(); }
|
||||
CoreMode coreMode() const
|
||||
{
|
||||
return m_CoreProcess.mode();
|
||||
}
|
||||
QString address() const;
|
||||
void open();
|
||||
ServerConfig &serverConfig() { return m_ServerConfig; }
|
||||
ServerConfig &serverConfig()
|
||||
{
|
||||
return m_ServerConfig;
|
||||
}
|
||||
void autoAddScreen(const QString name);
|
||||
|
||||
signals:
|
||||
@ -133,8 +143,14 @@ private slots:
|
||||
void on_m_pLineEditClientIp_textChanged(const QString &text);
|
||||
|
||||
private:
|
||||
AppConfig &appConfig() { return m_AppConfig; }
|
||||
AppConfig const &appConfig() const { return m_AppConfig; }
|
||||
AppConfig &appConfig()
|
||||
{
|
||||
return m_AppConfig;
|
||||
}
|
||||
AppConfig const &appConfig() const
|
||||
{
|
||||
return m_AppConfig;
|
||||
}
|
||||
void createMenuBar();
|
||||
void createStatusBar();
|
||||
void createTrayIcon();
|
||||
@ -163,7 +179,10 @@ private:
|
||||
void saveSettings();
|
||||
QString configFilename();
|
||||
void showConfigureServer(const QString &message);
|
||||
void showConfigureServer() { showConfigureServer(""); }
|
||||
void showConfigureServer()
|
||||
{
|
||||
showConfigureServer("");
|
||||
}
|
||||
void restoreWindow();
|
||||
void saveWindow();
|
||||
void setupControls();
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
enum qProcessorArch {
|
||||
enum qProcessorArch
|
||||
{
|
||||
kProcessorArchWin32,
|
||||
kProcessorArchWin64,
|
||||
kProcessorArchMac32,
|
||||
|
||||
@ -29,7 +29,8 @@
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData) {
|
||||
void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData)
|
||||
{
|
||||
for (int i = 0; i < comboBox->count(); ++i) {
|
||||
if (comboBox->itemData(i) == itemData) {
|
||||
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 hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
|
||||
return hash.toHex();
|
||||
}
|
||||
|
||||
qProcessorArch getProcessorArch() {
|
||||
qProcessorArch getProcessorArch()
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
SYSTEM_INFO systemInfo;
|
||||
GetNativeSystemInfo(&systemInfo);
|
||||
|
||||
@ -33,11 +33,11 @@ using enum ScreenConfig::Modifier;
|
||||
using enum ScreenConfig::SwitchCorner;
|
||||
using enum ScreenConfig::Fix;
|
||||
|
||||
ScreenSettingsDialog::ScreenSettingsDialog(
|
||||
QWidget *parent, Screen *pScreen, const ScreenList *pScreens)
|
||||
ScreenSettingsDialog::ScreenSettingsDialog(QWidget *parent, Screen *pScreen, const ScreenList *pScreens)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
Ui::ScreenSettingsDialogBase(),
|
||||
m_pScreen(pScreen) {
|
||||
m_pScreen(pScreen)
|
||||
{
|
||||
|
||||
setupUi(this);
|
||||
|
||||
@ -46,33 +46,27 @@ ScreenSettingsDialog::ScreenSettingsDialog(
|
||||
|
||||
m_pLineEditName->setText(m_pScreen->name());
|
||||
m_pLineEditName->setValidator(new validators::ScreenNameValidator(
|
||||
m_pLineEditName, new validators::ValidationError(this, m_pLabelNameError),
|
||||
pScreens));
|
||||
m_pLineEditName, new validators::ValidationError(this, m_pLabelNameError), pScreens
|
||||
));
|
||||
m_pLineEditName->selectAll();
|
||||
|
||||
m_pLineEditAlias->setValidator(new validators::AliasValidator(
|
||||
m_pLineEditAlias,
|
||||
new validators::ValidationError(this, m_pLabelAliasError)));
|
||||
m_pLineEditAlias->setValidator(
|
||||
new validators::AliasValidator(m_pLineEditAlias, new validators::ValidationError(this, m_pLabelAliasError))
|
||||
);
|
||||
|
||||
for (int i = 0; i < m_pScreen->aliases().count(); i++)
|
||||
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);
|
||||
|
||||
m_pComboBoxShift->setCurrentIndex(
|
||||
m_pScreen->modifier(static_cast<int>(Shift)));
|
||||
m_pComboBoxShift->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Shift)));
|
||||
m_pComboBoxCtrl->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Ctrl)));
|
||||
m_pComboBoxAlt->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Alt)));
|
||||
m_pComboBoxMeta->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Meta)));
|
||||
m_pComboBoxSuper->setCurrentIndex(
|
||||
m_pScreen->modifier(static_cast<int>(Super)));
|
||||
m_pComboBoxSuper->setCurrentIndex(m_pScreen->modifier(static_cast<int>(Super)));
|
||||
|
||||
m_pCheckBoxCornerTopLeft->setChecked(
|
||||
m_pScreen->switchCorner(static_cast<int>(TopLeft)));
|
||||
m_pCheckBoxCornerTopRight->setChecked(
|
||||
m_pScreen->switchCorner(static_cast<int>(TopRight)));
|
||||
m_pCheckBoxCornerBottomLeft->setChecked(
|
||||
m_pScreen->switchCorner(static_cast<int>(BottomLeft)));
|
||||
m_pCheckBoxCornerBottomRight->setChecked(
|
||||
m_pScreen->switchCorner(static_cast<int>(BottomRight)));
|
||||
m_pCheckBoxCornerTopLeft->setChecked(m_pScreen->switchCorner(static_cast<int>(TopLeft)));
|
||||
m_pCheckBoxCornerTopRight->setChecked(m_pScreen->switchCorner(static_cast<int>(TopRight)));
|
||||
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_pCheckBoxCapsLock->setChecked(m_pScreen->fix(CapsLock));
|
||||
@ -81,12 +75,14 @@ ScreenSettingsDialog::ScreenSettingsDialog(
|
||||
m_pCheckBoxXTest->setChecked(m_pScreen->fix(XTest));
|
||||
}
|
||||
|
||||
void ScreenSettingsDialog::accept() {
|
||||
void ScreenSettingsDialog::accept()
|
||||
{
|
||||
if (m_pLineEditName->text().isEmpty()) {
|
||||
QMessageBox::warning(
|
||||
this, tr("Screen name is 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;
|
||||
} else if (!m_pLabelNameError->text().isEmpty()) {
|
||||
return;
|
||||
@ -102,64 +98,56 @@ void ScreenSettingsDialog::accept() {
|
||||
QMessageBox::warning(
|
||||
this, tr("Screen name matches 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;
|
||||
}
|
||||
m_pScreen->addAlias(alias);
|
||||
}
|
||||
|
||||
m_pScreen->setModifier(
|
||||
static_cast<int>(Shift), m_pComboBoxShift->currentIndex());
|
||||
m_pScreen->setModifier(
|
||||
static_cast<int>(Ctrl), m_pComboBoxCtrl->currentIndex());
|
||||
m_pScreen->setModifier(static_cast<int>(Shift), m_pComboBoxShift->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>(Meta), m_pComboBoxMeta->currentIndex());
|
||||
m_pScreen->setModifier(
|
||||
static_cast<int>(Super), m_pComboBoxSuper->currentIndex());
|
||||
m_pScreen->setModifier(static_cast<int>(Meta), m_pComboBoxMeta->currentIndex());
|
||||
m_pScreen->setModifier(static_cast<int>(Super), m_pComboBoxSuper->currentIndex());
|
||||
|
||||
m_pScreen->setSwitchCorner(
|
||||
static_cast<int>(TopLeft), m_pCheckBoxCornerTopLeft->isChecked());
|
||||
m_pScreen->setSwitchCorner(
|
||||
static_cast<int>(TopRight), m_pCheckBoxCornerTopRight->isChecked());
|
||||
m_pScreen->setSwitchCorner(
|
||||
static_cast<int>(BottomLeft), m_pCheckBoxCornerBottomLeft->isChecked());
|
||||
m_pScreen->setSwitchCorner(
|
||||
static_cast<int>(BottomRight), m_pCheckBoxCornerBottomRight->isChecked());
|
||||
m_pScreen->setSwitchCorner(static_cast<int>(TopLeft), m_pCheckBoxCornerTopLeft->isChecked());
|
||||
m_pScreen->setSwitchCorner(static_cast<int>(TopRight), m_pCheckBoxCornerTopRight->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->setFix(
|
||||
static_cast<int>(CapsLock), m_pCheckBoxCapsLock->isChecked());
|
||||
m_pScreen->setFix(static_cast<int>(CapsLock), m_pCheckBoxCapsLock->isChecked());
|
||||
m_pScreen->setFix(static_cast<int>(NumLock), m_pCheckBoxNumLock->isChecked());
|
||||
m_pScreen->setFix(
|
||||
static_cast<int>(ScrollLock), m_pCheckBoxScrollLock->isChecked());
|
||||
m_pScreen->setFix(static_cast<int>(ScrollLock), m_pCheckBoxScrollLock->isChecked());
|
||||
m_pScreen->setFix(static_cast<int>(XTest), m_pCheckBoxXTest->isChecked());
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void ScreenSettingsDialog::on_m_pButtonAddAlias_clicked() {
|
||||
void ScreenSettingsDialog::on_m_pButtonAddAlias_clicked()
|
||||
{
|
||||
if (!m_pLineEditAlias->text().isEmpty() &&
|
||||
m_pListAliases->findItems(m_pLineEditAlias->text(), Qt::MatchFixedString)
|
||||
.isEmpty()) {
|
||||
m_pListAliases->findItems(m_pLineEditAlias->text(), Qt::MatchFixedString).isEmpty()) {
|
||||
new QListWidgetItem(m_pLineEditAlias->text(), m_pListAliases);
|
||||
m_pLineEditAlias->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(
|
||||
const QString &text) {
|
||||
m_pButtonAddAlias->setEnabled(
|
||||
!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
|
||||
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(const QString &text)
|
||||
{
|
||||
m_pButtonAddAlias->setEnabled(!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
|
||||
}
|
||||
|
||||
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked() {
|
||||
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked()
|
||||
{
|
||||
QList<QListWidgetItem *> items = m_pListAliases->selectedItems();
|
||||
|
||||
for (int i = 0; i < items.count(); i++)
|
||||
delete items[i];
|
||||
}
|
||||
|
||||
void ScreenSettingsDialog::on_m_pListAliases_itemSelectionChanged() {
|
||||
void ScreenSettingsDialog::on_m_pListAliases_itemSelectionChanged()
|
||||
{
|
||||
m_pButtonRemoveAlias->setEnabled(!m_pListAliases->selectedItems().isEmpty());
|
||||
}
|
||||
|
||||
@ -28,14 +28,12 @@ class QString;
|
||||
class Screen;
|
||||
class ScreenList;
|
||||
|
||||
class ScreenSettingsDialog : public QDialog,
|
||||
public Ui::ScreenSettingsDialogBase {
|
||||
class ScreenSettingsDialog : public QDialog, public Ui::ScreenSettingsDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScreenSettingsDialog(
|
||||
QWidget *parent, Screen *pScreen = nullptr,
|
||||
const ScreenList *pScreens = nullptr);
|
||||
ScreenSettingsDialog(QWidget *parent, Screen *pScreen = nullptr, const ScreenList *pScreens = nullptr);
|
||||
|
||||
public slots:
|
||||
void accept();
|
||||
|
||||
@ -23,35 +23,30 @@
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
const QString ScreenSetupModel::m_MimeType =
|
||||
"application/x-" DESKFLOW_APP_ID "-screen";
|
||||
const QString ScreenSetupModel::m_MimeType = "application/x-" DESKFLOW_APP_ID "-screen";
|
||||
|
||||
ScreenSetupModel::ScreenSetupModel(
|
||||
ScreenList &screens, int numColumns, int numRows)
|
||||
ScreenSetupModel::ScreenSetupModel(ScreenList &screens, int numColumns, int numRows)
|
||||
: QAbstractTableModel(NULL),
|
||||
m_Screens(screens),
|
||||
m_NumColumns(numColumns),
|
||||
m_NumRows(numRows) {
|
||||
m_NumRows(numRows)
|
||||
{
|
||||
|
||||
// bound rows and columns to prevent multiply overflow.
|
||||
// this is unlikely to happen, as the grid size is only 3x9.
|
||||
if (m_NumColumns > 100 || m_NumRows > 100) {
|
||||
qFatal(
|
||||
"grid size out of bounds: %d columns x %d rows", m_NumColumns,
|
||||
m_NumRows);
|
||||
qFatal("grid size out of bounds: %d columns x %d rows", m_NumColumns, m_NumRows);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_NumColumns * m_NumRows > screens.size()) {
|
||||
qFatal(
|
||||
"scrren list (%lld) too small for %d columns x %d rows", screens.size(),
|
||||
m_NumColumns, m_NumRows);
|
||||
qFatal("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 {
|
||||
if (index.isValid() && index.row() < m_NumRows &&
|
||||
index.column() < m_NumColumns) {
|
||||
QVariant ScreenSetupModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (index.isValid() && index.row() < m_NumRows && index.column() < m_NumColumns) {
|
||||
switch (role) {
|
||||
case Qt::DecorationRole:
|
||||
if (screen(index).isNull())
|
||||
@ -76,27 +71,29 @@ QVariant ScreenSetupModel::data(const QModelIndex &index, int role) const {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags ScreenSetupModel::flags(const QModelIndex &index) const {
|
||||
if (!index.isValid() || index.row() >= m_NumRows ||
|
||||
index.column() >= m_NumColumns)
|
||||
Qt::ItemFlags ScreenSetupModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_NumRows || index.column() >= m_NumColumns)
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
if (!screen(index).isNull())
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable |
|
||||
Qt::ItemIsDropEnabled;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
|
||||
|
||||
return Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
Qt::DropActions ScreenSetupModel::supportedDropActions() const {
|
||||
Qt::DropActions ScreenSetupModel::supportedDropActions() const
|
||||
{
|
||||
return Qt::MoveAction | Qt::CopyAction;
|
||||
}
|
||||
|
||||
QStringList ScreenSetupModel::mimeTypes() const {
|
||||
QStringList ScreenSetupModel::mimeTypes() const
|
||||
{
|
||||
return QStringList() << m_MimeType;
|
||||
}
|
||||
|
||||
QMimeData *ScreenSetupModel::mimeData(const QModelIndexList &indexes) const {
|
||||
QMimeData *ScreenSetupModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
QMimeData *pMimeData = new QMimeData();
|
||||
QByteArray encodedData;
|
||||
|
||||
@ -112,8 +109,9 @@ QMimeData *ScreenSetupModel::mimeData(const QModelIndexList &indexes) const {
|
||||
}
|
||||
|
||||
bool ScreenSetupModel::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 QModelIndex &parent
|
||||
)
|
||||
{
|
||||
if (action == Qt::IgnoreAction)
|
||||
return true;
|
||||
|
||||
@ -154,15 +152,16 @@ bool ScreenSetupModel::dropMimeData(
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenSetupModel::addScreen(const Screen &newScreen) {
|
||||
void ScreenSetupModel::addScreen(const Screen &newScreen)
|
||||
{
|
||||
m_Screens.addScreenByPriority(newScreen);
|
||||
emit screensChanged();
|
||||
}
|
||||
|
||||
bool ScreenSetupModel::isFull() const {
|
||||
auto emptyScreen = std::find_if(
|
||||
m_Screens.cbegin(), m_Screens.cend(),
|
||||
[](const Screen &item) { return item.isNull(); });
|
||||
bool ScreenSetupModel::isFull() const
|
||||
{
|
||||
auto emptyScreen =
|
||||
std::find_if(m_Screens.cbegin(), m_Screens.cend(), [](const Screen &item) { return item.isNull(); });
|
||||
|
||||
return (emptyScreen == m_Screens.cend());
|
||||
}
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
class ScreenSetupView;
|
||||
class ServerConfigDialog;
|
||||
|
||||
class ScreenSetupModel : public QAbstractTableModel {
|
||||
class ScreenSetupModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
friend class ScreenSetupView;
|
||||
@ -38,12 +39,27 @@ public:
|
||||
ScreenSetupModel(ScreenList &screens, int numColumns, int numRows);
|
||||
|
||||
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;
|
||||
int rowCount() const { return m_NumRows; }
|
||||
int columnCount() const { return m_NumColumns; }
|
||||
int rowCount(const QModelIndex &) const { return rowCount(); }
|
||||
int columnCount(const QModelIndex &) const { return columnCount(); }
|
||||
int rowCount() const
|
||||
{
|
||||
return m_NumRows;
|
||||
}
|
||||
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::ItemFlags flags(const QModelIndex &index) const;
|
||||
QStringList mimeTypes() const;
|
||||
@ -54,19 +70,21 @@ signals:
|
||||
void screensChanged();
|
||||
|
||||
protected:
|
||||
bool dropMimeData(
|
||||
const QMimeData *data, Qt::DropAction action, int row, int column,
|
||||
const QModelIndex &parent);
|
||||
const Screen &screen(const QModelIndex &index) const {
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
||||
const Screen &screen(const QModelIndex &index) const
|
||||
{
|
||||
return screen(index.column(), index.row());
|
||||
}
|
||||
Screen &screen(const QModelIndex &index) {
|
||||
Screen &screen(const QModelIndex &index)
|
||||
{
|
||||
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];
|
||||
}
|
||||
Screen &screen(int column, int row) {
|
||||
Screen &screen(int column, int row)
|
||||
{
|
||||
return m_Screens[row * m_NumColumns + column];
|
||||
}
|
||||
void addScreen(const Screen &newScreen);
|
||||
|
||||
@ -25,7 +25,8 @@
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
ScreenSetupView::ScreenSetupView(QWidget *parent) : QTableView(parent) {
|
||||
ScreenSetupView::ScreenSetupView(QWidget *parent) : QTableView(parent)
|
||||
{
|
||||
setDropIndicatorShown(true);
|
||||
setDragDropMode(DragDrop);
|
||||
setSelectionMode(SingleSelection);
|
||||
@ -38,16 +39,19 @@ ScreenSetupView::ScreenSetupView(QWidget *parent) : QTableView(parent) {
|
||||
verticalHeader()->hide();
|
||||
}
|
||||
|
||||
void ScreenSetupView::setModel(QAbstractItemModel *model) {
|
||||
void ScreenSetupView::setModel(QAbstractItemModel *model)
|
||||
{
|
||||
QTableView::setModel(model);
|
||||
setTableSize();
|
||||
}
|
||||
|
||||
ScreenSetupModel *ScreenSetupView::model() const {
|
||||
ScreenSetupModel *ScreenSetupView::model() const
|
||||
{
|
||||
return qobject_cast<ScreenSetupModel *>(QTableView::model());
|
||||
}
|
||||
|
||||
void ScreenSetupView::setTableSize() {
|
||||
void ScreenSetupView::setTableSize()
|
||||
{
|
||||
for (int i = 0; i < model()->columnCount(); i++)
|
||||
setColumnWidth(i, width() / model()->columnCount());
|
||||
|
||||
@ -55,19 +59,20 @@ void ScreenSetupView::setTableSize() {
|
||||
setRowHeight(i, height() / model()->rowCount());
|
||||
}
|
||||
|
||||
void ScreenSetupView::resizeEvent(QResizeEvent *event) {
|
||||
void ScreenSetupView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
setTableSize();
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent *event) {
|
||||
void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
int col = columnAt(event->pos().x());
|
||||
int row = rowAt(event->pos().y());
|
||||
|
||||
if (!model()->screen(col, row).isNull()) {
|
||||
ScreenSettingsDialog dlg(
|
||||
this, &model()->screen(col, row), &model()->m_Screens);
|
||||
ScreenSettingsDialog dlg(this, &model()->screen(col, row), &model()->m_Screens);
|
||||
dlg.exec();
|
||||
emit model() -> screensChanged();
|
||||
}
|
||||
@ -75,7 +80,8 @@ void ScreenSetupView::mouseDoubleClickEvent(QMouseEvent *event) {
|
||||
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
|
||||
// mime type is okay. anything else is dealt with in dragMoveEvent()
|
||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType()))
|
||||
@ -84,7 +90,8 @@ void ScreenSetupView::dragEnterEvent(QDragEnterEvent *event) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void ScreenSetupView::dragMoveEvent(QDragMoveEvent *event) {
|
||||
void ScreenSetupView::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
||||
// where does the event come from? myself or someone else?
|
||||
if (event->source() == this) {
|
||||
@ -107,7 +114,8 @@ void ScreenSetupView::dragMoveEvent(QDragMoveEvent *event) {
|
||||
}
|
||||
|
||||
// this is reimplemented from QAbstractItemView::startDrag()
|
||||
void ScreenSetupView::startDrag(Qt::DropActions) {
|
||||
void ScreenSetupView::startDrag(Qt::DropActions)
|
||||
{
|
||||
QModelIndexList indexes = selectedIndexes();
|
||||
|
||||
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->decorationPosition = QStyleOptionViewItem::Top;
|
||||
option->displayAlignment = Qt::AlignCenter;
|
||||
|
||||
@ -29,7 +29,8 @@ class QResizeEvent;
|
||||
class QDragEnterEvent;
|
||||
class ScreenSetupModel;
|
||||
|
||||
class ScreenSetupView : public QTableView {
|
||||
class ScreenSetupView : public QTableView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -47,5 +48,7 @@ protected:
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void startDrag(Qt::DropActions supportedActions) 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::Fix;
|
||||
|
||||
static const struct {
|
||||
static const struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
const char *name;
|
||||
@ -46,18 +47,19 @@ static const struct {
|
||||
|
||||
const int serverDefaultIndex = 7;
|
||||
|
||||
ServerConfig::ServerConfig(
|
||||
AppConfig &appConfig, MainWindow &mainWindow, int columns, int rows)
|
||||
ServerConfig::ServerConfig(AppConfig &appConfig, MainWindow &mainWindow, int columns, int rows)
|
||||
: m_pAppConfig(&appConfig),
|
||||
m_pMainWindow(&mainWindow),
|
||||
m_Screens(columns),
|
||||
m_Columns(columns),
|
||||
m_Rows(rows),
|
||||
m_ClipboardSharingSize(defaultClipboardSharingSize()) {
|
||||
m_ClipboardSharingSize(defaultClipboardSharingSize())
|
||||
{
|
||||
recall();
|
||||
}
|
||||
|
||||
bool ServerConfig::save(const QString &fileName) const {
|
||||
bool ServerConfig::save(const QString &fileName) const
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return false;
|
||||
@ -68,32 +70,28 @@ bool ServerConfig::save(const QString &fileName) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
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 &&
|
||||
m_Heartbeat == sc.m_Heartbeat &&
|
||||
m_RelativeMouseMoves == sc.m_RelativeMouseMoves &&
|
||||
m_Win32KeepForeground == sc.m_Win32KeepForeground &&
|
||||
m_HasSwitchDelay == sc.m_HasSwitchDelay &&
|
||||
m_SwitchDelay == sc.m_SwitchDelay &&
|
||||
m_HasSwitchDoubleTap == sc.m_HasSwitchDoubleTap &&
|
||||
m_SwitchDoubleTap == sc.m_SwitchDoubleTap &&
|
||||
m_SwitchCornerSize == sc.m_SwitchCornerSize &&
|
||||
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 &&
|
||||
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 && m_Heartbeat == sc.m_Heartbeat &&
|
||||
m_RelativeMouseMoves == sc.m_RelativeMouseMoves && m_Win32KeepForeground == sc.m_Win32KeepForeground &&
|
||||
m_HasSwitchDelay == sc.m_HasSwitchDelay && m_SwitchDelay == sc.m_SwitchDelay &&
|
||||
m_HasSwitchDoubleTap == sc.m_HasSwitchDoubleTap && m_SwitchDoubleTap == sc.m_SwitchDoubleTap &&
|
||||
m_SwitchCornerSize == sc.m_SwitchCornerSize && 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;
|
||||
}
|
||||
|
||||
void ServerConfig::save(QFile &file) const {
|
||||
void ServerConfig::save(QFile &file) const
|
||||
{
|
||||
QTextStream outStream(&file);
|
||||
outStream << *this;
|
||||
}
|
||||
|
||||
void ServerConfig::setupScreens() {
|
||||
void ServerConfig::setupScreens()
|
||||
{
|
||||
switchCorners().clear();
|
||||
screens().clear();
|
||||
hotkeys().clear();
|
||||
@ -108,7 +106,8 @@ void ServerConfig::setupScreens() {
|
||||
addScreen(Screen());
|
||||
}
|
||||
|
||||
void ServerConfig::commit() {
|
||||
void ServerConfig::commit()
|
||||
{
|
||||
qDebug("committing server config");
|
||||
|
||||
settings().beginGroup("internalConfig");
|
||||
@ -129,8 +128,7 @@ void ServerConfig::commit() {
|
||||
settings().setValue("disableLockToScreen", disableLockToScreen());
|
||||
settings().setValue("enableDragAndDrop", enableDragAndDrop());
|
||||
settings().setValue("clipboardSharing", clipboardSharing());
|
||||
settings().setValue(
|
||||
"clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
|
||||
settings().setValue("clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
|
||||
|
||||
if (!getClientAddress().isEmpty()) {
|
||||
settings().setValue("clientAddress", getClientAddress());
|
||||
@ -159,7 +157,8 @@ void ServerConfig::commit() {
|
||||
settings().endGroup();
|
||||
}
|
||||
|
||||
void ServerConfig::recall() {
|
||||
void ServerConfig::recall()
|
||||
{
|
||||
qDebug("recalling server config");
|
||||
|
||||
settings().beginGroup("internalConfig");
|
||||
@ -174,28 +173,21 @@ void ServerConfig::recall() {
|
||||
haveHeartbeat(settings().value("hasHeartbeat", false).toBool());
|
||||
setHeartbeat(settings().value("heartbeat", 5000).toInt());
|
||||
setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool());
|
||||
setWin32KeepForeground(
|
||||
settings().value("win32KeepForeground", false).toBool());
|
||||
setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool());
|
||||
haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool());
|
||||
setSwitchDelay(settings().value("switchDelay", 250).toInt());
|
||||
haveSwitchDoubleTap(settings().value("hasSwitchDoubleTap", false).toBool());
|
||||
setSwitchDoubleTap(settings().value("switchDoubleTap", 250).toInt());
|
||||
setSwitchCornerSize(settings().value("switchCornerSize").toInt());
|
||||
setDisableLockToScreen(
|
||||
settings().value("disableLockToScreen", false).toBool());
|
||||
setDisableLockToScreen(settings().value("disableLockToScreen", false).toBool());
|
||||
setEnableDragAndDrop(settings().value("enableDragAndDrop", false).toBool());
|
||||
setClipboardSharingSize(
|
||||
settings()
|
||||
.value(
|
||||
"clipboardSharingSize",
|
||||
(int)ServerConfig::defaultClipboardSharingSize())
|
||||
.toULongLong());
|
||||
settings().value("clipboardSharingSize", (int)ServerConfig::defaultClipboardSharingSize()).toULongLong()
|
||||
);
|
||||
setClipboardSharing(settings().value("clipboardSharing", true).toBool());
|
||||
setClientAddress(settings().value("clientAddress", "").toString());
|
||||
|
||||
readSettings(
|
||||
settings(), switchCorners(), "switchCorner", 0,
|
||||
static_cast<int>(NumSwitchCorners));
|
||||
readSettings(settings(), switchCorners(), "switchCorner", 0, static_cast<int>(NumSwitchCorners));
|
||||
|
||||
int numScreens = settings().beginReadArray("screens");
|
||||
Q_ASSERT(numScreens <= screens().size());
|
||||
@ -220,15 +212,14 @@ void ServerConfig::recall() {
|
||||
settings().endGroup();
|
||||
}
|
||||
|
||||
int ServerConfig::adjacentScreenIndex(
|
||||
int idx, int deltaColumn, int deltaRow) const {
|
||||
int ServerConfig::adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const
|
||||
{
|
||||
if (screens()[idx].isNull())
|
||||
return -1;
|
||||
|
||||
// if we're at the left or right end of the table, don't find results going
|
||||
// further left or right
|
||||
if ((deltaColumn > 0 && (idx + 1) % numColumns() == 0) ||
|
||||
(deltaColumn < 0 && idx % numColumns() == 0))
|
||||
if ((deltaColumn > 0 && (idx + 1) % numColumns() == 0) || (deltaColumn < 0 && idx % numColumns() == 0))
|
||||
return -1;
|
||||
|
||||
int arrayPos = idx + deltaColumn + deltaRow * numColumns();
|
||||
@ -239,7 +230,8 @@ int ServerConfig::adjacentScreenIndex(
|
||||
return arrayPos;
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
||||
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config)
|
||||
{
|
||||
outStream << "section: screens" << Qt::endl;
|
||||
|
||||
foreach (const Screen &s, config.screens())
|
||||
@ -262,13 +254,10 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
||||
if (!config.screens()[i].isNull()) {
|
||||
outStream << "\t" << config.screens()[i].name() << ":" << Qt::endl;
|
||||
|
||||
for (unsigned int j = 0;
|
||||
j < sizeof(neighbourDirs) / sizeof(neighbourDirs[0]); j++) {
|
||||
int idx = config.adjacentScreenIndex(
|
||||
i, neighbourDirs[j].x, neighbourDirs[j].y);
|
||||
for (unsigned int j = 0; j < sizeof(neighbourDirs) / sizeof(neighbourDirs[0]); j++) {
|
||||
int idx = config.adjacentScreenIndex(i, neighbourDirs[j].x, neighbourDirs[j].y);
|
||||
if (idx != -1 && !config.screens()[idx].isNull())
|
||||
outStream << "\t\t" << neighbourDirs[j].name << " = "
|
||||
<< config.screens()[idx].name() << Qt::endl;
|
||||
outStream << "\t\t" << neighbourDirs[j].name << " = " << config.screens()[idx].name() << Qt::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,20 +270,15 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
||||
<< "heartbeat = " << config.heartbeat() << Qt::endl;
|
||||
|
||||
outStream << "\t"
|
||||
<< "relativeMouseMoves = "
|
||||
<< (config.relativeMouseMoves() ? "true" : "false") << Qt::endl;
|
||||
<< "relativeMouseMoves = " << (config.relativeMouseMoves() ? "true" : "false") << Qt::endl;
|
||||
outStream << "\t"
|
||||
<< "win32KeepForeground = "
|
||||
<< (config.win32KeepForeground() ? "true" : "false") << Qt::endl;
|
||||
<< "win32KeepForeground = " << (config.win32KeepForeground() ? "true" : "false") << Qt::endl;
|
||||
outStream << "\t"
|
||||
<< "disableLockToScreen = "
|
||||
<< (config.disableLockToScreen() ? "true" : "false") << Qt::endl;
|
||||
<< "disableLockToScreen = " << (config.disableLockToScreen() ? "true" : "false") << Qt::endl;
|
||||
outStream << "\t"
|
||||
<< "clipboardSharing = "
|
||||
<< (config.clipboardSharing() ? "true" : "false") << Qt::endl;
|
||||
<< "clipboardSharing = " << (config.clipboardSharing() ? "true" : "false") << Qt::endl;
|
||||
outStream << "\t"
|
||||
<< "clipboardSharingSize = " << config.clipboardSharingSize()
|
||||
<< Qt::endl;
|
||||
<< "clipboardSharingSize = " << config.clipboardSharingSize() << Qt::endl;
|
||||
|
||||
if (!config.getClientAddress().isEmpty()) {
|
||||
outStream << "\t"
|
||||
@ -327,7 +311,8 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config) {
|
||||
return outStream;
|
||||
}
|
||||
|
||||
int ServerConfig::numScreens() const {
|
||||
int ServerConfig::numScreens() const
|
||||
{
|
||||
int rval = 0;
|
||||
|
||||
foreach (const Screen &s, screens())
|
||||
@ -337,7 +322,8 @@ int ServerConfig::numScreens() const {
|
||||
return rval;
|
||||
}
|
||||
|
||||
int ServerConfig::autoAddScreen(const QString name) {
|
||||
int ServerConfig::autoAddScreen(const QString name)
|
||||
{
|
||||
int serverIndex = -1;
|
||||
int targetIndex = -1;
|
||||
if (!findScreenName(m_pAppConfig->screenName(), serverIndex) &&
|
||||
@ -377,8 +363,7 @@ int ServerConfig::autoAddScreen(const QString name) {
|
||||
dirIndex = 3;
|
||||
}
|
||||
|
||||
int idx = adjacentScreenIndex(
|
||||
startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
||||
int idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
||||
while (idx != -1) {
|
||||
if (screens()[idx].isNull()) {
|
||||
m_Screens[idx].setName(name);
|
||||
@ -387,8 +372,7 @@ int ServerConfig::autoAddScreen(const QString name) {
|
||||
}
|
||||
|
||||
startIndex += offset;
|
||||
idx = adjacentScreenIndex(
|
||||
startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
||||
idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x, neighbourDirs[dirIndex].y);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
@ -399,11 +383,13 @@ int ServerConfig::autoAddScreen(const QString name) {
|
||||
return kAutoAddScreenOk;
|
||||
}
|
||||
|
||||
const QString &ServerConfig::getServerName() const {
|
||||
const QString &ServerConfig::getServerName() const
|
||||
{
|
||||
return m_pAppConfig->screenName();
|
||||
}
|
||||
|
||||
void ServerConfig::updateServerName() {
|
||||
void ServerConfig::updateServerName()
|
||||
{
|
||||
for (auto &screen : screens()) {
|
||||
if (screen.isServer()) {
|
||||
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();
|
||||
}
|
||||
|
||||
bool ServerConfig::useExternalConfig() const {
|
||||
bool ServerConfig::useExternalConfig() const
|
||||
{
|
||||
return m_pAppConfig->useExternalConfig();
|
||||
}
|
||||
|
||||
bool ServerConfig::isFull() const {
|
||||
bool ServerConfig::isFull() const
|
||||
{
|
||||
bool isFull = true;
|
||||
|
||||
for (const auto &screen : screens()) {
|
||||
@ -433,7 +422,8 @@ bool ServerConfig::isFull() const {
|
||||
return isFull;
|
||||
}
|
||||
|
||||
bool ServerConfig::screenExists(const QString &screenName) const {
|
||||
bool ServerConfig::screenExists(const QString &screenName) const
|
||||
{
|
||||
bool isExists = false;
|
||||
|
||||
for (const auto &screen : screens()) {
|
||||
@ -446,7 +436,8 @@ bool ServerConfig::screenExists(const QString &screenName) const {
|
||||
return isExists;
|
||||
}
|
||||
|
||||
void ServerConfig::addClient(const QString &clientName) {
|
||||
void ServerConfig::addClient(const QString &clientName)
|
||||
{
|
||||
int serverIndex = -1;
|
||||
|
||||
if (findScreenName(m_pAppConfig->screenName(), serverIndex)) {
|
||||
@ -458,15 +449,18 @@ void ServerConfig::addClient(const QString &clientName) {
|
||||
m_Screens.addScreenByPriority(Screen(clientName));
|
||||
}
|
||||
|
||||
void ServerConfig::setConfigFile(const QString &configFile) {
|
||||
void ServerConfig::setConfigFile(const QString &configFile)
|
||||
{
|
||||
m_pAppConfig->setConfigFile(configFile);
|
||||
}
|
||||
|
||||
void ServerConfig::setUseExternalConfig(bool useExternalConfig) {
|
||||
void ServerConfig::setUseExternalConfig(bool useExternalConfig)
|
||||
{
|
||||
m_pAppConfig->setUseExternalConfig(useExternalConfig);
|
||||
}
|
||||
|
||||
bool ServerConfig::findScreenName(const QString &name, int &index) {
|
||||
bool ServerConfig::findScreenName(const QString &name, int &index)
|
||||
{
|
||||
bool found = false;
|
||||
for (int i = 0; i < screens().size(); i++) {
|
||||
if (!screens()[i].isNull() && screens()[i].name().compare(name) == 0) {
|
||||
@ -478,7 +472,8 @@ bool ServerConfig::findScreenName(const QString &name, int &index) {
|
||||
return found;
|
||||
}
|
||||
|
||||
bool ServerConfig::fixNoServer(const QString &name, int &index) {
|
||||
bool ServerConfig::fixNoServer(const QString &name, int &index)
|
||||
{
|
||||
bool fixed = false;
|
||||
if (screens()[serverDefaultIndex].isNull()) {
|
||||
m_Screens[serverDefaultIndex].setName(name);
|
||||
@ -490,7 +485,8 @@ bool ServerConfig::fixNoServer(const QString &name, int &index) {
|
||||
return fixed;
|
||||
}
|
||||
|
||||
int ServerConfig::showAddClientDialog(const QString &clientName) {
|
||||
int ServerConfig::showAddClientDialog(const QString &clientName)
|
||||
{
|
||||
int result = kAddClientIgnore;
|
||||
|
||||
if (!m_pMainWindow->isActiveWindow()) {
|
||||
@ -505,7 +501,8 @@ int ServerConfig::showAddClientDialog(const QString &clientName) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void ::ServerConfig::addToFirstEmptyGrid(const QString &clientName) {
|
||||
void ::ServerConfig::addToFirstEmptyGrid(const QString &clientName)
|
||||
{
|
||||
for (int i = 0; i < screens().size(); i++) {
|
||||
if (screens()[i].isNull()) {
|
||||
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
|
||||
}
|
||||
|
||||
size_t ServerConfig::setClipboardSharingSize(size_t size) {
|
||||
size_t ServerConfig::setClipboardSharingSize(size_t size)
|
||||
{
|
||||
if (size) {
|
||||
size += 512; // Round up to the nearest megabyte
|
||||
size /= 1024;
|
||||
@ -532,13 +531,15 @@ size_t ServerConfig::setClipboardSharingSize(size_t size) {
|
||||
return size;
|
||||
}
|
||||
|
||||
void ServerConfig::setClientAddress(const QString &address) {
|
||||
void ServerConfig::setClientAddress(const QString &address)
|
||||
{
|
||||
if (m_pAppConfig->invertConnection()) {
|
||||
m_ClientAddress = address;
|
||||
}
|
||||
}
|
||||
|
||||
QString ServerConfig::getClientAddress() const {
|
||||
QString ServerConfig::getClientAddress() const
|
||||
{
|
||||
QString clientAddress;
|
||||
|
||||
if (m_pAppConfig->invertConnection()) {
|
||||
@ -548,6 +549,7 @@ QString ServerConfig::getClientAddress() const {
|
||||
return clientAddress;
|
||||
}
|
||||
|
||||
QSettingsProxy &ServerConfig::settings() {
|
||||
QSettingsProxy &ServerConfig::settings()
|
||||
{
|
||||
return m_pAppConfig->scopes().activeSettings();
|
||||
}
|
||||
|
||||
@ -36,17 +36,15 @@ class ServerConfigDialog;
|
||||
class MainWindow;
|
||||
class AppConfig;
|
||||
|
||||
class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig {
|
||||
class ServerConfig : public ScreenConfig, public deskflow::gui::IServerConfig
|
||||
{
|
||||
using QSettingsProxy = deskflow::gui::proxy::QSettingsProxy;
|
||||
|
||||
friend class ServerConfigDialog;
|
||||
friend QTextStream &
|
||||
operator<<(QTextStream &outStream, const ServerConfig &config);
|
||||
friend QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
|
||||
|
||||
public:
|
||||
ServerConfig(
|
||||
AppConfig &appConfig, MainWindow &mainWindow,
|
||||
int columns = kDefaultColumns, int rows = kDefaultRows);
|
||||
ServerConfig(AppConfig &appConfig, MainWindow &mainWindow, int columns = kDefaultColumns, int rows = kDefaultRows);
|
||||
~ServerConfig() override = default;
|
||||
|
||||
bool operator==(const ServerConfig &sc) const;
|
||||
@ -54,29 +52,86 @@ public:
|
||||
//
|
||||
// Overrides
|
||||
//
|
||||
const ScreenList &screens() const override { return m_Screens; }
|
||||
bool enableDragAndDrop() const override { return m_EnableDragAndDrop; }
|
||||
const ScreenList &screens() const override
|
||||
{
|
||||
return m_Screens;
|
||||
}
|
||||
bool enableDragAndDrop() const override
|
||||
{
|
||||
return m_EnableDragAndDrop;
|
||||
}
|
||||
|
||||
//
|
||||
// New methods
|
||||
//
|
||||
int numColumns() const { return m_Columns; }
|
||||
int numRows() const { return m_Rows; }
|
||||
bool hasHeartbeat() const { return m_HasHeartbeat; }
|
||||
int heartbeat() const { return m_Heartbeat; }
|
||||
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; }
|
||||
int numColumns() const
|
||||
{
|
||||
return m_Columns;
|
||||
}
|
||||
int numRows() const
|
||||
{
|
||||
return m_Rows;
|
||||
}
|
||||
bool hasHeartbeat() const
|
||||
{
|
||||
return m_HasHeartbeat;
|
||||
}
|
||||
int heartbeat() const
|
||||
{
|
||||
return m_Heartbeat;
|
||||
}
|
||||
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();
|
||||
|
||||
//
|
||||
@ -105,29 +160,89 @@ private:
|
||||
void recall();
|
||||
void setupScreens();
|
||||
QSettingsProxy &settings();
|
||||
ScreenList &screens() { return m_Screens; }
|
||||
void setScreens(const ScreenList &screens) { m_Screens = screens; }
|
||||
void addScreen(const Screen &screen) { m_Screens.append(screen); }
|
||||
void setNumColumns(int n) { m_Columns = n; }
|
||||
void setNumRows(int n) { 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; }
|
||||
ScreenList &screens()
|
||||
{
|
||||
return m_Screens;
|
||||
}
|
||||
void setScreens(const ScreenList &screens)
|
||||
{
|
||||
m_Screens = screens;
|
||||
}
|
||||
void addScreen(const Screen &screen)
|
||||
{
|
||||
m_Screens.append(screen);
|
||||
}
|
||||
void setNumColumns(int n)
|
||||
{
|
||||
m_Columns = n;
|
||||
}
|
||||
void setNumRows(int n)
|
||||
{
|
||||
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 setUseExternalConfig(bool useExternalConfig);
|
||||
size_t setClipboardSharingSize(size_t size);
|
||||
QList<bool> &switchCorners() { return m_SwitchCorners; }
|
||||
HotkeyList &hotkeys() { return m_Hotkeys; }
|
||||
QList<bool> &switchCorners()
|
||||
{
|
||||
return m_SwitchCorners;
|
||||
}
|
||||
HotkeyList &hotkeys()
|
||||
{
|
||||
return m_Hotkeys;
|
||||
}
|
||||
int adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const;
|
||||
bool findScreenName(const QString &name, int &index);
|
||||
bool fixNoServer(const QString &name, int &index);
|
||||
@ -161,7 +276,8 @@ private:
|
||||
|
||||
QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config);
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
kAutoAddScreenOk,
|
||||
kAutoAddScreenManualServer,
|
||||
kAutoAddScreenManualClient,
|
||||
|
||||
@ -30,19 +30,17 @@
|
||||
|
||||
using enum ScreenConfig::SwitchCorner;
|
||||
|
||||
ServerConfigDialog::ServerConfigDialog(
|
||||
QWidget *parent, ServerConfig &config, AppConfig &appConfig)
|
||||
ServerConfigDialog::ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||
Ui::ServerConfigDialogBase(),
|
||||
m_OriginalServerConfig(config),
|
||||
m_OriginalServerConfigIsExternal(config.useExternalConfig()),
|
||||
m_OriginalServerConfigUsesExternalFile(config.configFile()),
|
||||
m_ServerConfig(config),
|
||||
m_ScreenSetupModel(
|
||||
serverConfig().screens(), serverConfig().numColumns(),
|
||||
serverConfig().numRows()),
|
||||
m_ScreenSetupModel(serverConfig().screens(), serverConfig().numColumns(), serverConfig().numRows()),
|
||||
m_Message(""),
|
||||
m_appConfig(appConfig) {
|
||||
m_appConfig(appConfig)
|
||||
{
|
||||
|
||||
setupUi(this);
|
||||
|
||||
@ -55,10 +53,8 @@ ServerConfigDialog::ServerConfigDialog(
|
||||
m_pCheckBoxHeartbeat->setChecked(serverConfig().hasHeartbeat());
|
||||
m_pSpinBoxHeartbeat->setValue(serverConfig().heartbeat());
|
||||
|
||||
m_pCheckBoxRelativeMouseMoves->setChecked(
|
||||
serverConfig().relativeMouseMoves());
|
||||
m_pCheckBoxWin32KeepForeground->setChecked(
|
||||
serverConfig().win32KeepForeground());
|
||||
m_pCheckBoxRelativeMouseMoves->setChecked(serverConfig().relativeMouseMoves());
|
||||
m_pCheckBoxWin32KeepForeground->setChecked(serverConfig().win32KeepForeground());
|
||||
|
||||
m_pCheckBoxSwitchDelay->setChecked(serverConfig().hasSwitchDelay());
|
||||
m_pSpinBoxSwitchDelay->setValue(serverConfig().switchDelay());
|
||||
@ -66,21 +62,15 @@ ServerConfigDialog::ServerConfigDialog(
|
||||
m_pCheckBoxSwitchDoubleTap->setChecked(serverConfig().hasSwitchDoubleTap());
|
||||
m_pSpinBoxSwitchDoubleTap->setValue(serverConfig().switchDoubleTap());
|
||||
|
||||
m_pCheckBoxCornerTopLeft->setChecked(
|
||||
serverConfig().switchCorner(static_cast<int>(TopLeft)));
|
||||
m_pCheckBoxCornerTopRight->setChecked(
|
||||
serverConfig().switchCorner(static_cast<int>(TopRight)));
|
||||
m_pCheckBoxCornerBottomLeft->setChecked(
|
||||
serverConfig().switchCorner(static_cast<int>(BottomLeft)));
|
||||
m_pCheckBoxCornerBottomRight->setChecked(
|
||||
serverConfig().switchCorner(static_cast<int>(BottomRight)));
|
||||
m_pCheckBoxCornerTopLeft->setChecked(serverConfig().switchCorner(static_cast<int>(TopLeft)));
|
||||
m_pCheckBoxCornerTopRight->setChecked(serverConfig().switchCorner(static_cast<int>(TopRight)));
|
||||
m_pCheckBoxCornerBottomLeft->setChecked(serverConfig().switchCorner(static_cast<int>(BottomLeft)));
|
||||
m_pCheckBoxCornerBottomRight->setChecked(serverConfig().switchCorner(static_cast<int>(BottomRight)));
|
||||
m_pSpinBoxSwitchCornerSize->setValue(serverConfig().switchCornerSize());
|
||||
m_pCheckBoxDisableLockToScreen->setChecked(
|
||||
serverConfig().disableLockToScreen());
|
||||
m_pCheckBoxDisableLockToScreen->setChecked(serverConfig().disableLockToScreen());
|
||||
|
||||
m_pCheckBoxEnableClipboard->setChecked(serverConfig().clipboardSharing());
|
||||
int clipboardSharingSizeM =
|
||||
static_cast<int>(serverConfig().clipboardSharingSize() / 1024);
|
||||
int clipboardSharingSizeM = static_cast<int>(serverConfig().clipboardSharingSize() / 1024);
|
||||
m_pSpinBoxClipboardSizeLimit->setValue(clipboardSharingSizeM);
|
||||
m_pSpinBoxClipboardSizeLimit->setEnabled(serverConfig().clipboardSharing());
|
||||
|
||||
@ -90,223 +80,164 @@ ServerConfigDialog::ServerConfigDialog(
|
||||
m_pScreenSetupView->setModel(&m_ScreenSetupModel);
|
||||
|
||||
auto &screens = serverConfig().screens();
|
||||
auto server = std::find_if(
|
||||
screens.begin(), screens.end(), [this](const Screen &screen) {
|
||||
return (screen.name() == serverConfig().getServerName());
|
||||
});
|
||||
auto server = std::find_if(screens.begin(), screens.end(), [this](const Screen &screen) {
|
||||
return (screen.name() == serverConfig().getServerName());
|
||||
});
|
||||
|
||||
if (server == screens.end()) {
|
||||
Screen serverScreen(serverConfig().getServerName());
|
||||
serverScreen.markAsServer();
|
||||
model().screen(
|
||||
serverConfig().numColumns() / 2, serverConfig().numRows() / 2) =
|
||||
serverScreen;
|
||||
model().screen(serverConfig().numColumns() / 2, serverConfig().numRows() / 2) = serverScreen;
|
||||
} else {
|
||||
server->markAsServer();
|
||||
}
|
||||
|
||||
m_pButtonAddComputer->setEnabled(!model().isFull());
|
||||
connect(
|
||||
m_pTrashScreenWidget, &TrashScreenWidget::screenRemoved, this,
|
||||
&ServerConfigDialog::onScreenRemoved);
|
||||
connect(m_pTrashScreenWidget, &TrashScreenWidget::screenRemoved, this, &ServerConfigDialog::onScreenRemoved);
|
||||
|
||||
onChange();
|
||||
|
||||
// computers
|
||||
connect(
|
||||
&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this,
|
||||
&ServerConfigDialog::onChange);
|
||||
connect(&m_ScreenSetupModel, &ScreenSetupModel::screensChanged, this, &ServerConfigDialog::onChange);
|
||||
|
||||
#if QT_VERSION <= QT_VERSION_CHECK(6, 7, 0)
|
||||
// advanced
|
||||
connect(
|
||||
m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().haveSwitchDelay(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().haveSwitchDoubleTap(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setClipboardSharing(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxHeartbeat, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().haveHeartbeat(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setRelativeMouseMoves(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setWin32KeepForeground(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setDisableLockToScreen(v);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
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();
|
||||
});
|
||||
connect(m_pCheckBoxSwitchDelay, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().haveSwitchDelay(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().haveSwitchDoubleTap(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxEnableClipboard, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().setClipboardSharing(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxHeartbeat, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().haveHeartbeat(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().setRelativeMouseMoves(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().setWin32KeepForeground(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().setDisableLockToScreen(v);
|
||||
onChange();
|
||||
});
|
||||
connect(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
|
||||
connect(
|
||||
m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged, this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setUseExternalConfig(v);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::stateChanged, this, [this](const int &v) {
|
||||
serverConfig().setUseExternalConfig(v);
|
||||
onChange();
|
||||
});
|
||||
#else
|
||||
connect(
|
||||
m_pCheckBoxSwitchDelay, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().haveSwitchDelay(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxSwitchDoubleTap, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().haveSwitchDoubleTap(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxEnableClipboard, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().setClipboardSharing(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxHeartbeat, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().haveHeartbeat(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxRelativeMouseMoves, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().setRelativeMouseMoves(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxWin32KeepForeground, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().setWin32KeepForeground(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
m_pCheckBoxDisableLockToScreen, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().setDisableLockToScreen(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(
|
||||
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();
|
||||
});
|
||||
connect(m_pCheckBoxSwitchDelay, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().haveSwitchDelay(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxSwitchDoubleTap, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().haveSwitchDoubleTap(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxEnableClipboard, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().setClipboardSharing(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxHeartbeat, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().haveHeartbeat(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxRelativeMouseMoves, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().setRelativeMouseMoves(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxWin32KeepForeground, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().setWin32KeepForeground(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxDisableLockToScreen, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().setDisableLockToScreen(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(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
|
||||
connect(
|
||||
m_pCheckBoxUseExternalConfig, &QCheckBox::checkStateChanged, this,
|
||||
[this](const Qt::CheckState &v) {
|
||||
serverConfig().setUseExternalConfig(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
connect(m_pCheckBoxUseExternalConfig, &QCheckBox::checkStateChanged, this, [this](const Qt::CheckState &v) {
|
||||
serverConfig().setUseExternalConfig(v == Qt::Checked);
|
||||
onChange();
|
||||
});
|
||||
#endif
|
||||
|
||||
connect(
|
||||
m_pSpinBoxSwitchDelay,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
m_pSpinBoxSwitchDelay, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setSwitchDelay(v);
|
||||
onChange();
|
||||
});
|
||||
}
|
||||
);
|
||||
connect(
|
||||
m_pSpinBoxSwitchDoubleTap,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
m_pSpinBoxSwitchDoubleTap, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setSwitchDoubleTap(v);
|
||||
onChange();
|
||||
});
|
||||
}
|
||||
);
|
||||
connect(
|
||||
m_pSpinBoxClipboardSizeLimit,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
m_pSpinBoxClipboardSizeLimit, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setClipboardSharingSize(v * 1024);
|
||||
onChange();
|
||||
});
|
||||
}
|
||||
);
|
||||
connect(
|
||||
m_pSpinBoxHeartbeat,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
m_pSpinBoxHeartbeat, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setHeartbeat(v);
|
||||
onChange();
|
||||
});
|
||||
}
|
||||
);
|
||||
connect(
|
||||
m_pSpinBoxSwitchCornerSize,
|
||||
static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
m_pSpinBoxSwitchCornerSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
|
||||
[this](const int &v) {
|
||||
serverConfig().setSwitchCornerSize(v);
|
||||
onChange();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
connect(m_pEditConfigFile, &QLineEdit::textChanged, this, [this]() {
|
||||
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);
|
||||
}
|
||||
|
||||
void ServerConfigDialog::showEvent(QShowEvent *event) {
|
||||
void ServerConfigDialog::showEvent(QShowEvent *event)
|
||||
{
|
||||
QDialog::show();
|
||||
|
||||
if (!m_Message.isEmpty()) {
|
||||
@ -327,16 +260,15 @@ void ServerConfigDialog::showEvent(QShowEvent *event) {
|
||||
}
|
||||
}
|
||||
|
||||
void ServerConfigDialog::accept() {
|
||||
if (m_pCheckBoxUseExternalConfig->isChecked() &&
|
||||
!QFile::exists(m_pEditConfigFile->text())) {
|
||||
void ServerConfigDialog::accept()
|
||||
{
|
||||
if (m_pCheckBoxUseExternalConfig->isChecked() && !QFile::exists(m_pEditConfigFile->text())) {
|
||||
|
||||
auto selectedButton = QMessageBox::warning(
|
||||
this, "Filename invalid", "Please select a valid configuration file.",
|
||||
QMessageBox::Ok | QMessageBox::Ignore);
|
||||
this, "Filename invalid", "Please select a valid configuration file.", QMessageBox::Ok | QMessageBox::Ignore
|
||||
);
|
||||
|
||||
if (selectedButton != QMessageBox::Ok ||
|
||||
!on_m_pButtonBrowseConfigFile_clicked()) {
|
||||
if (selectedButton != QMessageBox::Ok || !on_m_pButtonBrowseConfigFile_clicked()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -348,14 +280,16 @@ void ServerConfigDialog::accept() {
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void ServerConfigDialog::reject() {
|
||||
void ServerConfigDialog::reject()
|
||||
{
|
||||
serverConfig().setUseExternalConfig(m_OriginalServerConfigIsExternal);
|
||||
serverConfig().setConfigFile(m_OriginalServerConfigUsesExternalFile);
|
||||
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked() {
|
||||
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked()
|
||||
{
|
||||
Hotkey hotkey;
|
||||
HotkeyDialog dlg(this, hotkey);
|
||||
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();
|
||||
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
||||
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();
|
||||
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
||||
serverConfig().hotkeys().removeAt(idx);
|
||||
@ -385,7 +321,8 @@ void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked() {
|
||||
onChange();
|
||||
}
|
||||
|
||||
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged() {
|
||||
void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged()
|
||||
{
|
||||
bool itemsSelected = !m_pListHotkeys->selectedItems().isEmpty();
|
||||
m_pButtonEditHotkey->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();
|
||||
Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size());
|
||||
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();
|
||||
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
|
||||
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();
|
||||
Q_ASSERT(idxHotkey >= 0 && idxHotkey < serverConfig().hotkeys().size());
|
||||
Hotkey &hotkey = serverConfig().hotkeys()[idxHotkey];
|
||||
@ -456,31 +396,34 @@ void ServerConfigDialog::on_m_pButtonRemoveAction_clicked() {
|
||||
onChange();
|
||||
}
|
||||
|
||||
void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(
|
||||
int const state) {
|
||||
void ServerConfigDialog::on_m_pCheckBoxEnableClipboard_stateChanged(int const state)
|
||||
{
|
||||
m_pSpinBoxClipboardSizeLimit->setEnabled(state == Qt::Checked);
|
||||
if ((state == Qt::Checked) && (!m_pSpinBoxClipboardSizeLimit->value())) {
|
||||
int size = static_cast<int>(
|
||||
(serverConfig().defaultClipboardSharingSize() + 512) / 1024);
|
||||
int size = static_cast<int>((serverConfig().defaultClipboardSharingSize() + 512) / 1024);
|
||||
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_pButtonRemoveAction->setEnabled(!m_pListActions->selectedItems().isEmpty());
|
||||
}
|
||||
|
||||
void ServerConfigDialog::on_m_pButtonAddComputer_clicked() {
|
||||
void ServerConfigDialog::on_m_pButtonAddComputer_clicked()
|
||||
{
|
||||
addComputer("", false);
|
||||
}
|
||||
|
||||
void ServerConfigDialog::onScreenRemoved() {
|
||||
void ServerConfigDialog::onScreenRemoved()
|
||||
{
|
||||
m_pButtonAddComputer->setEnabled(true);
|
||||
onChange();
|
||||
}
|
||||
|
||||
void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked) {
|
||||
void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked)
|
||||
{
|
||||
m_pLabelConfigFile->setEnabled(checked);
|
||||
m_pEditConfigFile->setEnabled(checked);
|
||||
m_pButtonBrowseConfigFile->setEnabled(checked);
|
||||
@ -490,19 +433,15 @@ void ServerConfigDialog::on_m_pCheckBoxUseExternalConfig_toggled(bool checked) {
|
||||
m_pTabWidget->setTabEnabled(2, !checked);
|
||||
}
|
||||
|
||||
bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked() {
|
||||
bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked()
|
||||
{
|
||||
#if defined(Q_OS_WIN)
|
||||
const QString deskflowConfigFilter(
|
||||
QString("%1 Configurations (*.sgc);;All files (*.*)")
|
||||
.arg(DESKFLOW_APP_NAME));
|
||||
const QString deskflowConfigFilter(QString("%1 Configurations (*.sgc);;All files (*.*)").arg(DESKFLOW_APP_NAME));
|
||||
#else
|
||||
const QString deskflowConfigFilter(
|
||||
QString("%1 Configurations (*.conf);;All files (*.*)")
|
||||
.arg(DESKFLOW_APP_NAME));
|
||||
const QString deskflowConfigFilter(QString("%1 Configurations (*.conf);;All files (*.*)").arg(DESKFLOW_APP_NAME));
|
||||
#endif
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this, "Browse for a config file", "", deskflowConfigFilter);
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "Browse for a config file", "", deskflowConfigFilter);
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
m_pEditConfigFile->setText(fileName);
|
||||
@ -512,7 +451,8 @@ bool ServerConfigDialog::on_m_pButtonBrowseConfigFile_clicked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent) {
|
||||
bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent)
|
||||
{
|
||||
bool isAccepted = false;
|
||||
Screen newScreen(clientName);
|
||||
|
||||
@ -526,11 +466,10 @@ bool ServerConfigDialog::addComputer(const QString &clientName, bool doSilent) {
|
||||
return isAccepted;
|
||||
}
|
||||
|
||||
void ServerConfigDialog::onChange() {
|
||||
bool isAppConfigDataEqual =
|
||||
m_OriginalServerConfigIsExternal == serverConfig().useExternalConfig() &&
|
||||
m_OriginalServerConfigUsesExternalFile == serverConfig().configFile();
|
||||
void ServerConfigDialog::onChange()
|
||||
{
|
||||
bool isAppConfigDataEqual = m_OriginalServerConfigIsExternal == serverConfig().useExternalConfig() &&
|
||||
m_OriginalServerConfigUsesExternalFile == serverConfig().configFile();
|
||||
m_pButtonBox->button(QDialogButtonBox::Ok)
|
||||
->setEnabled(
|
||||
!isAppConfigDataEqual || !(m_OriginalServerConfig == m_ServerConfig));
|
||||
->setEnabled(!isAppConfigDataEqual || !(m_OriginalServerConfig == m_ServerConfig));
|
||||
}
|
||||
|
||||
@ -25,19 +25,22 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase {
|
||||
class ServerConfigDialog : public QDialog, public Ui::ServerConfigDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ServerConfigDialog(
|
||||
QWidget *parent, ServerConfig &config, AppConfig &appConfig);
|
||||
ServerConfigDialog(QWidget *parent, ServerConfig &config, AppConfig &appConfig);
|
||||
bool addClient(const QString &clientName);
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void message(const QString &message) { m_Message = message; }
|
||||
void message(const QString &message)
|
||||
{
|
||||
m_Message = message;
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void on_m_pButtonNewHotkey_clicked();
|
||||
@ -57,12 +60,22 @@ protected slots:
|
||||
|
||||
protected:
|
||||
bool addComputer(const QString &clientName, bool doSilent);
|
||||
ServerConfig &serverConfig() { return m_ServerConfig; }
|
||||
void setOriginalServerConfig(const ServerConfig &s) {
|
||||
ServerConfig &serverConfig()
|
||||
{
|
||||
return m_ServerConfig;
|
||||
}
|
||||
void setOriginalServerConfig(const ServerConfig &s)
|
||||
{
|
||||
m_OriginalServerConfig = s;
|
||||
}
|
||||
ScreenSetupModel &model() { return m_ScreenSetupModel; }
|
||||
AppConfig &appConfig() { return m_appConfig; }
|
||||
ScreenSetupModel &model()
|
||||
{
|
||||
return m_ScreenSetupModel;
|
||||
}
|
||||
AppConfig &appConfig()
|
||||
{
|
||||
return m_appConfig;
|
||||
}
|
||||
|
||||
private:
|
||||
ServerConfig &m_OriginalServerConfig;
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
|
||||
using namespace deskflow::gui;
|
||||
|
||||
SetupWizard::SetupWizard(AppConfig &appConfig) : m_appConfig(appConfig) {
|
||||
SetupWizard::SetupWizard(AppConfig &appConfig) : m_appConfig(appConfig)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
setWindowTitle(QString("Setup %1").arg(DESKFLOW_APP_NAME));
|
||||
@ -31,26 +32,28 @@ SetupWizard::SetupWizard(AppConfig &appConfig) : m_appConfig(appConfig) {
|
||||
m_pLabelError->setStyleSheet(kStyleErrorActiveLabel);
|
||||
|
||||
m_pLineEditName->setText(appConfig.screenName());
|
||||
m_pLineEditName->setValidator(new validators::ScreenNameValidator(
|
||||
m_pLineEditName, new validators::ValidationError(this, m_pLabelError)));
|
||||
m_pLineEditName->setValidator(
|
||||
new validators::ScreenNameValidator(m_pLineEditName, new validators::ValidationError(this, m_pLabelError))
|
||||
);
|
||||
|
||||
connect(m_pButtonApply, &QPushButton::clicked, this, &SetupWizard::accept);
|
||||
connect(
|
||||
m_pLineEditName, &QLineEdit::textChanged, this,
|
||||
&SetupWizard::onLineEditNameChanged);
|
||||
connect(m_pLineEditName, &QLineEdit::textChanged, this, &SetupWizard::onLineEditNameChanged);
|
||||
}
|
||||
|
||||
void SetupWizard::accept() {
|
||||
void SetupWizard::accept()
|
||||
{
|
||||
m_appConfig.setWizardHasRun();
|
||||
m_appConfig.setScreenName(m_pLineEditName->text());
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void SetupWizard::onLineEditNameChanged(const QString &error) {
|
||||
void SetupWizard::onLineEditNameChanged(const QString &error)
|
||||
{
|
||||
m_pButtonApply->setEnabled(m_pLineEditName->hasAcceptableInput());
|
||||
}
|
||||
|
||||
void SetupWizard::reject() {
|
||||
void SetupWizard::reject()
|
||||
{
|
||||
QDialog::reject();
|
||||
QApplication::exit();
|
||||
}
|
||||
|
||||
@ -26,7 +26,8 @@
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class SetupWizard : public QDialog, public Ui::SetupWizardBase {
|
||||
class SetupWizard : public QDialog, public Ui::SetupWizardBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
|
||||
void TrashScreenWidget::dragEnterEvent(QDragEnterEvent *event) {
|
||||
void TrashScreenWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
event->accept();
|
||||
@ -30,7 +31,8 @@ void TrashScreenWidget::dragEnterEvent(QDragEnterEvent *event) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void TrashScreenWidget::dropEvent(QDropEvent *event) {
|
||||
void TrashScreenWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat(ScreenSetupModel::mimeType())) {
|
||||
event->acceptProposedAction();
|
||||
emit screenRemoved();
|
||||
|
||||
@ -23,11 +23,14 @@ class QWidget;
|
||||
class QDragEnterEvent;
|
||||
class QDropEvent;
|
||||
|
||||
class TrashScreenWidget : public QLabel {
|
||||
class TrashScreenWidget : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TrashScreenWidget(QWidget *parent) : QLabel(parent) {}
|
||||
TrashScreenWidget(QWidget *parent) : QLabel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
||||
@ -51,21 +51,26 @@
|
||||
|
||||
using namespace deskflow::gui;
|
||||
|
||||
class QThreadImpl : public QThread {
|
||||
class QThreadImpl : public QThread
|
||||
{
|
||||
public:
|
||||
static void msleep(unsigned long msecs) { QThread::msleep(msecs); }
|
||||
static void msleep(unsigned long msecs)
|
||||
{
|
||||
QThread::msleep(msecs);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
bool checkMacAssistiveDevices();
|
||||
#endif
|
||||
|
||||
bool hasArg(const QString &arg, const QStringList &args) {
|
||||
return std::ranges::any_of(
|
||||
args, [&arg](const QString &a) { return a == arg; });
|
||||
bool hasArg(const QString &arg, const QStringList &args)
|
||||
{
|
||||
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)
|
||||
/* Workaround for QTBUG-40332 - "High ping when QNetworkAccessManager is
|
||||
@ -95,7 +100,8 @@ int main(int argc, char *argv[]) {
|
||||
QMessageBox::information(
|
||||
NULL, DESKFLOW_APP_NAME,
|
||||
"Please drag " DESKFLOW_APP_NAME " to the Applications folder, "
|
||||
"and open it from there.");
|
||||
"and open it from there."
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -109,8 +115,7 @@ int main(int argc, char *argv[]) {
|
||||
// --no-reset
|
||||
QStringList arguments = QCoreApplication::arguments();
|
||||
const auto noReset = hasArg("--no-reset", arguments);
|
||||
const auto resetEnvVar =
|
||||
strToTrue(qEnvironmentVariable("DESKFLOW_RESET_ALL"));
|
||||
const auto resetEnvVar = strToTrue(qEnvironmentVariable("DESKFLOW_RESET_ALL"));
|
||||
if (resetEnvVar && !noReset) {
|
||||
diagnostic::clearSettings(configScopes, false);
|
||||
}
|
||||
@ -118,8 +123,8 @@ int main(int argc, char *argv[]) {
|
||||
AppConfig appConfig(configScopes);
|
||||
|
||||
QObject::connect(
|
||||
&configScopes, &ConfigScopes::saving, &appConfig,
|
||||
[&appConfig]() { appConfig.commit(); }, Qt::DirectConnection);
|
||||
&configScopes, &ConfigScopes::saving, &appConfig, [&appConfig]() { appConfig.commit(); }, Qt::DirectConnection
|
||||
);
|
||||
|
||||
if (appConfig.wizardShouldRun()) {
|
||||
SetupWizard wizard(appConfig);
|
||||
@ -134,9 +139,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
MainWindow mainWindow(configScopes, appConfig);
|
||||
|
||||
QObject::connect(
|
||||
&app, &DeskflowApplication::aboutToQuit, &mainWindow,
|
||||
&MainWindow::onAppAboutToQuit);
|
||||
QObject::connect(&app, &DeskflowApplication::aboutToQuit, &mainWindow, &MainWindow::onAppAboutToQuit);
|
||||
|
||||
mainWindow.open();
|
||||
|
||||
@ -148,7 +151,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
bool checkMacAssistiveDevices() {
|
||||
bool checkMacAssistiveDevices()
|
||||
{
|
||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 // mavericks
|
||||
|
||||
// new in mavericks, applications are trusted individually
|
||||
@ -163,8 +167,7 @@ bool checkMacAssistiveDevices() {
|
||||
|
||||
const void *keys[] = {kAXTrustedCheckOptionPrompt};
|
||||
const void *trueValue[] = {kCFBooleanTrue};
|
||||
CFDictionaryRef options =
|
||||
CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
|
||||
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, trueValue, 1, NULL, NULL);
|
||||
|
||||
bool result = AXIsProcessTrustedWithOptions(options);
|
||||
CFRelease(options);
|
||||
@ -179,7 +182,8 @@ bool checkMacAssistiveDevices() {
|
||||
NULL, DESKFLOW_APP_NAME,
|
||||
"Please enable access to assistive devices "
|
||||
"System Preferences -> Security & Privacy -> "
|
||||
"Privacy -> Accessibility, then re-open " DESKFLOW_APP_NAME ".");
|
||||
"Privacy -> Accessibility, then re-open " DESKFLOW_APP_NAME "."
|
||||
);
|
||||
}
|
||||
return result;
|
||||
|
||||
|
||||
@ -28,20 +28,26 @@
|
||||
|
||||
Arch *Arch::s_instance = NULL;
|
||||
|
||||
Arch::Arch() {
|
||||
Arch::Arch()
|
||||
{
|
||||
assert(s_instance == NULL);
|
||||
s_instance = this;
|
||||
}
|
||||
|
||||
Arch::Arch(Arch *arch) { s_instance = arch; }
|
||||
Arch::Arch(Arch *arch)
|
||||
{
|
||||
s_instance = arch;
|
||||
}
|
||||
|
||||
Arch::~Arch() {
|
||||
Arch::~Arch()
|
||||
{
|
||||
#if SYSAPI_WIN32
|
||||
ArchMiscWindows::cleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Arch::init() {
|
||||
void Arch::init()
|
||||
{
|
||||
ARCH_NETWORK::init();
|
||||
#if SYSAPI_WIN32
|
||||
ARCH_TASKBAR::init();
|
||||
@ -49,7 +55,8 @@ void Arch::init() {
|
||||
#endif
|
||||
}
|
||||
|
||||
Arch *Arch::getInstance() {
|
||||
Arch *Arch::getInstance()
|
||||
{
|
||||
assert(s_instance != NULL);
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
@ -96,7 +96,8 @@ class Arch : public ARCH_CONSOLE,
|
||||
public ARCH_STRING,
|
||||
public ARCH_SYSTEM,
|
||||
public ARCH_TASKBAR,
|
||||
public ARCH_TIME {
|
||||
public ARCH_TIME
|
||||
{
|
||||
public:
|
||||
Arch();
|
||||
Arch(Arch *arch);
|
||||
@ -120,19 +121,29 @@ public:
|
||||
*/
|
||||
static Arch *getInstance();
|
||||
|
||||
static void setInstance(Arch *s) { s_instance = s; }
|
||||
static void setInstance(Arch *s)
|
||||
{
|
||||
s_instance = s;
|
||||
}
|
||||
|
||||
private:
|
||||
static Arch *s_instance;
|
||||
};
|
||||
|
||||
//! Convenience object to lock/unlock an arch mutex
|
||||
class ArchMutexLock {
|
||||
class ArchMutexLock
|
||||
{
|
||||
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 &&) = delete;
|
||||
~ArchMutexLock() { ARCH->unlockMutex(m_mutex); }
|
||||
~ArchMutexLock()
|
||||
{
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
}
|
||||
|
||||
ArchMutexLock &operator=(ArchMutexLock const &) = delete;
|
||||
ArchMutexLock &operator=(ArchMutexLock &&) = delete;
|
||||
|
||||
@ -21,7 +21,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void ArchConsoleStd::writeConsole(ELevel level, const char *str) {
|
||||
void ArchConsoleStd::writeConsole(ELevel level, const char *str)
|
||||
{
|
||||
if ((level >= kFATAL) && (level <= kWARNING))
|
||||
std::cerr << str << std::endl;
|
||||
else
|
||||
|
||||
@ -21,14 +21,25 @@
|
||||
#include "arch/IArchConsole.h"
|
||||
|
||||
//! Cross platform implementation of IArchConsole
|
||||
class ArchConsoleStd : public IArchConsole {
|
||||
class ArchConsoleStd : public IArchConsole
|
||||
{
|
||||
public:
|
||||
ArchConsoleStd() {}
|
||||
virtual ~ArchConsoleStd() {}
|
||||
ArchConsoleStd()
|
||||
{
|
||||
}
|
||||
virtual ~ArchConsoleStd()
|
||||
{
|
||||
}
|
||||
|
||||
// IArchConsole overrides
|
||||
virtual void openConsole(const char *title) {}
|
||||
virtual void closeConsole() {}
|
||||
virtual void showConsole(bool) {}
|
||||
virtual void openConsole(const char *title)
|
||||
{
|
||||
}
|
||||
virtual void closeConsole()
|
||||
{
|
||||
}
|
||||
virtual void showConsole(bool)
|
||||
{
|
||||
}
|
||||
virtual void writeConsole(ELevel level, const char *);
|
||||
};
|
||||
|
||||
@ -22,35 +22,52 @@
|
||||
// ArchDaemonNone
|
||||
//
|
||||
|
||||
ArchDaemonNone::ArchDaemonNone() {
|
||||
ArchDaemonNone::ArchDaemonNone()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchDaemonNone::~ArchDaemonNone() {
|
||||
ArchDaemonNone::~ArchDaemonNone()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchDaemonNone::installDaemon(
|
||||
const char *, const char *, const char *, const char *, const char *) {
|
||||
void ArchDaemonNone::installDaemon(const char *, const char *, const char *, const char *, const char *)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchDaemonNone::uninstallDaemon(const char *) {
|
||||
void ArchDaemonNone::uninstallDaemon(const char *)
|
||||
{
|
||||
// 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
|
||||
// do any daemonizing.
|
||||
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
|
||||
function and returns its result.
|
||||
*/
|
||||
class ArchDaemonNone : public IArchDaemon {
|
||||
class ArchDaemonNone : public IArchDaemon
|
||||
{
|
||||
public:
|
||||
ArchDaemonNone();
|
||||
virtual ~ArchDaemonNone();
|
||||
|
||||
// IArchDaemon overrides
|
||||
virtual void installDaemon(
|
||||
const char *name, const char *description, const char *pathname,
|
||||
const char *commandLine, const char *dependencies);
|
||||
const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies
|
||||
);
|
||||
virtual void uninstallDaemon(const char *name);
|
||||
virtual int daemonize(const char *name, DaemonFunc func);
|
||||
virtual bool canInstallDaemon(const char *name);
|
||||
|
||||
@ -26,7 +26,8 @@
|
||||
This interface defines the console operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchConsole : public IInterface {
|
||||
class IArchConsole : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @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
|
||||
implement this interface.
|
||||
*/
|
||||
class IArchDaemon : public IInterface {
|
||||
class IArchDaemon : public IInterface
|
||||
{
|
||||
public:
|
||||
typedef int (*DaemonFunc)(int argc, const char **argv);
|
||||
|
||||
@ -48,8 +49,8 @@ public:
|
||||
the listed daemons. Throws an \c XArchDaemon exception on failure.
|
||||
*/
|
||||
virtual void installDaemon(
|
||||
const char *name, const char *description, const char *pathname,
|
||||
const char *commandLine, const char *dependencies) = 0;
|
||||
const char *name, const char *description, const char *pathname, const char *commandLine, const char *dependencies
|
||||
) = 0;
|
||||
|
||||
//! Uninstall daemon
|
||||
/*!
|
||||
|
||||
@ -27,7 +27,8 @@
|
||||
This interface defines the file system operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchFile : public IInterface {
|
||||
class IArchFile : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
@ -85,8 +86,7 @@ public:
|
||||
is longer than allowed by the system; we'll rely on the
|
||||
system calls to tell us that.
|
||||
*/
|
||||
virtual std::string
|
||||
concatPath(const std::string &prefix, const std::string &suffix) = 0;
|
||||
virtual std::string concatPath(const std::string &prefix, const std::string &suffix) = 0;
|
||||
|
||||
//@}
|
||||
//! Set the user's profile directory
|
||||
|
||||
@ -26,7 +26,8 @@
|
||||
This interface defines the logging operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchLog : public IInterface {
|
||||
class IArchLog : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
@ -68,7 +68,8 @@ typedef ArchThreadImpl *ArchThread;
|
||||
This interface defines the multithreading operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchMultithread : public IInterface {
|
||||
class IArchMultithread : public IInterface
|
||||
{
|
||||
public:
|
||||
//! Type of thread entry point
|
||||
typedef void *(*ThreadFunc)(void *);
|
||||
@ -79,7 +80,8 @@ public:
|
||||
Not all platforms support all signals. Unsupported signals are
|
||||
ignored.
|
||||
*/
|
||||
enum ESignal {
|
||||
enum ESignal
|
||||
{
|
||||
kINTERRUPT, //!< Interrupt (e.g. Ctrl+C)
|
||||
kTERMINATE, //!< Terminate (e.g. Ctrl+Break)
|
||||
kHANGUP, //!< Hangup (SIGHUP)
|
||||
|
||||
@ -60,24 +60,31 @@ typedef ArchNetAddressImpl *ArchNetAddress;
|
||||
This interface defines the networking operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchNetwork : public IInterface {
|
||||
class IArchNetwork : public IInterface
|
||||
{
|
||||
public:
|
||||
//! Supported address families
|
||||
enum EAddressFamily {
|
||||
enum EAddressFamily
|
||||
{
|
||||
kUNKNOWN,
|
||||
kINET,
|
||||
kINET6,
|
||||
};
|
||||
|
||||
//! Supported socket types
|
||||
enum ESocketType { kDGRAM, kSTREAM };
|
||||
enum ESocketType
|
||||
{
|
||||
kDGRAM,
|
||||
kSTREAM
|
||||
};
|
||||
|
||||
//! Events for \c poll()
|
||||
/*!
|
||||
Events for \c poll() are bitmasks and can be combined using the
|
||||
bitwise operators.
|
||||
*/
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
kPOLLIN = 1, //!< Socket is readable
|
||||
kPOLLOUT = 2, //!< Socket is writable
|
||||
kPOLLERR = 4, //!< The socket is in an error state
|
||||
@ -85,7 +92,8 @@ public:
|
||||
};
|
||||
|
||||
//! A socket query for \c poll()
|
||||
class PollEntry {
|
||||
class PollEntry
|
||||
{
|
||||
public:
|
||||
//! The socket to query
|
||||
ArchSocket m_socket;
|
||||
|
||||
@ -25,7 +25,8 @@
|
||||
This interface defines the sleep operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchSleep : public IInterface {
|
||||
class IArchSleep : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
@ -30,15 +30,16 @@ static ArchMutex s_mutex = NULL;
|
||||
// use C library non-reentrant multibyte conversion with mutex
|
||||
//
|
||||
|
||||
IArchString::~IArchString() {
|
||||
IArchString::~IArchString()
|
||||
{
|
||||
if (s_mutex != NULL) {
|
||||
ARCH->closeMutex(s_mutex);
|
||||
s_mutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int IArchString::convStringWCToMB(
|
||||
char *dst, const wchar_t *src, UInt32 n, bool *errors) {
|
||||
int IArchString::convStringWCToMB(char *dst, const wchar_t *src, UInt32 n, bool *errors)
|
||||
{
|
||||
ptrdiff_t len = 0;
|
||||
|
||||
bool dummyErrors;
|
||||
@ -94,8 +95,8 @@ int IArchString::convStringWCToMB(
|
||||
return static_cast<int>(len);
|
||||
}
|
||||
|
||||
int IArchString::convStringMBToWC(
|
||||
wchar_t *dst, const char *src, UInt32 n, bool *errors) {
|
||||
int IArchString::convStringMBToWC(wchar_t *dst, const char *src, UInt32 n, bool *errors)
|
||||
{
|
||||
ptrdiff_t len = 0;
|
||||
wchar_t dummy;
|
||||
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
This interface defines the string operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchString : public IInterface {
|
||||
class IArchString : public IInterface
|
||||
{
|
||||
public:
|
||||
IArchString() = default;
|
||||
IArchString(const IArchString &) = delete;
|
||||
@ -42,7 +43,8 @@ public:
|
||||
/*!
|
||||
The known wide character encodings
|
||||
*/
|
||||
enum EWideCharEncoding {
|
||||
enum EWideCharEncoding
|
||||
{
|
||||
kUCS2, //!< The UCS-2 encoding
|
||||
kUCS4, //!< The UCS-4 encoding
|
||||
kUTF16, //!< The UTF-16 encoding
|
||||
|
||||
@ -25,7 +25,8 @@
|
||||
/*!
|
||||
This interface defines operations for querying system info.
|
||||
*/
|
||||
class IArchSystem : public IInterface {
|
||||
class IArchSystem : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name accessors
|
||||
//@{
|
||||
@ -54,7 +55,6 @@ public:
|
||||
/*!
|
||||
Writes a Deskflow setting from the system.
|
||||
*/
|
||||
virtual void setting(
|
||||
const std::string &valueName, const std::string &valueString) const = 0;
|
||||
virtual void setting(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
|
||||
though each operation can be a no-op.
|
||||
*/
|
||||
class IArchTaskBar : public IInterface {
|
||||
class IArchTaskBar : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
@ -30,7 +30,8 @@ This interface defines the task bar icon event handlers required
|
||||
by deskflow. Each architecture must implement this interface
|
||||
though each operation can be a no-op.
|
||||
*/
|
||||
class IArchTaskBarReceiver : public IInterface {
|
||||
class IArchTaskBarReceiver : public IInterface
|
||||
{
|
||||
public:
|
||||
// Icon data is architecture dependent
|
||||
typedef void *Icon;
|
||||
@ -92,7 +93,9 @@ public:
|
||||
|
||||
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
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchTime : public IInterface {
|
||||
class IArchTime : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @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
|
||||
exceptions must always be rethrown by clients when caught.
|
||||
*/
|
||||
class XThread {};
|
||||
class XThread
|
||||
{
|
||||
};
|
||||
|
||||
//! Thread exception to cancel
|
||||
/*!
|
||||
Thrown to cancel a thread. Clients must not throw this type, but
|
||||
must rethrow it if caught (by XThreadCancel, XThread, or ...).
|
||||
*/
|
||||
class XThreadCancel : public XThread {};
|
||||
class XThreadCancel : public 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
|
||||
cleanup but before leaving or returning from the handler.
|
||||
*/
|
||||
#define RETHROW_XTHREAD \
|
||||
try { \
|
||||
throw; \
|
||||
} catch (XThread &) { \
|
||||
throw; \
|
||||
} catch (...) { \
|
||||
#define RETHROW_XTHREAD \
|
||||
try { \
|
||||
throw; \
|
||||
} catch (XThread &) { \
|
||||
throw; \
|
||||
} catch (...) { \
|
||||
}
|
||||
|
||||
//! 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
|
||||
string for that error code.
|
||||
*/
|
||||
class XArchEval {
|
||||
class XArchEval
|
||||
{
|
||||
public:
|
||||
XArchEval() {}
|
||||
virtual ~XArchEval() _NOEXCEPT {}
|
||||
XArchEval()
|
||||
{
|
||||
}
|
||||
virtual ~XArchEval() _NOEXCEPT
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::string eval() const = 0;
|
||||
};
|
||||
|
||||
//! Generic exception architecture dependent library
|
||||
class XArch : public std::runtime_error {
|
||||
class XArch : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
XArch(XArchEval *adopted) : std::runtime_error(adopted->eval()) {
|
||||
XArch(XArchEval *adopted) : std::runtime_error(adopted->eval())
|
||||
{
|
||||
delete adopted;
|
||||
}
|
||||
XArch(const std::string &msg) : std::runtime_error(msg) {}
|
||||
virtual ~XArch() _NOEXCEPT {}
|
||||
XArch(const std::string &msg) : std::runtime_error(msg)
|
||||
{
|
||||
}
|
||||
virtual ~XArch() _NOEXCEPT
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// Macro to declare XArch derived types
|
||||
#define XARCH_SUBCLASS(name_, super_) \
|
||||
class name_ : public super_ { \
|
||||
public: \
|
||||
name_(XArchEval *adoptedEvaluator) : super_(adoptedEvaluator) {} \
|
||||
name_(const std::string &msg) : super_(msg) {} \
|
||||
#define XARCH_SUBCLASS(name_, super_) \
|
||||
class name_ : public super_ \
|
||||
{ \
|
||||
public: \
|
||||
name_(XArchEval *adoptedEvaluator) : super_(adoptedEvaluator) \
|
||||
{ \
|
||||
} \
|
||||
name_(const std::string &msg) : super_(msg) \
|
||||
{ \
|
||||
} \
|
||||
}
|
||||
|
||||
//! Generic network exception
|
||||
|
||||
@ -37,12 +37,14 @@
|
||||
// implementations. hopefully at least the C++ compiler has
|
||||
// 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);
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -18,6 +18,10 @@
|
||||
|
||||
#include "arch/unix/ArchConsoleUnix.h"
|
||||
|
||||
ArchConsoleUnix::ArchConsoleUnix() {}
|
||||
ArchConsoleUnix::ArchConsoleUnix()
|
||||
{
|
||||
}
|
||||
|
||||
ArchConsoleUnix::~ArchConsoleUnix() {}
|
||||
ArchConsoleUnix::~ArchConsoleUnix()
|
||||
{
|
||||
}
|
||||
|
||||
@ -22,7 +22,8 @@
|
||||
|
||||
#define ARCH_CONSOLE ArchConsoleUnix
|
||||
|
||||
class ArchConsoleUnix : public ArchConsoleStd {
|
||||
class ArchConsoleUnix : public ArchConsoleStd
|
||||
{
|
||||
public:
|
||||
ArchConsoleUnix();
|
||||
virtual ~ArchConsoleUnix();
|
||||
|
||||
@ -32,11 +32,13 @@
|
||||
// ArchDaemonUnix
|
||||
//
|
||||
|
||||
ArchDaemonUnix::ArchDaemonUnix() {
|
||||
ArchDaemonUnix::ArchDaemonUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchDaemonUnix::~ArchDaemonUnix() {
|
||||
ArchDaemonUnix::~ArchDaemonUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@ -45,7 +47,8 @@ ArchDaemonUnix::~ArchDaemonUnix() {
|
||||
// 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),
|
||||
// so need to exec a copy of the program that doesn't fork so isn't limited.
|
||||
int execSelfNonDaemonized() {
|
||||
int execSelfNonDaemonized()
|
||||
{
|
||||
extern char **NXArgv;
|
||||
char **selfArgv = NXArgv;
|
||||
|
||||
@ -55,11 +58,15 @@ int execSelfNonDaemonized() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool alreadyDaemonized() { return getenv("_DESKFLOW_DAEMONIZED") != NULL; }
|
||||
bool alreadyDaemonized()
|
||||
{
|
||||
return getenv("_DESKFLOW_DAEMONIZED") != NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int ArchDaemonUnix::daemonize(const char *name, DaemonFunc func) {
|
||||
int ArchDaemonUnix::daemonize(const char *name, DaemonFunc func)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
if (alreadyDaemonized())
|
||||
return func(1, &name);
|
||||
|
||||
@ -24,7 +24,8 @@
|
||||
#define ARCH_DAEMON ArchDaemonUnix
|
||||
|
||||
//! Unix implementation of IArchDaemon
|
||||
class ArchDaemonUnix : public ArchDaemonNone {
|
||||
class ArchDaemonUnix : public ArchDaemonNone
|
||||
{
|
||||
public:
|
||||
ArchDaemonUnix();
|
||||
virtual ~ArchDaemonUnix();
|
||||
|
||||
@ -29,15 +29,18 @@
|
||||
// ArchFileUnix
|
||||
//
|
||||
|
||||
ArchFileUnix::ArchFileUnix() {
|
||||
ArchFileUnix::ArchFileUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchFileUnix::~ArchFileUnix() {
|
||||
ArchFileUnix::~ArchFileUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
const char *ArchFileUnix::getBasename(const char *pathname) {
|
||||
const char *ArchFileUnix::getBasename(const char *pathname)
|
||||
{
|
||||
if (pathname == 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;
|
||||
std::string dir;
|
||||
#if HAVE_GETPWUID_R
|
||||
@ -76,9 +80,13 @@ std::string ArchFileUnix::getUserDirectory() {
|
||||
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
|
||||
return "/usr/bin";
|
||||
#else
|
||||
@ -86,9 +94,13 @@ std::string ArchFileUnix::getInstalledDirectory() {
|
||||
#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()) {
|
||||
return m_pluginDirectory;
|
||||
}
|
||||
@ -100,7 +112,8 @@ std::string ArchFileUnix::getPluginDirectory() {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string ArchFileUnix::getProfileDirectory() {
|
||||
std::string ArchFileUnix::getProfileDirectory()
|
||||
{
|
||||
if (!m_profileDirectory.empty()) {
|
||||
return m_profileDirectory;
|
||||
} else {
|
||||
@ -118,8 +131,8 @@ std::string ArchFileUnix::getProfileDirectory() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
ArchFileUnix::concatPath(const std::string &prefix, const std::string &suffix) {
|
||||
std::string ArchFileUnix::concatPath(const std::string &prefix, const std::string &suffix)
|
||||
{
|
||||
std::string path;
|
||||
path.reserve(prefix.size() + 1 + suffix.size());
|
||||
path += prefix;
|
||||
@ -130,10 +143,12 @@ ArchFileUnix::concatPath(const std::string &prefix, const std::string &suffix) {
|
||||
return path;
|
||||
}
|
||||
|
||||
void ArchFileUnix::setProfileDirectory(const String &s) {
|
||||
void ArchFileUnix::setProfileDirectory(const String &s)
|
||||
{
|
||||
m_profileDirectory = s;
|
||||
}
|
||||
|
||||
void ArchFileUnix::setPluginDirectory(const String &s) {
|
||||
void ArchFileUnix::setPluginDirectory(const String &s)
|
||||
{
|
||||
m_pluginDirectory = s;
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_FILE ArchFileUnix
|
||||
|
||||
//! Unix implementation of IArchFile
|
||||
class ArchFileUnix : public IArchFile {
|
||||
class ArchFileUnix : public IArchFile
|
||||
{
|
||||
public:
|
||||
ArchFileUnix();
|
||||
virtual ~ArchFileUnix();
|
||||
@ -36,8 +37,7 @@ public:
|
||||
virtual std::string getLogDirectory();
|
||||
virtual std::string getPluginDirectory();
|
||||
virtual std::string getProfileDirectory();
|
||||
virtual std::string
|
||||
concatPath(const std::string &prefix, const std::string &suffix);
|
||||
virtual std::string concatPath(const std::string &prefix, const std::string &suffix);
|
||||
virtual void setProfileDirectory(const String &s);
|
||||
virtual void setPluginDirectory(const String &s);
|
||||
|
||||
|
||||
@ -24,23 +24,33 @@
|
||||
// ArchLogUnix
|
||||
//
|
||||
|
||||
ArchLogUnix::ArchLogUnix() {
|
||||
ArchLogUnix::ArchLogUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchLogUnix::~ArchLogUnix() {
|
||||
ArchLogUnix::~ArchLogUnix()
|
||||
{
|
||||
// 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
|
||||
}
|
||||
|
||||
void ArchLogUnix::writeLog(ELevel level, const char *msg) {
|
||||
void ArchLogUnix::writeLog(ELevel level, const char *msg)
|
||||
{
|
||||
// convert level
|
||||
int priority;
|
||||
switch (level) {
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_LOG ArchLogUnix
|
||||
|
||||
//! Unix implementation of IArchLog
|
||||
class ArchLogUnix : public IArchLog {
|
||||
class ArchLogUnix : public IArchLog
|
||||
{
|
||||
public:
|
||||
ArchLogUnix();
|
||||
virtual ~ArchLogUnix();
|
||||
|
||||
@ -47,7 +47,8 @@
|
||||
#define HAVE_POSIX_SIGWAIT 1
|
||||
#endif
|
||||
|
||||
static void setSignalSet(sigset_t *sigset) {
|
||||
static void setSignalSet(sigset_t *sigset)
|
||||
{
|
||||
sigemptyset(sigset);
|
||||
sigaddset(sigset, SIGHUP);
|
||||
sigaddset(sigset, SIGINT);
|
||||
@ -59,7 +60,8 @@ static void setSignalSet(sigset_t *sigset) {
|
||||
// ArchThreadImpl
|
||||
//
|
||||
|
||||
class ArchThreadImpl {
|
||||
class ArchThreadImpl
|
||||
{
|
||||
public:
|
||||
ArchThreadImpl();
|
||||
|
||||
@ -85,7 +87,8 @@ ArchThreadImpl::ArchThreadImpl()
|
||||
m_cancelling(false),
|
||||
m_exited(false),
|
||||
m_result(NULL),
|
||||
m_networkData(NULL) {
|
||||
m_networkData(NULL)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@ -95,9 +98,8 @@ ArchThreadImpl::ArchThreadImpl()
|
||||
|
||||
ArchMultithreadPosix *ArchMultithreadPosix::s_instance = NULL;
|
||||
|
||||
ArchMultithreadPosix::ArchMultithreadPosix()
|
||||
: m_newThreadCalled(false),
|
||||
m_nextID(0) {
|
||||
ArchMultithreadPosix::ArchMultithreadPosix() : m_newThreadCalled(false), m_nextID(0)
|
||||
{
|
||||
assert(s_instance == NULL);
|
||||
|
||||
s_instance = this;
|
||||
@ -143,30 +145,37 @@ ArchMultithreadPosix::ArchMultithreadPosix()
|
||||
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
|
||||
}
|
||||
|
||||
ArchMultithreadPosix::~ArchMultithreadPosix() {
|
||||
ArchMultithreadPosix::~ArchMultithreadPosix()
|
||||
{
|
||||
assert(s_instance != NULL);
|
||||
|
||||
closeMutex(m_threadMutex);
|
||||
s_instance = NULL;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data) {
|
||||
void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
ArchThreadImpl *thread = find(pthread_self());
|
||||
thread->m_networkData = data;
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::getNetworkDataForThread(ArchThread thread) {
|
||||
void *ArchMultithreadPosix::getNetworkDataForThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
void *data = thread->m_networkData;
|
||||
unlockMutex(m_threadMutex);
|
||||
return data;
|
||||
}
|
||||
|
||||
ArchMultithreadPosix *ArchMultithreadPosix::getInstance() { return s_instance; }
|
||||
ArchMultithreadPosix *ArchMultithreadPosix::getInstance()
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
ArchCond ArchMultithreadPosix::newCondVar() {
|
||||
ArchCond ArchMultithreadPosix::newCondVar()
|
||||
{
|
||||
ArchCondImpl *cond = new ArchCondImpl;
|
||||
int status = pthread_cond_init(&cond->m_cond, NULL);
|
||||
(void)status;
|
||||
@ -174,27 +183,30 @@ ArchCond ArchMultithreadPosix::newCondVar() {
|
||||
return cond;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::closeCondVar(ArchCond cond) {
|
||||
void ArchMultithreadPosix::closeCondVar(ArchCond cond)
|
||||
{
|
||||
int status = pthread_cond_destroy(&cond->m_cond);
|
||||
(void)status;
|
||||
assert(status == 0);
|
||||
delete cond;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::signalCondVar(ArchCond cond) {
|
||||
void ArchMultithreadPosix::signalCondVar(ArchCond cond)
|
||||
{
|
||||
int status = pthread_cond_signal(&cond->m_cond);
|
||||
(void)status;
|
||||
assert(status == 0);
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::broadcastCondVar(ArchCond cond) {
|
||||
void ArchMultithreadPosix::broadcastCondVar(ArchCond cond)
|
||||
{
|
||||
int status = pthread_cond_broadcast(&cond->m_cond);
|
||||
(void)status;
|
||||
assert(status == 0);
|
||||
}
|
||||
|
||||
bool ArchMultithreadPosix::waitCondVar(
|
||||
ArchCond cond, ArchMutex mutex, double timeout) {
|
||||
bool ArchMultithreadPosix::waitCondVar(ArchCond cond, ArchMutex mutex, double timeout)
|
||||
{
|
||||
// we can't wait on a condition variable and also wake it up for
|
||||
// cancellation since we don't use posix cancellation. so we
|
||||
// must wake up periodically to check for cancellation. we
|
||||
@ -227,8 +239,7 @@ bool ArchMultithreadPosix::waitCondVar(
|
||||
}
|
||||
|
||||
// wait
|
||||
int status =
|
||||
pthread_cond_timedwait(&cond->m_cond, &mutex->m_mutex, &finalTime);
|
||||
int status = pthread_cond_timedwait(&cond->m_cond, &mutex->m_mutex, &finalTime);
|
||||
|
||||
// check for cancel again
|
||||
testCancelThread();
|
||||
@ -247,7 +258,8 @@ bool ArchMultithreadPosix::waitCondVar(
|
||||
}
|
||||
}
|
||||
|
||||
ArchMutex ArchMultithreadPosix::newMutex() {
|
||||
ArchMutex ArchMultithreadPosix::newMutex()
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
int status = pthread_mutexattr_init(&attr);
|
||||
assert(status == 0);
|
||||
@ -257,14 +269,16 @@ ArchMutex ArchMultithreadPosix::newMutex() {
|
||||
return mutex;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::closeMutex(ArchMutex mutex) {
|
||||
void ArchMultithreadPosix::closeMutex(ArchMutex mutex)
|
||||
{
|
||||
int status = pthread_mutex_destroy(&mutex->m_mutex);
|
||||
(void)status;
|
||||
assert(status == 0);
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::lockMutex(ArchMutex mutex) {
|
||||
void ArchMultithreadPosix::lockMutex(ArchMutex mutex)
|
||||
{
|
||||
int status = pthread_mutex_lock(&mutex->m_mutex);
|
||||
|
||||
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
|
||||
// to solve possible lock order reversal.
|
||||
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);
|
||||
|
||||
// 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;
|
||||
int status = pthread_attr_init(&attr);
|
||||
if (status == 0) {
|
||||
status = pthread_create(
|
||||
&thread->m_thread, &attr, &ArchMultithreadPosix::threadFunc, thread);
|
||||
status = pthread_create(&thread->m_thread, &attr, &ArchMultithreadPosix::threadFunc, thread);
|
||||
pthread_attr_destroy(&attr);
|
||||
}
|
||||
|
||||
@ -359,7 +374,8 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data) {
|
||||
return thread;
|
||||
}
|
||||
|
||||
ArchThread ArchMultithreadPosix::newCurrentThread() {
|
||||
ArchThread ArchMultithreadPosix::newCurrentThread()
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
ArchThreadImpl *thread = find(pthread_self());
|
||||
unlockMutex(m_threadMutex);
|
||||
@ -367,7 +383,8 @@ ArchThread ArchMultithreadPosix::newCurrentThread() {
|
||||
return thread;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::closeThread(ArchThread thread) {
|
||||
void ArchMultithreadPosix::closeThread(ArchThread thread)
|
||||
{
|
||||
assert(thread != NULL);
|
||||
|
||||
// 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);
|
||||
return thread;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::cancelThread(ArchThread thread) {
|
||||
void ArchMultithreadPosix::cancelThread(ArchThread thread)
|
||||
{
|
||||
assert(thread != NULL);
|
||||
|
||||
// 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);
|
||||
|
||||
// FIXME
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::testCancelThread() {
|
||||
void ArchMultithreadPosix::testCancelThread()
|
||||
{
|
||||
// find current thread
|
||||
lockMutex(m_threadMutex);
|
||||
ArchThreadImpl *thread = findNoRef(pthread_self());
|
||||
@ -427,7 +448,8 @@ void ArchMultithreadPosix::testCancelThread() {
|
||||
testCancelThreadImpl(thread);
|
||||
}
|
||||
|
||||
bool ArchMultithreadPosix::wait(ArchThread target, double timeout) {
|
||||
bool ArchMultithreadPosix::wait(ArchThread target, double timeout)
|
||||
{
|
||||
assert(target != NULL);
|
||||
|
||||
lockMutex(m_threadMutex);
|
||||
@ -480,39 +502,42 @@ bool ArchMultithreadPosix::wait(ArchThread target, double timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
bool ArchMultithreadPosix::isSameThread(
|
||||
ArchThread thread1, ArchThread thread2) {
|
||||
bool ArchMultithreadPosix::isSameThread(ArchThread thread1, ArchThread thread2)
|
||||
{
|
||||
return (thread1 == thread2);
|
||||
}
|
||||
|
||||
bool ArchMultithreadPosix::isExitedThread(ArchThread thread) {
|
||||
bool ArchMultithreadPosix::isExitedThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
bool exited = thread->m_exited;
|
||||
unlockMutex(m_threadMutex);
|
||||
return exited;
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::getResultOfThread(ArchThread thread) {
|
||||
void *ArchMultithreadPosix::getResultOfThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
void *result = thread->m_result;
|
||||
unlockMutex(m_threadMutex);
|
||||
return result;
|
||||
}
|
||||
|
||||
IArchMultithread::ThreadID
|
||||
ArchMultithreadPosix::getIDOfThread(ArchThread thread) {
|
||||
IArchMultithread::ThreadID ArchMultithreadPosix::getIDOfThread(ArchThread thread)
|
||||
{
|
||||
return thread->m_id;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::setSignalHandler(
|
||||
ESignal signal, SignalFunc func, void *userData) {
|
||||
void ArchMultithreadPosix::setSignalHandler(ESignal signal, SignalFunc func, void *userData)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
m_signalFunc[signal] = func;
|
||||
m_signalUserData[signal] = userData;
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::raiseSignal(ESignal signal) {
|
||||
void ArchMultithreadPosix::raiseSignal(ESignal signal)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
if (m_signalFunc[signal] != NULL) {
|
||||
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
||||
@ -523,7 +548,8 @@ void ArchMultithreadPosix::raiseSignal(ESignal signal) {
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::startSignalHandler() {
|
||||
void ArchMultithreadPosix::startSignalHandler()
|
||||
{
|
||||
// set signal mask. the main thread blocks these signals and
|
||||
// the signal handler thread will listen for them.
|
||||
sigset_t sigset, oldsigset;
|
||||
@ -537,9 +563,7 @@ void ArchMultithreadPosix::startSignalHandler() {
|
||||
pthread_attr_t attr;
|
||||
int status = pthread_attr_init(&attr);
|
||||
if (status == 0) {
|
||||
status = pthread_create(
|
||||
&m_signalThread, &attr, &ArchMultithreadPosix::threadSignalHandler,
|
||||
NULL);
|
||||
status = pthread_create(&m_signalThread, &attr, &ArchMultithreadPosix::threadSignalHandler, NULL);
|
||||
pthread_attr_destroy(&attr);
|
||||
}
|
||||
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);
|
||||
if (impl != NULL) {
|
||||
refThread(impl);
|
||||
@ -557,10 +582,10 @@ ArchThreadImpl *ArchMultithreadPosix::find(pthread_t thread) {
|
||||
return impl;
|
||||
}
|
||||
|
||||
ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread) {
|
||||
ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread)
|
||||
{
|
||||
// linear search
|
||||
for (ThreadList::const_iterator index = m_threadList.begin();
|
||||
index != m_threadList.end(); ++index) {
|
||||
for (ThreadList::const_iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
||||
if ((*index)->m_thread == thread) {
|
||||
return *index;
|
||||
}
|
||||
@ -568,7 +593,8 @@ ArchThreadImpl *ArchMultithreadPosix::findNoRef(pthread_t thread) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::insert(ArchThreadImpl *thread) {
|
||||
void ArchMultithreadPosix::insert(ArchThreadImpl *thread)
|
||||
{
|
||||
assert(thread != NULL);
|
||||
|
||||
// thread shouldn't already be on the list
|
||||
@ -584,9 +610,9 @@ void ArchMultithreadPosix::insert(ArchThreadImpl *thread) {
|
||||
m_threadList.push_back(thread);
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::erase(ArchThreadImpl *thread) {
|
||||
for (ThreadList::iterator index = m_threadList.begin();
|
||||
index != m_threadList.end(); ++index) {
|
||||
void ArchMultithreadPosix::erase(ArchThreadImpl *thread)
|
||||
{
|
||||
for (ThreadList::iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
||||
if (*index == thread) {
|
||||
m_threadList.erase(index);
|
||||
break;
|
||||
@ -594,13 +620,15 @@ void ArchMultithreadPosix::erase(ArchThreadImpl *thread) {
|
||||
}
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::refThread(ArchThreadImpl *thread) {
|
||||
void ArchMultithreadPosix::refThread(ArchThreadImpl *thread)
|
||||
{
|
||||
assert(thread != NULL);
|
||||
assert(findNoRef(thread->m_thread) != NULL);
|
||||
++thread->m_refCount;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread) {
|
||||
void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread)
|
||||
{
|
||||
assert(thread != NULL);
|
||||
|
||||
// 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
|
||||
ArchThreadImpl *thread = static_cast<ArchThreadImpl *>(vrep);
|
||||
|
||||
@ -634,7 +663,8 @@ void *ArchMultithreadPosix::threadFunc(void *vrep) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::doThreadFunc(ArchThread thread) {
|
||||
void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||
{
|
||||
// default priority is slightly below normal
|
||||
setPriorityOfThread(thread, 1);
|
||||
|
||||
@ -671,11 +701,13 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread) {
|
||||
closeThread(thread);
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::threadCancel(int) {
|
||||
void ArchMultithreadPosix::threadCancel(int)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::threadSignalHandler(void *) {
|
||||
void *ArchMultithreadPosix::threadSignalHandler(void *)
|
||||
{
|
||||
// detach
|
||||
pthread_detach(pthread_self());
|
||||
|
||||
|
||||
@ -25,18 +25,21 @@
|
||||
|
||||
#define ARCH_MULTITHREAD ArchMultithreadPosix
|
||||
|
||||
class ArchCondImpl {
|
||||
class ArchCondImpl
|
||||
{
|
||||
public:
|
||||
pthread_cond_t m_cond;
|
||||
};
|
||||
|
||||
class ArchMutexImpl {
|
||||
class ArchMutexImpl
|
||||
{
|
||||
public:
|
||||
pthread_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
//! Posix implementation of IArchMultithread
|
||||
class ArchMultithreadPosix : public IArchMultithread {
|
||||
class ArchMultithreadPosix : public IArchMultithread
|
||||
{
|
||||
public:
|
||||
ArchMultithreadPosix();
|
||||
ArchMultithreadPosix(ArchMultithreadPosix const &) = delete;
|
||||
|
||||
@ -52,7 +52,8 @@ static const int s_type[] = {SOCK_DGRAM, SOCK_STREAM};
|
||||
#if !HAVE_INET_ATON
|
||||
// parse dotted quad addresses. we don't bother with the weird BSD'ism
|
||||
// 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;
|
||||
if (sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
|
||||
return 0;
|
||||
@ -73,44 +74,53 @@ static in_addr_t inet_aton(const char *cp, struct in_addr *inp) {
|
||||
// ArchNetworkBSD::Deps
|
||||
//
|
||||
|
||||
void ArchNetworkBSD::Deps::sleep(double seconds) {
|
||||
void ArchNetworkBSD::Deps::sleep(double 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);
|
||||
}
|
||||
|
||||
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
|
||||
// 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.
|
||||
return std::shared_ptr<struct pollfd[]>(
|
||||
new struct pollfd[n], std::default_delete<struct pollfd[]>());
|
||||
return std::shared_ptr<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);
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::Deps::testCancelThread() { ARCH->testCancelThread(); }
|
||||
void ArchNetworkBSD::Deps::testCancelThread()
|
||||
{
|
||||
ARCH->testCancelThread();
|
||||
}
|
||||
|
||||
//
|
||||
// ArchNetworkBSD
|
||||
//
|
||||
|
||||
ArchNetworkBSD::~ArchNetworkBSD() {
|
||||
ArchNetworkBSD::~ArchNetworkBSD()
|
||||
{
|
||||
if (m_mutex)
|
||||
ARCH->closeMutex(m_mutex);
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::init() {
|
||||
void ArchNetworkBSD::init()
|
||||
{
|
||||
// create mutex to make some calls thread safe
|
||||
m_mutex = ARCH->newMutex();
|
||||
}
|
||||
|
||||
ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type) {
|
||||
ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type)
|
||||
{
|
||||
// create socket
|
||||
int fd = socket(s_family[family], s_type[type], 0);
|
||||
if (fd == -1) {
|
||||
@ -130,7 +140,8 @@ ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type) {
|
||||
return newSocket;
|
||||
}
|
||||
|
||||
ArchSocket ArchNetworkBSD::copySocket(ArchSocket s) {
|
||||
ArchSocket ArchNetworkBSD::copySocket(ArchSocket s)
|
||||
{
|
||||
assert(s != NULL);
|
||||
|
||||
// ref the socket and return it
|
||||
@ -140,7 +151,8 @@ ArchSocket ArchNetworkBSD::copySocket(ArchSocket s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::closeSocket(ArchSocket s) {
|
||||
void ArchNetworkBSD::closeSocket(ArchSocket s)
|
||||
{
|
||||
assert(s != NULL);
|
||||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
|
||||
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(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);
|
||||
|
||||
// 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);
|
||||
|
||||
// if user passed NULL in addr then use scratch space
|
||||
@ -250,7 +267,8 @@ ArchSocket ArchNetworkBSD::acceptSocket(ArchSocket s, ArchNetAddress *addr) {
|
||||
return newSocket;
|
||||
}
|
||||
|
||||
bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr) {
|
||||
bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr)
|
||||
{
|
||||
assert(s != NULL);
|
||||
assert(addr != NULL);
|
||||
|
||||
@ -266,7 +284,8 @@ bool ArchNetworkBSD::connectSocket(ArchSocket s, ArchNetAddress addr) {
|
||||
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);
|
||||
|
||||
// return if nothing to do
|
||||
@ -351,7 +370,8 @@ int ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout) {
|
||||
return n;
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::unblockPollSocket(ArchThread thread) {
|
||||
void ArchNetworkBSD::unblockPollSocket(ArchThread thread)
|
||||
{
|
||||
const int *unblockPipe = getUnblockPipeForThread(thread);
|
||||
if (unblockPipe != nullptr) {
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s) {
|
||||
void ArchNetworkBSD::throwErrorOnSocket(ArchSocket s)
|
||||
{
|
||||
assert(s != NULL);
|
||||
|
||||
// get the error from the socket layer
|
||||
int err = 0;
|
||||
auto size = static_cast<socklen_t>(sizeof(err));
|
||||
if (getsockopt(
|
||||
s->m_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<optval_t *>(&err),
|
||||
&size) == -1) {
|
||||
if (getsockopt(s->m_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<optval_t *>(&err), &size) == -1) {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
// get old state
|
||||
int oflag;
|
||||
auto size = static_cast<socklen_t>(sizeof(oflag));
|
||||
if (getsockopt(
|
||||
s->m_fd, IPPROTO_TCP, TCP_NODELAY,
|
||||
reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
||||
if (getsockopt(s->m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
||||
throwError(errno);
|
||||
}
|
||||
|
||||
int flag = noDelay ? 1 : 0;
|
||||
size = static_cast<socklen_t>(sizeof(flag));
|
||||
if (setsockopt(
|
||||
s->m_fd, IPPROTO_TCP, TCP_NODELAY,
|
||||
reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
||||
if (setsockopt(s->m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
||||
throwError(errno);
|
||||
}
|
||||
|
||||
return (oflag != 0);
|
||||
}
|
||||
|
||||
bool ArchNetworkBSD::setReuseAddrOnSocket(ArchSocket s, bool reuse) {
|
||||
bool ArchNetworkBSD::setReuseAddrOnSocket(ArchSocket s, bool reuse)
|
||||
{
|
||||
assert(s != NULL);
|
||||
|
||||
// get old state
|
||||
int oflag;
|
||||
auto size = static_cast<socklen_t>(sizeof(oflag));
|
||||
if (getsockopt(
|
||||
s->m_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
||||
if (getsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<optval_t *>(&oflag), &size) == -1) {
|
||||
throwError(errno);
|
||||
}
|
||||
|
||||
int flag = reuse ? 1 : 0;
|
||||
size = static_cast<socklen_t>(sizeof(flag));
|
||||
if (setsockopt(
|
||||
s->m_fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
||||
if (setsockopt(s->m_fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<optval_t *>(&flag), size) == -1) {
|
||||
throwError(errno);
|
||||
}
|
||||
|
||||
return (oflag != 0);
|
||||
}
|
||||
|
||||
std::string ArchNetworkBSD::getHostName() {
|
||||
std::string ArchNetworkBSD::getHostName()
|
||||
{
|
||||
char name[256];
|
||||
if (gethostname(name, sizeof(name)) == -1) {
|
||||
name[0] = '\0';
|
||||
@ -478,7 +495,8 @@ std::string ArchNetworkBSD::getHostName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family) {
|
||||
ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family)
|
||||
{
|
||||
// allocate address
|
||||
auto *addr = new ArchNetAddressImpl;
|
||||
|
||||
@ -509,15 +527,16 @@ ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family) {
|
||||
return addr;
|
||||
}
|
||||
|
||||
ArchNetAddress ArchNetworkBSD::copyAddr(ArchNetAddress addr) {
|
||||
ArchNetAddress ArchNetworkBSD::copyAddr(ArchNetAddress addr)
|
||||
{
|
||||
assert(addr != NULL);
|
||||
|
||||
// allocate and copy address
|
||||
return new ArchNetAddressImpl(*addr);
|
||||
}
|
||||
|
||||
std::vector<ArchNetAddress>
|
||||
ArchNetworkBSD::nameToAddr(const std::string &name) {
|
||||
std::vector<ArchNetAddress> ArchNetworkBSD::nameToAddr(const std::string &name)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
struct in6_addr serveraddr;
|
||||
|
||||
@ -553,8 +572,7 @@ ArchNetworkBSD::nameToAddr(const std::string &name) {
|
||||
addresses.back()->m_len = (socklen_t)sizeof(struct sockaddr_in6);
|
||||
}
|
||||
|
||||
memcpy(
|
||||
&addresses.back()->m_addr, address->ai_addr, addresses.back()->m_len);
|
||||
memcpy(&addresses.back()->m_addr, address->ai_addr, addresses.back()->m_len);
|
||||
}
|
||||
|
||||
freeaddrinfo(pResult);
|
||||
@ -563,22 +581,23 @@ ArchNetworkBSD::nameToAddr(const std::string &name) {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::closeAddr(ArchNetAddress addr) {
|
||||
void ArchNetworkBSD::closeAddr(ArchNetAddress addr)
|
||||
{
|
||||
assert(addr != NULL);
|
||||
|
||||
delete addr;
|
||||
}
|
||||
|
||||
std::string ArchNetworkBSD::addrToName(ArchNetAddress addr) {
|
||||
std::string ArchNetworkBSD::addrToName(ArchNetAddress addr)
|
||||
{
|
||||
assert(addr != NULL);
|
||||
|
||||
// mutexed name lookup (ugh)
|
||||
ARCH->lockMutex(m_mutex);
|
||||
char host[1024];
|
||||
char service[20];
|
||||
int ret = getnameinfo(
|
||||
TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host),
|
||||
service, sizeof(service), 0);
|
||||
int ret =
|
||||
getnameinfo(TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host), service, sizeof(service), 0);
|
||||
if (ret != 0) {
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
throwNameError(ret);
|
||||
@ -593,7 +612,8 @@ std::string ArchNetworkBSD::addrToName(ArchNetAddress addr) {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string ArchNetworkBSD::addrToString(ArchNetAddress addr) {
|
||||
std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||
{
|
||||
assert(addr != NULL);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
@ -620,8 +640,8 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr) {
|
||||
}
|
||||
}
|
||||
|
||||
IArchNetwork::EAddressFamily
|
||||
ArchNetworkBSD::getAddrFamily(ArchNetAddress addr) {
|
||||
IArchNetwork::EAddressFamily ArchNetworkBSD::getAddrFamily(ArchNetAddress addr)
|
||||
{
|
||||
assert(addr != NULL);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
return (
|
||||
ipAddr->sin_addr.s_addr == INADDR_ANY &&
|
||||
addr->m_len == static_cast<socklen_t>(sizeof(struct sockaddr_in)));
|
||||
return (ipAddr->sin_addr.s_addr == INADDR_ANY && addr->m_len == static_cast<socklen_t>(sizeof(struct sockaddr_in)));
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
@ -693,8 +714,9 @@ bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr) {
|
||||
return (
|
||||
addr->m_len == (socklen_t)sizeof(struct sockaddr_in6) &&
|
||||
memcmp(
|
||||
static_cast<const void *>(&ipAddr->sin6_addr),
|
||||
static_cast<const void *>(&in6addr_any), sizeof(in6_addr)) == 0);
|
||||
static_cast<const void *>(&ipAddr->sin6_addr), static_cast<const void *>(&in6addr_any), sizeof(in6_addr)
|
||||
) == 0
|
||||
);
|
||||
}
|
||||
|
||||
default:
|
||||
@ -703,12 +725,13 @@ bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
const int *ArchNetworkBSD::getUnblockPipe() {
|
||||
const int *ArchNetworkBSD::getUnblockPipe()
|
||||
{
|
||||
ArchMultithreadPosix *mt = ArchMultithreadPosix::getInstance();
|
||||
ArchThread thread = mt->newCurrentThread();
|
||||
const int *p = getUnblockPipeForThread(thread);
|
||||
@ -716,7 +739,8 @@ const int *ArchNetworkBSD::getUnblockPipe() {
|
||||
return p;
|
||||
}
|
||||
|
||||
const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread) {
|
||||
const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
|
||||
{
|
||||
ArchMultithreadPosix *mt = ArchMultithreadPosix::getInstance();
|
||||
auto *unblockPipe = static_cast<int *>(mt->getNetworkDataForThread(thread));
|
||||
if (unblockPipe == nullptr) {
|
||||
@ -737,7 +761,8 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread) {
|
||||
return unblockPipe;
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::throwError(int err) {
|
||||
void ArchNetworkBSD::throwError(int err)
|
||||
{
|
||||
switch (err) {
|
||||
case EINTR:
|
||||
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[] = {
|
||||
"The specified host is unknown",
|
||||
"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",
|
||||
"An unknown name server error occurred"};
|
||||
"The specified host is unknown", "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",
|
||||
"An unknown name server error occurred"
|
||||
};
|
||||
|
||||
switch (err) {
|
||||
case HOST_NOT_FOUND:
|
||||
|
||||
@ -30,7 +30,8 @@
|
||||
#if HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#else
|
||||
struct sockaddr_storage {
|
||||
struct sockaddr_storage
|
||||
{
|
||||
unsigned char ss_len; /* address length */
|
||||
unsigned char ss_family; /* [XSI] address family */
|
||||
char __ss_pad1[_SS_PAD1SIZE];
|
||||
@ -53,15 +54,19 @@ typedef int socklen_t;
|
||||
// compatible so we always use it.
|
||||
typedef char optval_t;
|
||||
|
||||
class ArchSocketImpl {
|
||||
class ArchSocketImpl
|
||||
{
|
||||
public:
|
||||
int m_fd;
|
||||
int m_refCount;
|
||||
};
|
||||
|
||||
class ArchNetAddressImpl {
|
||||
class ArchNetAddressImpl
|
||||
{
|
||||
public:
|
||||
ArchNetAddressImpl() : m_len(sizeof(m_addr)) {}
|
||||
ArchNetAddressImpl() : m_len(sizeof(m_addr))
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
struct sockaddr_storage m_addr;
|
||||
@ -69,10 +74,12 @@ public:
|
||||
};
|
||||
|
||||
//! Berkeley (BSD) sockets implementation of IArchNetwork
|
||||
class ArchNetworkBSD : public IArchNetwork {
|
||||
class ArchNetworkBSD : public IArchNetwork
|
||||
{
|
||||
|
||||
public:
|
||||
struct Deps {
|
||||
struct Deps
|
||||
{
|
||||
virtual ~Deps() = default;
|
||||
virtual void sleep(double);
|
||||
virtual int poll(struct pollfd *, nfds_t, int);
|
||||
@ -81,8 +88,9 @@ public:
|
||||
virtual void testCancelThread();
|
||||
};
|
||||
|
||||
explicit ArchNetworkBSD(std::shared_ptr<Deps> deps = std::make_shared<Deps>())
|
||||
: m_pDeps(deps) {}
|
||||
explicit ArchNetworkBSD(std::shared_ptr<Deps> deps = std::make_shared<Deps>()) : m_pDeps(deps)
|
||||
{
|
||||
}
|
||||
ArchNetworkBSD(ArchNetworkBSD const &) = delete;
|
||||
ArchNetworkBSD(ArchNetworkBSD &&) = delete;
|
||||
~ArchNetworkBSD() override;
|
||||
|
||||
@ -46,15 +46,18 @@
|
||||
// ArchSleepUnix
|
||||
//
|
||||
|
||||
ArchSleepUnix::ArchSleepUnix() {
|
||||
ArchSleepUnix::ArchSleepUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchSleepUnix::~ArchSleepUnix() {
|
||||
ArchSleepUnix::~ArchSleepUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchSleepUnix::sleep(double timeout) {
|
||||
void ArchSleepUnix::sleep(double timeout)
|
||||
{
|
||||
ARCH->testCancelThread();
|
||||
if (timeout < 0.0) {
|
||||
return;
|
||||
@ -78,8 +81,9 @@ void ArchSleepUnix::sleep(double timeout) {
|
||||
timeout2.tv_sec = static_cast<int>(timeLeft);
|
||||
timeout2.tv_usec = static_cast<int>(1.0e+6 * (timeLeft - timeout2.tv_sec));
|
||||
select(
|
||||
(SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL,
|
||||
SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG5 & timeout2);
|
||||
(SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG234 NULL,
|
||||
SELECT_TYPE_ARG5 & timeout2
|
||||
);
|
||||
ARCH->testCancelThread();
|
||||
timeLeft = timeout - (ARCH->time() - startTime);
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_SLEEP ArchSleepUnix
|
||||
|
||||
//! Unix implementation of IArchSleep
|
||||
class ArchSleepUnix : public IArchSleep {
|
||||
class ArchSleepUnix : public IArchSleep
|
||||
{
|
||||
public:
|
||||
ArchSleepUnix();
|
||||
virtual ~ArchSleepUnix();
|
||||
|
||||
@ -27,10 +27,15 @@
|
||||
#include "arch/multibyte.h"
|
||||
#include "arch/vsnprintf.h"
|
||||
|
||||
ArchStringUnix::ArchStringUnix() {}
|
||||
ArchStringUnix::ArchStringUnix()
|
||||
{
|
||||
}
|
||||
|
||||
ArchStringUnix::~ArchStringUnix() {}
|
||||
ArchStringUnix::~ArchStringUnix()
|
||||
{
|
||||
}
|
||||
|
||||
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding() {
|
||||
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding()
|
||||
{
|
||||
return kUCS4;
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_STRING ArchStringUnix
|
||||
|
||||
//! Unix implementation of IArchString
|
||||
class ArchStringUnix : public IArchString {
|
||||
class ArchStringUnix : public IArchString
|
||||
{
|
||||
public:
|
||||
ArchStringUnix();
|
||||
virtual ~ArchStringUnix();
|
||||
|
||||
@ -28,15 +28,18 @@
|
||||
// ArchSystemUnix
|
||||
//
|
||||
|
||||
ArchSystemUnix::ArchSystemUnix() {
|
||||
ArchSystemUnix::ArchSystemUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchSystemUnix::~ArchSystemUnix() {
|
||||
ArchSystemUnix::~ArchSystemUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
std::string ArchSystemUnix::getOSName() const {
|
||||
std::string ArchSystemUnix::getOSName() const
|
||||
{
|
||||
#if defined(HAVE_SYS_UTSNAME_H)
|
||||
struct utsname info;
|
||||
if (uname(&info) == 0) {
|
||||
@ -50,7 +53,8 @@ std::string ArchSystemUnix::getOSName() const {
|
||||
return "Unix";
|
||||
}
|
||||
|
||||
std::string ArchSystemUnix::getPlatformName() const {
|
||||
std::string ArchSystemUnix::getPlatformName() const
|
||||
{
|
||||
#if defined(HAVE_SYS_UTSNAME_H)
|
||||
struct utsname info;
|
||||
if (uname(&info) == 0) {
|
||||
@ -60,22 +64,26 @@ std::string ArchSystemUnix::getPlatformName() const {
|
||||
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";
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
bool ArchSystemUnix::DBusInhibitScreenCall(
|
||||
InhibitScreenServices serviceID, bool state, std::string &error) {
|
||||
bool ArchSystemUnix::DBusInhibitScreenCall(InhibitScreenServices serviceID, bool state, std::string &error)
|
||||
{
|
||||
error = "";
|
||||
static const std::array<QString, 2> services = {
|
||||
"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> services = {"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;
|
||||
|
||||
auto serviceNum = static_cast<uint8_t>(serviceID);
|
||||
@ -86,8 +94,7 @@ bool ArchSystemUnix::DBusInhibitScreenCall(
|
||||
return false;
|
||||
}
|
||||
|
||||
QDBusInterface screenSaverInterface(
|
||||
services[serviceNum], paths[serviceNum], services[serviceNum], bus);
|
||||
QDBusInterface screenSaverInterface(services[serviceNum], paths[serviceNum], services[serviceNum], bus);
|
||||
|
||||
if (!screenSaverInterface.isValid()) {
|
||||
error = "screen saver interface failed to initialize";
|
||||
@ -102,8 +109,8 @@ bool ArchSystemUnix::DBusInhibitScreenCall(
|
||||
}
|
||||
|
||||
reply = screenSaverInterface.call(
|
||||
"Inhibit", DESKFLOW_APP_NAME,
|
||||
"Sleep is manually prevented by the " DESKFLOW_APP_NAME " preferences");
|
||||
"Inhibit", DESKFLOW_APP_NAME, "Sleep is manually prevented by the " DESKFLOW_APP_NAME " preferences"
|
||||
);
|
||||
if (reply.isValid())
|
||||
cookies[serviceNum] = reply.value();
|
||||
} else {
|
||||
@ -117,8 +124,7 @@ bool ArchSystemUnix::DBusInhibitScreenCall(
|
||||
|
||||
if (!reply.isValid()) {
|
||||
QDBusError qerror = reply.error();
|
||||
error =
|
||||
qerror.name().toStdString() + " : " + qerror.message().toStdString();
|
||||
error = qerror.name().toStdString() + " : " + qerror.message().toStdString();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_SYSTEM ArchSystemUnix
|
||||
|
||||
//! Unix implementation of IArchString
|
||||
class ArchSystemUnix : public IArchSystem {
|
||||
class ArchSystemUnix : public IArchSystem
|
||||
{
|
||||
public:
|
||||
ArchSystemUnix();
|
||||
virtual ~ArchSystemUnix();
|
||||
@ -36,8 +37,11 @@ public:
|
||||
virtual std::string getLibsUsed(void) const;
|
||||
|
||||
#ifndef __APPLE__
|
||||
enum class InhibitScreenServices { kScreenSaver, kSessionManager };
|
||||
static bool DBusInhibitScreenCall(
|
||||
InhibitScreenServices serviceID, bool state, std::string &error);
|
||||
enum class InhibitScreenServices
|
||||
{
|
||||
kScreenSaver,
|
||||
kSessionManager
|
||||
};
|
||||
static bool DBusInhibitScreenCall(InhibitScreenServices serviceID, bool state, std::string &error);
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -22,22 +22,27 @@
|
||||
// ArchTaskBarXWindows
|
||||
//
|
||||
|
||||
ArchTaskBarXWindows::ArchTaskBarXWindows() {
|
||||
ArchTaskBarXWindows::ArchTaskBarXWindows()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchTaskBarXWindows::~ArchTaskBarXWindows() {
|
||||
ArchTaskBarXWindows::~ArchTaskBarXWindows()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchTaskBarXWindows::addReceiver(IArchTaskBarReceiver * /*receiver*/) {
|
||||
void ArchTaskBarXWindows::addReceiver(IArchTaskBarReceiver * /*receiver*/)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchTaskBarXWindows::removeReceiver(IArchTaskBarReceiver * /*receiver*/) {
|
||||
void ArchTaskBarXWindows::removeReceiver(IArchTaskBarReceiver * /*receiver*/)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchTaskBarXWindows::updateReceiver(IArchTaskBarReceiver * /*receiver*/) {
|
||||
void ArchTaskBarXWindows::updateReceiver(IArchTaskBarReceiver * /*receiver*/)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_TASKBAR ArchTaskBarXWindows
|
||||
|
||||
//! X11 implementation of IArchTaskBar
|
||||
class ArchTaskBarXWindows : public IArchTaskBar {
|
||||
class ArchTaskBarXWindows : public IArchTaskBar
|
||||
{
|
||||
public:
|
||||
ArchTaskBarXWindows();
|
||||
virtual ~ArchTaskBarXWindows();
|
||||
|
||||
@ -33,15 +33,18 @@
|
||||
// ArchTimeUnix
|
||||
//
|
||||
|
||||
ArchTimeUnix::ArchTimeUnix() {
|
||||
ArchTimeUnix::ArchTimeUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchTimeUnix::~ArchTimeUnix() {
|
||||
ArchTimeUnix::~ArchTimeUnix()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
double ArchTimeUnix::time() {
|
||||
double ArchTimeUnix::time()
|
||||
{
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#define ARCH_TIME ArchTimeUnix
|
||||
|
||||
//! Generic Unix implementation of IArchTime
|
||||
class ArchTimeUnix : public IArchTime {
|
||||
class ArchTimeUnix : public IArchTime
|
||||
{
|
||||
public:
|
||||
ArchTimeUnix();
|
||||
virtual ~ArchTimeUnix();
|
||||
|
||||
@ -24,7 +24,8 @@
|
||||
// XArchEvalUnix
|
||||
//
|
||||
|
||||
std::string XArchEvalUnix::eval() const {
|
||||
std::string XArchEvalUnix::eval() const
|
||||
{
|
||||
// FIXME -- not thread safe
|
||||
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