[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:49 UTC 2016


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

The following commit has been merged in the master branch:
commit 0b5d45d855ffed8cef991b5687971cdbeeea6e8f
Author: Martin Klapetek <mklapetek at kde.org>
Date:   Mon Mar 30 19:01:22 2015 +0200

    Add support for "Connect and start chat" action into kpeople actions
    
    When the contact is offline, special action is returned which will first
    connect the account and then start the chat.
    
    This is done for text chat only as there is no way of knowing if the
    target contact has a support for audio/video calls before it's
    connected, while text chats will work in 98% of the cases.
    
    REVIEW: 123185
---
 kpeople/actionsplugin/CMakeLists.txt             |  1 +
 kpeople/actionsplugin/kpeople-actions-plugin.cpp | 70 +++++++++++++++++++++++-
 kpeople/actionsplugin/kpeople-actions-plugin.h   |  3 +
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/kpeople/actionsplugin/CMakeLists.txt b/kpeople/actionsplugin/CMakeLists.txt
index f0f4dd5..c4ac2d7 100644
--- a/kpeople/actionsplugin/CMakeLists.txt
+++ b/kpeople/actionsplugin/CMakeLists.txt
@@ -5,6 +5,7 @@ add_library (ktp_kpeople_plugin MODULE
 target_link_libraries (ktp_kpeople_plugin
     KF5::People
     KF5::PeopleBackend
+    KF5::PeopleWidgets
     KF5::I18n
     KF5::Service
     KTp::CommonInternals
diff --git a/kpeople/actionsplugin/kpeople-actions-plugin.cpp b/kpeople/actionsplugin/kpeople-actions-plugin.cpp
index d065840..000dd35 100644
--- a/kpeople/actionsplugin/kpeople-actions-plugin.cpp
+++ b/kpeople/actionsplugin/kpeople-actions-plugin.cpp
@@ -35,6 +35,7 @@
 #include <TelepathyQt/Constants>
 
 #include <KPeople/PersonData>
+#include <kpeople/widgets/actions.h> // pretty headers are currently broken for this
 
 enum IMActionType {
     TextChannel,
@@ -57,6 +58,7 @@ public:
     IMActionType type() const;
     QUrl uri() const;
 private:
+    void setActionType();
     KTp::ContactPtr m_contact;
     Tp::AccountPtr m_account;
     QUrl m_uri;
@@ -70,6 +72,7 @@ IMAction::IMAction(const QString &text, const QIcon &icon, const KTp::ContactPtr
     m_account(account),
     m_type(type)
 {
+    setActionType();
 }
 
 IMAction::IMAction(const QString &text, const QIcon &icon, const QUrl &uri,
@@ -78,6 +81,28 @@ IMAction::IMAction(const QString &text, const QIcon &icon, const QUrl &uri,
     m_uri(uri),
     m_type(type)
 {
+    setActionType();
+}
+
+void IMAction::setActionType()
+{
+    switch (m_type) {
+        case TextChannel:
+            setProperty("actionType", KPeople::TextChatAction);
+            break;
+        case AudioChannel:
+            setProperty("actionType", KPeople::AudioCallAction);
+            break;
+        case VideoChannel:
+            setProperty("actionType", KPeople::VideoCallAction);
+            break;
+        case FileTransfer:
+            setProperty("actionType", KPeople::SendFileAction);
+            break;
+        default:
+            setProperty("actionType", KPeople::OtherAction);
+            break;
+    }
 }
 
 KTp::ContactPtr IMAction::contact() const
@@ -157,7 +182,19 @@ QList<QAction*> KPeopleActionsPlugin::actionsForPerson(const KPeople::PersonData
         }
 
         const KTp::ContactPtr contact = KTp::contactManager()->contactForContactId(accountPath, contactId);
-        if (!contact || !contact->manager()) {
+        if (!contact || !contact->manager() || account->currentPresence().type() == Tp::ConnectionPresenceTypeOffline) {
+            // if there is no valid contact or if the contact is online,
+            // add a special action that will first connect the account
+            // and then start a chat right away
+            QAction *action = new IMAction(i18nc("Context menu action; means 'Bring your account online and then start a chat using %1 account'",
+                                                 "Connect and Start Chat Using %1...", account->displayName()),
+                                           QIcon::fromTheme(QStringLiteral("text-x-generic")),
+                                           contactId,
+                                           TextChannel,
+                                           parent);
+            action->setProperty("accountPath", accountPath);
+            connect(action, SIGNAL(triggered(bool)), SLOT(onConnectAndActionTriggered()));
+            actions << action;
             continue;
         }
 
@@ -262,6 +299,37 @@ void KPeopleActionsPlugin::onActionTriggered()
     }
 }
 
+void KPeopleActionsPlugin::onConnectAndActionTriggered()
+{
+    IMAction *action = qobject_cast<IMAction*>(sender());
+
+    const Tp::AccountPtr account = KTp::contactManager()->accountForAccountPath(action->property("accountPath").toString());
+    account->setProperty("contactId", action->uri());
+    connect(account.data(), &Tp::Account::connectionStatusChanged, this, &KPeopleActionsPlugin::onAccountConnectionStatusChanged);
+    account->setRequestedPresence(Tp::Presence::available());
+}
+
+void KPeopleActionsPlugin::onAccountConnectionStatusChanged(Tp::ConnectionStatus status)
+{
+    Tp::AccountPtr account = Tp::AccountPtr(qobject_cast<Tp::Account*>(sender()));
+    if (!account || status != Tp::ConnectionStatusConnected) {
+        return;
+    }
+
+    QString contactId = account->property("contactId").toString();
+
+    if (contactId.isEmpty()) {
+        return;
+    }
+
+    account->ensureTextChat(contactId,
+                            QDateTime::currentDateTime(),
+                            QLatin1String("org.freedesktop.Telepathy.Client.KTp.TextUi"));
+
+    // avoid calling this slot repeatedly on account connection changes
+    disconnect(account.data(), &Tp::Account::connectionStatusChanged, this, &KPeopleActionsPlugin::onAccountConnectionStatusChanged);
+}
+
 K_PLUGIN_FACTORY( KPeopleActionsPluginFactory, registerPlugin<KPeopleActionsPlugin>(); )
 K_EXPORT_PLUGIN( KPeopleActionsPluginFactory("ktp_kpeople_plugin", "ktp-common-internals") )
 
diff --git a/kpeople/actionsplugin/kpeople-actions-plugin.h b/kpeople/actionsplugin/kpeople-actions-plugin.h
index b80bef8..4208e1e 100644
--- a/kpeople/actionsplugin/kpeople-actions-plugin.h
+++ b/kpeople/actionsplugin/kpeople-actions-plugin.h
@@ -20,6 +20,7 @@
 #define IM_PLUGIN_H
 
 #include <KPeopleBackend/AbstractPersonAction>
+#include <TelepathyQt/Connection>
 
 class KPeopleActionsPlugin : public KPeople::AbstractPersonAction
 {
@@ -31,6 +32,8 @@ public:
 
 private Q_SLOTS:
     void onActionTriggered();
+    void onConnectAndActionTriggered();
+    void onAccountConnectionStatusChanged(Tp::ConnectionStatus status);
 };
 
 #endif // IM_PLUGIN_H

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list