[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kte-collaborative/ktp-integration] kte-plugin/ktpintegration: Extremely bad, but working prototype
From:       Sven Brauch <svenbrauch () googlemail ! com>
Date:       2013-07-05 0:23:56
Message-ID: E1Uutoa-0001N3-Lg () scm ! kde ! org
[Download RAW message or body]

Git commit dc25c6ecd2664b68cd4637055fa4dbcbec5a8381 by Sven Brauch.
Committed on 05/07/2013 at 00:23.
Pushed by brauch into branch 'ktp-integration'.

Extremely bad, but working prototype for launching a collab session over Tp

Installation of the service files is missing, sorry

M  +12   -0    kte-plugin/ktpintegration/CMakeLists.txt
A  +9    -0    kte-plugin/ktpintegration/KTp.infinity.client
M  +47   -22   kte-plugin/ktpintegration/inftube.cpp
M  +42   -12   kte-plugin/ktpintegration/inftube.h
A  +20   -0    kte-plugin/ktpintegration/inftube_export.h     [License: UNKNOWN]  *
A  +3    -0    kte-plugin/ktpintegration/org.freedesktop.Telepathy.Client.KTp.infinity.service
 A  +45   -0    kte-plugin/ktpintegration/tubehandler.cpp     [License: GPL (v2+)]

The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.


http://commits.kde.org/kte-collaborative/dc25c6ecd2664b68cd4637055fa4dbcbec5a8381

diff --git a/kte-plugin/ktpintegration/CMakeLists.txt \
b/kte-plugin/ktpintegration/CMakeLists.txt index 77e3a1d..98685ad 100644
--- a/kte-plugin/ktpintegration/CMakeLists.txt
+++ b/kte-plugin/ktpintegration/CMakeLists.txt
@@ -24,3 +24,15 @@ target_link_libraries(inftube
 )
 
 install(TARGETS inftube ${INSTALL_TARGETS_DEFAULT_ARGS})
+
+# the tube handler
+kde4_add_executable(tubehandler tubehandler.cpp)
+target_link_libraries(tubehandler
+                      inftube
+                      ${KTP_LIBRARIES}
+                      ${KDE4_KIO_LIBS}
+                      ${KDE4_KDEUI_LIBS}
+                      ${TELEPATHY_QT4_LIBRARIES}
+)
+
+install(TARGETS tubehandler DESTINATION ${BIN_INSTALL_DIR})
diff --git a/kte-plugin/ktpintegration/KTp.infinity.client \
b/kte-plugin/ktpintegration/KTp.infinity.client new file mode 100644
index 0000000..a7e40e0
--- /dev/null
+++ b/kte-plugin/ktpintegration/KTp.infinity.client
@@ -0,0 +1,9 @@
+[org.freedesktop.Telepathy.Client]
+Interfaces=org.freedesktop.Telepathy.Client.Handler
+
+[org.freedesktop.Telepathy.Client.Handler.HandlerChannelFilter 0]
+org.freedesktop.Telepathy.Channel.ChannelType \
s=org.freedesktop.Telepathy.Channel.Type.StreamTube \
+org.freedesktop.Telepathy.Channel.TargetHandleType u=1 \
+org.freedesktop.Telepathy.Channel.Type.StreamTube.Service s=infinity \
+org.freedesktop.Telepathy.Channel.Requested b=false +
diff --git a/kte-plugin/ktpintegration/inftube.cpp \
b/kte-plugin/ktpintegration/inftube.cpp index 0b60edc..86a5fa7 100644
--- a/kte-plugin/ktpintegration/inftube.cpp
+++ b/kte-plugin/ktpintegration/inftube.cpp
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}>                 *
+ *   Copyright (C) 2013 by Sven Brauch <svenbrauch@gmail.com>              *
  *                                                                         *
  *   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  *
@@ -28,10 +28,13 @@
 #include <telepathy-qt4/TelepathyQt/StreamTubeServer>
 #include <telepathy-qt4/TelepathyQt/PendingChannelRequest>
 #include <TelepathyQt/ReferencedHandles>
+#include <TelepathyQt/ClientRegistrar>
+#include <TelepathyQt/ChannelClassSpecList>
 #include <QTcpServer>
 #include <QTcpSocket>
 #include <unistd.h>
 #include <KIO/Job>
+#include <KRun>
 #include <KDebug>
 #include <krun.h>
 
@@ -65,8 +68,15 @@ void InfTubeBase::initialize()
                                                   channelFactory,
                                                   contactFactory);
 
