Changeset View
Changeset View
Standalone View
Standalone View
interfaces/conversationmessage.cpp
- This file was added.
1 | /** | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Simon Redman <simon@ergotech.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "conversationmessage.h" | ||||
22 | | ||||
23 | #include <QtCore> | ||||
24 | #include <QVariantMap> | ||||
25 | | ||||
26 | | ||||
27 | ConversationMessage::ConversationMessage(const QVariantMap& args, QObject* parent) | ||||
28 | : QObject(parent), | ||||
29 | m_body(args["body"].toString()), | ||||
30 | m_address(args["address"].toString()), | ||||
31 | m_date(args["date"].toLongLong()), | ||||
32 | m_type(args["type"].toInt()), | ||||
33 | m_read(args["read"].toInt()), | ||||
34 | m_threadID(args["thread_id"].toInt()), | ||||
35 | m_uID(args["_id"].toInt()) | ||||
36 | { | ||||
37 | } | ||||
38 | | ||||
39 | ConversationMessage::ConversationMessage (const QString& body, const QString& address, const qint64& date, | ||||
40 | const qint32& type, const qint32& read, const qint32& threadID, | ||||
41 | const qint32& uID, | ||||
42 | QObject* parent) | ||||
43 | : QObject(parent) | ||||
44 | , m_body(body) | ||||
45 | , m_address(address) | ||||
46 | , m_date(date) | ||||
47 | , m_type(type) | ||||
48 | , m_read(read) | ||||
49 | , m_threadID(threadID) | ||||
50 | , m_uID(uID) | ||||
51 | { | ||||
52 | | ||||
53 | } | ||||
54 | | ||||
55 | ConversationMessage::ConversationMessage(const ConversationMessage& other, QObject* parent) | ||||
56 | : QObject(parent) | ||||
57 | , m_body(other.m_body) | ||||
58 | , m_address(other.m_address) | ||||
59 | , m_date(other.m_date) | ||||
60 | , m_type(other.m_type) | ||||
61 | , m_read(other.m_read) | ||||
62 | , m_threadID(other.m_threadID) | ||||
63 | , m_uID(other.m_uID) | ||||
64 | { | ||||
65 | | ||||
66 | } | ||||
67 | | ||||
68 | ConversationMessage::~ConversationMessage() { } | ||||
69 | | ||||
70 | ConversationMessage& ConversationMessage::operator=(const ConversationMessage& other) | ||||
71 | { | ||||
72 | this->m_body = other.m_body; | ||||
73 | this->m_address = other.m_address; | ||||
74 | this->m_date = other.m_date; | ||||
75 | this->m_type = other.m_type; | ||||
76 | this->m_read = other.m_read; | ||||
77 | this->m_threadID = other.m_threadID; | ||||
78 | this->m_uID = other.m_uID; | ||||
79 | return *this; | ||||
80 | } | ||||
81 | | ||||
82 | QVariantMap ConversationMessage::toVariant() const | ||||
83 | { | ||||
84 | return { | ||||
85 | {"body", m_body}, | ||||
86 | {"address", m_address}, | ||||
87 | {"date", m_date}, | ||||
88 | {"type", m_type}, | ||||
89 | {"read", m_read}, | ||||
90 | {"thread_id", m_threadID}, | ||||
91 | {"_id", m_uID}, | ||||
92 | }; | ||||
93 | } | ||||
94 | | ||||
95 | QDBusArgument &operator<<(QDBusArgument &argument, const ConversationMessage &message) | ||||
96 | { | ||||
97 | argument.beginStructure(); | ||||
98 | argument << message.body() << message.address() << message.date() << message.type() | ||||
99 | << message.read() << message.threadID() << message.uID(); | ||||
100 | argument.endStructure(); | ||||
101 | return argument; | ||||
102 | } | ||||
103 | | ||||
104 | const QDBusArgument &operator>>(const QDBusArgument &argument, ConversationMessage &message) | ||||
105 | { | ||||
106 | QString body; | ||||
107 | QString address; | ||||
108 | qint64 date; | ||||
109 | qint32 type; | ||||
110 | qint32 read; | ||||
111 | qint32 threadID; | ||||
112 | qint32 uID; | ||||
113 | | ||||
114 | argument.beginStructure(); | ||||
115 | argument >> body; | ||||
116 | argument >> address; | ||||
117 | argument >> date; | ||||
118 | argument >> type; | ||||
119 | argument >> read; | ||||
120 | argument >> threadID; | ||||
121 | argument >> uID; | ||||
122 | argument.endStructure(); | ||||
123 | | ||||
124 | message = ConversationMessage(body, address, date, type, read, threadID, uID); | ||||
125 | | ||||
126 | return argument; | ||||
127 | } | ||||
128 | | ||||
129 | void ConversationMessage::registerDbusType() | ||||
130 | { | ||||
131 | qDBusRegisterMetaType<ConversationMessage>(); | ||||
132 | qRegisterMetaType<ConversationMessage>(); | ||||
133 | } |