Format all source with Clang and introduce lint workflow (#7364)

* Lint script with CLang format

* Use `-i` for `clang-format` and add more logging for lint scripts

* Apply LLVM CLang formatting

* Fixed comment

* Update ChangeLog

* Fixed bad return code logic

* Improve output for linters

* Fixed re-used var in clang lint

* Fixed include order for tests and use `#if 0` instead of commenting out code

* Use full Clang format dump

* Dump Ubuntu Clang format

* Dump Clang format from Debian

* Dumped from: clang-format version 18.1.8

* Revert "Dumped from: clang-format version 18.1.8"

This reverts commit b9bbda2995bb0b4b65baf14afebb0361ec64e644.

* Remove BasedOnStyle

* Restore base Clang format file

* Use clang-format from pip

* Apply Clang format 18 style

* Add clang_format deps

* Fixed include order issues and *some* accidental includes
This commit is contained in:
Nick Bolton 2024-07-02 20:07:06 +01:00 committed by GitHub
parent f2cc964b3d
commit 37bb0f989e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
664 changed files with 62656 additions and 70427 deletions

11
.clang-format Normal file
View file

@ -0,0 +1,11 @@
# Important: Use the same version of clang-format as our linter, which is:
#
# $ ./scripts/install_deps.py --only-python
# $ ./build/python/bin/clang-format --version
#
# Warning: If you use a different version, the formatting will be different.
#
# To install a specific version of clang-format, use pip:
# $ pip install clang-format==<version>
BasedOnStyle: LLVM

View file

@ -1,23 +0,0 @@
# Runs
name: "Lint CMake files"
on:
pull_request:
jobs:
lint-cmake-files:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 -m venv build/python
source build/python/bin/activate
pip install cmake_format pyyaml
- name: Lint CMake files
run: ./scripts/lint_cmake_files.py

26
.github/workflows/lint-source.yml vendored Normal file
View file

@ -0,0 +1,26 @@
# Lints CMake config and C++ source code.
name: "Lint source code"
on:
pull_request:
jobs:
lint-cmake-files:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
python3 -m venv build/python
source build/python/bin/activate
pip install pyyaml cmake_format clang_format
- name: Linting with CMake formatter
run: ./scripts/lint_cmake.py
- name: Linting with Clang format
run: ./scripts/lint_clang.py

View file

@ -38,6 +38,7 @@ Enhancements:
- #7360 Re-implement packaging for GitHub workflows (Windows)
- #7361 Re-implement packaging for GitHub workflows (Linux)
- #7363 Schedule CI daily at 5am to detect code rot early
- #7364 Format all source with Clang and introduce lint workflow
# 1.14.6

View file

@ -13,6 +13,11 @@ def main():
parser.add_argument(
"--only", type=str, help="Only install the specified dependency"
)
parser.add_argument(
"--only-python",
action="store_true",
help="Only install Python dependencies",
)
args = parser.parse_args()
env.ensure_dependencies()
@ -20,12 +25,13 @@ def main():
env.install_requirements()
error = False
try:
deps = Dependencies(args.only)
deps.install()
except Exception:
traceback.print_exc()
error = True
if not args.only_python:
try:
deps = Dependencies(args.only)
deps.install()
except Exception:
traceback.print_exc()
error = True
if args.pause_on_exit:
input("Press enter to continue...")

14
scripts/lib/fs.py Normal file
View file

@ -0,0 +1,14 @@
import os, fnmatch
def find_files(search_dirs, include_files, exclude_dirs=[]):
"""Recursively find files, excluding specified directories"""
matches = []
for dir in search_dirs:
for root, dirnames, filenames in os.walk(dir):
dirnames[:] = [d for d in dirnames if d not in exclude_dirs]
for pattern in include_files:
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(root, filename))
return matches

57
scripts/lint_clang.py Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env python3
import argparse, sys
import lib.fs as fs
import lib.env as env
include_files = [
"*.h",
"*.c",
"*.hpp",
"*.cpp",
]
dirs = ["src"]
def main():
"""
Cross-platform equivalent of using find and xargs with clang-format.
Lints by performing a dry run (--dry-run) which fails when formatting is needed.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--format",
action="store_true",
help="In-place format all files",
)
args = parser.parse_args()
env.ensure_in_venv(__file__)
from clang_format import clang_format # type: ignore
cmd_args = ["-i"] if args.format else ["--dry-run", "--Werror"]
files_recursive = fs.find_files(dirs, include_files)
if args.format:
print("Formatting files with Clang formatter:")
else:
print("Checking files with Clang formatter:")
for file in files_recursive:
print(file)
if files_recursive:
sys.argv = [""] + cmd_args + files_recursive
result = clang_format()
if result == 0:
print("Clang lint passed")
sys.exit(result)
else:
print("No files for Clang to process", file=sys.stderr)
sys.exit(0)
if __name__ == "__main__":
main()

59
scripts/lint_cmake.py Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env python3
import sys, argparse
import lib.env as env
import lib.fs as fs
include_files = [
"*.cmake",
"CMakeLists.txt",
]
exclude_dirs = [
"ext",
"build",
]
def main():
"""
Cross-platform equivalent of using find and xargs with cmake-format.
Lints by performing a dry run (--check) which fails when formatting is needed.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--format",
action="store_true",
help="In-place format all files",
)
args = parser.parse_args()
env.ensure_in_venv(__file__)
from cmakelang.format.__main__ import main as cmake_format_main
cmd_args = ["--in-place"] if args.format else ["--check"]
files_recursive = fs.find_files(".", include_files, exclude_dirs)
if args.format:
print("Formatting files with CMake formatter:")
else:
print("Checking files with CMake formatter:")
for file in files_recursive:
print(file)
if files_recursive:
sys.argv = [""] + cmd_args + files_recursive
result = cmake_format_main()
if result == 0:
print("CMake lint passed")
sys.exit(result)
else:
print("No CMake files found to process.", file=sys.stderr)
sys.exit(0)
if __name__ == "__main__":
main()

View file

@ -1,51 +0,0 @@
#!/usr/bin/env python3
import sys, os, argparse, fnmatch
import lib.env as env
include_files = [
"*.cmake",
"CMakeLists.txt",
]
exclude_dirs = [
"ext",
"build",
]
def find_files(base_dir, include_files, exclude_dirs):
"""Recursively find files, excluding specified directories"""
matches = []
for root, dirnames, filenames in os.walk(base_dir):
dirnames[:] = [d for d in dirnames if d not in exclude_dirs]
for pattern in include_files:
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.join(root, filename))
return matches
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--format", action="store_true", help="Formats all CMake files")
args = parser.parse_args()
# important: load venv before loading modules that install deps.
env.ensure_in_venv(__file__)
from cmakelang.format.__main__ import main as cmake_format_main
new_args = ["--in-place"] if args.format else ["--check"]
files_recursive = find_files(".", include_files, exclude_dirs)
if files_recursive:
sys.argv = [""] + new_args + files_recursive
sys.exit(cmake_format_main())
else:
print("No CMake files found to process.")
sys.exit(0)
if __name__ == "__main__":
main()

View file