+//     m_registrar = Tp::ClientRegistrar::create(QDBusConnection::sessionBus(), \
accountFactory, +//                                                                 \
connectionFactory, channelFactory, contactFactory);  }
 
+// Tp::ClientRegistrarPtr InfTubeBase::clientRegistrar() const
+// {
+//     return m_registrar;
+// }
+
 unsigned int InfTubeBase::localPort() const
 {
     return m_port;
@@ -76,7 +86,7 @@ KUrl InfTubeBase::localUrl() const
 {
     KUrl url;
     url.setProtocol(QLatin1String("inf"));
-    url.setHost(QLatin1String("localhost"));
+    url.setHost(QLatin1String("127.0.0.1"));
     url.setPort(m_port);
     return url;
 }
@@ -86,10 +96,15 @@ InfTubeBase::ConnectionStatus InfTubeBase::status() const
     return m_status;
 }
 
+//  + QString::number(QApplication::instance()->applicationPid())
+
 InfTubeServer::InfTubeServer(QObject* parent)
 {
+    m_port = 12345;
     initialize();
-    m_tubeServer = Tp::StreamTubeServer::create(m_accountManager, QStringList() << \
"infinity-collaborative"); +    qDebug() << "CREATING STREAM TUBE SERVER";
+    m_tubeServer = Tp::StreamTubeServer::create(m_accountManager, QStringList() << \
"infinity", QStringList(), +                                                \
"KTp.infserver" + QString::number(QApplication::instance()->applicationPid()));  }
 
 bool InfTubeServer::offer(Tp::AccountPtr account, const Tp::ContactPtr contact, \
const KUrl& document) @@ -100,28 +115,30 @@ bool InfTubeServer::offer(Tp::AccountPtr \
account, const Tp::ContactPtr contact,  bool InfTubeServer::offer(Tp::AccountPtr \
account, const ContactList& contacts, const DocumentList& documents)  {
     qDebug() << "starting infinoted";
+    // start infinoted
     startInfinoted();
+    // set infinoted's socket as the local endpoint of the tube
     m_tubeServer->exportTcpSocket(QHostAddress(QHostAddress::LocalHost), m_port);
+    // add the initial documents
     foreach ( const KUrl& document, documents ) {
         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);
+                   TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE);
     request.insert(TP_QT_IFACE_CHANNEL + QLatin1String(".TargetHandleType"),
-                    (uint) Tp::HandleTypeContact);
+                   (uint) Tp::HandleTypeContact);
     request.insert(TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE + QLatin1String(".Service"),
-                    QLatin1String("tubetest"));
+                   QLatin1String("infinity"));
     // 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"); +                   \
contacts.first()->handle().at(0)); +    channelRequest = \
account->ensureChannel(request, +                                            \
QDateTime::currentDateTime(), +                                            \
"org.freedesktop.Telepathy.Client.KTp.infserver" + \
QString::number(QApplication::instance()->applicationPid()));  
     connect(channelRequest, SIGNAL(finished(Tp::PendingOperation*)),
             this, SLOT(onCreateTubeFinished(Tp::PendingOperation*)));
@@ -129,6 +146,12 @@ bool InfTubeServer::offer(Tp::AccountPtr account, const \
ContactList& contacts, c  return true;
 }
 
+void InfTubeServer::onCreateTubeFinished(Tp::PendingOperation* operation)
+{
+    kDebug() << "create tube finished; is error:" << operation->isError();
+    kDebug() << "error message:" << operation->errorMessage();
+}
+
 void InfTubeServer::startInfinoted()
 {
     m_serverProcess = new QProcess;
@@ -138,8 +161,7 @@ void InfTubeServer::startInfinoted()
     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);
+    while ( m_serverProcess->state() == QProcess::Running ) {
         QTcpSocket s;
         s.connectToHost("localhost", m_port);
         if ( s.waitForConnected(100) ) {
@@ -151,7 +173,7 @@ void InfTubeServer::startInfinoted()
 
 const QString InfTubeServer::serverDirectory() const
 {
-    return QLatin1String("/tmp");
+    return QLatin1String("/tmp/inftest");
 }
 
 InfTubeServer::~InfTubeServer()
@@ -159,22 +181,25 @@ InfTubeServer::~InfTubeServer()
 
 }
 
-InfTubeClient::InfTubeClient(QObject* parent)
-{
-
-}
-
 void InfTubeClient::listen()
 {
-    m_tubeClient = Tp::StreamTubeClient::create(m_accountManager, QStringList() << \
"tubetest", QStringList(), QString(), true, true); +    kDebug() << "listen called";
+    m_tubeClient = Tp::StreamTubeClient::create(m_accountManager, QStringList() << \
"infinity", +                                                QStringList(), \
QLatin1String("KTp.infinity"), true, true); +    kDebug() << "tube client: \
listening";  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)));
 +    kDebug() << m_tubeClient->tubes();
 }
 
