6 #include <QStringBuilder>
17 using namespace swift::misc::aviation;
18 using namespace swift::misc::physical_quantities;
22 namespace swift::misc::network
25 : m_senderCallsign(senderCallsign), m_frequency(frequency)
33 : m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(0, nullptr)
42 return m_message % u
' ' % m_senderCallsign.
toQString(i18n) % u
' ' % m_recipientCallsign.
toQString(i18n);
44 return m_message % u
' ' % m_frequency.
toQString(i18n);
49 static const QString s(
"swift relayed: ");
55 return !m_senderCallsign.
isEmpty() && !m_recipientCallsign.
isEmpty();
87 m_recipientCallsign.
setTypeHint(CCallsign::Aircraft);
90 m_message = newMessage;
96 const int index = m_message.
indexOf(
';');
98 if (m_message.
length() <= index + 1) {
return false; }
101 if (sr.
size() != 2) {
return false; }
106 m_message = m_message.
mid(index + 1);
112 if (textMessage.
isEmpty()) {
return false; }
129 if (textMessage.
isEmpty()) {
return false; }
137 if (!m_recipientCallsign.
isEmpty()) {
return m_recipientCallsign.
asString(); }
138 if (m_frequency.
isNull()) {
return {}; }
145 return m_frequency == frequency;
155 if (!m_recipientCallsign.
isEmpty()) {
return true; }
156 return CComSystem::isValidCivilAviationFrequency(m_frequency);
161 if (callsign.
isEmpty()) {
return false; }
168 if (m_message.
isEmpty()) {
return {}; }
174 if (m_message.
isEmpty()) {
return {}; }
206 if (!m_senderCallsign.
isEmpty())
214 if (!m_recipientCallsign.
isEmpty())
220 if (CComSystem::isValidCivilAviationFrequency(m_frequency))
227 if (m_message.
isEmpty()) {
return s; }
228 if (!s.
isEmpty()) { s += separator % m_message; }
234 const QString m = this->
asString(withSender, withRecipient, separator);
240 return this->
asString(
true,
true, separator);
248 if (this->
isEmpty()) {
return false; }
259 if (!CSelcal::isValidCode(selcal))
return false;
270 if (this->
isEmpty())
return {};
277 if (candidate.
length() != 10)
return {};
319 case IndexMessage: m_message = variant.
value<
QString>();
break;
333 case IndexSenderCallsign:
335 case IndexRecipientCallsign:
338 case IndexRecipientCallsignOrFrequency:
344 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No comparison");
Value object for icons. An icon is stored in the global icon repository and identified by its index....
QPixmap toPixmap() const
Corresponding pixmap.
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
Streamable status message, e.g.
constexpr static auto SeverityInfo
Status severities.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
int comparePropertyByIndex(CPropertyIndexRef index, const ITimestampBased &compareValue) const
Compare for index.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
void setCurrentUtcTime()
Set the current time as timestamp.
QString getFormattedUtcTimestampHms() const
As hh:mm:ss.
bool hasValidTimestamp() const
Valid timestamp?
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Value object encapsulating information of a callsign.
int comparePropertyByIndex(CPropertyIndexRef index, const CCallsign &compareValue) const
Compare for index.
const QString & asString() const
Get callsign (normalized)
CIcons::IconIndex toIcon() const
As icon, not implemented by all classes.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool isSupervisorCallsign() const
Supervisor?
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isEmpty() const
Is empty?
void setTypeHint(TypeHint hint)
Type hint.
bool isBroadcastCallsign() const
Pseudo callsing for broadcast messages.
const QString & getStringAsSet() const
Get callsign.
ColumnIndex
Base class enums.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating information of a text message.
QString getHtmlEncodedMessage() const
Get HTML escaped message.
int comparePropertyByIndex(CPropertyIndexRef index, const CTextMessage &compareValue) const
Compare for index.
void markAsSent()
Mark as sent.
bool isRelayedMessage() const
Is relayed message.
bool relayedMessageToPrivateMessage()
Turn relayed message into private message.
void setMessage(const QString &message)
Set message.
bool isWallopMessage() const
Is this a message send via .wallop.
bool isPrivateMessage() const
Is private message?
bool mentionsCallsign(const aviation::CCallsign &callsign) const
Is the callsign given mentioned in that message.
void setSenderCallsign(const aviation::CCallsign &callsign)
Set callsign (from)
bool isSelcalMessageFor(const QString &selcal) const
Is this a text message encapsulating a SELCAL for given code?
CIcons::IconIndex toIcon() const
As icon, not implement by all classes.
QString getRecipientCallsignOrFrequency() const
Get recipient or frequency.
QString getSelcalCode() const
Get SELCAL code (if applicable, e.g. ABCD), otherwise "".
bool isBroadcastMessage() const
Is this a broadcast message.
QString asHtmlSummary(const QString &separator="<br>") const
Summary HTML code.
void markAsRelayedMessage()
Mark as relayed message.
bool isEmpty() const
Empty message.
const QString & getMessage() const
Get message.
bool canBeAppended(const CTextMessage &textMessage) const
Can another message be appended.
bool isSendToUnicom() const
Send to UNICOM?
QString asString(bool withSender, bool withRecipient, const QString &separator=", ") const
Whole message as formatted string. Used to display message in a console window.
void setRecipientCallsign(const aviation::CCallsign &callsign)
Set callsign (recipient)
bool isServerMessage() const
Initial message of server?
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
bool hasValidRecipient() const
Valid receviver?
QPixmap toPixmap() const
As pixmap, required for most GUI views.
bool isSendToFrequency(const physical_quantities::CFrequency &frequency) const
Send to particular frequency?
void makeRelayedMessage(const aviation::CCallsign &partnerCallsign)
Mark as relayed and keep original sender.
CStatusMessage asStatusMessage(bool withSender, bool withRecipient, const QString &separator=", ") const
Whole message as swift::misc::CStatusMessage. Used to display message in logs, or any other situation...
const aviation::CCallsign & getSenderCallsign() const
Get callsign (from)
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
const aviation::CCallsign & getRecipientCallsign() const
Get callsign (to)
void toggleSenderRecipient()
Toggle sender receiver, can be used to ping my own message.
static const QString & swiftRelayMessage()
swift relay message marker
void markAsBroadcastMessage()
Mark as broadcast message.
CTextMessage()
Default constructor.
bool isRadioMessage() const
Is radio message?
QString getAsciiOnlyMessage() const
Get ASCII only message.
const physical_quantities::CFrequency & getFrequency() const
Get frequency.
bool isSelcalMessage() const
Is this a text message encapsulating a SELCAL.
bool appendIfPossible(const CTextMessage &textMessage)
Append if possible.
bool isSupervisorMessage() const
Supervisor message?
QString convertToQString(bool i18n=false) const
Cast as QString.
static CFrequencyUnit MHz()
Megahertz.
PQ & switchUnit(const MU &newUnit)
Change unit, and convert value to maintain the same quantity.
bool isNull() const
Is quantity null?
int compare(const PQ &other) const
Compare with other PQ.
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
QString removeChars(const QString &s, F predicate)
Return a string with characters removed that match the given predicate.
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate)
Remove accents / diacritic marks from a string.
QString asciiOnlyString(const QString &string)
String only with ASCII values.
void swap(Optional< T > &a, Optional< T > &b) noexcept(std::is_nothrow_swappable_v< T >)
Efficient swap for two Optional objects.
bool isLetter(char32_t ucs4)
qsizetype size() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString right(qsizetype n) &&
QString simplified() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString toHtmlEscaped() const const
QString toUpper() const const
QString trimmed() const const
QVariant fromValue(T &&value)
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.