diff --git a/interfaces/conversationmessage.cpp b/interfaces/conversationmessage.cpp index e672eb57..6319c656 100644 --- a/interfaces/conversationmessage.cpp +++ b/interfaces/conversationmessage.cpp @@ -1,85 +1,113 @@ /** * Copyright 2018 Simon Redman * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "conversationmessage.h" #include #include ConversationMessage::ConversationMessage(const QVariantMap& args, QObject* parent) : QObject(parent), m_body(args["body"].toString()), m_address(args["address"].toString()), m_date(args["date"].toLongLong()), m_type(args["type"].toInt()), m_read(args["read"].toInt()), m_threadID(args["thread_id"].toInt()) { } +ConversationMessage::ConversationMessage (const QString& body, const QString& address, const qint64& date, + const qint32& type, const qint32& read, const qint32& threadID, + QObject* parent) + : QObject(parent) + , m_body(body) + , m_address(address) + , m_date(date) + , m_type(type) + , m_read(read) + , m_threadID(threadID) +{ + +} + ConversationMessage::ConversationMessage(const ConversationMessage& other, QObject* parent) : QObject(parent) , m_body(other.m_body) , m_address(other.m_address) , m_date(other.m_date) , m_type(other.m_type) , m_read(other.m_read) , m_threadID(other.m_threadID) { } ConversationMessage::~ConversationMessage() { } ConversationMessage& ConversationMessage::operator=(const ConversationMessage& other) { this->m_body = other.m_body; this->m_address = other.m_address; this->m_date = other.m_date; this->m_type = other.m_type; this->m_read = other.m_read; this->m_threadID = other.m_threadID; return *this; } QDBusArgument &operator<<(QDBusArgument &argument, const ConversationMessage &message) { argument.beginStructure(); - argument << message.m_body << message.m_address << message.m_date << message.m_type - << message.m_read << message.m_threadID; + argument << message.body() << message.address() << message.date() << message.type() + << message.read() << message.threadID(); argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, ConversationMessage &message) { + QString body; + QString address; + qint64 date; + qint32 type; + qint32 read; + qint32 threadID; + argument.beginStructure(); - argument >> message.m_body >> message.m_address >> message.m_date >> message.m_type - >> message.m_read >> message.m_threadID; + argument >> body; + argument >> address; + argument >> date; + argument >> type; + argument >> read; + argument >> threadID; argument.endStructure(); + + message = ConversationMessage(body, address, date, type, read, threadID); + return argument; } void ConversationMessage::registerDbusType() { qDBusRegisterMetaType(); qRegisterMetaType(); } diff --git a/interfaces/conversationmessage.h b/interfaces/conversationmessage.h index 51181c81..16758d38 100644 --- a/interfaces/conversationmessage.h +++ b/interfaces/conversationmessage.h @@ -1,108 +1,113 @@ /** * Copyright 2018 Simon Redman * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef PLUGINS_TELEPHONY_CONVERSATIONMESSAGE_H_ #define PLUGINS_TELEPHONY_CONVERSATIONMESSAGE_H_ #include #include #include #include #include "interfaces/kdeconnectinterfaces_export.h" class KDECONNECTINTERFACES_EXPORT ConversationMessage : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.telephony.messages") Q_PROPERTY(QString body READ body) Q_PROPERTY(QString address READ address) Q_PROPERTY(qint64 date READ date) Q_PROPERTY(qint32 type READ type) Q_PROPERTY(qint32 read READ read) Q_PROPERTY(qint32 threadID READ threadID) public: // TYPE field values from Android enum Types { MessageTypeAll = 0, MessageTypeInbox = 1, MessageTypeSent = 2, MessageTypeDraft = 3, MessageTypeOutbox = 4, MessageTypeFailed = 5, MessageTypeQueued = 6, }; Q_ENUM(Types); /** - * Build a new message + * Build a new message from a keyword argument dictionary * * @param args mapping of field names to values as might be contained in a network packet containing a message */ ConversationMessage(const QVariantMap& args = QVariantMap(), QObject* parent = Q_NULLPTR); + + ConversationMessage(const QString& body, const QString& address, const qint64& date, + const qint32& type, const qint32& read, const qint32& threadID, + QObject* parent = Q_NULLPTR); + ConversationMessage(const ConversationMessage& other, QObject* parent = Q_NULLPTR); ~ConversationMessage(); ConversationMessage& operator=(const ConversationMessage& other); static void registerDbusType(); QString body() const { return m_body; } QString address() const { return m_address; } qint64 date() const { return m_date; } qint32 type() const { return m_type; } qint32 read() const { return m_read; } qint32 threadID() const { return m_threadID; } -public: +protected: /** * Body of the message */ QString m_body; /** * Remote-side address of the message. Most likely a phone number, but may be an email address */ QString m_address; /** * Date stamp (Unix epoch millis) associated with the message */ qint64 m_date; /** * Type of the message. See the message.type enum */ qint32 m_type; /** * Whether we have a read report for this message */ qint32 m_read; /** * Tag which binds individual messages into a thread */ qint32 m_threadID; }; Q_DECLARE_METATYPE(ConversationMessage); #endif /* PLUGINS_TELEPHONY_CONVERSATIONMESSAGE_H_ */