From 1892690c14306ea154daea6a2b1da8e43b4d5ae1 Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 20 Aug 2026 22:43:52 -0400 Subject: [PATCH] refactor(Hotkey): remove protected and friends add accessors for needed Action items --- src/lib/common/Hotkey.cpp | 21 +++++++++++++++- src/lib/common/Hotkey.h | 28 +++++++--------------- src/lib/gui/dialogs/ServerConfigDialog.cpp | 6 ++--- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/lib/common/Hotkey.cpp b/src/lib/common/Hotkey.cpp index 2828f14da..18cb3597f 100644 --- a/src/lib/common/Hotkey.cpp +++ b/src/lib/common/Hotkey.cpp @@ -1,6 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * SPDX-FileCopyrightText: (C) 2025 - 2026 Chris Rizzitello * SPDX-FileCopyrightText: (C) 2012 - 2016 Synergy App Ltd * SPDX-FileCopyrightText: (C) 2008 Volker Lanz * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -16,6 +16,25 @@ QString Hotkey::text() const : kKeystroke.arg(m_keySequence.toString()); } +Action &Hotkey::actionAt(int index) +{ + return m_actions[index]; +} + +void Hotkey::addAction(const Action &action) +{ + if (m_actions.contains(action)) + return; + m_actions.append(action); +} + +void Hotkey::removeActionAt(int index) +{ + if (index < 0 || index >= m_actions.size()) + return; + m_actions.removeAt(index); +} + void Hotkey::loadSettings(QSettings &settings) { m_keySequence.loadSettings(settings); diff --git a/src/lib/common/Hotkey.h b/src/lib/common/Hotkey.h index 9fb3824ff..506ddf3b4 100644 --- a/src/lib/common/Hotkey.h +++ b/src/lib/common/Hotkey.h @@ -1,6 +1,6 @@ /* * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * SPDX-FileCopyrightText: (C) 2025 - 2026 Chris Rizzitello * SPDX-FileCopyrightText: (C) 2012 - 2016 Synergy App Ltd * SPDX-FileCopyrightText: (C) 2008 Volker Lanz * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception @@ -21,10 +21,6 @@ class QSettings; class Hotkey { - friend class HotkeyDialog; - friend class ServerConfigDialog; - friend QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey); - public: Hotkey() = default; @@ -33,30 +29,24 @@ public: { return m_keySequence; } + void setKeySequence(const KeySequence &seq) + { + m_keySequence = seq; + } const ActionList &actions() const { return m_actions; } + Action &actionAt(int index); + void addAction(const Action &action); + void removeActionAt(int index); + void loadSettings(QSettings &settings); void saveSettings(QSettings &settings) 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; - } - private: KeySequence m_keySequence = {}; ActionList m_actions = {}; diff --git a/src/lib/gui/dialogs/ServerConfigDialog.cpp b/src/lib/gui/dialogs/ServerConfigDialog.cpp index a72bba43a..5602a344f 100644 --- a/src/lib/gui/dialogs/ServerConfigDialog.cpp +++ b/src/lib/gui/dialogs/ServerConfigDialog.cpp @@ -177,7 +177,7 @@ void ServerConfigDialog::addAction() Action action; ActionDialog dlg(this, serverConfig(), hotkey, action); if (dlg.exec() == QDialog::Accepted) { - hotkey.actions().append(action); + hotkey.addAction(action); ui->listActions->addItem(action.text()); setButtonBoxEnabledButtons(); } @@ -197,7 +197,7 @@ void ServerConfigDialog::editAction() qDebug() << "Attempt to remove out of bounds action row: " << actionRow; return; } - Action &action = hotkey.actions()[actionRow]; + Action &action = hotkey.actionAt(actionRow); ActionDialog dlg(this, serverConfig(), hotkey, action); if (dlg.exec() == QDialog::Accepted) { @@ -221,7 +221,7 @@ void ServerConfigDialog::removeAction() return; } - hotkey.actions().removeAt(actionRow); + hotkey.removeActionAt(actionRow); delete ui->listActions->currentItem(); setButtonBoxEnabledButtons(); }