-void InfTubeClient::tubeAcceptedAsTcp(QHostAddress , quint16 , QHostAddress , \
quint16 , Tp::AccountPtr , Tp::IncomingStreamTubeChannelPtr ) +void \
InfTubeClient::tubeAcceptedAsTcp(QHostAddress address, quint16 port, QHostAddress , \
quint16 , Tp::AccountPtr , Tp::IncomingStreamTubeChannelPtr )  {
-    kDebug() << "Tube accepted as Tcp";
+    kDebug() << "Tube accepted as Tcp, port:" << port;
+    // TODO error handling
+    m_port = port;
+    emit connected();
+    KRun::run("dolphin " + localUrl().url(), KUrl::List(), 0);
 }
 
 InfTubeClient::~InfTubeClient()
diff --git a/kte-plugin/ktpintegration/inftube.h \
b/kte-plugin/ktpintegration/inftube.h index 90b4c25..50c184e 100644
--- a/kte-plugin/ktpintegration/inftube.h
+++ b/kte-plugin/ktpintegration/inftube.h
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}>                 *
+ *   Copyright (C) 2013 by Sven Brauch <svenbrauch@gmail.com>              *
  *                                                                         *
  *   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  *
@@ -28,9 +28,15 @@
 #include <telepathy-qt4/TelepathyQt/StreamTubeServer>
 #include <telepathy-qt4/TelepathyQt/AccountManager>
 #include <telepathy-qt4/TelepathyQt/Account>
+#include <telepathy-qt4/TelepathyQt/ClientRegistrar>
+#include <TelepathyQt/AbstractClientObserver>
+#include <TelepathyQt/ChannelClassSpecList>
+#include <KTp/telepathy-handler-application.h>
 
 #include <KJob>
 #include <KUrl>
+#include <KDebug>
+#include <QTcpSocket>
 
 #include "inftube_export.h"
 
