[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:08:24 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=3b03d1c

The following commit has been merged in the master branch:
commit 3b03d1c53b267c22acd504b87d657612fdd8d431
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Tue Aug 19 16:25:33 2014 +0200

    Provide factories to the registrar.
    
    Signed-off-by: Marcin Ziemiński <zieminn at gmail.com>
---
 otr-proxy/CMakeLists.txt              |   5 +-
 otr-proxy/KTpProxy/CMakeLists.txt     |   1 +
 otr-proxy/KTpProxy/main.cpp           |  26 +++++++-
 otr-proxy/KTpProxy/proxy-observer.cpp |  53 ++++-----------
 otr-proxy/KTpProxy/proxy-service.cpp  | 119 +++++++++++-----------------------
 otr-proxy/KTpProxy/proxy-service.h    |   5 +-
 6 files changed, 79 insertions(+), 130 deletions(-)

diff --git a/otr-proxy/CMakeLists.txt b/otr-proxy/CMakeLists.txt
index 26fc0d0..7f9e389 100644
--- a/otr-proxy/CMakeLists.txt
+++ b/otr-proxy/CMakeLists.txt
@@ -1,14 +1,16 @@
 project(ktp-proxy)
 set(KTP_PROXY_VERSION "0.1.1")
-
 set(KDE_MIN_VERSION "4.13.1")
 
+set(IS_KTP_INTERNAL_MODULE TRUE)
+
 set(CMAKE_MODULE_PATH
     "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
     ${CMAKE_MODULE_PATH}
 )
 
 find_package (KDE4 ${KDE_MIN_VERSION} REQUIRED)
+find_package (KTp REQUIRED) # TODO - remove this after merging
 find_package (TelepathyQt4 0.9.1 REQUIRED)
 find_package (TelepathyQt4Service 0.9.2.1 REQUIRED)
 find_package (LibOTR 4.0.0 REQUIRED)
@@ -17,6 +19,7 @@ find_package (Libgcrypt REQUIRED)
 FIND_LIBRARY (LIBGCRYPT_LIBS NAMES gcrypt)
 
 include_directories (${KDE4_INCLUDES}
+                     ${KTP_INCLUDE_DIR} # TODO - remove this after merging
                      ${TELEPATHY_QT4_INCLUDE_DIR}
                      ${LIBOTR_INCLUDE_DIR}
                      ${LIBGCRYPT_INCLUDE_DIR}
diff --git a/otr-proxy/KTpProxy/CMakeLists.txt b/otr-proxy/KTpProxy/CMakeLists.txt
index 1caee52..97ce903 100644
--- a/otr-proxy/KTpProxy/CMakeLists.txt
+++ b/otr-proxy/KTpProxy/CMakeLists.txt
@@ -24,6 +24,7 @@ set(ktp-proxy_LIBS
         ${KDE4_KDECORE_LIBS}
         ${KDE4_KDEUI_LIBS}
         ${KDE4_KIO_LIBS}
+        ${KTP_LIBRARIES}
         ${TELEPATHY_QT4_LIBRARIES}
         ${TELEPATHY_QT4_SERVICE_LIBRARIES}
         ${LIBOTR_LIBRARY}
diff --git a/otr-proxy/KTpProxy/main.cpp b/otr-proxy/KTpProxy/main.cpp
index 62797bf..1f47e99 100644
--- a/otr-proxy/KTpProxy/main.cpp
+++ b/otr-proxy/KTpProxy/main.cpp
@@ -27,10 +27,11 @@
 #include <KApplication>
 #include <KDebug>
 
+#include <KTp/core.h>
+
 #include <QDBusConnection>
 
 #include <TelepathyQt/AbstractAdaptor>
-#include <TelepathyQt/Channel>
 #include <TelepathyQt/Connection>
 #include <TelepathyQt/ClientRegistrar>
 #include <TelepathyQt/TextChannel>
@@ -40,6 +41,20 @@ extern "C" {
 }
 
 
+Tp::ChannelFactoryPtr getChannelFactory()
+{
+    Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
+    channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
+
+    Tp::Features textFeatures = Tp::Features() << Tp::TextChannel::FeatureMessageQueue
+                                               << Tp::TextChannel::FeatureMessageSentSignal
+                                               << Tp::TextChannel::FeatureChatState
+                                               << Tp::TextChannel::FeatureMessageCapabilities;
+    channelFactory->addFeaturesForTextChats(textFeatures);
+
+    return channelFactory;
+}
+
 int main(int argc, char *argv[])
 {
     KAboutData aboutData("ktp-proxy", 0,
@@ -62,8 +77,15 @@ int main(int argc, char *argv[])
     OTR::Config config;
 
     Tp::DBusError error;
+
     QDBusConnection dbusConnection = QDBusConnection::sessionBus();
-    ProxyService ps(dbusConnection, &config);
+    Tp::ClientRegistrarPtr registrar = Tp::ClientRegistrar::create(
+            KTp::accountFactory(),
+            KTp::connectionFactory(),
+            getChannelFactory(),
+            KTp::contactFactory());
+
+    ProxyService ps(dbusConnection, &config, registrar);
     ps.registerService(&error);
 
     if(error.isValid())
diff --git a/otr-proxy/KTpProxy/proxy-observer.cpp b/otr-proxy/KTpProxy/proxy-observer.cpp
index 92dec25..09b91e0 100644
--- a/otr-proxy/KTpProxy/proxy-observer.cpp
+++ b/otr-proxy/KTpProxy/proxy-observer.cpp
@@ -19,51 +19,14 @@
 
 #include "proxy-observer.h"
 #include "proxy-service.h"
-#include "pending-curry-operation.h"
 
 #include <TelepathyQt/ChannelClassSpecList>
 #include <TelepathyQt/Channel>
+#include <TelepathyQt/TextChannel>
 #include <TelepathyQt/PendingReady>
 
 #include <KDebug>
 
-// class to wait for all account fields to be ready
-// (displayName is not properly initializted sometimes)
-// and magic things happen
-class PendingAccountReady : public PendingCurryOperation
-{
-    public:
-        PendingAccountReady(
-                Tp::PendingOperation *op,
-                const Tp::AccountPtr &account,
-                const QList<Tp::ChannelPtr> &channels,
-                const Tp::MethodInvocationContextPtr<> &context,
-                ProxyService *ps)
-            : PendingCurryOperation(op, Tp::SharedPtr<Tp::RefCounted>::dynamicCast(account)),
-            account(account),
-            channels(channels),
-            context(context),
-            ps(ps)
-        {
-        }
-
-        virtual void extract(Tp::PendingOperation *op)
-        {
-            Q_UNUSED(op);
-
-            Q_FOREACH(const Tp::ChannelPtr &chan, channels) {
-                ps->addChannel(chan, account);
-            }
-            context->setFinished();
-        }
-
-    private:
-        Tp::AccountPtr account;
-        QList<Tp::ChannelPtr> channels;
-        Tp::MethodInvocationContextPtr<> context;
-        ProxyService *ps;
-};
-
 ProxyObserver::ProxyObserver(ProxyService *ps)
     : Tp::AbstractClientObserver(Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::textChat()),
     ps(ps)
@@ -89,9 +52,15 @@ void ProxyObserver::observeChannels(
     Q_UNUSED(observerInfo);
     kDebug() << "Observed a channel";
 
-    PendingAccountReady *ready = new PendingAccountReady(
-            account->becomeReady(Tp::Features() << Tp::Account::FeatureCore),
-            account, channels, context, ps);
+    Q_FOREACH(const Tp::ChannelPtr &chan, channels) {
+
+        Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(chan);
+        if(textChannel) {
+            ps->addChannel(textChannel, account);
+        } else {
+            kWarning() << "Could not get a text channel";
+        }
+    }
 
-    QObject::connect(ready, SIGNAL(finished(Tp::PendingOperation*)), ready, SLOT(deleteLater()));
+    context->setFinished();
 }
diff --git a/otr-proxy/KTpProxy/proxy-service.cpp b/otr-proxy/KTpProxy/proxy-service.cpp
index 79a0d00..72cc426 100644
--- a/otr-proxy/KTpProxy/proxy-service.cpp
+++ b/otr-proxy/KTpProxy/proxy-service.cpp
@@ -32,30 +32,12 @@
 #include <KDebug>
 #include <KApplication>
 
-class PendingChannelReadyResult : public PendingCurryOperation
-{
-    public:
-        PendingChannelReadyResult(Tp::PendingOperation *op, const Tp::TextChannelPtr &chan, const Tp::AccountPtr &account)
-            : PendingCurryOperation(op, Tp::SharedPtr<Tp::RefCounted>::dynamicCast(chan)),
-            channel(chan),
-            account(account)
-        {
-        }
-
-        virtual void extract(Tp::PendingOperation *op)
-        {
-            Q_UNUSED(op);
-        }
 
-        Tp::TextChannelPtr channel;
-        Tp::AccountPtr account;
-};
-
-ProxyService::ProxyService(const QDBusConnection &dbusConnection, OTR::Config *config)
+ProxyService::ProxyService(const QDBusConnection &dbusConnection, OTR::Config *config, const Tp::ClientRegistrarPtr &registrar)
     : Tp::DBusService(dbusConnection),
     adaptee(this, dbusConnection),
     observer(new ProxyObserver(this)),
-    registrar(Tp::ClientRegistrar::create(dbusConnection)),
+    registrar(registrar),
     manager(config),
     am(Tp::AccountManager::create(dbusConnection))
 {
@@ -76,22 +58,45 @@ Tp::AccountManagerPtr ProxyService::accountManager()
     return am;
 }
 
-void ProxyService::addChannel(const Tp::ChannelPtr &channel, const Tp::AccountPtr &account)
+void ProxyService::addChannel(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account)
 {
-    Tp::TextChannelPtr textChannel = Tp::TextChannel::create(channel->connection(), channel->objectPath(), QVariantMap());
+    Tp::DBusError error;
+    OTR::SessionContext ctx =
+    {
+        OTR::utils::accountIdFor(QDBusObjectPath(account->objectPath())),
+        account->displayName(),
+        channel->targetId(),
+        channel->connection()->protocolName()
+    };
+
+    OtrProxyChannelPtr proxyChannel = OtrProxyChannel::create(dbusConnection(), channel, ctx, this);
+    proxyChannel->registerService(&error);
+
+    if(error.isValid()) {
+        kError() << "Couldn't install proxy for the channel: " << channel->objectPath() << "
"
+            << "error name: " << error.name() << "
"
+            << "error message: " << error.message();
+
+        return;
+    }
 
-    PendingChannelReadyResult *pending = new PendingChannelReadyResult(
-            textChannel->becomeReady(Tp::Features()
-                << Tp::TextChannel::FeatureCore
-                << Tp::TextChannel::FeatureMessageQueue
-                << Tp::TextChannel::FeatureMessageCapabilities
-                << Tp::TextChannel::FeatureChatState
-                ),
-            textChannel,
-            account);
+    channels.insert(proxyChannel.data(), proxyChannel);
 
+    connect(proxyChannel.data(), SIGNAL(closed()), SLOT(onChannelProxyClosed()));
+    QObject::connect(
+            proxyChannel.data(), SIGNAL(connected(const QDBusObjectPath&)),
+            &adaptee, SLOT(onProxyConnected(const QDBusObjectPath&)));
+    QObject::connect(
+            proxyChannel.data(), SIGNAL(disconnected(const QDBusObjectPath&)),
+            &adaptee, SLOT(onProxyDisconnected(const QDBusObjectPath&)));
 
-    connect(pending, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onChannelReady(Tp::PendingOperation*)));
+    kDebug() << "Installed proxy: " << proxyChannel->objectPath() << "
"
+        << " for the channel: " << channel->objectPath() << "
"
+        << "Context: " << "
"
+        << "	 id: " << ctx.accountId << "
"
+        << "	 name: " << ctx.accountName << "
"
+        << "	 protocol: " << ctx.protocol << "
"
+        << "	 recipient: " << ctx.recipientName;
 }
 
 void ProxyService::registerService(Tp::DBusError *error)
@@ -138,56 +143,6 @@ void ProxyService::onChannelProxyClosed()
     }
 }
 
-void ProxyService::onChannelReady(Tp::PendingOperation *pendingChanReady)
-{
-    if(pendingChanReady->isError()) {
-        kWarning() << "Channel couldn't become ready due to: "
-            << pendingChanReady->errorName() << " - " << pendingChanReady->errorMessage();
-        return;
-    }
-    PendingChannelReadyResult *pendingReady = dynamic_cast<PendingChannelReadyResult*>(pendingChanReady);
-    Tp::TextChannelPtr textChannel = pendingReady->channel;
-    kDebug() << "Channel ready: " << textChannel->objectPath();
-
-    Tp::DBusError error;
-    OTR::SessionContext ctx =
-    {
-        OTR::utils::accountIdFor(QDBusObjectPath(pendingReady->account->objectPath())),
-        pendingReady->account->displayName(),
-        textChannel->targetId(),
-        textChannel->connection()->protocolName()
-    };
-
-    OtrProxyChannelPtr proxyChannel = OtrProxyChannel::create(dbusConnection(), textChannel, ctx, this);
-    proxyChannel->registerService(&error);
-
-    if(error.isValid()) {
-        kError() << "Couldn't install proxy for the channel: " << textChannel->objectPath() << "
"
-            << "error name: " << error.name() << "
"
-            << "error message: " << error.message();
-
-        return;
-    }
-
-    channels.insert(proxyChannel.data(), proxyChannel);
-
-    connect(proxyChannel.data(), SIGNAL(closed()), SLOT(onChannelProxyClosed()));
-    QObject::connect(
-            proxyChannel.data(), SIGNAL(connected(const QDBusObjectPath&)),
-            &adaptee, SLOT(onProxyConnected(const QDBusObjectPath&)));
-    QObject::connect(
-            proxyChannel.data(), SIGNAL(disconnected(const QDBusObjectPath&)),
-            &adaptee, SLOT(onProxyDisconnected(const QDBusObjectPath&)));
-
-    kDebug() << "Installed proxy: " << proxyChannel->objectPath() << "
"
-        << " for the channel: " << textChannel->objectPath() << "
"
-        << "Context: " << "
"
-        << "	 id: " << ctx.accountId << "
"
-        << "	 name: " << ctx.accountName << "
"
-        << "	 protocol: " << ctx.protocol << "
"
-        << "	 recipient: " << ctx.recipientName;
-}
-
 bool ProxyService::createNewPrivateKey(const QString &accountId, const QString &accountName)
 {
     kDebug() << "Generating new private key for " << accountId;
diff --git a/otr-proxy/KTpProxy/proxy-service.h b/otr-proxy/KTpProxy/proxy-service.h
index 3d46430..a1ad13e 100644
--- a/otr-proxy/KTpProxy/proxy-service.h
+++ b/otr-proxy/KTpProxy/proxy-service.h
@@ -45,10 +45,10 @@ class ProxyService : public Tp::DBusService
     Q_DISABLE_COPY(ProxyService)
 
     public:
-        ProxyService(const QDBusConnection &dbusConnection, OTR::Config *config);
+        ProxyService(const QDBusConnection &dbusConnection, OTR::Config *config, const Tp::ClientRegistrarPtr &registrar);
         ~ProxyService();
 
-        void addChannel(const Tp::ChannelPtr &channel, const Tp::AccountPtr &account);
+        void addChannel(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account);
 
         void registerService(Tp::DBusError *error);
 
@@ -68,7 +68,6 @@ class ProxyService : public Tp::DBusService
 
     private Q_SLOTS:
         void onChannelProxyClosed();
-        void onChannelReady(Tp::PendingOperation *pendingChanReady);
         void onKeyGenerationThreadFinished();
 
     Q_SIGNALS:

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list