2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2024-08-08 17:41:59 +00:00
|
|
|
* Copyright (C) 2012 Symless Ltd.
|
2012-06-10 16:50:54 +00:00
|
|
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
2012-06-10 16:50:54 +00:00
|
|
|
* 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.
|
2024-07-02 19:07:06 +00:00
|
|
|
*
|
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 "Screen.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
#include "config/ScreenConfig.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
using namespace synergy::gui::proxy;
|
|
|
|
|
using enum ScreenConfig::Modifier;
|
|
|
|
|
using enum ScreenConfig::SwitchCorner;
|
|
|
|
|
using enum ScreenConfig::Fix;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
Screen::Screen() { init(); }
|
|
|
|
|
|
|
|
|
|
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-07-02 19:07:06 +00:00
|
|
|
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.
|
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-08-08 17:41:59 +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-07-16 13:36:44 +00:00
|
|
|
readSettings(
|
|
|
|
|
settings, modifiers(), "modifier", static_cast<int>(DefaultMod),
|
2024-08-08 17:41:59 +00:00
|
|
|
static_cast<int>(NumModifiers));
|
2024-07-16 13:36:44 +00:00
|
|
|
readSettings(
|
2024-08-08 17:41:59 +00:00
|
|
|
settings, switchCorners(), "switchCorner", 0,
|
|
|
|
|
static_cast<int>(NumSwitchCorners));
|
|
|
|
|
readSettings(settings, fixes(), "fix", 0, static_cast<int>(NumFixes));
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-08 17:41:59 +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-07-02 19:07:06 +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)
|
|
|
|
|
outStream << "\t\t" << modifierName(i) << " = "
|
2024-07-08 14:37:51 +00:00
|
|
|
<< 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++)
|
|
|
|
|
outStream << "\t\t" << fixName(i) << " = "
|
2024-07-08 14:37:51 +00:00
|
|
|
<< (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-07-02 19:07:06 +00:00
|
|
|
QTextStream &Screen::writeAliasesSection(QTextStream &outStream) const {
|
|
|
|
|
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-07-02 19:07:06 +00:00
|
|
|
foreach (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-07-02 19:07:06 +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
|
|
|
}
|