diff --git a/src/blackmisc/audio/voiceroom.cpp b/src/blackmisc/audio/voiceroom.cpp index 4101dc088..f318b6925 100644 --- a/src/blackmisc/audio/voiceroom.cpp +++ b/src/blackmisc/audio/voiceroom.cpp @@ -91,5 +91,10 @@ namespace BlackMisc { return (m_channel.contains("ATIS", Qt::CaseInsensitive)); } + + bool CVoiceRoom::canTalkTo() const + { + return this->isConnected() && !this->isAtis(); + } } // ns } // ns diff --git a/src/blackmisc/audio/voiceroom.h b/src/blackmisc/audio/voiceroom.h index a1fb8ac50..030f84d6e 100644 --- a/src/blackmisc/audio/voiceroom.h +++ b/src/blackmisc/audio/voiceroom.h @@ -31,7 +31,7 @@ namespace BlackMisc //! Properties by index enum ColumnIndex { - IndexHostname = BlackMisc::CPropertyIndex::GlobalIndexCVoiceRoom, + IndexHostname = CPropertyIndex::GlobalIndexCVoiceRoom, IndexChannel, IndexUrl, IndexConnected, @@ -68,23 +68,26 @@ namespace BlackMisc void setVoiceRoomUrl(const QString &serverUrl); //! Valid voice room object? - bool isValid() const { return !this->m_hostname.isEmpty() && !this->m_channel.isEmpty(); } + bool isValid() const { return !m_hostname.isEmpty() && !m_channel.isEmpty(); } //! Is connected? - bool isConnected() const { return this->isValid() && this->m_connected; } + bool isConnected() const { return this->isValid() && m_connected; } //! Set connection status - void setConnected(bool isConnected) { this->m_connected = isConnected; } + void setConnected(bool isConnected) { m_connected = isConnected; } //! Is audio playing in this room? - bool isAudioPlaying() const { return this->m_audioPlaying; } + bool isAudioPlaying() const { return m_audioPlaying; } //! Set audio playing - void setAudioPlaying(bool playing) { this->m_audioPlaying = playing; } + void setAudioPlaying(bool playing) { m_audioPlaying = playing; } //! Is ATIS voice channel bool isAtis() const; + //! Can talk to channel + bool canTalkTo() const; + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; @@ -115,8 +118,8 @@ namespace BlackMisc BLACK_METAMEMBER(audioPlaying) ); }; - } // Voice -} // BlackMisc + } // ns +} // ns Q_DECLARE_METATYPE(BlackMisc::Audio::CVoiceRoom) diff --git a/src/blackmisc/audio/voiceroomlist.cpp b/src/blackmisc/audio/voiceroomlist.cpp index 4b3bac65c..76ea62fa0 100644 --- a/src/blackmisc/audio/voiceroomlist.cpp +++ b/src/blackmisc/audio/voiceroomlist.cpp @@ -23,6 +23,16 @@ namespace BlackMisc CSequence(other) { } + int CVoiceRoomList::countCanTalkTo() const + { + int c = 0; + for (const CVoiceRoom &r : *this) + { + if (r.canTalkTo()) { c++; } + } + return c; + } + const CVoiceRoomList &CVoiceRoomList::twoEmptyRooms() { static CVoiceRoomList emptyRooms; diff --git a/src/blackmisc/audio/voiceroomlist.h b/src/blackmisc/audio/voiceroomlist.h index d7bba4f53..1cc464563 100644 --- a/src/blackmisc/audio/voiceroomlist.h +++ b/src/blackmisc/audio/voiceroomlist.h @@ -39,6 +39,9 @@ namespace BlackMisc //! Construct from a base class object. CVoiceRoomList(const CSequence &other); + //! Count how many rooms can be talked to + int countCanTalkTo() const; + //! Frequently needed for voice room resolutions static const CVoiceRoomList &twoEmptyRooms(); };