summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Gehre <M.Gehre@gmx.de>2013-03-25 20:34:25 (GMT)
committerDavid Edmundson <davidedmundson@kde.org>2014-06-14 11:51:53 (GMT)
commit483c0d518278aa7c7762cca8517f8fa6dc4e169e (patch)
treea0b67d7f41284cc385d0da6759472570400a3a80
parent516e26cf2d4b3e13b58e2f6d0fbd6ed052b5d8d7 (diff)
downloadtelepathy-qt4-483c0d518278aa7c7762cca8517f8fa6dc4e169e.tar.gz
telepathy-qt4-483c0d518278aa7c7762cca8517f8fa6dc4e169e.tar.xz
Add BaseChannelTextType
-rw-r--r--TelepathyQt/base-channel-internal.h23
-rw-r--r--TelepathyQt/base-channel.cpp190
-rw-r--r--TelepathyQt/base-channel.h50
-rw-r--r--TelepathyQt/service-types.h2
4 files changed, 265 insertions, 0 deletions
diff --git a/TelepathyQt/base-channel-internal.h b/TelepathyQt/base-channel-internal.h
index 4b8c807..543d759 100644
--- a/TelepathyQt/base-channel-internal.h
+++ b/TelepathyQt/base-channel-internal.h
@@ -92,4 +92,27 @@ signals:
void closed();
};
+class TP_QT_NO_EXPORT BaseChannelTextType::Adaptee : public QObject
+{
+ Q_OBJECT
+public:
+ Adaptee(BaseChannelTextType *interface);
+ ~Adaptee();
+
+public slots:
+ void acknowledgePendingMessages(const Tp::UIntList &IDs, const Tp::Service::ChannelTypeTextAdaptor::AcknowledgePendingMessagesContextPtr &context);
+//deprecated:
+ //void getMessageTypes(const Tp::Service::ChannelTypeTextAdaptor::GetMessageTypesContextPtr &context);
+ //void listPendingMessages(bool clear, const Tp::Service::ChannelTypeTextAdaptor::ListPendingMessagesContextPtr &context);
+ //void send(uint type, const QString &text, const Tp::Service::ChannelTypeTextAdaptor::SendContextPtr &context);
+signals:
+ void lostMessage();
+ void received(uint ID, uint timestamp, uint sender, uint type, uint flags, const QString &text);
+ void sendError(uint error, uint timestamp, uint type, const QString &text);
+ void sent(uint timestamp, uint type, const QString &text);
+
+public:
+ BaseChannelTextType *mInterface;
+};
+
}
diff --git a/TelepathyQt/base-channel.cpp b/TelepathyQt/base-channel.cpp
index a5fb5e9..b41b484 100644
--- a/TelepathyQt/base-channel.cpp
+++ b/TelepathyQt/base-channel.cpp
@@ -339,4 +339,194 @@ AbstractChannelInterface::~AbstractChannelInterface()
{
}
+// Chan.T.Text
+BaseChannelTextType::Adaptee::Adaptee(BaseChannelTextType *interface)
+ : QObject(interface),
+ mInterface(interface)
+{
+}
+
+BaseChannelTextType::Adaptee::~Adaptee()
+{
+}
+
+void BaseChannelTextType::Adaptee::acknowledgePendingMessages(const Tp::UIntList &IDs,
+ const Tp::Service::ChannelTypeTextAdaptor::AcknowledgePendingMessagesContextPtr &context)
+{
+ qDebug() << "BaseConnectionContactsInterface::acknowledgePendingMessages " << IDs;
+ DBusError error;
+ mInterface->acknowledgePendingMessages(IDs, &error);
+ if (error.isValid()) {
+ context->setFinishedWithError(error.name(), error.message());
+ return;
+ }
+ context->setFinished();
+}
+
+struct TP_QT_NO_EXPORT BaseChannelTextType::Private {
+ Private(BaseChannelTextType *parent, BaseChannel* channel)
+ : channel(channel),
+ pendingMessagesId(0),
+ adaptee(new BaseChannelTextType::Adaptee(parent)) {
+ }
+
+ BaseChannel* channel;
+ /* maps pending-message-id to message part list */
+ QMap<uint, Tp::MessagePartList> pendingMessages;
+ /* increasing unique id of pending messages */
+ uint pendingMessagesId;
+ MessageAcknowledgedCallback messageAcknowledgedCB;
+ BaseChannelTextType::Adaptee *adaptee;
+};
+
+/**
+ * \class BaseChannelTextType
+ * \ingroup servicecm
+ * \headerfile TelepathyQt/base-channel.h <TelepathyQt/BaseChannel>
+ *
+ * \brief Base class for implementations of Channel.Type.Text
+ *
+ */
+
+/**
+ * Class constructor.
+ */
+BaseChannelTextType::BaseChannelTextType(BaseChannel* channel)
+ : AbstractChannelInterface(TP_QT_IFACE_CHANNEL_TYPE_TEXT),
+ mPriv(new Private(this, channel))
+{
+}
+
+/**
+ * Class destructor.
+ */
+BaseChannelTextType::~BaseChannelTextType()
+{
+ delete mPriv;
+}
+
+/**
+ * Return the immutable properties of this interface.
+ *
+ * Immutable properties cannot change after the interface has been registered
+ * on a service on the bus with registerInterface().
+ *
+ * \return The immutable properties of this interface.
+ */
+QVariantMap BaseChannelTextType::immutableProperties() const
+{
+ return QVariantMap();
+}
+
+void BaseChannelTextType::createAdaptor()
+{
+ (void) new Service::ChannelTypeTextAdaptor(dbusObject()->dbusConnection(),
+ mPriv->adaptee, dbusObject());
+}
+
+void BaseChannelTextType::addReceivedMessage(const Tp::MessagePartList &msg)
+{
+ MessagePartList message = msg;
+ if (msg.empty()) {
+ warning() << "empty message: not sent";
+ return;
+ }
+ MessagePart &header = message.front();
+
+ if (header.count(QLatin1String("pending-message-id")))
+ warning() << "pending-message-id will be overwritten";
+
+ /* Add pending-message-id to header */
+ uint pendingMessageId = mPriv->pendingMessagesId++;
+ header[QLatin1String("pending-message-id")] = QDBusVariant(pendingMessageId);
+ mPriv->pendingMessages[pendingMessageId] = message;
+
+ uint timestamp = 0;
+ if (header.count(QLatin1String("message-received")))
+ timestamp = header[QLatin1String("message-received")].variant().toUInt();
+
+ uint handle = 0;
+ if (header.count(QLatin1String("message-sender")))
+ handle = header[QLatin1String("message-sender")].variant().toUInt();
+
+ uint type = ChannelTextMessageTypeNormal;
+ if (header.count(QLatin1String("message-type")))
+ type = header[QLatin1String("message-type")].variant().toUInt();
+
+ //FIXME: flags are not parsed
+ uint flags = 0;
+
+ QString content;
+ for (MessagePartList::Iterator i = message.begin() + 1; i != message.end(); ++i)
+ if (i->count(QLatin1String("content-type"))
+ && i->value(QLatin1String("content-type")).variant().toString() == QLatin1String("text/plain")
+ && i->count(QLatin1String("content"))) {
+ content = i->value(QLatin1String("content")).variant().toString();
+ break;
+ }
+ if (content.length() > 0)
+ QMetaObject::invokeMethod(mPriv->adaptee, "received",
+ Qt::QueuedConnection,
+ Q_ARG(uint, pendingMessageId),
+ Q_ARG(uint, timestamp),
+ Q_ARG(uint, handle),
+ Q_ARG(uint, type),
+ Q_ARG(uint, flags),
+ Q_ARG(QString, content));
+
+ /* Signal on ChannelMessagesInterface */
+ BaseChannelMessagesInterfacePtr messagesIface = BaseChannelMessagesInterfacePtr::dynamicCast(
+ mPriv->channel->interface(TP_QT_IFACE_CHANNEL_INTERFACE_MESSAGES));
+ if (messagesIface)
+ QMetaObject::invokeMethod(messagesIface.data(), "messageReceived",
+ Qt::QueuedConnection,
+ Q_ARG(Tp::MessagePartList, message));
+}
+
+Tp::MessagePartListList BaseChannelTextType::pendingMessages()
+{
+ return mPriv->pendingMessages.values();
+}
+
+/*
+ * Will be called with the value of the message-token field after a received message has been acknowledged,
+ * if the message-token field existed in the header.
+ */
+void BaseChannelTextType::setMessageAcknowledgedCallback(const MessageAcknowledgedCallback &cb)
+{
+ mPriv->messageAcknowledgedCB = cb;
+}
+
+void BaseChannelTextType::acknowledgePendingMessages(const Tp::UIntList &IDs, DBusError* error)
+{
+ foreach(uint id, IDs) {
+ QMap<uint, Tp::MessagePartList>::Iterator i = mPriv->pendingMessages.find(id);
+ if (i == mPriv->pendingMessages.end()) {
+ error->set(TP_QT_ERROR_INVALID_ARGUMENT, QLatin1String("id not found"));
+ return;
+ }
+
+ MessagePart &header = i->front();
+ if (header.count(QLatin1String("message-token")) && mPriv->messageAcknowledgedCB.isValid())
+ mPriv->messageAcknowledgedCB(header[QLatin1String("message-token")].variant().toString());
+
+ mPriv->pendingMessages.erase(i);
+ }
+
+ /* Signal on ChannelMessagesInterface */
+ BaseChannelMessagesInterfacePtr messagesIface = BaseChannelMessagesInterfacePtr::dynamicCast(
+ mPriv->channel->interface(TP_QT_IFACE_CHANNEL_INTERFACE_MESSAGES));
+ if (messagesIface) //emit after return
+ QMetaObject::invokeMethod(messagesIface.data(), "pendingMessagesRemoved",
+ Qt::QueuedConnection,
+ Q_ARG(Tp::UIntList, IDs));
+}
+
+
+
+void BaseChannelTextType::sent(uint timestamp, uint type, QString text)
+{
+ emit mPriv->adaptee->sent(timestamp, type, text);
+}
+
}
diff --git a/TelepathyQt/base-channel.h b/TelepathyQt/base-channel.h
index b9911a6..c6cc7bd 100644
--- a/TelepathyQt/base-channel.h
+++ b/TelepathyQt/base-channel.h
@@ -106,5 +106,55 @@ private:
Private *mPriv;
};
+class TP_QT_EXPORT BaseChannelTextType : public AbstractChannelInterface
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(BaseChannelTextType)
+
+public:
+ static BaseChannelTextTypePtr create(BaseChannel* channel) {
+ return BaseChannelTextTypePtr(new BaseChannelTextType(channel));
+ }
+ template<typename BaseChannelTextTypeSubclass>
+ static SharedPtr<BaseChannelTextTypeSubclass> create(BaseChannel* channel) {
+ return SharedPtr<BaseChannelTextTypeSubclass>(
+ new BaseChannelTextTypeSubclass(channel));
+ }
+
+ typedef Callback2<QDBusObjectPath, const QVariantMap&, DBusError*> CreateChannelCallback;
+ CreateChannelCallback createChannel;
+
+ typedef Callback2<bool, const QVariantMap&, DBusError*> EnsureChannelCallback;
+ EnsureChannelCallback ensureChannel;
+
+ virtual ~BaseChannelTextType();
+
+ QVariantMap immutableProperties() const;
+
+ Tp::RequestableChannelClassList requestableChannelClasses;
+
+ typedef Callback1<void, QString> MessageAcknowledgedCallback;
+ void setMessageAcknowledgedCallback(const MessageAcknowledgedCallback &cb);
+
+ Tp::MessagePartListList pendingMessages();
+
+ /* Convenience function */
+ void addReceivedMessage(const Tp::MessagePartList &message);
+private Q_SLOTS:
+ void sent(uint timestamp, uint type, QString text);
+protected:
+ BaseChannelTextType(BaseChannel* channel);
+ void acknowledgePendingMessages(const Tp::UIntList &IDs, DBusError* error);
+
+private:
+ void createAdaptor();
+
+ class Adaptee;
+ friend class Adaptee;
+ struct Private;
+ friend struct Private;
+ Private *mPriv;
+};
+
}
#endif
diff --git a/TelepathyQt/service-types.h b/TelepathyQt/service-types.h
index c579767..bb19d29 100644
--- a/TelepathyQt/service-types.h
+++ b/TelepathyQt/service-types.h
@@ -44,6 +44,7 @@ class BaseProtocolAddressingInterface;
class BaseProtocolAvatarsInterface;
class BaseProtocolPresenceInterface;
class BaseChannel;
+class BaseChannelTextType;
class DBusService;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -60,6 +61,7 @@ typedef SharedPtr<BaseProtocolAddressingInterface> BaseProtocolAddressingInterfa
typedef SharedPtr<BaseProtocolAvatarsInterface> BaseProtocolAvatarsInterfacePtr;
typedef SharedPtr<BaseProtocolPresenceInterface> BaseProtocolPresenceInterfacePtr;
typedef SharedPtr<BaseChannel> BaseChannelPtr;
+typedef SharedPtr<BaseChannelTextType> BaseChannelTextTypePtr;
typedef SharedPtr<DBusService> DBusServicePtr;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */