2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- 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)
|
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 "Hotkey.h"
|
|
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
Hotkey::Hotkey() : m_KeySequence(), m_Actions()
|
|
|
|
|
{
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QString Hotkey::text() const
|
|
|
|
|
{
|
2025-01-05 21:28:47 +00:00
|
|
|
return keySequence().isMouseButton() ? kMousebutton.arg(keySequence().toString())
|
|
|
|
|
: kKeystroke.arg(keySequence().toString());
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Hotkey::loadSettings(QSettings &settings)
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
keySequence().loadSettings(settings);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
actions().clear();
|
2025-01-05 21:28:47 +00:00
|
|
|
int num = settings.beginReadArray(kSectionActions);
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
|
settings.setArrayIndex(i);
|
|
|
|
|
Action a;
|
|
|
|
|
a.loadSettings(settings);
|
|
|
|
|
actions().append(a);
|
|
|
|
|
}
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2024-07-02 19:07:06 +00:00
|
|
|
settings.endArray();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void Hotkey::saveSettings(QSettings &settings) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
keySequence().saveSettings(settings);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2025-01-05 21:28:47 +00:00
|
|
|
settings.beginWriteArray(kSectionActions);
|
2024-07-02 19:07:06 +00:00
|
|
|
for (int i = 0; i < actions().size(); i++) {
|
|
|
|
|
settings.setArrayIndex(i);
|
|
|
|
|
actions()[i].saveSettings(settings);
|
|
|
|
|
}
|
|
|
|
|
settings.endArray();
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
bool Hotkey::operator==(const Hotkey &hk) const
|
|
|
|
|
{
|
2024-07-02 19:07:06 +00:00
|
|
|
return m_KeySequence == hk.m_KeySequence && m_Actions == hk.m_Actions;
|
2021-08-20 12:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
QTextStream &operator<<(QTextStream &outStream, const Hotkey &hotkey)
|
|
|
|
|
{
|
2025-01-05 21:02:12 +00:00
|
|
|
// Don't write a config if there is no actions
|
|
|
|
|
if (hotkey.actions().size() == 0)
|
|
|
|
|
return outStream;
|
|
|
|
|
|
2025-01-05 21:34:26 +00:00
|
|
|
QString outText = QStringLiteral("\t%1 = ").arg(hotkey.text());
|
2025-01-05 21:02:12 +00:00
|
|
|
for (int i = 0; i < hotkey.actions().size(); i++) {
|
2025-01-05 21:34:26 +00:00
|
|
|
outText.append(hotkey.actions().at(i).text());
|
2025-01-05 21:02:12 +00:00
|
|
|
if (i != hotkey.actions().size() - 1) {
|
2025-01-05 21:34:26 +00:00
|
|
|
outText.append(QStringLiteral(", "));
|
2025-01-05 21:02:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-05 21:34:26 +00:00
|
|
|
outText.append(QStringLiteral("\n"));
|
2025-01-05 21:02:12 +00:00
|
|
|
|
2025-01-05 21:34:26 +00:00
|
|
|
outStream << outText;
|
2024-07-02 19:07:06 +00:00
|
|
|
return outStream;
|
2012-06-10 16:50:54 +00:00
|
|
|
}
|