Ref T739, removed voice room value objects

This commit is contained in:
Klaus Basan
2019-10-04 23:50:11 +02:00
committed by Mat Sutcliffe
parent 09e65a2525
commit 7e36e67f89
12 changed files with 1 additions and 374 deletions

View File

@@ -18,8 +18,6 @@
#include "blackmisc/audio/audiodeviceinfo.h"
#include "blackmisc/audio/audiodeviceinfolist.h"
#include "blackmisc/audio/voiceroom.h"
#include "blackmisc/audio/voiceroomlist.h"
#include "blackmisc/audio/audiosettings.h"
#include "blackmisc/audio/voicesetup.h"

View File

@@ -20,8 +20,6 @@ namespace BlackMisc
{
CAudioDeviceInfo::registerMetadata();
CAudioDeviceInfoList::registerMetadata();
CVoiceRoom::registerMetadata();
CVoiceRoomList::registerMetadata();
CSettings::registerMetadata();
CVoiceSetup::registerMetadata();

View File

@@ -1,100 +0,0 @@
/* Copyright (C) 2013
* 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 "blackmisc/audio/voiceroom.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/variant.h"
#include <QStringList>
#include <QStringBuilder>
#include <Qt>
namespace BlackMisc
{
namespace Audio
{
CVoiceRoom::CVoiceRoom(const QString &voiceRoomUrl, bool connected) :
m_connected(connected), m_audioPlaying(false)
{
this->setVoiceRoomUrl(voiceRoomUrl);
}
CVariant CVoiceRoom::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAudioPlaying: return CVariant::from(this->isAudioPlaying());
case IndexConnected: return CVariant::from(this->isConnected());
case IndexChannel: return CVariant::from(this->getChannel());
case IndexHostname: return CVariant::from(this->getHostname());
case IndexUrl: return CVariant::from(this->getVoiceRoomUrl());
default: return CValueObject::propertyByIndex(index);
}
}
void CVoiceRoom::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CVoiceRoom>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAudioPlaying: this->setAudioPlaying(variant.toBool()); break;
case IndexConnected: this->setConnected(variant.toBool()); break;
case IndexChannel: this->setChannel(variant.value<QString>()); break;
case IndexHostname: this->setHostName(variant.value<QString>()); break;
case IndexUrl: this->setVoiceRoomUrl(variant.value<QString>()); break;
default: CValueObject::setPropertyByIndex(index, variant); break;
}
}
QString CVoiceRoom::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
if (!this->isValid()) { return QStringLiteral("Invalid"); }
return this->getVoiceRoomUrl(false) %
(this->isConnected() ? u" connected" : u" unconnected") %
(m_audioPlaying ? u" playing" : u"");
}
QString CVoiceRoom::getVoiceRoomUrl(bool noProtocol) const
{
if (!this->isValid()) { return {}; }
return (noProtocol ? QStringLiteral("") : CVoiceRoom::protocolComplete()) % m_hostname % u"/" % m_channel;
}
void CVoiceRoom::setVoiceRoomUrl(const QString &serverUrl)
{
if (serverUrl.isEmpty())
{
m_hostname.clear();
m_channel.clear();
}
else if (serverUrl.contains("/"))
{
QString url = serverUrl.trimmed().toLower();
url.replace(CVoiceRoom::protocolComplete(), "");
url.replace(CVoiceRoom::protocol(), "");
const QStringList splitParts = url.split("/");
m_hostname = splitParts.at(0);
m_channel = splitParts.at(1);
}
}
bool CVoiceRoom::isAtis() const
{
return (m_channel.contains("ATIS", Qt::CaseInsensitive));
}
bool CVoiceRoom::canTalkTo() const
{
return this->isConnected() && !this->isAtis();
}
} // ns
} // ns

View File

@@ -1,126 +0,0 @@
/* Copyright (C) 2013
* 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.
*/
//! \file
#ifndef BLACKMISC_AUDIO_VOICEROOM_H
#define BLACKMISC_AUDIO_VOICEROOM_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/metaclass.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/variant.h"
#include <QMetaType>
#include <QString>
namespace BlackMisc
{
namespace Audio
{
//! Value object encapsulating information of a voice room
class BLACKMISC_EXPORT CVoiceRoom : public CValueObject<CVoiceRoom>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexHostname = CPropertyIndex::GlobalIndexCVoiceRoom,
IndexChannel,
IndexUrl,
IndexConnected,
IndexAudioPlaying
};
//! Default constructor.
CVoiceRoom() : m_connected(false), m_audioPlaying(false) {}
//! Constructor.
CVoiceRoom(const QString &hostname, const QString &channel) :
m_hostname(hostname), m_channel(channel), m_connected(false), m_audioPlaying(false) {}
//! Constructor.
CVoiceRoom(const QString &voiceRoomUrl, bool connected = false);
//! Get the host name
const QString &getHostname() const { return m_hostname; }
//! Get the voice room channel
const QString &getChannel() const { return m_channel; }
//! Set the host name
void setHostName(const QString &hostName) { m_hostname = hostName; }
//! Set the voice channel
void setChannel(const QString &channel) { m_channel = channel; }
//! Server URL
//! \param noProtocol either with (pseudo) protocol prefix or without
QString getVoiceRoomUrl(bool noProtocol = true) const;
//! Set voice room URL
void setVoiceRoomUrl(const QString &serverUrl);
//! Valid voice room object?
bool isValid() const { return !m_hostname.isEmpty() && !m_channel.isEmpty(); }
//! Is connected?
bool isConnected() const { return this->isValid() && m_connected; }
//! Set connection status
void setConnected(bool isConnected) { m_connected = isConnected; }
//! Is audio playing in this room?
bool isAudioPlaying() const { return m_audioPlaying; }
//! Set audio 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;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
//! Protocol prefix "vvl"
static const QString &protocol() { static QString p("vvl"); return p; }
//! Protocol
//! \return with protocol prefix or without
static const QString &protocolComplete() { static QString p("vvl://"); return p; }
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
private:
QString m_hostname;
QString m_channel;
bool m_connected;
bool m_audioPlaying;
BLACK_METACLASS(
CVoiceRoom,
BLACK_METAMEMBER(hostname),
BLACK_METAMEMBER(channel),
BLACK_METAMEMBER(connected),
BLACK_METAMEMBER(audioPlaying)
);
};
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Audio::CVoiceRoom)
#endif // guard

