mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 23:45:35 +08:00
131 lines
5.2 KiB
C++
131 lines
5.2 KiB
C++
/* Copyright (C) 2019
|
|
* swift project Community / Contributors
|
|
*
|
|
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
|
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
|
* or distributed except according to the terms contained in the LICENSE file.
|
|
*/
|
|
|
|
#include "audioadvanceddistributedcomponent.h"
|
|
#include "ui_audioadvanceddistributedcomponent.h"
|
|
|
|
#include "blackgui/guiapplication.h"
|
|
#include "blackcore/context/contextaudio.h"
|
|
#include "blackcore/context/contextnetwork.h"
|
|
#include "blackcore/afv/clients/afvclient.h"
|
|
|
|
using namespace BlackMisc::Audio;
|
|
using namespace BlackCore::Context;
|
|
|
|
namespace BlackGui
|
|
{
|
|
namespace Components
|
|
{
|
|
CAudioAdvancedDistributedComponent::CAudioAdvancedDistributedComponent(QWidget *parent) :
|
|
QFrame(parent),
|
|
ui(new Ui::CAudioAdvancedDistributedComponent)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
connect(sGui->getCContextAudioBase(), &CContextAudioBase::startedAudio, this, &CAudioAdvancedDistributedComponent::onAudioStarted, Qt::QueuedConnection);
|
|
connect(sGui->getCContextAudioBase(), &CContextAudioBase::stoppedAudio, this, &CAudioAdvancedDistributedComponent::onAudioStoppend, Qt::QueuedConnection);
|
|
connect(ui->pb_EnableDisable, &QPushButton::pressed, this, &CAudioAdvancedDistributedComponent::toggleAudioEnableDisable, Qt::QueuedConnection);
|
|
connect(ui->pb_StartStop, &QPushButton::pressed, this, &CAudioAdvancedDistributedComponent::toggleAudioStartStop, Qt::QueuedConnection);
|
|
connect(ui->pb_ReloadRegistered, &QPushButton::pressed, this, &CAudioAdvancedDistributedComponent::reloadRegisteredDevices, Qt::QueuedConnection);
|
|
|
|
this->setButtons();
|
|
}
|
|
|
|
CAudioAdvancedDistributedComponent::~CAudioAdvancedDistributedComponent()
|
|
{ }
|
|
|
|
void CAudioAdvancedDistributedComponent::toggleAudioStartStop()
|
|
{
|
|
if (!hasContexts()) { return; }
|
|
const bool started = sGui->getCContextAudioBase()->isAudioStarted();
|
|
if (started)
|
|
{
|
|
sGui->getCContextAudioBase()->afvClient()->disconnectFromAndStop();
|
|
}
|
|
else
|
|
{
|
|
sGui->getCContextAudioBase()->afvClient()->startAudio();
|
|
if (sGui->getIContextNetwork()->isConnected())
|
|
{
|
|
const bool connected = sGui->getCContextAudioBase()->connectAudioWithNetworkCredentials();
|
|
Q_UNUSED(connected)
|
|
|
|
// one reason for not connecting is NOT using the VATSIM ecosystem
|
|
}
|
|
}
|
|
|
|
this->setButtons(2000);
|
|
}
|
|
|
|
void CAudioAdvancedDistributedComponent::toggleAudioEnableDisable()
|
|
{
|
|
if (!hasContexts()) { return; }
|
|
const bool enabled = sGui->getCContextAudioBase()->isAudioEnabled();
|
|
if (enabled)
|
|
{
|
|
sGui->getCContextAudioBase()->disableVoiceClient();
|
|
}
|
|
else
|
|
{
|
|
sGui->getCContextAudioBase()->enableVoiceClientAndStart();
|
|
}
|
|
|
|
this->setButtons(2000);
|
|
}
|
|
|
|
void CAudioAdvancedDistributedComponent::reloadRegisteredDevices()
|
|
{
|
|
if (!hasContexts()) { return; }
|
|
const CAudioDeviceInfoList registeredDevices = sGui->getIContextAudio()->getRegisteredDevices();
|
|
ui->tvp_RegisteredDevices->updateContainerMaybeAsync(registeredDevices);
|
|
}
|
|
|
|
void CAudioAdvancedDistributedComponent::setButtons()
|
|
{
|
|
if (!hasContexts()) { return; }
|
|
const bool started = sGui->getCContextAudioBase()->isAudioStarted();
|
|
const bool enabled = sGui->getCContextAudioBase()->isAudioEnabled();
|
|
ui->pb_StartStop->setText(started ? "stop" : "start");
|
|
ui->pb_StartStop->setEnabled(enabled);
|
|
ui->pb_EnableDisable->setText(enabled ? "disable" : "enable");
|
|
}
|
|
|
|
void CAudioAdvancedDistributedComponent::setButtons(int delayMs)
|
|
{
|
|
if (!hasContexts()) { return; }
|
|
QPointer<CAudioAdvancedDistributedComponent> myself(this);
|
|
QTimer::singleShot(delayMs, this, [ = ]
|
|
{
|
|
if (!sGui || !myself || sGui->isShuttingDown()) { return; }
|
|
this->setButtons();
|
|
});
|
|
}
|
|
|
|
void CAudioAdvancedDistributedComponent::onAudioStarted(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice)
|
|
{
|
|
Q_UNUSED(inputDevice)
|
|
Q_UNUSED(outputDevice)
|
|
this->setButtons();
|
|
this->reloadRegisteredDevices();
|
|
}
|
|
|
|
void CAudioAdvancedDistributedComponent::onAudioStoppend()
|
|
{
|
|
this->setButtons();
|
|
this->reloadRegisteredDevices();
|
|
}
|
|
|
|
bool CAudioAdvancedDistributedComponent::hasContexts()
|
|
{
|
|
if (!sGui || sGui->isShuttingDown() || !sGui->getCContextAudioBase()) { return false; }
|
|
if (!sGui->getIContextNetwork()) { return false; }
|
|
return true;
|
|
}
|
|
}
|
|
}
|