summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbner Silva <abner@mustang.(none)>2009-08-27 17:55:51 (GMT)
committerAbner Silva <abner@mustang.(none)>2009-08-27 17:55:51 (GMT)
commitedc5fd15807e9c9954ff3d1d8e277a5af94fe21c (patch)
tree39c3c7ec1fb55221d129f6317754d3ec1994f518
parentf7fae34688ea70344957730eb0b9200c1b80b8b2 (diff)
downloadkrdc-telepathy-edc5fd15807e9c9954ff3d1d8e277a5af94fe21c.tar.gz
krdc-telepathy-edc5fd15807e9c9954ff3d1d8e277a5af94fe21c.tar.xz
First version of krdc approver.
-rw-r--r--krdc_approver/CMakeLists.txt23
-rw-r--r--krdc_approver/approver.cpp132
-rw-r--r--krdc_approver/approver.h65
-rw-r--r--krdc_approver/approvermanager.cpp95
-rw-r--r--krdc_approver/approvermanager.h50
-rw-r--r--krdc_approver/krdc_rfb_approver.client12
-rw-r--r--krdc_approver/krdc_rfb_approver.notifyrc13
-rw-r--r--krdc_approver/main.cpp63
-rw-r--r--krdc_approver/org.freedesktop.Telepathy.Client.krdc_rfb_approver.service.in3
9 files changed, 456 insertions, 0 deletions
diff --git a/krdc_approver/CMakeLists.txt b/krdc_approver/CMakeLists.txt
new file mode 100644
index 0000000..44d0d33
--- /dev/null
+++ b/krdc_approver/CMakeLists.txt
@@ -0,0 +1,23 @@
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+set (krdc_rfb_approver_SRCS
+ main.cpp
+ approvermanager.cpp
+ approver.cpp
+)
+
+kde4_add_executable(krdc_rfb_approver ${krdc_rfb_approver_SRCS})
+target_link_libraries(krdc_rfb_approver ${KDE4_KDEUI_LIBS}
+ ${TELEPATHY_QT4_LIBRARIES}
+)
+
+install(TARGETS krdc_rfb_approver ${INSTALL_TARGETS_DEFAULT_ARGS})
+install(FILES krdc_rfb_approver.notifyrc DESTINATION ${DATA_INSTALL_DIR}/krdc_rfb_approver)
+
+configure_file(org.freedesktop.Telepathy.Client.krdc_rfb_approver.service.in
+ org.freedesktop.Telepathy.Client.krdc_rfb_approver.service)
+install(FILES ${CMAKE_BINARY_DIR}/org.freedesktop.Telepathy.Client.krdc_rfb_approver.service
+ DESTINATION ${DBUS_SERVICES_INSTALL_DIR})
+
+# FIXME any better macro for ${XDG_DATA_DIRS} ?
+install(FILES krdc_rfb_approver.client DESTINATION ${CMAKE_INSTALL_PREFIX}/share/telepathy/clients/)
diff --git a/krdc_approver/approver.cpp b/krdc_approver/approver.cpp
new file mode 100644
index 0000000..bee7020
--- /dev/null
+++ b/krdc_approver/approver.cpp
@@ -0,0 +1,132 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Collabora Ltd <http://www.collabora.co.uk>
+** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net>
+**
+** This file is part of KDE.
+**
+** 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; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include "approver.h"
+
+#include <KDebug>
+#include <KNotification>
+#include <KLocalizedString>
+
+#include <TelepathyQt4/Contact>
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/ReferencedHandles>
+#include <TelepathyQt4/PendingReady>
+#include <TelepathyQt4/ChannelDispatchOperation>
+
+using namespace Tp;
+
+Approver::Approver(const MethodInvocationContextPtr<> &context,
+ const QList<ChannelPtr> &channels,
+ const ChannelDispatchOperationPtr &dispatchOperation,
+ QObject *parent)
+ : QObject(parent),
+ m_context(context),
+ m_channels(channels),
+ m_dispatchOp(dispatchOperation),
+ m_notification(0)
+{
+ kDebug() << "Initializing approver";
+
+ connect(m_dispatchOp->becomeReady(),
+ SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onDispatchOperationReady(Tp::PendingOperation*)));
+}
+
+void Approver::onDispatchOperationReady(Tp::PendingOperation *op)
+{
+ if (op->isError()) {
+ kError() << "Dispatch operation failed to become ready"
+ << op->errorName() << op->errorMessage();
+ m_context->setFinishedWithError(op->errorName(), op->errorMessage());
+ emit finished();
+ return;
+ }
+
+ kDebug() << "DispatchOp ready!";
+
+ Tp::ContactPtr contact = m_dispatchOp->channels()[0]->initiatorContact();
+
+ KNotification *notification = new KNotification("newrfb", NULL, KNotification::Persistent);
+ notification->setTitle(i18n("Invitation to view remote desktop"));
+ notification->setText(i18n("%1 wants to share its desktop with you", contact->alias()));
+ notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
+
+ Client::ConnectionInterfaceAvatarsInterface *avatarIface =
+ m_dispatchOp->channels()[0]->connection()->avatarsInterface();
+
+ if (avatarIface) {
+ QDBusPendingReply<QByteArray, QString> reply = avatarIface->RequestAvatar(
+ contact->handle().takeFirst());
+
+ if (!reply.isError()) {
+ QPixmap avatar;
+ avatar.loadFromData(reply.value());
+ notification->setPixmap(avatar);
+ }
+ }
+
+ connect(notification, SIGNAL(action1Activated()), SLOT(onAccepted()));
+ connect(notification, SIGNAL(action2Activated()), SLOT(onRejected()));
+ connect(notification, SIGNAL(ignored()), SLOT(onRejected()));
+
+ notification->sendEvent();
+
+ m_notification = notification;
+
+ m_context->setFinished();
+}
+
+Approver::~Approver()
+{
+ kDebug() << "Destroying approver";
+}
+
+void Approver::onAccepted()
+{
+ kDebug() << "Channel approved";
+ m_dispatchOp->handleWith(TELEPATHY_INTERFACE_CLIENT ".krdc_rfb_handler");
+
+ emit finished();
+}
+
+void Approver::onRejected()
+{
+ kDebug() << "Channel rejected";
+ connect(m_dispatchOp->claim(), SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(onClaimFinished(Tp::PendingOperation*)));
+}
+
+void Approver::onClaimFinished(Tp::PendingOperation *op)
+{
+ if (op->isError()) {
+ kError() << "Claim operation failed"
+ << op->errorName() << op->errorMessage();
+ m_context->setFinishedWithError(op->errorName(), op->errorMessage());
+ }
+ else {
+ foreach(const Tp::ChannelPtr &channel, m_channels)
+ channel->requestClose();
+ }
+
+ emit finished();
+}
diff --git a/krdc_approver/approver.h b/krdc_approver/approver.h
new file mode 100644
index 0000000..cce70c9
--- /dev/null
+++ b/krdc_approver/approver.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Collabora Ltd <http://www.collabora.co.uk>
+** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net>
+**
+** This file is part of KDE.
+**
+** 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; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#ifndef APPROVER_H
+#define APPROVER_H
+
+#include <QObject>
+
+#include <TelepathyQt4/Channel>
+
+class KNotification;
+
+class Approver : public QObject
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(Approver)
+
+public:
+ ~Approver();
+
+private Q_SLOTS:
+ void onAccepted();
+ void onRejected();
+ void onDispatchOperationReady(Tp::PendingOperation*);
+ void onClaimFinished(Tp::PendingOperation*);
+
+Q_SIGNALS:
+ void finished();
+
+private:
+ Approver(const Tp::MethodInvocationContextPtr<> &context,
+ const QList<Tp::ChannelPtr> &channels,
+ const Tp::ChannelDispatchOperationPtr &dispatchOperation,
+ QObject *parent);
+
+private:
+ Tp::MethodInvocationContextPtr<> m_context;
+ QList<Tp::ChannelPtr> m_channels;
+ Tp::ChannelDispatchOperationPtr m_dispatchOp;
+ QPointer<KNotification> m_notification;
+
+ friend class ApproverManager;
+};
+#endif
diff --git a/krdc_approver/approvermanager.cpp b/krdc_approver/approvermanager.cpp
new file mode 100644
index 0000000..55ff14e
--- /dev/null
+++ b/krdc_approver/approvermanager.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Collabora Ltd <http://www.collabora.co.uk>
+** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net>
+**
+** This file is part of KDE.
+**
+** 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; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include "approvermanager.h"
+#include "approver.h"
+
+#include <QDBusObjectPath>
+#include <QDBusConnection>
+
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/PendingOperation>
+#include <TelepathyQt4/PendingReady>
+#include <TelepathyQt4/Debug>
+
+#include <KDebug>
+
+using namespace Tp;
+
+static inline Tp::ChannelClassList channelClassList()
+{
+ QMap<QString, QDBusVariant> filter0, filter1;
+ filter0[TELEPATHY_INTERFACE_CHANNEL ".ChannelType"] =
+ QDBusVariant(TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAM_TUBE);
+ filter0[TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAM_TUBE ".Service"] = QDBusVariant("rfb");
+ filter0[TELEPATHY_INTERFACE_CHANNEL ".Requested"] = QDBusVariant(false);
+
+ filter1[TELEPATHY_INTERFACE_CHANNEL ".ChannelType"] =
+ QDBusVariant(TELEPATHY_INTERFACE_CHANNEL_TYPE_TUBES);
+ filter1[TELEPATHY_INTERFACE_CHANNEL ".TargetHandleType"] = QDBusVariant(Tp::HandleTypeContact);
+ filter1[TELEPATHY_INTERFACE_CHANNEL ".Requested"] = QDBusVariant(false);
+
+ return Tp::ChannelClassList() << Tp::ChannelClass(filter0) << Tp::ChannelClass(filter1);
+}
+
+ApproverManager::ApproverManager(QObject *parent)
+ : QObject(parent),
+ AbstractClientApprover(channelClassList())
+{
+ kDebug() << "Initializing approver manager";
+
+ /* Registering telepathy types */
+ registerTypes();
+}
+
+ApproverManager::~ApproverManager()
+{
+ kDebug() << "Destroying approver manager";
+}
+
+void ApproverManager::addDispatchOperation(const MethodInvocationContextPtr<> &context,
+ const QList<ChannelPtr> &channels,
+ const ChannelDispatchOperationPtr &dispatchOperation)
+{
+ kDebug() << "New channel for approving arrived";
+
+ Approver *approver = new Approver(context, channels, dispatchOperation, this);
+ connect(approver, SIGNAL(finished()), SLOT(onFinished()));
+
+ m_approvers << approver;
+}
+
+void ApproverManager::onFinished()
+{
+ kDebug() << "Approver finished";
+
+ Approver *approver = qobject_cast<Approver*>(sender());
+ m_approvers.removeOne(approver);
+ approver->deleteLater();
+
+ if (m_approvers.empty()) {
+ kDebug() << "Quiting approver manager";
+ QCoreApplication::quit();
+ }
+}
diff --git a/krdc_approver/approvermanager.h b/krdc_approver/approvermanager.h
new file mode 100644
index 0000000..b141ec6
--- /dev/null
+++ b/krdc_approver/approvermanager.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Collabora Ltd <http://www.collabora.co.uk>
+** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net>
+**
+** This file is part of KDE.
+**
+** 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; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#ifndef APPROVERMANAGER_H
+#define APPROVERMANAGER_H
+
+#include <TelepathyQt4/AbstractClientApprover>
+
+class Approver;
+
+class ApproverManager : public QObject, public Tp::AbstractClientApprover
+{
+ Q_OBJECT
+
+public:
+ ApproverManager(QObject *parent);
+ virtual ~ApproverManager();
+
+ virtual void addDispatchOperation(const Tp::MethodInvocationContextPtr<> &context,
+ const QList<Tp::ChannelPtr> &channels,
+ const Tp::ChannelDispatchOperationPtr &dispatchOperation);
+
+private Q_SLOTS:
+ void onFinished();
+
+private:
+ QList<Approver *> m_approvers;
+};
+#endif
diff --git a/krdc_approver/krdc_rfb_approver.client b/krdc_approver/krdc_rfb_approver.client
new file mode 100644
index 0000000..e1202e9
--- /dev/null
+++ b/krdc_approver/krdc_rfb_approver.client
@@ -0,0 +1,12 @@
+[org.freedesktop.Telepathy.Client]
+Interfaces=org.freedesktop.Telepathy.Client.Approver;
+
+[org.freedesktop.Telepathy.Client.Approver.ApproverChannelFilter 0]
+org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.StreamTube
+org.freedesktop.Telepathy.Channel.Type.StreamTube.Service s=rfb
+org.freedesktop.Telepathy.Channel.Requested b=false
+
+[org.freedesktop.Telepathy.Client.Approver.ApproverChannelFilter 1]
+org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Tubes
+org.freedesktop.Telepathy.Channel.TargetHandleType u=1
+org.freedesktop.Telepathy.Channel.Requested b=false
diff --git a/krdc_approver/krdc_rfb_approver.notifyrc b/krdc_approver/krdc_rfb_approver.notifyrc
new file mode 100644
index 0000000..902beab
--- /dev/null
+++ b/krdc_approver/krdc_rfb_approver.notifyrc
@@ -0,0 +1,13 @@
+[Global]
+IconName=krdc
+Comment=Krdc
+Comment[sv]=Krdc
+Comment[x-test]=xxKrdcxx
+Name=Krdc
+Name[sv]=Krdc
+Name[x-test]=xxKrdcxx
+
+[Event/newrfb]
+Name=Incoming RFB Tube
+Action=Popup
+Flags=Persistent
diff --git a/krdc_approver/main.cpp b/krdc_approver/main.cpp
new file mode 100644
index 0000000..8807a14
--- /dev/null
+++ b/krdc_approver/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Collabora Ltd <http://www.collabora.co.uk>
+** Copyright (C) 2009 Abner Silva <abner.silva@kdemail.net>
+**
+** This file is part of KDE.
+**
+** 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; see the file COPYING. If not, write to
+** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+** Boston, MA 02110-1301, USA.
+**
+****************************************************************************/
+
+#include "approvermanager.h"
+
+#include <KAboutData>
+#include <KCmdLineArgs>
+#include <KLocalizedString>
+#include <KUniqueApplication>
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Debug>
+#include <TelepathyQt4/ClientRegistrar>
+
+int main(int argc, char **argv)
+{
+ KAboutData aboutData("krdc_rfb_approver", "Krdc", ki18n("Krdc"), "0.1",
+ ki18n("Approver for Krdc"), KAboutData::License_GPL,
+ ki18n("(C) 2009, Abner Silva"));
+ aboutData.setProgramIconName("krdc");
+ aboutData.addAuthor(ki18nc("@info:credit", "Abner Silva"), KLocalizedString(),
+ "abner.silva@kdemail.net");
+
+ KCmdLineArgs::init(argc, argv, &aboutData);
+
+ if (!KUniqueApplication::start())
+ return 0;
+
+ KUniqueApplication app;
+ app.disableSessionManagement();
+
+ Tp::registerTypes();
+ Tp::enableDebug(true);
+ Tp::enableWarnings(true);
+
+ Tp::ClientRegistrarPtr registrar = Tp::ClientRegistrar::create();
+ Tp::SharedPtr<ApproverManager> approverManager;
+ approverManager = Tp::SharedPtr<ApproverManager>(new ApproverManager(0));
+ registrar->registerClient(Tp::AbstractClientPtr::dynamicCast(approverManager), "krdc_rfb_approver");
+
+ return app.exec();
+}
diff --git a/krdc_approver/org.freedesktop.Telepathy.Client.krdc_rfb_approver.service.in b/krdc_approver/org.freedesktop.Telepathy.Client.krdc_rfb_approver.service.in
new file mode 100644
index 0000000..9b1633a
--- /dev/null
+++ b/krdc_approver/org.freedesktop.Telepathy.Client.krdc_rfb_approver.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.freedesktop.Telepathy.Client.krdc_rfb_approver
+Exec=@CMAKE_INSTALL_PREFIX@/bin/krdc_rfb_approver