@@ -45,8 +51,7 @@ typedef QList<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 INFTUBE_EXPORT InfTubeBase : public QObject {
-Q_OBJECT
+class INFTUBE_EXPORT InfTubeBase {
 public:
     virtual ~InfTubeBase() { };
 
@@ -73,17 +78,16 @@ public:
      */
     ConnectionStatus status() const;
 
-signals:
-    /**
-     * @brief Emitted when the connection has been established
-     */
-    void connected(InfTubeBase* self);
-
+//     /**
+//      * @brief Get the client registrar instance.
+//      */
+//     Tp::ClientRegistrarPtr clientRegistrar() const;
 
 protected:
     Tp::AccountManagerPtr m_accountManager;
     ConnectionStatus m_status;
     unsigned int m_port;
+//     Tp::ClientRegistrarPtr m_registrar;
 
     /**
      * @brief Performs some initialization tasks. Call before everything else.
@@ -91,13 +95,22 @@ protected:
     void initialize();
 };
 
+
+inline Tp::ChannelClassSpecList channelClassList()
+{
+    return Tp::ChannelClassSpecList() << \
Tp::ChannelClassSpec::incomingStreamTube("infinity"); +}
+
 /**
  * @brief This class implements InfTubeBase and is used on the receiving end.
  */
-class INFTUBE_EXPORT InfTubeClient : public InfTubeBase {
+class INFTUBE_EXPORT InfTubeClient : public QObject, public InfTubeBase {
 Q_OBJECT
 public:
-    InfTubeClient(QObject* parent = 0);
+    explicit InfTubeClient() {
+        // TODO move to cpp
+        initialize();
+    };
     virtual ~InfTubeClient();
 
     /**
@@ -105,8 +118,16 @@ public:
      */
     void listen();
 
+signals:
+    /**
+     * @brief Emitted as soon as the tube is connected.
+     */
+    void connected();
+
 private:
     Tp::StreamTubeClientPtr m_tubeClient;
+    QTcpSocket* m_socket;
+
 public slots:
     void tubeAcceptedAsTcp(QHostAddress,quint16,QHostAddress,quint16,Tp::AccountPtr,Tp::IncomingStreamTubeChannelPtr);
  };
@@ -114,7 +135,7 @@ public slots:
 /**
  * @brief This class implements InfTubeBase and can be used to offer some documents \
                to a contact.
  */
-class INFTUBE_EXPORT InfTubeServer : public InfTubeBase {
+class INFTUBE_EXPORT InfTubeServer : public QObject, public InfTubeBase {
 Q_OBJECT
 public:
     InfTubeServer(QObject* parent = 0);
@@ -134,6 +155,15 @@ public:
      */
     bool offer(Tp::AccountPtr account, const Tp::ContactPtr contact, const KUrl& \
document);  
+signals:
+    /**
+     * @brief Emitted when the connection has been established
+     */
+    void connected(InfTubeBase* self);
+
+private slots:
+    void onCreateTubeFinished(Tp::PendingOperation*);
+
 private:
     Tp::StreamTubeServerPtr m_tubeServer;
     QProcess* m_serverProcess;
diff --git a/kte-plugin/ktpintegration/inftube_export.h \
b/kte-plugin/ktpintegration/inftube_export.h new file mode 100644
index 0000000..dc1c227
--- /dev/null
+++ b/kte-plugin/ktpintegration/inftube_export.h
@@ -0,0 +1,20 @@
+#ifndef INFTUBE_EXPORT_H
+#define INFTUBE_EXPORT_H
+
+#include <kdemacros.h>
+
+#ifndef INFTUBE_EXPORT
+# if defined(MAKE_INFTUBE_LIB)
+   // We are building this library
+#  define INFTUBE_EXPORT KDE_EXPORT
+# else
+   // We are using this library
+#  define INFTUBE_EXPORT KDE_IMPORT
+# endif
+#endif
+
+# ifndef INFTUBE_EXPORT_DEPRECATED
+#  define INFTUBE_EXPORT_DEPRECATED KDE_DEPRECATED INFTUBE_EXPORT
+# endif
+
+#endif
\ No newline at end of file
diff --git a/kte-plugin/ktpintegration/org.freedesktop.Telepathy.Client.KTp.infinity.service \
b/kte-plugin/ktpintegration/org.freedesktop.Telepathy.Client.KTp.infinity.service new \
file mode 100644 index 0000000..68735a0
--- /dev/null
+++ b/kte-plugin/ktpintegration/org.freedesktop.Telepathy.Client.KTp.infinity.service
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Telepathy.Client.KTp.infinity
+Exec=/home/sven/install/bin/tubehandler
diff --git a/kte-plugin/ktpintegration/tubehandler.cpp \
b/kte-plugin/ktpintegration/tubehandler.cpp new file mode 100644
index 0000000..25b2dbe
--- /dev/null
+++ b/kte-plugin/ktpintegration/tubehandler.cpp
@@ -0,0 +1,45 @@
+/***************************************************************************
+ *   Copyright (C) 2013 by Sven Brauch <svenbrauch@gmail.com>              *
+ *                                                                         *
+ *   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 <krun.h>
+#include <KDebug>
+#include <KCmdLineArgs>
+#include <KAboutData>
+#include <KApplication>
+#include <TelepathyQt/ClientRegistrar>
+
+// Proxy application which accepts a tube, then starts a handler application.
+int main(int argc, char** argv) {
+    KAboutData about("infinity", 0, ki18n("infinity"), "0.1", ki18n("..."),
+                     KAboutData::License_GPL, ki18n("(C) 2013 Sven Brauch"), \
KLocalizedString(), 0, "svenbrauch@gmail.com"); +    about.addAuthor( ki18n("Sven \
Brauch"), KLocalizedString(), "svenbrauch@gmail.com" ); +    KCmdLineArgs::init(argc, \
argv, &about); +    kDebug() << "Starting tube acceptor";
+
+    KApplication app;
+    InfTubeClient* client = new InfTubeClient();
+    client->listen();
+//     Tp::SharedPtr<InfTubeClient> app = Tp::SharedPtr<InfTubeClient>(new \
InfTubeClient()); +//     Tp::AbstractClientPtr handler = Tp::AbstractClientPtr(app);
+//     app->listen();
+//     app->clientRegistrar()->registerClient(handler, \
QLatin1String("KTp.infinity")); +//     QObject::connect(client, SIGNAL(connected()), \
client, SLOT(launch())); +    app.exec();
+}
\ No newline at end of file


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic