[sms] Change address type in DBus API from variant to variantlist

While mostly theoretical it makes for a more expressive API since it communicates that it is a list instead of a single value. It also allows to get rid of some conversion code.

This is also preparation work for potentially using the custom type capabilities that QtDBus offers.
This commit is contained in:
Nicolas Fella 2020-07-29 15:18:19 +00:00
parent e38cdb111b
commit 1bd59787e2
8 changed files with 19 additions and 27 deletions

View file

@ -135,14 +135,6 @@ ConversationAddress& ConversationAddress::operator=(const ConversationAddress& o
return *this;
}
QList<ConversationAddress> ConversationAddress::listfromDBus(const QDBusVariant& var)
{
QDBusArgument data = var.variant().value<QDBusArgument>();
QList<ConversationAddress> addresses;
data >> addresses;
return addresses;
}
QVariantMap ConversationAddress::toVariant() const
{
return {

View file

@ -149,7 +149,6 @@ public:
ConversationAddress(const ConversationAddress& other);
~ConversationAddress();
ConversationAddress& operator=(const ConversationAddress& other);
static QList<ConversationAddress> listfromDBus(const QDBusVariant&);
QString address() const { return m_address; }

View file

@ -195,13 +195,16 @@ void ConversationsDbusInterface::replyToConversation(const qint64& conversationI
}
const QList<ConversationAddress>& addressList = messagesList.first().addresses();
QVariant addresses;
addresses.setValue(addressList);
QVariantList addresses;
m_smsInterface.sendSms(QDBusVariant(addresses), message, messagesList.first().subID());
for (const auto& address : addressList) {
addresses << QVariant::fromValue(addresse);
}
m_smsInterface.sendSms(addresses, message, messagesList.first().subID());
}
void ConversationsDbusInterface::sendWithoutConversation(const QDBusVariant& addresses, const QString& message) {
void ConversationsDbusInterface::sendWithoutConversation(const QVariantList& addresses, const QString& message) {
m_smsInterface.sendSms(addresses, message);
}

View file

@ -90,7 +90,7 @@ public Q_SLOTS:
/**
* Send a new message to the contact having no previous coversation with
*/
void sendWithoutConversation(const QDBusVariant& addressList, const QString& message);
void sendWithoutConversation(const QVariantList& addressList, const QString& message);
/**
* Send the request to the Telephony plugin to update the list of conversation threads

View file

@ -57,15 +57,12 @@ bool SmsPlugin::receivePacket(const NetworkPacket& np)
return true;
}
void SmsPlugin::sendSms(const QDBusVariant& addresses, const QString& messageBody, const qint64 subID)
void SmsPlugin::sendSms(const QVariantList& addresses, const QString& messageBody, const qint64 subID)
{
QList<ConversationAddress> addressList = ConversationAddress::listfromDBus(addresses);
QVariantList addressMapList;
for (const ConversationAddress& address : addressList) {
QVariantMap addressMap({{QStringLiteral("address"), address.address()}});
for (const QVariant& address : addresses) {
QVariantMap addressMap({{QStringLiteral("address"), qdbus_cast<ConversationAddress>(address).address()}});
addressMapList.append(addressMap);
qDebug() <<address.address();
}
QVariantMap packetMap({

View file

@ -127,7 +127,7 @@ public:
QString dbusPath() const override;
public Q_SLOTS:
Q_SCRIPTABLE void sendSms(const QDBusVariant& addresses, const QString& messageBody, const qint64 subID = -1);
Q_SCRIPTABLE void sendSms(const QVariantList& addresses, const QString& messageBody, const qint64 subID = -1);
/**
* Send a request to the remote for all of its conversations

View file

@ -81,8 +81,6 @@ void ConversationModel::setDeviceId(const QString& deviceId)
connect(m_conversationsInterface, SIGNAL(conversationUpdated(QDBusVariant)), this, SLOT(handleConversationUpdate(QDBusVariant)));
connect(m_conversationsInterface, SIGNAL(conversationLoaded(qint64, quint64)), this, SLOT(handleConversationLoaded(qint64, quint64)));
connect(m_conversationsInterface, SIGNAL(conversationCreated(QDBusVariant)), this, SLOT(handleConversationCreated(QDBusVariant)));
connect(this, SIGNAL(sendMessageWithoutConversation(QDBusVariant, QString)), m_conversationsInterface, SLOT(sendWithoutConversation(QDBusVariant, QString)));
}
void ConversationModel::setAddressList(const QList<ConversationAddress>& addressList) {
@ -97,9 +95,13 @@ void ConversationModel::sendReplyToConversation(const QString& message)
void ConversationModel::startNewConversation(const QString& message, const QList<ConversationAddress>& addressList)
{
QVariant addresses;
addresses.setValue(addressList);
Q_EMIT sendMessageWithoutConversation(QDBusVariant(addresses), message);
QVariantList addresses;
for (const auto& address : addressList) {
addresses << QVariant::fromValue(address);
}
m_conversationsInterface->sendWithoutConversation(addresses, message);
}
void ConversationModel::requestMoreMessages(const quint32& howMany)

View file

@ -68,7 +68,6 @@ public:
Q_SIGNALS:
void loadingFinished();
void sendMessageWithoutConversation(const QDBusVariant& addressList, const QString& message);
private Q_SLOTS:
void handleConversationUpdate(const QDBusVariant &message);