summaryrefslogtreecommitdiff
path: root/TelepathyQt/message.h
blob: 7aa6bc2a4fa6f8e4900b561bc74bb92bb87059ef (plain)
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
/**
 * This file is part of TelepathyQt
 *
 * @copyright Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
 * @copyright Copyright (C) 2009 Nokia Corporation
 * @license LGPL 2.1
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _TelepathyQt_message_h_HEADER_GUARD_
#define _TelepathyQt_message_h_HEADER_GUARD_

#ifndef IN_TP_QT_HEADER
#error IN_TP_QT_HEADER
#endif

#include <QSharedDataPointer>

#include <TelepathyQt/Constants>
#include <TelepathyQt/Contact>
#include <TelepathyQt/Types>

class QDateTime;

namespace Tp
{

class Contact;
class TextChannel;

class TP_QT_EXPORT Message
{
public:
    Message(ChannelTextMessageType, const QString &);
    Message(const Message &other);
    ~Message();

    Message &operator=(const Message &other);
    bool operator==(const Message &other) const;
    inline bool operator!=(const Message &other) const
    {
        return !(*this == other);
    }

    // Convenient access to headers

    QDateTime sent() const;

    ChannelTextMessageType messageType() const;

    bool isTruncated() const;

    bool hasNonTextContent() const;

    QString messageToken() const;

    bool isSpecificToDBusInterface() const;
    QString dbusInterface() const;

    QString text() const;

    // Direct access to the whole message (header and body)

    MessagePart header() const;

    int size() const;
    MessagePart part(uint index) const;
    MessagePartList parts() const;

private:
    friend class ContactMessenger;
    friend class ReceivedMessage;
    friend class TextChannel;

    TP_QT_NO_EXPORT Message();
    TP_QT_NO_EXPORT Message(const MessagePartList &parts);
    TP_QT_NO_EXPORT Message(uint, uint, const QString &);

    struct Private;
    friend struct Private;
    QSharedDataPointer<Private> mPriv;
};

class TP_QT_EXPORT ReceivedMessage : public Message
{
public:
    class DeliveryDetails
    {
    public:
        DeliveryDetails();
        DeliveryDetails(const DeliveryDetails &other);
        ~DeliveryDetails();

        DeliveryDetails &operator=(const DeliveryDetails &other);

        bool isValid() const { return mPriv.constData() != nullptr; }

        DeliveryStatus status() const;

        bool hasOriginalToken() const;
        QString originalToken() const;

        bool isError() const;
        ChannelTextSendError error() const;

        bool hasDebugMessage() const;
        QString debugMessage() const;

        QString dbusError() const;

        bool hasEchoedMessage() const;
        Message echoedMessage() const;

    private:
        friend class ReceivedMessage;

        TP_QT_NO_EXPORT DeliveryDetails(const MessagePartList &parts);

        struct Private;
        friend struct Private;
        QSharedDataPointer<Private> mPriv;
    };

    ReceivedMessage(const ReceivedMessage &other);
    ReceivedMessage &operator=(const ReceivedMessage &other);
    ~ReceivedMessage();

    QDateTime received() const;
    ContactPtr sender() const;
    QString senderNickname() const;

    QString supersededToken() const;

    bool isScrollback() const;
    bool isRescued() const;
    bool isSilent() const;

    bool isDeliveryReport() const;
    DeliveryDetails deliveryDetails() const;

    bool isFromChannel(const TextChannelPtr &channel) const;

protected:
    friend class TextChannel;

    ReceivedMessage(const MessagePartList &parts,
            const TextChannelPtr &channel);
    ReceivedMessage();

    uint senderHandle() const;
    QString senderId() const;
    uint pendingId() const;

    void setForceNonText();
    void clearSenderHandle();
    void setSender(const ContactPtr &sender);
};

} // Tp

#endif