diff options
author | Robert Adam <dev@robert-adam.de> | 2022-09-09 13:53:13 +0300 |
---|---|---|
committer | Robert Adam <dev@robert-adam.de> | 2022-09-09 13:54:06 +0300 |
commit | 3c5c411d4bd3184162ae44dc926a5688f832d481 (patch) | |
tree | cd9adab5baf12629de3afb5edadb57625c989b3e /src/mumble | |
parent | a400356548681664f6a0110500002975ac68f16a (diff) |
REFAC(client): Use constants for shortcut types/IDs
Diffstat (limited to 'src/mumble')
-rw-r--r-- | src/mumble/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/mumble/GlobalShortcutTypes.h | 48 | ||||
-rw-r--r-- | src/mumble/MainWindow.cpp | 63 |
3 files changed, 86 insertions, 26 deletions
diff --git a/src/mumble/CMakeLists.txt b/src/mumble/CMakeLists.txt index 80681555f..2189f9525 100644 --- a/src/mumble/CMakeLists.txt +++ b/src/mumble/CMakeLists.txt @@ -157,6 +157,7 @@ set(MUMBLE_SOURCES "GlobalShortcutButtons.h" "GlobalShortcutButtons.ui" "GlobalShortcutTarget.ui" + "GlobalShortcutTypes.h" "JSONSerialization.cpp" "JSONSerialization.h" "LCD.cpp" diff --git a/src/mumble/GlobalShortcutTypes.h b/src/mumble/GlobalShortcutTypes.h new file mode 100644 index 000000000..6fb54400d --- /dev/null +++ b/src/mumble/GlobalShortcutTypes.h @@ -0,0 +1,48 @@ +// Copyright 2022 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at <https://www.mumble.info/LICENSE>. + +#ifndef MUMBLE_MUMBLE_GLOBALSHORTCUTTYPES_H_ +#define MUMBLE_MUMBLE_GLOBALSHORTCUTTYPES_H_ + +/** + * The entries in this namespace/enum represent the shortcut types (often referred to as a shortcut's "index") + * of the existing global shortcuts. + * + * IMPORTANT: ONLY EVER APPEND TO THE END OF THE ENUM! + */ +namespace GlobalShortcutType { +enum Type { + PushToTalk = 1, + ResetAudio, + MuteSelf, + DeafenSelf, + UnlinkPlugin, + PushToMute, + JoinChannel, + ToggleOverlay, + ToggleMinimalView, + VolumeUp, + VolumeDown, + Whisper_Shout, + LinkChannel, + CycleTransmitMode, + ToggleMainWindowVisibility, + UsePushToTalk, + UseContinous, + UseVAD, + SendTextMessage, + SendTextMessageClipboard, + ToggleTalkingUI, + ToggleSearch, +}; + +// A few assertions meant to catch, if anyone inserts a new value in-between instead of appending +// to the end of the enum +static_assert(PushToTalk == 1, "You may only append to the end of the enum!"); +static_assert(ToggleMinimalView == 9, "You may only append to the end of the enum!"); +static_assert(ToggleSearch == 22, "You may only append to the end of the enum!"); +} // namespace GlobalShortcutType + +#endif // MUMBLE_MUMBLE_GLOBALSHORTCUTTYPES_H_ diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index 78a39e136..f9c42c63d 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -24,6 +24,7 @@ #include "NetworkConfig.h" #include "OpusCodec.h" #include "GlobalShortcut.h" +#include "GlobalShortcutTypes.h" #ifdef USE_OVERLAY # include "OverlayClient.h" #endif @@ -202,8 +203,7 @@ MainWindow::MainWindow(QWidget *p) } void MainWindow::createActions() { - int idx = 1; - gsPushTalk = new GlobalShortcut(this, idx++, tr("Push-to-Talk", "Global Shortcut")); + gsPushTalk = new GlobalShortcut(this, GlobalShortcutType::PushToTalk, tr("Push-to-Talk", "Global Shortcut")); gsPushTalk->setObjectName(QLatin1String("PushToTalk")); gsPushTalk->qsToolTip = tr("Push and hold this button to send voice.", "Global Shortcut"); gsPushTalk->qsWhatsThis = tr( @@ -211,35 +211,37 @@ void MainWindow::createActions() { "Global Shortcut"); - gsResetAudio = new GlobalShortcut(this, idx++, tr("Reset Audio Processor", "Global Shortcut")); + gsResetAudio = + new GlobalShortcut(this, GlobalShortcutType::ResetAudio, tr("Reset Audio Processor", "Global Shortcut")); gsResetAudio->setObjectName(QLatin1String("ResetAudio")); - gsMuteSelf = new GlobalShortcut(this, idx++, tr("Mute Self", "Global Shortcut"), 0); + gsMuteSelf = new GlobalShortcut(this, GlobalShortcutType::MuteSelf, tr("Mute Self", "Global Shortcut"), 0); gsMuteSelf->setObjectName(QLatin1String("gsMuteSelf")); gsMuteSelf->qsToolTip = tr("Set self-mute status.", "Global Shortcut"); gsMuteSelf->qsWhatsThis = tr("This will set or toggle your muted status. If you turn this off, you will also disable self-deafen.", "Global Shortcut"); - gsDeafSelf = new GlobalShortcut(this, idx++, tr("Deafen Self", "Global Shortcut"), 0); + gsDeafSelf = new GlobalShortcut(this, GlobalShortcutType::DeafenSelf, tr("Deafen Self", "Global Shortcut"), 0); gsDeafSelf->setObjectName(QLatin1String("gsDeafSelf")); gsDeafSelf->qsToolTip = tr("Set self-deafen status.", "Global Shortcut"); gsDeafSelf->qsWhatsThis = tr("This will set or toggle your deafened status. If you turn this on, you will also enable self-mute.", "Global Shortcut"); - gsUnlink = new GlobalShortcut(this, idx++, tr("Unlink Plugin", "Global Shortcut")); + gsUnlink = new GlobalShortcut(this, GlobalShortcutType::UnlinkPlugin, tr("Unlink Plugin", "Global Shortcut")); gsUnlink->setObjectName(QLatin1String("UnlinkPlugin")); - gsPushMute = new GlobalShortcut(this, idx++, tr("Push-to-Mute", "Global Shortcut")); + gsPushMute = new GlobalShortcut(this, GlobalShortcutType::PushToMute, tr("Push-to-Mute", "Global Shortcut")); gsPushMute->setObjectName(QLatin1String("PushToMute")); - gsJoinChannel = new GlobalShortcut(this, idx++, tr("Join Channel", "Global Shortcut")); + gsJoinChannel = new GlobalShortcut(this, GlobalShortcutType::JoinChannel, tr("Join Channel", "Global Shortcut")); gsJoinChannel->setObjectName(QLatin1String("MetaChannel")); gsJoinChannel->qsToolTip = tr("Use in conjunction with Whisper to.", "Global Shortcut"); #ifdef USE_OVERLAY - gsToggleOverlay = new GlobalShortcut(this, idx++, tr("Toggle Overlay", "Global Shortcut")); + gsToggleOverlay = + new GlobalShortcut(this, GlobalShortcutType::ToggleOverlay, tr("Toggle Overlay", "Global Shortcut")); gsToggleOverlay->setObjectName(QLatin1String("ToggleOverlay")); gsToggleOverlay->qsToolTip = tr("Toggle state of in-game overlay.", "Global Shortcut"); gsToggleOverlay->qsWhatsThis = tr("This will switch the states of the in-game overlay.", "Global Shortcut"); @@ -247,57 +249,66 @@ void MainWindow::createActions() { connect(gsToggleOverlay, SIGNAL(down(QVariant)), Global::get().o, SLOT(toggleShow())); #endif - gsMinimal = new GlobalShortcut(this, idx++, tr("Toggle Minimal", "Global Shortcut")); + gsMinimal = + new GlobalShortcut(this, GlobalShortcutType::ToggleMinimalView, tr("Toggle Minimal", "Global Shortcut")); gsMinimal->setObjectName(QLatin1String("ToggleMinimal")); - gsVolumeUp = new GlobalShortcut(this, idx++, tr("Volume Up (+10%)", "Global Shortcut")); + gsVolumeUp = new GlobalShortcut(this, GlobalShortcutType::VolumeUp, tr("Volume Up (+10%)", "Global Shortcut")); gsVolumeUp->setObjectName(QLatin1String("VolumeUp")); - gsVolumeDown = new GlobalShortcut(this, idx++, tr("Volume Down (-10%)", "Global Shortcut")); + gsVolumeDown = + new GlobalShortcut(this, GlobalShortcutType::VolumeDown, tr("Volume Down (-10%)", "Global Shortcut")); gsVolumeDown->setObjectName(QLatin1String("VolumeDown")); qstiIcon = new QSystemTrayIcon(qiIcon, this); qstiIcon->setToolTip(tr("Mumble -- %1").arg(Version::getRelease())); qstiIcon->setObjectName(QLatin1String("Icon")); - gsWhisper = new GlobalShortcut(this, idx++, tr("Whisper/Shout"), QVariant::fromValue(ShortcutTarget())); + gsWhisper = new GlobalShortcut(this, GlobalShortcutType::Whisper_Shout, tr("Whisper/Shout"), + QVariant::fromValue(ShortcutTarget())); gsWhisper->setObjectName(QLatin1String("gsWhisper")); - gsLinkChannel = new GlobalShortcut(this, idx++, tr("Link Channel", "Global Shortcut")); + gsLinkChannel = new GlobalShortcut(this, GlobalShortcutType::LinkChannel, tr("Link Channel", "Global Shortcut")); gsLinkChannel->setObjectName(QLatin1String("MetaLink")); gsLinkChannel->qsToolTip = tr("Use in conjunction with Whisper to.", "Global Shortcut"); - gsCycleTransmitMode = new GlobalShortcut(this, idx++, tr("Cycle Transmit Mode", "Global Shortcut")); + gsCycleTransmitMode = + new GlobalShortcut(this, GlobalShortcutType::CycleTransmitMode, tr("Cycle Transmit Mode", "Global Shortcut")); gsCycleTransmitMode->setObjectName(QLatin1String("gsCycleTransmitMode")); - gsToggleMainWindowVisibility = new GlobalShortcut(this, idx++, tr("Hide/show main window", "Global Shortcut")); + gsToggleMainWindowVisibility = new GlobalShortcut(this, GlobalShortcutType::ToggleMainWindowVisibility, + tr("Hide/show main window", "Global Shortcut")); gsToggleMainWindowVisibility->setObjectName(QLatin1String("gsToggleMainWindowVisibility")); - gsTransmitModePushToTalk = - new GlobalShortcut(this, idx++, tr("Set Transmit Mode to Push-To-Talk", "Global Shortcut")); + gsTransmitModePushToTalk = new GlobalShortcut(this, GlobalShortcutType::UsePushToTalk, + tr("Set Transmit Mode to Push-To-Talk", "Global Shortcut")); gsTransmitModePushToTalk->setObjectName(QLatin1String("gsTransmitModePushToTalk")); - gsTransmitModeContinuous = - new GlobalShortcut(this, idx++, tr("Set Transmit Mode to Continuous", "Global Shortcut")); + gsTransmitModeContinuous = new GlobalShortcut(this, GlobalShortcutType::UseContinous, + tr("Set Transmit Mode to Continuous", "Global Shortcut")); gsTransmitModeContinuous->setObjectName(QLatin1String("gsTransmitModeContinuous")); - gsTransmitModeVAD = new GlobalShortcut(this, idx++, tr("Set Transmit Mode to VAD", "Global Shortcut")); + gsTransmitModeVAD = + new GlobalShortcut(this, GlobalShortcutType::UseVAD, tr("Set Transmit Mode to VAD", "Global Shortcut")); gsTransmitModeVAD->setObjectName(QLatin1String("gsTransmitModeVAD")); - gsSendTextMessage = - new GlobalShortcut(this, idx++, tr("Send Text Message", "Global Shortcut"), QVariant(QString())); + gsSendTextMessage = new GlobalShortcut(this, GlobalShortcutType::SendTextMessage, + tr("Send Text Message", "Global Shortcut"), QVariant(QString())); gsSendTextMessage->setObjectName(QLatin1String("gsSendTextMessage")); - gsSendClipboardTextMessage = new GlobalShortcut(this, idx++, tr("Send Clipboard Text Message", "Global Shortcut")); + gsSendClipboardTextMessage = new GlobalShortcut(this, GlobalShortcutType::SendTextMessageClipboard, + tr("Send Clipboard Text Message", "Global Shortcut")); gsSendClipboardTextMessage->setObjectName(QLatin1String("gsSendClipboardTextMessage")); gsSendClipboardTextMessage->qsWhatsThis = tr("This will send your Clipboard content to the channel you are currently in.", "Global Shortcut"); - gsToggleTalkingUI = new GlobalShortcut(this, idx++, tr("Toggle TalkingUI", "Global shortcut")); + gsToggleTalkingUI = + new GlobalShortcut(this, GlobalShortcutType::ToggleTalkingUI, tr("Toggle TalkingUI", "Global shortcut")); gsToggleTalkingUI->setObjectName(QLatin1String("gsToggleTalkingUI")); gsToggleTalkingUI->qsWhatsThis = tr("Toggles the visibility of the TalkingUI.", "Global Shortcut"); - gsToggleSearch = new GlobalShortcut(this, idx++, tr("Toggle search dialog", "Global Shortcut")); + gsToggleSearch = + new GlobalShortcut(this, GlobalShortcutType::ToggleSearch, tr("Toggle search dialog", "Global Shortcut")); gsToggleSearch->setObjectName(QLatin1String("gsToggleSearch")); gsToggleSearch->qsWhatsThis = tr("This will open or close the search dialog depending on whether it is currently opened already"); |