~ps-jenkins/telepathy-ofono/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to ofonotextchannel.cpp

  • Committer: Tiago Salem Herrmann
  • Date: 2013-07-08 15:55:12 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: tiago.herrmann@canonical.com-20130708155512-0n61cdowordh9sev
add initial mms support

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
// telepathy-ofono
23
23
#include "ofonotextchannel.h"
24
24
 
 
25
QDBusArgument &operator<<(QDBusArgument &argument, const AttachmentStruct &attachment)
 
26
{
 
27
    argument.beginStructure();
 
28
    argument << attachment.id << attachment.contentType << attachment.filePath << attachment.offset << attachment.length;
 
29
    argument.endStructure();
 
30
    return argument;
 
31
}
 
32
 
 
33
const QDBusArgument &operator>>(const QDBusArgument &argument, AttachmentStruct &attachment)
 
34
{
 
35
    argument.beginStructure();
 
36
    argument >> attachment.id >> attachment.contentType >> attachment.filePath >> attachment.offset >> attachment.length;
 
37
    argument.endStructure();
 
38
    return argument;
 
39
}
 
40
 
25
41
oFonoTextChannel::oFonoTextChannel(oFonoConnection *conn, QString phoneNumber, uint targetHandle, QObject *parent):
26
42
    QObject(parent),
27
43
    mConnection(conn),
29
45
    mTargetHandle(targetHandle),
30
46
    mMessageCounter(1)
31
47
{
 
48
    qDBusRegisterMetaType<AttachmentStruct>();
 
49
    qDBusRegisterMetaType<AttachmentList>();
 
50
 
32
51
    Tp::BaseChannelPtr baseChannel = Tp::BaseChannel::create(mConnection,
33
52
                                                             TP_QT_IFACE_CHANNEL_TYPE_TEXT,
34
53
                                                             targetHandle,
54
73
    baseChannel->plugInterface(Tp::AbstractChannelInterfacePtr::dynamicCast(mMessagesIface));
55
74
    mBaseChannel = baseChannel;
56
75
    mTextChannel = Tp::BaseChannelTextTypePtr::dynamicCast(mBaseChannel->interface(TP_QT_IFACE_CHANNEL_TYPE_TEXT));
 
76
    mTextChannel->setMessageAcknowledgedCallback(Tp::memFun(this,&oFonoTextChannel::messageAcknowledged));
57
77
    QObject::connect(mBaseChannel.data(), SIGNAL(closed()), this, SLOT(deleteLater()));
58
78
}
59
79
 
66
86
    return mBaseChannel;
67
87
}
68
88
 
 
89
void oFonoTextChannel::messageAcknowledged(const QString &id)
 
90
{
 
91
    Q_EMIT messageRead(id);
 
92
}
 
93
 
69
94
QString oFonoTextChannel::sendMessage(const Tp::MessagePartList& message, uint flags, Tp::DBusError* error)
70
95
{
71
96
    bool success = true;
133
158
 
134
159
    mTextChannel->addReceivedMessage(partList);
135
160
}
 
161
 
 
162
void oFonoTextChannel::mmsReceived(const QString &id, const QVariantMap &properties)
 
163
{
 
164
    Tp::MessagePartList message;
 
165
 
 
166
    Tp::MessagePart header;
 
167
    header["message-token"] = QDBusVariant(id);
 
168
    header["message-sender"] = QDBusVariant(mTargetHandle);
 
169
    header["message-received"] = QDBusVariant(QDateTime::fromString(properties["Date"].toString(), Qt::ISODate).toTime_t());
 
170
    header["message-type"] = QDBusVariant(Tp::DeliveryStatusDelivered);
 
171
    message << header;
 
172
    if (!properties["Subject"].toString().isEmpty())
 
173
    {
 
174
        Tp::MessagePart part;
 
175
        part["content-type"] =  QDBusVariant("text/plain");
 
176
        part["content"] = QDBusVariant(properties["Subject"].toString());
 
177
        message << part;
 
178
    }
 
179
    AttachmentList a = qdbus_cast<AttachmentList>(properties["Attachments"]);
 
180
    Q_FOREACH(AttachmentStruct b, a) {
 
181
        QFile a(b.filePath);
 
182
        if (!a.open(QIODevice::ReadOnly)) {
 
183
            qDebug() << "fail to load attachment";
 
184
        }
 
185
        a.seek(b.offset);
 
186
        QByteArray fileData = a.read(b.length);
 
187
        Tp::MessagePart part;
 
188
        part["content-type"] =  QDBusVariant(b.contentType);
 
189
        part["identifier"] = QDBusVariant(b.id);
 
190
        part["content"] = QDBusVariant(fileData);
 
191
        part["size"] = QDBusVariant(b.length);
 
192
 
 
193
        message << part;
 
194
    }
 
195
 
 
196
    mTextChannel->addReceivedMessage(message);
 
197
}