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
|
/**
* 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
*/
#include <TelepathyQt/PendingSendMessage>
#include "TelepathyQt/_gen/pending-send-message.moc.hpp"
#include <TelepathyQt/ContactMessenger>
#include <TelepathyQt/Message>
#include <TelepathyQt/TextChannel>
namespace Tp
{
struct TP_QT_NO_EXPORT PendingSendMessage::Private
{
Private(const Message &message)
: message(message)
{
}
QString token;
Message message;
};
/**
* \class PendingSendMessage
* \ingroup clientchannel
* \headerfile TelepathyQt/pending-send-message.h <TelepathyQt/PendingSendMessage>
*
* \brief The PendingSendMessage class represents the parameters of and the
* reply to an asynchronous message send request.
*
* See \ref async_model
*/
PendingSendMessage::PendingSendMessage(const TextChannelPtr &channel, const Message &message)
: PendingOperation(channel),
mPriv(new Private(message))
{
}
PendingSendMessage::PendingSendMessage(const ContactMessengerPtr &messenger, const Message &message)
: PendingOperation(messenger),
mPriv(new Private(message))
{
}
PendingSendMessage::~PendingSendMessage()
{
delete mPriv;
}
/**
* Return the channel used to send the message if this instance was created using
* TextChannel. If it was created using ContactMessenger, return a null TextChannelPtr.
*
* \return A pointer to the TextChannel object, or a null TextChannelPtr if created using
* ContactMessenger.
*/
TextChannelPtr PendingSendMessage::channel() const
{
return TextChannelPtr(qobject_cast<TextChannel*>((TextChannel*) object().data()));
}
/**
* Return the contact messenger used to send the message if this instance was created using
* ContactMessenger. If it was created using TextChannel, return a null ContactMessengerPtr.
*
* \return A pointer to the ContactMessenger object, or a null ContactMessengerPtr if created using
* TextChannel.
*/
ContactMessengerPtr PendingSendMessage::messenger() const
{
return ContactMessengerPtr(qobject_cast<ContactMessenger*>((ContactMessenger*) object().data()));
}
QString PendingSendMessage::sentMessageToken() const
{
return mPriv->token;
}
Message PendingSendMessage::message() const
{
return mPriv->message;
}
void PendingSendMessage::onTextSent(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<> reply = *watcher;
if (reply.isError()) {
setFinishedWithError(reply.error());
} else {
setFinished();
}
watcher->deleteLater();
}
void PendingSendMessage::onMessageSent(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<QString> reply = *watcher;
if (reply.isError()) {
setFinishedWithError(reply.error());
} else {
mPriv->token = reply.value();
setFinished();
}
watcher->deleteLater();
}
void PendingSendMessage::onCDMessageSent(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply<QString> reply = *watcher;
if (reply.isError()) {
QDBusError error = reply.error();
if (error.name() == TP_QT_DBUS_ERROR_UNKNOWN_METHOD ||
error.name() == TP_QT_DBUS_ERROR_UNKNOWN_INTERFACE) {
setFinishedWithError(TP_QT_ERROR_NOT_IMPLEMENTED,
QLatin1String("Channel Dispatcher implementation (e.g. mission-control), "
"does not support interface CD.I.Messages"));
} else {
setFinishedWithError(error);
}
} else {
mPriv->token = reply.value();
setFinished();
}
watcher->deleteLater();
}
} // Tp
|