diff --git a/src/blackgui/components/voiceroomscomponent.cpp b/src/blackgui/components/voiceroomscomponent.cpp index d070ece87..28ef431e7 100644 --- a/src/blackgui/components/voiceroomscomponent.cpp +++ b/src/blackgui/components/voiceroomscomponent.cpp @@ -9,6 +9,13 @@ #include "voiceroomscomponent.h" #include "ui_voiceroomscomponent.h" +#include "blackcore/context_audio.h" +#include "blackmisc/notificationsounds.h" + +using namespace BlackCore; +using namespace BlackSound; +using namespace BlackMisc::Audio; + namespace BlackGui { @@ -20,11 +27,108 @@ namespace BlackGui ui(new Ui::CVoiceRoomsComponent) { ui->setupUi(this); + this->setVoiceRoomUrlFields(); + connect(ui->cb_CockpitVoiceRoom1Override, &QCheckBox::toggled, this, &CVoiceRoomsComponent::ps_voiceRoomOverrideChanged); + connect(ui->le_CockpitVoiceRoomCom1, &QLineEdit::returnPressed, this, &CVoiceRoomsComponent::ps_voiceRoomUrlsReturnPressed); } CVoiceRoomsComponent::~CVoiceRoomsComponent() { } + void CVoiceRoomsComponent::runtimeHasBeenSet() + { + this->connect(this->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CVoiceRoomsComponent::ps_updateAudioVoiceRoomsFromContext); + } + + void CVoiceRoomsComponent::ps_voiceRoomOverrideChanged(bool checked) + { + Q_UNUSED(checked); + this->setVoiceRoomUrlFields(); + } + + void CVoiceRoomsComponent::ps_voiceRoomUrlsReturnPressed() + { + + } + + void CVoiceRoomsComponent::setVoiceRoomUrlFields() + { + bool c1 = ui->cb_CockpitVoiceRoom1Override->isChecked(); + bool c2 = ui->cb_CockpitVoiceRoom2Override->isChecked(); + this->ui->le_CockpitVoiceRoomCom1->setReadOnly(!c1); + this->ui->le_CockpitVoiceRoomCom2->setReadOnly(!c2); + } + + void CVoiceRoomsComponent::ps_updateAudioVoiceRoomsFromContext(const CVoiceRoomList &selectedVoiceRooms, bool connected) + { + Q_ASSERT(selectedVoiceRooms.size() == 2); + CVoiceRoom room1 = selectedVoiceRooms[0]; + CVoiceRoom room2 = selectedVoiceRooms[1]; + + // remark + // isAudioPlaying() is not set, as this is only a temporary value when really "something is playing" + + bool changedUrl1 = (room1.getVoiceRoomUrl() == this->ui->le_CockpitVoiceRoomCom1->text()); + this->ui->le_CockpitVoiceRoomCom1->setText(room1.getVoiceRoomUrl()); + if (room1.isConnected()) + { + this->ui->le_CockpitVoiceRoomCom1->setStyleSheet("background: green"); + if (this->getIContextAudio()) this->ui->tvp_CockpitVoiceRoom1->updateContainer(this->getIContextAudio()->getCom1RoomUsers()); + } + else + { + this->ui->le_CockpitVoiceRoomCom1->setStyleSheet(""); + this->ui->tvp_CockpitVoiceRoom1->clear(); + } + + bool changedUrl2 = (room2.getVoiceRoomUrl() == this->ui->le_CockpitVoiceRoomCom2->text()); + this->ui->le_CockpitVoiceRoomCom2->setText(room2.getVoiceRoomUrl()); + if (room2.isConnected()) + { + this->ui->le_CockpitVoiceRoomCom2->setStyleSheet("background: green"); + } + else + { + this->ui->le_CockpitVoiceRoomCom2->setStyleSheet(""); + this->ui->tvp_CockpitVoiceRoom2->clear(); + } + if (changedUrl1 || changedUrl2) + { + this->updateVoiceRoomMembers(); + + // notify + if (this->getIContextAudio()) + { + CNotificationSounds::Notification sound = connected ? + CNotificationSounds::NotificationVoiceRoomJoined : + CNotificationSounds::NotificationVoiceRoomLeft; + this->getIContextAudio()->playNotification(static_cast(sound), true); + } + } + } + + void CVoiceRoomsComponent::updateVoiceRoomMembers() + { + if (!this->getIContextAudio()) return; + if (!this->ui->le_CockpitVoiceRoomCom1->text().trimmed().isEmpty()) + { + this->ui->tvp_CockpitVoiceRoom1->updateContainer(this->getIContextAudio()->getCom1RoomUsers()); + } + else + { + this->ui->tvp_CockpitVoiceRoom1->clear(); + } + + if (!this->ui->le_CockpitVoiceRoomCom2->text().trimmed().isEmpty()) + { + this->ui->tvp_CockpitVoiceRoom2->updateContainer(this->getIContextAudio()->getCom2RoomUsers()); + } + else + { + this->ui->tvp_CockpitVoiceRoom2->clear(); + } + } + } // namespace } // namespace diff --git a/src/blackgui/components/voiceroomscomponent.h b/src/blackgui/components/voiceroomscomponent.h index 56ff2ef26..4f47626aa 100644 --- a/src/blackgui/components/voiceroomscomponent.h +++ b/src/blackgui/components/voiceroomscomponent.h @@ -12,6 +12,8 @@ #ifndef BLACKGUI_VOICEROOMSCOMPONENT_H #define BLACKGUI_VOICEROOMSCOMPONENT_H +#include "enableforruntime.h" +#include "blackmisc/voiceroomlist.h" #include #include @@ -23,7 +25,8 @@ namespace BlackGui { //! Displays the voice rooms class CVoiceRoomsComponent : - public QFrame + public QFrame, + public CEnableForRuntime { Q_OBJECT @@ -34,7 +37,28 @@ namespace BlackGui //! Destructor ~CVoiceRoomsComponent(); + protected: + //! \copydoc CEnableForRuntime::runtimeHasBeenSet + virtual void runtimeHasBeenSet() override; + + private slots: + //! Override for voice was changed + void ps_voiceRoomOverrideChanged(bool checked); + + //! Return pressed + void ps_voiceRoomUrlsReturnPressed(); + + //! set the voice room url fields (checkboxes, line edits) + void ps_updateAudioVoiceRoomsFromContext(const BlackMisc::Audio::CVoiceRoomList &selectedVoiceRooms, bool connected); + private: + //! Set the URL fields + void setVoiceRoomUrlFields(); + + //! Update voice room views + void updateVoiceRoomMembers(); + + QScopedPointer ui; }; diff --git a/src/blackgui/components/voiceroomscomponent.ui b/src/blackgui/components/voiceroomscomponent.ui index d9bab15f2..975ad7c24 100644 --- a/src/blackgui/components/voiceroomscomponent.ui +++ b/src/blackgui/components/voiceroomscomponent.ui @@ -6,12 +6,12 @@ 0 0 - 400 - 300 + 522 + 226 - Frame + Voice rooms QFrame::StyledPanel @@ -19,7 +19,7 @@ QFrame::Raised - + 0 @@ -38,8 +38,8 @@ - - + + 2 @@ -57,6 +57,12 @@ + + + 0 + 0 + + 75 @@ -69,8 +75,14 @@ - + + + + 0 + 0 + + Ovr. @@ -80,8 +92,8 @@ - - + + 2 @@ -99,6 +111,12 @@ + + + 0 + 0 + + 75 @@ -111,7 +129,7 @@ - + Ovr. @@ -123,6 +141,12 @@ + + + 0 + 0 + + QAbstractItemView::SingleSelection @@ -136,6 +160,12 @@ + + + 0 + 0 + + QAbstractItemView::SingleSelection