View File

@@ -1,48 +0,0 @@
/* Copyright (C) 2013
* 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 "blackmisc/audio/voiceroom.h"
#include "blackmisc/audio/voiceroomlist.h"
#include <QString>
#include <tuple>
namespace BlackMisc
{
namespace Audio
{
CVoiceRoomList::CVoiceRoomList() { }
CVoiceRoomList::CVoiceRoomList(const CSequence &other) :
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;
if (emptyRooms.isEmpty())
{
emptyRooms.push_back(CVoiceRoom());
emptyRooms.push_back(CVoiceRoom());
}
return emptyRooms;
}
} // namespace
} // namespace

View File

@@ -1,57 +0,0 @@
/* Copyright (C) 2013
* 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.
*/
//! \file
#ifndef BLACKMISC_AUDIO_VOICEROOMLIST_H
#define BLACKMISC_AUDIO_VOICEROOMLIST_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
#include "blackmisc/variant.h"
#include "voiceroom.h"
#include <QMetaType>
namespace BlackMisc
{
namespace Audio
{
class CVoiceRoom;
//! Value object encapsulating a list of voice rooms.
class BLACKMISC_EXPORT CVoiceRoomList :
public CSequence<CVoiceRoom>,
public BlackMisc::Mixin::MetaType<CVoiceRoomList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CVoiceRoomList)
using CSequence::CSequence;
//! Default constructor.
CVoiceRoomList();
//! 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();
};
} //namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Audio::CVoiceRoomList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Audio::CVoiceRoom>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Audio::CVoiceRoom>)
#endif //guard