1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2009-2011 Collabora Ltd <info@collabora.co.uk> |
4 | ** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net> |
5 | ** |
6 | ** This file is part of KDE. |
7 | ** |
8 | ** This program is free software; you can redistribute it and/or modify |
9 | ** it under the terms of the GNU General Public License as published by |
10 | ** the Free Software Foundation; either version 2 of the License, or |
11 | ** (at your option) any later version. |
12 | ** |
13 | ** This program is distributed in the hope that it will be useful, |
14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | ** GNU General Public License for more details. |
17 | ** |
18 | ** You should have received a copy of the GNU General Public License |
19 | ** along with this program; see the file COPYING. If not, write to |
20 | ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | ** Boston, MA 02110-1301, USA. |
22 | ** |
23 | ****************************************************************************/ |
24 | |
25 | #include "tubesmanager.h" |
26 | |
27 | #include <TelepathyQt/IncomingStreamTubeChannel> |
28 | #include <TelepathyQt/Debug> |
29 | |
30 | #include <KDebug> |
31 | |
32 | |
33 | TubesManager::TubesManager(QObject *parent) |
34 | : QObject(parent) |
35 | { |
36 | kDebug() << "Initializing tubes manager" ; |
37 | |
38 | Tp::enableDebug(true); |
39 | Tp::enableWarnings(true); |
40 | |
41 | /* Registering telepathy types */ |
42 | Tp::registerTypes(); |
43 | |
44 | m_stubeClient = Tp::StreamTubeClient::create( |
45 | QStringList() << QLatin1String("rfb" ), |
46 | QStringList(), |
47 | QLatin1String("krdc_rfb_handler" )); |
48 | |
49 | m_stubeClient->setToAcceptAsTcp(); |
50 | |
51 | connect(m_stubeClient.data(), |
52 | SIGNAL(tubeAcceptedAsTcp(QHostAddress,quint16,QHostAddress,quint16, |
53 | Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr)), |
54 | SLOT(onTubeAccepted(QHostAddress,quint16,QHostAddress,quint16, |
55 | Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr))); |
56 | } |
57 | |
58 | TubesManager::~TubesManager() |
59 | { |
60 | kDebug() << "Destroying tubes manager" ; |
61 | } |
62 | |
63 | void TubesManager::closeTube(const KUrl& url) |
64 | { |
65 | if (m_tubes.contains(url)) { |
66 | m_tubes.take(url)->requestClose(); |
67 | } |
68 | } |
69 | |
70 | void TubesManager::onTubeAccepted( |
71 | const QHostAddress & listenAddress, quint16 listenPort, |
72 | const QHostAddress & sourceAddress, quint16 sourcePort, |
73 | const Tp::AccountPtr & account, |
74 | const Tp::IncomingStreamTubeChannelPtr & tube) |
75 | { |
76 | Q_UNUSED(sourceAddress); |
77 | Q_UNUSED(sourcePort); |
78 | Q_UNUSED(account); |
79 | |
80 | KUrl url; |
81 | url.setScheme("vnc" ); |
82 | url.setHost(listenAddress.toString()); |
83 | url.setPort(listenPort); |
84 | |
85 | kDebug() << "newConnection:" << url; |
86 | m_tubes.insert(url, tube); |
87 | emit newConnection(url); |
88 | } |
89 | |