2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* 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
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ServerConfig.h"
|
|
|
|
|
#include "Hotkey.h"
|
2014-08-26 14:49:27 +00:00
|
|
|
#include "MainWindow.h"
|
2014-11-18 11:00:31 +00:00
|
|
|
#include "AddClientDialog.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
#include <QtCore>
|
2014-08-26 14:49:27 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QAbstractButton>
|
|
|
|
|
#include <QPushButton>
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
const char* name;
|
2012-06-10 16:50:54 +00:00
|
|
|
} neighbourDirs[] =
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
{ 1, 0, "right" },
|
|
|
|
|
{ -1, 0, "left" },
|
|
|
|
|
{ 0, -1, "up" },
|
|
|
|
|
{ 0, 1, "down" },
|
2014-08-21 17:32:40 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
2014-08-21 17:32:40 +00:00
|
|
|
const int serverDefaultIndex = 7;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2021-02-22 11:33:18 +00:00
|
|
|
ServerConfig::ServerConfig(int numColumns, int numRows, AppConfig* appConfig, MainWindow* mainWindow) :
|
2020-04-27 12:02:26 +00:00
|
|
|
|
2021-05-18 10:05:59 +00:00
|
|
|
m_Screens(numColumns),
|
2020-02-25 16:32:46 +00:00
|
|
|
m_NumColumns(numColumns),
|
|
|
|
|
m_NumRows(numRows),
|
2021-02-22 11:33:18 +00:00
|
|
|
m_pAppConfig(appConfig),
|
2020-02-25 16:32:46 +00:00
|
|
|
m_IgnoreAutoConfigClient(false),
|
|
|
|
|
m_EnableDragAndDrop(false),
|
|
|
|
|
m_DisableLockToScreen(false),
|
|
|
|
|
m_ClipboardSharing(true),
|
|
|
|
|
m_ClipboardSharingSize(defaultClipboardSharingSize()),
|
|
|
|
|
m_pMainWindow(mainWindow)
|
2012-06-10 16:50:54 +00:00
|
|
|
{
|
2020-04-27 12:02:26 +00:00
|
|
|
GUI::Config::ConfigWriter::make()->registerClass(this);
|
2016-12-28 11:50:32 +00:00
|
|
|
loadSettings();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerConfig::~ServerConfig()
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
saveSettings();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ServerConfig::save(const QString& fileName) const
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
QFile file(fileName);
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
|
return false;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
save(file);
|
|
|
|
|
file.close();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
return true;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-20 12:22:07 +00:00
|
|
|
bool ServerConfig::operator==(const ServerConfig& sc) const
|
|
|
|
|
{
|
|
|
|
|
return m_Screens == sc.m_Screens &&
|
|
|
|
|
m_NumColumns == sc.m_NumColumns &&
|
|
|
|
|
m_NumRows == sc.m_NumRows &&
|
|
|
|
|
m_HasHeartbeat == sc.m_HasHeartbeat &&
|
|
|
|
|
m_Heartbeat == sc.m_Heartbeat &&
|
|
|
|
|
m_RelativeMouseMoves == sc.m_RelativeMouseMoves &&
|
|
|
|
|
m_Win32KeepForeground == sc.m_Win32KeepForeground &&
|
|
|
|
|
m_HasSwitchDelay == sc.m_HasSwitchDelay &&
|
|
|
|
|
m_SwitchDelay == sc.m_SwitchDelay &&
|
|
|
|
|
m_HasSwitchDoubleTap == sc.m_HasSwitchDoubleTap &&
|
|
|
|
|
m_SwitchDoubleTap == sc.m_SwitchDoubleTap &&
|
|
|
|
|
m_SwitchCornerSize == sc.m_SwitchCornerSize &&
|
|
|
|
|
m_SwitchCorners == sc.m_SwitchCorners &&
|
|
|
|
|
m_Hotkeys == sc.m_Hotkeys &&
|
|
|
|
|
m_pAppConfig == sc.m_pAppConfig &&
|
|
|
|
|
m_IgnoreAutoConfigClient == sc.m_IgnoreAutoConfigClient &&
|
|
|
|
|
m_EnableDragAndDrop == sc.m_EnableDragAndDrop &&
|
|
|
|
|
m_DisableLockToScreen == sc.m_DisableLockToScreen &&
|
|
|
|
|
m_ClipboardSharing == sc.m_ClipboardSharing &&
|
|
|
|
|
m_ClipboardSharingSize == sc.m_ClipboardSharingSize &&
|
|
|
|
|
m_pMainWindow == sc.m_pMainWindow;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
void ServerConfig::save(QFile& file) const
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
QTextStream outStream(&file);
|
|
|
|
|
outStream << *this;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServerConfig::init()
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
switchCorners().clear();
|
|
|
|
|
screens().clear();
|
2021-09-27 14:04:11 +00:00
|
|
|
hotkeys().clear();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
// m_NumSwitchCorners is used as a fixed size array. See Screen::init()
|
|
|
|
|
for (int i = 0; i < NumSwitchCorners; i++)
|
|
|
|
|
switchCorners() << false;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
// There must always be screen objects for each cell in the screens QList. Unused screens
|
|
|
|
|
// are identified by having an empty name.
|
|
|
|
|
for (int i = 0; i < numColumns() * numRows(); i++)
|
|
|
|
|
addScreen(Screen());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServerConfig::saveSettings()
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
settings().beginGroup("internalConfig");
|
|
|
|
|
settings().remove("");
|
|
|
|
|
|
|
|
|
|
settings().setValue("numColumns", numColumns());
|
|
|
|
|
settings().setValue("numRows", numRows());
|
|
|
|
|
|
|
|
|
|
settings().setValue("hasHeartbeat", hasHeartbeat());
|
|
|
|
|
settings().setValue("heartbeat", heartbeat());
|
|
|
|
|
settings().setValue("relativeMouseMoves", relativeMouseMoves());
|
|
|
|
|
settings().setValue("win32KeepForeground", win32KeepForeground());
|
|
|
|
|
settings().setValue("hasSwitchDelay", hasSwitchDelay());
|
|
|
|
|
settings().setValue("switchDelay", switchDelay());
|
|
|
|
|
settings().setValue("hasSwitchDoubleTap", hasSwitchDoubleTap());
|
|
|
|
|
settings().setValue("switchDoubleTap", switchDoubleTap());
|
|
|
|
|
settings().setValue("switchCornerSize", switchCornerSize());
|
|
|
|
|
settings().setValue("ignoreAutoConfigClient", ignoreAutoConfigClient());
|
2016-11-24 12:15:22 +00:00
|
|
|
settings().setValue("disableLockToScreen", disableLockToScreen());
|
2016-12-28 11:50:32 +00:00
|
|
|
settings().setValue("enableDragAndDrop", enableDragAndDrop());
|
2021-02-22 11:33:18 +00:00
|
|
|
settings().setValue("clipboardSharing", clipboardSharing());
|
|
|
|
|
settings().setValue("clipboardSharingSize", QVariant::fromValue(clipboardSharingSize()));
|
2016-12-28 11:50:32 +00:00
|
|
|
|
|
|
|
|
writeSettings(settings(), switchCorners(), "switchCorner");
|
|
|
|
|
|
|
|
|
|
settings().beginWriteArray("screens");
|
|
|
|
|
for (int i = 0; i < screens().size(); i++)
|
|
|
|
|
{
|
|
|
|
|
settings().setArrayIndex(i);
|
2021-02-22 11:33:18 +00:00
|
|
|
auto& screen = screens()[i];
|
|
|
|
|
screen.saveSettings(settings());
|
|
|
|
|
if (screen.isServer() && m_pAppConfig->screenName() != screen.name()){
|
|
|
|
|
m_pAppConfig->setScreenName(screen.name());
|
|
|
|
|
}
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
|
|
|
|
settings().endArray();
|
|
|
|
|
|
|
|
|
|
settings().beginWriteArray("hotkeys");
|
|
|
|
|
for (int i = 0; i < hotkeys().size(); i++)
|
|
|
|
|
{
|
|
|
|
|
settings().setArrayIndex(i);
|
|
|
|
|
hotkeys()[i].saveSettings(settings());
|
|
|
|
|
}
|
|
|
|
|
settings().endArray();
|
|
|
|
|
|
|
|
|
|
settings().endGroup();
|
2020-04-27 12:02:26 +00:00
|
|
|
|
2021-03-12 18:09:30 +00:00
|
|
|
m_pAppConfig->saveSettings();
|
2020-04-27 12:02:26 +00:00
|
|
|
//Tell the config writer there are changes
|
|
|
|
|
GUI::Config::ConfigWriter::make()->markUnsaved();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServerConfig::loadSettings()
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
settings().beginGroup("internalConfig");
|
|
|
|
|
|
|
|
|
|
setNumColumns(settings().value("numColumns", 5).toInt());
|
|
|
|
|
setNumRows(settings().value("numRows", 3).toInt());
|
|
|
|
|
|
|
|
|
|
// we need to know the number of columns and rows before we can set up ourselves
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
|
|
haveHeartbeat(settings().value("hasHeartbeat", false).toBool());
|
|
|
|
|
setHeartbeat(settings().value("heartbeat", 5000).toInt());
|
|
|
|
|
setRelativeMouseMoves(settings().value("relativeMouseMoves", false).toBool());
|
|
|
|
|
setWin32KeepForeground(settings().value("win32KeepForeground", false).toBool());
|
|
|
|
|
haveSwitchDelay(settings().value("hasSwitchDelay", false).toBool());
|
|
|
|
|
setSwitchDelay(settings().value("switchDelay", 250).toInt());
|
|
|
|
|
haveSwitchDoubleTap(settings().value("hasSwitchDoubleTap", false).toBool());
|
|
|
|
|
setSwitchDoubleTap(settings().value("switchDoubleTap", 250).toInt());
|
|
|
|
|
setSwitchCornerSize(settings().value("switchCornerSize").toInt());
|
|
|
|
|
setIgnoreAutoConfigClient(settings().value("ignoreAutoConfigClient").toBool());
|
2016-11-24 12:15:22 +00:00
|
|
|
setDisableLockToScreen(settings().value("disableLockToScreen", false).toBool());
|
2022-05-24 14:47:26 +00:00
|
|
|
setEnableDragAndDrop(settings().value("enableDragAndDrop", false).toBool());
|
2017-01-25 12:29:44 +00:00
|
|
|
setClipboardSharingSize(settings().value("clipboardSharingSize",
|
|
|
|
|
(int) ServerConfig::defaultClipboardSharingSize()).toULongLong());
|
2021-08-25 10:49:54 +00:00
|
|
|
setClipboardSharing(settings().value("clipboardSharing", true).toBool());
|
2016-12-28 11:50:32 +00:00
|
|
|
|
|
|
|
|
readSettings(settings(), switchCorners(), "switchCorner", false, NumSwitchCorners);
|
|
|
|
|
|
|
|
|
|
int numScreens = settings().beginReadArray("screens");
|
|
|
|
|
Q_ASSERT(numScreens <= screens().size());
|
|
|
|
|
for (int i = 0; i < numScreens; i++)
|
|
|
|
|
{
|
|
|
|
|
settings().setArrayIndex(i);
|
|
|
|
|
screens()[i].loadSettings(settings());
|
2021-02-22 11:33:18 +00:00
|
|
|
if (getServerName() == screens()[i].name()) {
|
|
|
|
|
screens()[i].markAsServer();
|
|
|
|
|
}
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
|
|
|
|
settings().endArray();
|
|
|
|
|
|
|
|
|
|
int numHotkeys = settings().beginReadArray("hotkeys");
|
|
|
|
|
for (int i = 0; i < numHotkeys; i++)
|
|
|
|
|
{
|
|
|
|
|
settings().setArrayIndex(i);
|
|
|
|
|
Hotkey h;
|
|
|
|
|
h.loadSettings(settings());
|
|
|
|
|
hotkeys().append(h);
|
|
|
|
|
}
|
|
|
|
|
settings().endArray();
|
|
|
|
|
|
|
|
|
|
settings().endGroup();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ServerConfig::adjacentScreenIndex(int idx, int deltaColumn, int deltaRow) const
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
if (screens()[idx].isNull())
|
|
|
|
|
return -1;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
// if we're at the left or right end of the table, don't find results going further left or right
|
|
|
|
|
if ((deltaColumn > 0 && (idx+1) % numColumns() == 0)
|
|
|
|
|
|| (deltaColumn < 0 && idx % numColumns() == 0))
|
|
|
|
|
return -1;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
int arrayPos = idx + deltaColumn + deltaRow * numColumns();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
if (arrayPos >= screens().size() || arrayPos < 0)
|
|
|
|
|
return -1;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
return arrayPos;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextStream& operator<<(QTextStream& outStream, const ServerConfig& config)
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "section: screens" << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
foreach (const Screen& s, config.screens())
|
|
|
|
|
if (!s.isNull())
|
|
|
|
|
s.writeScreensSection(outStream);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "end" << endl << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "section: aliases" << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
foreach (const Screen& s, config.screens())
|
|
|
|
|
if (!s.isNull())
|
|
|
|
|
s.writeAliasesSection(outStream);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "end" << endl << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "section: links" << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
for (int i = 0; i < config.screens().size(); i++)
|
|
|
|
|
if (!config.screens()[i].isNull())
|
|
|
|
|
{
|
|
|
|
|
outStream << "\t" << config.screens()[i].name() << ":" << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
for (unsigned int j = 0; j < sizeof(neighbourDirs) / sizeof(neighbourDirs[0]); j++)
|
|
|
|
|
{
|
|
|
|
|
int idx = config.adjacentScreenIndex(i, neighbourDirs[j].x, neighbourDirs[j].y);
|
|
|
|
|
if (idx != -1 && !config.screens()[idx].isNull())
|
|
|
|
|
outStream << "\t\t" << neighbourDirs[j].name << " = " << config.screens()[idx].name() << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "end" << endl << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "section: options" << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
if (config.hasHeartbeat())
|
|
|
|
|
outStream << "\t" << "heartbeat = " << config.heartbeat() << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "\t" << "relativeMouseMoves = " << (config.relativeMouseMoves() ? "true" : "false") << endl;
|
|
|
|
|
outStream << "\t" << "win32KeepForeground = " << (config.win32KeepForeground() ? "true" : "false") << endl;
|
2016-11-24 12:15:22 +00:00
|
|
|
outStream << "\t" << "disableLockToScreen = " << (config.disableLockToScreen() ? "true" : "false") << endl;
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "\t" << "clipboardSharing = " << (config.clipboardSharing() ? "true" : "false") << endl;
|
2017-01-24 15:06:50 +00:00
|
|
|
outStream << "\t" << "clipboardSharingSize = " << config.clipboardSharingSize() << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
if (config.hasSwitchDelay())
|
|
|
|
|
outStream << "\t" << "switchDelay = " << config.switchDelay() << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
if (config.hasSwitchDoubleTap())
|
|
|
|
|
outStream << "\t" << "switchDoubleTap = " << config.switchDoubleTap() << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "\t" << "switchCorners = none ";
|
|
|
|
|
for (int i = 0; i < config.switchCorners().size(); i++)
|
|
|
|
|
if (config.switchCorners()[i])
|
|
|
|
|
outStream << "+" << config.switchCornerName(i) << " ";
|
|
|
|
|
outStream << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "\t" << "switchCornerSize = " << config.switchCornerSize() << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
foreach(const Hotkey& hotkey, config.hotkeys())
|
|
|
|
|
outStream << hotkey;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
outStream << "end" << endl << endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
return outStream;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ServerConfig::numScreens() const
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
int rval = 0;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
foreach(const Screen& s, screens())
|
|
|
|
|
if (!s.isNull())
|
|
|
|
|
rval++;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
return rval;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
2014-08-21 17:32:40 +00:00
|
|
|
|
|
|
|
|
int ServerConfig::autoAddScreen(const QString name)
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
int serverIndex = -1;
|
|
|
|
|
int targetIndex = -1;
|
2021-02-22 11:33:18 +00:00
|
|
|
if (!findScreenName(m_pAppConfig->screenName(), serverIndex) &&
|
|
|
|
|
!fixNoServer(m_pAppConfig->screenName(), serverIndex))
|
|
|
|
|
{
|
|
|
|
|
return kAutoAddScreenManualServer;
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2021-02-22 11:33:18 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
if (findScreenName(name, targetIndex)) {
|
2018-08-08 16:20:16 +00:00
|
|
|
m_pMainWindow->appendLogDebug(QString("ignoring screen already in config: %1").arg(name));
|
2016-12-28 11:50:32 +00:00
|
|
|
return kAutoAddScreenIgnore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int result = showAddClientDialog(name);
|
|
|
|
|
|
|
|
|
|
if (result == kAddClientIgnore) {
|
|
|
|
|
return kAutoAddScreenIgnore;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == kAddClientOther) {
|
|
|
|
|
addToFirstEmptyGrid(name);
|
|
|
|
|
return kAutoAddScreenManualClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
int startIndex = serverIndex;
|
|
|
|
|
int offset = 1;
|
|
|
|
|
int dirIndex = 0;
|
|
|
|
|
|
|
|
|
|
if (result == kAddClientLeft) {
|
|
|
|
|
offset = -1;
|
|
|
|
|
dirIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
else if (result == kAddClientUp) {
|
|
|
|
|
offset = -5;
|
|
|
|
|
dirIndex = 2;
|
|
|
|
|
}
|
|
|
|
|
else if (result == kAddClientDown) {
|
|
|
|
|
offset = 5;
|
|
|
|
|
dirIndex = 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x,
|
|
|
|
|
neighbourDirs[dirIndex].y);
|
|
|
|
|
while (idx != -1) {
|
|
|
|
|
if (screens()[idx].isNull()) {
|
|
|
|
|
m_Screens[idx].setName(name);
|
|
|
|
|
success = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
startIndex += offset;
|
|
|
|
|
idx = adjacentScreenIndex(startIndex, neighbourDirs[dirIndex].x,
|
|
|
|
|
neighbourDirs[dirIndex].y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
addToFirstEmptyGrid(name);
|
|
|
|
|
return kAutoAddScreenManualClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveSettings();
|
|
|
|
|
return kAutoAddScreenOk;
|
2014-08-21 17:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-22 11:33:18 +00:00
|
|
|
const QString& ServerConfig::getServerName() const
|
|
|
|
|
{
|
|
|
|
|
return m_pAppConfig->screenName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServerConfig::updateServerName()
|
|
|
|
|
{
|
|
|
|
|
for (auto& screen : screens()) {
|
|
|
|
|
if (screen.isServer()) {
|
|
|
|
|
screen.setName(m_pAppConfig->screenName());
|
2021-03-19 15:53:32 +00:00
|
|
|
saveSettings();
|
2021-02-22 11:33:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 09:03:37 +00:00
|
|
|
const QString& ServerConfig::getConfigFile() const
|
|
|
|
|
{
|
|
|
|
|
return m_pAppConfig->getConfigFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ServerConfig::getUseExternalConfig() const
|
|
|
|
|
{
|
|
|
|
|
return m_pAppConfig->getUseExternalConfig();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-22 07:29:46 +00:00
|
|
|
bool ServerConfig::isFull() const
|
|
|
|
|
{
|
|
|
|
|
bool isFull = true;
|
|
|
|
|
|
|
|
|
|
for (const auto& screen : screens())
|
|
|
|
|
{
|
|
|
|
|
if (screen.isNull())
|
|
|
|
|
{
|
|
|
|
|
isFull = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isFull;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 12:49:27 +00:00
|
|
|
bool ServerConfig::isScreenExists(const QString& screenName) const
|
|
|
|
|
{
|
|
|
|
|
bool isExists = false;
|
|
|
|
|
|
|
|
|
|
for (const auto& screen : screens())
|
|
|
|
|
{
|
|
|
|
|
if (!screen.isNull() &&
|
|
|
|
|
screen.name() == screenName)
|
|
|
|
|
{
|
|
|
|
|
isExists = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isExists;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 10:05:59 +00:00
|
|
|
void ServerConfig::addClient(const QString& clientName)
|
|
|
|
|
{
|
2021-06-09 08:23:09 +00:00
|
|
|
int serverIndex = -1;
|
|
|
|
|
|
|
|
|
|
if (findScreenName(m_pAppConfig->screenName(), serverIndex))
|
|
|
|
|
{
|
|
|
|
|
m_Screens[serverIndex].markAsServer();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fixNoServer(m_pAppConfig->screenName(), serverIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 10:05:59 +00:00
|
|
|
m_Screens.addScreenByPriority(clientName);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 09:03:37 +00:00
|
|
|
void ServerConfig::setConfigFile(const QString& configFile)
|
|
|
|
|
{
|
|
|
|
|
m_pAppConfig->setConfigFile(configFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ServerConfig::setUseExternalConfig(bool useExternalConfig)
|
|
|
|
|
{
|
|
|
|
|
m_pAppConfig->setUseExternalConfig(useExternalConfig);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 17:32:40 +00:00
|
|
|
bool ServerConfig::findScreenName(const QString& name, int& index)
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
bool found = false;
|
|
|
|
|
for (int i = 0; i < screens().size(); i++) {
|
|
|
|
|
if (!screens()[i].isNull() &&
|
|
|
|
|
screens()[i].name().compare(name) == 0) {
|
|
|
|
|
index = i;
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return found;
|
2014-08-21 17:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 11:27:17 +00:00
|
|
|
bool ServerConfig::fixNoServer(const QString& name, int& index)
|
2014-08-21 17:32:40 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
bool fixed = false;
|
|
|
|
|
if (screens()[serverDefaultIndex].isNull()) {
|
|
|
|
|
m_Screens[serverDefaultIndex].setName(name);
|
2021-06-09 08:23:09 +00:00
|
|
|
m_Screens[serverDefaultIndex].markAsServer();
|
2016-12-28 11:50:32 +00:00
|
|
|
index = serverDefaultIndex;
|
|
|
|
|
fixed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fixed;
|
2014-08-21 17:32:40 +00:00
|
|
|
}
|
2014-08-26 14:49:27 +00:00
|
|
|
|
2014-11-18 11:00:31 +00:00
|
|
|
int ServerConfig::showAddClientDialog(const QString& clientName)
|
2014-08-26 14:49:27 +00:00
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
int result = kAddClientIgnore;
|
2014-12-01 11:22:42 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
if (!m_pMainWindow->isActiveWindow()) {
|
|
|
|
|
m_pMainWindow->showNormal();
|
|
|
|
|
m_pMainWindow->activateWindow();
|
|
|
|
|
}
|
2014-08-26 14:49:27 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
AddClientDialog addClientDialog(clientName, m_pMainWindow);
|
|
|
|
|
addClientDialog.exec();
|
|
|
|
|
result = addClientDialog.addResult();
|
|
|
|
|
m_IgnoreAutoConfigClient = addClientDialog.ignoreAutoConfigClient();
|
2015-01-05 13:32:58 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
return result;
|
2014-08-26 14:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void::ServerConfig::addToFirstEmptyGrid(const QString &clientName)
|
|
|
|
|
{
|
2016-12-28 11:50:32 +00:00
|
|
|
for (int i = 0; i < screens().size(); i++) {
|
|
|
|
|
if (screens()[i].isNull()) {
|
|
|
|
|
m_Screens[i].setName(clientName);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-26 14:49:27 +00:00
|
|
|
}
|
2017-01-24 15:06:50 +00:00
|
|
|
|
|
|
|
|
size_t ServerConfig::defaultClipboardSharingSize() {
|
|
|
|
|
return 3 * 1024; // 3 MiB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t ServerConfig::setClipboardSharingSize(size_t size) {
|
|
|
|
|
if (size) {
|
|
|
|
|
size += 512; // Round up to the nearest megabyte
|
|
|
|
|
size /= 1024;
|
|
|
|
|
size *= 1024;
|
|
|
|
|
setClipboardSharing(true);
|
|
|
|
|
} else {
|
|
|
|
|
setClipboardSharing(false);
|
|
|
|
|
}
|
|
|
|
|
using std::swap;
|
|
|
|
|
swap (size, m_ClipboardSharingSize);
|
|
|
|
|
return size;
|
|
|
|
|
}
|
2020-02-25 16:32:46 +00:00
|
|
|
|
|
|
|
|
QSettings &ServerConfig::settings() {
|
2020-04-23 17:11:20 +00:00
|
|
|
using GUI::Config::ConfigWriter;
|
|
|
|
|
|
|
|
|
|
return ConfigWriter::make()->settings();
|
2020-02-25 16:32:46 +00:00
|
|
|
}
|