From 1bd59787e20c49846caf7697d039af66ed95f4bf Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Wed, 29 Jul 2020 15:18:19 +0000 Subject: [PATCH] [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. --- interfaces/conversationmessage.cpp | 8 -------- interfaces/conversationmessage.h | 1 - plugins/sms/conversationsdbusinterface.cpp | 11 +++++++---- plugins/sms/conversationsdbusinterface.h | 2 +- plugins/sms/smsplugin.cpp | 9 +++------ plugins/sms/smsplugin.h | 2 +- smsapp/conversationmodel.cpp | 12 +++++++----- smsapp/conversationmodel.h | 1 - 8 files changed, 19 insertions(+), 27 deletions(-) diff --git a/interfaces/conversationmessage.cpp b/interfaces/conversationmessage.cpp index 4b2a4fcde..a8216f858 100644 --- a/interfaces/conversationmessage.cpp +++ b/interfaces/conversationmessage.cpp @@ -135,14 +135,6 @@ ConversationAddress& ConversationAddress::operator=(const ConversationAddress& o return *this; } -QList ConversationAddress::listfromDBus(const QDBusVariant& var) -{ - QDBusArgument data = var.variant().value(); - QList addresses; - data >> addresses; - return addresses; -} - QVariantMap ConversationAddress::toVariant() const { return { diff --git a/interfaces/conversationmessage.h b/interfaces/conversationmessage.h index 0287734d3..db298f5ae 100644 --- a/interfaces/conversationmessage.h +++ b/interfaces/conversationmessage.h @@ -149,7 +149,6 @@ public: ConversationAddress(const ConversationAddress& other); ~ConversationAddress(); ConversationAddress& operator=(const ConversationAddress& other); - static QList listfromDBus(const QDBusVariant&); QString address() const { return m_address; } diff --git a/plugins/sms/conversationsdbusinterface.cpp b/plugins/sms/conversationsdbusinterface.cpp index 4151a6b1b..5866e5827 100644 --- a/plugins/sms/conversationsdbusinterface.cpp +++ b/plugins/sms/conversationsdbusinterface.cpp @@ -195,13 +195,16 @@ void ConversationsDbusInterface::replyToConversation(const qint64& conversationI } const QList& 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); } diff --git a/plugins/sms/conversationsdbusinterface.h b/plugins/sms/conversationsdbusinterface.h index 0da7b06f6..08e359f6a 100644 --- a/plugins/sms/conversationsdbusinterface.h +++ b/plugins/sms/conversationsdbusinterface.h @@ -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 diff --git a/plugins/sms/smsplugin.cpp b/plugins/sms/smsplugin.cpp index 335447544..113fc909f 100644 --- a/plugins/sms/smsplugin.cpp +++ b/plugins/sms/smsplugin.cpp @@ -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 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(address).address()}}); addressMapList.append(addressMap); - qDebug() <& addressList) { @@ -97,9 +95,13 @@ void ConversationModel::sendReplyToConversation(const QString& message) void ConversationModel::startNewConversation(const QString& message, const QList& 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) diff --git a/smsapp/conversationmodel.h b/smsapp/conversationmodel.h index 14784e3e5..2d73184bf 100644 --- a/smsapp/conversationmodel.h +++ b/smsapp/conversationmodel.h @@ -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);