2 * This file is part of TpSession
4 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
5 * Contact Kate Alhola kate.alholanokia.com
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "tpsessionchannel.h"
23 TpSessionChannel::TpSessionChannel(Tp::ConnectionPtr conn,const Tp::ContactPtr &contact)
26 qDebug() << "TpSessionChannel::TpSessionChannel" <<"contact.id() " << contact->id();
27 request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".ChannelType"),
28 TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT);
29 request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"),
30 (uint) Tp::HandleTypeContact);
31 request.insert(QLatin1String(TELEPATHY_INTERFACE_CHANNEL ".TargetHandle"),
32 contact->handle()[0]);
34 connect(conn->ensureChannel(request),
35 SIGNAL(finished(Tp::PendingOperation*)),
36 SLOT(onChannelCreated(Tp::PendingOperation*)));
42 TpSessionChannel::TpSessionChannel(Tp::TextChannelPtr ch)
44 qDebug() << "TpSessionChannel::TpSessionChannel" <<"path " << ch->objectPath();
46 connect(channel->becomeReady(Tp::TextChannel::FeatureMessageQueue|Tp::TextChannel::FeatureMessageSentSignal),
47 SIGNAL(finished(Tp::PendingOperation *)),
48 SLOT(onChannelReady(Tp::PendingOperation *)));
52 void TpSessionChannel::onChannelCreated(Tp::PendingOperation *op)
54 qDebug() << "TpSessionChannel::onOutgoingChannelCreated" ;
56 qWarning() << "Connection cannot become connected" ;
59 Tp::PendingChannel *pc = qobject_cast<Tp::PendingChannel *>(op);
61 channel = Tp::TextChannel::create(pc->connection(),pc->objectPath(), pc->immutableProperties());
63 connect(channel->becomeReady(Tp::TextChannel::FeatureMessageQueue | Tp::TextChannel::FeatureMessageSentSignal),
64 SIGNAL(finished(Tp::PendingOperation*)),
65 SLOT(onChannelReady(Tp::PendingOperation*)));
68 void TpSessionChannel::onChannelReady(Tp::PendingOperation *op)
70 qDebug() << "TpSessionChannel::onChannelReady type=" << channel->channelType() <<"path " << channel->objectPath() <<
71 "initiatorContact=" << (channel->initiatorContact() ? channel->initiatorContact()->id():"NULL") ;
73 connect(channel.data(),
74 SIGNAL(messageReceived(const Tp::ReceivedMessage &)),
75 SLOT(onMessageReceived(const Tp::ReceivedMessage &)));
76 connect(channel.data(),
77 SIGNAL(messageSent(const Tp::Message &,Tp::MessageSendingFlags, const QString &)),
78 SLOT(onMessageSent(const Tp::Message &,Tp::MessageSendingFlags, const QString &)));
79 emit channelReady(this);
80 peerContact=channel->initiatorContact();
81 QList<Tp::ReceivedMessage> queuedMessages = channel->messageQueue();
82 foreach(Tp::ReceivedMessage message, queuedMessages) {
83 qDebug() << "received " << message.text();
84 emit messageReceived(message,this);
87 void TpSessionChannel::sendMessage(QString message)
89 channel->send(message);
91 void TpSessionChannel::onMessageReceived(const Tp::ReceivedMessage &msg)
93 qDebug() << "TpSessionChannel::onMessageReceived " << msg.text();
94 emit messageReceived(msg,this);
96 void TpSessionChannel::onMessageSent(const Tp::Message &msg,Tp::MessageSendingFlags sflags, const QString &flags)
98 qDebug() << "TpSessionChannel::onMessageSent";
99 emit messageSent(msg,sflags,flags,this);
102 QString TpSessionChannel::peerId()
104 return peerContact ? peerContact->id():"";