@ -1,4 +1,5 @@
cmake_format
clang-format
python-dotenv
pyyaml
dmgbuild; sys_platform == 'darwin'

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2022 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -15,54 +15,54 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "arch/Arch.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include "synergy/ClientApp.h"
#include "synergy/ServerApp.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/EventQueue.h"
#include <iostream>
void showHelp()
{
std::cout<<"Usage: synergy-core <server | client> [...options]"<<std::endl;
std::cout<<"server - start as a server (synergys)"<<std::endl;
std::cout<<"client - start as a client (synergyc)"<<std::endl;
std::cout<<"use synergy-core <server|client> --help for more information."<<std::endl;
}
bool isServer(int argc, char** argv)
{
return (argc > 1 && argv[1] == std::string("server"));
}
bool isClient(int argc, char** argv)
{
return (argc > 1 && argv[1] == std::string("client"));
}
int main(int argc, char** argv)
{
#if SYSAPI_WIN32
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#include "arch/win32/ArchMiscWindows.h"
#endif
Arch arch;
arch.init();
Log log;
EventQueue events;
if (isServer(argc, argv)) {
ServerApp app(&events, nullptr);
return app.run(argc, argv);
}
else if (isClient(argc, argv)) {
ClientApp app(&events, nullptr);
return app.run(argc, argv);
}
else {
showHelp();
}
return 0;
void showHelp() {
std::cout << "Usage: synergy-core <server | client> [...options]"
<< std::endl;
std::cout << "server - start as a server (synergys)" << std::endl;
std::cout << "client - start as a client (synergyc)" << std::endl;
std::cout << "use synergy-core <server|client> --help for more information."
<< std::endl;
}
bool isServer(int argc, char **argv) {
return (argc > 1 && argv[1] == std::string("server"));
}
bool isClient(int argc, char **argv) {
return (argc > 1 && argv[1] == std::string("client"));
}
int main(int argc, char **argv) {
#if SYSAPI_WIN32
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
Arch arch;
arch.init();
Log log;
EventQueue events;
if (isServer(argc, argv)) {
ServerApp app(&events, nullptr);
return app.run(argc, argv);
} else if (isClient(argc, argv)) {
ClientApp app(&events, nullptr);
return app.run(argc, argv);
} else {
showHelp();
}
return 0;
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -18,359 +18,308 @@
#include "MSWindowsClientTaskBarReceiver.h"
#include "resource.h"
#include "arch/Arch.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/win32/ArchTaskBarWindows.h"
#include "base/EventQueue.h"
#include "base/EventTypes.h"
#include "base/log_outputters.h"
#include "client/Client.h"
#include "platform/MSWindowsClipboard.h"
#include "platform/MSWindowsScreen.h"
#include "arch/win32/ArchTaskBarWindows.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/Arch.h"
#include "base/EventQueue.h"
#include "base/log_outputters.h"
#include "base/EventTypes.h"
#include "resource.h"
//
// MSWindowsClientTaskBarReceiver
//
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
};
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};
MSWindowsClientTaskBarReceiver::MSWindowsClientTaskBarReceiver(
HINSTANCE appInstance, const BufferedLogOutputter* logBuffer, IEventQueue* events) :
ClientTaskBarReceiver(events),
m_appInstance(appInstance),
m_window(NULL),
m_logBuffer(logBuffer)
{
for (UInt32 i = 0; i < kMaxState; ++i) {
m_icon[i] = loadIcon(s_stateToIconID[i]);
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer,
IEventQueue *events)
: ClientTaskBarReceiver(events), m_appInstance(appInstance), m_window(NULL),
m_logBuffer(logBuffer) {
for (UInt32 i = 0; i < kMaxState; ++i) {
m_icon[i] = loadIcon(s_stateToIconID[i]);
}
m_menu = LoadMenu(m_appInstance, MAKEINTRESOURCE(IDR_TASKBAR));
// don't create the window yet. we'll create it on demand. this
// has the side benefit of being created in the thread used for
// the task bar. that's good because it means the existence of
// the window won't prevent changing the main thread's desktop.
// add ourself to the task bar
ARCH->addReceiver(this);
}
MSWindowsClientTaskBarReceiver::~MSWindowsClientTaskBarReceiver() { cleanup(); }
void MSWindowsClientTaskBarReceiver::cleanup() {
ARCH->removeReceiver(this);
for (UInt32 i = 0; i < kMaxState; ++i) {
deleteIcon(m_icon[i]);
}
DestroyMenu(m_menu);
destroyWindow();
}
void MSWindowsClientTaskBarReceiver::showStatus() {
// create the window
createWindow();
// lock self while getting status
lock();
// get the current status
std::string status = getToolTip();
// done getting status
unlock();
// update dialog
HWND child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_STATUS);
SendMessage(child, WM_SETTEXT, 0, (LPARAM)status.c_str());
if (!IsWindowVisible(m_window)) {
// position it by the mouse
POINT cursorPos;
GetCursorPos(&cursorPos);
RECT windowRect;
GetWindowRect(m_window, &windowRect);
int x = cursorPos.x;
int y = cursorPos.y;
int fw = GetSystemMetrics(SM_CXDLGFRAME);
int fh = GetSystemMetrics(SM_CYDLGFRAME);
int ww = windowRect.right - windowRect.left;
int wh = windowRect.bottom - windowRect.top;
int sw = GetSystemMetrics(SM_CXFULLSCREEN);
int sh = GetSystemMetrics(SM_CYFULLSCREEN);
if (fw < 1) {
fw = 1;
}
m_menu = LoadMenu(m_appInstance, MAKEINTRESOURCE(IDR_TASKBAR));
// don't create the window yet. we'll create it on demand. this
// has the side benefit of being created in the thread used for
// the task bar. that's good because it means the existence of
// the window won't prevent changing the main thread's desktop.
// add ourself to the task bar
ARCH->addReceiver(this);
}
MSWindowsClientTaskBarReceiver::~MSWindowsClientTaskBarReceiver()
{
cleanup();
}
void
MSWindowsClientTaskBarReceiver::cleanup()
{
ARCH->removeReceiver(this);
for (UInt32 i = 0; i < kMaxState; ++i) {
deleteIcon(m_icon[i]);
if (fh < 1) {
fh = 1;
}
DestroyMenu(m_menu);
destroyWindow();
}
void
MSWindowsClientTaskBarReceiver::showStatus()
{
// create the window
createWindow();
// lock self while getting status
lock();
// get the current status
std::string status = getToolTip();
// done getting status
unlock();
// update dialog
HWND child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_STATUS);
SendMessage(child, WM_SETTEXT, 0, (LPARAM)status.c_str());
if (!IsWindowVisible(m_window)) {
// position it by the mouse
POINT cursorPos;
GetCursorPos(&cursorPos);
RECT windowRect;
GetWindowRect(m_window, &windowRect);
int x = cursorPos.x;
int y = cursorPos.y;
int fw = GetSystemMetrics(SM_CXDLGFRAME);
int fh = GetSystemMetrics(SM_CYDLGFRAME);
int ww = windowRect.right - windowRect.left;
int wh = windowRect.bottom - windowRect.top;
int sw = GetSystemMetrics(SM_CXFULLSCREEN);
int sh = GetSystemMetrics(SM_CYFULLSCREEN);
if (fw < 1) {
fw = 1;
}
if (fh < 1) {
fh = 1;
}
if (x + ww - fw > sw) {
x -= ww - fw;
}
else {
x -= fw;
}
if (x < 0) {
x = 0;
}
if (y + wh - fh > sh) {
y -= wh - fh;
}
else {
y -= fh;
}
if (y < 0) {
y = 0;
}
SetWindowPos(m_window, HWND_TOPMOST, x, y, ww, wh,
SWP_SHOWWINDOW);
if (x + ww - fw > sw) {
x -= ww - fw;
} else {
x -= fw;
}
}
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
// another window gets activated and are just one of those
// win32 weirdnesses.
createWindow();
SetForegroundWindow(m_window);
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);
SendMessage(m_window, WM_NULL, 0, 0);
// perform the requested operation
switch (n) {
case IDC_TASKBAR_STATUS:
showStatus();
break;
case IDC_TASKBAR_LOG:
copyLog();
break;
case IDC_TASKBAR_SHOW_LOG:
ARCH->showConsole(true);
break;
case IDC_TASKBAR_LOG_LEVEL_ERROR:
CLOG->setFilter(kERROR);
break;
case IDC_TASKBAR_LOG_LEVEL_WARNING:
CLOG->setFilter(kWARNING);
break;
case IDC_TASKBAR_LOG_LEVEL_NOTE:
CLOG->setFilter(kNOTE);
break;
case IDC_TASKBAR_LOG_LEVEL_INFO:
CLOG->setFilter(kINFO);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG:
CLOG->setFilter(kDEBUG);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG1:
CLOG->setFilter(kDEBUG1);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG2:
CLOG->setFilter(kDEBUG2);
break;
case IDC_TASKBAR_QUIT:
quit();
break;
if (x < 0) {
x = 0;
}
if (y + wh - fh > sh) {
y -= wh - fh;
} else {
y -= fh;
}
if (y < 0) {
y = 0;
}
SetWindowPos(m_window, HWND_TOPMOST, x, y, ww, wh, SWP_SHOWWINDOW);
}
}
void
MSWindowsClientTaskBarReceiver::primaryAction()
{
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
// another window gets activated and are just one of those
// win32 weirdnesses.
createWindow();
SetForegroundWindow(m_window);
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);
SendMessage(m_window, WM_NULL, 0, 0);
// perform the requested operation
switch (n) {
case IDC_TASKBAR_STATUS:
showStatus();
break;
case IDC_TASKBAR_LOG:
copyLog();
break;
case IDC_TASKBAR_SHOW_LOG:
ARCH->showConsole(true);
break;
case IDC_TASKBAR_LOG_LEVEL_ERROR:
CLOG->setFilter(kERROR);
break;
case IDC_TASKBAR_LOG_LEVEL_WARNING:
CLOG->setFilter(kWARNING);
break;
case IDC_TASKBAR_LOG_LEVEL_NOTE:
CLOG->setFilter(kNOTE);
break;
case IDC_TASKBAR_LOG_LEVEL_INFO:
CLOG->setFilter(kINFO);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG:
CLOG->setFilter(kDEBUG);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG1:
CLOG->setFilter(kDEBUG1);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG2:
CLOG->setFilter(kDEBUG2);
break;
case IDC_TASKBAR_QUIT:
quit();
break;
}
}
void MSWindowsClientTaskBarReceiver::primaryAction() { showStatus(); }
const IArchTaskBarReceiver::Icon
MSWindowsClientTaskBarReceiver::getIcon() const
{
return static_cast<Icon>(m_icon[getStatus()]);
MSWindowsClientTaskBarReceiver::getIcon() const {
return static_cast<Icon>(m_icon[getStatus()]);
}
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) {
data += *index;
data += "\n";
}
// copy log to clipboard
if (!data.empty()) {
MSWindowsClipboard clipboard(m_window);
clipboard.open(0);
clipboard.emptyUnowned();
clipboard.add(IClipboard::kText, data);
clipboard.close();
}
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) {
data += *index;
data += "\n";
}
// copy log to clipboard
if (!data.empty()) {
MSWindowsClipboard clipboard(m_window);
clipboard.open(0);
clipboard.emptyUnowned();
clipboard.add(IClipboard::kText, data);
clipboard.close();
}
}
}
void
MSWindowsClientTaskBarReceiver::onStatusChanged()
{
if (IsWindowVisible(m_window)) {
showStatus();
}
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);
return static_cast<HICON>(icon);
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)
{
if (icon != NULL) {
DestroyIcon(icon);
}
void MSWindowsClientTaskBarReceiver::deleteIcon(HICON icon) {
if (icon != NULL) {
DestroyIcon(icon);
}
}
void
MSWindowsClientTaskBarReceiver::createWindow()
{
// ignore if already created
if (m_window != NULL) {
return;
}
void MSWindowsClientTaskBarReceiver::createWindow() {
// ignore if already created
if (m_window != NULL) {
return;
}
// get the status dialog
m_window = CreateDialogParam(m_appInstance,
MAKEINTRESOURCE(IDD_TASKBAR_STATUS),
NULL,
(DLGPROC)&MSWindowsClientTaskBarReceiver::staticDlgProc,
reinterpret_cast<LPARAM>(
static_cast<void*>(this)));
// get the status dialog
m_window = CreateDialogParam(
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.
LONG_PTR style = GetWindowLongPtr(m_window, GWL_EXSTYLE);
style |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
SetWindowLongPtr(m_window, GWL_EXSTYLE, style);
// window should appear on top of everything, including (especially)
// the task bar.
LONG_PTR style = GetWindowLongPtr(m_window, GWL_EXSTYLE);
style |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
SetWindowLongPtr(m_window, GWL_EXSTYLE, style);
// tell the task bar about this dialog
ArchTaskBarWindows::addDialog(m_window);
// tell the task bar about this dialog
ArchTaskBarWindows::addDialog(m_window);
}
void
MSWindowsClientTaskBarReceiver::destroyWindow()
{
if (m_window != NULL) {
ArchTaskBarWindows::removeDialog(m_window);
DestroyWindow(m_window);
m_window = NULL;
}
void MSWindowsClientTaskBarReceiver::destroyWindow() {
if (m_window != NULL) {
ArchTaskBarWindows::removeDialog(m_window);
DestroyWindow(m_window);
m_window = NULL;
}
}
BOOL
MSWindowsClientTaskBarReceiver::dlgProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM)
{
switch (msg) {
case WM_INITDIALOG:
// use default focus
return TRUE;
BOOL MSWindowsClientTaskBarReceiver::dlgProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM) {
switch (msg) {
case WM_INITDIALOG:
// use default focus
return TRUE;
case WM_ACTIVATE:
// hide when another window is activated
if (LOWORD(wParam) == WA_INACTIVE) {
ShowWindow(hwnd, SW_HIDE);
}
break;
case WM_ACTIVATE:
// hide when another window is activated
if (LOWORD(wParam) == WA_INACTIVE) {
ShowWindow(hwnd, SW_HIDE);
}
return FALSE;
break;
}
return FALSE;
}
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));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) lParam);
}
else {
// get the extra window data and forward the call
LONG_PTR data = GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (data != 0) {
self = (MSWindowsClientTaskBarReceiver*) data;
}
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));
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
} else {
// get the extra window data and forward the call
LONG_PTR data = GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (data != 0) {
self = (MSWindowsClientTaskBarReceiver *)data;
}
}
// forward the message
if (self != NULL) {
return self->dlgProc(hwnd, msg, wParam, lParam);
}
else {
return (msg == WM_INITDIALOG) ? TRUE : FALSE;
}
// forward the message
if (self != NULL) {
return self->dlgProc(hwnd, msg, wParam, lParam);
} else {
return (msg == WM_INITDIALOG) ? TRUE : FALSE;
}
}
IArchTaskBarReceiver*
createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events)
{
ArchMiscWindows::setIcons(
(HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON,
32, 32, LR_SHARED),
(HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON,
16, 16, LR_SHARED));
IArchTaskBarReceiver *
createTaskBarReceiver(const BufferedLogOutputter *logBuffer,
IEventQueue *events) {
ArchMiscWindows::setIcons((HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON, 32, 32, LR_SHARED),
(HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON, 16, 16, LR_SHARED));
return new MSWindowsClientTaskBarReceiver(
MSWindowsScreen::getWindowInstance(), logBuffer, events);
return new MSWindowsClientTaskBarReceiver(
MSWindowsScreen::getWindowInstance(), logBuffer, events);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -29,40 +29,39 @@ class IEventQueue;
//! Implementation of ClientTaskBarReceiver for Microsoft Windows
class MSWindowsClientTaskBarReceiver : public ClientTaskBarReceiver {
public:
MSWindowsClientTaskBarReceiver(HINSTANCE, const BufferedLogOutputter*, IEventQueue* events);
virtual ~MSWindowsClientTaskBarReceiver();
MSWindowsClientTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *,
IEventQueue *events);
virtual ~MSWindowsClientTaskBarReceiver();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
void cleanup();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
void cleanup();
protected:
void copyLog() const;
void copyLog() const;
// ClientTaskBarReceiver overrides
virtual void onStatusChanged();
// ClientTaskBarReceiver overrides
virtual void onStatusChanged();
private:
HICON loadIcon(UINT);
void deleteIcon(HICON);
void createWindow();
void destroyWindow();
HICON loadIcon(UINT);
void deleteIcon(HICON);
void createWindow();
void destroyWindow();
BOOL dlgProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK
staticDlgProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM lParam);
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam);
private:
HINSTANCE m_appInstance;
HWND m_window;
HMENU m_menu;
HICON m_icon[kMaxState];
const BufferedLogOutputter* m_logBuffer;
HINSTANCE m_appInstance;
HWND m_window;
HMENU m_menu;
HICON m_icon[kMaxState];
const BufferedLogOutputter *m_logBuffer;
static const UINT s_stateToIconID[];
static const UINT s_stateToIconID[];
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -23,47 +23,35 @@
// OSXClientTaskBarReceiver
//
OSXClientTaskBarReceiver::OSXClientTaskBarReceiver(
const BufferedLogOutputter*,
IEventQueue* events) :
ClientTaskBarReceiver(events)
{
// add ourself to the task bar
ARCH->addReceiver(this);
OSXClientTaskBarReceiver::OSXClientTaskBarReceiver(const BufferedLogOutputter *,
IEventQueue *events)
: ClientTaskBarReceiver(events) {
// add ourself to the task bar
ARCH->addReceiver(this);
}
OSXClientTaskBarReceiver::~OSXClientTaskBarReceiver()
{
ARCH->removeReceiver(this);
OSXClientTaskBarReceiver::~OSXClientTaskBarReceiver() {
ARCH->removeReceiver(this);
}
void
OSXClientTaskBarReceiver::showStatus()
{
// do nothing
void OSXClientTaskBarReceiver::showStatus() {
// do nothing
}
void
OSXClientTaskBarReceiver::runMenu(int, int)
{
// do nothing
void OSXClientTaskBarReceiver::runMenu(int, int) {
// do nothing
}
void
OSXClientTaskBarReceiver::primaryAction()
{
// do nothing
void OSXClientTaskBarReceiver::primaryAction() {
// do nothing
}
const IArchTaskBarReceiver::Icon
OSXClientTaskBarReceiver::getIcon() const
{
return NULL;
const IArchTaskBarReceiver::Icon OSXClientTaskBarReceiver::getIcon() const {
return NULL;
}
IArchTaskBarReceiver*
createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events)
{
return new OSXClientTaskBarReceiver(logBuffer, events);
IArchTaskBarReceiver *
createTaskBarReceiver(const BufferedLogOutputter *logBuffer,
IEventQueue *events) {
return new OSXClientTaskBarReceiver(logBuffer, events);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -26,12 +26,12 @@ class IEventQueue;
//! Implementation of ClientTaskBarReceiver for OS X
class OSXClientTaskBarReceiver : public ClientTaskBarReceiver {
public:
OSXClientTaskBarReceiver(const BufferedLogOutputter*, IEventQueue* events);
virtual ~OSXClientTaskBarReceiver();
OSXClientTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
virtual ~OSXClientTaskBarReceiver();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -24,45 +24,35 @@
//
CXWindowsClientTaskBarReceiver::CXWindowsClientTaskBarReceiver(
const BufferedLogOutputter*,
IEventQueue* events) :
ClientTaskBarReceiver(events)
{
// add ourself to the task bar
ARCH->addReceiver(this);
const BufferedLogOutputter *, IEventQueue *events)
: ClientTaskBarReceiver(events) {
// add ourself to the task bar
ARCH->addReceiver(this);
}
CXWindowsClientTaskBarReceiver::~CXWindowsClientTaskBarReceiver()
{
ARCH->removeReceiver(this);
CXWindowsClientTaskBarReceiver::~CXWindowsClientTaskBarReceiver() {
ARCH->removeReceiver(this);
}
void
CXWindowsClientTaskBarReceiver::showStatus()
{
// do nothing
void CXWindowsClientTaskBarReceiver::showStatus() {
// do nothing
}
void
CXWindowsClientTaskBarReceiver::runMenu(int, int)
{
// do nothing
void CXWindowsClientTaskBarReceiver::runMenu(int, int) {
// do nothing
}
void
CXWindowsClientTaskBarReceiver::primaryAction()
{
// do nothing
void CXWindowsClientTaskBarReceiver::primaryAction() {
// do nothing
}
const IArchTaskBarReceiver::Icon
CXWindowsClientTaskBarReceiver::getIcon() const
{
return NULL;
CXWindowsClientTaskBarReceiver::getIcon() const {
return NULL;
}
IArchTaskBarReceiver*
createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events)
{
return new CXWindowsClientTaskBarReceiver(logBuffer, events);
IArchTaskBarReceiver *
createTaskBarReceiver(const BufferedLogOutputter *logBuffer,
IEventQueue *events) {
return new CXWindowsClientTaskBarReceiver(logBuffer, events);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -26,18 +26,21 @@ class IEventQueue;
//! Implementation of ClientTaskBarReceiver for X Windows
class CXWindowsClientTaskBarReceiver : public ClientTaskBarReceiver {
public:
CXWindowsClientTaskBarReceiver(
const BufferedLogOutputter*, IEventQueue* events);
CXWindowsClientTaskBarReceiver(const CXWindowsClientTaskBarReceiver &) =delete;
CXWindowsClientTaskBarReceiver(CXWindowsClientTaskBarReceiver &&) =delete;
virtual ~CXWindowsClientTaskBarReceiver();
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();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
};

View file

@ -2,36 +2,36 @@
// Microsoft Developer Studio generated include file.
// Used by synergyc.rc
//
#define IDS_FAILED 1
#define IDS_INIT_FAILED 2
#define IDS_UNCAUGHT_EXCEPTION 3
#define IDI_SYNERGY 101
#define IDI_TASKBAR_NOT_RUNNING 102
#define IDI_TASKBAR_NOT_WORKING 103
#define IDI_TASKBAR_NOT_CONNECTED 104
#define IDI_TASKBAR_CONNECTED 105
#define IDR_TASKBAR 107
#define IDD_TASKBAR_STATUS 108
#define IDC_TASKBAR_STATUS_STATUS 1000
#define IDC_TASKBAR_QUIT 40001
#define IDC_TASKBAR_STATUS 40002
#define IDC_TASKBAR_LOG 40003
#define IDC_TASKBAR_SHOW_LOG 40004
#define IDC_TASKBAR_LOG_LEVEL_ERROR 40009
#define IDC_TASKBAR_LOG_LEVEL_WARNING 40010
#define IDC_TASKBAR_LOG_LEVEL_NOTE 40011
#define IDC_TASKBAR_LOG_LEVEL_INFO 40012
#define IDC_TASKBAR_LOG_LEVEL_DEBUG 40013
#define IDC_TASKBAR_LOG_LEVEL_DEBUG1 40014
#define IDC_TASKBAR_LOG_LEVEL_DEBUG2 40015
#define IDS_FAILED 1
#define IDS_INIT_FAILED 2
#define IDS_UNCAUGHT_EXCEPTION 3
#define IDI_SYNERGY 101
#define IDI_TASKBAR_NOT_RUNNING 102
#define IDI_TASKBAR_NOT_WORKING 103
#define IDI_TASKBAR_NOT_CONNECTED 104
#define IDI_TASKBAR_CONNECTED 105
#define IDR_TASKBAR 107
#define IDD_TASKBAR_STATUS 108
#define IDC_TASKBAR_STATUS_STATUS 1000
#define IDC_TASKBAR_QUIT 40001
#define IDC_TASKBAR_STATUS 40002
#define IDC_TASKBAR_LOG 40003
#define IDC_TASKBAR_SHOW_LOG 40004
#define IDC_TASKBAR_LOG_LEVEL_ERROR 40009
#define IDC_TASKBAR_LOG_LEVEL_WARNING 40010
#define IDC_TASKBAR_LOG_LEVEL_NOTE 40011
#define IDC_TASKBAR_LOG_LEVEL_INFO 40012
#define IDC_TASKBAR_LOG_LEVEL_DEBUG 40013
#define IDC_TASKBAR_LOG_LEVEL_DEBUG1 40014
#define IDC_TASKBAR_LOG_LEVEL_DEBUG2 40015
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40016
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40016
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -16,10 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "synergy/ClientApp.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include "synergy/ClientApp.h"
#if SYSAPI_WIN32
#include "arch/win32/ArchMiscWindows.h"
#endif
#if WINAPI_MSWINDOWS
#include "MSWindowsClientTaskBarReceiver.h"
@ -31,20 +35,18 @@
#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));
// record window instance for tray icon, etc
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
Arch arch;
arch.init();
Log log;
EventQueue events;
Arch arch;
arch.init();
ClientApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
Log log;
EventQueue events;
ClientApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2012 Nick Bolton
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -22,11 +22,9 @@
#ifdef SYSAPI_UNIX
int
main(int argc, char** argv)
{
DaemonApp app;
return app.run(argc, argv);
int main(int argc, char **argv) {
DaemonApp app;
return app.run(argc, argv);
}
#elif SYSAPI_WIN32
@ -34,11 +32,9 @@ main(int argc, char** argv)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
int WINAPI
WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
DaemonApp app;
return app.run(__argc, __argv);
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
DaemonApp app;
return app.run(__argc, __argv);
}
#endif

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -18,391 +18,339 @@
#include "MSWindowsServerTaskBarReceiver.h"
#include "resource.h"
#include "server/Server.h"
#include "platform/MSWindowsClipboard.h"
#include "platform/MSWindowsScreen.h"
#include "arch/win32/ArchTaskBarWindows.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/Arch.h"
#include "arch/win32/ArchMiscWindows.h"
#include "arch/win32/ArchTaskBarWindows.h"
#include "base/EventQueue.h"
#include "base/EventTypes.h"
#include "base/IEventQueue.h"
#include "base/log_outputters.h"
#include "base/EventTypes.h"
#include "platform/MSWindowsClipboard.h"
#include "platform/MSWindowsScreen.h"
#include "resource.h"
#include "server/Server.h"
//
// MSWindowsServerTaskBarReceiver
//
const UINT MSWindowsServerTaskBarReceiver::s_stateToIconID[kMaxState] =
{
IDI_TASKBAR_NOT_RUNNING,
IDI_TASKBAR_NOT_WORKING,
IDI_TASKBAR_NOT_CONNECTED,
IDI_TASKBAR_CONNECTED
};
const UINT MSWindowsServerTaskBarReceiver::s_stateToIconID[kMaxState] = {
IDI_TASKBAR_NOT_RUNNING, IDI_TASKBAR_NOT_WORKING, IDI_TASKBAR_NOT_CONNECTED,
IDI_TASKBAR_CONNECTED};
MSWindowsServerTaskBarReceiver::MSWindowsServerTaskBarReceiver(
HINSTANCE appInstance, const BufferedLogOutputter* logBuffer, IEventQueue* events) :
ServerTaskBarReceiver(events),
m_events(events),
m_appInstance(appInstance),
m_window(NULL),
m_logBuffer(logBuffer)
{
for (UInt32 i = 0; i < kMaxState; ++i) {
m_icon[i] = loadIcon(s_stateToIconID[i]);
}
m_menu = LoadMenu(m_appInstance, MAKEINTRESOURCE(IDR_TASKBAR));
HINSTANCE appInstance, const BufferedLogOutputter *logBuffer,
IEventQueue *events)
: ServerTaskBarReceiver(events), m_events(events),
m_appInstance(appInstance), m_window(NULL), m_logBuffer(logBuffer) {
for (UInt32 i = 0; i < kMaxState; ++i) {
m_icon[i] = loadIcon(s_stateToIconID[i]);
}
m_menu = LoadMenu(m_appInstance, MAKEINTRESOURCE(IDR_TASKBAR));
// don't create the window yet. we'll create it on demand. this
// has the side benefit of being created in the thread used for
// the task bar. that's good because it means the existence of
// the window won't prevent changing the main thread's desktop.
// don't create the window yet. we'll create it on demand. this
// has the side benefit of being created in the thread used for
// the task bar. that's good because it means the existence of
// the window won't prevent changing the main thread's desktop.
// add ourself to the task bar
ARCH->addReceiver(this);
// add ourself to the task bar
ARCH->addReceiver(this);
}
void
MSWindowsServerTaskBarReceiver::cleanup()
{
ARCH->removeReceiver(this);
for (UInt32 i = 0; i < kMaxState; ++i) {
deleteIcon(m_icon[i]);
}
DestroyMenu(m_menu);
destroyWindow();
void MSWindowsServerTaskBarReceiver::cleanup() {
ARCH->removeReceiver(this);
for (UInt32 i = 0; i < kMaxState; ++i) {
deleteIcon(m_icon[i]);
}
DestroyMenu(m_menu);
destroyWindow();
}
MSWindowsServerTaskBarReceiver::~MSWindowsServerTaskBarReceiver()
{
cleanup();
MSWindowsServerTaskBarReceiver::~MSWindowsServerTaskBarReceiver() { cleanup(); }
void MSWindowsServerTaskBarReceiver::showStatus() {
// create the window
createWindow();
// lock self while getting status
lock();
// get the current status
std::string status = getToolTip();
// get the connect clients, if any
const Clients &clients = getClients();
// done getting status
unlock();
// update dialog
HWND child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_STATUS);
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();) {
const char *client = index->c_str();
if (++index == clients.end()) {
SendMessage(child, LB_ADDSTRING, 0, (LPARAM)client);
} else {
SendMessage(child, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)client);
}
}
if (!IsWindowVisible(m_window)) {
// position it by the mouse
POINT cursorPos;
GetCursorPos(&cursorPos);
RECT windowRect;
GetWindowRect(m_window, &windowRect);
int x = cursorPos.x;
int y = cursorPos.y;
int fw = GetSystemMetrics(SM_CXDLGFRAME);
int fh = GetSystemMetrics(SM_CYDLGFRAME);
int ww = windowRect.right - windowRect.left;
int wh = windowRect.bottom - windowRect.top;
int sw = GetSystemMetrics(SM_CXFULLSCREEN);
int sh = GetSystemMetrics(SM_CYFULLSCREEN);
if (fw < 1) {
fw = 1;
}
if (fh < 1) {
fh = 1;
}
if (x + ww - fw > sw) {
x -= ww - fw;
} else {
x -= fw;
}
if (x < 0) {
x = 0;
}
if (y + wh - fh > sh) {
y -= wh - fh;
} else {
y -= fh;
}
if (y < 0) {
y = 0;
}
SetWindowPos(m_window, HWND_TOPMOST, x, y, ww, wh, SWP_SHOWWINDOW);
}
}
void
MSWindowsServerTaskBarReceiver::showStatus()
{
// create the window
createWindow();
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
// another window gets activated and are just one of those
// win32 weirdnesses.
createWindow();
SetForegroundWindow(m_window);
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);
SendMessage(m_window, WM_NULL, 0, 0);
// lock self while getting status
lock();
// get the current status
std::string status = getToolTip();
// get the connect clients, if any
const Clients& clients = getClients();
// done getting status
unlock();
// update dialog
HWND child = GetDlgItem(m_window, IDC_TASKBAR_STATUS_STATUS);
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(); ) {
const char* client = index->c_str();
if (++index == clients.end()) {
SendMessage(child, LB_ADDSTRING, 0, (LPARAM)client);
}
else {
SendMessage(child, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)client);
}
}
if (!IsWindowVisible(m_window)) {
// position it by the mouse
POINT cursorPos;
GetCursorPos(&cursorPos);
RECT windowRect;
GetWindowRect(m_window, &windowRect);
int x = cursorPos.x;
int y = cursorPos.y;
int fw = GetSystemMetrics(SM_CXDLGFRAME);
int fh = GetSystemMetrics(SM_CYDLGFRAME);
int ww = windowRect.right - windowRect.left;
int wh = windowRect.bottom - windowRect.top;
int sw = GetSystemMetrics(SM_CXFULLSCREEN);
int sh = GetSystemMetrics(SM_CYFULLSCREEN);
if (fw < 1) {
fw = 1;
}
if (fh < 1) {
fh = 1;
}
if (x + ww - fw > sw) {
x -= ww - fw;
}
else {
x -= fw;
}
if (x < 0) {
x = 0;
}
if (y + wh - fh > sh) {
y -= wh - fh;
}
else {
y -= fh;
}
if (y < 0) {
y = 0;
}
SetWindowPos(m_window, HWND_TOPMOST, x, y, ww, wh,
SWP_SHOWWINDOW);
}
}
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
// another window gets activated and are just one of those
// win32 weirdnesses.
createWindow();
SetForegroundWindow(m_window);
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);
SendMessage(m_window, WM_NULL, 0, 0);
// perform the requested operation
switch (n) {
case IDC_TASKBAR_STATUS:
showStatus();
break;
case IDC_TASKBAR_LOG:
copyLog();
break;
case IDC_TASKBAR_SHOW_LOG:
ARCH->showConsole(true);
break;
case IDC_RELOAD_CONFIG:
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()));
break;
case ID_SYNERGY_RESETSERVER:
m_events->addEvent(Event(m_events->forServerApp().resetServer(),
m_events->getSystemTarget()));
break;
case IDC_TASKBAR_LOG_LEVEL_ERROR:
CLOG->setFilter(kERROR);
break;
case IDC_TASKBAR_LOG_LEVEL_WARNING:
CLOG->setFilter(kWARNING);
break;
case IDC_TASKBAR_LOG_LEVEL_NOTE:
CLOG->setFilter(kNOTE);
break;
case IDC_TASKBAR_LOG_LEVEL_INFO:
CLOG->setFilter(kINFO);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG:
CLOG->setFilter(kDEBUG);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG1:
CLOG->setFilter(kDEBUG1);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG2:
CLOG->setFilter(kDEBUG2);
break;
case IDC_TASKBAR_QUIT:
quit();
break;
}
}
void
MSWindowsServerTaskBarReceiver::primaryAction()
{
// perform the requested operation
switch (n) {
case IDC_TASKBAR_STATUS:
showStatus();
break;
case IDC_TASKBAR_LOG:
copyLog();
break;
case IDC_TASKBAR_SHOW_LOG:
ARCH->showConsole(true);
break;
case IDC_RELOAD_CONFIG:
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()));
break;
case ID_SYNERGY_RESETSERVER:
m_events->addEvent(Event(m_events->forServerApp().resetServer(),
m_events->getSystemTarget()));
break;
case IDC_TASKBAR_LOG_LEVEL_ERROR:
CLOG->setFilter(kERROR);
break;
case IDC_TASKBAR_LOG_LEVEL_WARNING:
CLOG->setFilter(kWARNING);
break;
case IDC_TASKBAR_LOG_LEVEL_NOTE:
CLOG->setFilter(kNOTE);
break;
case IDC_TASKBAR_LOG_LEVEL_INFO:
CLOG->setFilter(kINFO);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG:
CLOG->setFilter(kDEBUG);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG1:
CLOG->setFilter(kDEBUG1);
break;
case IDC_TASKBAR_LOG_LEVEL_DEBUG2:
CLOG->setFilter(kDEBUG2);
break;
case IDC_TASKBAR_QUIT:
quit();
break;
}
}
void MSWindowsServerTaskBarReceiver::primaryAction() { showStatus(); }
const IArchTaskBarReceiver::Icon
MSWindowsServerTaskBarReceiver::getIcon() const
{
return static_cast<Icon>(m_icon[getStatus()]);
MSWindowsServerTaskBarReceiver::getIcon() const {
return static_cast<Icon>(m_icon[getStatus()]);
}
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) {
data += *index;
data += "\n";
}
// copy log to clipboard
if (!data.empty()) {
MSWindowsClipboard clipboard(m_window);
clipboard.open(0);
clipboard.emptyUnowned();
clipboard.add(IClipboard::kText, data);
clipboard.close();
}
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) {
data += *index;
data += "\n";
}
// copy log to clipboard
if (!data.empty()) {
MSWindowsClipboard clipboard(m_window);
clipboard.open(0);
clipboard.emptyUnowned();
clipboard.add(IClipboard::kText, data);
clipboard.close();
}
}
}
void
MSWindowsServerTaskBarReceiver::onStatusChanged()
{
if (IsWindowVisible(m_window)) {
showStatus();
}
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);
return static_cast<HICON>(icon);
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)
{
if (icon != NULL) {
DestroyIcon(icon);
}
void MSWindowsServerTaskBarReceiver::deleteIcon(HICON icon) {
if (icon != NULL) {
DestroyIcon(icon);
}
}
void
MSWindowsServerTaskBarReceiver::createWindow()
{
// ignore if already created
if (m_window != NULL) {
return;
}
void MSWindowsServerTaskBarReceiver::createWindow() {
// ignore if already created
if (m_window != NULL) {
return;
}
// get the status dialog
m_window = CreateDialogParam(m_appInstance,
MAKEINTRESOURCE(IDD_TASKBAR_STATUS),
NULL,
(DLGPROC)&MSWindowsServerTaskBarReceiver::staticDlgProc,
reinterpret_cast<LPARAM>(
static_cast<void*>(this)));
// get the status dialog
m_window = CreateDialogParam(
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.
LONG_PTR style = GetWindowLongPtr(m_window, GWL_EXSTYLE);
style |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
SetWindowLongPtr(m_window, GWL_EXSTYLE, style);
// window should appear on top of everything, including (especially)
// the task bar.
LONG_PTR style = GetWindowLongPtr(m_window, GWL_EXSTYLE);
style |= WS_EX_TOOLWINDOW | WS_EX_TOPMOST;
SetWindowLongPtr(m_window, GWL_EXSTYLE, style);
// tell the task bar about this dialog
ArchTaskBarWindows::addDialog(m_window);
// tell the task bar about this dialog
ArchTaskBarWindows::addDialog(m_window);
}
void
MSWindowsServerTaskBarReceiver::destroyWindow()
{
if (m_window != NULL) {
ArchTaskBarWindows::removeDialog(m_window);
DestroyWindow(m_window);
m_window = NULL;
}
void MSWindowsServerTaskBarReceiver::destroyWindow() {
if (m_window != NULL) {
ArchTaskBarWindows::removeDialog(m_window);
DestroyWindow(m_window);
m_window = NULL;
}
}
BOOL
MSWindowsServerTaskBarReceiver::dlgProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM)
{
switch (msg) {
case WM_INITDIALOG:
// use default focus
return TRUE;
BOOL MSWindowsServerTaskBarReceiver::dlgProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM) {
switch (msg) {
case WM_INITDIALOG:
// use default focus
return TRUE;
case WM_ACTIVATE:
// hide when another window is activated
if (LOWORD(wParam) == WA_INACTIVE) {
ShowWindow(hwnd, SW_HIDE);
}
break;
case WM_ACTIVATE:
// hide when another window is activated
if (LOWORD(wParam) == WA_INACTIVE) {
ShowWindow(hwnd, SW_HIDE);
}
return FALSE;
break;
}
return FALSE;
}
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));
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));
}
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));
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));
}
}
// forward the message
if (self != NULL) {
return self->dlgProc(hwnd, msg, wParam, lParam);
}
else {
return (msg == WM_INITDIALOG) ? TRUE : FALSE;
}
// forward the message
if (self != NULL) {
return self->dlgProc(hwnd, msg, wParam, lParam);
} else {
return (msg == WM_INITDIALOG) ? TRUE : FALSE;
}
}
IArchTaskBarReceiver*
createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events)
{
ArchMiscWindows::setIcons(
(HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON,
32, 32, LR_SHARED),
(HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON,
16, 16, LR_SHARED));
IArchTaskBarReceiver *
createTaskBarReceiver(const BufferedLogOutputter *logBuffer,
IEventQueue *events) {
ArchMiscWindows::setIcons((HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON, 32, 32, LR_SHARED),
(HICON)LoadImage(ArchMiscWindows::instanceWin32(),
MAKEINTRESOURCE(IDI_SYNERGY),
IMAGE_ICON, 16, 16, LR_SHARED));
return new MSWindowsServerTaskBarReceiver(
MSWindowsScreen::getWindowInstance(), logBuffer, events);
return new MSWindowsServerTaskBarReceiver(
MSWindowsScreen::getWindowInstance(), logBuffer, events);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -29,41 +29,40 @@ class IEventQueue;
//! Implementation of ServerTaskBarReceiver for Microsoft Windows
class MSWindowsServerTaskBarReceiver : public ServerTaskBarReceiver {
public:
MSWindowsServerTaskBarReceiver(HINSTANCE, const BufferedLogOutputter*, IEventQueue* events);
virtual ~MSWindowsServerTaskBarReceiver();
MSWindowsServerTaskBarReceiver(HINSTANCE, const BufferedLogOutputter *,
IEventQueue *events);
virtual ~MSWindowsServerTaskBarReceiver();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
void cleanup();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
void cleanup();
protected:
void copyLog() const;
void copyLog() const;
// ServerTaskBarReceiver overrides
virtual void onStatusChanged();
// ServerTaskBarReceiver overrides
virtual void onStatusChanged();
private:
HICON loadIcon(UINT);
void deleteIcon(HICON);
void createWindow();
void destroyWindow();
HICON loadIcon(UINT);
void deleteIcon(HICON);
void createWindow();
void destroyWindow();
BOOL dlgProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK
staticDlgProc(HWND hwnd,
UINT msg, WPARAM wParam, LPARAM lParam);
BOOL dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK staticDlgProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam);
private:
HINSTANCE m_appInstance;
HWND m_window;
HMENU m_menu;
HICON m_icon[kMaxState];
const BufferedLogOutputter* m_logBuffer;
IEventQueue* m_events;
HINSTANCE m_appInstance;
HWND m_window;
HMENU m_menu;
HICON m_icon[kMaxState];
const BufferedLogOutputter *m_logBuffer;
IEventQueue *m_events;
static const UINT s_stateToIconID[];
static const UINT s_stateToIconID[];
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -23,45 +23,35 @@
// OSXServerTaskBarReceiver
//
OSXServerTaskBarReceiver::OSXServerTaskBarReceiver(
const BufferedLogOutputter*, IEventQueue* events) :
ServerTaskBarReceiver(events)
{
// add ourself to the task bar
ARCH->addReceiver(this);
OSXServerTaskBarReceiver::OSXServerTaskBarReceiver(const BufferedLogOutputter *,
IEventQueue *events)
: ServerTaskBarReceiver(events) {
// add ourself to the task bar
ARCH->addReceiver(this);
}
OSXServerTaskBarReceiver::~OSXServerTaskBarReceiver()
{
ARCH->removeReceiver(this);
OSXServerTaskBarReceiver::~OSXServerTaskBarReceiver() {
ARCH->removeReceiver(this);
}
void
OSXServerTaskBarReceiver::showStatus()
{
// do nothing
void OSXServerTaskBarReceiver::showStatus() {
// do nothing
}
void
OSXServerTaskBarReceiver::runMenu(int, int)
{
// do nothing
void OSXServerTaskBarReceiver::runMenu(int, int) {
// do nothing
}
void
OSXServerTaskBarReceiver::primaryAction()
{
// do nothing
void OSXServerTaskBarReceiver::primaryAction() {
// do nothing
}
const IArchTaskBarReceiver::Icon
OSXServerTaskBarReceiver::getIcon() const
{
return NULL;
const IArchTaskBarReceiver::Icon OSXServerTaskBarReceiver::getIcon() const {
return NULL;
}
IArchTaskBarReceiver*
createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events)
{
return new OSXServerTaskBarReceiver(logBuffer, events);
IArchTaskBarReceiver *
createTaskBarReceiver(const BufferedLogOutputter *logBuffer,
IEventQueue *events) {
return new OSXServerTaskBarReceiver(logBuffer, events);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2004 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -25,12 +25,12 @@ class BufferedLogOutputter;
//! Implementation of ServerTaskBarReceiver for OS X
class OSXServerTaskBarReceiver : public ServerTaskBarReceiver {
public:
OSXServerTaskBarReceiver(const BufferedLogOutputter*, IEventQueue* events);
virtual ~OSXServerTaskBarReceiver();
OSXServerTaskBarReceiver(const BufferedLogOutputter *, IEventQueue *events);
virtual ~OSXServerTaskBarReceiver();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -24,44 +24,35 @@
//
CXWindowsServerTaskBarReceiver::CXWindowsServerTaskBarReceiver(
const BufferedLogOutputter*, IEventQueue* events) :
ServerTaskBarReceiver(events)
{
// add ourself to the task bar
ARCH->addReceiver(this);
const BufferedLogOutputter *, IEventQueue *events)
: ServerTaskBarReceiver(events) {
// add ourself to the task bar
ARCH->addReceiver(this);
}
CXWindowsServerTaskBarReceiver::~CXWindowsServerTaskBarReceiver()
{
ARCH->removeReceiver(this);
CXWindowsServerTaskBarReceiver::~CXWindowsServerTaskBarReceiver() {
ARCH->removeReceiver(this);
}
void
CXWindowsServerTaskBarReceiver::showStatus()
{
// do nothing
void CXWindowsServerTaskBarReceiver::showStatus() {
// do nothing
}
void
CXWindowsServerTaskBarReceiver::runMenu(int, int)
{
// do nothing
void CXWindowsServerTaskBarReceiver::runMenu(int, int) {
// do nothing
}
void
CXWindowsServerTaskBarReceiver::primaryAction()
{
// do nothing
void CXWindowsServerTaskBarReceiver::primaryAction() {
// do nothing
}
const IArchTaskBarReceiver::Icon
CXWindowsServerTaskBarReceiver::getIcon() const
{
return NULL;
CXWindowsServerTaskBarReceiver::getIcon() const {
return NULL;
}
IArchTaskBarReceiver*
createTaskBarReceiver(const BufferedLogOutputter* logBuffer, IEventQueue* events)
{
return new CXWindowsServerTaskBarReceiver(logBuffer, events);
IArchTaskBarReceiver *
createTaskBarReceiver(const BufferedLogOutputter *logBuffer,
IEventQueue *events) {
return new CXWindowsServerTaskBarReceiver(logBuffer, events);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2003 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -26,18 +26,21 @@ class IEventQueue;
//! Implementation of ServerTaskBarReceiver for X Windows
class CXWindowsServerTaskBarReceiver : public ServerTaskBarReceiver {
public:
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(const BufferedLogOutputter *,
IEventQueue *events);
CXWindowsServerTaskBarReceiver(const CXWindowsServerTaskBarReceiver &) =
delete;
CXWindowsServerTaskBarReceiver(CXWindowsServerTaskBarReceiver &&) = delete;
virtual ~CXWindowsServerTaskBarReceiver();
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
CXWindowsServerTaskBarReceiver &
operator=(const CXWindowsServerTaskBarReceiver &) = delete;
CXWindowsServerTaskBarReceiver &
operator=(const CXWindowsServerTaskBarReceiver &&) = delete;
// IArchTaskBarReceiver overrides
virtual void showStatus();
virtual void runMenu(int x, int y);
virtual void primaryAction();
virtual const Icon getIcon() const;
};

View file

@ -2,41 +2,41 @@
// Microsoft Visual C++ generated include file.
// Used by synergys.rc
//
#define IDS_FAILED 1
#define IDS_INIT_FAILED 2
#define IDS_UNCAUGHT_EXCEPTION 3
#define IDI_SYNERGY 101
#define IDI_TASKBAR_NOT_RUNNING 102
#define IDI_TASKBAR_NOT_WORKING 103
#define IDI_TASKBAR_NOT_CONNECTED 104
#define IDI_TASKBAR_CONNECTED 105
#define IDR_TASKBAR 107
#define IDD_TASKBAR_STATUS 108
#define IDC_TASKBAR_STATUS_STATUS 1000
#define IDC_TASKBAR_STATUS_CLIENTS 1001
#define IDC_TASKBAR_QUIT 40003
#define IDC_TASKBAR_STATUS 40004
#define IDC_TASKBAR_LOG 40005
#define IDC_RELOAD_CONFIG 40006
#define IDC_FORCE_RECONNECT 40007
#define IDC_TASKBAR_SHOW_LOG 40008
#define IDC_TASKBAR_LOG_LEVEL_ERROR 40009
#define IDC_TASKBAR_LOG_LEVEL_WARNING 40010
#define IDC_TASKBAR_LOG_LEVEL_NOTE 40011
#define IDC_TASKBAR_LOG_LEVEL_INFO 40012
#define IDC_TASKBAR_LOG_LEVEL_DEBUG 40013
#define IDC_TASKBAR_LOG_LEVEL_DEBUG1 40014
#define IDC_TASKBAR_LOG_LEVEL_DEBUG2 40015
#define ID_SYNERGY_RELOADSYSTEM 40016
#define ID_SYNERGY_RESETSERVER 40017
#define IDS_FAILED 1
#define IDS_INIT_FAILED 2
#define IDS_UNCAUGHT_EXCEPTION 3
#define IDI_SYNERGY 101
#define IDI_TASKBAR_NOT_RUNNING 102
#define IDI_TASKBAR_NOT_WORKING 103
#define IDI_TASKBAR_NOT_CONNECTED 104
#define IDI_TASKBAR_CONNECTED 105
#define IDR_TASKBAR 107
#define IDD_TASKBAR_STATUS 108
#define IDC_TASKBAR_STATUS_STATUS 1000
#define IDC_TASKBAR_STATUS_CLIENTS 1001
#define IDC_TASKBAR_QUIT 40003
#define IDC_TASKBAR_STATUS 40004
#define IDC_TASKBAR_LOG 40005
#define IDC_RELOAD_CONFIG 40006
#define IDC_FORCE_RECONNECT 40007
#define IDC_TASKBAR_SHOW_LOG 40008
#define IDC_TASKBAR_LOG_LEVEL_ERROR 40009
#define IDC_TASKBAR_LOG_LEVEL_WARNING 40010
#define IDC_TASKBAR_LOG_LEVEL_NOTE 40011
#define IDC_TASKBAR_LOG_LEVEL_INFO 40012
#define IDC_TASKBAR_LOG_LEVEL_DEBUG 40013
#define IDC_TASKBAR_LOG_LEVEL_DEBUG1 40014
#define IDC_TASKBAR_LOG_LEVEL_DEBUG2 40015
#define ID_SYNERGY_RELOADSYSTEM 40016
#define ID_SYNERGY_RESETSERVER 40017
// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40018
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40018
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2002 Chris Schoeneman
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -16,10 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "synergy/ServerApp.h"
#include "arch/Arch.h"
#include "base/Log.h"
#include "base/EventQueue.h"
#include "base/Log.h"
#include "synergy/ServerApp.h"
#if SYSAPI_WIN32
#include "arch/win32/ArchMiscWindows.h"
#endif
#if WINAPI_MSWINDOWS
#include "MSWindowsServerTaskBarReceiver.h"
@ -31,20 +35,18 @@
#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));
// record window instance for tray icon, etc
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
Arch arch;
arch.init();
Log log;
EventQueue events;
Arch arch;
arch.init();
ServerApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
Log log;
EventQueue events;
ServerApp app(&events, createTaskBarReceiver);
return app.run(argc, argv);
}

View file

@ -1,11 +1,11 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2014-2016 Symless Ltd.
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -15,17 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "synergy/ToolApp.h"
#include "arch/Arch.h"
#include "synergy/ToolApp.h"
int
main(int argc, char** argv)
{
#if SYSAPI_WIN32
// record window instance for tray icon, etc
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#include "arch/win32/ArchMiscWindows.h"
#endif
ToolApp app;
return app.run(argc, argv);
int main(int argc, char **argv) {
#if SYSAPI_WIN32
// record window instance for tray icon, etc
ArchMiscWindows::setInstanceWin32(GetModuleHandle(NULL));
#endif
ToolApp app;
return app.run(argc, argv);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -16,72 +16,68 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OSXHelpers.h"
#include "AboutDialog.h"
#include "OSXHelpers.h"
AboutDialog::AboutDialog(MainWindow* parent, const AppConfig& config) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::AboutDialogBase()
{
setupUi(this);
AboutDialog::AboutDialog(MainWindow *parent, const AppConfig &config)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::AboutDialogBase() {
setupUi(this);
m_versionChecker.setApp(parent->appPath(config.synergycName()));
m_pLabelSynergyVersion->setText(SYNERGY_VERSION);
m_versionChecker.setApp(parent->appPath(config.synergycName()));
m_pLabelSynergyVersion->setText(SYNERGY_VERSION);
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();
QDate buildDate = QLocale("en_US").toDate(buildDateString, "MMM d yyyy");
m_pLabelBuildDate->setText(buildDate.toString(Qt::SystemLocaleLongDate));
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();
QDate buildDate = QLocale("en_US").toDate(buildDateString, "MMM d yyyy");
m_pLabelBuildDate->setText(buildDate.toString(Qt::SystemLocaleLongDate));
textEliteBackers->hide();
labelEliteBackers->hide();
labelEliteBackerLink->hide();
labelCreditsLink->hide();
textEliteBackers->hide();
labelEliteBackers->hide();
labelEliteBackerLink->hide();
labelCreditsLink->hide();
}
int AboutDialog::exec()
{
//Sets the current build year into the copyright text
label_3->setText(getCopyrights() + getKeyContributors());
resizeWindow();
updateLogo();
int AboutDialog::exec() {
// Sets the current build year into the copyright text
label_3->setText(getCopyrights() + getKeyContributors());
resizeWindow();
updateLogo();
return QDialog::exec();
return QDialog::exec();
}
void AboutDialog::resizeWindow()
{
QSize size(600, 310);
setMaximumSize(size);
setMinimumSize(size);
resize(size);
void AboutDialog::resizeWindow() {
QSize size(600, 310);
setMaximumSize(size);
setMinimumSize(size);
resize(size);
}
void AboutDialog::updateLogo() const
{
void AboutDialog::updateLogo() const {
#if defined(Q_OS_MAC)
if (isOSXInterfaceStyleDark()) {
QPixmap logo(":/res/image/about-dark.png");
if (!logo.isNull()) {
label_Logo->setPixmap(logo);
}
if (isOSXInterfaceStyleDark()) {
QPixmap logo(":/res/image/about-dark.png");
if (!logo.isNull()) {
label_Logo->setPixmap(logo);
}
}
#endif
}
QString AboutDialog::getKeyContributors() const
{
return QString(R"(<p style="font-size: 14px">Key contributors<br>
QString AboutDialog::getKeyContributors() const {
return QString(R"(<p style="font-size: 14px">Key contributors<br>
<span style="font-size: 11px">Chris Schoeneman, Nick Bolton, Richard Lee, Adam Feder, Volker Lanz,
Ryan Breen, Guido Poschta, Bertrand Landry Hetu, Tom Chadwick, Brent Priddy, Kyle Bloom,
Daun Chung, Serhii Hadzhylov, Oleksandr Lysytsia, Olena Kutytska, Francisco Magalhães.</span>
</p>)");
}
QString AboutDialog::getCopyrights() const
{
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();
QDate buildDate = QLocale("en_US").toDate(buildDateString, "MMM d yyyy");
QString AboutDialog::getCopyrights() const {
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();
QDate buildDate = QLocale("en_US").toDate(buildDateString, "MMM d yyyy");
QString copyrights(R"(<p>Keyboard and mouse sharing application.<br /><br />Copyright © %%YEAR%% Symless Ltd.</p>)");
return copyrights.replace(QString("%%YEAR%%"), QString::number(buildDate.year()));
QString copyrights(
R"(<p>Keyboard and mouse sharing application.<br /><br />Copyright © %%YEAR%% Symless Ltd.</p>)");
return copyrights.replace(QString("%%YEAR%%"),
QString::number(buildDate.year()));
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -20,9 +20,9 @@
#define ABOUTDIALOG__H
#include <QDialog>
#include "VersionChecker.h"
#include "MainWindow.h"
#include "VersionChecker.h"
#include <QDialog>
#include "ui_AboutDialogBase.h"
@ -30,18 +30,18 @@ class QWidget;
class QString;
class AboutDialog : public QDialog, public Ui::AboutDialogBase {
Q_OBJECT
Q_OBJECT
public:
AboutDialog(MainWindow* parent, const AppConfig& config);
int exec() override;
private:
VersionChecker m_versionChecker;
void updateLogo() const;
AboutDialog(MainWindow *parent, const AppConfig &config);
int exec() override;
virtual void resizeWindow();
virtual QString getCopyrights() const;
virtual QString getKeyContributors() const;
private:
VersionChecker m_versionChecker;
void updateLogo() const;
virtual void resizeWindow();
virtual QString getCopyrights() const;
virtual QString getKeyContributors() const;
};
#endif

View file

@ -14,60 +14,59 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CreditsLoader.h"
#include "AboutDialogEliteBackers.h"
#include "CreditsLoader.h"
AboutDialogEliteBackers::AboutDialogEliteBackers(MainWindow* parent, const AppConfig& config) :
AboutDialog(parent, config),
credits(*parent, config)
{
setupCreditsLoader();
AboutDialogEliteBackers::AboutDialogEliteBackers(MainWindow *parent,
const AppConfig &config)
: AboutDialog(parent, config), credits(*parent, config) {
setupCreditsLoader();
textEliteBackers->show();
labelEliteBackers->show();
labelEliteBackerLink->show();
labelCreditsLink->show();
textEliteBackers->show();
labelEliteBackers->show();
labelEliteBackerLink->show();
labelCreditsLink->show();
}
void AboutDialogEliteBackers::setupCreditsLoader()
{
this->textEliteBackers->setText("Loading...");
this->textEliteBackers->viewport()->setAutoFillBackground(false);
this->textEliteBackers->document()->setDocumentMargin(0);
void AboutDialogEliteBackers::setupCreditsLoader() {
this->textEliteBackers->setText("Loading...");
this->textEliteBackers->viewport()->setAutoFillBackground(false);
this->textEliteBackers->document()->setDocumentMargin(0);
connect(&credits, SIGNAL(loaded(const QString&)), this, SLOT(updateEliteBackers(const QString&)));
credits.loadEliteBackers();
connect(&credits, SIGNAL(loaded(const QString &)), this,
SLOT(updateEliteBackers(const QString &)));
credits.loadEliteBackers();
}
void AboutDialogEliteBackers::updateEliteBackers(const QString& eliteBackers) const
{
this->textEliteBackers->setText(eliteBackers);
void AboutDialogEliteBackers::updateEliteBackers(
const QString &eliteBackers) const {
this->textEliteBackers->setText(eliteBackers);
}
QString AboutDialogEliteBackers::getCopyrights() const
{
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();
QDate buildDate = QLocale("en_US").toDate(buildDateString, "MMM d yyyy");
QString AboutDialogEliteBackers::getCopyrights() const {
QString buildDateString = QString::fromLocal8Bit(__DATE__).simplified();
QDate buildDate = QLocale("en_US").toDate(buildDateString, "MMM d yyyy");
QString aboutText(R"(<p>Keyboard and mouse sharing application. Cross platform and open source since 2001.<br /><br />
QString aboutText(
R"(<p>Keyboard and mouse sharing application. Cross platform and open source since 2001.<br /><br />
Copyright © %%YEAR%% Symless Ltd.<br /><br />
Synergy is released under the GNU General Public License (GPLv2).</p>)");
return aboutText.replace(QString("%%YEAR%%"), QString::number(buildDate.year()));
return aboutText.replace(QString("%%YEAR%%"),
QString::number(buildDate.year()));
}
void AboutDialogEliteBackers::resizeWindow()
{
void AboutDialogEliteBackers::resizeWindow() {
// change default size based on os
#if defined(Q_OS_MAC)
QSize size(600, 490);
setMaximumSize(size);
setMinimumSize(size);
resize(size);
QSize size(600, 490);
setMaximumSize(size);
setMinimumSize(size);
resize(size);
#elif defined(Q_OS_LINUX)
QSize size(600, 420);
setMaximumSize(size);
setMinimumSize(size);
resize(size);
QSize size(600, 420);
setMaximumSize(size);
setMinimumSize(size);
resize(size);
#endif
}

View file

@ -16,21 +16,21 @@
*/
#pragma once
#include "CreditsLoader.h"
#include "AboutDialog.h"
#include "CreditsLoader.h"
class AboutDialogEliteBackers : public AboutDialog {
Q_OBJECT
Q_OBJECT
public:
AboutDialogEliteBackers(MainWindow* parent, const AppConfig& config);
AboutDialogEliteBackers(MainWindow *parent, const AppConfig &config);
public slots:
void updateEliteBackers(const QString& eliteBackers) const;
void updateEliteBackers(const QString &eliteBackers) const;
private:
CreditsLoader credits;
CreditsLoader credits;
void setupCreditsLoader();
void resizeWindow() override;
QString getCopyrights() const override;
void setupCreditsLoader();
void resizeWindow() override;
QString getCopyrights() const override;
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -21,148 +21,129 @@
#include <QSettings>
#include <QTextStream>
const char* Action::m_ActionTypeNames[] =
{
"keyDown", "keyUp", "keystroke",
"switchToScreen", "switchInDirection", "lockCursorToScreen", "restartServer",
"mouseDown", "mouseUp", "mousebutton"
};
const char *Action::m_ActionTypeNames[] = {
"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" };
const char *Action::m_SwitchDirectionNames[] = {"left", "right", "up", "down"};
const char *Action::m_LockCursorModeNames[] = {"toggle", "on", "off"};
Action::Action() :
m_KeySequence(),
m_Type(keystroke),
m_TypeScreenNames(),
m_SwitchScreenName(),
m_SwitchDirection(switchLeft),
m_LockCursorMode(lockCursorToggle),
m_ActiveOnRelease(false),
m_HasScreens(false)
{
}
Action::Action()
: m_KeySequence(), m_Type(keystroke), m_TypeScreenNames(),
m_SwitchScreenName(), m_SwitchDirection(switchLeft),
m_LockCursorMode(lockCursorToggle), m_ActiveOnRelease(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:
case keyUp:
case keystroke:
{
text += keySequence().toString();
switch (type()) {
case keyDown:
case keyUp:
case keystroke: {
text += keySequence().toString();
if (!keySequence().isMouseButton())
{
const QStringList& screens = typeScreenNames();
if (haveScreens() && !screens.isEmpty())
{
text += ",";
if (!keySequence().isMouseButton()) {
const QStringList &screens = typeScreenNames();
if (haveScreens() && !screens.isEmpty()) {
text += ",";
for (int i = 0; i < screens.size(); i++)
{
text += screens[i];
if (i != screens.size() - 1)
text += ":";
}
}
else
text += ",*";
}
}
break;
case switchToScreen:
text += switchScreenName();
break;
case switchInDirection:
text += m_SwitchDirectionNames[m_SwitchDirection];
break;
case lockCursorToScreen:
text += m_LockCursorModeNames[m_LockCursorMode];
break;
case restartAllConnections:
text += "restart";
break;
default:
Q_ASSERT(0);
break;
for (int i = 0; i < screens.size(); i++) {
text += screens[i];
if (i != screens.size() - 1)
text += ":";
}
} else
text += ",*";
}
} break;
text += ")";
case switchToScreen:
text += switchScreenName();
break;
return text;
case switchInDirection:
text += m_SwitchDirectionNames[m_SwitchDirection];
break;
case lockCursorToScreen:
text += m_LockCursorModeNames[m_LockCursorMode];
break;
case restartAllConnections:
text += "restart";
break;
default:
Q_ASSERT(0);
break;
}
text += ")";
return text;
}
void Action::loadSettings(QSettings& settings)
{
keySequence().loadSettings(settings);
setType(settings.value("type", keyDown).toInt());
void Action::loadSettings(QSettings &settings) {
keySequence().loadSettings(settings);
setType(settings.value("type", keyDown).toInt());
typeScreenNames().clear();
int numTypeScreens = settings.beginReadArray("typeScreenNames");
for (int i = 0; i < numTypeScreens; i++)
{
settings.setArrayIndex(i);
typeScreenNames().append(settings.value("typeScreenName").toString());
}
settings.endArray();
typeScreenNames().clear();
int numTypeScreens = settings.beginReadArray("typeScreenNames");
for (int i = 0; i < numTypeScreens; i++) {
settings.setArrayIndex(i);
typeScreenNames().append(settings.value("typeScreenName").toString());
}
settings.endArray();
setSwitchScreenName(settings.value("switchScreenName").toString());
setSwitchDirection(settings.value("switchInDirection", switchLeft).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());
setSwitchScreenName(settings.value("switchScreenName").toString());
setSwitchDirection(settings.value("switchInDirection", switchLeft).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
{
keySequence().saveSettings(settings);
settings.setValue("type", type());
void Action::saveSettings(QSettings &settings) const {
keySequence().saveSettings(settings);
settings.setValue("type", type());
settings.beginWriteArray("typeScreenNames");
for (int i = 0; i < typeScreenNames().size(); i++)
{
settings.setArrayIndex(i);
settings.setValue("typeScreenName", typeScreenNames()[i]);
}
settings.endArray();
settings.beginWriteArray("typeScreenNames");
for (int i = 0; i < typeScreenNames().size(); i++) {
settings.setArrayIndex(i);
settings.setValue("typeScreenName", typeScreenNames()[i]);
}
settings.endArray();
settings.setValue("switchScreenName", switchScreenName());
settings.setValue("switchInDirection", switchDirection());
settings.setValue("lockCursorToScreen", lockCursorMode());
settings.setValue("activeOnRelease", activeOnRelease());
settings.setValue("hasScreens", haveScreens());
settings.setValue("restartServer", restartServer());
settings.setValue("switchScreenName", switchScreenName());
settings.setValue("switchInDirection", switchDirection());
settings.setValue("lockCursorToScreen", lockCursorMode());
settings.setValue("activeOnRelease", activeOnRelease());
settings.setValue("hasScreens", haveScreens());
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 &&
m_HasScreens == a.m_HasScreens &&
m_restartServer == a.m_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 &&
m_HasScreens == a.m_HasScreens && m_restartServer == a.m_restartServer;
}
QTextStream& operator<<(QTextStream& outStream, const Action& action)
{
if (action.activeOnRelease())
outStream << ";";
QTextStream &operator<<(QTextStream &outStream, const Action &action) {
if (action.activeOnRelease())
outStream << ";";
outStream << action.text();
outStream << action.text();
return outStream;
return outStream;
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -22,93 +22,83 @@
#include "KeySequence.h"
#include <QList>
#include <QString>
#include <QStringList>
#include <QList>
class ActionDialog;
class QSettings;
class QTextStream;
class Action
{
friend class ActionDialog;
friend QTextStream& operator<<(QTextStream& outStream, const Action& action);
class Action {
friend class ActionDialog;
friend QTextStream &operator<<(QTextStream &outStream, const Action &action);
public:
enum ActionType {
keyDown,
keyUp,
keystroke,
switchToScreen,
switchInDirection,
lockCursorToScreen,
restartAllConnections,
mouseDown,
mouseUp,
mousebutton,
};
enum SwitchDirection {
switchLeft,
switchRight,
switchUp,
switchDown
};
enum LockCursorMode {
lockCursorToggle,
lockCursonOn,
lockCursorOff
};
public:
enum ActionType {
keyDown,
keyUp,
keystroke,
switchToScreen,
switchInDirection,
lockCursorToScreen,
restartAllConnections,
mouseDown,
mouseUp,
mousebutton,
};
enum SwitchDirection { switchLeft, switchRight, switchUp, switchDown };
enum LockCursorMode { lockCursorToggle, lockCursonOn, lockCursorOff };
public:
Action();
public:
Action();
public:
QString text() const;
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; }
public:
QString text() const;
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; }
bool operator==(const Action& a) const;
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; }
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; }
private:
KeySequence m_KeySequence;
int m_Type;
QStringList m_TypeScreenNames;
QString m_SwitchScreenName;
int m_SwitchDirection;
int m_LockCursorMode;
bool m_ActiveOnRelease;
bool m_HasScreens;
bool m_restartServer;
private:
KeySequence m_KeySequence;
int m_Type;
QStringList m_TypeScreenNames;
QString m_SwitchScreenName;
int m_SwitchDirection;
int m_LockCursorMode;
bool m_ActiveOnRelease;
bool m_HasScreens;
bool m_restartServer;
static const char* m_ActionTypeNames[];
static const char* m_SwitchDirectionNames[];
static const char* m_LockCursorModeNames[];
static const char *m_ActionTypeNames[];
static const char *m_SwitchDirectionNames[];
static const char *m_LockCursorModeNames[];
};
typedef QList<Action> ActionList;
QTextStream& operator<<(QTextStream& outStream, const Action& action);
QTextStream &operator<<(QTextStream &outStream, const Action &action);
#endif

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -18,94 +18,93 @@
#include "ActionDialog.h"
#include "Hotkey.h"
#include "Action.h"
#include "ServerConfig.h"
#include "Hotkey.h"
#include "KeySequence.h"
#include "ServerConfig.h"
#include <QButtonGroup>
#include <QtCore>
#include <QtGui>
#include <QButtonGroup>
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))
{
setupUi(this);
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)) {
setupUi(this);
// work around Qt Designer's lack of a QButtonGroup; we need it to get
// at the button id of the checked radio button
QRadioButton* const typeButtons[] = { m_pRadioPress, m_pRadioRelease, m_pRadioPressAndRelease, m_pRadioSwitchToScreen, m_pRadioSwitchInDirection, m_pRadioLockCursorToScreen , m_pRadioRestartAllConnections};
// work around Qt Designer's lack of a QButtonGroup; we need it to get
// at the button id of the checked radio button
QRadioButton *const typeButtons[] = {m_pRadioPress,
m_pRadioRelease,
m_pRadioPressAndRelease,
m_pRadioSwitchToScreen,
m_pRadioSwitchInDirection,
m_pRadioLockCursorToScreen,
m_pRadioRestartAllConnections};
for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++)
m_pButtonGroupType->addButton(typeButtons[i], 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());
m_pKeySequenceWidgetHotkey->setKeySequence(m_Action.keySequence());
m_pButtonGroupType->button(m_Action.type())->setChecked(true);
m_pComboSwitchInDirection->setCurrentIndex(m_Action.switchDirection());
m_pComboLockCursorToScreen->setCurrentIndex(m_Action.lockCursorMode());
m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString());
m_pKeySequenceWidgetHotkey->setKeySequence(m_Action.keySequence());
m_pButtonGroupType->button(m_Action.type())->setChecked(true);
m_pComboSwitchInDirection->setCurrentIndex(m_Action.switchDirection());
m_pComboLockCursorToScreen->setCurrentIndex(m_Action.lockCursorMode());
if (m_Action.activeOnRelease())
m_pRadioHotkeyReleased->setChecked(true);
else
m_pRadioHotkeyPressed->setChecked(true);
if (m_Action.activeOnRelease())
m_pRadioHotkeyReleased->setChecked(true);
else
m_pRadioHotkeyPressed->setChecked(true);
m_pGroupBoxScreens->setChecked(m_Action.haveScreens());
m_pGroupBoxScreens->setChecked(m_Action.haveScreens());
int idx = 0;
foreach(const Screen& screen, serverConfig().screens())
if (!screen.isNull())
{
QListWidgetItem *pListItem = new QListWidgetItem(screen.name());
m_pListScreens->addItem(pListItem);
if (m_Action.typeScreenNames().indexOf(screen.name()) != -1)
m_pListScreens->setCurrentItem(pListItem);
int idx = 0;
foreach (const Screen &screen, serverConfig().screens())
if (!screen.isNull()) {
QListWidgetItem *pListItem = new QListWidgetItem(screen.name());
m_pListScreens->addItem(pListItem);
if (m_Action.typeScreenNames().indexOf(screen.name()) != -1)
m_pListScreens->setCurrentItem(pListItem);
m_pComboSwitchToScreen->addItem(screen.name());
if (screen.name() == m_Action.switchScreenName())
m_pComboSwitchToScreen->setCurrentIndex(idx);
m_pComboSwitchToScreen->addItem(screen.name());
if (screen.name() == m_Action.switchScreenName())
m_pComboSwitchToScreen->setCurrentIndex(idx);
idx++;
}
}
void ActionDialog::accept()
{
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 && m_pButtonGroupType->checkedId() < 3)
return;
m_Action.setKeySequence(sequenceWidget()->keySequence());
m_Action.setType(m_pButtonGroupType->checkedId());
m_Action.setHaveScreens(m_pGroupBoxScreens->isChecked());
m_Action.typeScreenNames().clear();
foreach(const QListWidgetItem* pItem, m_pListScreens->selectedItems())
m_Action.typeScreenNames().append(pItem->text());
m_Action.setSwitchScreenName(m_pComboSwitchToScreen->currentText());
m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex());
m_Action.setLockCursorMode(m_pComboLockCursorToScreen->currentIndex());
m_Action.setActiveOnRelease(m_pRadioHotkeyReleased->isChecked());
m_Action.setRestartServer(m_pRadioRestartAllConnections->isChecked());
QDialog::accept();
}
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged()
{
if (sequenceWidget()->keySequence().isMouseButton())
{
m_pGroupBoxScreens->setEnabled(false);
m_pListScreens->setEnabled(false);
}
else
{
m_pGroupBoxScreens->setEnabled(true);
m_pListScreens->setEnabled(true);
idx++;
}
}
void ActionDialog::accept() {
if (!sequenceWidget()->valid() && m_pButtonGroupType->checkedId() >= 0 &&
m_pButtonGroupType->checkedId() < 3)
return;
m_Action.setKeySequence(sequenceWidget()->keySequence());
m_Action.setType(m_pButtonGroupType->checkedId());
m_Action.setHaveScreens(m_pGroupBoxScreens->isChecked());
m_Action.typeScreenNames().clear();
foreach (const QListWidgetItem *pItem, m_pListScreens->selectedItems())
m_Action.typeScreenNames().append(pItem->text());
m_Action.setSwitchScreenName(m_pComboSwitchToScreen->currentText());
m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex());
m_Action.setLockCursorMode(m_pComboLockCursorToScreen->currentIndex());
m_Action.setActiveOnRelease(m_pRadioHotkeyReleased->isChecked());
m_Action.setRestartServer(m_pRadioRestartAllConnections->isChecked());
QDialog::accept();
}
void ActionDialog::on_m_pKeySequenceWidgetHotkey_keySequenceChanged() {
if (sequenceWidget()->keySequence().isMouseButton()) {
m_pGroupBoxScreens->setEnabled(false);
m_pListScreens->setEnabled(false);
} else {
m_pGroupBoxScreens->setEnabled(true);
m_pListScreens->setEnabled(true);
}
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -30,27 +30,29 @@ class QRadioButton;
class QButtonGroup;
class ServerConfig;
class ActionDialog : public QDialog, public Ui::ActionDialogBase
{
Q_OBJECT
class ActionDialog : public QDialog, public Ui::ActionDialogBase {
Q_OBJECT
public:
ActionDialog(QWidget* parent, ServerConfig& config, Hotkey& hotkey, Action& action);
public:
ActionDialog(QWidget *parent, ServerConfig &config, Hotkey &hotkey,
Action &action);
protected slots:
void accept();
void on_m_pKeySequenceWidgetHotkey_keySequenceChanged();
protected slots:
void accept();
void on_m_pKeySequenceWidgetHotkey_keySequenceChanged();
protected:
const KeySequenceWidget* sequenceWidget() const { return m_pKeySequenceWidgetHotkey; }
const ServerConfig& serverConfig() const { return m_ServerConfig; }
protected:
const KeySequenceWidget *sequenceWidget() const {
return m_pKeySequenceWidgetHotkey;
}
const ServerConfig &serverConfig() const { return m_ServerConfig; }
private:
const ServerConfig& m_ServerConfig;
Hotkey& m_Hotkey;
Action& m_Action;
private:
const ServerConfig &m_ServerConfig;
Hotkey &m_Hotkey;
Action &m_Action;
QButtonGroup* m_pButtonGroupType;
QButtonGroup *m_pButtonGroupType;
};
#endif

View file

@ -1,107 +1,102 @@
#include "ActivationDialog.h"
#include "ui_ActivationDialog.h"
#include "CancelActivationDialog.h"
#include "AppConfig.h"
#include <shared/EditionType.h>
#include "ActivationNotifier.h"
#include "AppConfig.h"
#include "CancelActivationDialog.h"
#include "FailedLoginDialog.h"
#include "LicenseManager.h"
#include "MainWindow.h"
#include "QUtility.h"
#include "LicenseManager.h"
#include "FailedLoginDialog.h"
#include "ui_ActivationDialog.h"
#include <shared/EditionType.h>
#include <QMessageBox>
#include <QThread>
#include <iostream>
ActivationDialog::ActivationDialog(QWidget* parent, AppConfig& appConfig,
LicenseManager& licenseManager) :
QDialog(parent),
ui(new Ui::ActivationDialog),
m_appConfig(&appConfig),
m_LicenseManager (&licenseManager)
{
ui->setupUi(this);
ActivationDialog::ActivationDialog(QWidget *parent, AppConfig &appConfig,
LicenseManager &licenseManager)
: QDialog(parent), ui(new Ui::ActivationDialog), m_appConfig(&appConfig),
m_LicenseManager(&licenseManager) {
ui->setupUi(this);
refreshSerialKey();
time_t currentTime = ::time(0);
if (!m_LicenseManager->serialKey().isExpired(currentTime)) {
ui->m_trialWidget->hide();
}
}
void ActivationDialog::refreshSerialKey() {
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
ui->m_trialLabel->setText(
tr(m_LicenseManager->getLicenseNotice().toStdString().c_str()));
}
ActivationDialog::~ActivationDialog() { delete ui; }
void ActivationDialog::reject() {
if (m_LicenseManager->activeEdition() == kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_LicenseManager->skipActivation();
} else {
return;
}
}
QDialog::reject();
}
void ActivationDialog::accept() {
QMessageBox message;
m_appConfig->activationHasRun(true);
try {
SerialKey serialKey(
ui->m_pTextEditSerialKey->toPlainText().trimmed().toStdString());
m_LicenseManager->setSerialKey(serialKey);
} catch (std::exception &e) {
message.critical(
this, "Activation failed",
tr("An error occurred while trying to activate Synergy. "
"<a href=\"https://symless.com/synergy/contact-support?source=gui\" "
"style=\"text-decoration: none; color: #4285F4;\">"
"Please contact the helpdesk</a>, and provide the following "
"information:"
"<br><br>%1")
.arg(e.what()));
refreshSerialKey();
time_t currentTime = ::time(0);
if (!m_LicenseManager->serialKey().isExpired(currentTime)) {
ui->m_trialWidget->hide();
}
}
return;
}
void ActivationDialog::refreshSerialKey()
{
ui->m_pTextEditSerialKey->setText(m_appConfig->serialKey());
ui->m_pTextEditSerialKey->setFocus();
ui->m_pTextEditSerialKey->moveCursor(QTextCursor::End);
ui->m_trialLabel->setText(tr(m_LicenseManager->getLicenseNotice().toStdString().c_str()));
}
m_LicenseManager->notifyActivation("serial:" + m_appConfig->serialKey());
Edition edition = m_LicenseManager->activeEdition();
time_t daysLeft = m_LicenseManager->serialKey().daysLeft(::time(0));
if (edition != kUnregistered) {
QString thanksMessage = tr("Thanks for trying %1! %5\n\n%2 day%3 of "
"your trial remain%4")
.arg(m_LicenseManager->getEditionName(edition))
.arg(daysLeft)
.arg((daysLeft == 1) ? "" : "s")
.arg((daysLeft == 1) ? "s" : "");
ActivationDialog::~ActivationDialog()
{
delete ui;
}
void ActivationDialog::reject()
{
if (m_LicenseManager->activeEdition() == kUnregistered) {
CancelActivationDialog cancelActivationDialog(this);
if (QDialog::Accepted == cancelActivationDialog.exec()) {
m_LicenseManager->skipActivation();
} else {
return;
}
}
QDialog::reject();
}
void ActivationDialog::accept()
{
QMessageBox message;
m_appConfig->activationHasRun(true);
try {
SerialKey serialKey (ui->m_pTextEditSerialKey->toPlainText().
trimmed().toStdString());
m_LicenseManager->setSerialKey(serialKey);
}
catch (std::exception& e) {
message.critical(this, "Activation failed",
tr("An error occurred while trying to activate Synergy. "
"<a href=\"https://symless.com/synergy/contact-support?source=gui\" style=\"text-decoration: none; color: #4285F4;\">"
"Please contact the helpdesk</a>, and provide the following information:"
"<br><br>%1").arg(e.what()));
refreshSerialKey();
return;
}
m_LicenseManager->notifyActivation("serial:" + m_appConfig->serialKey());
Edition edition = m_LicenseManager->activeEdition();
time_t daysLeft = m_LicenseManager->serialKey().daysLeft(::time(0));
if (edition != kUnregistered) {
QString thanksMessage = tr("Thanks for trying %1! %5\n\n%2 day%3 of "
"your trial remain%4").
arg (m_LicenseManager->getEditionName(edition)).
arg (daysLeft).
arg ((daysLeft == 1) ? "" : "s").
arg ((daysLeft == 1) ? "s" : "");
if (m_appConfig->isCryptoAvailable()) {
m_appConfig->generateCertificate();
thanksMessage = thanksMessage.arg("If you're using SSL, "
if (m_appConfig->isCryptoAvailable()) {
m_appConfig->generateCertificate();
thanksMessage =
thanksMessage.arg("If you're using SSL, "
"remember to activate all of your devices.");
} else {
thanksMessage = thanksMessage.arg("");
}
if (m_LicenseManager->serialKey().isTrial()) {
message.information(this, "Thanks!", thanksMessage);
}
else {
message.information(this, "Activated!",
tr("Thanks for activating %1!").arg
(m_LicenseManager->getEditionName(edition)));
}
} else {
thanksMessage = thanksMessage.arg("");
}
QDialog::accept();
if (m_LicenseManager->serialKey().isTrial()) {
message.information(this, "Thanks!", thanksMessage);
} else {
message.information(this, "Activated!",
tr("Thanks for activating %1!")
.arg(m_LicenseManager->getEditionName(edition)));
}
}
QDialog::accept();
}

View file

@ -1,8 +1,8 @@
#ifndef ACTIVATIONDIALOG_H
#define ACTIVATIONDIALOG_H
#include <QDialog>
#include <LicenseManager.h>
#include <QDialog>
namespace Ui {
class ActivationDialog;
@ -10,26 +10,25 @@ class ActivationDialog;
class AppConfig;
class ActivationDialog : public QDialog
{
Q_OBJECT
class ActivationDialog : public QDialog {
Q_OBJECT
public:
ActivationDialog(QWidget *parent, AppConfig& appConfig,
LicenseManager& licenseManager);
~ActivationDialog();
ActivationDialog(QWidget *parent, AppConfig &appConfig,
LicenseManager &licenseManager);
~ActivationDialog();
public slots:
void reject();
void accept();
void reject();
void accept();
protected:
void refreshSerialKey();
void refreshSerialKey();
private:
Ui::ActivationDialog *ui;
AppConfig* m_appConfig;
LicenseManager* m_LicenseManager;
Ui::ActivationDialog *ui;
AppConfig *m_appConfig;
LicenseManager *m_LicenseManager;
};
#endif // ACTIVATIONDIALOG_H

View file

@ -19,31 +19,24 @@
#include "CoreInterface.h"
ActivationNotifier::ActivationNotifier(QObject *parent) :
QObject(parent)
{
ActivationNotifier::ActivationNotifier(QObject *parent) : QObject(parent) {}
void ActivationNotifier::setIdentity(QString identity) {
m_Identity = identity;
}
void ActivationNotifier::setIdentity(QString identity)
{
m_Identity = identity;
void ActivationNotifier::setUpdateInfo(QString const &fromVersion,
QString const &toVersion,
QString const &serialKey) {
m_fromVersion = fromVersion;
m_toVersion = toVersion;
m_serialKey = serialKey;
}
void ActivationNotifier::setUpdateInfo(QString const& fromVersion,
QString const& toVersion,
QString const& serialKey)
{
m_fromVersion = fromVersion;
m_toVersion = toVersion;
m_serialKey = serialKey;
void ActivationNotifier::notify() {
// TODO: use something other than CURL
}
void ActivationNotifier::notify()
{
// TODO: use something other than CURL
}
void ActivationNotifier::notifyUpdate()
{
// TODO: use something other than CURL
void ActivationNotifier::notifyUpdate() {
// TODO: use something other than CURL
}

View file

@ -20,28 +20,27 @@
#include <QObject>
class ActivationNotifier : public QObject
{
Q_OBJECT
class ActivationNotifier : public QObject {
Q_OBJECT
public:
explicit ActivationNotifier(QObject *parent = 0);
explicit ActivationNotifier(QObject *parent = 0);
void setIdentity(QString identity);
void setUpdateInfo(QString const& fromVersion,
QString const& toVersion, QString const& serialKey);
void setIdentity(QString identity);
void setUpdateInfo(QString const &fromVersion, QString const &toVersion,
QString const &serialKey);
public slots:
void notify();
void notifyUpdate();
void notify();
void notifyUpdate();
signals:
void finished();
void finished();
private:
QString m_Identity;
QString m_fromVersion;
QString m_toVersion;
QString m_serialKey;
QString m_Identity;
QString m_fromVersion;
QString m_toVersion;
QString m_serialKey;
};
#endif // ACTIVATIONNOTIFIER_H

View file

@ -18,112 +18,103 @@
#include "AddClientDialog.h"
#include "ui_AddClientDialogBase.h"
#include <QPushButton>
#include <QLabel>
#include <QPushButton>
AddClientDialog::AddClientDialog(const QString& clientName, QWidget* parent) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::AddClientDialog(),
m_AddResult(kAddClientIgnore),
m_IgnoreAutoConfigClient(false)
{
setupUi(this);
AddClientDialog::AddClientDialog(const QString &clientName, QWidget *parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::AddClientDialog(), m_AddResult(kAddClientIgnore),
m_IgnoreAutoConfigClient(false) {
setupUi(this);
m_pLabelHead->setText("A client wants to connect. "
"Please choose a location for " + clientName + ".");
m_pLabelHead->setText("A client wants to connect. "
"Please choose a location for " +
clientName + ".");
QIcon icon(":res/icons/64x64/video-display.png");
QSize IconSize(32,32);
QIcon icon(":res/icons/64x64/video-display.png");
QSize IconSize(32, 32);
m_pButtonLeft = new QPushButton(this);
m_pButtonLeft->setIcon(icon);
m_pButtonLeft->setIconSize(IconSize);
gridLayout->addWidget(m_pButtonLeft, 2, 0, 1, 1, Qt::AlignCenter);
connect(m_pButtonLeft, SIGNAL(clicked()), this, SLOT(handleButtonLeft()));
m_pButtonLeft = new QPushButton(this);
m_pButtonLeft->setIcon(icon);
m_pButtonLeft->setIconSize(IconSize);
gridLayout->addWidget(m_pButtonLeft, 2, 0, 1, 1, Qt::AlignCenter);
connect(m_pButtonLeft, SIGNAL(clicked()), this, SLOT(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, SIGNAL(clicked()), this, SLOT(handleButtonUp()));
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, SIGNAL(clicked()), this, SLOT(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, SIGNAL(clicked()), this, SLOT(handleButtonRight()));
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, SIGNAL(clicked()), this, SLOT(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, SIGNAL(clicked()), this, SLOT(handleButtonDown()));
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, SIGNAL(clicked()), this, SLOT(handleButtonDown()));
m_pLabelCenter = new QLabel(this);
m_pLabelCenter->setPixmap(QPixmap(":res/icons/64x64/video-display.png"));
gridLayout->addWidget(m_pLabelCenter, 2, 1, 1, 1, Qt::AlignCenter);
m_pLabelCenter = new QLabel(this);
m_pLabelCenter->setPixmap(QPixmap(":res/icons/64x64/video-display.png"));
gridLayout->addWidget(m_pLabelCenter, 2, 1, 1, 1, Qt::AlignCenter);
#if defined(Q_OS_MAC)
m_pDialogButtonBox->setLayoutDirection(Qt::RightToLeft);
m_pDialogButtonBox->setLayoutDirection(Qt::RightToLeft);
#endif
QPushButton* advanced = m_pDialogButtonBox->addButton("Advanced",
QDialogButtonBox::HelpRole);
connect(advanced, SIGNAL(clicked()), this, SLOT(handleButtonAdvanced()));
QPushButton *advanced =
m_pDialogButtonBox->addButton("Advanced", QDialogButtonBox::HelpRole);
connect(advanced, SIGNAL(clicked()), this, SLOT(handleButtonAdvanced()));
}
AddClientDialog::~AddClientDialog()
{
delete m_pButtonUp;
delete m_pButtonDown;
delete m_pButtonLeft;
delete m_pButtonRight;
delete m_pLabelCenter;
AddClientDialog::~AddClientDialog() {
delete m_pButtonUp;
delete m_pButtonDown;
delete m_pButtonLeft;
delete m_pButtonRight;
delete m_pLabelCenter;
}
void AddClientDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
void AddClientDialog::changeEvent(QEvent *e) {
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
retranslateUi(this);
break;
default:
break;
}
}
void AddClientDialog::handleButtonLeft()
{
m_AddResult = kAddClientLeft;
close();
void AddClientDialog::handleButtonLeft() {
m_AddResult = kAddClientLeft;
close();
}
void AddClientDialog::handleButtonUp()
{
m_AddResult = kAddClientUp;
close();
void AddClientDialog::handleButtonUp() {
m_AddResult = kAddClientUp;
close();
}
void AddClientDialog::handleButtonRight()
{
m_AddResult = kAddClientRight;
close();
void AddClientDialog::handleButtonRight() {
m_AddResult = kAddClientRight;
close();
}
void AddClientDialog::handleButtonDown()
{
m_AddResult = kAddClientDown;
close();
void AddClientDialog::handleButtonDown() {
m_AddResult = kAddClientDown;
close();
}
void AddClientDialog::handleButtonAdvanced()
{
m_AddResult = kAddClientOther;
close();
void AddClientDialog::handleButtonAdvanced() {
m_AddResult = kAddClientOther;
close();
}
void AddClientDialog::on_m_pCheckBoxIgnoreClient_toggled(bool checked)
{
m_IgnoreAutoConfigClient = checked;
void AddClientDialog::on_m_pCheckBoxIgnoreClient_toggled(bool checked) {
m_IgnoreAutoConfigClient = checked;
}

View file

@ -26,43 +26,42 @@ class QPushButton;
class QLabel;
enum {
kAddClientRight,
kAddClientLeft,
kAddClientUp,
kAddClientDown,
kAddClientOther,
kAddClientIgnore
kAddClientRight,
kAddClientLeft,
kAddClientUp,
kAddClientDown,
kAddClientOther,
kAddClientIgnore
};
class AddClientDialog : public QDialog, public Ui::AddClientDialog
{
Q_OBJECT
class AddClientDialog : public QDialog, public Ui::AddClientDialog {
Q_OBJECT
public:
AddClientDialog(const QString& clientName, QWidget* parent = 0);
~AddClientDialog();
AddClientDialog(const QString &clientName, QWidget *parent = 0);
~AddClientDialog();
int addResult() { return m_AddResult; }
bool ignoreAutoConfigClient() { return m_IgnoreAutoConfigClient; }
int addResult() { return m_AddResult; }
bool ignoreAutoConfigClient() { return m_IgnoreAutoConfigClient; }
protected:
void changeEvent(QEvent *e);
void changeEvent(QEvent *e);
private slots:
void on_m_pCheckBoxIgnoreClient_toggled(bool checked);
void handleButtonLeft();
void handleButtonUp();
void handleButtonRight();
void handleButtonDown();
void handleButtonAdvanced();
void on_m_pCheckBoxIgnoreClient_toggled(bool checked);
void handleButtonLeft();
void handleButtonUp();
void handleButtonRight();
void handleButtonDown();
void handleButtonAdvanced();
private:
QPushButton* m_pButtonLeft;
QPushButton* m_pButtonUp;
QPushButton* m_pButtonRight;
QPushButton* m_pButtonDown;
QLabel* m_pLabelCenter;
int m_AddResult;
bool m_IgnoreAutoConfigClient;
QPushButton *m_pButtonLeft;
QPushButton *m_pButtonUp;
QPushButton *m_pButtonRight;
QPushButton *m_pButtonDown;
QLabel *m_pLabelCenter;
int m_AddResult;
bool m_IgnoreAutoConfigClient;
};
#endif // ADDCLIENTDIALOG_H

File diff suppressed because it is too large Load diff

View file

@ -20,15 +20,15 @@
#define APPCONFIG_H
#include <QObject>
#include <QString>
#include <QVariant>
#include "ElevateMode.h"
#include <shared/EditionType.h>
#include <mutex>
#include "ConfigBase.h"
#include "ConfigWriter.h"
#include "CoreInterface.h"
#include "ElevateMode.h"
#include <QObject>
#include <QString>
#include <QVariant>
#include <mutex>
#include <shared/EditionType.h>
// this should be incremented each time a new page is added. this is
// saved to settings when the user finishes running the wizard. if
@ -52,308 +52,307 @@ class SettingsDialog;
class ServerConfig;
class LicenseRegister;
enum ProcessMode {
Service,
Desktop
};
enum ProcessMode { Service, Desktop };
class AppConfig: public QObject, public GUI::Config::ConfigBase
{
Q_OBJECT
class AppConfig : public QObject, public GUI::Config::ConfigBase {
Q_OBJECT
friend class SettingsDialog;
friend class MainWindow;
friend class SetupWizard;
friend class ServerConfig;
friend class SettingsDialog;
friend class MainWindow;
friend class SetupWizard;
friend class ServerConfig;
public:
AppConfig();
public:
AppConfig();
public:
bool isWritable() const;
bool isSystemScoped() const;
public:
bool isWritable() const;
bool isSystemScoped() const;
const QString& screenName() const;
int port() const;
const QString& networkInterface() const;
int logLevel() const;
bool logToFile() const;
const QString& logFilename() const;
const QString logFilenameCmd() const;
QString logLevelText() const;
ProcessMode processMode() const;
bool wizardShouldRun() const;
const QString& language() const;
bool startedBefore() const;
bool autoConfig() const;
void setAutoConfig(bool autoConfig);
QString autoConfigServer() const;
void setAutoConfigServer(const QString& autoConfigServer);
const QString &screenName() const;
int port() const;
const QString &networkInterface() const;
int logLevel() const;
bool logToFile() const;
const QString &logFilename() const;
const QString logFilenameCmd() const;
QString logLevelText() const;
ProcessMode processMode() const;
bool wizardShouldRun() const;
const QString &language() const;
bool startedBefore() const;
bool autoConfig() const;
void setAutoConfig(bool autoConfig);
QString autoConfigServer() const;
void setAutoConfigServer(const QString &autoConfigServer);
#ifndef SYNERGY_ENTERPRISE
void setEdition(Edition);
Edition edition() const;
void setSerialKey(const QString& serial);
void clearSerialKey();
QString serialKey() const;
int lastExpiringWarningTime() const;
void setLastExpiringWarningTime(int t);
void setEdition(Edition);
Edition edition() const;
void setSerialKey(const QString &serial);
void clearSerialKey();
QString serialKey() const;
int lastExpiringWarningTime() const;
void setLastExpiringWarningTime(int t);
#endif
QString synergysName() const;
QString synergycName() const;
QString synergyProgramDir() const;
QString synergyLogDir() const;
QString synergysName() const;
QString synergycName() const;
QString synergyProgramDir() const;
QString synergyLogDir() const;
void persistLogDir();
ElevateMode elevateMode();
void persistLogDir();
ElevateMode elevateMode();
bool isCryptoAvailable() const;
void setCryptoEnabled(bool e);
bool getCryptoEnabled() const;
bool isCryptoAvailable() const;
void setCryptoEnabled(bool e);
bool getCryptoEnabled() const;
void setAutoHide(bool b);
bool getAutoHide();
void setInvertScrollDirection(bool b);
bool getInvertScrollDirection() const;
void setEliteBackersUrl(const QString&);
void setLicenseNextCheck(unsigned long long);
const QString& getEliteBackersUrl() const;
const QString& getLicenseRegistryUrl() const;
unsigned long long getLicenseNextCheck() const;
const QString& getGuid() const;
void setLanguageSync(bool b);
bool getLanguageSync() const;
void setPreventSleep(bool b);
bool getPreventSleep() const;
bool getClientHostMode() const;
bool getServerClientMode() const;
bool getInitiateConnectionFromServer() const;
void setAutoHide(bool b);
bool getAutoHide();
void setInvertScrollDirection(bool b);
bool getInvertScrollDirection() const;
void setEliteBackersUrl(const QString &);
void setLicenseNextCheck(unsigned long long);
const QString &getEliteBackersUrl() const;
const QString &getLicenseRegistryUrl() const;
unsigned long long getLicenseNextCheck() const;
const QString &getGuid() const;
void setLanguageSync(bool b);
bool getLanguageSync() const;
void setPreventSleep(bool b);
bool getPreventSleep() const;
bool getClientHostMode() const;
bool getServerClientMode() const;
bool getInitiateConnectionFromServer() const;
#ifndef SYNERGY_ENTERPRISE
bool activationHasRun() const;
AppConfig& activationHasRun(bool value);
bool activationHasRun() const;
AppConfig &activationHasRun(bool value);
#endif
/// @brief Sets the user preference to load from SystemScope.
/// @param [in] value
/// True - This will set the variable and load the global scope settings.
/// False - This will set the variable and load the user scope settings.
void setLoadFromSystemScope(bool value);
/// @brief Sets the user preference to load from SystemScope.
/// @param [in] value
/// True - This will set the variable and load the global scope
/// settings. False - This will set the variable and load the user
/// scope settings.
void setLoadFromSystemScope(bool value);
bool getServerGroupChecked() const;
bool getUseExternalConfig() const;
const QString &getConfigFile() const;
bool getUseInternalConfig() const;
bool getClientGroupChecked() const;
QString getServerHostname() const;
bool getServerGroupChecked() const;
bool getUseExternalConfig() const;
const QString& getConfigFile() const;
bool getUseInternalConfig() const;
bool getClientGroupChecked() const;
QString getServerHostname() const;
/// @brief Gets the current TLS certificate path
/// @return QString The path to the cert
QString getTLSCertPath() const;
/// @brief Gets the current TLS certificate path
/// @return QString The path to the cert
QString getTLSCertPath() const;
/// @brief Get the key length to be used for the private key of a TLS cert
/// @return QString The key length in bits
QString getTLSKeyLength() const;
/// @brief Get the key length to be used for the private key of a TLS cert
/// @return QString The key length in bits
QString getTLSKeyLength() const;
void setServerGroupChecked(bool);
void setUseExternalConfig(bool);
void setConfigFile(const QString &);
void setUseInternalConfig(bool);
void setClientGroupChecked(bool);
void setServerHostname(const QString &);
void setClientHostMode(bool newValue);
void setServerClientMode(bool newValue);
void setServerGroupChecked(bool);
void setUseExternalConfig(bool) ;
void setConfigFile(const QString&);
void setUseInternalConfig(bool) ;
void setClientGroupChecked(bool) ;
void setServerHostname(const QString&);
void setClientHostMode(bool newValue);
void setServerClientMode(bool newValue);
/// @brief Set the path to the TLS/SSL certificate file that will be used
/// @param [in] path The path to the Certificate
void setTLSCertPath(const QString &path);
/// @brief Set the path to the TLS/SSL certificate file that will be used
/// @param [in] path The path to the Certificate
void setTLSCertPath(const QString& path);
/// @brief Sets the key length of the private key to use in a TLS connection
/// @param [in] QString length The key length eg: 1024, 2048, 4096
void setTLSKeyLength(const QString &length);
/// @brief Sets the key length of the private key to use in a TLS connection
/// @param [in] QString length The key length eg: 1024, 2048, 4096
void setTLSKeyLength(const QString& length);
QString lastVersion() const;
void setMinimizeToTray(bool b);
bool getMinimizeToTray();
QString lastVersion() const;
void saveSettings() override;
void setLastVersion(const QString &version);
void setMinimizeToTray(bool b);
bool getMinimizeToTray();
void saveSettings() override;
void setLastVersion(const QString& version);
/// @brief Generates TLS certificate
/// @param [in] bool forceGeneration Generate certificate even if it's exists.
void generateCertificate(bool forceGeneration=false) const;
/// @brief Generates TLS certificate
/// @param [in] bool forceGeneration Generate certificate even if it's exists.
void generateCertificate(bool forceGeneration = false) const;
protected:
/// @brief The enumeration to easily access the names of the setting inside m_SynergySettingsName
enum Setting {
kScreenName,
kPort,
kInterfaceSetting,
kLogLevel,
kLogToFile,
kLogFilename,
kWizardLastRun,
kLanguage,
kStartedBefore,
kAutoConfig,
kAutoConfigServer,
kElevateModeSetting,
kElevateModeEnum,
kEditionSetting,
kCryptoEnabled,
kAutoHide,
kSerialKey,
kLastVersion,
kLastExpireWarningTime,
kActivationHasRun,
kMinimizeToTray,
kActivateEmail,
kLoadSystemSettings,
kGroupServerCheck,
kUseExternalConfig,
kConfigFile,
kUseInternalConfig,
kGroupClientCheck,
kServerHostname,
kTLSCertPath,
kTLSKeyLength,
kPreventSleep,
kLanguageSync,
kInvertScrollDirection,
kEliteBackersUrl,
kGuid,
kLicenseRegistryUrl,
kLicenseNextCheck,
kInitiateConnectionFromServer,
kClientHostMode,
kServerClientMode
};
/// @brief The enumeration to easily access the names of the setting inside
/// m_SynergySettingsName
enum Setting {
kScreenName,
kPort,
kInterfaceSetting,
kLogLevel,
kLogToFile,
kLogFilename,
kWizardLastRun,
kLanguage,
kStartedBefore,
kAutoConfig,
kAutoConfigServer,
kElevateModeSetting,
kElevateModeEnum,
kEditionSetting,
kCryptoEnabled,
kAutoHide,
kSerialKey,
kLastVersion,
kLastExpireWarningTime,
kActivationHasRun,
kMinimizeToTray,
kActivateEmail,
kLoadSystemSettings,
kGroupServerCheck,
kUseExternalConfig,
kConfigFile,
kUseInternalConfig,
kGroupClientCheck,
kServerHostname,
kTLSCertPath,
kTLSKeyLength,
kPreventSleep,
kLanguageSync,
kInvertScrollDirection,
kEliteBackersUrl,
kGuid,
kLicenseRegistryUrl,
kLicenseNextCheck,
kInitiateConnectionFromServer,
kClientHostMode,
kServerClientMode
};
void setScreenName(const QString& s);
void setPort(int i);
void setNetworkInterface(const QString& s);
void setLogLevel(int i);
void setLogToFile(bool b);
void setLogFilename(const QString& s);
void setWizardHasRun();
void setLanguage(const QString& language);
void setStartedBefore(bool b);
void setElevateMode(ElevateMode em);
void setScreenName(const QString &s);
void setPort(int i);
void setNetworkInterface(const QString &s);
void setLogLevel(int i);
void setLogToFile(bool b);
void setLogFilename(const QString &s);
void setWizardHasRun();
void setLanguage(const QString &language);
void setStartedBefore(bool b);
void setElevateMode(ElevateMode em);
/// @brief loads the setting from the current scope
/// @param ignoreSystem should the load feature ignore the globalScope setting that was saved
void loadSettings() override;
static QString settingName(AppConfig::Setting name);
/// @brief loads the setting from the current scope
/// @param ignoreSystem should the load feature ignore the globalScope setting
/// that was saved
void loadSettings() override;
static QString settingName(AppConfig::Setting name);
private:
private:
QString m_ScreenName;
int m_Port;
QString m_Interface;
int m_LogLevel;
bool m_LogToFile;
QString m_LogFilename;
int m_WizardLastRun;
ProcessMode m_ProcessMode;
QString m_Language;
bool m_StartedBefore;
bool m_AutoConfig;
QString m_AutoConfigServer;
ElevateMode m_ElevateMode;
Edition m_Edition;
QString m_ActivateEmail;
bool m_CryptoEnabled;
bool m_AutoHide;
QString m_Serialkey;
QString m_lastVersion;
QString m_eliteBackersUrl;
QString m_guid;
QString m_licenseRegistryUrl;
unsigned long long m_licenseNextCheck;
int m_LastExpiringWarningTime;
bool m_ActivationHasRun;
bool m_MinimizeToTray;
bool m_InvertScrollDirection = false;
bool m_LanguageSync = true;
bool m_PreventSleep = false;
bool m_InitiateConnectionFromServer = false;
bool m_ClientHostMode = true;
bool m_ServerClientMode = true;
QString m_ScreenName;
int m_Port;
QString m_Interface;
int m_LogLevel;
bool m_LogToFile;
QString m_LogFilename;
int m_WizardLastRun;
ProcessMode m_ProcessMode;
QString m_Language;
bool m_StartedBefore;
bool m_AutoConfig;
QString m_AutoConfigServer;
ElevateMode m_ElevateMode;
Edition m_Edition;
QString m_ActivateEmail;
bool m_CryptoEnabled;
bool m_AutoHide;
QString m_Serialkey;
QString m_lastVersion;
QString m_eliteBackersUrl;
QString m_guid;
QString m_licenseRegistryUrl;
unsigned long long m_licenseNextCheck;
int m_LastExpiringWarningTime;
bool m_ActivationHasRun;
bool m_MinimizeToTray;
bool m_InvertScrollDirection = false;
bool m_LanguageSync = true;
bool m_PreventSleep = false;
bool m_InitiateConnectionFromServer = false;
bool m_ClientHostMode = true;
bool m_ServerClientMode = true;
bool m_ServerGroupChecked;
bool m_UseExternalConfig;
QString m_ConfigFile;
bool m_UseInternalConfig;
bool m_ClientGroupChecked;
QString m_ServerHostname;
bool m_ServerGroupChecked;
bool m_UseExternalConfig;
QString m_ConfigFile;
bool m_UseInternalConfig;
bool m_ClientGroupChecked;
QString m_ServerHostname;
QString m_TLSCertificatePath; /// @brief The path to the TLS certificate file
QString m_TLSKeyLength; /// @brief The key length of the TLS cert to make
QString m_TLSCertificatePath; /// @brief The path to the TLS certificate file
QString m_TLSKeyLength; /// @brief The key length of the TLS cert to make
bool m_LoadFromSystemScope; /// @brief should the setting be loaded from
/// SystemScope
/// If the user has settings but this is
/// true then system settings will be
/// loaded instead of the users
bool m_LoadFromSystemScope; /// @brief should the setting be loaded from SystemScope
/// If the user has settings but this is true then
/// system settings will be loaded instead of the users
CoreInterface m_CoreInterface;
CoreInterface m_CoreInterface;
static const char m_SynergysName[];
static const char m_SynergycName[];
static const char m_SynergyLogDir[];
static const char m_SynergysName[];
static const char m_SynergycName[];
static const char m_SynergyLogDir[];
/// @brief Contains the string values of the settings names that will be saved
static const char *m_SynergySettingsName[];
/// @brief Contains the string values of the settings names that will be saved
static const char* m_SynergySettingsName[];
/// @brief Contains the name of the default configuration filename
static const char synergyConfigName[];
/// @brief Contains the name of the default configuration filename
static const char synergyConfigName[];
/// @brief Sets the value of a setting
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved
template <typename T> void setSetting(AppConfig::Setting name, T value);
/// @brief Sets the value of a setting
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved
template <typename T>
void setSetting(AppConfig::Setting name, T value);
/// @brief Sets the value of a common setting
/// which should have the same value for all scopes
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved
template <typename T> void setCommonSetting(AppConfig::Setting name, T value);
/// @brief Sets the value of a common setting
/// which should have the same value for all scopes
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved
template <typename T>
void setCommonSetting(AppConfig::Setting name, T value);
/// @brief Loads a setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
QVariant loadSetting(AppConfig::Setting name,
const QVariant &defaultValue = QVariant());
/// @brief Loads a setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
QVariant loadSetting(AppConfig::Setting name, const QVariant& defaultValue = QVariant());
/// @brief Loads a common setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
QVariant loadCommonSetting(AppConfig::Setting name,
const QVariant &defaultValue = QVariant()) const;
/// @brief Loads a common setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
QVariant loadCommonSetting(AppConfig::Setting name, const QVariant& defaultValue = QVariant()) const;
/// @brief As the settings will be accessible by multiple objects this lock
/// will ensure that
/// it cant be modified by more that one object at a time if the
/// setting is being switched from system to user.
std::mutex m_settings_lock;
/// @brief As the settings will be accessible by multiple objects this lock will ensure that
/// it cant be modified by more that one object at a time if the setting is being switched
/// from system to user.
std::mutex m_settings_lock;
/// @brief Sets the setting in the config checking if it has changed and
/// flagging that settings
/// needs to be saved if the setting was different
/// @param [in] variable the setting that will be changed
/// @param [in] newValue The new value of the setting
template <typename T> void setSettingModified(T &variable, const T &newValue);
/// @brief Sets the setting in the config checking if it has changed and flagging that settings
/// needs to be saved if the setting was different
/// @param [in] variable the setting that will be changed
/// @param [in] newValue The new value of the setting
template <typename T>
void setSettingModified(T& variable,const T& newValue);
/// @brief This method loads config from specified scope
/// @param [in] scope which should be loaded.
void loadScope(GUI::Config::ConfigWriter::Scope scope);
/// @brief This method loads config from specified scope
/// @param [in] scope which should be loaded.
void loadScope(GUI::Config::ConfigWriter::Scope scope);
/// @brief This function sets default values
/// for settings that shouldn't be copied from between scopes.
void setDefaultValues();
/// @brief This function sets default values
/// for settings that shouldn't be copied from between scopes.
void setDefaultValues();
signals:
void sslToggled() const;
void zeroConfToggled();
void screenNameChanged() const;
signals:
void sslToggled() const;
void zeroConfToggled();
void screenNameChanged() const;
};
#endif

View file

@ -7,9 +7,12 @@ extern "C" {
#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

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -18,29 +18,12 @@
#include "BaseConfig.h"
const char* BaseConfig::m_ModifierNames[] =
{
"shift",
"ctrl",
"alt",
"meta",
"super",
"none"
};
const char *BaseConfig::m_ModifierNames[] = {"shift", "ctrl", "alt",
"meta", "super", "none"};
const char* BaseConfig::m_FixNames[] =
{
"halfDuplexCapsLock",
"halfDuplexNumLock",
"halfDuplexScrollLock",
"xtestIsXineramaUnaware"
};
const char* BaseConfig::m_SwitchCornerNames[] =
{
"top-left",
"top-right",
"bottom-left",
"bottom-right"
};
const char *BaseConfig::m_FixNames[] = {
"halfDuplexCapsLock", "halfDuplexNumLock", "halfDuplexScrollLock",
"xtestIsXineramaUnaware"};
const char *BaseConfig::m_SwitchCornerNames[] = {"top-left", "top-right",
"bottom-left", "bottom-right"};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -24,68 +24,80 @@
#include <QString>
#include <QVariant>
class BaseConfig
{
public:
enum Modifier { DefaultMod = -1, Shift, Ctrl, Alt, Meta, Super, None, NumModifiers };
enum SwitchCorner { TopLeft, TopRight, BottomLeft, BottomRight, NumSwitchCorners };
enum Fix { CapsLock, NumLock, ScrollLock, XTest, NumFixes };
class BaseConfig {
public:
enum Modifier {
DefaultMod = -1,
Shift,
Ctrl,
Alt,
Meta,
Super,
None,
NumModifiers
};
enum SwitchCorner {
TopLeft,
TopRight,
BottomLeft,
BottomRight,
NumSwitchCorners
};
enum Fix { CapsLock, NumLock, ScrollLock, XTest, NumFixes };
protected:
BaseConfig() {}
virtual ~BaseConfig() {}
protected:
BaseConfig() {}
virtual ~BaseConfig() {}
protected:
template<typename T1, typename T2>
void readSettings(QSettings& settings, T1& array, const QString& arrayName, const T2& deflt)
{
int entries = settings.beginReadArray(arrayName + "Array");
array.clear();
for (int i = 0; i < entries; i++)
{
settings.setArrayIndex(i);
QVariant v = settings.value(arrayName, deflt);
array.append(v.value<T2>());
}
settings.endArray();
}
protected:
template <typename T1, typename T2>
void readSettings(QSettings &settings, T1 &array, const QString &arrayName,
const T2 &deflt) {
int entries = settings.beginReadArray(arrayName + "Array");
array.clear();
for (int i = 0; i < entries; i++) {
settings.setArrayIndex(i);
QVariant v = settings.value(arrayName, deflt);
array.append(v.value<T2>());
}
settings.endArray();
}
template<typename T1, typename T2>
void readSettings(QSettings& settings, T1& array, const QString& arrayName, const T2& deflt, int entries)
{
Q_ASSERT(array.size() >= entries);
settings.beginReadArray(arrayName + "Array");
for (int i = 0; i < entries; i++)
{
settings.setArrayIndex(i);
QVariant v = settings.value(arrayName, deflt);
array[i] = v.value<T2>();
}
settings.endArray();
}
template <typename T1, typename T2>
void readSettings(QSettings &settings, T1 &array, const QString &arrayName,
const T2 &deflt, int entries) {
Q_ASSERT(array.size() >= entries);
settings.beginReadArray(arrayName + "Array");
for (int i = 0; i < entries; i++) {
settings.setArrayIndex(i);
QVariant v = settings.value(arrayName, deflt);
array[i] = v.value<T2>();
}
settings.endArray();
}
template<typename T>
void writeSettings(QSettings& settings, const T& array, const QString& arrayName) const
{
settings.beginWriteArray(arrayName + "Array");
for (int i = 0; i < array.size(); i++)
{
settings.setArrayIndex(i);
settings.setValue(arrayName, array[i]);
}
settings.endArray();
}
template <typename T>
void writeSettings(QSettings &settings, const T &array,
const QString &arrayName) const {
settings.beginWriteArray(arrayName + "Array");
for (int i = 0; i < array.size(); i++) {
settings.setArrayIndex(i);
settings.setValue(arrayName, array[i]);
}
settings.endArray();
}
public:
static const char *modifierName(int idx) { return m_ModifierNames[idx]; }
static const char *fixName(int idx) { return m_FixNames[idx]; }
static const char *switchCornerName(int idx) {
return m_SwitchCornerNames[idx];
}
public:
static const char* modifierName(int idx) { return m_ModifierNames[idx]; }
static const char* fixName(int idx) { return m_FixNames[idx]; }
static const char* switchCornerName(int idx) { return m_SwitchCornerNames[idx]; }
private:
static const char* m_ModifierNames[];
static const char* m_FixNames[];
static const char* m_SwitchCornerNames[];
private:
static const char *m_ModifierNames[];
static const char *m_FixNames[];
static const char *m_SwitchCornerNames[];
};
#endif

View file

@ -19,185 +19,172 @@
#if defined(Q_OS_WIN)
#include "MainWindow.h"
#include "SettingsDialog.h"
#include "DataDownloader.h"
#include "QUtility.h"
#include "CommandProcess.h"
#include "DataDownloader.h"
#include "MainWindow.h"
#include "QUtility.h"
#include "SettingsDialog.h"
#include <QUrl>
#include <QThread>
#include <QDir>
#include <QStandardPaths>
#include <QMessageBox>
#include <QStandardPaths>
#include <QThread>
#include <QUrl>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
BonjourWindows::BonjourWindows(
SettingsDialog* settingsDialog,
MainWindow* mainWindow,
AppConfig& appConfig) :
m_pSettingsDialog(settingsDialog),
m_pMainWindow(mainWindow),
m_pBonjourInstall(nullptr),
m_pDownloadMessageBox(nullptr),
m_pDataDownloader(nullptr),
m_appConfig(appConfig)
{
BonjourWindows::BonjourWindows(SettingsDialog *settingsDialog,
MainWindow *mainWindow, AppConfig &appConfig)
: m_pSettingsDialog(settingsDialog), m_pMainWindow(mainWindow),
m_pBonjourInstall(nullptr), m_pDownloadMessageBox(nullptr),
m_pDataDownloader(nullptr), m_appConfig(appConfig) {}
BonjourWindows::~BonjourWindows() {
if (m_pBonjourInstall != nullptr) {
delete m_pBonjourInstall;
}
if (m_pDownloadMessageBox != nullptr) {
delete m_pDownloadMessageBox;
}
if (m_pDataDownloader != nullptr) {
delete m_pDataDownloader;
}
}
BonjourWindows::~BonjourWindows()
{
if (m_pBonjourInstall != nullptr) {
delete m_pBonjourInstall;
}
void BonjourWindows::downloadAndInstall() {
QUrl url;
int arch = getProcessorArch();
if (arch == kProcessorArchWin32) {
url.setUrl(bonjourBaseUrl + bonjourFilename32);
m_pMainWindow->appendLogInfo("downloading bonjour (32-bit)");
} else if (arch == kProcessorArchWin64) {
url.setUrl(bonjourBaseUrl + bonjourFilename64);
m_pMainWindow->appendLogInfo("downloading bonjour (64-bit)");
} else {
QMessageBox::critical(m_pSettingsDialog, tr("Synergy Auto Config"),
tr("Failed to detect system architecture."));
return;
}
if (m_pDownloadMessageBox != nullptr) {
delete m_pDownloadMessageBox;
}
if (m_pDataDownloader == nullptr) {
m_pDataDownloader = new DataDownloader(this);
connect(m_pDataDownloader, SIGNAL(isComplete()), SLOT(downloadFinished()));
}
if (m_pDataDownloader != nullptr) {
delete m_pDataDownloader;
}
m_pDataDownloader->download(url);
if (m_pDownloadMessageBox != nullptr) {
delete m_pDownloadMessageBox;
m_pDownloadMessageBox = nullptr;
}
m_pDownloadMessageBox = new QMessageBox(m_pSettingsDialog);
m_pDownloadMessageBox->setWindowTitle("Synergy Auto Config");
m_pDownloadMessageBox->setIcon(QMessageBox::Information);
m_pDownloadMessageBox->setText("Installing Bonjour, please wait...");
QAbstractButton *cancel =
m_pDownloadMessageBox->addButton(tr("Cancel"), QMessageBox::RejectRole);
m_pDownloadMessageBox->exec();
if (cancel == m_pDownloadMessageBox->clickedButton()) {
m_pDataDownloader->cancel();
}
}
void BonjourWindows::downloadAndInstall()
{
QUrl url;
int arch = getProcessorArch();
if (arch == kProcessorArchWin32) {
url.setUrl(bonjourBaseUrl + bonjourFilename32);
m_pMainWindow->appendLogInfo("downloading bonjour (32-bit)");
}
else if (arch == kProcessorArchWin64) {
url.setUrl(bonjourBaseUrl + bonjourFilename64);
m_pMainWindow->appendLogInfo("downloading bonjour (64-bit)");
}
else {
QMessageBox::critical(
m_pSettingsDialog, tr("Synergy Auto Config"),
tr("Failed to detect system architecture."));
return;
}
if (m_pDataDownloader == nullptr) {
m_pDataDownloader = new DataDownloader(this);
connect(m_pDataDownloader, SIGNAL(isComplete()), SLOT(downloadFinished()));
}
m_pDataDownloader->download(url);
if (m_pDownloadMessageBox != nullptr) {
delete m_pDownloadMessageBox;
m_pDownloadMessageBox = nullptr;
}
m_pDownloadMessageBox = new QMessageBox(m_pSettingsDialog);
m_pDownloadMessageBox->setWindowTitle("Synergy Auto Config");
m_pDownloadMessageBox->setIcon(QMessageBox::Information);
m_pDownloadMessageBox->setText("Installing Bonjour, please wait...");
QAbstractButton* cancel = m_pDownloadMessageBox->addButton(
tr("Cancel"), QMessageBox::RejectRole);
m_pDownloadMessageBox->exec();
if (cancel == m_pDownloadMessageBox->clickedButton()) {
m_pDataDownloader->cancel();
}
void BonjourWindows::downloadFinished() {
m_pMainWindow->appendLogInfo("bonjour downloaded");
install();
}
void BonjourWindows::downloadFinished()
{
m_pMainWindow->appendLogInfo("bonjour downloaded");
install();
}
void BonjourWindows::install() {
m_pMainWindow->appendLogInfo("installing bonjour");
void BonjourWindows::install()
{
m_pMainWindow->appendLogInfo("installing bonjour");
QString tempLocation = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
QString filename = tempLocation;
filename.append("\\").append(bonjourTargetFilename);
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
m_pDownloadMessageBox->hide();
QMessageBox::warning(
m_pSettingsDialog, "Synergy",
tr("Failed to download Bonjour installer to location: %1")
.arg(tempLocation));
return;
}
file.write(m_pDataDownloader->data());
file.close();
QStringList arguments;
arguments.append("/i");
QString winFilename = QDir::toNativeSeparators(filename);
arguments.append(winFilename);
arguments.append("/passive");
if (m_pBonjourInstall != nullptr) {
delete m_pBonjourInstall;
m_pBonjourInstall = nullptr;
}
m_pBonjourInstall = new CommandProcess("msiexec", arguments);
QThread* thread = new QThread;
connect(m_pBonjourInstall, SIGNAL(finished()), this, SLOT(installFinished()));
connect(m_pBonjourInstall, SIGNAL(finished()), thread, SLOT(quit()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
m_pBonjourInstall->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(m_pBonjourInstall, "run", Qt::QueuedConnection);
QString tempLocation =
QStandardPaths::writableLocation(QStandardPaths::TempLocation);
QString filename = tempLocation;
filename.append("\\").append(bonjourTargetFilename);
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
m_pDownloadMessageBox->hide();
QMessageBox::warning(
m_pSettingsDialog, "Synergy",
tr("Failed to download Bonjour installer to location: %1")
.arg(tempLocation));
return;
}
file.write(m_pDataDownloader->data());
file.close();
QStringList arguments;
arguments.append("/i");
QString winFilename = QDir::toNativeSeparators(filename);
arguments.append(winFilename);
arguments.append("/passive");
if (m_pBonjourInstall != nullptr) {
delete m_pBonjourInstall;
m_pBonjourInstall = nullptr;
}
m_pBonjourInstall = new CommandProcess("msiexec", arguments);
QThread *thread = new QThread;
connect(m_pBonjourInstall, SIGNAL(finished()), this, SLOT(installFinished()));
connect(m_pBonjourInstall, SIGNAL(finished()), thread, SLOT(quit()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
m_pBonjourInstall->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(m_pBonjourInstall, "run", Qt::QueuedConnection);
m_pDownloadMessageBox->hide();
}
bool BonjourWindows::isRunning() const
{
QString name = "Bonjour Service";
bool BonjourWindows::isRunning() const {
QString name = "Bonjour Service";
SC_HANDLE hSCManager;
hSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
if (hSCManager == nullptr) {
m_pMainWindow->appendLogError(
QString("failed to open a service controller manager, error: %1").arg(GetLastError()));
return false;
}
auto array = name.toLocal8Bit();
SC_HANDLE hService = OpenService(hSCManager, array.data(), SERVICE_QUERY_STATUS);
if (hService == nullptr) {
m_pMainWindow->appendLogDebug(
QString("failed to open service: %1").arg(name));
return false;
}
SERVICE_STATUS status;
if (QueryServiceStatus(hService, &status)) {
if (status.dwCurrentState == SERVICE_RUNNING) {
return true;
}
}
SC_HANDLE hSCManager;
hSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
if (hSCManager == nullptr) {
m_pMainWindow->appendLogError(
QString("failed to open a service controller manager, error: %1")
.arg(GetLastError()));
return false;
}
auto array = name.toLocal8Bit();
SC_HANDLE hService =
OpenService(hSCManager, array.data(), SERVICE_QUERY_STATUS);
if (hService == nullptr) {
m_pMainWindow->appendLogDebug(
QString("failed to open service: %1").arg(name));
return false;
}
SERVICE_STATUS status;
if (QueryServiceStatus(hService, &status)) {
if (status.dwCurrentState == SERVICE_RUNNING) {
return true;
}
}
return false;
}
void BonjourWindows::installFinished()
{
m_pMainWindow->appendLogInfo("bonjour installed");
m_appConfig.setAutoConfig(true);
m_pSettingsDialog->allowAutoConfig();
void BonjourWindows::installFinished() {
m_pMainWindow->appendLogInfo("bonjour installed");
m_appConfig.setAutoConfig(true);
m_pSettingsDialog->allowAutoConfig();
}
#endif // Q_OS_WIN

View file

@ -34,32 +34,32 @@ class CommandProcess;
class DataDownloader;
class AppConfig;
class BonjourWindows : public QObject
{
Q_OBJECT
class BonjourWindows : public QObject {
Q_OBJECT
public:
BonjourWindows(SettingsDialog* settingsDialog, MainWindow* mainWindow, AppConfig& appConfig);
virtual ~BonjourWindows();
BonjourWindows(SettingsDialog *settingsDialog, MainWindow *mainWindow,
AppConfig &appConfig);
virtual ~BonjourWindows();
public:
void downloadAndInstall();
bool isRunning() const;
void downloadAndInstall();
bool isRunning() const;
protected slots:
void downloadFinished();
void installFinished();
void downloadFinished();
void installFinished();
private:
void install();
void install();
private:
SettingsDialog* m_pSettingsDialog;
MainWindow* m_pMainWindow;
CommandProcess* m_pBonjourInstall;
QMessageBox* m_pDownloadMessageBox;
DataDownloader* m_pDataDownloader;
AppConfig& m_appConfig;
SettingsDialog *m_pSettingsDialog;
MainWindow *m_pMainWindow;
CommandProcess *m_pBonjourInstall;
QMessageBox *m_pDownloadMessageBox;
DataDownloader *m_pDataDownloader;
AppConfig &m_appConfig;
};
#endif // Q_OS_WIN

View file

@ -1,14 +1,9 @@
#include "CancelActivationDialog.h"
#include "ui_CancelActivationDialog.h"
CancelActivationDialog::CancelActivationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CancelActivationDialog)
{
ui->setupUi(this);
CancelActivationDialog::CancelActivationDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::CancelActivationDialog) {
ui->setupUi(this);
}
CancelActivationDialog::~CancelActivationDialog()
{
delete ui;
}
CancelActivationDialog::~CancelActivationDialog() { delete ui; }

View file

@ -7,16 +7,15 @@ namespace Ui {
class CancelActivationDialog;
}
class CancelActivationDialog : public QDialog
{
Q_OBJECT
class CancelActivationDialog : public QDialog {
Q_OBJECT
public:
explicit CancelActivationDialog(QWidget *parent = 0);
~CancelActivationDialog();
explicit CancelActivationDialog(QWidget *parent = 0);
~CancelActivationDialog();
private:
Ui::CancelActivationDialog *ui;
Ui::CancelActivationDialog *ui;
};
#endif // CANCELACTIVATIONDIALOG_H

View file

@ -20,78 +20,65 @@
#include "MainWindow.h"
#include <QMessageBox>
#include <QHostAddress>
#include <QMessageBox>
ClientConnection::ClientConnection(MainWindow& parent) :
m_parent(parent)
{
}
ClientConnection::ClientConnection(MainWindow &parent) : m_parent(parent) {}
void ClientConnection::update(const QString& line)
{
if (m_checkConnection && checkMainWindow())
{
if (line.contains("failed to connect to server"))
{
m_checkConnection = false;
if (!line.contains("server refused client with our name") &&
!line.contains("Trying next address"))
{
showMessage(getMessage(line));
}
}
else if (line.contains("connected to server"))
{
m_checkConnection = false;
}
void ClientConnection::update(const QString &line) {
if (m_checkConnection && checkMainWindow()) {
if (line.contains("failed to connect to server")) {
m_checkConnection = false;
if (!line.contains("server refused client with our name") &&
!line.contains("Trying next address")) {
showMessage(getMessage(line));
}
} else if (line.contains("connected to server")) {
m_checkConnection = false;
}
}
}
bool ClientConnection::checkMainWindow()
{
bool result = m_parent.isActiveWindow();
bool ClientConnection::checkMainWindow() {
bool result = m_parent.isActiveWindow();
if (m_parent.isMinimized() || m_parent.isHidden())
{
m_parent.showNormal();
m_parent.activateWindow();
result = true;
if (m_parent.isMinimized() || m_parent.isHidden()) {
m_parent.showNormal();
m_parent.activateWindow();
result = true;
}
return result;
}
QString ClientConnection::getMessage(const QString &line) const {
QString message(QObject::tr("Connection failed.\nCheck the IP address on the "
"server, your TLS and firewall settings."));
if (line.contains("server already has a connected client with our name")) {
message =
QObject::tr("Connection failed.\nYou can’t name 2 computers the same.");
} else {
QHostAddress address(m_parent.appConfig().getServerHostname());
if (address.isNull()) {
message =
QObject::tr(
"We can’t connect to the server \"%1\" try to connect using the "
"server IP address and check your firewall settings.")
.arg(m_parent.appConfig().getServerHostname());
}
}
return result;
return message;
}
QString ClientConnection::getMessage(const QString& line) const
{
QString message(QObject::tr("Connection failed.\nCheck the IP address on the server, your TLS and firewall settings."));
if (line.contains("server already has a connected client with our name"))
{
message = QObject::tr("Connection failed.\nYou can’t name 2 computers the same.");
}
else
{
QHostAddress address(m_parent.appConfig().getServerHostname());
if (address.isNull())
{
message = QObject::tr("We can’t connect to the server \"%1\" try to connect using the server IP address and check your firewall settings.")
.arg(m_parent.appConfig().getServerHostname());
}
}
return message;
void ClientConnection::showMessage(const QString &message) const {
QMessageBox dialog(&m_parent);
dialog.addButton(QObject::tr("Close"), QMessageBox::RejectRole);
dialog.setText(message);
dialog.exec();
}
void ClientConnection::showMessage(const QString& message) const
{
QMessageBox dialog(&m_parent);
dialog.addButton(QObject::tr("Close"), QMessageBox::RejectRole);
dialog.setText(message);
dialog.exec();
}
void ClientConnection::setCheckConnection(bool checkConnection)
{
m_checkConnection = checkConnection;
void ClientConnection::setCheckConnection(bool checkConnection) {
m_checkConnection = checkConnection;
}

View file

@ -23,20 +23,19 @@
class MainWindow;
class ClientConnection
{
MainWindow& m_parent;
bool m_checkConnection = false;
class ClientConnection {
MainWindow &m_parent;
bool m_checkConnection = false;
public:
explicit ClientConnection(MainWindow& parent);
void update(const QString& line);
void setCheckConnection(bool checkConnection);
explicit ClientConnection(MainWindow &parent);
void update(const QString &line);
void setCheckConnection(bool checkConnection);
private:
QString getMessage(const QString& line) const;
bool checkMainWindow();
void showMessage(const QString& message) const;
QString getMessage(const QString &line) const;
bool checkMainWindow();
void showMessage(const QString &message) const;
};
#endif // CLIENTCONNECTION_H

View file

@ -20,44 +20,38 @@
#include <QProcess>
#include <stdexcept>
CommandProcess::CommandProcess(QString cmd, QStringList arguments, QString input) :
m_Command(cmd),
m_Arguments(arguments),
m_Input(input)
{
}
CommandProcess::CommandProcess(QString cmd, QStringList arguments,
QString input)
: m_Command(cmd), m_Arguments(arguments), m_Input(input) {}
QString CommandProcess::run()
{
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
process.start(m_Command, m_Arguments);
bool success = process.waitForStarted();
QString CommandProcess::run() {
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
process.start(m_Command, m_Arguments);
bool success = process.waitForStarted();
QString output, error;
if (success)
{
if (!m_Input.isEmpty()) {
process.write(m_Input.toStdString().c_str());
}
if (process.waitForFinished()) {
output = QString::fromLocal8Bit(process.readAllStandardOutput().trimmed());
error = process.readAllStandardError().trimmed();
}
QString output, error;
if (success) {
if (!m_Input.isEmpty()) {
process.write(m_Input.toStdString().c_str());
}
int code = process.exitCode();
if (!error.isEmpty() || !success || code != 0)
{
throw std::runtime_error(
QString("Code: %1\nError: %2")
.arg(process.exitCode())
.arg(error.isEmpty() ? "Unknown" : error)
.toStdString());
if (process.waitForFinished()) {
output =
QString::fromLocal8Bit(process.readAllStandardOutput().trimmed());
error = process.readAllStandardError().trimmed();
}
}
emit finished();
int code = process.exitCode();
if (!error.isEmpty() || !success || code != 0) {
throw std::runtime_error(QString("Code: %1\nError: %2")
.arg(process.exitCode())
.arg(error.isEmpty() ? "Unknown" : error)
.toStdString());
}
return output;
emit finished();
return output;
}

View file

@ -21,23 +21,22 @@
#include <QObject>
#include <QStringList>
class CommandProcess : public QObject
{
Q_OBJECT
class CommandProcess : public QObject {
Q_OBJECT
public:
CommandProcess(QString cmd, QStringList arguments, QString input = "");
CommandProcess(QString cmd, QStringList arguments, QString input = "");
signals:
void finished();
void finished();
public slots:
QString run();
QString run();
private:
QString m_Command;
QStringList m_Arguments;
QString m_Input;
QString m_Command;
QStringList m_Arguments;
QString m_Input;
};
#endif // COMMANDTHREAD_H

View file

@ -19,30 +19,33 @@
#define SYNERGY_CORE_CONFIGBASE_H
namespace GUI {
namespace Config {
namespace Config {
///@brief This abstract class will be used by all classes that use the ConfigWriter
/// to allow global saving and loading
class ConfigBase {
public :
ConfigBase() = default;
///@brief This abstract class will be used by all classes that use the
/// ConfigWriter
/// to allow global saving and loading
class ConfigBase {
public:
ConfigBase() = default;
virtual ~ConfigBase() = default;
virtual ~ConfigBase() = default;
/// @brief The function that is called when the settings need to be loaded from file
virtual void loadSettings() = 0;
/// @brief The function that is called when the settings need to be loaded
/// from file
virtual void loadSettings() = 0;
/// @brief The function that is called when the settings need to be saved to file
virtual void saveSettings() = 0;
/// @brief The function that is called when the settings need to be saved to
/// file
virtual void saveSettings() = 0;
/// @brief Returns true if the class has marked itself with having unsaved changes
bool modified() const { return m_unsavedChanges; }
/// @brief Returns true if the class has marked itself with having unsaved
/// changes
bool modified() const { return m_unsavedChanges; }
protected:
/// @brief Does the class have unsaved changes in it.
bool m_unsavedChanges = false;
};
}
}
#endif //SYNERGY_CORE_CONFIGBASE_H
protected:
/// @brief Does the class have unsaved changes in it.
bool m_unsavedChanges = false;
};
} // namespace Config
} // namespace GUI
#endif // SYNERGY_CORE_CONFIGBASE_H

View file

@ -20,207 +20,193 @@
#include <QCoreApplication>
#include <QFile>
#include "ConfigWriter.h"
#include "ConfigBase.h"
#include "ConfigWriter.h"
namespace {
QString getSystemSettingPath()
{
const QString settingFilename("SystemConfig.ini");
QString path;
QString getSystemSettingPath() {
const QString settingFilename("SystemConfig.ini");
QString path;
#if defined(Q_OS_WIN)
// Program file
path = QCoreApplication::applicationDirPath() + "\\";
// Program file
path = QCoreApplication::applicationDirPath() + "\\";
#elif defined(Q_OS_DARWIN)
//Global preferances dir
// Would be nice to use /library, but QT has no elevate system in place
path = "/usr/local/etc/symless/";
// Global preferances dir
// Would be nice to use /library, but QT has no elevate system in place
path = "/usr/local/etc/symless/";
#elif defined(Q_OS_LINUX)
// QT adds application and filename to the end of the path already on linux
path = "/usr/local/etc/symless/";
return path;
// QT adds application and filename to the end of the path already on linux
path = "/usr/local/etc/symless/";
return path;
#else
assert("OS not supported");
assert("OS not supported");
#endif
return path + settingFilename;
return path + settingFilename;
}
#if defined(Q_OS_WIN)
void loadOldSystemSettings(QSettings& settings)
{
if (!QFile(settings.fileName()).exists()) {
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "SystemConfig.ini");
QSettings oldSystemSettings (QSettings::IniFormat,
QSettings::SystemScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
void loadOldSystemSettings(QSettings &settings) {
if (!QFile(settings.fileName()).exists()) {
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
"SystemConfig.ini");
QSettings oldSystemSettings(QSettings::IniFormat, QSettings::SystemScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
if (QFile(oldSystemSettings.fileName()).exists()) {
for (const auto& key : oldSystemSettings.allKeys()) {
settings.setValue(key, oldSystemSettings.value(key));
}
}
//Restore system settings path
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, getSystemSettingPath());
if (QFile(oldSystemSettings.fileName()).exists()) {
for (const auto &key : oldSystemSettings.allKeys()) {
settings.setValue(key, oldSystemSettings.value(key));
}
}
// Restore system settings path
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
getSystemSettingPath());
}
}
#endif
}
} // namespace
namespace GUI {
namespace Config {
//Assignment of static variable
ConfigWriter *ConfigWriter::s_pConfiguration = nullptr;
namespace Config {
// Assignment of static variable
ConfigWriter *ConfigWriter::s_pConfiguration = nullptr;
ConfigWriter *ConfigWriter::make() {
// Only one ConfigWriter can exist at any one time (Singleton)
if (!s_pConfiguration) {
s_pConfiguration = new ConfigWriter();
}
return s_pConfiguration;
}
ConfigWriter::ConfigWriter() {
QSettings::setPath(QSettings::Format::IniFormat,
QSettings::Scope::SystemScope,
getSystemSettingPath());
//Config will default to User settings if they exist,
// otherwise it will load System setting and save them to User settings
m_pSettingsSystem = new QSettings(QSettings::Format::IniFormat,
QSettings::Scope::SystemScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
#if defined(Q_OS_WIN)
//This call is needed for backwardcapability with old settings.
loadOldSystemSettings(*m_pSettingsSystem);
#endif
//defaults to user scope, if we set the scope specifically then we also have to set
// the application name and the organisation name which breaks backwards compatibility
// See #6730
m_pSettingsUser = new QSettings();
//Set scope to user for initially
m_pSettingsCurrent = m_pSettingsUser;
}
void ConfigWriter::destroy() {
destroy(s_pConfiguration);
}
ConfigWriter::~ConfigWriter() {
while(!m_pCallerList.empty()) {
m_pCallerList.pop_back();
}
m_pSettingsCurrent = nullptr; //this only references other pointers
destroy(m_pSettingsSystem);
destroy(m_pSettingsUser);
}
bool ConfigWriter::hasSetting(const QString &name, Scope scope) const {
switch (scope){
case kUser:
return m_pSettingsUser->contains(name);
case kSystem:
return m_pSettingsSystem->contains(name);
default:
return m_pSettingsCurrent->contains(name);
}
}
bool ConfigWriter::isWritable() const {
return m_pSettingsCurrent->isWritable();
}
QVariant ConfigWriter::loadSetting(const QString& name, const QVariant &defaultValue, Scope scope) {
switch (scope){
case kUser:
return m_pSettingsUser->value(name, defaultValue);
case kSystem:
return m_pSettingsSystem->value(name, defaultValue);
default:
return m_pSettingsCurrent->value(name, defaultValue);
}
}
void ConfigWriter::setScope(ConfigWriter::Scope scope) {
if (m_CurrentScope != scope) {
m_CurrentScope = scope;
switch (scope) {
case kUser:
m_pSettingsCurrent = m_pSettingsUser;
break;
case kSystem:
m_pSettingsCurrent = m_pSettingsSystem;
break;
default:
//setScope should never be kCurrent
assert(scope);
}
}
}
ConfigWriter::Scope ConfigWriter::getScope() const {
return m_CurrentScope;
}
void ConfigWriter::globalLoad() {
for (auto &i : m_pCallerList) {
i->loadSettings();
}
}
void ConfigWriter::globalSave() {
//Save if there are any unsaved changes otherwise skip
if (unsavedChanges()) {
for (auto &i : m_pCallerList) {
i->saveSettings();
}
m_pSettingsUser->sync();
m_pSettingsSystem->sync();
m_unsavedChanges = false;
}
}
QSettings &ConfigWriter::settings() {
return *m_pSettingsCurrent;
}
void ConfigWriter::registerClass(ConfigBase * receiver) {
m_pCallerList.push_back(receiver);
}
bool ConfigWriter::unsavedChanges() const {
if (m_unsavedChanges) {
return true;
}
for (const auto &i : m_pCallerList) {
if (i->modified()){
//If any class returns true there is no point checking more
return true;
}
}
// If this line is reached no class has unsaved changes
return false;
}
void ConfigWriter::markUnsaved() {
m_unsavedChanges = true;
}
}
ConfigWriter *ConfigWriter::make() {
// Only one ConfigWriter can exist at any one time (Singleton)
if (!s_pConfiguration) {
s_pConfiguration = new ConfigWriter();
}
return s_pConfiguration;
}
ConfigWriter::ConfigWriter() {
QSettings::setPath(QSettings::Format::IniFormat,
QSettings::Scope::SystemScope, getSystemSettingPath());
// Config will default to User settings if they exist,
// otherwise it will load System setting and save them to User settings
m_pSettingsSystem =
new QSettings(QSettings::Format::IniFormat, QSettings::Scope::SystemScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
#if defined(Q_OS_WIN)
// This call is needed for backwardcapability with old settings.
loadOldSystemSettings(*m_pSettingsSystem);
#endif
// defaults to user scope, if we set the scope specifically then we also have
// to set
// the application name and the organisation name which breaks backwards
// compatibility See #6730
m_pSettingsUser = new QSettings();
// Set scope to user for initially
m_pSettingsCurrent = m_pSettingsUser;
}
void ConfigWriter::destroy() { destroy(s_pConfiguration); }
ConfigWriter::~ConfigWriter() {
while (!m_pCallerList.empty()) {
m_pCallerList.pop_back();
}
m_pSettingsCurrent = nullptr; // this only references other pointers
destroy(m_pSettingsSystem);
destroy(m_pSettingsUser);
}
bool ConfigWriter::hasSetting(const QString &name, Scope scope) const {
switch (scope) {
case kUser:
return m_pSettingsUser->contains(name);
case kSystem:
return m_pSettingsSystem->contains(name);
default:
return m_pSettingsCurrent->contains(name);
}
}
bool ConfigWriter::isWritable() const {
return m_pSettingsCurrent->isWritable();
}
QVariant ConfigWriter::loadSetting(const QString &name,
const QVariant &defaultValue, Scope scope) {
switch (scope) {
case kUser:
return m_pSettingsUser->value(name, defaultValue);
case kSystem:
return m_pSettingsSystem->value(name, defaultValue);
default:
return m_pSettingsCurrent->value(name, defaultValue);
}
}
void ConfigWriter::setScope(ConfigWriter::Scope scope) {
if (m_CurrentScope != scope) {
m_CurrentScope = scope;
switch (scope) {
case kUser:
m_pSettingsCurrent = m_pSettingsUser;
break;
case kSystem:
m_pSettingsCurrent = m_pSettingsSystem;
break;
default:
// setScope should never be kCurrent
assert(scope);
}
}
}
ConfigWriter::Scope ConfigWriter::getScope() const { return m_CurrentScope; }
void ConfigWriter::globalLoad() {
for (auto &i : m_pCallerList) {
i->loadSettings();
}
}
void ConfigWriter::globalSave() {
// Save if there are any unsaved changes otherwise skip
if (unsavedChanges()) {
for (auto &i : m_pCallerList) {
i->saveSettings();
}
m_pSettingsUser->sync();
m_pSettingsSystem->sync();
m_unsavedChanges = false;
}
}
QSettings &ConfigWriter::settings() { return *m_pSettingsCurrent; }
void ConfigWriter::registerClass(ConfigBase *receiver) {
m_pCallerList.push_back(receiver);
}
bool ConfigWriter::unsavedChanges() const {
if (m_unsavedChanges) {
return true;
}
for (const auto &i : m_pCallerList) {
if (i->modified()) {
// If any class returns true there is no point checking more
return true;
}
}
// If this line is reached no class has unsaved changes
return false;
}
void ConfigWriter::markUnsaved() { m_unsavedChanges = true; }
} // namespace Config
} // namespace GUI

View file

@ -17,133 +17,141 @@
#ifndef SYNERGY_CORE_CONFIGWRITER_H
#define SYNERGY_CORE_CONFIGWRITER_H
#include <QVariant>
#include <QSettings>
#include <QVariant>
/// @brief Contains GUI code
namespace GUI {
/// @brief Contains Configuration code
namespace Config {
/// @brief Contains Configuration code
namespace Config {
//Forward declare the class referenced by pointer
class ConfigBase;
// Forward declare the class referenced by pointer
class ConfigBase;
class ConfigWriter: private QObject {
class ConfigWriter : private QObject {
public:
public:
/// @brief the public way to construct the configuration calls
/// The pointer returned is owned by this class and should not be
/// stored by other classes.
static ConfigWriter *make();
/// @brief the public way to construct the configuration calls
/// The pointer returned is owned by this class and should not be stored
/// by other classes.
static ConfigWriter* make();
/// @brief the public way to destroy the configuration class
static void destroy();
/// @brief the public way to destroy the configuration class
static void destroy();
~ConfigWriter() override;
~ConfigWriter() override;
///@brief An Enumeration of all the scopes available
enum Scope { kCurrent, kSystem, kUser };
///@brief An Enumeration of all the scopes available
enum Scope { kCurrent, kSystem, kUser};
/// @brief Checks if the setting exists
/// @param [in] name The name of the setting to check
/// @param [in] scope The scope to search in
/// @return bool True if the current scope has the named setting
bool hasSetting(const QString &name, Scope scope = kCurrent) const;
/// @brief Checks if the setting exists
/// @param [in] name The name of the setting to check
/// @param [in] scope The scope to search in
/// @return bool True if the current scope has the named setting
bool hasSetting(const QString& name, Scope scope = kCurrent) const;
/// @brief Checks if the current scope settings writable
/// @return bool True if the current scope writable
bool isWritable() const;
/// @brief Checks if the current scope settings writable
/// @return bool True if the current scope writable
bool isWritable() const;
/// @brief Sets the value of a setting
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved (Templated)
/// @param [in] scope The scope to get the value from, default is current
/// scope
template <typename T>
void setSetting(const QString &name, T value, Scope scope = kCurrent);
/// @brief Sets the value of a setting
/// @param [in] name The Setting to be saved
/// @param [in] value The Value to be saved (Templated)
/// @param [in] scope The scope to get the value from, default is current scope
template <typename T>
void setSetting(const QString& name, T value, Scope scope = kCurrent);
/// @brief Loads a setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
/// @param [in] scope The scope to get the value from, default is current
/// scope
QVariant loadSetting(const QString &name,
const QVariant &defaultValue = QVariant(),
Scope scope = kCurrent);
/// @brief Loads a setting
/// @param [in] name The setting to be loaded
/// @param [in] defaultValue The default value of the setting
/// @param [in] scope The scope to get the value from, default is current scope
QVariant loadSetting(const QString& name, const QVariant& defaultValue = QVariant(), Scope scope = kCurrent);
/// @brief Changes the setting save and load location between System and User
/// scope
/// @param [in] scope The scope to set
void setScope(Scope scope = kUser);
/// @brief Changes the setting save and load location between System and User scope
/// @param [in] scope The scope to set
void setScope(Scope scope = kUser);
/// @brief Get the current scope the settings are loading and save from.
/// @return Scope An enum defining the current scope
Scope getScope() const;
/// @brief Get the current scope the settings are loading and save from.
/// @return Scope An enum defining the current scope
Scope getScope() const;
/// @brief trigger a config load across all registered classes
void globalLoad();
/// @brief trigger a config load across all registered classes
void globalLoad();
/// @brief trigger a config save across all registered classes
void globalSave();
/// @brief trigger a config save across all registered classes
void globalSave();
/// @brief Returns the current scopes settings object
/// If more specialize control into the settings is needed this can
/// provide direct access to the settings file handler
/// @return QSettings The Settings object as a reference
QSettings &settings();
/// @brief Returns the current scopes settings object
/// If more specialize control into the settings is needed this can provide
/// direct access to the settings file handler
/// @return QSettings The Settings object as a reference
QSettings& settings();
/// @brief This marks the settings as unsaved if the settings() was used to
/// directly affect the config file
void markUnsaved();
/// @brief This marks the settings as unsaved if the settings() was used to directly affect the config file
void markUnsaved();
/// @brief Register a class to receives globalLoad and globalSave events
/// @param [in] ConfigBase The class that will receive the events
void registerClass(ConfigBase *receiver);
/// @brief Register a class to receives globalLoad and globalSave events
/// @param [in] ConfigBase The class that will receive the events
void registerClass(ConfigBase* receiver);
/// @brief Checks if any registered class has any unsaved changes
/// @return bool True if any registered class has unsaved changes
bool unsavedChanges() const;
/// @brief Checks if any registered class has any unsaved changes
/// @return bool True if any registered class has unsaved changes
bool unsavedChanges() const;
protected:
Scope m_CurrentScope = kUser; /// @brief The current scope of the settings
protected:
QSettings *m_pSettingsCurrent =
nullptr; /// @brief The currently active settings
QSettings *m_pSettingsUser = nullptr; /// @brief The user specific settings
QSettings *m_pSettingsSystem = nullptr; /// @brief The system wide settings
Scope m_CurrentScope = kUser; /// @brief The current scope of the settings
private:
/// @brief Contains a list all all classes that hook into the writer.
/// This allows all classes that save settings to be called an updated
/// on a save and reload by any other class
std::list<ConfigBase *> m_pCallerList;
QSettings* m_pSettingsCurrent = nullptr; /// @brief The currently active settings
QSettings* m_pSettingsUser = nullptr; /// @brief The user specific settings
QSettings* m_pSettingsSystem = nullptr; /// @brief The system wide settings
/// @brief if this class modified settings then set the flag
bool m_unsavedChanges = false;
private:
/// @brief The constructor, as this is a singolton we want to control who can
/// call the constructor
ConfigWriter();
/// @brief Contains a list all all classes that hook into the writer.
/// This allows all classes that save settings to be called an updated
/// on a save and reload by any other class
std::list<ConfigBase*> m_pCallerList;
/// @brief the pointer of the ConfigWriter for singolton use
static ConfigWriter *s_pConfiguration;
/// @brief if this class modified settings then set the flag
bool m_unsavedChanges = false;
/// @brief deletes pointers and sets the value to null
template <class T> static inline void destroy(T *&p) {
delete p;
p = 0;
}
};
/// @brief The constructor, as this is a singolton we want to control who can call the constructor
ConfigWriter();
/// @brief the pointer of the ConfigWriter for singolton use
static ConfigWriter* s_pConfiguration;
/// @brief deletes pointers and sets the value to null
template<class T> static inline void destroy(T*& p) { delete p; p = 0; }
};
// Implementation of a template function needs to be visible to all calls thus is must be in the header
// Moved so its not bulking out the class definition
template<typename T>
void ConfigWriter::setSetting(const QString& name, T value, Scope scope) {
switch (scope){
case kUser:
m_pSettingsUser->setValue(name, value);
break;
case kSystem:
m_pSettingsSystem->setValue(name, value);
break;
default:
m_pSettingsCurrent->setValue(name, value);
break;
}
m_unsavedChanges = true;
}
}
// Implementation of a template function needs to be visible to all calls thus
// is must be in the header Moved so its not bulking out the class definition
template <typename T>
void ConfigWriter::setSetting(const QString &name, T value, Scope scope) {
switch (scope) {
case kUser:
m_pSettingsUser->setValue(name, value);
break;
case kSystem:
m_pSettingsSystem->setValue(name, value);
break;
default:
m_pSettingsCurrent->setValue(name, value);
break;
}
m_unsavedChanges = true;
}
#endif //SYNERGY_CORE_CONFIGWRITER_H
} // namespace Config
} // namespace GUI
#endif // SYNERGY_CORE_CONFIGWRITER_H

View file

@ -21,9 +21,9 @@
#include "QUtility.h"
#include <QCoreApplication>
#include <QDir>
#include <QProcess>
#include <QtGlobal>
#include <QDir>
#include <stdexcept>
static const char kCoreBinary[] = "syntool";
@ -34,40 +34,31 @@ static const char kSerialKeyFilename[] = "Synergy.subkey";
static const char kSerialKeyFilename[] = ".synergy.subkey";
#endif
CoreInterface::CoreInterface()
{
CoreInterface::CoreInterface() {}
QString CoreInterface::getProfileDir() {
QStringList args("--get-profile-dir");
return run(args);
}
QString CoreInterface::getProfileDir()
{
QStringList args("--get-profile-dir");
return run(args);
QString CoreInterface::getInstalledDir() {
QStringList args("--get-installed-dir");
return run(args);
}
QString CoreInterface::getInstalledDir()
{
QStringList args("--get-installed-dir");
return run(args);
QString CoreInterface::getArch() {
QStringList args("--get-arch");
return run(args);
}
QString CoreInterface::getArch()
{
QStringList args("--get-arch");
return run(args);
QString CoreInterface::getSerialKeyFilePath() {
QString filename = getProfileDir() + QDir::separator() + kSerialKeyFilename;
return filename;
}
QString CoreInterface::getSerialKeyFilePath()
{
QString filename = getProfileDir() + QDir::separator() + kSerialKeyFilename;
return filename;
}
QString CoreInterface::run(const QStringList &args, const QString &input) {
QString program(QCoreApplication::applicationDirPath() + "/" + kCoreBinary);
QString CoreInterface::run(const QStringList& args, const QString& input)
{
QString program(
QCoreApplication::applicationDirPath()
+ "/" + kCoreBinary);
CommandProcess commandProcess(program, args, input);
return commandProcess.run();
CommandProcess commandProcess(program, args, input);
return commandProcess.run();
}

View file

@ -19,14 +19,13 @@
#include <QString>
class CoreInterface
{
class CoreInterface {
public:
CoreInterface();
CoreInterface();
QString getProfileDir();
QString getInstalledDir();
QString getArch();
QString getSerialKeyFilePath();
QString run(const QStringList& args, const QString& input = "");
QString getProfileDir();
QString getInstalledDir();
QString getArch();
QString getSerialKeyFilePath();
QString run(const QStringList &args, const QString &input = "");
};

View file

@ -16,93 +16,83 @@
*/
#include "CreditsLoader.h"
#include "MainWindow.h"
#include "AppConfig.h"
#include "MainWindow.h"
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QNetworkReply>
#include <QNetworkRequest>
namespace {
class CreditsResponse {
public:
explicit CreditsResponse(const QByteArray& response) {
auto data = parseJson(response);
m_status = data["status"].toString();
explicit CreditsResponse(const QByteArray &response) {
auto data = parseJson(response);
m_status = data["status"].toString();
if (isSuccess()) {
m_data = data["data"].toString();
}
else if (isFailed()) {
m_data = data["message"].toString();
}
else {
m_data = "Unknown response from the server";
}
if (isSuccess()) {
m_data = data["data"].toString();
} else if (isFailed()) {
m_data = data["message"].toString();
} else {
m_data = "Unknown response from the server";
}
}
bool isSuccess() const {
return (m_status == "success");
}
bool isSuccess() const { return (m_status == "success"); }
bool isFailed() const {
return (m_status == "failed");
}
bool isFailed() const { return (m_status == "failed"); }
const QString& getData() const {
return m_data;
}
const QString &getData() const { return m_data; }
private:
QMap<QString, QVariant> parseJson(const QByteArray& json) const {
QJsonParseError jsonError;
auto data = QJsonDocument::fromJson(json, &jsonError);
if (jsonError.error == QJsonParseError::NoError) {
return data.toVariant().toMap();
}
return QMap<QString, QVariant>();
QMap<QString, QVariant> parseJson(const QByteArray &json) const {
QJsonParseError jsonError;
auto data = QJsonDocument::fromJson(json, &jsonError);
if (jsonError.error == QJsonParseError::NoError) {
return data.toVariant().toMap();
}
return QMap<QString, QVariant>();
}
QString m_data;
QString m_status;
QString m_data;
QString m_status;
};
} // namespace
CreditsLoader::CreditsLoader(MainWindow &mainWindow, const AppConfig &config)
: m_mainWindow(mainWindow), m_config(config) {
connect(&m_manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(replyFinished(QNetworkReply *)));
}
CreditsLoader::CreditsLoader(MainWindow& mainWindow, const AppConfig& config) :
m_mainWindow(mainWindow),
m_config(config)
{
connect(&m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
void CreditsLoader::loadEliteBackers() {
const auto ELITE_BACKERS_URL = m_config.getEliteBackersUrl();
m_mainWindow.appendLogDebug(
QString("Send request: %1").arg(ELITE_BACKERS_URL));
const auto url = QUrl(ELITE_BACKERS_URL);
const auto request = QNetworkRequest(url);
m_manager.get(request);
}
void CreditsLoader::loadEliteBackers()
{
const auto ELITE_BACKERS_URL = m_config.getEliteBackersUrl();
m_mainWindow.appendLogDebug(QString("Send request: %1").arg(ELITE_BACKERS_URL));
const auto url = QUrl(ELITE_BACKERS_URL);
const auto request = QNetworkRequest(url);
m_manager.get(request);
void CreditsLoader::replyFinished(QNetworkReply *reply) const {
auto response = reply->readAll();
m_mainWindow.appendLogDebug(
QString("Received response: %1").arg(response.toStdString().c_str()));
CreditsResponse creditsResponse(response);
if (creditsResponse.isSuccess()) {
emit loaded(creditsResponse.getData());
} else {
error(QString("Server error: %1").arg(creditsResponse.getData()));
}
}
void CreditsLoader::replyFinished(QNetworkReply* reply) const
{
auto response = reply->readAll();
m_mainWindow.appendLogDebug(QString("Received response: %1").arg(response.toStdString().c_str()));
CreditsResponse creditsResponse(response);
if (creditsResponse.isSuccess()) {
emit loaded(creditsResponse.getData());
}
else {
error(QString("Server error: %1").arg(creditsResponse.getData()));
}
}
void CreditsLoader::error(const QString& error) const
{
m_mainWindow.appendLogError(error);
emit loaded("Something went wrong when retrieving the list of Elite Backers. Check the logs for more info.");
void CreditsLoader::error(const QString &error) const {
m_mainWindow.appendLogError(error);
emit loaded("Something went wrong when retrieving the list of Elite Backers. "
"Check the logs for more info.");
}

View file

@ -16,30 +16,29 @@
*/
#pragma once
#include <QObject>
#include <QNetworkAccessManager>
#include <QObject>
class QNetworkReply;
class MainWindow;
class AppConfig;
class CreditsLoader : public QObject
{
Q_OBJECT
class CreditsLoader : public QObject {
Q_OBJECT
public:
explicit CreditsLoader(MainWindow& mainWindow, const AppConfig& config);
void loadEliteBackers();
explicit CreditsLoader(MainWindow &mainWindow, const AppConfig &config);
void loadEliteBackers();
signals:
void loaded(const QString& eliteBakers) const;
void loaded(const QString &eliteBakers) const;
public slots:
void replyFinished(QNetworkReply* reply) const;
void replyFinished(QNetworkReply *reply) const;
private:
MainWindow& m_mainWindow;
const AppConfig& m_config;
QNetworkAccessManager m_manager;
MainWindow &m_mainWindow;
const AppConfig &m_config;
QNetworkAccessManager m_manager;
void error(const QString& error) const;
void error(const QString &error) const;
};

View file

@ -17,45 +17,34 @@
#include "DataDownloader.h"
DataDownloader::DataDownloader(QObject* parent) :
QObject(parent),
m_pReply(nullptr),
m_IsFinished(false)
{
connect(&m_NetworkManager, SIGNAL(finished(QNetworkReply*)),
SLOT(complete(QNetworkReply*)));
DataDownloader::DataDownloader(QObject *parent)
: QObject(parent), m_pReply(nullptr), m_IsFinished(false) {
connect(&m_NetworkManager, SIGNAL(finished(QNetworkReply *)),
SLOT(complete(QNetworkReply *)));
}
DataDownloader::~DataDownloader()
{
DataDownloader::~DataDownloader() {}
void DataDownloader::complete(QNetworkReply *reply) {
m_Data = reply->readAll();
reply->deleteLater();
m_pReply = nullptr;
if (!m_Data.isEmpty()) {
m_IsFinished = true;
emit isComplete();
}
}
void DataDownloader::complete(QNetworkReply* reply)
{
m_Data = reply->readAll();
reply->deleteLater();
m_pReply = nullptr;
QByteArray DataDownloader::data() const { return m_Data; }
if (!m_Data.isEmpty()) {
m_IsFinished = true;
emit isComplete();
}
void DataDownloader::cancel() {
if (m_pReply != nullptr) {
m_pReply->abort();
}
}
QByteArray DataDownloader::data() const
{
return m_Data;
}
void DataDownloader::cancel()
{
if (m_pReply != nullptr) {
m_pReply->abort();
}
}
void DataDownloader::download(QUrl url)
{
QNetworkRequest request(url);
m_pReply = m_NetworkManager.get(request);
void DataDownloader::download(QUrl url) {
QNetworkRequest request(url);
m_pReply = m_NetworkManager.get(request);
}

View file

@ -18,36 +18,35 @@
#ifndef DATADOWNLOADER_H
#define DATADOWNLOADER_H
#include <QObject>
#include <QByteArray>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QObject>
class DataDownloader : public QObject
{
Q_OBJECT
class DataDownloader : public QObject {
Q_OBJECT
public:
explicit DataDownloader(QObject* parent = 0);
virtual ~DataDownloader();
explicit DataDownloader(QObject *parent = 0);
virtual ~DataDownloader();
QByteArray data() const;
void cancel();
void download(QUrl url);
bool isFinished() const { return m_IsFinished; }
QByteArray data() const;
void cancel();
void download(QUrl url);
bool isFinished() const { return m_IsFinished; }
signals:
void isComplete();
void isComplete();
private slots:
void complete(QNetworkReply* reply);
void complete(QNetworkReply *reply);
private:
QNetworkAccessManager m_NetworkManager;
QByteArray m_Data;
QNetworkReply* m_pReply;
bool m_IsFinished;
QNetworkAccessManager m_NetworkManager;
QByteArray m_Data;
QNetworkReply *m_pReply;
bool m_IsFinished;
};
#endif // DATADOWNLOADER_H

View file

@ -32,10 +32,6 @@
// ElevateAlways | false | true
// ElevateNever | false | false
//
enum ElevateMode {
ElevateAsNeeded = 0,
ElevateAlways = 1,
ElevateNever = 2
};
enum ElevateMode { ElevateAsNeeded = 0, ElevateAlways = 1, ElevateNever = 2 };
extern const ElevateMode defaultElevateMode;

View file

@ -1,15 +1,10 @@
#include "FailedLoginDialog.h"
#include "ui_FailedLoginDialog.h"
FailedLoginDialog::FailedLoginDialog(QWidget *parent, QString message):
QDialog(parent),
ui(new Ui::FailedLoginDialog)
{
ui->setupUi(this);
ui->messageLabel->setText(ui->messageLabel->text().arg(message));
FailedLoginDialog::FailedLoginDialog(QWidget *parent, QString message)
: QDialog(parent), ui(new Ui::FailedLoginDialog) {
ui->setupUi(this);
ui->messageLabel->setText(ui->messageLabel->text().arg(message));
}
FailedLoginDialog::~FailedLoginDialog()
{
delete ui;
}
FailedLoginDialog::~FailedLoginDialog() { delete ui; }

View file

@ -8,16 +8,15 @@ namespace Ui {
class FailedLoginDialog;
}
class FailedLoginDialog : public QDialog
{
Q_OBJECT
class FailedLoginDialog : public QDialog {
Q_OBJECT
public:
explicit FailedLoginDialog(QWidget *parent = 0, QString message = "");
~FailedLoginDialog();
explicit FailedLoginDialog(QWidget *parent = 0, QString message = "");
~FailedLoginDialog();
private:
Ui::FailedLoginDialog *ui;
Ui::FailedLoginDialog *ui;
};
#endif // FAILEDLOGINDIALOG_H

View file

@ -27,123 +27,100 @@ static const char kLocalFilename[] = "Local.txt";
static const char kTrustedServersFilename[] = "TrustedServers.txt";
static const char kTrustedClientsFilename[] = "TrustedClients.txt";
Fingerprint::Fingerprint(const QString& filename)
{
m_Filename = filename;
Fingerprint::Fingerprint(const QString &filename) { m_Filename = filename; }
void Fingerprint::trust(const QString &fingerprintText, bool append) {
Fingerprint::persistDirectory();
QIODevice::OpenMode openMode;
if (append) {
openMode = QIODevice::Append;
} else {
openMode = QIODevice::WriteOnly;
}
QFile file(filePath());
if (file.open(openMode)) {
QTextStream out(&file);
out << fingerprintText << "\n";
file.close();
}
}
void Fingerprint::trust(const QString& fingerprintText, bool append)
{
Fingerprint::persistDirectory();
QIODevice::OpenMode openMode;
if (append) {
openMode = QIODevice::Append;
}
else {
openMode = QIODevice::WriteOnly;
}
QFile file(filePath());
if (file.open(openMode))
{
QTextStream out(&file);
out << fingerprintText << "\n";
file.close();
}
}
bool Fingerprint::fileExists() const
{
QString dirName = Fingerprint::directoryPath();
if (!QDir(dirName).exists()) {
return false;
}
QFile file(filePath());
return file.exists();
}
bool Fingerprint::isTrusted(const QString& fingerprintText)
{
QStringList list = readList();
foreach (QString trusted, list)
{
if (trusted == fingerprintText) {
return true;
}
}
bool Fingerprint::fileExists() const {
QString dirName = Fingerprint::directoryPath();
if (!QDir(dirName).exists()) {
return false;
}
QFile file(filePath());
return file.exists();
}
QStringList Fingerprint::readList(const int readTo)
{
QStringList list;
QString dirName = Fingerprint::directoryPath();
if (!QDir(dirName).exists()) {
return list;
bool Fingerprint::isTrusted(const QString &fingerprintText) {
QStringList list = readList();
foreach (QString trusted, list) {
if (trusted == fingerprintText) {
return true;
}
}
return false;
}
QFile file(filePath());
if (file.open(QIODevice::ReadOnly))
{
QTextStream in(&file);
while (!in.atEnd())
{
list.append(in.readLine());
if (list.size() == readTo) {
break;
}
}
file.close();
}
QStringList Fingerprint::readList(const int readTo) {
QStringList list;
QString dirName = Fingerprint::directoryPath();
if (!QDir(dirName).exists()) {
return list;
}
}
QString Fingerprint::readFirst()
{
QStringList list = readList(1);
return list.at(0);
}
QFile file(filePath());
QString Fingerprint::filePath() const
{
QString dir = Fingerprint::directoryPath();
return QString("%1/%2").arg(dir).arg(m_Filename);
}
void Fingerprint::persistDirectory()
{
QDir dir(Fingerprint::directoryPath());
if (!dir.exists()) {
dir.mkpath(".");
if (file.open(QIODevice::ReadOnly)) {
QTextStream in(&file);
while (!in.atEnd()) {
list.append(in.readLine());
if (list.size() == readTo) {
break;
}
}
file.close();
}
return list;
}
QString Fingerprint::directoryPath()
{
CoreInterface coreInterface;
QString profileDir = coreInterface.getProfileDir();
return QString("%1/%2")
.arg(profileDir)
.arg(kDirName);
QString Fingerprint::readFirst() {
QStringList list = readList(1);
return list.at(0);
}
Fingerprint Fingerprint::local()
{
return Fingerprint(kLocalFilename);
QString Fingerprint::filePath() const {
QString dir = Fingerprint::directoryPath();
return QString("%1/%2").arg(dir).arg(m_Filename);
}
Fingerprint Fingerprint::trustedServers()
{
return Fingerprint(kTrustedServersFilename);
void Fingerprint::persistDirectory() {
QDir dir(Fingerprint::directoryPath());
if (!dir.exists()) {
dir.mkpath(".");
}
}
Fingerprint Fingerprint::trustedClients()
{
return Fingerprint(kTrustedClientsFilename);
QString Fingerprint::directoryPath() {
CoreInterface coreInterface;
QString profileDir = coreInterface.getProfileDir();
return QString("%1/%2").arg(profileDir).arg(kDirName);
}
Fingerprint Fingerprint::local() { return Fingerprint(kLocalFilename); }
Fingerprint Fingerprint::trustedServers() {
return Fingerprint(kTrustedServersFilename);
}
Fingerprint Fingerprint::trustedClients() {
return Fingerprint(kTrustedClientsFilename);
}

View file

@ -19,28 +19,27 @@
#include <QString>
class Fingerprint
{
class Fingerprint {
private:
Fingerprint(const QString& filename);
Fingerprint(const QString &filename);
public:
void trust(const QString& fingerprintText, bool append = true);
bool isTrusted(const QString& fingerprintText);
QStringList readList(const int readTo = -1);
QString readFirst();
QString filePath() const;
bool fileExists() const;
void trust(const QString &fingerprintText, bool append = true);
bool isTrusted(const QString &fingerprintText);
QStringList readList(const int readTo = -1);
QString readFirst();
QString filePath() const;
bool fileExists() const;
public:
static Fingerprint local();
static Fingerprint trustedServers();
static Fingerprint trustedClients();
static QString directoryPath();
static QString localFingerprint();
static bool localFingerprintExists();
static void persistDirectory();
static Fingerprint local();
static Fingerprint trustedServers();
static Fingerprint trustedClients();
static QString directoryPath();
static QString localFingerprint();
static bool localFingerprintExists();
static void persistDirectory();
private:
QString m_Filename;
QString m_Filename;
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -20,61 +20,50 @@
#include <QSettings>
Hotkey::Hotkey() :
m_KeySequence(),
m_Actions()
{
Hotkey::Hotkey() : m_KeySequence(), m_Actions() {}
QString Hotkey::text() const {
QString text = keySequence().toString();
if (keySequence().isMouseButton())
return "mousebutton(" + text + ")";
return "keystroke(" + text + ")";
}
QString Hotkey::text() const
{
QString text = keySequence().toString();
void Hotkey::loadSettings(QSettings &settings) {
keySequence().loadSettings(settings);
if (keySequence().isMouseButton())
return "mousebutton(" + text + ")";
actions().clear();
int num = settings.beginReadArray("actions");
for (int i = 0; i < num; i++) {
settings.setArrayIndex(i);
Action a;
a.loadSettings(settings);
actions().append(a);
}
return "keystroke(" + text + ")";
settings.endArray();
}
void Hotkey::loadSettings(QSettings& settings)
{
keySequence().loadSettings(settings);
void Hotkey::saveSettings(QSettings &settings) const {
keySequence().saveSettings(settings);
actions().clear();
int num = settings.beginReadArray("actions");
for (int i = 0; i < num; i++)
{
settings.setArrayIndex(i);
Action a;
a.loadSettings(settings);
actions().append(a);
}
settings.endArray();
settings.beginWriteArray("actions");
for (int i = 0; i < actions().size(); i++) {
settings.setArrayIndex(i);
actions()[i].saveSettings(settings);
}
settings.endArray();
}
void Hotkey::saveSettings(QSettings& settings) const
{
keySequence().saveSettings(settings);
settings.beginWriteArray("actions");
for (int i = 0; i < actions().size(); i++)
{
settings.setArrayIndex(i);
actions()[i].saveSettings(settings);
}
settings.endArray();
bool Hotkey::operator==(const Hotkey &hk) const {
return m_KeySequence == hk.m_KeySequence && m_Actions == hk.m_Actions;
}
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) {
for (int i = 0; i < hotkey.actions().size(); i++)
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i] << endl;
QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey)
{
for (int i = 0; i < hotkey.actions().size(); i++)
outStream << "\t" << hotkey.text() << " = " << hotkey.actions()[i] << endl;
return outStream;
return outStream;
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -20,8 +20,8 @@
#define HOTKEY_H
#include <QString>
#include <QList>
#include <QString>
#include <QTextStream>
#include "Action.h"
@ -31,38 +31,36 @@ class HotkeyDialog;
class ServerConfigDialog;
class QSettings;
class Hotkey
{
friend class HotkeyDialog;
friend class ServerConfigDialog;
friend QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey);
class Hotkey {
friend class HotkeyDialog;
friend class ServerConfigDialog;
friend QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey);
public:
Hotkey();
public:
Hotkey();
public:
QString text() const;
const KeySequence& keySequence() const { return m_KeySequence; }
const ActionList& actions() const { return m_Actions; }
public:
QString text() const;
const KeySequence &keySequence() const { return m_KeySequence; }
const ActionList &actions() const { return m_Actions; }
void loadSettings(QSettings& settings);
void saveSettings(QSettings& settings) const;
void loadSettings(QSettings &settings);
void saveSettings(QSettings &settings) const;
bool operator==(const Hotkey& hk) const;
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; }
protected:
KeySequence &keySequence() { return m_KeySequence; }
void setKeySequence(const KeySequence &seq) { m_KeySequence = seq; }
ActionList &actions() { return m_Actions; }
private:
KeySequence m_KeySequence;
ActionList m_Actions;
private:
KeySequence m_KeySequence;
ActionList m_Actions;
};
typedef QList<Hotkey> HotkeyList;
QTextStream& operator<<(QTextStream& outStream, const Hotkey& hotkey);
QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey);
#endif

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -21,21 +21,18 @@
#include <QtCore>
#include <QtGui>
HotkeyDialog::HotkeyDialog (QWidget* parent, Hotkey& hotkey) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::HotkeyDialogBase(),
m_Hotkey(hotkey)
{
setupUi(this);
HotkeyDialog::HotkeyDialog(QWidget *parent, Hotkey &hotkey)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
Ui::HotkeyDialogBase(), m_Hotkey(hotkey) {
setupUi(this);
m_pKeySequenceWidgetHotkey->setText(m_Hotkey.text());
m_pKeySequenceWidgetHotkey->setText(m_Hotkey.text());
}
void HotkeyDialog::accept()
{
if (!sequenceWidget()->valid())
return;
void HotkeyDialog::accept() {
if (!sequenceWidget()->valid())
return;
hotkey().setKeySequence(sequenceWidget()->keySequence());
QDialog::accept();
hotkey().setKeySequence(sequenceWidget()->keySequence());
QDialog::accept();
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -20,30 +20,31 @@
#define HOTKEYDIALOG_H
#include "ui_HotkeyDialogBase.h"
#include "Hotkey.h"
#include "ui_HotkeyDialogBase.h"
#include <QDialog>
class HotkeyDialog : public QDialog, public Ui::HotkeyDialogBase
{
Q_OBJECT
class HotkeyDialog : public QDialog, public Ui::HotkeyDialogBase {
Q_OBJECT
public:
HotkeyDialog(QWidget* parent, Hotkey& hotkey);
public:
HotkeyDialog(QWidget *parent, Hotkey &hotkey);
public:
const Hotkey& hotkey() const { return m_Hotkey; }
public:
const Hotkey &hotkey() const { return m_Hotkey; }
protected slots:
void accept();
protected slots:
void accept();
protected:
const KeySequenceWidget* sequenceWidget() const { return m_pKeySequenceWidgetHotkey; }
Hotkey& hotkey() { return m_Hotkey; }
protected:
const KeySequenceWidget *sequenceWidget() const {
return m_pKeySequenceWidgetHotkey;
}
Hotkey &hotkey() { return m_Hotkey; }
private:
Hotkey& m_Hotkey;
private:
Hotkey &m_Hotkey;
};
#endif

View file

@ -20,7 +20,7 @@
#include "Ipc.h"
const char* kIpcMsgHello = "IHEL%1i";
const char* kIpcMsgLogLine = "ILOG%s";
const char* kIpcMsgCommand = "ICMD%s%1i";
const char* kIpcMsgShutdown = "ISDN";
const char *kIpcMsgHello = "IHEL%1i";
const char *kIpcMsgLogLine = "ILOG%s";
const char *kIpcMsgCommand = "ICMD%s%1i";
const char *kIpcMsgShutdown = "ISDN";

View file

@ -24,19 +24,19 @@
#define IPC_PORT 24801
enum qIpcMessageType {
kIpcHello,
kIpcLogLine,
kIpcCommand,
kIpcShutdown,
kIpcHello,
kIpcLogLine,
kIpcCommand,
kIpcShutdown,
};
enum qIpcClientType {
kIpcClientUnknown,
kIpcClientGui,
kIpcClientNode,
kIpcClientUnknown,
kIpcClientGui,
kIpcClientNode,
};
extern const char* kIpcMsgHello;
extern const char* kIpcMsgLogLine;
extern const char* kIpcMsgCommand;
extern const char* kIpcMsgShutdown;
extern const char *kIpcMsgHello;
extern const char *kIpcMsgLogLine;
extern const char *kIpcMsgCommand;
extern const char *kIpcMsgShutdown;

View file

@ -17,130 +17,122 @@
*/
#include "IpcClient.h"
#include <QTcpSocket>
#include <QHostAddress>
#include <iostream>
#include <QTimer>
#include "IpcReader.h"
#include "Ipc.h"
#include "IpcReader.h"
#include <QDataStream>
#include <QHostAddress>
#include <QTcpSocket>
#include <QTimer>
#include <iostream>
IpcClient::IpcClient() :
m_ReaderStarted(false),
m_Enabled(false)
{
m_Socket = new QTcpSocket(this);
connect(m_Socket, SIGNAL(connected()), this, SLOT(connected()));
connect(m_Socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
IpcClient::IpcClient() : m_ReaderStarted(false), m_Enabled(false) {
m_Socket = new QTcpSocket(this);
connect(m_Socket, SIGNAL(connected()), this, SLOT(connected()));
connect(m_Socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
SLOT(error(QAbstractSocket::SocketError)));
m_Reader = new IpcReader(m_Socket);
connect(m_Reader, SIGNAL(readLogLine(const QString&)), this, SLOT(handleReadLogLine(const QString&)));
m_Reader = new IpcReader(m_Socket);
connect(m_Reader, SIGNAL(readLogLine(const QString &)), this,
SLOT(handleReadLogLine(const QString &)));
}
IpcClient::~IpcClient()
{
IpcClient::~IpcClient() {}
void IpcClient::connected() {
sendHello();
infoMessage("connection established");
}
void IpcClient::connected()
{
sendHello();
infoMessage("connection established");
void IpcClient::connectToHost() {
m_Enabled = true;
infoMessage("connecting to service...");
m_Socket->connectToHost(QHostAddress(QHostAddress::LocalHost), IPC_PORT);
if (!m_ReaderStarted) {
m_Reader->start();
m_ReaderStarted = true;
}
}
void IpcClient::connectToHost()
{
m_Enabled = true;
infoMessage("connecting to service...");
m_Socket->connectToHost(QHostAddress(QHostAddress::LocalHost), IPC_PORT);
if (!m_ReaderStarted) {
m_Reader->start();
m_ReaderStarted = true;
}
void IpcClient::disconnectFromHost() {
infoMessage("service disconnect");
m_Reader->stop();
m_Socket->close();
}
void IpcClient::disconnectFromHost()
{
infoMessage("service disconnect");
m_Reader->stop();
m_Socket->close();
void IpcClient::error(QAbstractSocket::SocketError error) {
QString text;
switch (error) {
case 0:
text = "connection refused";
break;
case 1:
text = "remote host closed";
break;
default:
text = QString("code=%1").arg(error);
break;
}
errorMessage(QString("ipc connection error, %1").arg(text));
QTimer::singleShot(1000, this, SLOT(retryConnect()));
}
void IpcClient::error(QAbstractSocket::SocketError error)
{
QString text;
switch (error) {
case 0: text = "connection refused"; break;
case 1: text = "remote host closed"; break;
default: text = QString("code=%1").arg(error); break;
}
errorMessage(QString("ipc connection error, %1").arg(text));
QTimer::singleShot(1000, this, SLOT(retryConnect()));
void IpcClient::retryConnect() {
if (m_Enabled) {
connectToHost();
}
}
void IpcClient::retryConnect()
{
if (m_Enabled) {
connectToHost();
}
void IpcClient::sendHello() {
QDataStream stream(m_Socket);
stream.writeRawData(kIpcMsgHello, 4);
char typeBuf[1];
typeBuf[0] = kIpcClientGui;
stream.writeRawData(typeBuf, 1);
}
void IpcClient::sendHello()
{
QDataStream stream(m_Socket);
stream.writeRawData(kIpcMsgHello, 4);
void IpcClient::sendCommand(const QString &command, ElevateMode const elevate) {
QDataStream stream(m_Socket);
char typeBuf[1];
typeBuf[0] = kIpcClientGui;
stream.writeRawData(typeBuf, 1);
stream.writeRawData(kIpcMsgCommand, 4);
std::string stdStringCommand = command.toStdString();
const char *charCommand = stdStringCommand.c_str();
int length = static_cast<int>(
strlen(charCommand)); // Compliant: we made sure that charCommand variable
// ended with null(String type is safe)
char lenBuf[4];
intToBytes(length, lenBuf, 4);
stream.writeRawData(lenBuf, 4);
stream.writeRawData(charCommand, length);
char elevateBuf[1];
// Refer to enum ElevateMode documentation for why this flag is mapped this
// way
elevateBuf[0] = (elevate == ElevateAlways) ? 1 : 0;
stream.writeRawData(elevateBuf, 1);
}
void IpcClient::sendCommand(const QString& command, ElevateMode const elevate)
{
QDataStream stream(m_Socket);
stream.writeRawData(kIpcMsgCommand, 4);
std::string stdStringCommand = command.toStdString();
const char* charCommand = stdStringCommand.c_str();
int length = static_cast<int>(strlen(charCommand)); // Compliant: we made sure that charCommand variable ended with null(String type is safe)
char lenBuf[4];
intToBytes(length, lenBuf, 4);
stream.writeRawData(lenBuf, 4);
stream.writeRawData(charCommand, length);
char elevateBuf[1];
// Refer to enum ElevateMode documentation for why this flag is mapped this way
elevateBuf[0] = (elevate == ElevateAlways) ? 1 : 0;
stream.writeRawData(elevateBuf, 1);
}
void IpcClient::handleReadLogLine(const QString& text)
{
readLogLine(text);
}
void IpcClient::handleReadLogLine(const QString &text) { readLogLine(text); }
// TODO: qt must have a built in way of converting int to bytes.
void IpcClient::intToBytes(int value, char *buffer, int size)
{
if (size == 1) {
buffer[0] = value & 0xff;
}
else if (size == 2) {
buffer[0] = (value >> 8) & 0xff;
buffer[1] = value & 0xff;
}
else if (size == 4) {
buffer[0] = (value >> 24) & 0xff;
buffer[1] = (value >> 16) & 0xff;
buffer[2] = (value >> 8) & 0xff;
buffer[3] = value & 0xff;
}
else {
// TODO: other sizes, if needed.
}
void IpcClient::intToBytes(int value, char *buffer, int size) {
if (size == 1) {
buffer[0] = value & 0xff;
} else if (size == 2) {
buffer[0] = (value >> 8) & 0xff;
buffer[1] = value & 0xff;
} else if (size == 4) {
buffer[0] = (value >> 24) & 0xff;
buffer[1] = (value >> 16) & 0xff;
buffer[2] = (value >> 8) & 0xff;
buffer[3] = value & 0xff;
} else {
// TODO: other sizes, if needed.
}
}

View file

@ -18,46 +18,45 @@
#pragma once
#include <QObject>
#include <QAbstractSocket>
#include <QObject>
#include "ElevateMode.h"
class QTcpSocket;
class IpcReader;
class IpcClient : public QObject
{
Q_OBJECT
class IpcClient : public QObject {
Q_OBJECT
public:
IpcClient();
virtual ~IpcClient();
IpcClient();
virtual ~IpcClient();
void sendHello();
void sendCommand(const QString& command, ElevateMode elevate);
void connectToHost();
void disconnectFromHost();
void sendHello();
void sendCommand(const QString &command, ElevateMode elevate);
void connectToHost();
void disconnectFromHost();
public slots:
void retryConnect();
void retryConnect();
private:
void intToBytes(int value, char* buffer, int size);
void intToBytes(int value, char *buffer, int size);
private slots:
void connected();
void error(QAbstractSocket::SocketError error);
void handleReadLogLine(const QString& text);
void connected();
void error(QAbstractSocket::SocketError error);
void handleReadLogLine(const QString &text);
signals:
void readLogLine(const QString& text);
void infoMessage(const QString& text);
void errorMessage(const QString& text);
void readLogLine(const QString &text);
void infoMessage(const QString &text);
void errorMessage(const QString &text);
private:
QTcpSocket* m_Socket;
IpcReader* m_Reader;
bool m_ReaderStarted;
bool m_Enabled;
QTcpSocket *m_Socket;
IpcReader *m_Reader;
bool m_ReaderStarted;
bool m_Enabled;
};

View file

@ -17,115 +17,96 @@
*/
#include "IpcReader.h"
#include <QTcpSocket>
#include "Ipc.h"
#include <iostream>
#include <QMutex>
#include <QByteArray>
#include <QMutex>
#include <QTcpSocket>
#include <iostream>
IpcReader::IpcReader(QTcpSocket* socket) :
m_Socket(socket)
{
IpcReader::IpcReader(QTcpSocket *socket) : m_Socket(socket) {}
IpcReader::~IpcReader() {}
void IpcReader::start() {
connect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
}
IpcReader::~IpcReader()
{
void IpcReader::stop() {
disconnect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
}
void IpcReader::start()
{
connect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
void IpcReader::read() {
QMutexLocker locker(&m_Mutex);
std::cout << "ready read" << std::endl;
while (m_Socket->bytesAvailable()) {
std::cout << "bytes available" << std::endl;
char codeBuf[5];
readStream(codeBuf, 4);
codeBuf[4] = 0;
std::cout << "ipc read: " << codeBuf << std::endl;
if (memcmp(codeBuf, kIpcMsgLogLine, 4) == 0) {
std::cout << "reading log line" << std::endl;
char lenBuf[4];
readStream(lenBuf, 4);
int len = bytesToInt(lenBuf, 4);
char *data = new char[len];
readStream(data, len);
QString line = QString::fromUtf8(data, len);
delete[] data;
readLogLine(line);
} else {
std::cerr << "aborting, message invalid" << std::endl;
return;
}
}
std::cout << "read done" << std::endl;
}
void IpcReader::stop()
{
disconnect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
}
bool IpcReader::readStream(char *buffer, int length) {
std::cout << "reading stream" << std::endl;
void IpcReader::read()
{
QMutexLocker locker(&m_Mutex);
std::cout << "ready read" << std::endl;
while (m_Socket->bytesAvailable()) {
std::cout << "bytes available" << std::endl;
char codeBuf[5];
readStream(codeBuf, 4);
codeBuf[4] = 0;
std::cout << "ipc read: " << codeBuf << std::endl;
if (memcmp(codeBuf, kIpcMsgLogLine, 4) == 0) {
std::cout << "reading log line" << std::endl;
char lenBuf[4];
readStream(lenBuf, 4);
int len = bytesToInt(lenBuf, 4);
char* data = new char[len];
readStream(data, len);
QString line = QString::fromUtf8(data, len);
delete[] data;
readLogLine(line);
}
else {
std::cerr << "aborting, message invalid" << std::endl;
return;
}
int read = 0;
while (read < length) {
int ask = length - read;
if (m_Socket->bytesAvailable() < ask) {
std::cout << "buffer too short, waiting" << std::endl;
m_Socket->waitForReadyRead(-1);
}
std::cout << "read done" << std::endl;
int got = m_Socket->read(buffer, ask);
read += got;
std::cout << "> ask=" << ask << " got=" << got << " read=" << read
<< std::endl;
if (got == -1) {
std::cout << "socket ended, aborting" << std::endl;
return false;
} else if (length - read > 0) {
std::cout << "more remains, seek to " << got << std::endl;
buffer += got;
}
}
return true;
}
bool IpcReader::readStream(char* buffer, int length)
{
std::cout << "reading stream" << std::endl;
int read = 0;
while (read < length) {
int ask = length - read;
if (m_Socket->bytesAvailable() < ask) {
std::cout << "buffer too short, waiting" << std::endl;
m_Socket->waitForReadyRead(-1);
}
int got = m_Socket->read(buffer, ask);
read += got;
std::cout << "> ask=" << ask << " got=" << got
<< " read=" << read << std::endl;
if (got == -1) {
std::cout << "socket ended, aborting" << std::endl;
return false;
}
else if (length - read > 0) {
std::cout << "more remains, seek to " << got << std::endl;
buffer += got;
}
}
return true;
}
int IpcReader::bytesToInt(const char *buffer, int size)
{
if (size == 1) {
return (unsigned char)buffer[0];
}
else if (size == 2) {
return
(((unsigned char)buffer[0]) << 8) +
(unsigned char)buffer[1];
}
else if (size == 4) {
return
(((unsigned char)buffer[0]) << 24) +
(((unsigned char)buffer[1]) << 16) +
(((unsigned char)buffer[2]) << 8) +
(unsigned char)buffer[3];
}
else {
return 0;
}
int IpcReader::bytesToInt(const char *buffer, int size) {
if (size == 1) {
return (unsigned char)buffer[0];
} else if (size == 2) {
return (((unsigned char)buffer[0]) << 8) + (unsigned char)buffer[1];
} else if (size == 4) {
return (((unsigned char)buffer[0]) << 24) +
(((unsigned char)buffer[1]) << 16) +
(((unsigned char)buffer[2]) << 8) + (unsigned char)buffer[3];
} else {
return 0;
}
}

View file

@ -18,32 +18,31 @@
#pragma once
#include <QObject>
#include <QMutex>
#include <QObject>
class QTcpSocket;
class IpcReader : public QObject
{
Q_OBJECT;
class IpcReader : public QObject {
Q_OBJECT;
public:
IpcReader(QTcpSocket* socket);
virtual ~IpcReader();
void start();
void stop();
IpcReader(QTcpSocket *socket);
virtual ~IpcReader();
void start();
void stop();
signals:
void readLogLine(const QString& text);
void readLogLine(const QString &text);
private:
bool readStream(char* buffer, int length);
int bytesToInt(const char* buffer, int size);
bool readStream(char *buffer, int length);
int bytesToInt(const char *buffer, int size);
private slots:
void read();
void read();
private:
QTcpSocket* m_Socket;
QMutex m_Mutex;
QTcpSocket *m_Socket;
QMutex m_Mutex;
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -23,222 +23,198 @@
// this table originally comes from Qt sources (gui/kernel/qkeysequence.cpp)
// and is heavily modified for QSynergy
static const struct
{
int key;
const char* name;
} keyname[] =
{
{ Qt::Key_Space, "Space" },
{ Qt::Key_Escape, "Escape" },
{ Qt::Key_Tab, "Tab" },
{ Qt::Key_Backtab, "LeftTab" },
{ Qt::Key_Backspace, "BackSpace" },
{ Qt::Key_Return, "Return" },
{ Qt::Key_Insert, "Insert" },
{ Qt::Key_Delete, "Delete" },
{ Qt::Key_Pause, "Pause" },
{ Qt::Key_Print, "Print" },
{ Qt::Key_SysReq, "SysReq" },
{ Qt::Key_Home, "Home" },
{ Qt::Key_End, "End" },
{ Qt::Key_Left, "Left" },
{ Qt::Key_Up, "Up" },
{ Qt::Key_Right, "Right" },
{ Qt::Key_Down, "Down" },
{ Qt::Key_PageUp, "PageUp" },
{ Qt::Key_PageDown, "PageDown" },
{ Qt::Key_CapsLock, "CapsLock" },
{ Qt::Key_NumLock, "NumLock" },
{ Qt::Key_ScrollLock, "ScrollLock" },
{ Qt::Key_Menu, "Menu" },
{ Qt::Key_Help, "Help" },
{ Qt::Key_Enter, "KP_Enter" },
{ Qt::Key_Clear, "Clear" },
static const struct {
int key;
const char *name;
} keyname[] = {{Qt::Key_Space, "Space"},
{Qt::Key_Escape, "Escape"},
{Qt::Key_Tab, "Tab"},
{Qt::Key_Backtab, "LeftTab"},
{Qt::Key_Backspace, "BackSpace"},
{Qt::Key_Return, "Return"},
{Qt::Key_Insert, "Insert"},
{Qt::Key_Delete, "Delete"},
{Qt::Key_Pause, "Pause"},
{Qt::Key_Print, "Print"},
{Qt::Key_SysReq, "SysReq"},
{Qt::Key_Home, "Home"},
{Qt::Key_End, "End"},
{Qt::Key_Left, "Left"},
{Qt::Key_Up, "Up"},
{Qt::Key_Right, "Right"},
{Qt::Key_Down, "Down"},
{Qt::Key_PageUp, "PageUp"},
{Qt::Key_PageDown, "PageDown"},
{Qt::Key_CapsLock, "CapsLock"},
{Qt::Key_NumLock, "NumLock"},
{Qt::Key_ScrollLock, "ScrollLock"},
{Qt::Key_Menu, "Menu"},
{Qt::Key_Help, "Help"},
{Qt::Key_Enter, "KP_Enter"},
{Qt::Key_Clear, "Clear"},
{ Qt::Key_Back, "WWWBack" },
{ Qt::Key_Forward, "WWWForward" },
{ Qt::Key_Stop, "WWWStop" },
{ Qt::Key_Refresh, "WWWRefresh" },
{ Qt::Key_VolumeDown, "AudioDown" },
{ Qt::Key_VolumeMute, "AudioMute" },
{ Qt::Key_VolumeUp, "AudioUp" },
{ Qt::Key_MediaPlay, "AudioPlay" },
{ Qt::Key_MediaStop, "AudioStop" },
{ Qt::Key_MediaPrevious,"AudioPrev" },
{ Qt::Key_MediaNext, "AudioNext" },
{ Qt::Key_HomePage, "WWWHome" },
{ Qt::Key_Favorites, "WWWFavorites" },
{ Qt::Key_Search, "WWWSearch" },
{ Qt::Key_Standby, "Sleep" },
{ Qt::Key_LaunchMail, "AppMail" },
{ Qt::Key_LaunchMedia, "AppMedia" },
{ Qt::Key_Launch0, "AppUser1" },
{ Qt::Key_Launch1, "AppUser2" },
{ Qt::Key_Select, "Select" },
{Qt::Key_Back, "WWWBack"},
{Qt::Key_Forward, "WWWForward"},
{Qt::Key_Stop, "WWWStop"},
{Qt::Key_Refresh, "WWWRefresh"},
{Qt::Key_VolumeDown, "AudioDown"},
{Qt::Key_VolumeMute, "AudioMute"},
{Qt::Key_VolumeUp, "AudioUp"},
{Qt::Key_MediaPlay, "AudioPlay"},
{Qt::Key_MediaStop, "AudioStop"},
{Qt::Key_MediaPrevious, "AudioPrev"},
{Qt::Key_MediaNext, "AudioNext"},
{Qt::Key_HomePage, "WWWHome"},
{Qt::Key_Favorites, "WWWFavorites"},
{Qt::Key_Search, "WWWSearch"},
{Qt::Key_Standby, "Sleep"},
{Qt::Key_LaunchMail, "AppMail"},
{Qt::Key_LaunchMedia, "AppMedia"},
{Qt::Key_Launch0, "AppUser1"},
{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 {
return !m_Sequence.isEmpty() && m_Sequence.last() < Qt::Key_Space;
}
bool KeySequence::isMouseButton() const
{
return !m_Sequence.isEmpty() && m_Sequence.last() < Qt::Key_Space;
QString KeySequence::toString() const {
QString result;
for (int i = 0; i < m_Sequence.size(); i++) {
result += keyToString(m_Sequence[i]);
if (i != m_Sequence.size() - 1)
result += "+";
}
return result;
}
QString KeySequence::toString() const
{
QString result;
bool KeySequence::appendMouseButton(int button) { return appendKey(button, 0); }
for (int i = 0; i < m_Sequence.size(); i++)
{
result += keyToString(m_Sequence[i]);
if (i != m_Sequence.size() - 1)
result += "+";
}
return result;
}
bool KeySequence::appendMouseButton(int button)
{
return appendKey(button, 0);
}
bool KeySequence::appendKey(int key, int modifiers)
{
if (m_Sequence.size() == 4)
return true;
switch(key)
{
case Qt::Key_AltGr:
return false;
case Qt::Key_Control:
case Qt::Key_Alt:
case Qt::Key_Shift:
case Qt::Key_Meta:
case Qt::Key_Menu:
{
int mod = modifiers & (~m_Modifiers);
if (mod)
{
m_Sequence.append(mod);
m_Modifiers |= mod;
}
}
break;
default:
// see if we can handle this key, if not, don't accept it
if (keyToString(key).isEmpty())
break;
m_Sequence.append(key);
setValid(true);
return true;
}
bool KeySequence::appendKey(int key, int modifiers) {
if (m_Sequence.size() == 4)
return true;
switch (key) {
case Qt::Key_AltGr:
return false;
}
void KeySequence::loadSettings(QSettings& settings)
{
sequence().clear();
int num = settings.beginReadArray("keys");
for (int i = 0; i < num; i++)
{
settings.setArrayIndex(i);
sequence().append(settings.value("key", 0).toInt());
case Qt::Key_Control:
case Qt::Key_Alt:
case Qt::Key_Shift:
case Qt::Key_Meta:
case Qt::Key_Menu: {
int mod = modifiers & (~m_Modifiers);
if (mod) {
m_Sequence.append(mod);
m_Modifiers |= mod;
}
settings.endArray();
} break;
setModifiers(0);
default:
// see if we can handle this key, if not, don't accept it
if (keyToString(key).isEmpty())
break;
m_Sequence.append(key);
setValid(true);
return true;
}
return false;
}
void KeySequence::saveSettings(QSettings& settings) const
{
settings.beginWriteArray("keys");
for (int i = 0; i < sequence().size(); i++)
{
settings.setArrayIndex(i);
settings.setValue("key", sequence()[i]);
}
settings.endArray();
void KeySequence::loadSettings(QSettings &settings) {
sequence().clear();
int num = settings.beginReadArray("keys");
for (int i = 0; i < num; i++) {
settings.setArrayIndex(i);
sequence().append(settings.value("key", 0).toInt());
}
settings.endArray();
setModifiers(0);
setValid(true);
}
QString KeySequence::keyToString(int key)
{
// nothing there?
if (key == 0)
return "";
void KeySequence::saveSettings(QSettings &settings) const {
settings.beginWriteArray("keys");
for (int i = 0; i < sequence().size(); i++) {
settings.setArrayIndex(i);
settings.setValue("key", sequence()[i]);
}
settings.endArray();
}
// a hack to handle mouse buttons as if they were keys
if (key < Qt::Key_Space)
{
switch(key)
{
case Qt::LeftButton: return "1";
case Qt::RightButton: return "2";
case Qt::MidButton: return "3";
}
return "4"; // qt only knows three mouse buttons, so assume it's an unknown fourth one
}
// modifiers?
if (key & Qt::ShiftModifier)
return "Shift";
if (key & Qt::ControlModifier)
return "Control";
if (key & Qt::AltModifier)
return "Alt";
if (key & Qt::MetaModifier)
return "Meta";
// treat key pad like normal keys (FIXME: we should have another lookup table for keypad keys instead)
key &= ~Qt::KeypadModifier;
// a printable 7 bit character?
if (key < 0x80 && key != Qt::Key_Space)
return QChar(key & 0x7f).toLower();
// a function key?
if (key >= Qt::Key_F1 && key <= Qt::Key_F35)
return QString::fromUtf8("F%1").arg(key - Qt::Key_F1 + 1);
// a special key?
int i=0;
while (keyname[i].name)
{
if (key == keyname[i].key)
return QString::fromUtf8(keyname[i].name);
i++;
}
// representable in ucs2?
if (key < 0x10000)
return QString("\\u%1").arg(QChar(key).toLower().unicode(), 4, 16, QChar('0'));
// give up, synergy probably won't handle this
QString KeySequence::keyToString(int key) {
// nothing there?
if (key == 0)
return "";
// a hack to handle mouse buttons as if they were keys
if (key < Qt::Key_Space) {
switch (key) {
case Qt::LeftButton:
return "1";
case Qt::RightButton:
return "2";
case Qt::MidButton:
return "3";
}
return "4"; // qt only knows three mouse buttons, so assume it's an unknown
// fourth one
}
// modifiers?
if (key & Qt::ShiftModifier)
return "Shift";
if (key & Qt::ControlModifier)
return "Control";
if (key & Qt::AltModifier)
return "Alt";
if (key & Qt::MetaModifier)
return "Meta";
// treat key pad like normal keys (FIXME: we should have another lookup table
// for keypad keys instead)
key &= ~Qt::KeypadModifier;
// a printable 7 bit character?
if (key < 0x80 && key != Qt::Key_Space)
return QChar(key & 0x7f).toLower();
// a function key?
if (key >= Qt::Key_F1 && key <= Qt::Key_F35)
return QString::fromUtf8("F%1").arg(key - Qt::Key_F1 + 1);
// a special key?
int i = 0;
while (keyname[i].name) {
if (key == keyname[i].key)
return QString::fromUtf8(keyname[i].name);
i++;
}
// representable in ucs2?
if (key < 0x10000)
return QString("\\u%1").arg(QChar(key).toLower().unicode(), 4, 16,
QChar('0'));
// give up, synergy 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;
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -25,36 +25,34 @@
class QSettings;
class KeySequence
{
public:
KeySequence();
class KeySequence {
public:
KeySequence();
public:
QString toString() const;
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; }
void saveSettings(QSettings& settings) const;
void loadSettings(QSettings& settings);
const QList<int>& sequence() const { return m_Sequence; }
public:
QString toString() const;
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; }
void saveSettings(QSettings &settings) const;
void loadSettings(QSettings &settings);
const QList<int> &sequence() const { return m_Sequence; }
bool operator==(const KeySequence& ks) const;
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; }
private:
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;
int m_Modifiers;
bool m_IsValid;
private:
QList<int> m_Sequence;
int m_Modifiers;
bool m_IsValid;
static QString keyToString(int key);
static QString keyToString(int key);
};
#endif

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -18,128 +18,110 @@
#include "KeySequenceWidget.h"
#include <iostream>
#include <QMouseEvent>
#include <iostream>
KeySequenceWidget::KeySequenceWidget(QWidget* parent, const KeySequence& seq) :
QPushButton(parent),
m_KeySequence(seq),
m_BackupSequence(seq),
m_Status(Stopped),
m_MousePrefix("mousebutton("),
m_MousePostfix(")"),
m_KeyPrefix("keystroke("),
m_KeyPostfix(")")
{
setFocusPolicy(Qt::NoFocus);
KeySequenceWidget::KeySequenceWidget(QWidget *parent, const KeySequence &seq)
: QPushButton(parent), m_KeySequence(seq), m_BackupSequence(seq),
m_Status(Stopped), m_MousePrefix("mousebutton("), m_MousePostfix(")"),
m_KeyPrefix("keystroke("), m_KeyPostfix(")") {
setFocusPolicy(Qt::NoFocus);
updateOutput();
}
void KeySequenceWidget::setKeySequence(const KeySequence &seq) {
keySequence() = seq;
backupSequence() = seq;
setStatus(Stopped);
updateOutput();
}
void KeySequenceWidget::mousePressEvent(QMouseEvent *event) {
event->accept();
if (status() == Stopped) {
startRecording();
return;
}
if (m_KeySequence.appendMouseButton(event->button()))
stopRecording();
updateOutput();
}
void KeySequenceWidget::startRecording() {
keySequence() = KeySequence();
setDown(true);
setFocus();
grabKeyboard();
setStatus(Recording);
}
void KeySequenceWidget::stopRecording() {
if (!keySequence().valid()) {
keySequence() = backupSequence();
updateOutput();
}
setDown(false);
focusNextChild();
releaseKeyboard();
setStatus(Stopped);
emit keySequenceChanged();
}
void KeySequenceWidget::setKeySequence(const KeySequence& seq)
{
keySequence() = seq;
backupSequence() = seq;
bool KeySequenceWidget::event(QEvent *event) {
if (status() == Recording) {
switch (event->type()) {
case QEvent::KeyPress:
keyPressEvent(static_cast<QKeyEvent *>(event));
return true;
setStatus(Stopped);
updateOutput();
}
case QEvent::MouseButtonRelease:
event->accept();
return true;
void KeySequenceWidget::mousePressEvent(QMouseEvent* event)
{
event->accept();
case QEvent::ShortcutOverride:
event->accept();
return true;
if (status() == Stopped)
{
startRecording();
return;
}
if (m_KeySequence.appendMouseButton(event->button()))
stopRecording();
updateOutput();
}
void KeySequenceWidget::startRecording()
{
keySequence() = KeySequence();
setDown(true);
setFocus();
grabKeyboard();
setStatus(Recording);
}
void KeySequenceWidget::stopRecording()
{
if (!keySequence().valid())
{
case QEvent::FocusOut:
stopRecording();
if (!valid()) {
keySequence() = backupSequence();
updateOutput();
}
break;
default:
break;
}
}
setDown(false);
focusNextChild();
releaseKeyboard();
setStatus(Stopped);
emit keySequenceChanged();
return QPushButton::event(event);
}
bool KeySequenceWidget::event(QEvent* event)
{
if (status() == Recording)
{
switch(event->type())
{
case QEvent::KeyPress:
keyPressEvent(static_cast<QKeyEvent*>(event));
return true;
void KeySequenceWidget::keyPressEvent(QKeyEvent *event) {
event->accept();
case QEvent::MouseButtonRelease:
event->accept();
return true;
if (status() == Stopped)
return;
case QEvent::ShortcutOverride:
event->accept();
return true;
if (m_KeySequence.appendKey(event->key(), event->modifiers()))
stopRecording();
case QEvent::FocusOut:
stopRecording();
if (!valid())
{
keySequence() = backupSequence();
updateOutput();
}
break;
default:
break;
}
}
return QPushButton::event(event);
updateOutput();
}
void KeySequenceWidget::keyPressEvent(QKeyEvent* event)
{
event->accept();
void KeySequenceWidget::updateOutput() {
QString s;
if (status() == Stopped)
return;
if (m_KeySequence.isMouseButton())
s = mousePrefix() + m_KeySequence.toString() + mousePostfix();
else
s = keyPrefix() + m_KeySequence.toString() + keyPostfix();
if (m_KeySequence.appendKey(event->key(), event->modifiers()))
stopRecording();
updateOutput();
}
void KeySequenceWidget::updateOutput()
{
QString s;
if (m_KeySequence.isMouseButton())
s = mousePrefix() + m_KeySequence.toString() + mousePostfix();
else
s = keyPrefix() + m_KeySequence.toString() + keyPostfix();
setText(s);
setText(s);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -24,58 +24,56 @@
#include "KeySequence.h"
class KeySequenceWidget : public QPushButton
{
Q_OBJECT
class KeySequenceWidget : public QPushButton {
Q_OBJECT
public:
KeySequenceWidget(QWidget* parent, const KeySequence& seq = KeySequence());
public:
KeySequenceWidget(QWidget *parent, const KeySequence &seq = KeySequence());
signals:
void keySequenceChanged();
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; }
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; }
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; }
void setKeySequence(const KeySequence& seq);
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*);
void keyPressEvent(QKeyEvent*);
bool event(QEvent* event);
void appendToSequence(int key);
void updateOutput();
void startRecording();
void stopRecording();
KeySequence& keySequence() { return m_KeySequence; }
KeySequence& backupSequence() { return m_BackupSequence; }
protected:
void mousePressEvent(QMouseEvent *);
void keyPressEvent(QKeyEvent *);
bool event(QEvent *event);
void appendToSequence(int key);
void updateOutput();
void startRecording();
void stopRecording();
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; }
private:
enum Status { Stopped, Recording };
void setStatus(Status s) { m_Status = s; }
Status status() const { return m_Status; }
private:
KeySequence m_KeySequence;
KeySequence m_BackupSequence;
Status m_Status;
QString m_MousePrefix;
QString m_MousePostfix;
QString m_KeyPrefix;
QString m_KeyPostfix;
private:
KeySequence m_KeySequence;
KeySequence m_BackupSequence;
Status m_Status;
QString m_MousePrefix;
QString m_MousePostfix;
QString m_KeyPrefix;
QString m_KeyPostfix;
};
#endif

View file

@ -17,255 +17,218 @@
#include "LicenseManager.h"
#include "AppConfig.h"
#include <QDateTime>
#include <QLocale>
#include <QThread>
#include <QTimer>
#include <ctime>
#include <stdexcept>
#include <utility>
#include <QThread>
#include <QTimer>
#include <QDateTime>
#include <QLocale>
namespace {
std::string
getMaintenanceMessage(const SerialKey& serialKey)
{
auto expiration = QDateTime::fromTime_t(serialKey.getExpiration()).date();
QString message = "The license key you used will only work with versions of Synergy released before %1."
"<p>To use this version, you’ll need to renew your Synergy maintenance license. "
"<a href=\"https://symless.com/synergy/account?source=gui\""
"style=\"text-decoration: none; color: #4285F4;\">Renew today</a>.</p>";
auto formatedDate = QLocale("en_US").toString(expiration, "MMM dd yyyy");
return message.arg(formatedDate).toStdString();
std::string getMaintenanceMessage(const SerialKey &serialKey) {
auto expiration = QDateTime::fromTime_t(serialKey.getExpiration()).date();
QString message =
"The license key you used will only work with versions of Synergy "
"released before %1."
"<p>To use this version, you’ll need to renew your Synergy maintenance "
"license. "
"<a href=\"https://symless.com/synergy/account?source=gui\""
"style=\"text-decoration: none; color: #4285F4;\">Renew today</a>.</p>";
auto formatedDate = QLocale("en_US").toString(expiration, "MMM dd yyyy");
return message.arg(formatedDate).toStdString();
}
void
checkSerialKey(const SerialKey& serialKey, bool acceptExpired)
{
if (serialKey.isMaintenance()) {
auto buildDate = QDateTime::fromString(__TIMESTAMP__).toTime_t();
void checkSerialKey(const SerialKey &serialKey, bool acceptExpired) {
if (serialKey.isMaintenance()) {
auto buildDate = QDateTime::fromString(__TIMESTAMP__).toTime_t();
if (buildDate > serialKey.getExpiration()) {
throw std::runtime_error(getMaintenanceMessage(serialKey));
}
if (buildDate > serialKey.getExpiration()) {
throw std::runtime_error(getMaintenanceMessage(serialKey));
}
}
if (!acceptExpired && serialKey.isExpired(::time(nullptr))) {
throw std::runtime_error("Serial key expired");
if (!acceptExpired && serialKey.isExpired(::time(nullptr))) {
throw std::runtime_error("Serial key expired");
}
#ifdef SYNERGY_BUSINESS
if (!serialKey.isValid()) {
throw std::runtime_error("The serial key is not compatible with the "
"business version of Synergy.");
}
#endif
}
} // namespace
LicenseManager::LicenseManager(AppConfig *appConfig)
: m_AppConfig(appConfig), m_serialKey(appConfig->edition()),
m_registry(*appConfig) {}
void LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired) {
checkSerialKey(serialKey, acceptExpired);
if (serialKey != m_serialKey) {
using std::swap;
swap(serialKey, m_serialKey);
m_AppConfig->setSerialKey(QString::fromStdString(m_serialKey.toString()));
emit showLicenseNotice(getLicenseNotice());
validateSerialKey();
m_registry.scheduleRegistration();
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition(m_serialKey.edition());
emit editionChanged(m_serialKey.edition());
}
}
}
#ifdef SYNERGY_BUSINESS
if (!serialKey.isValid()) {
throw std::runtime_error("The serial key is not compatible with the business version of Synergy.");
void LicenseManager::notifyUpdate(QString fromVersion,
QString toVersion) const {
if ((fromVersion == "Unknown") && (m_serialKey == SerialKey(kUnregistered))) {
return;
}
ActivationNotifier *notifier = new ActivationNotifier();
notifier->setUpdateInfo(fromVersion, toVersion,
QString::fromStdString(m_serialKey.toString()));
QThread *thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
notifier->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(notifier, "notifyUpdate", Qt::QueuedConnection);
}
Edition LicenseManager::activeEdition() const { return m_serialKey.edition(); }
QString LicenseManager::activeEditionName() const {
return getEditionName(activeEdition(), m_serialKey.isTrial());
}
const SerialKey &LicenseManager::serialKey() const { return m_serialKey; }
void LicenseManager::refresh() {
if (!m_AppConfig->serialKey().isEmpty()) {
try {
SerialKey serialKey(m_AppConfig->serialKey().toStdString());
setSerialKey(serialKey, true);
} catch (...) {
m_serialKey = SerialKey();
m_AppConfig->clearSerialKey();
}
#endif
}
if (!m_serialKey.isValid()) {
emit InvalidLicense();
}
}
void LicenseManager::skipActivation() const {
notifyActivation("skip:unknown");
}
QString LicenseManager::getEditionName(Edition const edition, bool trial) {
SerialKeyEdition KeyEdition(edition);
std::string name = KeyEdition.getDisplayName();
LicenseManager::LicenseManager(AppConfig* appConfig) :
m_AppConfig(appConfig),
m_serialKey(appConfig->edition()),
m_registry(*appConfig) {
if (trial) {
name += " (Trial)";
}
return QString::fromUtf8(name.c_str(), static_cast<int>(name.size()));
}
void
LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
{
checkSerialKey(serialKey, acceptExpired);
void LicenseManager::notifyActivation(QString identity) const {
ActivationNotifier *notifier = new ActivationNotifier();
notifier->setIdentity(identity);
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey(QString::fromStdString
(m_serialKey.toString()));
QThread *thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
emit showLicenseNotice(getLicenseNotice());
validateSerialKey();
m_registry.scheduleRegistration();
notifier->moveToThread(thread);
thread->start();
if (m_serialKey.edition() != serialKey.edition()) {
m_AppConfig->setEdition(m_serialKey.edition());
emit editionChanged(m_serialKey.edition());
}
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
}
QString LicenseManager::getLicenseNotice() const {
QString Notice;
if (m_serialKey.isTemporary()) {
if (m_serialKey.isTrial()) {
Notice = getTrialNotice();
} else {
Notice = getTemporaryNotice();
}
}
return Notice;
}
void
LicenseManager::notifyUpdate(QString fromVersion, QString toVersion) const {
if ((fromVersion == "Unknown")
&& (m_serialKey == SerialKey(kUnregistered))) {
return;
}
ActivationNotifier* notifier = new ActivationNotifier();
notifier->setUpdateInfo (fromVersion, toVersion,
QString::fromStdString(m_serialKey.toString()));
QThread* thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
notifier->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(notifier, "notifyUpdate",
Qt::QueuedConnection);
}
Edition
LicenseManager::activeEdition() const
{
return m_serialKey.edition();
}
QString
LicenseManager::activeEditionName() const
{
return getEditionName(activeEdition(), m_serialKey.isTrial());
}
const SerialKey&
LicenseManager::serialKey() const
{
return m_serialKey;
}
void
LicenseManager::refresh()
{
if (!m_AppConfig->serialKey().isEmpty()) {
try {
SerialKey serialKey (m_AppConfig->serialKey().toStdString());
setSerialKey(serialKey, true);
} catch (...) {
m_serialKey = SerialKey();
m_AppConfig->clearSerialKey();
}
}
if (!m_serialKey.isValid()) {
emit InvalidLicense();
}
}
void
LicenseManager::skipActivation() const
{
notifyActivation ("skip:unknown");
}
QString
LicenseManager::getEditionName(Edition const edition, bool trial)
{
SerialKeyEdition KeyEdition(edition);
std::string name = KeyEdition.getDisplayName();
if (trial) {
name += " (Trial)";
}
return QString::fromUtf8 (name.c_str(), static_cast<int>(name.size()));
}
void
LicenseManager::notifyActivation(QString identity) const
{
ActivationNotifier* notifier = new ActivationNotifier();
notifier->setIdentity(identity);
QThread* thread = new QThread();
connect(notifier, SIGNAL(finished()), thread, SLOT(quit()));
connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
notifier->moveToThread(thread);
thread->start();
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
}
QString
LicenseManager::getLicenseNotice() const
{
QString Notice;
if (m_serialKey.isTemporary()){
if (m_serialKey.isTrial()){
Notice = getTrialNotice();
}
else{
Notice = getTemporaryNotice();
}
}
return Notice;
}
void
LicenseManager::registerLicense()
{
m_registry.registerLicense();
}
QString
LicenseManager::getTrialNotice() const
{
QString Notice;
if (m_serialKey.isExpired(::time(0))){
Notice = "<html><head/><body><p>"
"Trial expired - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" style=\"color: #FFFFFF;\">Buy now</a>"
"</p></body></html>";
}
else{
Notice = "<html><head/><body><p>"
"Trial expires in %1 day%2 - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" style=\"color: #FFFFFF;\">Buy now</a>"
"</p></body></html>";
time_t daysLeft = m_serialKey.daysLeft(::time(0));
Notice = Notice.arg (daysLeft).arg ((daysLeft == 1) ? "" : "s");
}
return Notice;
}
QString
LicenseManager::getTemporaryNotice() const
{
QString Notice;
if (m_serialKey.isExpired(::time(0))) {
Notice = "<html><head/><body><p>"
"License expired - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" style=\"color: #FFFFFF;\">Renew now</a>"
"</p></body></html>";
}
else if (m_serialKey.isExpiring(::time(0))) {
Notice = "<html><head/><body><p>"
"License expires in %1 day%2 - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" style=\"color: #FFFFFF;\">Renew now</a>"
"</p></body></html>";
time_t daysLeft = m_serialKey.daysLeft(::time(0));
Notice = Notice.arg (daysLeft).arg ((daysLeft == 1) ? "" : "s");
}
return Notice;
}
void
LicenseManager::validateSerialKey() const
{
if (m_serialKey.isValid()) {
if (m_serialKey.isTemporary()){
QTimer::singleShot(m_serialKey.getSpanLeft(), this, SLOT(validateSerialKey()));
}
}
else{
emit InvalidLicense();
void LicenseManager::registerLicense() { m_registry.registerLicense(); }
QString LicenseManager::getTrialNotice() const {
QString Notice;
if (m_serialKey.isExpired(::time(0))) {
Notice = "<html><head/><body><p>"
"Trial expired - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" "
"style=\"color: #FFFFFF;\">Buy now</a>"
"</p></body></html>";
} else {
Notice = "<html><head/><body><p>"
"Trial expires in %1 day%2 - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" "
"style=\"color: #FFFFFF;\">Buy now</a>"
"</p></body></html>";
time_t daysLeft = m_serialKey.daysLeft(::time(0));
Notice = Notice.arg(daysLeft).arg((daysLeft == 1) ? "" : "s");
}
return Notice;
}
QString LicenseManager::getTemporaryNotice() const {
QString Notice;
if (m_serialKey.isExpired(::time(0))) {
Notice = "<html><head/><body><p>"
"License expired - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" "
"style=\"color: #FFFFFF;\">Renew now</a>"
"</p></body></html>";
} else if (m_serialKey.isExpiring(::time(0))) {
Notice = "<html><head/><body><p>"
"License expires in %1 day%2 - "
"<a href=\"https://symless.com/synergy/purchase?source=gui\" "
"style=\"color: #FFFFFF;\">Renew now</a>"
"</p></body></html>";
time_t daysLeft = m_serialKey.daysLeft(::time(0));
Notice = Notice.arg(daysLeft).arg((daysLeft == 1) ? "" : "s");
}
return Notice;
}
void LicenseManager::validateSerialKey() const {
if (m_serialKey.isValid()) {
if (m_serialKey.isTemporary()) {
QTimer::singleShot(m_serialKey.getSpanLeft(), this,
SLOT(validateSerialKey()));
}
} else {
emit InvalidLicense();
}
}

View file

@ -17,48 +17,47 @@
#pragma once
#include <ActivationNotifier.h>
#include <QObject>
#include <shared/EditionType.h>
#include <shared/SerialKey.h>
#include <ActivationNotifier.h>
#include <utility>
#include "LicenseRegistry.h"
class AppConfig;
class LicenseManager: public QObject
{
Q_OBJECT
class LicenseManager : public QObject {
Q_OBJECT
public:
LicenseManager(AppConfig* appConfig);
void setSerialKey(SerialKey serialKey, bool acceptExpired = false);
void refresh();
Edition activeEdition() const;
QString activeEditionName() const;
const SerialKey& serialKey() const;
void skipActivation() const;
void notifyUpdate(QString fromVersion, QString toVersion) const;
static QString getEditionName(Edition edition, bool trial = false);
void notifyActivation(QString identity) const;
QString getLicenseNotice() const;
LicenseManager(AppConfig *appConfig);
void setSerialKey(SerialKey serialKey, bool acceptExpired = false);
void refresh();
Edition activeEdition() const;
QString activeEditionName() const;
const SerialKey &serialKey() const;
void skipActivation() const;
void notifyUpdate(QString fromVersion, QString toVersion) const;
static QString getEditionName(Edition edition, bool trial = false);
void notifyActivation(QString identity) const;
QString getLicenseNotice() const;
private:
AppConfig* m_AppConfig;
SerialKey m_serialKey;
LicenseRegistry m_registry;
AppConfig *m_AppConfig;
SerialKey m_serialKey;
LicenseRegistry m_registry;
public slots:
void validateSerialKey() const;
void registerLicense();
void validateSerialKey() const;
void registerLicense();
signals:
void editionChanged (Edition) const;
void InvalidLicense () const;
void showLicenseNotice(const QString& notice) const;
void editionChanged(Edition) const;
void InvalidLicense() const;
void showLicenseNotice(const QString &notice) const;
protected:
QString getTrialNotice() const;
QString getTemporaryNotice() const;
QString getTrialNotice() const;
QString getTemporaryNotice() const;
};

View file

@ -14,92 +14,85 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QNetworkReply>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
#include <QTimer>
#include "LicenseRegistry.h"
#include "AppConfig.h"
#include "LicenseRegistry.h"
#include <QSysInfo>
LicenseRegistry::LicenseRegistry(AppConfig& config) :
m_config(config)
{
connect(&m_timer, SIGNAL(timeout()), this, SLOT(registerLicense()));
LicenseRegistry::LicenseRegistry(AppConfig &config) : m_config(config) {
connect(&m_timer, SIGNAL(timeout()), this, SLOT(registerLicense()));
}
void LicenseRegistry::registerLicense()
{
m_timer.stop();
if (m_config.edition() == Edition::kBusiness) {
const auto REGISTER_LICENSE_URL = m_config.getLicenseRegistryUrl();
const auto url = QUrl(REGISTER_LICENSE_URL);
void LicenseRegistry::registerLicense() {
m_timer.stop();
if (m_config.edition() == Edition::kBusiness) {
const auto REGISTER_LICENSE_URL = m_config.getLicenseRegistryUrl();
const auto url = QUrl(REGISTER_LICENSE_URL);
auto request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
auto request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
m_manager.post(request, getRequestData());
connect(&m_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(handleResponse(QNetworkReply*)));
m_manager.post(request, getRequestData());
connect(&m_manager, SIGNAL(finished(QNetworkReply *)), this,
SLOT(handleResponse(QNetworkReply *)));
}
}
void LicenseRegistry::handleResponse(QNetworkReply *reply) {
if (reply) {
const auto HOUR = (60 * 60); // seconds per hour
const auto DAY = (24 * HOUR); // seconds per day
const auto WEEK = (7 * DAY); // seconds per week
const auto currentTimestamp = time(nullptr);
if (reply->error() == QNetworkReply::NoError) {
m_config.setLicenseNextCheck(currentTimestamp + WEEK);
} else {
m_config.setLicenseNextCheck(currentTimestamp + HOUR);
}
scheduleRegistration();
reply->deleteLater();
}
}
void LicenseRegistry::handleResponse(QNetworkReply *reply)
{
if (reply) {
const auto HOUR = (60*60); //seconds per hour
const auto DAY = (24*HOUR);//seconds per day
const auto WEEK = (7*DAY); //seconds per week
const auto currentTimestamp = time(nullptr);
if(reply->error() == QNetworkReply::NoError) {
m_config.setLicenseNextCheck(currentTimestamp + WEEK);
}
else{
m_config.setLicenseNextCheck(currentTimestamp + HOUR);
}
scheduleRegistration();
reply->deleteLater();
}
}
QByteArray LicenseRegistry::getRequestData() const
{
QByteArray LicenseRegistry::getRequestData() const {
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
QString guid(QSysInfo::machineUniqueId());
QString guid(QSysInfo::machineUniqueId());
#else
QString guid;
QString guid;
#endif
QJsonObject data;
if (!guid.isEmpty()) {
data["guid"] = guid;
data["guid_type"] = "system";
}
else {
data["guid"] = m_config.getGuid();
data["guid_type"] = "synergy";
}
QJsonObject data;
if (!guid.isEmpty()) {
data["guid"] = guid;
data["guid_type"] = "system";
} else {
data["guid"] = m_config.getGuid();
data["guid_type"] = "synergy";
}
data["key"] = m_config.serialKey();
data["is_server"] = m_config.getServerGroupChecked();
data["key"] = m_config.serialKey();
data["is_server"] = m_config.getServerGroupChecked();
return QJsonDocument(data).toJson();
return QJsonDocument(data).toJson();
}
void LicenseRegistry::scheduleRegistration()
{
const auto nextCheck = m_config.getLicenseNextCheck();
const auto currentTimestamp = static_cast<unsigned long long>(time(nullptr));
void LicenseRegistry::scheduleRegistration() {
const auto nextCheck = m_config.getLicenseNextCheck();
const auto currentTimestamp = static_cast<unsigned long long>(time(nullptr));
if (currentTimestamp >= nextCheck) {
registerLicense();
}
else {
const auto interval = (nextCheck - currentTimestamp) * 1000; //interval in milliseconds
m_timer.setInterval(static_cast<int>(interval));
m_timer.setSingleShot(true);
m_timer.start();
}
if (currentTimestamp >= nextCheck) {
registerLicense();
} else {
const auto interval =
(nextCheck - currentTimestamp) * 1000; // interval in milliseconds
m_timer.setInterval(static_cast<int>(interval));
m_timer.setSingleShot(true);
m_timer.start();
}
}

View file

@ -16,29 +16,28 @@
*/
#pragma once
#include <QNetworkAccessManager>
#include <QObject>
#include <QTimer>
#include <QNetworkAccessManager>
class QNetworkReply;
class AppConfig;
class LicenseRegistry : public QObject
{
Q_OBJECT
class LicenseRegistry : public QObject {
Q_OBJECT
public:
explicit LicenseRegistry(AppConfig& config);
void scheduleRegistration();
explicit LicenseRegistry(AppConfig &config);
void scheduleRegistration();
public slots:
void registerLicense();
void handleResponse(QNetworkReply *reply);
void registerLicense();
void handleResponse(QNetworkReply *reply);
private:
AppConfig& m_config;
QNetworkAccessManager m_manager;
QTimer m_timer;
AppConfig &m_config;
QNetworkAccessManager m_manager;
QTimer m_timer;
QByteArray getRequestData() const;
QByteArray getRequestData() const;
};

File diff suppressed because it is too large Load diff

View file

@ -19,23 +19,23 @@
#pragma once
#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QSettings>
#include <QProcess>
#include <QThread>
#include <QMutex>
#include <QProcess>
#include <QSettings>
#include <QSystemTrayIcon>
#include <QThread>
#include "ui_MainWindowBase.h"
#include "ActivationDialog.h"
#include "AppConfig.h"
#include "ClientConnection.h"
#include "ConfigWriter.h"
#include "Ipc.h"
#include "IpcClient.h"
#include "ServerConfig.h"
#include "ServerConnection.h"
#include "ClientConnection.h"
#include "AppConfig.h"
#include "VersionChecker.h"
#include "IpcClient.h"
#include "Ipc.h"
#include "ActivationDialog.h"
#include "ConfigWriter.h"
#include "TrayIcon.h"
@ -61,210 +61,203 @@ class SslCertificate;
class LicenseManager;
class Zeroconf;
class MainWindow : public QMainWindow, public Ui::MainWindowBase
{
Q_OBJECT
class MainWindow : public QMainWindow, public Ui::MainWindowBase {
Q_OBJECT
friend class QSynergyApplication;
friend class SetupWizard;
friend class ActivationDialog;
friend class SettingsDialog;
friend class ServerConnection;
friend class ClientConnection;
friend class QSynergyApplication;
friend class SetupWizard;
friend class ActivationDialog;
friend class SettingsDialog;
friend class ServerConnection;
friend class ClientConnection;
public:
enum qSynergyState
{
synergyDisconnected,
synergyConnecting,
synergyConnected,
synergyListening,
synergyPendingRetry
};
public:
enum qSynergyState {
synergyDisconnected,
synergyConnecting,
synergyConnected,
synergyListening,
synergyPendingRetry
};
enum qSynergyType
{
synergyClient,
synergyServer
};
enum qSynergyType { synergyClient, synergyServer };
enum qLevel {
Error,
Info
};
enum qLevel { Error, Info };
enum qRuningState {
kStarted,
kStopped
};
enum qRuningState { kStarted, kStopped };
public:
public:
#ifdef SYNERGY_ENTERPRISE
MainWindow(AppConfig& appConfig);
MainWindow(AppConfig &appConfig);
#else
MainWindow(AppConfig& appConfig,
LicenseManager& licenseManager);
MainWindow(AppConfig &appConfig, LicenseManager &licenseManager);
#endif
~MainWindow();
~MainWindow();
public:
void setVisible(bool visible);
int synergyType() const { return m_pRadioGroupClient->isChecked() ? synergyClient : synergyServer; }
int synergyState() const { return m_SynergyState; }
QString hostname() const { return m_pLineEditHostname->text(); }
QString configFilename();
QString address() const;
QString appPath(const QString& name);
void open();
void clearLog();
VersionChecker& versionChecker() { return m_VersionChecker; }
ServerConfig& serverConfig() { return m_ServerConfig; }
void showConfigureServer(const QString& message);
void showConfigureServer() { showConfigureServer(""); }
void autoAddScreen(const QString name);
void addZeroconfServer(const QString name);
Zeroconf& zeroconf() { return *m_pZeroconf; }
public:
void setVisible(bool visible);
int synergyType() const {
return m_pRadioGroupClient->isChecked() ? synergyClient : synergyServer;
}
int synergyState() const { return m_SynergyState; }
QString hostname() const { return m_pLineEditHostname->text(); }
QString configFilename();
QString address() const;
QString appPath(const QString &name);
void open();
void clearLog();
VersionChecker &versionChecker() { return m_VersionChecker; }
ServerConfig &serverConfig() { return m_ServerConfig; }
void showConfigureServer(const QString &message);
void showConfigureServer() { showConfigureServer(""); }
void autoAddScreen(const QString name);
void addZeroconfServer(const QString name);
Zeroconf &zeroconf() { return *m_pZeroconf; }
#ifndef SYNERGY_ENTERPRISE
LicenseManager& licenseManager() const;
int raiseActivationDialog();
LicenseManager &licenseManager() const;
int raiseActivationDialog();
#endif
void updateZeroconfService();
void updateZeroconfService();
public slots:
void setEdition(Edition edition);
void setEdition(Edition edition);
#ifndef SYNERGY_ENTERPRISE
void InvalidLicense();
void showLicenseNotice(const QString& message);
void InvalidLicense();
void showLicenseNotice(const QString &message);
#endif
void appendLogRaw(const QString& text);
void appendLogInfo(const QString& text);
void appendLogDebug(const QString& text);
void appendLogError(const QString& text);
void startSynergy();
void retryStart(); // If the connection failed this will retry a startSynergy
void actionStart();
void handleIdleService(const QString& text);
void appendLogRaw(const QString &text);
void appendLogInfo(const QString &text);
void appendLogDebug(const QString &text);
void appendLogError(const QString &text);
void startSynergy();
void retryStart(); // If the connection failed this will retry a startSynergy
void actionStart();
void handleIdleService(const QString &text);
protected slots:
void updateLocalFingerprint();
void updateScreenName();
void on_m_pRadioGroupServer_clicked(bool);
void on_m_pRadioGroupClient_clicked(bool);
void on_m_pButtonConfigureServer_clicked();
bool on_m_pActionSave_triggered();
void on_m_pActionAbout_triggered();
void on_m_pActionHelp_triggered();
void on_m_pActionSettings_triggered();
void on_m_pActivate_triggered();
void synergyFinished(int exitCode, QProcess::ExitStatus);
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void stopSynergy();
void logOutput();
void logError();
void updateFound(const QString& version);
void saveSettings();
protected slots:
void updateLocalFingerprint();
void updateScreenName();
void on_m_pRadioGroupServer_clicked(bool);
void on_m_pRadioGroupClient_clicked(bool);
void on_m_pButtonConfigureServer_clicked();
bool on_m_pActionSave_triggered();
void on_m_pActionAbout_triggered();
void on_m_pActionHelp_triggered();
void on_m_pActionSettings_triggered();
void on_m_pActivate_triggered();
void synergyFinished(int exitCode, QProcess::ExitStatus);
void trayActivated(QSystemTrayIcon::ActivationReason reason);
void stopSynergy();
void logOutput();
void logError();
void updateFound(const QString &version);
void saveSettings();
/// @brief Receives the signal that the auto config option has changed
void zeroConfToggled();
/// @brief Receives the signal that the auto config option has changed
void zeroConfToggled();
protected:
// TODO This should be properly using the ConfigWriter system.
QSettings& settings() { return GUI::Config::ConfigWriter::make()->settings(); }
AppConfig& appConfig() { return *m_AppConfig; }
AppConfig const& appConfig() const { return *m_AppConfig; }
QProcess* synergyProcess() { return m_pSynergy; }
void setSynergyProcess(QProcess* p) { m_pSynergy = p; }
void initConnections();
void createMenuBar();
void createStatusBar();
void createTrayIcon();
void loadSettings();
void setIcon(qSynergyState state) const;
void setSynergyState(qSynergyState state);
bool checkForApp(int which, QString& app);
bool clientArgs(QStringList& args, QString& app);
bool serverArgs(QStringList& args, QString& app);
void setStatus(const QString& status);
void sendIpcMessage(qIpcMessageType type, const char* buffer, bool showErrors);
void updateFromLogLine(const QString& line);
QString getIPAddresses();
void stopService();
void stopDesktop();
void changeEvent(QEvent* event);
void retranslateMenuBar();
void enableServer(bool enable);
void enableClient(bool enable);
void closeEvent(QCloseEvent* event) override;
protected:
// TODO This should be properly using the ConfigWriter system.
QSettings &settings() {
return GUI::Config::ConfigWriter::make()->settings();
}
AppConfig &appConfig() { return *m_AppConfig; }
AppConfig const &appConfig() const { return *m_AppConfig; }
QProcess *synergyProcess() { return m_pSynergy; }
void setSynergyProcess(QProcess *p) { m_pSynergy = p; }
void initConnections();
void createMenuBar();
void createStatusBar();
void createTrayIcon();
void loadSettings();
void setIcon(qSynergyState state) const;
void setSynergyState(qSynergyState state);
bool checkForApp(int which, QString &app);
bool clientArgs(QStringList &args, QString &app);
bool serverArgs(QStringList &args, QString &app);
void setStatus(const QString &status);
void sendIpcMessage(qIpcMessageType type, const char *buffer,
bool showErrors);
void updateFromLogLine(const QString &line);
QString getIPAddresses();
void stopService();
void stopDesktop();
void changeEvent(QEvent *event);
void retranslateMenuBar();
void enableServer(bool enable);
void enableClient(bool enable);
void closeEvent(QCloseEvent *event) override;
#if defined(Q_OS_WIN)
bool isServiceRunning(QString name);
bool isServiceRunning(QString name);
#else
bool isServiceRunning();
bool isServiceRunning();
#endif
QString getProfileRootForArg();
void checkConnected(const QString& line);
void checkFingerprint(const QString& line);
void checkSecureSocket(const QString& line);
QString getProfileRootForArg();
void checkConnected(const QString &line);
void checkFingerprint(const QString &line);
void checkSecureSocket(const QString &line);
#ifdef Q_OS_MAC
void checkOSXNotification(const QString& line);
void checkOSXNotification(const QString &line);
#endif
#ifndef SYNERGY_ENTERPRISE
void checkLicense(const QString& line);
void checkLicense(const QString &line);
#endif
QString getTimeStamp();
void restartSynergy();
void proofreadInfo();
QString getTimeStamp();
void restartSynergy();
void proofreadInfo();
void showEvent (QShowEvent*);
void secureSocket(bool secureSocket);
void showEvent(QShowEvent *);
void secureSocket(bool secureSocket);
void windowStateChanged();
void windowStateChanged();
private:
private:
#ifndef SYNERGY_ENTERPRISE
LicenseManager* m_LicenseManager;
bool m_ActivationDialogRunning;
QStringList m_PendingClientNames;
LicenseManager *m_LicenseManager;
bool m_ActivationDialogRunning;
QStringList m_PendingClientNames;
#endif
Zeroconf* m_pZeroconf;
AppConfig* m_AppConfig;
QProcess* m_pSynergy;
int m_SynergyState;
ServerConfig m_ServerConfig;
bool m_AlreadyHidden;
VersionChecker m_VersionChecker;
IpcClient m_IpcClient;
QMenuBar* m_pMenuBar;
QMenu* m_pMenuFile;
QMenu* m_pMenuEdit;
QMenu* m_pMenuWindow;
QMenu* m_pMenuHelp;
QAbstractButton* m_pCancelButton;
TrayIcon m_trayIcon;
qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
bool m_SecureSocket; // brief Is the program running a secure socket protocol (SSL/TLS)
QString m_SecureSocketVersion; // brief Contains the version of the Secure Socket currently active
ServerConnection m_serverConnection;
ClientConnection m_clientConnection;
Zeroconf *m_pZeroconf;
AppConfig *m_AppConfig;
QProcess *m_pSynergy;
int m_SynergyState;
ServerConfig m_ServerConfig;
bool m_AlreadyHidden;
VersionChecker m_VersionChecker;
IpcClient m_IpcClient;
QMenuBar *m_pMenuBar;
QMenu *m_pMenuFile;
QMenu *m_pMenuEdit;
QMenu *m_pMenuWindow;
QMenu *m_pMenuHelp;
QAbstractButton *m_pCancelButton;
TrayIcon m_trayIcon;
qRuningState m_ExpectedRunningState;
QMutex m_StopDesktopMutex;
bool m_SecureSocket; // brief Is the program running a secure socket protocol
// (SSL/TLS)
QString m_SecureSocketVersion; // brief Contains the version of the Secure
// Socket currently active
ServerConnection m_serverConnection;
ClientConnection m_clientConnection;
void updateAutoConfigWidgets();
void updateWindowTitle();
void updateAutoConfigWidgets();
void updateWindowTitle();
private slots:
void on_m_pButtonApply_clicked();
void on_windowShown();
void on_m_pButtonApply_clicked();
void on_windowShown();
void on_m_pLabelComputerName_linkActivated(const QString &link);
void on_m_pLabelFingerprint_linkActivated(const QString& link);
void on_m_pComboServerList_currentIndexChanged(const QString &arg1);
void on_m_pLabelComputerName_linkActivated(const QString &link);
void on_m_pLabelFingerprint_linkActivated(const QString &link);
void on_m_pComboServerList_currentIndexChanged(const QString &arg1);
void on_m_pButtonConnect_clicked();
void on_m_pButtonConnectToClient_clicked();
void on_m_pButtonConnect_clicked();
void on_m_pButtonConnectToClient_clicked();
signals:
void windowShown();
void windowShown();
};

View file

@ -21,15 +21,11 @@
#include <QString>
enum class IconsTheme {
ICONS_DARK,
ICONS_LIGHT,
ICONS_TEMPLATE
};
enum class IconsTheme { ICONS_DARK, ICONS_LIGHT, ICONS_TEMPLATE };
void requestOSXNotificationPermission();
bool isOSXDevelopmentBuild();
bool showOSXNotification(const QString& title, const QString& body);
bool showOSXNotification(const QString &title, const QString &body);
bool isOSXInterfaceStyleDark();
IconsTheme getOSXIconsTheme();

View file

@ -18,11 +18,11 @@
#pragma once
enum qProcessorArch {
kProcessorArchWin32,
kProcessorArchWin64,
kProcessorArchMac32,
kProcessorArchMac64,
kProcessorArchLinux32,
kProcessorArchLinux64,
kProcessorArchUnknown
kProcessorArchWin32,
kProcessorArchWin64,
kProcessorArchMac32,
kProcessorArchMac64,
kProcessorArchLinux32,
kProcessorArchLinux64,
kProcessorArchUnknown
};

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -22,57 +22,44 @@
#include <QtCore>
#include <QtGui>
QSynergyApplication* QSynergyApplication::s_Instance = NULL;
QSynergyApplication *QSynergyApplication::s_Instance = NULL;
QSynergyApplication::QSynergyApplication(int& argc, char** argv) :
QApplication(argc, argv),
m_Translator(NULL)
{
s_Instance = this;
QSynergyApplication::QSynergyApplication(int &argc, char **argv)
: QApplication(argc, argv), m_Translator(NULL) {
s_Instance = this;
QFontDatabase::addApplicationFont(":/res/fonts/Arial.ttf");
QFont Arial("Arial");
Arial.setPixelSize(13);
Arial.setStyleHint(QFont::SansSerif);
setFont(Arial);
QFontDatabase::addApplicationFont(":/res/fonts/Arial.ttf");
QFont Arial("Arial");
Arial.setPixelSize(13);
Arial.setStyleHint(QFont::SansSerif);
setFont(Arial);
}
QSynergyApplication::~QSynergyApplication()
{
QSynergyApplication::~QSynergyApplication() { delete m_Translator; }
void QSynergyApplication::commitData(QSessionManager &) {
foreach (QWidget *widget, topLevelWidgets()) {
MainWindow *mainWindow = qobject_cast<MainWindow *>(widget);
if (mainWindow)
mainWindow->saveSettings();
}
}
QSynergyApplication *QSynergyApplication::getInstance() { return s_Instance; }
void QSynergyApplication::switchTranslator(QString lang) {
if (m_Translator != NULL) {
removeTranslator(m_Translator);
delete m_Translator;
}
QResource locale(":/res/lang/gui_" + lang + ".qm");
m_Translator = new QTranslator();
m_Translator->load(locale.data(), locale.size());
installTranslator(m_Translator);
}
void QSynergyApplication::commitData(QSessionManager&)
{
foreach(QWidget* widget, topLevelWidgets())
{
MainWindow* mainWindow = qobject_cast<MainWindow*>(widget);
if (mainWindow)
mainWindow->saveSettings();
}
}
QSynergyApplication* QSynergyApplication::getInstance()
{
return s_Instance;
}
void QSynergyApplication::switchTranslator(QString lang)
{
if (m_Translator != NULL)
{
removeTranslator(m_Translator);
delete m_Translator;
}
QResource locale(":/res/lang/gui_" + lang + ".qm");
m_Translator = new QTranslator();
m_Translator->load(locale.data(), locale.size());
installTranslator(m_Translator);
}
void QSynergyApplication::setTranslator(QTranslator* translator)
{
m_Translator = translator;
installTranslator(m_Translator);
void QSynergyApplication::setTranslator(QTranslator *translator) {
m_Translator = translator;
installTranslator(m_Translator);
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -24,24 +24,22 @@
class QSessionManager;
class QSynergyApplication : public QApplication
{
public:
QSynergyApplication(int& argc, char** argv);
~QSynergyApplication();
class QSynergyApplication : public QApplication {
public:
QSynergyApplication(int &argc, char **argv);
~QSynergyApplication();
public:
void commitData(QSessionManager& manager);
void switchTranslator(QString lang);
void setTranslator(QTranslator* translator);
public:
void commitData(QSessionManager &manager);
void switchTranslator(QString lang);
void setTranslator(QTranslator *translator);
static QSynergyApplication* getInstance();
static QSynergyApplication *getInstance();
private:
QTranslator* m_Translator;
private:
QTranslator *m_Translator;
static QSynergyApplication* s_Instance;
static QSynergyApplication *s_Instance;
};
#endif

View file

@ -17,12 +17,12 @@
#include "QUtility.h"
#include "ProcessorArch.h"
#include "CommandProcess.h"
#include "ProcessorArch.h"
#if defined(Q_OS_LINUX)
#include <QProcess>
#include <QFile>
#include <QProcess>
#endif
#if defined(Q_OS_WIN)
@ -30,50 +30,45 @@
#include <Windows.h>
#endif
void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData)
{
for (int i = 0; i < comboBox->count(); ++i)
{
if (comboBox->itemData(i) == itemData)
{
comboBox->setCurrentIndex(i);
return;
}
void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData) {
for (int i = 0; i < comboBox->count(); ++i) {
if (comboBox->itemData(i) == itemData) {
comboBox->setCurrentIndex(i);
return;
}
}
}
QString hash(const QString& string)
{
QByteArray data = string.toUtf8();
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
return hash.toHex();
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);
SYSTEM_INFO systemInfo;
GetNativeSystemInfo(&systemInfo);
switch (systemInfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_INTEL:
return kProcessorArchWin32;
case PROCESSOR_ARCHITECTURE_IA64:
return kProcessorArchWin64;
case PROCESSOR_ARCHITECTURE_AMD64:
return kProcessorArchWin64;
default:
return kProcessorArchUnknown;
}
switch (systemInfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_INTEL:
return kProcessorArchWin32;
case PROCESSOR_ARCHITECTURE_IA64:
return kProcessorArchWin64;
case PROCESSOR_ARCHITECTURE_AMD64:
return kProcessorArchWin64;
default:
return kProcessorArchUnknown;
}
#endif
#if defined(Q_OS_LINUX)
#ifdef __i386__
return kProcessorArchLinux32;
return kProcessorArchLinux32;
#else
return kProcessorArchLinux64;
return kProcessorArchLinux64;
#endif
#endif
return kProcessorArchUnknown;
return kProcessorArchUnknown;
}

View file

@ -20,10 +20,10 @@
#include "ProcessorArch.h"
#include <QComboBox>
#include <QVariant>
#include <QCryptographicHash>
#include <QNetworkInterface>
#include <QVariant>
void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData);
QString hash(const QString& string);
void setIndexFromItemData(QComboBox *comboBox, const QVariant &itemData);
QString hash(const QString &string);
qProcessorArch getProcessorArch();

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -21,141 +21,124 @@
#include <QtCore>
#include <QtGui>
Screen::Screen() :
m_Pixmap(QPixmap(":res/icons/64x64/video-display.png")),
m_Swapped(false)
{
init();
Screen::Screen()
: m_Pixmap(QPixmap(":res/icons/64x64/video-display.png")),
m_Swapped(false) {
init();
}
Screen::Screen(const QString& name) :
m_Pixmap(QPixmap(":res/icons/64x64/video-display.png")),
m_Swapped(false)
{
init();
setName(name);
Screen::Screen(const QString &name)
: m_Pixmap(QPixmap(":res/icons/64x64/video-display.png")),
m_Swapped(false) {
init();
setName(name);
}
void Screen::init()
{
name().clear();
aliases().clear();
modifiers().clear();
switchCorners().clear();
fixes().clear();
setSwitchCornerSize(0);
void Screen::init() {
name().clear();
aliases().clear();
modifiers().clear();
switchCorners().clear();
fixes().clear();
setSwitchCornerSize(0);
// m_Modifiers, m_SwitchCorners and m_Fixes are QLists we use like fixed-size arrays,
// thus we need to make sure to fill them with the required number of elements.
for (int i = 0; i < NumModifiers; i++)
modifiers() << i;
// m_Modifiers, m_SwitchCorners and m_Fixes are QLists we use like fixed-size
// arrays, thus we need to make sure to fill them with the required number of
// elements.
for (int i = 0; i < NumModifiers; i++)
modifiers() << i;
for (int i = 0; i < NumSwitchCorners; i++)
switchCorners() << false;
for (int i = 0; i < NumSwitchCorners; i++)
switchCorners() << false;
for (int i = 0; i < NumFixes; i++)
fixes() << false;
for (int i = 0; i < NumFixes; i++)
fixes() << false;
}
void Screen::loadSettings(QSettings& settings)
{
setName(settings.value("name").toString());
void Screen::loadSettings(QSettings &settings) {
setName(settings.value("name").toString());
if (name().isEmpty())
return;
if (name().isEmpty())
return;
setSwitchCornerSize(settings.value("switchCornerSize").toInt());
setSwitchCornerSize(settings.value("switchCornerSize").toInt());
readSettings(settings, aliases(), "alias", QString(""));
readSettings(settings, modifiers(), "modifier", static_cast<int>(DefaultMod), NumModifiers);
readSettings(settings, switchCorners(), "switchCorner", false, NumSwitchCorners);
readSettings(settings, fixes(), "fix", false, NumFixes);
readSettings(settings, aliases(), "alias", QString(""));
readSettings(settings, modifiers(), "modifier", static_cast<int>(DefaultMod),
NumModifiers);
readSettings(settings, switchCorners(), "switchCorner", false,
NumSwitchCorners);
readSettings(settings, fixes(), "fix", false, NumFixes);
}
void Screen::saveSettings(QSettings& settings) const
{
settings.setValue("name", name());
void Screen::saveSettings(QSettings &settings) const {
settings.setValue("name", name());
if (name().isEmpty())
return;
if (name().isEmpty())
return;
settings.setValue("switchCornerSize", switchCornerSize());
settings.setValue("switchCornerSize", switchCornerSize());
writeSettings(settings, aliases(), "alias");
writeSettings(settings, modifiers(), "modifier");
writeSettings(settings, switchCorners(), "switchCorner");
writeSettings(settings, fixes(), "fix");
writeSettings(settings, aliases(), "alias");
writeSettings(settings, modifiers(), "modifier");
writeSettings(settings, switchCorners(), "switchCorner");
writeSettings(settings, fixes(), "fix");
}
QTextStream& Screen::writeScreensSection(QTextStream& outStream) const
{
QTextStream &Screen::writeScreensSection(QTextStream &outStream) const {
outStream << "\t" << name() << ":" << endl;
for (int i = 0; i < modifiers().size(); i++)
if (modifier(i) != i)
outStream << "\t\t" << modifierName(i) << " = "
<< modifierName(modifier(i)) << endl;
for (int i = 0; i < fixes().size(); i++)
outStream << "\t\t" << fixName(i) << " = "
<< (fixes()[i] ? "true" : "false") << endl;
outStream << "\t\t"
<< "switchCorners = none ";
for (int i = 0; i < switchCorners().size(); i++)
if (switchCorners()[i])
outStream << "+" << switchCornerName(i) << " ";
outStream << endl;
outStream << "\t\t"
<< "switchCornerSize = " << switchCornerSize() << endl;
return outStream;
}
QTextStream &Screen::writeAliasesSection(QTextStream &outStream) const {
if (!aliases().isEmpty()) {
outStream << "\t" << name() << ":" << endl;
for (int i = 0; i < modifiers().size(); i++)
if (modifier(i) != i)
outStream << "\t\t" << modifierName(i) << " = " << modifierName(modifier(i)) << endl;
foreach (const QString &alias, aliases())
outStream << "\t\t" << alias << endl;
}
for (int i = 0; i < fixes().size(); i++)
outStream << "\t\t" << fixName(i) << " = " << (fixes()[i] ? "true" : "false") << endl;
outStream << "\t\t" << "switchCorners = none ";
for (int i = 0; i < switchCorners().size(); i++)
if (switchCorners()[i])
outStream << "+" << switchCornerName(i) << " ";
outStream << endl;
outStream << "\t\t" << "switchCornerSize = " << switchCornerSize() << endl;
return outStream;
return outStream;
}
QTextStream& Screen::writeAliasesSection(QTextStream& outStream) const
{
if (!aliases().isEmpty())
{
outStream << "\t" << name() << ":" << endl;
foreach (const QString& alias, aliases())
outStream << "\t\t" << alias << endl;
}
return outStream;
bool Screen::operator==(const Screen &screen) const {
return m_Name == screen.m_Name && m_Aliases == screen.m_Aliases &&
m_Modifiers == screen.m_Modifiers &&
m_SwitchCorners == screen.m_SwitchCorners &&
m_SwitchCornerSize == screen.m_SwitchCornerSize &&
m_Fixes == screen.m_Fixes && m_Swapped == screen.m_Swapped &&
m_isServer == screen.m_isServer;
}
bool Screen::operator==(const Screen& screen) const
{
return m_Name == screen.m_Name &&
m_Aliases == screen.m_Aliases &&
m_Modifiers == screen.m_Modifiers &&
m_SwitchCorners == screen.m_SwitchCorners &&
m_SwitchCornerSize == screen.m_SwitchCornerSize &&
m_Fixes == screen.m_Fixes &&
m_Swapped == screen.m_Swapped &&
m_isServer == screen.m_isServer;
QDataStream &operator<<(QDataStream &outStream, const Screen &screen) {
return outStream << screen.name() << screen.switchCornerSize()
<< screen.aliases() << screen.modifiers()
<< screen.switchCorners() << screen.fixes()
<< screen.isServer();
}
QDataStream& operator<<(QDataStream& outStream, const Screen& screen)
{
return outStream
<< screen.name()
<< screen.switchCornerSize()
<< screen.aliases()
<< screen.modifiers()
<< screen.switchCorners()
<< screen.fixes()
<< screen.isServer()
;
}
QDataStream& operator>>(QDataStream& inStream, Screen& screen)
{
return inStream
>> screen.m_Name
>> screen.m_SwitchCornerSize
>> screen.m_Aliases
>> screen.m_Modifiers
>> screen.m_SwitchCorners
>> screen.m_Fixes
>> screen.m_isServer
;
QDataStream &operator>>(QDataStream &inStream, Screen &screen) {
return inStream >> screen.m_Name >> screen.m_SwitchCornerSize >>
screen.m_Aliases >> screen.m_Modifiers >> screen.m_SwitchCorners >>
screen.m_Fixes >> screen.m_isServer;
}

View file

@ -2,11 +2,11 @@
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
*
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -20,9 +20,9 @@
#define SCREEN__H
#include <QList>
#include <QPixmap>
#include <QString>
#include <QList>
#include <QStringList>
#include "BaseConfig.h"
@ -32,75 +32,75 @@ class QTextStream;
class ScreenSettingsDialog;
class Screen : public BaseConfig
{
friend QDataStream& operator<<(QDataStream& outStream, const Screen& screen);
friend QDataStream& operator>>(QDataStream& inStream, Screen& screen);
friend class ScreenSettingsDialog;
friend class ScreenSetupModel;
friend class ScreenSetupView;
class Screen : public BaseConfig {
friend QDataStream &operator<<(QDataStream &outStream, const Screen &screen);
friend QDataStream &operator>>(QDataStream &inStream, Screen &screen);
friend class ScreenSettingsDialog;
friend class ScreenSetupModel;
friend class ScreenSetupView;
public:
Screen();
Screen(const QString& name);
public:
Screen();
Screen(const QString &name);
public:
const QPixmap& pixmap() const { return m_Pixmap; }
const QString& name() const { return m_Name; }
const QStringList& aliases() const { return m_Aliases; }
public:
const QPixmap &pixmap() const { return m_Pixmap; }
const QString &name() const { return m_Name; }
const QStringList &aliases() const { return m_Aliases; }
bool isNull() const { return m_Name.isEmpty(); }
int modifier(int m) const { return m_Modifiers[m] == DefaultMod ? m : m_Modifiers[m]; }
const QList<int>& modifiers() const { return m_Modifiers; }
bool switchCorner(int c) const { return m_SwitchCorners[c]; }
const QList<bool>& switchCorners() const { return m_SwitchCorners; }
int switchCornerSize() const { return m_SwitchCornerSize; }
bool fix(Fix f) const { return m_Fixes[f]; }
const QList<bool>& fixes() const { return m_Fixes; }
bool isNull() const { return m_Name.isEmpty(); }
int modifier(int m) const {
return m_Modifiers[m] == DefaultMod ? m : m_Modifiers[m];
}
const QList<int> &modifiers() const { return m_Modifiers; }
bool switchCorner(int c) const { return m_SwitchCorners[c]; }
const QList<bool> &switchCorners() const { return m_SwitchCorners; }
int switchCornerSize() const { return m_SwitchCornerSize; }
bool fix(Fix f) const { return m_Fixes[f]; }
const QList<bool> &fixes() const { return m_Fixes; }
void loadSettings(QSettings& settings);
void saveSettings(QSettings& settings) const;
QTextStream& writeScreensSection(QTextStream& outStream) const;
QTextStream& writeAliasesSection(QTextStream& outStream) const;
void loadSettings(QSettings &settings);
void saveSettings(QSettings &settings) const;
QTextStream &writeScreensSection(QTextStream &outStream) const;
QTextStream &writeAliasesSection(QTextStream &outStream) const;
bool swapped() const { return m_Swapped; }
QString& name() { return m_Name; }
void setName(const QString& name) { m_Name = name; }
bool isServer() const { return m_isServer;}
void markAsServer() { m_isServer = true; }
bool swapped() const { return m_Swapped; }
QString &name() { return m_Name; }
void setName(const QString &name) { m_Name = name; }
bool isServer() const { return m_isServer; }
void markAsServer() { m_isServer = true; }
bool operator==(const Screen& screen) const;
bool operator==(const Screen &screen) const;
protected:
void init();
protected:
void init();
QStringList& aliases() { return m_Aliases; }
void setModifier(int m, int n) { m_Modifiers[m] = n; }
QList<int>& modifiers() { return m_Modifiers; }
void addAlias(const QString& alias) { m_Aliases.append(alias); }
void setSwitchCorner(int c, bool on) { m_SwitchCorners[c] = on; }
QList<bool>& switchCorners() { return m_SwitchCorners; }
void setSwitchCornerSize(int val) { m_SwitchCornerSize = val; }
void setFix(int f, bool on) { m_Fixes[f] = on; }
QList<bool>& fixes() { return m_Fixes; }
void setSwapped(bool on) { m_Swapped = on; }
QStringList &aliases() { return m_Aliases; }
void setModifier(int m, int n) { m_Modifiers[m] = n; }
QList<int> &modifiers() { return m_Modifiers; }
void addAlias(const QString &alias) { m_Aliases.append(alias); }
void setSwitchCorner(int c, bool on) { m_SwitchCorners[c] = on; }
QList<bool> &switchCorners() { return m_SwitchCorners; }
void setSwitchCornerSize(int val) { m_SwitchCornerSize = val; }
void setFix(int f, bool on) { m_Fixes[f] = on; }
QList<bool> &fixes() { return m_Fixes; }
void setSwapped(bool on) { m_Swapped = on; }
private:
QPixmap m_Pixmap;
QString m_Name;
private:
QPixmap m_Pixmap;
QString m_Name;
QStringList m_Aliases;
QList<int> m_Modifiers;
QList<bool> m_SwitchCorners;
int m_SwitchCornerSize;
QList<bool> m_Fixes;
QStringList m_Aliases;
QList<int> m_Modifiers;
QList<bool> m_SwitchCorners;
int m_SwitchCornerSize;
QList<bool> m_Fixes;
bool m_Swapped;
bool m_isServer = false;
bool m_Swapped;
bool m_isServer = false;
};
QDataStream& operator<<(QDataStream& outStream, const Screen& screen);
QDataStream& operator>>(QDataStream& inStream, Screen& screen);
QDataStream &operator<<(QDataStream &outStream, const Screen &screen);
QDataStream &operator>>(QDataStream &inStream, Screen &screen);
#endif

View file

@ -28,33 +28,42 @@ namespace {
* @param size of the grid
* @return indexes for server neighbors
*/
std::array<int, 8> getNeighborsIndexes(int serverIndex, int width, int size)
{
const int UNSET = -1;
const int LEFT = 0;
const int RIGHT = 1;
const int TOP = 2;
const int BOTTOM = 3;
const int TOP_LEFT = 4;
const int TOP_RIGHT = 5;
const int BOTTOM_RIGHT = 6;
const int BOTTOM_LEFT = 7;
std::array<int, 8> getNeighborsIndexes(int serverIndex, int width, int size) {
const int UNSET = -1;
const int LEFT = 0;
const int RIGHT = 1;
const int TOP = 2;
const int BOTTOM = 3;
const int TOP_LEFT = 4;
const int TOP_RIGHT = 5;
const int BOTTOM_RIGHT = 6;
const int BOTTOM_LEFT = 7;
std::array<int, 8> indexes = { UNSET };
std::array<int, 8> indexes = {UNSET};
if (serverIndex >= 0 && serverIndex < size)
{
indexes[LEFT] = (serverIndex - 1) % width != width - 1 ? (serverIndex - 1) : UNSET;
indexes[RIGHT] = (serverIndex + 1) % width != 0 ? (serverIndex + 1) : UNSET;
indexes[TOP] = (serverIndex - width) >= 0 ? (serverIndex - width) : UNSET;
indexes[BOTTOM] = (serverIndex + width) < size ? (serverIndex + width) : UNSET;
indexes[TOP_LEFT] = (indexes[TOP] != UNSET && indexes[LEFT] != UNSET) ? indexes[TOP] - 1 : UNSET;
indexes[TOP_RIGHT] = (indexes[TOP] != UNSET && indexes[RIGHT] != UNSET) ? indexes[TOP] + 1 : UNSET;
indexes[BOTTOM_RIGHT] = (indexes[BOTTOM] != UNSET && indexes[RIGHT] != UNSET) ? indexes[BOTTOM] + 1 : UNSET;
indexes[BOTTOM_LEFT] = (indexes[BOTTOM] != UNSET && indexes[LEFT] != UNSET) ? indexes[BOTTOM] - 1 : UNSET;
}
if (serverIndex >= 0 && serverIndex < size) {
indexes[LEFT] =
(serverIndex - 1) % width != width - 1 ? (serverIndex - 1) : UNSET;
indexes[RIGHT] = (serverIndex + 1) % width != 0 ? (serverIndex + 1) : UNSET;
indexes[TOP] = (serverIndex - width) >= 0 ? (serverIndex - width) : UNSET;
indexes[BOTTOM] =
(serverIndex + width) < size ? (serverIndex + width) : UNSET;
indexes[TOP_LEFT] = (indexes[TOP] != UNSET && indexes[LEFT] != UNSET)
? indexes[TOP] - 1
: UNSET;
indexes[TOP_RIGHT] = (indexes[TOP] != UNSET && indexes[RIGHT] != UNSET)
? indexes[TOP] + 1
: UNSET;
indexes[BOTTOM_RIGHT] =
(indexes[BOTTOM] != UNSET && indexes[RIGHT] != UNSET)
? indexes[BOTTOM] + 1
: UNSET;
indexes[BOTTOM_LEFT] = (indexes[BOTTOM] != UNSET && indexes[LEFT] != UNSET)
? indexes[BOTTOM] - 1
: UNSET;
}
return indexes;
return indexes;
}
/**
@ -62,71 +71,54 @@ std::array<int, 8> getNeighborsIndexes(int serverIndex, int width, int size)
* @param screens list to find server
* @return server index
*/
int getServerIndex(const ScreenList& screens)
{
int serverIndex = -1;
int getServerIndex(const ScreenList &screens) {
int serverIndex = -1;
for (int i = 0; i < screens.size(); ++i)
{
if (screens[i].isServer()){
serverIndex = i;
break;
}
for (int i = 0; i < screens.size(); ++i) {
if (screens[i].isServer()) {
serverIndex = i;
break;
}
}
return serverIndex;
return serverIndex;
}
} //namespace
} // namespace
ScreenList::ScreenList(int width) :
QList<Screen>(),
m_width(width)
{
ScreenList::ScreenList(int width) : QList<Screen>(), m_width(width) {}
}
void ScreenList::addScreenByPriority(const Screen &newScreen) {
int serverIndex = getServerIndex(*this);
auto indexes = getNeighborsIndexes(serverIndex, m_width, size());
void ScreenList::addScreenByPriority(const Screen& newScreen)
{
int serverIndex = getServerIndex(*this);
auto indexes = getNeighborsIndexes(serverIndex, m_width, size());
bool isAdded = false;
for (const auto& index : indexes)
{
if (index >= 0 && index < size())
{
auto& screen = operator[](index);
if (screen.isNull())
{
screen = newScreen;
isAdded = true;
break;
}
}
bool isAdded = false;
for (const auto &index : indexes) {
if (index >= 0 && index < size()) {
auto &screen = operator[](index);
if (screen.isNull()) {
screen = newScreen;
isAdded = true;
break;
}
}
}
if (!isAdded)
{
addScreenToFirstEmpty(newScreen);
if (!isAdded) {
addScreenToFirstEmpty(newScreen);
}
}
void ScreenList::addScreenToFirstEmpty(const Screen &newScreen) {
for (int i = 0; i < size(); ++i) {
auto &screen = operator[](i);
if (screen.isNull()) {
screen = newScreen;
break;
}
}
}
void ScreenList::addScreenToFirstEmpty(const Screen& newScreen)
{
for (int i = 0; i < size(); ++i)
{
auto& screen = operator[](i);
if (screen.isNull())
{
screen = newScreen;
break;
}
}
bool ScreenList::operator==(const ScreenList &sc) const {
return m_width == sc.m_width && QList::operator==(sc);
}
bool ScreenList::operator==(const ScreenList& sc) const
{
return m_width == sc.m_width && QList::operator==(sc);
}

View file

@ -20,39 +20,36 @@
#include "Screen.h"
class ScreenList : public QList<Screen>
{
int m_width = 5;
class ScreenList : public QList<Screen> {
int m_width = 5;
public:
explicit ScreenList(int width = 5);
explicit ScreenList(int width = 5);
/**
* @brief addScreenByPriority adds a new screen according to the following priority:
* 1.left side of the server
* 2.right side of the server
* 3.top
* 4.down
* 5.top left-hand diagonally
* 6.top right-hand diagonally
* 7.bottom right-hand diagonally
* 8.bottom left-hand diagonally
* 9.In case all places from the list have already booked, place in any spare place
* @param newScreen
*/
void addScreenByPriority(const Screen& newScreen);
/**
* @brief addScreenByPriority adds a new screen according to the following
* priority: 1.left side of the server 2.right side of the server 3.top 4.down
* 5.top left-hand diagonally
* 6.top right-hand diagonally
* 7.bottom right-hand diagonally
* 8.bottom left-hand diagonally
* 9.In case all places from the list have already booked, place in any spare
* place
* @param newScreen
*/
void addScreenByPriority(const Screen &newScreen);
/**
* @brief addScreenToFirstEmpty adds screen into the first empty place
* @param newScreen
*/
void addScreenToFirstEmpty(const Screen& newScreen);
/**
* @brief addScreenToFirstEmpty adds screen into the first empty place
* @param newScreen
*/
void addScreenToFirstEmpty(const Screen &newScreen);
/**
* @brief Returns true if screens are equal
* @param sc
*/
bool operator==(const ScreenList& sc) const;
/**
* @brief Returns true if screens are equal
* @param sc
*/
bool operator==(const ScreenList &sc) const;
};
#endif // SCREENLIST_H

Some files were not shown because too many files have changed in this diff Show more