[SCM] ktp-kded-integration-module packaging branch, master, updated. debian/15.12.1-2-382-gbd961c2
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:13:08 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-kded-module.git;a=commitdiff;h=fb15de2
The following commit has been merged in the master branch:
commit fb15de23a5d62b54b77f1319e64b2bc26c9f4887
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date: Thu Nov 10 12:49:58 2011 +0100
Add contact request handler to handle incoming request for subscription
---
CMakeLists.txt | 1 +
contact-request-handler.cpp | 256 ++++++++++++++++++++++++++++++++++++++++++++
contact-request-handler.h | 64 +++++++++++
telepathy-module.cpp | 12 ++-
telepathy-module.h | 4 +-
5 files changed, 334 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 335d7f7..e0d273c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@ include_directories (${KDE4_INCLUDES}
)
set (telepathy_module_SRCS
+ contact-request-handler.cpp
telepathy-kded-module-plugin.cpp
telepathy-module.cpp
autoaway.cpp
diff --git a/contact-request-handler.cpp b/contact-request-handler.cpp
new file mode 100644
index 0000000..9959379
--- /dev/null
+++ b/contact-request-handler.cpp
@@ -0,0 +1,256 @@
+/*
+ <one line to give the library's name and an idea of what it does.>
+ Copyright (C) 2011 Martin Klapetek <email>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#include "contact-request-handler.h"
+
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/ContactManager>
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/Account>
+
+#include <KDebug>
+#include <KGlobal>
+#include <KAboutData>
+
+#include <QFutureWatcher>
+#include <KMenu>
+#include <KAction>
+
+bool kde_tp_filter_contacts_by_publication_status(const Tp::ContactPtr &contact)
+{
+ return contact->publishState() == Tp::Contact::PresenceStateAsk;
+}
+
+ContactRequestHandler::ContactRequestHandler(const Tp::AccountManagerPtr& am, QObject *parent)
+ : QObject(parent)
+{
+ m_notifierMenu = new KMenu(0);
+ m_notifierMenu->addTitle(i18nc("Context menu title", "Received contact requests"));
+ m_accountManager = am;
+ connect(m_accountManager.data(), SIGNAL(newAccount(Tp::AccountPtr)),
+ this, SLOT(onNewAccountAdded(Tp::AccountPtr)));
+
+ QList<Tp::AccountPtr> accounts = m_accountManager->allAccounts();
+
+ Q_FOREACH(const Tp::AccountPtr &account, accounts) {
+ onNewAccountAdded(account);
+ }
+}
+
+ContactRequestHandler::~ContactRequestHandler()
+{
+
+}
+
+void ContactRequestHandler::onNewAccountAdded(const Tp::AccountPtr& account)
+{
+ kWarning();
+ Q_ASSERT(account->isReady(Tp::Account::FeatureCore));
+
+ if (account->connection()) {
+ monitorPresence(account->connection());
+ }
+
+ connect(account.data(),
+ SIGNAL(connectionChanged(Tp::ConnectionPtr)),
+ this, SLOT(onConnectionChanged(Tp::ConnectionPtr)));
+}
+
+void ContactRequestHandler::onConnectionChanged(const Tp::ConnectionPtr& connection)
+{
+ if (!connection.isNull()) {
+ monitorPresence(connection);
+ }
+}
+
+void ContactRequestHandler::monitorPresence(const Tp::ConnectionPtr &connection)
+{
+ kDebug();
+ connect(connection->contactManager().data(), SIGNAL(presencePublicationRequested(Tp::Contacts)),
+ this, SLOT(onPresencePublicationRequested(Tp::Contacts)));
+
+ connect(connection->contactManager().data(),
+ SIGNAL(stateChanged(Tp::ContactListState)),
+ this, SLOT(onContactManagerStateChanged(Tp::ContactListState)));
+
+ onContactManagerStateChanged(connection->contactManager(),
+ connection->contactManager()->state());
+}
+
+void ContactRequestHandler::onContactManagerStateChanged(Tp::ContactListState state)
+{
+ onContactManagerStateChanged(Tp::ContactManagerPtr(qobject_cast< Tp::ContactManager* >(sender())), state);
+}
+
+void ContactRequestHandler::onContactManagerStateChanged(const Tp::ContactManagerPtr &contactManager, Tp::ContactListState state)
+{
+ if (state == Tp::ContactListStateSuccess) {
+ QFutureWatcher< Tp::ContactPtr > *watcher = new QFutureWatcher< Tp::ContactPtr >(this);
+ connect(watcher, SIGNAL(finished()), this, SLOT(onAccountsPresenceStatusFiltered()));
+ watcher->setFuture(QtConcurrent::filtered(contactManager->allKnownContacts(),
+ kde_tp_filter_contacts_by_publication_status));
+
+ kDebug() << "Watcher is on";
+ } else {
+ kDebug() << "Watcher still off, state is" << state << "contactManager is" << contactManager.isNull();
+ }
+}
+
+void ContactRequestHandler::onAccountsPresenceStatusFiltered()
+{
+ kDebug() << "Watcher is here";
+ QFutureWatcher< Tp::ContactPtr > *watcher = dynamic_cast< QFutureWatcher< Tp::ContactPtr > * >(sender());
+ kDebug() << "Watcher is casted";
+ Tp::Contacts contacts = watcher->future().results().toSet();
+ kDebug() << "Watcher is used";
+ if (!contacts.isEmpty()) {
+ onPresencePublicationRequested(contacts);
+ }
+ watcher->deleteLater();
+}
+
+void ContactRequestHandler::onPresencePublicationRequested(const Tp::Contacts& contacts)
+{
+ kWarning() << "New contact requested";
+
+ Q_FOREACH (const Tp::ContactPtr &contact, contacts) {
+ Tp::ContactManagerPtr manager = contact->manager();
+ Tp::PendingOperation *op = 0;
+
+ if (contact->subscriptionState() == Tp::Contact::PresenceStateYes) {
+ op = manager->authorizePresencePublication(QList< Tp::ContactPtr >() << contact);
+ } else {
+ KNotification *notification = new KNotification(QLatin1String("telepathyInfo"), KNotification::CloseOnTimeout);
+
+ KAboutData aboutData("ktelepathy",0,KLocalizedString(),0);
+ notification->setComponentData(KComponentData(aboutData));
+
+ notification->setText(i18n("The contact %1 added you to their contact list. "
+ "Do you want to allow this person to see your presence "
+ "and add them to your contact list?", contact->id()));
+ notification->sendEvent();
+
+ m_pendingContacts.insert(contact->id(), contact);
+
+ m_notifierItem = getNotifierItem();
+
+ KMenu *contactMenu = new KMenu(m_notifierMenu);
+ contactMenu->setTitle(i18n("Request from %1", contact->id()));
+ contactMenu->setObjectName(contact->id());
+
+ KAction *menuAction;
+ if (!contact->publishStateMessage().isEmpty()) {
+ contactMenu->addTitle(contact->publishStateMessage());
+ } else {
+ contactMenu->addTitle(contact->alias());
+ }
+ menuAction = new KAction(KIcon(QLatin1String("dialog-ok-apply")), i18n("Approve"), contactMenu);
+ connect(menuAction, SIGNAL(triggered(bool)),
+ this, SLOT(onContactRequestApproved()));
+ menuAction->setData(contact->id());
+ contactMenu->addAction(menuAction);
+
+ menuAction = new KAction(KIcon(QLatin1String("dialog-close")), i18n("Deny"), contactMenu);
+ menuAction->setData(contact->id());
+
+ connect(menuAction, SIGNAL(triggered(bool)),
+ this, SLOT(onContactRequestDenied()));
+ contactMenu->addAction(menuAction);
+
+ m_notifierMenu->addMenu(contactMenu);
+ m_notifierItem->setContextMenu(m_notifierMenu);
+
+ updateNotifierItemTooltip();
+ }
+
+ if (op) {
+// connect(op, SIGNAL(finished(Tp::PendingOperation*)),
+// SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
+ }
+ }
+}
+
+K_GLOBAL_STATIC(QWeakPointer<KStatusNotifierItem>, s_notifierItem)
+
+//static
+QSharedPointer<KStatusNotifierItem> ContactRequestHandler::getNotifierItem()
+{
+ QSharedPointer<KStatusNotifierItem> notifierItem = s_notifierItem->toStrongRef();
+ if (!notifierItem) {
+ notifierItem = QSharedPointer<KStatusNotifierItem>(new KStatusNotifierItem);
+ notifierItem->setCategory(KStatusNotifierItem::Communications);
+ notifierItem->setStatus(KStatusNotifierItem::NeedsAttention);
+ notifierItem->setIconByName(QLatin1String("user-identity"));
+ notifierItem->setAttentionIconByName(QLatin1String("list-add-user"));
+ notifierItem->setStandardActionsEnabled(false);
+ notifierItem->setProperty("contact_requests_count", 0U);
+ *s_notifierItem = notifierItem;
+ }
+
+ return notifierItem;
+}
+
+void ContactRequestHandler::updateNotifierItemTooltip()
+{
+ QVariant requestsCount = m_notifierItem->property("contact_requests_count");
+ requestsCount = QVariant(requestsCount.toUInt() + 1);
+ m_notifierItem->setProperty("contact_requests_count", requestsCount);
+
+ m_notifierItem->setToolTip(QLatin1String("list-add-user"),
+ i18np("You have 1 incoming contact request",
+ "You have %1 incoming contact requests",
+ requestsCount.toUInt()),
+ QString());
+}
+
+void ContactRequestHandler::onContactRequestApproved()
+{
+ QString contactId = qobject_cast<KAction*>(sender())->data().toString();
+
+ if (!contactId.isEmpty()) {
+ Tp::ContactPtr contact = m_pendingContacts.value(contactId);
+ if (!contact.isNull()) {
+ Tp::PendingOperation *op = contact->manager()->authorizePresencePublication(QList< Tp::ContactPtr >() << contact);
+ //TODO: connect and let user know the result, find and remove the menu from statusnotifier
+ // don't forget to update the tooltip with -1
+ //delete m_notifierMenu->findChild<KMenu*>(contactId);
+ if (contact->manager()->canRequestPresenceSubscription() && contact->subscriptionState() == Tp::Contact::PresenceStateNo) {
+ contact->manager()->requestPresenceSubscription(QList< Tp::ContactPtr >() << contact);
+ }
+ }
+ }
+}
+
+void ContactRequestHandler::onContactRequestDenied()
+{
+QString contactId = qobject_cast<KAction*>(sender())->data().toString();
+
+ if (!contactId.isEmpty()) {
+ Tp::ContactPtr contact = m_pendingContacts.value(contactId);
+ if (!contact.isNull()) {
+ Tp::PendingOperation *op = contact->manager()->removePresencePublication(QList< Tp::ContactPtr >() << contact);
+ //TODO: connect and let user know the result, find and remove the menu from statusnotifier
+ // don't forget to update the tooltip with -1
+// delete m_notifierMenu->findChild<KMenu*>(contactId);
+ }
+ }
+}
+
+#include "contact-request-handler.moc"
\ No newline at end of file
diff --git a/contact-request-handler.h b/contact-request-handler.h
new file mode 100644
index 0000000..41a358e
--- /dev/null
+++ b/contact-request-handler.h
@@ -0,0 +1,64 @@
+/*
+ <one line to give the library's name and an idea of what it does.>
+ Copyright (C) 2011 Martin Klapetek <email>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+
+#ifndef CONTACT_REQUEST_HANDLER_H
+#define CONTACT_REQUEST_HANDLER_H
+
+#include <QObject>
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/AccountManager>
+
+#include <KStatusNotifierItem>
+#include <KNotification>
+
+class KMenu;
+class ContactRequestHandler : public QObject
+{
+ Q_OBJECT
+public:
+ ContactRequestHandler(const Tp::AccountManagerPtr& am, QObject *parent = 0);
+ virtual ~ContactRequestHandler();
+
+ void monitorPresence(const Tp::ConnectionPtr &connection);
+
+public Q_SLOTS:
+ void onNewAccountAdded(const Tp::AccountPtr &account);
+ void onContactManagerStateChanged(Tp::ContactListState state);
+ void onContactManagerStateChanged(const Tp::ContactManagerPtr &contactManager, Tp::ContactListState state);
+ void onAccountsPresenceStatusFiltered();
+ void onPresencePublicationRequested(const Tp::Contacts& contacts);
+ void onConnectionChanged(const Tp::ConnectionPtr& connection);
+
+ void onContactRequestApproved();
+ void onContactRequestDenied();
+
+private:
+ static QSharedPointer<KStatusNotifierItem> getNotifierItem();
+ void updateNotifierItemTooltip();
+
+ QWeakPointer<KNotification> m_notification;
+ QSharedPointer<KStatusNotifierItem> m_notifierItem;
+ Tp::AccountManagerPtr m_accountManager;
+ KMenu *m_notifierMenu;
+ QHash<QString, Tp::ContactPtr> m_pendingContacts;
+};
+
+#endif // CONTACT_REQUEST_HANDLER_H
diff --git a/telepathy-module.cpp b/telepathy-module.cpp
index 0c3ea5f..f0a2c5a 100644
--- a/telepathy-module.cpp
+++ b/telepathy-module.cpp
@@ -35,6 +35,7 @@
#include "telepathy-kded-module-plugin.h"
#include <KConfigGroup>
+#include "contact-request-handler.h"
K_PLUGIN_FACTORY(TelepathyModuleFactory, registerPlugin<TelepathyModule>(); )
K_EXPORT_PLUGIN(TelepathyModuleFactory("telepathy_module", "telepathy-kded-module"))
@@ -53,14 +54,20 @@ TelepathyModule::TelepathyModule(QObject* parent, const QList<QVariant>& args)
Tp::Features() << Tp::Account::FeatureCore);
Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
- Tp::Features() << Tp::Connection::FeatureCore);
+ Tp::Features() << Tp::Connection::FeatureCore
+ << Tp::Connection::FeatureRoster);
+
+ Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias
+ << Tp::Contact::FeatureSimplePresence
+ << Tp::Contact::FeatureCapabilities);
Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
m_accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
accountFactory,
connectionFactory,
- channelFactory);
+ channelFactory,
+ contactFactory);
connect(m_accountManager->becomeReady(),
@@ -100,6 +107,7 @@ void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
m_mpris, SLOT(onSettingsChanged()));
m_errorHandler = new ErrorHandler(m_accountManager, this);
+ m_contactHandler = new ContactRequestHandler(m_accountManager, this);
}
void TelepathyModule::onPresenceChanged(const Tp::Presence &presence)
diff --git a/telepathy-module.h b/telepathy-module.h
index 7215c0b..8a7e14d 100644
--- a/telepathy-module.h
+++ b/telepathy-module.h
@@ -25,6 +25,7 @@
#include <TelepathyQt4/AccountManager>
+class ContactRequestHandler;
namespace Tp {
class PendingOperation;
}
@@ -59,7 +60,8 @@ private:
AutoAway *m_autoAway;
TelepathyMPRIS *m_mpris;
ErrorHandler *m_errorHandler;
- KTp::GlobalPresence *m_globalPresence;
+ KTp::GlobalPresence *m_globalPresence;
+ ContactRequestHandler *m_contactHandler;
QList<TelepathyKDEDModulePlugin*> m_pluginStack;
};
--
ktp-kded-integration-module packaging
More information about the pkg-kde-commits
mailing list