26 #include <TelepathyQt/Debug>
27 #include <TelepathyQt/Contact>
28 #include <TelepathyQt/AccountFactory>
29 #include <TelepathyQt/ConnectionFactory>
30 #include <TelepathyQt/ContactFactory>
31 #include <TelepathyQt/ChannelFactory>
32 #include <TelepathyQt/OutgoingStreamTubeChannel>
33 #include <TelepathyQt/StreamTubeServer>
35 #ifdef KRFB_WITH_KDE_TELEPATHY
36 #include <TelepathyQt/AccountSet>
37 #include <TelepathyQt/AccountManager>
38 #include <TelepathyQt/PendingReady>
39 #include <KTp/Models/contacts-list-model.h>
40 #include <KTp/contact-factory.h>
43 struct TubesRfbServer::Private
45 Tp::StreamTubeServerPtr stubeServer;
65 kDebug() <<
"starting";
67 Tp::enableDebug(
true);
68 Tp::enableWarnings(
true);
71 Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
73 Tp::Features() << Tp::Account::FeatureCore
74 << Tp::Account::FeatureAvatar
75 << Tp::Account::FeatureCapabilities
76 << Tp::Account::FeatureProtocolInfo
77 << Tp::Account::FeatureProfile);
79 Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(
81 Tp::Features() << Tp::Connection::FeatureCore
82 << Tp::Connection::FeatureSelfContact);
84 Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(
87 #ifdef KRFB_WITH_KDE_TELEPATHY
88 Tp::ContactFactoryPtr contactFactory = KTp::ContactFactory::create(
89 Tp::Features() << Tp::Contact::FeatureAlias
90 <<Tp::Contact::FeatureAvatarToken
91 <<Tp::Contact::FeatureAvatarData
92 <<Tp::Contact::FeatureSimplePresence
93 <<Tp::Contact::FeatureCapabilities
94 <<Tp::Contact::FeatureClientTypes);
96 m_accountManager = Tp::AccountManager::create(
103 d->stubeServer = Tp::StreamTubeServer::create(
110 connect(m_accountManager->becomeReady(),
111 SIGNAL(finished(Tp::PendingOperation*)),
113 SLOT(onAccountManagerReady()));
115 m_contactsListModel =
new KTp::ContactsListModel(
this);
117 Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(
118 Tp::Contact::FeatureAlias);
120 d->stubeServer = Tp::StreamTubeServer::create(
129 #endif //KRFB_WITH_KDE_TELEPATHY
132 SIGNAL(tubeRequested(Tp::AccountPtr,Tp::OutgoingStreamTubeChannelPtr,
134 SLOT(onTubeRequested()));
136 SIGNAL(tubeClosed(Tp::AccountPtr,Tp::OutgoingStreamTubeChannelPtr,
QString,
QString)),
137 SLOT(onTubeClosed()));
140 SIGNAL(newTcpConnection(
QHostAddress,quint16,Tp::AccountPtr,
141 Tp::ContactPtr,Tp::OutgoingStreamTubeChannelPtr)),
142 SLOT(onNewTcpConnection(
QHostAddress,quint16,Tp::AccountPtr,
143 Tp::ContactPtr,Tp::OutgoingStreamTubeChannelPtr)));
145 SIGNAL(tcpConnectionClosed(
QHostAddress,quint16,Tp::AccountPtr,Tp::ContactPtr,
147 SLOT(onTcpConnectionClosed(
QHostAddress,quint16,Tp::AccountPtr,Tp::ContactPtr,
164 #ifdef KRFB_WITH_KDE_TELEPATHY
165 KTp::ContactsListModel *TubesRfbServer::contactsListModel()
167 return m_contactsListModel;
171 void TubesRfbServer::startAndCheck()
176 for (
int i=0; !ok && i<5; i++) {
182 kError() <<
"Failed to start tubes rfb server";
192 void TubesRfbServer::onTubeRequested()
194 kDebug() <<
"Got a tube";
197 void TubesRfbServer::onTubeClosed()
199 kDebug() <<
"tube closed";
202 void TubesRfbServer::onNewTcpConnection(
const QHostAddress & sourceAddress,
204 const Tp::AccountPtr & account,
205 const Tp::ContactPtr & contact,
206 const Tp::OutgoingStreamTubeChannelPtr & tube)
211 kDebug() <<
"CM signaled tube connection from" << sourceAddress <<
":" << sourcePort;
213 d->contactsPerPort[sourcePort] = contact;
214 if (d->clientsPerPort.contains(sourcePort)) {
215 kDebug() <<
"client already exists";
216 d->clientsPerPort[sourcePort]->setContact(contact);
220 void TubesRfbServer::onTcpConnectionClosed(
const QHostAddress& sourceAddress,
222 const Tp::AccountPtr& account,
223 const Tp::ContactPtr& contact,
226 const Tp::OutgoingStreamTubeChannelPtr& tube)
232 kDebug() <<
"Connection from" << sourceAddress <<
":" << sourcePort <<
"closed."
235 d->clientsPerPort.remove(sourcePort);
236 d->contactsPerPort.remove(sourcePort);
244 kDebug() <<
"new tube client on port" << port;
246 d->clientsPerPort[port] = c;
247 if (d->contactsPerPort.contains(port)) {
248 kDebug() <<
"already have a contact";
255 #ifdef KRFB_WITH_KDE_TELEPATHY
256 void TubesRfbServer::onAccountManagerReady()
258 m_contactsListModel->setAccountManager(m_accountManager);
262 #include "tubesrfbserver.moc"
QString fromAscii(const char *str, int size)
void setListeningPort(int port)
QDBusConnection sessionBus()
unsigned short peerPort(int sock)
virtual PendingRfbClient * newClient(rfbClientPtr client)
int listeningPort() const
virtual void stop(bool disconnectClients=true)
static TubesRfbServer * instance
void setPasswordRequired(bool passwordRequired)
virtual ~TubesRfbServer()
void setListeningAddress(const QByteArray &address)
TubesRfbServer(QObject *parent=0)
void setContact(const Tp::ContactPtr &contact)
QByteArray listeningAddress() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)