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 - 2016 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 "Action.h"
|
|
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QString Action::text() const
|
|
|
|
|
{
|
2025-04-27 16:49:45 +00:00
|
|
|
auto text = QString(m_actionTypeNames.at(keySequence().isMouseButton() ? type() + 6 : type()));
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-08-14 23:26:32 +00:00
|
|
|
switch (static_cast<Action::Type>(type())) {
|
|
|
|
|
using enum Type;
|
2024-07-02 19:07:06 +00:00
|
|
|
case keyDown:
|
|
|
|
|
case keyUp:
|
|
|
|
|
case keystroke: {
|
2025-01-05 01:53:48 +00:00
|
|
|
QString commandArgs = keySequence().toString();
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
if (!keySequence().isMouseButton()) {
|
|
|
|
|
const QStringList &screens = typeScreenNames();
|
|
|
|
|
if (haveScreens() && !screens.isEmpty()) {
|
2025-01-05 01:53:48 +00:00
|
|
|
QString screenList;
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < screens.size(); i++) {
|
2025-01-05 01:53:48 +00:00
|
|
|
screenList.append(screens[i]);
|
2024-07-02 19:07:06 +00:00
|
|
|
if (i != screens.size() - 1)
|
2025-01-05 01:53:48 +00:00
|
|
|
screenList.append(QStringLiteral(":"));
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2025-01-05 01:53:48 +00:00
|
|
|
commandArgs.append(QStringLiteral(",%1").arg(screenList));
|
2024-07-02 19:07:06 +00:00
|
|
|
} else
|
2025-01-05 01:53:48 +00:00
|
|
|
commandArgs.append(QStringLiteral(",*"));
|
2016-12-28 11:50:32 +00:00
|
|
|
}
|
2025-01-05 01:53:48 +00:00
|
|
|
text.append(m_commandTemplate.arg(commandArgs));
|
2024-07-02 19:07:06 +00:00
|
|
|
} break;
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2025-08-14 23:26:32 +00:00
|
|
|
case Type::switchToScreen:
|
2025-01-05 01:53:48 +00:00
|
|
|
text.append(m_commandTemplate.arg(m_switchScreenName));
|
2024-07-02 19:07:06 +00:00
|
|
|
break;
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2025-08-14 23:26:32 +00:00
|
|
|
case Type::switchInDirection:
|
2025-01-05 02:10:28 +00:00
|
|
|
text.append(m_commandTemplate.arg(m_switchDirectionNames.at(m_switchDirection)));
|
2024-07-02 19:07:06 +00:00
|
|
|
break;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-08-14 23:26:32 +00:00
|
|
|
case Type::lockCursorToScreen:
|
2025-01-05 02:10:28 +00:00
|
|
|
text.append(m_commandTemplate.arg(m_lockCursorModeNames.at(m_lockCursorMode)));
|
2024-07-02 19:07:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Action::loadSettings(QSettings &settings)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
keySequence().loadSettings(settings);
|
2025-08-14 23:26:32 +00:00
|
|
|
setType(settings.value(SettingsKeys::ActionType, static_cast<int>(Type::keyDown)).toInt());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
typeScreenNames().clear();
|
2025-01-05 01:21:09 +00:00
|
|
|
int numTypeScreens = settings.beginReadArray(SettingsKeys::ScreenNames);
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < numTypeScreens; i++) {
|
|
|
|
|
settings.setArrayIndex(i);
|
2025-01-05 01:21:09 +00:00
|
|
|
typeScreenNames().append(settings.value(SettingsKeys::ScreenName).toString());
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
settings.endArray();
|
|
|
|
|
|
2025-01-05 01:21:09 +00:00
|
|
|
setSwitchScreenName(settings.value(SettingsKeys::SwitchToScreen).toString());
|
2025-08-14 23:41:13 +00:00
|
|
|
setSwitchDirection(settings.value(SettingsKeys::SwitchDirection, static_cast<int>(SwitchDirection::left)).toInt());
|
2025-01-05 01:21:09 +00:00
|
|
|
setLockCursorMode(settings.value(SettingsKeys::LockToScreen, lockCursorToggle).toInt());
|
|
|
|
|
setActiveOnRelease(settings.value(SettingsKeys::ActiveOnRelease, false).toBool());
|
|
|
|
|
setHaveScreens(settings.value(SettingsKeys::HasScreens, false).toBool());
|
|
|
|
|
setRestartServer(settings.value(SettingsKeys::RestartServer, false).toBool());
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
2016-12-28 11:50:32 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Action::saveSettings(QSettings &settings) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
keySequence().saveSettings(settings);
|
2025-01-05 01:21:09 +00:00
|
|
|
settings.setValue(SettingsKeys::ActionType, type());
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2025-01-05 01:21:09 +00:00
|
|
|
settings.beginWriteArray(SettingsKeys::ScreenNames);
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < typeScreenNames().size(); i++) {
|
|
|
|
|
settings.setArrayIndex(i);
|
2025-01-05 01:21:09 +00:00
|
|
|
settings.setValue(SettingsKeys::ScreenName, typeScreenNames()[i]);
|
2024-07-02 19:07:06 +00:00
|
|
|
}
|
|
|
|
|
settings.endArray();
|
|
|
|
|
|
2025-01-05 01:21:09 +00:00
|
|
|
settings.setValue(SettingsKeys::SwitchToScreen, switchScreenName());
|
|
|
|
|
settings.setValue(SettingsKeys::SwitchDirection, switchDirection());
|
|
|
|
|
settings.setValue(SettingsKeys::LockToScreen, lockCursorMode());
|
|
|
|
|
settings.setValue(SettingsKeys::ActiveOnRelease, activeOnRelease());
|
|
|
|
|
settings.setValue(SettingsKeys::HasScreens, haveScreens());
|
|
|
|
|
settings.setValue(SettingsKeys::RestartServer, restartServer());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QTextStream &operator<<(QTextStream &outStream, const Action &action)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
if (action.activeOnRelease())
|
|
|
|
|
outStream << ";";
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
outStream << action.text();
|
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
|
|
|
}
|