blob: 6d02db1c80d9bcf17507db7ed73cc8087f6038e4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#include "message.h"
DcMessage::DcMessage(QObject *parent)
: QObject{parent}
{
}
DcMessage::DcMessage(dc_msg_t *message)
: QObject{nullptr}
, m_message{message}
{
}
DcMessage::~DcMessage()
{
dc_msg_unref(m_message);
}
uint32_t
DcMessage::getId()
{
return dc_msg_get_id(m_message);
}
uint32_t
DcMessage::getFromId()
{
return dc_msg_get_from_id(m_message);
}
uint32_t
DcMessage::getChatId()
{
return dc_msg_get_chat_id(m_message);
}
int
DcMessage::getViewtype()
{
return dc_msg_get_viewtype(m_message);
}
int
DcMessage::getState()
{
return dc_msg_get_state(m_message);
}
QDateTime
DcMessage::getTimestamp()
{
return QDateTime::fromSecsSinceEpoch (dc_msg_get_timestamp(m_message), Qt::UTC);
}
bool
DcMessage::saveAttach(QString dest)
{
if(!dest.isNull()){
char *file = dc_msg_get_file(m_message);
QString fileUrl{file};
dc_str_unref(file);
// we need to replace, so we delete file first
if (QFile::exists(dest)){
if(!QFile::remove(dest))
return false;
}
return QFile::copy(fileUrl, dest);
}
else{
return false;
}
}
void
DcMessage::setText(QString text)
{
QByteArray utf8Text = text.toUtf8();
return dc_msg_set_text(m_message, utf8Text.constData());
}
QString
DcMessage::getText()
{
char *text = dc_msg_get_text(m_message);
QString result{text};
dc_str_unref(text);
return result;
}
void
DcMessage::setFile(QString file)
{
QByteArray utf8File = file.toUtf8();
return dc_msg_set_file(m_message, utf8File.constData(), NULL);
}
QString
DcMessage::getSubject()
{
char *subject = dc_msg_get_subject(m_message);
QString result{subject};
dc_str_unref(subject);
return result;
}
QString
DcMessage::getFile()
{
char *file = dc_msg_get_file(m_message);
QString result{file};
dc_str_unref(file);
return result;
}
QString
DcMessage::getFilename()
{
char *filename = dc_msg_get_filename(m_message);
QString result{filename};
dc_str_unref(filename);
return result;
}
QString
DcMessage::getFilemime()
{
char *filemime = dc_msg_get_filemime(m_message);
QString result{filemime};
dc_str_unref(filemime);
return result;
}
int
DcMessage::getWidth()
{
return dc_msg_get_width(m_message);
}
int
DcMessage::getHeight()
{
return dc_msg_get_height(m_message);
}
bool
DcMessage::getShowPadlock()
{
return dc_msg_get_showpadlock(m_message);
}
bool
DcMessage::getIsBot()
{
return dc_msg_is_bot(m_message);
}
QString
DcMessage::getOverrideSenderName()
{
char *name = dc_msg_get_override_sender_name(m_message);
QString result{name};
dc_str_unref(name);
return result;
}
bool
DcMessage::isInfo()
{
return dc_msg_is_info(m_message);
}
QString
DcMessage::getError()
{
char *error = dc_msg_get_error(m_message);
QString result{error};
dc_str_unref(error);
return result;
}
bool
DcMessage::hasHtml()
{
return dc_msg_has_html(m_message);
}
QString
DcMessage::getQuotedText()
{
char *text = dc_msg_get_quoted_text(m_message);
QString result{text};
dc_str_unref(text);
return result;
}
DcMessage *
DcMessage::getQuotedMessage()
{
dc_msg_t *quote = dc_msg_get_quoted_msg(m_message);
if (quote) {
return new DcMessage{quote};
} else {
return NULL;
}
}
|