swift
Loading...
Searching...
No Matches
textmessage.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_NETWORK_TEXTMESSAGE_H
7#define SWIFT_MISC_NETWORK_TEXTMESSAGE_H
8
9#include <QMetaType>
10#include <QPixmap>
11#include <QString>
12
14#include "misc/metaclass.h"
15#include "misc/pq/frequency.h"
16#include "misc/pq/units.h"
18#include "misc/statusmessage.h"
20#include "misc/timestampbased.h"
21#include "misc/valueobject.h"
22
23SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::network, CTextMessage)
24
25namespace swift::misc::network
26{
30 class SWIFT_MISC_EXPORT CTextMessage : public CValueObject<CTextMessage>, public ITimestampBased
31 {
32 public:
35 {
36 IndexSenderCallsign = CPropertyIndexRef::GlobalIndexCTextMessage,
37 IndexRecipientCallsign,
38 IndexRecipientCallsignOrFrequency,
39 IndexMessage
40 };
41
43 CTextMessage() = default;
44
46 CTextMessage(const QString &message, const physical_quantities::CFrequency &frequency,
47 const aviation::CCallsign &senderCallsign = {});
48
50 CTextMessage(const QString &message, const aviation::CCallsign &senderCallsign,
51 const aviation::CCallsign &recipientCallsign = {});
52
54 const aviation::CCallsign &getSenderCallsign() const { return m_senderCallsign; }
55
57 void setSenderCallsign(const aviation::CCallsign &callsign) { m_senderCallsign = callsign; }
58
60 const aviation::CCallsign &getRecipientCallsign() const { return m_recipientCallsign; }
61
63 void setRecipientCallsign(const aviation::CCallsign &callsign) { m_recipientCallsign = callsign; }
64
66 QString getRecipientCallsignOrFrequency() const;
67
69 bool isSendToFrequency(const physical_quantities::CFrequency &frequency) const;
70
72 bool isSendToUnicom() const;
73
75 bool hasValidRecipient() const;
76
78 const QString &getMessage() const { return m_message; }
79
81 bool mentionsCallsign(const aviation::CCallsign &callsign) const;
82
84 QString getAsciiOnlyMessage() const;
85
87 QString getHtmlEncodedMessage() const;
88
90 bool isEmpty() const { return m_message.isEmpty(); }
91
93 void setMessage(const QString &message);
94
96 const physical_quantities::CFrequency &getFrequency() const { return m_frequency; }
97
99 void setFrequency(const physical_quantities::CFrequency &frequency) { m_frequency = frequency; }
100
102 bool isPrivateMessage() const;
103
105 bool isRadioMessage() const;
106
108 bool isServerMessage() const;
109
111 bool isBroadcastMessage() const;
112
114 bool isWallopMessage() const;
115
120 QString asString(bool withSender, bool withRecipient, const QString &separator = ", ") const;
121
127 CStatusMessage asStatusMessage(bool withSender, bool withRecipient, const QString &separator = ", ") const;
128
130 QString asHtmlSummary(const QString &separator = "<br>") const;
131
133 void toggleSenderRecipient();
134
137 bool isSelcalMessage() const;
138
140 bool isSelcalMessageFor(const QString &selcal) const;
141
143 bool isSupervisorMessage() const;
144
146 bool wasSent() const { return m_wasSent; }
147
150 void markAsSent();
151
153 bool isRelayedMessage() const;
154
156 void markAsRelayedMessage() { m_relayedMessage = true; }
157
159 void markAsBroadcastMessage();
160
162 void makeRelayedMessage(const aviation::CCallsign &partnerCallsign);
163
165 bool relayedMessageToPrivateMessage();
166
168 bool canBeAppended(const CTextMessage &textMessage) const;
169
171 bool appendIfPossible(const CTextMessage &textMessage);
172
174 QString getSelcalCode() const;
175
177 CIcons::IconIndex toIcon() const;
178
180 QPixmap toPixmap() const;
181
183 QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
184
186 void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
187
189 int comparePropertyByIndex(CPropertyIndexRef index, const CTextMessage &compareValue) const;
190
192 QString convertToQString(bool i18n = false) const;
193
195 static const QString &swiftRelayMessage();
196
197 private:
198 QString m_message;
199 aviation::CCallsign m_senderCallsign;
200 aviation::CCallsign m_recipientCallsign;
201 physical_quantities::CFrequency m_frequency { 0, nullptr };
202 bool m_wasSent = false;
203 bool m_relayedMessage = false;
204
206 CTextMessage,
207 SWIFT_METAMEMBER(message),
208 SWIFT_METAMEMBER(timestampMSecsSinceEpoch),
209 SWIFT_METAMEMBER(senderCallsign),
210 SWIFT_METAMEMBER(recipientCallsign),
211 SWIFT_METAMEMBER(frequency));
212 };
213} // namespace swift::misc::network
214
215Q_DECLARE_METATYPE(swift::misc::network::CTextMessage)
216
217#endif // SWIFT_MISC_NETWORK_TEXTMESSAGE_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition icons.h:32
Non-owning reference to a CPropertyIndex with a subset of its features.
Streamable status message, e.g.
ITimestampBased()=default
Constructor.
Value object encapsulating information of a callsign.
Definition callsign.h:30
Value object encapsulating information of a text message.
Definition textmessage.h:31
void setSenderCallsign(const aviation::CCallsign &callsign)
Set callsign (from).
Definition textmessage.h:57
const QString & getMessage() const
Get message.
Definition textmessage.h:78
void markAsRelayedMessage()
Mark as relayed message.
bool isEmpty() const
Empty message.
Definition textmessage.h:90
void setRecipientCallsign(const aviation::CCallsign &callsign)
Set callsign (recipient).
Definition textmessage.h:63
const physical_quantities::CFrequency & getFrequency() const
Get frequency.
Definition textmessage.h:96
bool wasSent() const
Was sent?
void setFrequency(const physical_quantities::CFrequency &frequency)
Set frequency.
Definition textmessage.h:99
ColumnIndex
Properties by index.
Definition textmessage.h:35
const aviation::CCallsign & getRecipientCallsign() const
Get callsign (to).
Definition textmessage.h:60
CTextMessage()=default
Default constructor.
const aviation::CCallsign & getSenderCallsign() const
Get callsign (from).
Definition textmessage.h:54
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition valueobject.h:65