Skip to content

Commit

Permalink
added output/input traymenus
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Nov 18, 2024
1 parent 6ab6712 commit af0f309
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
49 changes: 41 additions & 8 deletions QuickSoundSwitcher/QuickSoundSwitcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,57 @@ QuickSoundSwitcher::~QuickSoundSwitcher() {
void QuickSoundSwitcher::createTrayIcon()
{
onOutputMuteChanged();

QMenu *trayMenu = new QMenu(this);

QAction *startupAction = new QAction(tr("Run at startup"), this);
startupAction->setCheckable(true);
startupAction->setChecked(ShortcutManager::isShortcutPresent());
connect(startupAction, &QAction::triggered, this, &QuickSoundSwitcher::onRunAtStartupStateChanged);
trayMenu->addAction(startupAction);
connect(trayMenu, &QMenu::aboutToShow, this, [trayMenu, this]() {
trayMenu->clear();

QList<AudioDevice> playbackDevices;
AudioManager::enumeratePlaybackDevices(playbackDevices);
createDeviceSubMenu(trayMenu, playbackDevices, tr("Output device"));

QList<AudioDevice> recordingDevices;
AudioManager::enumerateRecordingDevices(recordingDevices);
createDeviceSubMenu(trayMenu, recordingDevices, tr("Input device"));

trayMenu->addSeparator();

QAction *exitAction = new QAction(tr("Exit"), this);
connect(exitAction, &QAction::triggered, this, &QApplication::quit);
trayMenu->addAction(exitAction);
QAction *startupAction = new QAction(tr("Run at startup"), this);
startupAction->setCheckable(true);
startupAction->setChecked(ShortcutManager::isShortcutPresent());
connect(startupAction, &QAction::triggered, this, &QuickSoundSwitcher::onRunAtStartupStateChanged);
trayMenu->addAction(startupAction);

QAction *exitAction = new QAction(tr("Exit"), this);
connect(exitAction, &QAction::triggered, this, &QApplication::quit);
trayMenu->addAction(exitAction);
});

trayIcon->setContextMenu(trayMenu);
trayIcon->setToolTip("Quick Sound Switcher");
trayIcon->show();
connect(trayIcon, &QSystemTrayIcon::activated, this, &QuickSoundSwitcher::trayIconActivated);
}

void QuickSoundSwitcher::createDeviceSubMenu(QMenu *parentMenu, const QList<AudioDevice> &devices, const QString &title)
{
QMenu *subMenu = parentMenu->addMenu(title);

for (const AudioDevice &device : devices) {
QAction *deviceAction = new QAction(device.shortName, subMenu);
deviceAction->setCheckable(true);
deviceAction->setChecked(device.isDefault);

connect(deviceAction, &QAction::triggered, this, [device]() {
AudioManager::setDefaultEndpoint(device.id);
});

subMenu->addAction(deviceAction);
}
}


void QuickSoundSwitcher::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
if (reason == QSystemTrayIcon::Trigger) {
Expand Down
1 change: 1 addition & 0 deletions QuickSoundSwitcher/QuickSoundSwitcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private slots:
void movePanelDown();
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
bool hiding;
void createDeviceSubMenu(QMenu *parentMenu, const QList<AudioDevice> &devices, const QString &title);
};

#endif // QUICKSOUNDSWITCHER_H
22 changes: 16 additions & 6 deletions Resources/Tr/QuickSoundSwitcher_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@
<context>
<name>Panel</name>
<message>
<location filename="../../Panel/Panel.ui" line="194"/>
<location filename="../../Panel/Panel.ui" line="201"/>
<source>Input</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../Panel/Panel.ui" line="73"/>
<location filename="../../Panel/Panel.ui" line="74"/>
<source>Output</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../Panel/Panel.ui" line="297"/>
<location filename="../../Panel/Panel.ui" line="310"/>
<source>Volume mixer</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../Panel/Panel.cpp" line="282"/>
<location filename="../../Panel/Panel.cpp" line="262"/>
<source>All quiet for now.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QuickSoundSwitcher</name>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="28"/>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="34"/>
<source>Output device</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="38"/>
<source>Input device</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="42"/>
<source>Run at startup</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="34"/>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="48"/>
<source>Exit</source>
<translation type="unfinished"></translation>
</message>
Expand Down
22 changes: 16 additions & 6 deletions Resources/Tr/QuickSoundSwitcher_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,45 @@
<context>
<name>Panel</name>
<message>
<location filename="../../Panel/Panel.ui" line="194"/>
<location filename="../../Panel/Panel.ui" line="201"/>
<source>Input</source>
<translation>Entrée</translation>
</message>
<message>
<location filename="../../Panel/Panel.ui" line="73"/>
<location filename="../../Panel/Panel.ui" line="74"/>
<source>Output</source>
<translation>Sortie</translation>
</message>
<message>
<location filename="../../Panel/Panel.ui" line="297"/>
<location filename="../../Panel/Panel.ui" line="310"/>
<source>Volume mixer</source>
<translation>Mélangeur de volume</translation>
</message>
<message>
<location filename="../../Panel/Panel.cpp" line="282"/>
<location filename="../../Panel/Panel.cpp" line="262"/>
<source>All quiet for now.</source>
<translation>C&apos;est bien calme ici.</translation>
</message>
</context>
<context>
<name>QuickSoundSwitcher</name>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="28"/>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="34"/>
<source>Output device</source>
<translation>Périphérique de sortie</translation>
</message>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="38"/>
<source>Input device</source>
<translation>Périphérique d&apos;entrée</translation>
</message>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="42"/>
<source>Run at startup</source>
<translation>Lancer au démarrage</translation>
</message>
<message>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="34"/>
<location filename="../../QuickSoundSwitcher/QuickSoundSwitcher.cpp" line="48"/>
<source>Exit</source>
<translation>Quitter</translation>
</message>
Expand Down

0 comments on commit af0f309

Please sign in to comment.