[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kte-collaborative/ktp-integration] kte-plugin: (non-working, non-compiling) API draft for KTp integ
From: Sven Brauch <svenbrauch () googlemail ! com>
Date: 2013-06-30 20:44:44
Message-ID: E1UtOUG-0003ze-K6 () scm ! kde ! org
[Download RAW message or body]
Git commit c441d2d52a3ade94b96844d6ba0788a1a08af3a7 by Sven Brauch.
Committed on 30/06/2013 at 20:44.
Pushed by brauch into branch 'ktp-integration'.
(non-working, non-compiling) API draft for KTp integration
M +1 -0 kte-plugin/CMakeLists.txt
A +24 -0 kte-plugin/ktpintegration/CMakeLists.txt
A +168 -0 kte-plugin/ktpintegration/inftube.cpp [License: GPL (v2+)]
A +141 -0 kte-plugin/ktpintegration/inftube.h [License: GPL (v2+)]
http://commits.kde.org/kte-collaborative/c441d2d52a3ade94b96844d6ba0788a1a08af3a7
diff --git a/kte-plugin/CMakeLists.txt b/kte-plugin/CMakeLists.txt
index d080612..33e9dbd 100644
--- a/kte-plugin/CMakeLists.txt
+++ b/kte-plugin/CMakeLists.txt
@@ -8,6 +8,7 @@
cmake_minimum_required(VERSION 2.8)
add_subdirectory(settings)
+add_subdirectory(ktpintegration)
find_package(KDE4 4.5.0 REQUIRED)
include(KDE4Defaults)
diff --git a/kte-plugin/ktpintegration/CMakeLists.txt \
b/kte-plugin/ktpintegration/CMakeLists.txt new file mode 100644
index 0000000..6324952
--- /dev/null
+++ b/kte-plugin/ktpintegration/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(tubestest_SRCS
+ tubestest.cpp
+)
+
+set(IS_KTP_INTERNAL_MODULE TRUE) # aw yeah
+find_package(TelepathyQt4 0.8.9 REQUIRED)
+find_package(KTp REQUIRED)
+include_directories(
+ ${TELEPATHY_QT4_INCLUDE_DIR}
+ ${KTP_INCLUDE_DIR}
+)
+
+add_library(inftube SHARED ${tubestest_SRCS})
+
+target_link_libraries(inftube
+ ${KDE4_KDEUI_LIBS}
+ ${TELEPATHY_QT4_LIBRARIES}
+ ${KTP_LIBRARIES}
+ ${KDE4_KIO_LIBS}
+ ${KTP_MODELS_LIBRARIES}
+ ${KTP_WIDGETS_LIBRARIES}
+)
+
+install(TARGETS inftube lib)
diff --git a/kte-plugin/ktpintegration/inftube.cpp \
b/kte-plugin/ktpintegration/inftube.cpp new file mode 100644
index 0000000..a01c87b
--- /dev/null
+++ b/kte-plugin/ktpintegration/inftube.cpp
@@ -0,0 +1,168 @@
+/***************************************************************************
+ * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ ***************************************************************************/
+
+#include "inftube.h"
+
+#include <KTp/debug.h>
+#include <KTp/Widgets/contact-grid-dialog.h>
+#include <KTp/contact-factory.h>
+#include <telepathy-qt4/TelepathyQt/AccountFactory>
+#include <telepathy-qt4/TelepathyQt/AccountManager>
+#include <telepathy-qt4/TelepathyQt/StreamTubeClient>
+#include <telepathy-qt4/TelepathyQt/StreamTubeServer>
+#include <telepathy-qt4/TelepathyQt/PendingChannelRequest>
+#include <TelepathyQt/ReferencedHandles>
+#include <QTcpServer>
+#include <QTcpSocket>
+#include <unistd.h>
+#include <KIO/Job>
+#include <KDebug>
+#include <krun.h>
+
+void InfTubeBase::initialize()
+{
+ Tp::registerTypes();
+ KTp::Debug::installCallback(true);
+
+ Tp::AccountFactoryPtr accountFactory = \
Tp::AccountFactory::create(QDBusConnection::sessionBus(), + \
Tp::Features() << Tp::Account::FeatureCore + \
<< Tp::Account::FeatureAvatar + \
<< Tp::Account::FeatureProtocolInfo + \
<< Tp::Account::FeatureProfile); +
+ Tp::ConnectionFactoryPtr connectionFactory = \
Tp::ConnectionFactory::create(QDBusConnection::sessionBus(), + \
Tp::Features() << Tp::Connection::FeatureCore + \
<< Tp::Connection::FeatureRosterGroups + \
<< Tp::Connection::FeatureRoster + \
<< Tp::Connection::FeatureSelfContact); +
+ Tp::ContactFactoryPtr contactFactory = \
KTp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias + \
<< Tp::Contact::FeatureAvatarData + \
<< Tp::Contact::FeatureSimplePresence + \
<< Tp::Contact::FeatureCapabilities); +
+ Tp::ChannelFactoryPtr channelFactory = \
Tp::ChannelFactory::create(QDBusConnection::sessionBus()); +
+ m_accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
+ accountFactory,
+ connectionFactory,
+ channelFactory,
+ contactFactory);
+
+}
+
+unsigned int InfTubeBase::localPort() const
+{
+ return m_port;
+}
+
+KUrl InfTubeBase::localUrl() const
+{
+ KUrl url;
+ url.setProtocol(QLatin1String("inf"));
+ url.setHost(QLatin1String("localhost"));
+ url.setPort(m_port);
+ return url;
+}
+
+InfTubeBase::ConnectionStatus InfTubeBase::status() const
+{
+ return m_status;
+}
+
+InfTubeServer::InfTubeServer(QObject* parent)
+{
+ initialize();
+ m_tubeServer = Tp::StreamTubeServer::create(m_accountManager, QStringList() << \
"infinity-collaborative"); +}
+
+bool InfTubeServer::offer(const Tp::Account& account, const Tp::ContactPtr& contact, \
const KUrl& document) +{
+ offer(ContactList() << contact, DocumentList() << document);
+}
+
+bool InfTubeServer::offer(const Tp::Account& account, const ContactList& contacts, \
const DocumentList& initialDocuments) +{
+ qDebug() << "starting infinoted";
+ startInfinoted();
+ m_tubeServer->exportTcpSocket(QHostAddress(QHostAddress::LocalHost), m_port);
+ foreach ( const KUrl& document, initialDocuments ) {
+ KUrl x = localUrl();
+ x.setFileName(document.fileName());
+ KIO::TransferJob* job = KIO::put(x, -1);
+ connect(job, SIGNAL(finished(KJob*)), this, SLOT(testFileCreated(KJob*)));
+ }
+ Tp::PendingChannelRequest* channelRequest = 0;
+ QVariantMap request;
+ request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".ChannelType"),
+ TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE);
+ request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
+ (uint) Tp::HandleTypeContact);
+ request.insert(TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE + QLatin1String(".Service"),
+ QLatin1String("tubetest"));
+ // TODO !!!
+ request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandle"),
+ contacts.first()->handle().at(0));
+ account.ensureChannel(request,
+ QDateTime::currentDateTime(),
+ \
"org.freedesktop.Telepathy.Client.KTp.infinity-collaborative"); +
+ connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)),
+ this, SLOT(onCreateTubeFinished(Tp::PendingOperation*)));
+}
+
+void InfTubeServer::startInfinoted()
+{
+ m_serverProcess = new QProcess;
+ m_serverProcess->setEnvironment(QStringList() << \
"LIBINFINITY_DEBUG_PRINT_TRAFFIC=1"); + \
m_serverProcess->setStandardOutputFile(serverDirectory() + "/infinoted.log"); + \
m_serverProcess->setStandardErrorFile(serverDirectory() + "/infinoted.errors"); + \
m_serverProcess->start("/usr/bin/env", QStringList() << "infinoted-0.5" << \
"--security-policy=no-tls" + << "-r" << \
serverDirectory() << "-p" << QString::number(m_port)); + \
m_serverProcess->waitForStarted(500); + while ( true ) {
+ sleep(1);
+ QTcpSocket s;
+ s.connectToHost("localhost", m_port);
+ if ( s.waitForConnected(100) ) {
+ break;
+ }
+ }
+ qDebug() << "successfully started infinioted on port" << m_port << "( root dir" \
<< serverDirectory() << ")"; +}
+
+const QString InfTubeServer::serverDirectory() const
+{
+ return QLatin1String("/tmp");
+}
+
+void InfTubeClient::listen()
+{
+ m_tubeClient = Tp::StreamTubeClient::create(m_accountManager, QStringList() << \
"tubetest", QStringList(), QString(), true, true); + \
m_tubeClient->setToAcceptAsTcp(); + connect(m_tubeClient.data(), \
SIGNAL(tubeAcceptedAsTcp(QHostAddress,quint16,QHostAddress,quint16,Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr)),
+ this, SLOT(tubeAcceptedAsTcp(QHostAddress,quint16,QHostAddress,quint16,Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr)));
+}
+
+void InfTubeClient::tubeAcceptedAsTcp(QHostAddress , quint16 , QHostAddress , \
quint16 , Tp::AccountPtr , Tp::IncomingStreamTubeChannelPtr ) +{
+ kDebug() << "Tube accepted as Tcp";
+}
+
+#include "inftube.moc"
diff --git a/kte-plugin/ktpintegration/inftube.h \
b/kte-plugin/ktpintegration/inftube.h new file mode 100644
index 0000000..e3b2b21
--- /dev/null
+++ b/kte-plugin/ktpintegration/inftube.h
@@ -0,0 +1,141 @@
+/***************************************************************************
+ * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ ***************************************************************************/
+
+#ifndef TUBESTEST_H
+#define TUBESTEST_H
+
+#include <telepathy-qt4/TelepathyQt/Types>
+#include <telepathy-qt4/TelepathyQt/StreamTubeChannel>
+#include <telepathy-qt4/TelepathyQt/IncomingStreamTubeChannel>
+#include <telepathy-qt4/TelepathyQt/OutgoingStreamTubeChannel>
+#include <telepathy-qt4/TelepathyQt/StreamTubeClient>
+#include <telepathy-qt4/TelepathyQt/StreamTubeServer>
+#include <telepathy-qt4/TelepathyQt/AccountManager>
+
+#include <KJob>
+#include <KUrl>
+
+namespace Tp {
+ class StreamTubeClient;
+}
+
+typedef QList<const Tp::ContactPtr> ContactList;
+typedef QList<const KUrl> DocumentList;
+
+/**
+ * This class defines the API for routing infinity traffic through a TP tube
+ * which is common to both the receiving an the offering side.
+ */
+class InfTubeBase : public QObject {
+Q_OBJECT
+public:
+ InfTubeBase(QObject* parent = 0) = 0;
+ virtual ~InfTubeBase() = 0;
+
+ enum ConnectionStatus {
+ StatusConnected,
+ StatusConnecting,
+ StatusDisconnected
+ };
+
+ /**
+ * @brief Get the local port this tube ends in.
+ * @return unsigned int the port
+ */
+ unsigned int localPort() const;
+
+ /**
+ * @brief Get the URL which points to the infinote server.
+ * @return KUrl the URL, something like inf://localhost:foo
+ */
+ KUrl localUrl() const;
+
+ /**
+ * @brief Get the status of the connection.
+ */
+ ConnectionStatus status() const;
+
+signals:
+ /**
+ * @brief Emitted when the connection has been established
+ */
+ void connected(InfTubeBase* self);
+
+
+protected:
+ Tp::AccountManagerPtr m_accountManager;
+ ConnectionStatus m_status;
+ unsigned int m_port;
+
+ /**
+ * @brief Performs some initialization tasks. Call before everything else.
+ */
+ void initialize();
+};
+
+/**
+ * @brief This class implements InfTubeBase and is used on the receiving end.
+ */
+class InfTubeClient : public InfTubeBase {
+public:
+ InfTubeClient(QObject* parent = 0);
+ virtual ~InfTubeClient();
+
+ /**
+ * @brief Begin waiting for incoming connections.
+ */
+ void listen();
+
+private:
+ Tp::StreamTubeClientPtr m_tubeClient;
+public slots:
+ void tubeAcceptedAsTcp(QHostAddress,quint16,QHostAddress,quint16,Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr);
+};
+
+/**
+ * @brief This class implements InfTubeBase and can be used to offer some documents \
to a contact. + */
+class InfTubeServer : public InfTubeBase {
+public:
+ InfTubeServer(QObject* parent = 0);
+ virtual ~InfTubeServer();
+
+ /**
+ * @brief Initiate editing a list of documents with the given contacts.
+ *
+ * @param contacts The list of contacts to edit documents with
+ * @param initialDocuments The documents all contacts should have opened \
initially + * @return bool true if the request was successful
+ */
+ bool offer(const Tp::Account& account, const ContactList& contacts, const \
DocumentList& initialDocuments); +
+ /**
+ * @brief Convenience overload, for offering a single document to a single \
contact. + */
+ bool offer(const Tp::Account& account, const Tp::ContactPtr& contact, const \
KUrl& document); +
+private:
+ Tp::StreamTubeServerPtr m_tubeServer;
+ QProcess* m_serverProcess;
+
+ void startInfinoted();
+ const QString serverDirectory() const;
+};
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic