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:
Klaus Basan
2014-01-13 02:30:42 +01:00
parent 1051a343aa
commit 43e5e54f22
4 changed files with 113 additions and 64 deletions

View File

@@ -2,6 +2,9 @@
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/pqconstants.h" #include "blackmisc/pqconstants.h"
#include "blackmisc/aviocomsystem.h" #include "blackmisc/aviocomsystem.h"
#include "blackmisc/avcallsign.h"
using namespace BlackMisc::Aviation;
namespace BlackMisc namespace BlackMisc
{ {
@@ -15,8 +18,8 @@ namespace BlackMisc
QString s(this->m_message); QString s(this->m_message);
if (this->isPrivateMessage()) if (this->isPrivateMessage())
{ {
s.append(" ").append(this->m_sender.toQString(i18n)); s.append(" ").append(this->m_senderCallsign.toQString(i18n));
s.append(" ").append(this->m_recipient.toQString(i18n)); s.append(" ").append(this->m_recipientCallsign.toQString(i18n));
} }
else else
{ {
@@ -30,10 +33,11 @@ namespace BlackMisc
*/ */
void CTextMessage::marshallToDbus(QDBusArgument &argument) const void CTextMessage::marshallToDbus(QDBusArgument &argument) const
{ {
argument << this->m_sender; argument << this->m_senderCallsign;
argument << this->m_recipient; argument << this->m_recipientCallsign;
argument << this->m_message; argument << this->m_message;
argument << this->m_frequency; argument << this->m_frequency;
argument << this->m_received;
} }
/* /*
@@ -41,10 +45,11 @@ namespace BlackMisc
*/ */
void CTextMessage::unmarshallFromDbus(const QDBusArgument &argument) void CTextMessage::unmarshallFromDbus(const QDBusArgument &argument)
{ {
argument >> this->m_sender; argument >> this->m_senderCallsign;
argument >> this->m_recipient; argument >> this->m_recipientCallsign;
argument >> this->m_message; argument >> this->m_message;
argument >> this->m_frequency; argument >> this->m_frequency;
argument >> this->m_received;
} }
/* /*
@@ -52,7 +57,7 @@ namespace BlackMisc
*/ */
bool CTextMessage::isPrivateMessage() const 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 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); return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency);
} }
@@ -89,26 +94,37 @@ namespace BlackMisc
return (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency)); 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 * Formatted string
*/ */
QString CTextMessage::asString(bool withSender, bool withRecipient, const QString separator) const QString CTextMessage::asString(bool withSender, bool withRecipient, const QString separator) const
{ {
QString s; QString s = this->receivedTime();
if (withSender) 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 (withRecipient)
{ {
if (!this->m_recipient.isEmpty()) if (!this->m_recipientCallsign.isEmpty())
{ {
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
s.append(this->m_recipient.getStringAsSet()); s.append(this->m_recipientCallsign.getStringAsSet());
} }
else else
{ {
@@ -117,8 +133,9 @@ namespace BlackMisc
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
s.append(this->m_frequency.valueRoundedWithUnit(3, true)); s.append(this->m_frequency.valueRoundedWithUnit(3, true));
} }
} }
} } // to
if (this->m_message.isEmpty()) return s; if (this->m_message.isEmpty()) return s;
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
@@ -131,7 +148,9 @@ namespace BlackMisc
*/ */
void CTextMessage::toggleSenderRecipient() 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 uint CTextMessage::getValueHash() const
{ {
QList<uint> hashs; QList<uint> hashs;
hashs << qHash(this->m_sender); hashs << qHash(this->m_senderCallsign.getValueHash());
hashs << qHash(this->m_recipient); hashs << qHash(this->m_recipientCallsign.getValueHash());
hashs << qHash(this->m_frequency); hashs << qHash(this->m_frequency.getValueHash());
hashs << qHash(this->m_message); hashs << qHash(this->m_message);
hashs << qHash(this->m_received);
return BlackMisc::calculateHash(hashs, "CTextMessage"); return BlackMisc::calculateHash(hashs, "CTextMessage");
} }

View File

