2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2008 Volker Lanz <vl@fidra.de>
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Screen.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
#include "config/ScreenConfig.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
using namespace deskflow::gui::proxy;
|
2024-08-08 17:41:59 +00:00
|
|
|
using enum ScreenConfig::Modifier;
|
|
|
|
|
using enum ScreenConfig::SwitchCorner;
|
|
|
|
|
using enum ScreenConfig::Fix;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
Screen::Screen()
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
2024-08-08 17:41:59 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
Screen::Screen(const QString &name)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
init();
|
|
|
|
|
setName(name);
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Screen::init()
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
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.
|
2024-08-08 17:41:59 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(NumModifiers); i++)
|
2024-07-02 19:07:06 +00:00
|
|
|
modifiers() << i;
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(NumSwitchCorners); i++)
|
2024-07-02 19:07:06 +00:00
|
|
|
switchCorners() << false;
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
for (int i = 0; i < static_cast<int>(NumFixes); i++)
|
2024-07-02 19:07:06 +00:00
|
|
|
fixes() << false;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Screen::loadSettings(QSettingsProxy &settings)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
setName(settings.value("name").toString());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (name().isEmpty())
|
|
|
|
|
return;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
setSwitchCornerSize(settings.value("switchCornerSize").toInt());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
readSettings(settings, aliases(), "alias", QString(""));
|
2024-10-17 18:04:35 +00:00
|
|
|
readSettings(settings, modifiers(), "modifier", static_cast<int>(DefaultMod), static_cast<int>(NumModifiers));
|
|
|
|
|
readSettings(settings, switchCorners(), "switchCorner", 0, static_cast<int>(NumSwitchCorners));
|
2024-08-08 17:41:59 +00:00
|
|
|
readSettings(settings, fixes(), "fix", 0, static_cast<int>(NumFixes));
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Screen::saveSettings(QSettingsProxy &settings) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
settings.setValue("name", name());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
if (name().isEmpty())
|
|
|
|
|
return;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
settings.setValue("switchCornerSize", switchCornerSize());
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
writeSettings(settings, aliases(), "alias");
|
|
|
|
|
writeSettings(settings, modifiers(), "modifier");
|
|
|
|
|
writeSettings(settings, switchCorners(), "switchCorner");
|
|
|
|
|
writeSettings(settings, fixes(), "fix");
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QTextStream &Screen::writeScreensSection(QTextStream &outStream) const
|
|
|
|
|
{
|
2024-07-08 14:37:51 +00:00
|
|
|
outStream << "\t" << name() << ":" << Qt::endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < modifiers().size(); i++)
|
|
|
|
|
if (modifier(i) != i)
|
2024-10-17 18:04:35 +00:00
|
|
|
outStream << "\t\t" << modifierName(i) << " = " << modifierName(modifier(i)) << Qt::endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < fixes().size(); i++)
|
2024-10-17 18:04:35 +00:00
|
|
|
outStream << "\t\t" << fixName(i) << " = " << (fixes()[i] ? "true" : "false") << Qt::endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
outStream << "\t\t"
|
|
|
|
|
<< "switchCorners = none ";
|
|
|
|
|
for (int i = 0; i < switchCorners().size(); i++)
|
|
|
|
|
if (switchCorners()[i])
|
|
|
|
|
outStream << "+" << switchCornerName(i) << " ";
|
2024-07-08 14:37:51 +00:00
|
|
|
outStream << Qt::endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
outStream << "\t\t"
|
2024-07-08 14:37:51 +00:00
|
|
|
<< "switchCornerSize = " << switchCornerSize() << Qt::endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return outStream;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QTextStream &Screen::writeAliasesSection(QTextStream &outStream) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (!aliases().isEmpty()) {
|
2024-07-08 14:37:51 +00:00
|
|
|
outStream << "\t" << name() << ":" << Qt::endl;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-21 02:58:12 +00:00
|
|
|
for (const QString &alias : aliases())
|
2024-07-08 14:37:51 +00:00
|
|
|
outStream << "\t\t" << alias << Qt::endl;
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
return outStream;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
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;
|
2021-08-20 12:22:07 +00:00
|
|
|
}
|