-
Notifications
You must be signed in to change notification settings - Fork 1
/
qlmessage.cpp
86 lines (72 loc) · 1.78 KB
/
qlmessage.cpp
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
#include "qlmessage.h"
#include "linphone/linphonecore.h"
#include <QDateTime>
#include <QColor>
QLMessage::QLMessage(LinphoneChatMessage *msg, QObject *parent) : QObject(parent)
{
this->msg = linphone_chat_message_ref(msg);
}
QLMessage::QLMessage(const QLMessage &orig)
{
msg = linphone_chat_message_ref(orig.msg);
}
QLMessage::~QLMessage()
{
if( msg ){
linphone_chat_message_unref(msg);
}
}
void QLMessage::setMsg(LinphoneChatMessage *m)
{
if( msg ){
linphone_chat_message_unref(msg);
}
msg = linphone_chat_message_ref(m);
}
bool QLMessage::hasBodyURL() const
{
return linphone_chat_message_get_external_body_url(msg) != NULL;
}
bool QLMessage::isOutgoing() const
{
return linphone_chat_message_is_outgoing(msg);
}
QString QLMessage::chatMessage() const
{
QString t;
const char* text = linphone_chat_message_get_text(msg);
if( text ) t = text;
return t;
}
QString QLMessage::state() const
{
return linphone_chat_message_state_to_string(linphone_chat_message_get_state(msg));
}
QDateTime QLMessage::date() const {
return QDateTime::fromTime_t(linphone_chat_message_get_time(msg));
}
QColor QLMessage::statusColor() const
{
switch(linphone_chat_message_get_state(msg)){
case LinphoneChatMessageStateDelivered: return QColor("green");
case LinphoneChatMessageStateInProgress: return QColor("orange");
case LinphoneChatMessageStateNotDelivered: return QColor("red");
}
return QColor("grey");
}
unsigned long QLMessage::uid() const
{
return linphone_chat_message_get_storage_id(msg);
}
QString QLMessage::from() const
{
const LinphoneAddress* fromAddr = linphone_chat_message_get_from_address(msg);
char* url = linphone_address_as_string_uri_only(fromAddr);
QString from = url;
ms_free(url);
return from;
}
QString QLMessage::formattedDate() const
{
return date().toString();
}