@@ -27,16 +27,16 @@ namespace BlackMisc
/*! /*!
* Default constructor. * 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 * Constructor, radio message
* \param message * \param message
* \param frequency * \param frequency
* \param sender * \param senderCallsign
*/ */
CTextMessage(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &sender = BlackMisc::Aviation::CCallsign()) CTextMessage(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &senderCallsign = BlackMisc::Aviation::CCallsign())
: m_message(message), m_sender(sender), m_frequency(frequency) : m_message(message), m_received(QDateTime::currentDateTimeUtc()), m_senderCallsign(senderCallsign), m_frequency(frequency)
{ {
this->m_frequency.switchUnit(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()); this->m_frequency.switchUnit(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz());
} }
@@ -44,11 +44,11 @@ namespace BlackMisc
/*! /*!
* Constructor, private message * Constructor, private message
* \param message * \param message
* \param sender * \param senderCallsign
* \param recipient * \param recipientCallsign
*/ */
CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &sender, const BlackMisc::Aviation::CCallsign &recipient = BlackMisc::Aviation::CCallsign()) CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign = BlackMisc::Aviation::CCallsign())
: m_message(message), m_sender(sender), m_recipient(recipient), m_frequency(-1.0, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()) {} : 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 * \brief QVariant, required for DBus QVariant lists
@@ -63,25 +63,37 @@ namespace BlackMisc
* Get callsign (from) * Get callsign (from)
* \return * \return
*/ */
const BlackMisc::Aviation::CCallsign &getSender() const { return m_sender; } const BlackMisc::Aviation::CCallsign &getSenderCallsign() const
{
return m_senderCallsign;
}
/*! /*!
* Set callsign (from) * Set callsign (from)
* \param * \param
*/ */
void setSender(const BlackMisc::Aviation::CCallsign &sender) { m_sender = sender; } void setSenderCallsign(const BlackMisc::Aviation::CCallsign &callsign)
{
m_senderCallsign = callsign;
}
/*! /*!
* Get callsign (to) * Get callsign (to)
* \return * \return
*/ */
const BlackMisc::Aviation::CCallsign &getRecipient() const { return m_recipient; } const BlackMisc::Aviation::CCallsign &getRecipientCallsign() const
{
return m_recipientCallsign;
}
/*! /*!
* Set callsign (to) * Set callsign (to)
* \param * \param
*/ */
void setRecipient(const BlackMisc::Aviation::CCallsign &recipient) { m_recipient = recipient; } void setRecipientCallsign(const BlackMisc::Aviation::CCallsign &callsign)
{
m_recipientCallsign = callsign;
}
/* /*
* Send to frequency? * Send to frequency?
@@ -97,7 +109,7 @@ namespace BlackMisc
bool isSendToUnicom() const; bool isSendToUnicom() const;
/*! /*!
* \brief Valid recipient? * \brief Valid receviver?
* \return * \return
*/ */
bool hasValidRecipient() const; bool hasValidRecipient() const;
@@ -106,31 +118,46 @@ namespace BlackMisc
* Get message * Get message
* \return * \return
*/ */
const QString &getMessage() const { return m_message; } const QString &getMessage() const
{
return m_message;
}
/*! /*!
* Empty message * Empty message
* \return * \return
*/ */
bool isEmpty() const { return m_message.isEmpty(); } bool isEmpty() const
{
return m_message.isEmpty();
}
/*! /*!
* Set message * Set message
* \param * \param
*/ */
void setMessage(const QString &message) { m_message = message.trimmed(); } void setMessage(const QString &message)
{
m_message = message.trimmed();
}
/*! /*!
* Get frequency * Get frequency
* \return * \return
*/ */
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; } const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const
{
return m_frequency;
}
/*! /*!
* Set frequency * Set frequency
* \param * \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? * \brief Is private message?
@@ -144,6 +171,22 @@ namespace BlackMisc
*/ */
bool isRadioMessage() const; 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. * Whole message as formatted string.
* Used to display message in a console window. * Used to display message in a console window.
@@ -152,7 +195,7 @@ namespace BlackMisc
* \param separator * \param separator
* \return * \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 * Toggle sender receiver, can be used to ping my own message
@@ -205,8 +248,9 @@ namespace BlackMisc
private: private:
QString m_message; QString m_message;
BlackMisc::Aviation::CCallsign m_sender; QDateTime m_received;
BlackMisc::Aviation::CCallsign m_recipient; BlackMisc::Aviation::CCallsign m_senderCallsign;
BlackMisc::Aviation::CCallsign m_recipientCallsign;
BlackMisc::PhysicalQuantities::CFrequency m_frequency; BlackMisc::PhysicalQuantities::CFrequency m_frequency;
}; };
} // namespace } // namespace

View File

@@ -21,9 +21,9 @@ namespace BlackMisc
/* /*
* Single private message constructor * 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); this->push_back(pm);
} }
@@ -118,14 +118,6 @@ namespace BlackMisc
qDBusRegisterMetaType<CTextMessageList>(); qDBusRegisterMetaType<CTextMessageList>();
} }
/*
* Find by callsign
*/
CTextMessageList CTextMessageList::findByRecipient(const CCallsign &callsign) const
{
return CTextMessageList(this->findBy(&CTextMessage::getRecipient, callsign));
}
/* /*
* Find by frequency * Find by frequency
*/ */
@@ -137,7 +129,7 @@ namespace BlackMisc
/* /*
* Toggle all senders / receivers * Toggle all senders / receivers
*/ */
void CTextMessageList::toggleSenderReceivers() void CTextMessageList::toggleSenderRecipients()
{ {
if (this->isEmpty()) return; if (this->isEmpty()) return;
for (int i = 0; i < this->size(); i++) for (int i = 0; i < this->size(); i++)

View File

@@ -35,17 +35,17 @@ namespace BlackMisc
/*! /*!
* \brief Constructor, single private message * \brief Constructor, single private message
* \param 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 * \brief Constructor, single private message
* \param message * \param message
* \param sender * \param senderCallsign
* \param recipient * \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 * \brief Constructor, single radio message
@@ -53,7 +53,7 @@ namespace BlackMisc
* \param frequency * \param frequency
* \param sender * \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 * \brief Constructor, single message
@@ -108,13 +108,6 @@ namespace BlackMisc
*/ */
bool containsRadioMessages() const; 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 * \brief Find by frequency
* \param frequency * \param frequency
@@ -125,7 +118,7 @@ namespace BlackMisc
/*! /*!
* \brief Toggle all sender receivers * \brief Toggle all sender receivers
*/ */
void toggleSenderReceivers(); void toggleSenderRecipients();
/*! /*!
* \brief Register metadata * \brief Register metadata