6#include <QStringBuilder>
17using namespace swift::misc::aviation;
18using namespace swift::misc::physical_quantities;
22namespace 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();
67 return m_senderCallsign.isSupervisorCallsign();
96 m_recipientCallsign.setTypeHint(CCallsign::Aircraft);
99 m_message = newMessage;
108 const int index = m_message.
indexOf(
';');
113 if (m_message.length() <= index + 1)
127 m_message = m_message.mid(index + 1);
168 if (!m_recipientCallsign.isEmpty())
170 return m_recipientCallsign.asString();
172 if (m_frequency.isNull())
185 return m_frequency == frequency;
195 if (!m_recipientCallsign.isEmpty())
217 if (m_message.isEmpty())
226 if (m_message.isEmpty())
264 if (!m_senderCallsign.isEmpty())
268 s += separator % m_senderCallsign.getStringAsSet();
275 if (!m_recipientCallsign.isEmpty())
279 s += separator % m_recipientCallsign.getStringAsSet();
288 s += separator % m_frequency.valueRoundedWithUnit(3,
true);
294 if (m_message.isEmpty())
300 s += separator % m_message;
307 const QString m = this->
asString(withSender, withRecipient, separator);
313 return this->
asString(
true,
true, separator);
329 if (m_message.length() > 15 || m_message.length() < 10)
349 if (this->
isEmpty())
return {};
352 if (m_message.length() > 15 || m_message.length() < 10)
356 if (candidate.
length() != 10)
return {};
378 case IndexSenderCallsign:
return m_senderCallsign.propertyByIndex(index.
copyFrontRemoved());
379 case IndexRecipientCallsign:
return m_recipientCallsign.propertyByIndex(index.
copyFrontRemoved());
402 case IndexSenderCallsign: m_senderCallsign.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
403 case IndexRecipientCallsign: m_recipientCallsign.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
404 case IndexMessage: m_message = variant.
value<
QString>();
break;
418 case IndexSenderCallsign:
420 case IndexRecipientCallsign:
423 case IndexRecipientCallsignOrFrequency:
432 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No comparison");
static CFrequencyUnit MHz()
Megahertz.
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.
static constexpr 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.
const QString & asString() const
Get callsign (normalized).
const QString & getStringAsSet() const
Get callsign.
bool isEmpty() const
Is empty?
bool isBroadcastCallsign() const
Pseudo callsing for broadcast messages.
static bool isValidCivilAviationFrequency(const physical_quantities::CFrequency &f)
Valid civil aviation frequency?
static bool isValidCode(const QString &code)
Valid SELCAL code?
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 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?
const QString & getMessage() const
Get message.
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.
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.
const physical_quantities::CFrequency & getFrequency() const
Get frequency.
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...
ColumnIndex
Properties by index.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void toggleSenderRecipient()
Toggle sender receiver, can be used to ping my own message.
const aviation::CCallsign & getRecipientCallsign() const
Get callsign (to).
static const QString & swiftRelayMessage()
swift relay message marker
void markAsBroadcastMessage()
Mark as broadcast message.
bool isRadioMessage() const
Is radio message?
QString getAsciiOnlyMessage() const
Get ASCII only message.
bool isSelcalMessage() const
Is this a text message encapsulating a SELCAL.
CTextMessage()=default
Default constructor.
bool appendIfPossible(const CTextMessage &textMessage)
Append if possible.
bool isSupervisorMessage() const
Supervisor message?
QString convertToQString(bool i18n=false) const
Cast as QString.
const aviation::CCallsign & getSenderCallsign() const
Get callsign (from).
static CFrequencyUnit MHz()
Megahertz.
static const CFrequency & FrequencyUnicom()
Unicom frequency.
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.
bool isLetter(char32_t ucs4)
qsizetype size() 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 & 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.