mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Added received timestamp. Taken renaming to sender /recipient
one step further. getSender will be used later to return the real CUser object
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/pqconstants.h"
|
||||
#include "blackmisc/aviocomsystem.h"
|
||||
#include "blackmisc/avcallsign.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -15,8 +18,8 @@ namespace BlackMisc
|
||||
QString s(this->m_message);
|
||||
if (this->isPrivateMessage())
|
||||
{
|
||||
s.append(" ").append(this->m_sender.toQString(i18n));
|
||||
s.append(" ").append(this->m_recipient.toQString(i18n));
|
||||
s.append(" ").append(this->m_senderCallsign.toQString(i18n));
|
||||
s.append(" ").append(this->m_recipientCallsign.toQString(i18n));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -30,10 +33,11 @@ namespace BlackMisc
|
||||
*/
|
||||
void CTextMessage::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << this->m_sender;
|
||||
argument << this->m_recipient;
|
||||
argument << this->m_senderCallsign;
|
||||
argument << this->m_recipientCallsign;
|
||||
argument << this->m_message;
|
||||
argument << this->m_frequency;
|
||||
argument << this->m_received;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -41,10 +45,11 @@ namespace BlackMisc
|
||||
*/
|
||||
void CTextMessage::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> this->m_sender;
|
||||
argument >> this->m_recipient;
|
||||
argument >> this->m_senderCallsign;
|
||||
argument >> this->m_recipientCallsign;
|
||||
argument >> this->m_message;
|
||||
argument >> this->m_frequency;
|
||||
argument >> this->m_received;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -52,7 +57,7 @@ namespace BlackMisc
|
||||
*/
|
||||
bool CTextMessage::isPrivateMessage() const
|
||||
{
|
||||
return !this->m_sender.isEmpty() && !this->m_recipient.isEmpty();
|
||||
return !this->m_senderCallsign.isEmpty() && !this->m_recipientCallsign.isEmpty();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -77,7 +82,7 @@ namespace BlackMisc
|
||||
*/
|
||||
bool CTextMessage::hasValidRecipient() const
|
||||
{
|
||||
if (!this->m_recipient.isEmpty()) return true;
|
||||
if (!this->m_recipientCallsign.isEmpty()) return true;
|
||||
return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency);
|
||||
}
|
||||
|
||||
@@ -89,26 +94,37 @@ namespace BlackMisc
|
||||
return (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency));
|
||||
}
|
||||
|
||||
/*
|
||||
* Initial server message?
|
||||
*/
|
||||
bool CTextMessage::isServerMessage() const
|
||||
{
|
||||
if (!this->isPrivateMessage()) return false;
|
||||
CCallsign cs = this->getSenderCallsign();
|
||||
return (cs.asString().startsWith("SERVER", Qt::CaseInsensitive));
|
||||
}
|
||||
|
||||
/*
|
||||
* Formatted string
|
||||
*/
|
||||
QString CTextMessage::asString(bool withSender, bool withRecipient, const QString separator) const
|
||||
{
|
||||
QString s;
|
||||
QString s = this->receivedTime();
|
||||
if (withSender)
|
||||
{
|
||||
if (!this->m_sender.isEmpty())
|
||||
if (!this->m_senderCallsign.isEmpty())
|
||||
{
|
||||
s.append(this->m_sender.getStringAsSet());
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_senderCallsign.getStringAsSet());
|
||||
}
|
||||
}
|
||||
|
||||
if (withRecipient)
|
||||
{
|
||||
if (!this->m_recipient.isEmpty())
|
||||
if (!this->m_recipientCallsign.isEmpty())
|
||||
{
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_recipient.getStringAsSet());
|
||||
s.append(this->m_recipientCallsign.getStringAsSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,8 +133,9 @@ namespace BlackMisc
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_frequency.valueRoundedWithUnit(3, true));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // to
|
||||
|
||||
if (this->m_message.isEmpty()) return s;
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
@@ -131,7 +148,9 @@ namespace BlackMisc
|
||||
*/
|
||||
void CTextMessage::toggleSenderRecipient()
|
||||
{
|
||||
qSwap(this->m_sender, this->m_recipient);
|
||||
BlackMisc::Aviation::CCallsign csOldFrom(this->getSenderCallsign());
|
||||
this->setSenderCallsign(this->getRecipientCallsign());
|
||||
this->setRecipientCallsign(csOldFrom);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -157,10 +176,11 @@ namespace BlackMisc
|
||||
uint CTextMessage::getValueHash() const
|
||||
{
|
||||
QList<uint> hashs;
|
||||
hashs << qHash(this->m_sender);
|
||||
hashs << qHash(this->m_recipient);
|
||||
hashs << qHash(this->m_frequency);
|
||||
hashs << qHash(this->m_senderCallsign.getValueHash());
|
||||
hashs << qHash(this->m_recipientCallsign.getValueHash());
|
||||
hashs << qHash(this->m_frequency.getValueHash());
|
||||
hashs << qHash(this->m_message);
|
||||
hashs << qHash(this->m_received);
|
||||
return BlackMisc::calculateHash(hashs, "CTextMessage");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,16 +27,16 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Default constructor.
|
||||
*/
|
||||
CTextMessage() : m_frequency(-1.0, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()) {}
|
||||
CTextMessage() : m_received(QDateTime::currentDateTimeUtc()), m_frequency(-1.0, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()) {}
|
||||
|
||||
/*!
|
||||
* Constructor, radio message
|
||||
* \param message
|
||||
* \param frequency
|
||||
* \param sender
|
||||
* \param senderCallsign
|
||||
*/
|
||||
CTextMessage(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &sender = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_sender(sender), m_frequency(frequency)
|
||||
CTextMessage(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &senderCallsign = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_received(QDateTime::currentDateTimeUtc()), m_senderCallsign(senderCallsign), m_frequency(frequency)
|
||||
{
|
||||
this->m_frequency.switchUnit(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz());
|
||||
}
|
||||
@@ -44,11 +44,11 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Constructor, private message
|
||||
* \param message
|
||||
* \param sender
|
||||
* \param recipient
|
||||
* \param senderCallsign
|
||||
* \param recipientCallsign
|
||||
*/
|
||||
CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &sender, const BlackMisc::Aviation::CCallsign &recipient = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_sender(sender), m_recipient(recipient), m_frequency(-1.0, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()) {}
|
||||
CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_received(QDateTime::currentDateTimeUtc()), m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(-1.0, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()) {}
|
||||
|
||||
/*!
|
||||
* \brief QVariant, required for DBus QVariant lists
|
||||
@@ -63,25 +63,37 @@ namespace BlackMisc
|
||||
* Get callsign (from)
|
||||
* \return
|
||||
*/
|
||||
const BlackMisc::Aviation::CCallsign &getSender() const { return m_sender; }
|
||||
const BlackMisc::Aviation::CCallsign &getSenderCallsign() const
|
||||
{
|
||||
return m_senderCallsign;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Set callsign (from)
|
||||
* \param
|
||||
*/
|
||||
void setSender(const BlackMisc::Aviation::CCallsign &sender) { m_sender = sender; }
|
||||
void setSenderCallsign(const BlackMisc::Aviation::CCallsign &callsign)
|
||||
{
|
||||
m_senderCallsign = callsign;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Get callsign (to)
|
||||
* \return
|
||||
*/
|
||||
const BlackMisc::Aviation::CCallsign &getRecipient() const { return m_recipient; }
|
||||
const BlackMisc::Aviation::CCallsign &getRecipientCallsign() const
|
||||
{
|
||||
return m_recipientCallsign;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Set callsign (to)
|
||||
* \param
|
||||
*/
|
||||
void setRecipient(const BlackMisc::Aviation::CCallsign &recipient) { m_recipient = recipient; }
|
||||
void setRecipientCallsign(const BlackMisc::Aviation::CCallsign &callsign)
|
||||
{
|
||||
m_recipientCallsign = callsign;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send to frequency?
|
||||
@@ -97,7 +109,7 @@ namespace BlackMisc
|
||||
bool isSendToUnicom() const;
|
||||
|
||||
/*!
|
||||
* \brief Valid recipient?
|
||||
* \brief Valid receviver?
|
||||
* \return
|
||||
*/
|
||||
bool hasValidRecipient() const;
|
||||
@@ -106,31 +118,46 @@ namespace BlackMisc
|
||||
* Get message
|
||||
* \return
|
||||
*/
|
||||
const QString &getMessage() const { return m_message; }
|
||||
const QString &getMessage() const
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Empty message
|
||||
* \return
|
||||
*/
|
||||
bool isEmpty() const { return m_message.isEmpty(); }
|
||||
bool isEmpty() const
|
||||
{
|
||||
return m_message.isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Set message
|
||||
* \param
|
||||
*/
|
||||
void setMessage(const QString &message) { m_message = message.trimmed(); }
|
||||
void setMessage(const QString &message)
|
||||
{
|
||||
m_message = message.trimmed();
|
||||
}
|
||||
|
||||
/*!
|
||||
* Get frequency
|
||||
* \return
|
||||
*/
|
||||
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }
|
||||
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Set frequency
|
||||
* \param
|
||||
*/
|
||||
void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { m_frequency = frequency; }
|
||||
void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Is private message?
|
||||
@@ -144,6 +171,22 @@ namespace BlackMisc
|
||||
*/
|
||||
bool isRadioMessage() const;
|
||||
|
||||
/*!
|
||||
* \brief Initial message of server?
|
||||
* \return
|
||||
*/
|
||||
bool isServerMessage() const;
|
||||
|
||||
/*!
|
||||
* \brief Received (hh mm ss)
|
||||
* \return
|
||||
*/
|
||||
QString receivedTime() const
|
||||
{
|
||||
QString rt = this->m_received.toString("hh::mm::ss");
|
||||
return rt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Whole message as formatted string.
|
||||
* Used to display message in a console window.
|
||||
@@ -152,7 +195,7 @@ namespace BlackMisc
|
||||
* \param separator
|
||||
* \return
|
||||
*/
|
||||
QString asString(bool withSender, bool withRecipient, QString separator = ", ") const;
|
||||
QString asString(bool withSender, bool withRecipient, const QString separator = ", ") const;
|
||||
|
||||
/*!
|
||||
* Toggle sender receiver, can be used to ping my own message
|
||||
@@ -205,8 +248,9 @@ namespace BlackMisc
|
||||
|
||||
private:
|
||||
QString m_message;
|
||||
BlackMisc::Aviation::CCallsign m_sender;
|
||||
BlackMisc::Aviation::CCallsign m_recipient;
|
||||
QDateTime m_received;
|
||||
BlackMisc::Aviation::CCallsign m_senderCallsign;
|
||||
BlackMisc::Aviation::CCallsign m_recipientCallsign;
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequency;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -21,9 +21,9 @@ namespace BlackMisc
|
||||
/*
|
||||
* Single private message constructor
|
||||
*/
|
||||
CTextMessageList::CTextMessageList(const QString &message, const CCallsign &toCallsign)
|
||||
CTextMessageList::CTextMessageList(const QString &message, const CCallsign &recipientCallsign)
|
||||
{
|
||||
CTextMessage pm(message, toCallsign);
|
||||
CTextMessage pm(message, recipientCallsign);
|
||||
this->push_back(pm);
|
||||
}
|
||||
|
||||
@@ -118,14 +118,6 @@ namespace BlackMisc
|
||||
qDBusRegisterMetaType<CTextMessageList>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Find by callsign
|
||||
*/
|
||||
CTextMessageList CTextMessageList::findByRecipient(const CCallsign &callsign) const
|
||||
{
|
||||
return CTextMessageList(this->findBy(&CTextMessage::getRecipient, callsign));
|
||||
}
|
||||
|
||||
/*
|
||||
* Find by frequency
|
||||
*/
|
||||
@@ -137,7 +129,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Toggle all senders / receivers
|
||||
*/
|
||||
void CTextMessageList::toggleSenderReceivers()
|
||||
void CTextMessageList::toggleSenderRecipients()
|
||||
{
|
||||
if (this->isEmpty()) return;
|
||||
for (int i = 0; i < this->size(); i++)
|
||||
|
||||
@@ -35,17 +35,17 @@ namespace BlackMisc
|
||||
/*!
|
||||
* \brief Constructor, single private message
|
||||
* \param message
|
||||
* \param recipient
|
||||
* \param recipientCallsign
|
||||
*/
|
||||
CTextMessageList(const QString &message, const BlackMisc::Aviation::CCallsign &recipient);
|
||||
CTextMessageList(const QString &message, const BlackMisc::Aviation::CCallsign &recipientCallsign);
|
||||
|
||||
/*!
|
||||
* \brief Constructor, single private message
|
||||
* \param message
|
||||
* \param sender
|
||||
* \param recipient
|
||||
* \param senderCallsign
|
||||
* \param recipientCallsign
|
||||
*/
|
||||
CTextMessageList(const QString &message, const BlackMisc::Aviation::CCallsign &sender, const BlackMisc::Aviation::CCallsign &recipient);
|
||||
CTextMessageList(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign);
|
||||
|
||||
/*!
|
||||
* \brief Constructor, single radio message
|
||||
@@ -53,7 +53,7 @@ namespace BlackMisc
|
||||
* \param frequency
|
||||
* \param sender
|
||||
*/
|
||||
CTextMessageList(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &sender = BlackMisc::Aviation::CCallsign());
|
||||
CTextMessageList(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &senderCallsign = BlackMisc::Aviation::CCallsign());
|
||||
|
||||
/*!
|
||||
* \brief Constructor, single message
|
||||
@@ -108,13 +108,6 @@ namespace BlackMisc
|
||||
*/
|
||||
bool containsRadioMessages() const;
|
||||
|
||||
/*!
|
||||
* \brief Find 0..n stations by callsign
|
||||
* \param callsign
|
||||
* \return
|
||||
*/
|
||||
CTextMessageList findByRecipient(const BlackMisc::Aviation::CCallsign &callsign) const;
|
||||
|
||||
/*!
|
||||
* \brief Find by frequency
|
||||
* \param frequency
|
||||
@@ -125,7 +118,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* \brief Toggle all sender receivers
|
||||
*/
|
||||
void toggleSenderReceivers();
|
||||
void toggleSenderRecipients();
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
|
||||
Reference in New Issue
Block a user