[SCM] ktp-approver packaging branch, master, updated. debian/15.12.1-1-299-g62cbbd7

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 09:13:06 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-approver.git;a=commitdiff;h=ad7303f

The following commit has been merged in the master branch:
commit ad7303fcbd97feb7042aaf36b5c29d31ad1cbcba
Author: George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
Date:   Mon Dec 6 18:13:35 2010 +0200

    Initial implementation of the approver.
---
 CMakeLists.txt                      |  11 ++++
 src/CMakeLists.txt                  |  18 ++++++
 src/approverdaemon.cpp              |  48 +++++++++++++++
 src/approverdaemon.h                |  33 +++++++++++
 src/channelapprover.cpp             |  31 ++++++++++
 src/channelapprover.h               |  40 +++++++++++++
 src/dispatchoperation.cpp           |  97 ++++++++++++++++++++++++++++++
 src/dispatchoperation.h             |  50 ++++++++++++++++
 src/handlewithcaller.cpp            |  58 ++++++++++++++++++
 src/handlewithcaller.h              |  40 +++++++++++++
 src/telepathy_kde_approver.desktop  |   9 +++
 src/telepathy_kde_approver.notifyrc |  10 ++++
 src/textchannelapprover.cpp         | 114 ++++++++++++++++++++++++++++++++++++
 src/textchannelapprover.h           |  48 +++++++++++++++
 src/tpkdeapprovermodule.cpp         |  82 ++++++++++++++++++++++++++
 15 files changed, 689 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..a0a1606
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,11 @@
+project(telepathy_kde_approver)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
+
+find_package(KDE4 REQUIRED)
+find_package(TelepathyQt4 0.5.0 REQUIRED)
+
+include_directories(${KDE4_INCLUDES} ${TELEPATHY_QT4_INCLUDE_DIR})
+add_definitions(${KDE4_DEFINITIONS})
+
+add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..b1c062f
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,18 @@
+set(telepathy_kde_approver_SRCS
+    tpkdeapprovermodule.cpp
+    approverdaemon.cpp
+    dispatchoperation.cpp
+    handlewithcaller.cpp
+    channelapprover.cpp
+    textchannelapprover.cpp
+)
+
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+kde4_add_plugin(kded_telepathy_kde_approver ${telepathy_kde_approver_SRCS})
+target_link_libraries(kded_telepathy_kde_approver ${KDE4_KDEUI_LIBS}
+                                                  ${TELEPATHY_QT4_LIBRARIES})
+
+install(TARGETS kded_telepathy_kde_approver DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES telepathy_kde_approver.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
+install(FILES telepathy_kde_approver.notifyrc DESTINATION ${DATA_INSTALL_DIR}/telepathy_kde_approver)
diff --git a/src/approverdaemon.cpp b/src/approverdaemon.cpp
new file mode 100644
index 0000000..3068145
--- /dev/null
+++ b/src/approverdaemon.cpp
@@ -0,0 +1,48 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "approverdaemon.h"
+#include "dispatchoperation.h"
+#include <TelepathyQt4/ChannelClassSpec>
+#include <TelepathyQt4/ChannelDispatchOperation>
+
+static inline Tp::ChannelClassSpecList channelClassSpecList()
+{
+    return Tp::ChannelClassSpecList()
+                << Tp::ChannelClassSpec::textChat()
+#if 0
+                << Tp::ChannelClassSpec::unnamedTextChat()
+                << Tp::ChannelClassSpec::textChatroom()
+                << Tp::ChannelClassSpec::streamedMediaCall()
+                << Tp::ChannelClassSpec::streamedMediaAudioCall()
+                << Tp::ChannelClassSpec::streamedMediaVideoCall()
+                << Tp::ChannelClassSpec::incomingFileTransfer()
+#endif
+                ;
+}
+
+ApproverDaemon::ApproverDaemon()
+    : QObject(), AbstractClientApprover(channelClassSpecList())
+{
+}
+
+void ApproverDaemon::addDispatchOperation(const Tp::MethodInvocationContextPtr<> & context,
+                                          const Tp::ChannelDispatchOperationPtr & dispatchOperation)
+{
+    new DispatchOperation(dispatchOperation, this);
+    context->setFinished();
+}
diff --git a/src/approverdaemon.h b/src/approverdaemon.h
new file mode 100644
index 0000000..2cee00e
--- /dev/null
+++ b/src/approverdaemon.h
@@ -0,0 +1,33 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef APPROVERDAEMON_H
+#define APPROVERDAEMON_H
+
+#include <TelepathyQt4/AbstractClientApprover>
+
+class ApproverDaemon : public QObject, public Tp::AbstractClientApprover
+{
+public:
+    ApproverDaemon();
+
+protected:
+    virtual void addDispatchOperation(const Tp::MethodInvocationContextPtr<> & context,
+                                      const Tp::ChannelDispatchOperationPtr & dispatchOperation);
+};
+
+#endif // APPROVERDAEMON_H
diff --git a/src/channelapprover.cpp b/src/channelapprover.cpp
new file mode 100644
index 0000000..917058e
--- /dev/null
+++ b/src/channelapprover.cpp
@@ -0,0 +1,31 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "channelapprover.h"
+#include "textchannelapprover.h"
+
+ChannelApprover *ChannelApprover::create(const Tp::ChannelPtr & channel, QObject *parent)
+{
+    if (channel->channelType() == TP_QT4_IFACE_CHANNEL_TYPE_TEXT) {
+        return new TextChannelApprover(Tp::TextChannelPtr::dynamicCast(channel), parent);
+    }
+
+    Q_ASSERT(false);
+    return NULL;
+}
+
+#include "channelapprover.moc"
diff --git a/src/channelapprover.h b/src/channelapprover.h
new file mode 100644
index 0000000..65fec51
--- /dev/null
+++ b/src/channelapprover.h
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef CHANNELAPPROVER_H
+#define CHANNELAPPROVER_H
+
+#include <QtCore/QObject>
+#include <TelepathyQt4/Channel>
+
+class ChannelApprover : public QObject
+{
+    Q_OBJECT
+public:
+    static ChannelApprover *create(const Tp::ChannelPtr & channel, QObject *parent);
+
+    virtual ~ChannelApprover() {}
+
+Q_SIGNALS:
+    void channelAccepted();
+    void channelRejected();
+
+protected:
+    inline ChannelApprover(QObject *parent) : QObject(parent) {}
+};
+
+#endif // CHANNELAPPROVER_H
diff --git a/src/dispatchoperation.cpp b/src/dispatchoperation.cpp
new file mode 100644
index 0000000..35e0508
--- /dev/null
+++ b/src/dispatchoperation.cpp
@@ -0,0 +1,97 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "dispatchoperation.h"
+#include "channelapprover.h"
+#include "handlewithcaller.h"
+#include <KDebug>
+#include <TelepathyQt4/PendingOperation>
+
+DispatchOperation::DispatchOperation(const Tp::ChannelDispatchOperationPtr & dispatchOperation,
+                                     QObject *parent)
+    : QObject(parent), m_dispatchOperation(dispatchOperation)
+{
+    connect(m_dispatchOperation.data(), SIGNAL(channelLost(Tp::ChannelPtr,QString,QString)),
+            SLOT(onChannelLost(Tp::ChannelPtr,QString,QString)));
+    connect(m_dispatchOperation.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
+            SLOT(onDispatchOperationInvalidated(Tp::DBusProxy*,QString,QString)));
+
+    Q_FOREACH(const Tp::ChannelPtr & channel, dispatchOperation->channels()) {
+        ChannelApprover *approver = ChannelApprover::create(channel, this);
+        Q_ASSERT(approver);
+
+        m_channelApprovers.insert(channel, approver);
+
+        connect(approver, SIGNAL(channelAccepted()), SLOT(onChannelAccepted()));
+        connect(approver, SIGNAL(channelRejected()), SLOT(onChannelRejected()));
+    }
+
+    Q_ASSERT(!m_channelApprovers.isEmpty());
+}
+
+DispatchOperation::~DispatchOperation()
+{
+    kDebug();
+}
+
+void DispatchOperation::onChannelLost(const Tp::ChannelPtr & channel,
+                                      const QString & errorName,
+                                      const QString & errorMessage)
+{
+    kDebug() << "Channel lost:" << errorName << errorMessage;
+
+    ChannelApprover *approver = m_channelApprovers.take(channel);
+    Q_ASSERT(approver);
+    approver->deleteLater();
+}
+
+void DispatchOperation::onDispatchOperationInvalidated(Tp::DBusProxy *proxy,
+                                                       const QString & errorName,
+                                                       const QString & errorMessage)
+{
+    Q_UNUSED(proxy);
+    kDebug() << "Dispatch operation invalidated" << errorName << errorMessage;
+    deleteLater();
+}
+
+void DispatchOperation::onChannelAccepted()
+{
+    new HandleWithCaller(m_dispatchOperation, this);
+}
+
+void DispatchOperation::onChannelRejected()
+{
+    Tp::PendingOperation *operation = m_dispatchOperation->claim();
+    connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(onClaimFinished(Tp::PendingOperation*)));
+}
+
+void DispatchOperation::onClaimFinished(Tp::PendingOperation *operation)
+{
+    if (operation->isError()) {
+        kDebug() << "Claim error:" << operation->errorName() << operation->errorMessage();
+        return;
+    }
+
+    QHashIterator<Tp::ChannelPtr, ChannelApprover*> it(m_channelApprovers);
+    while(it.hasNext()) {
+        it.next();
+        it.key()->requestClose();
+    }
+}
+
+#include "dispatchoperation.moc"
diff --git a/src/dispatchoperation.h b/src/dispatchoperation.h
new file mode 100644
index 0000000..39ee5cb
--- /dev/null
+++ b/src/dispatchoperation.h
@@ -0,0 +1,50 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef DISPATCHOPERATION_H
+#define DISPATCHOPERATION_H
+
+#include <QtCore/QObject>
+#include <TelepathyQt4/ChannelDispatchOperation>
+
+class ChannelApprover;
+
+class DispatchOperation : public QObject
+{
+    Q_OBJECT
+public:
+    DispatchOperation(const Tp::ChannelDispatchOperationPtr & dispatchOperation, QObject *parent);
+    virtual ~DispatchOperation();
+
+
+private Q_SLOTS:
+    void onChannelLost(const Tp::ChannelPtr & channel,
+                       const QString & errorName,
+                       const QString & errorMessage);
+    void onDispatchOperationInvalidated(Tp::DBusProxy *proxy,
+                                        const QString & errorName,
+                                        const QString & errorMessage);
+    void onChannelAccepted();
+    void onChannelRejected();
+    void onClaimFinished(Tp::PendingOperation *operation);
+
+private:
+    Tp::ChannelDispatchOperationPtr m_dispatchOperation;
+    QHash<Tp::ChannelPtr, ChannelApprover*> m_channelApprovers;
+};
+
+#endif // DISPATCHOPERATION_H
diff --git a/src/handlewithcaller.cpp b/src/handlewithcaller.cpp
new file mode 100644
index 0000000..659a867
--- /dev/null
+++ b/src/handlewithcaller.cpp
@@ -0,0 +1,58 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "handlewithcaller.h"
+#include <TelepathyQt4/PendingOperation>
+
+HandleWithCaller::HandleWithCaller(const Tp::ChannelDispatchOperationPtr & dispatchOperation,
+                                   QObject *parent)
+    : QObject(parent)
+{
+    m_dispatchOperation = dispatchOperation;
+    m_possibleHandlers = dispatchOperation->possibleHandlers();
+    Q_ASSERT(!m_possibleHandlers.isEmpty());
+
+    callHandleWith();
+}
+
+void HandleWithCaller::callHandleWith()
+{
+    Tp::PendingOperation *op = m_dispatchOperation->handleWith(m_possibleHandlers.first());
+    connect(op, SIGNAL(finished(Tp::PendingOperation*)),
+            SLOT(onHandleWithFinished(Tp::PendingOperation*)));
+}
+
+void HandleWithCaller::onHandleWithFinished(Tp::PendingOperation* operation)
+{
+    if (operation->isError()) {
+        if (operation->errorName() == TP_QT4_ERROR_INVALID_ARGUMENT ||
+            operation->errorName() == TP_QT4_ERROR_NOT_AVAILABLE ||
+            operation->errorName() == TP_QT4_ERROR_NOT_IMPLEMENTED)
+        {
+            //remove the handler that we just tried and try the next one
+            m_possibleHandlers.removeFirst();
+            if (!m_possibleHandlers.isEmpty()) {
+                callHandleWith();
+                return;
+            }
+        }
+    }
+
+    deleteLater();
+}
+
+#include "handlewithcaller.moc"
diff --git a/src/handlewithcaller.h b/src/handlewithcaller.h
new file mode 100644
index 0000000..1e026a6
--- /dev/null
+++ b/src/handlewithcaller.h
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef HANDLEWITHCALLER_H
+#define HANDLEWITHCALLER_H
+
+#include <QtCore/QObject>
+#include <TelepathyQt4/ChannelDispatchOperation>
+
+class HandleWithCaller : public QObject
+{
+    Q_OBJECT
+public:
+    HandleWithCaller(const Tp::ChannelDispatchOperationPtr & dispatchOperation, QObject *parent);
+
+private Q_SLOTS:
+    void onHandleWithFinished(Tp::PendingOperation *operation);
+
+private:
+    void callHandleWith();
+
+    Tp::ChannelDispatchOperationPtr m_dispatchOperation;
+    QStringList m_possibleHandlers;
+};
+
+#endif //HANDLEWITHCALLER_H
diff --git a/src/telepathy_kde_approver.desktop b/src/telepathy_kde_approver.desktop
new file mode 100644
index 0000000..cc69f59
--- /dev/null
+++ b/src/telepathy_kde_approver.desktop
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Name=Telepathy KDE Approver
+Comment=Shows notifications for incoming IM/Call requests and allows you to open a handler to answer
+Type=Service
+X-KDE-ServiceTypes=KDEDModule
+X-KDE-Library=telepathy_kde_approver
+X-KDE-DBus-ModuleName=telepathy_kde_approver
+X-KDE-Kded-autoload=false
+X-KDE-Kded-load-on-demand=true
diff --git a/src/telepathy_kde_approver.notifyrc b/src/telepathy_kde_approver.notifyrc
new file mode 100644
index 0000000..81e92e1
--- /dev/null
+++ b/src/telepathy_kde_approver.notifyrc
@@ -0,0 +1,10 @@
+[Global]
+IconName=kopete
+Name=Instant messaging
+Comment=Instant messaging
+
+[Event/new_text_message]
+Name=Incoming message
+Comment=A new instant message has been received
+Sound=KDE-Im-Message-In.ogg
+Action=Popup|Sound
diff --git a/src/textchannelapprover.cpp b/src/textchannelapprover.cpp
new file mode 100644
index 0000000..a777582
--- /dev/null
+++ b/src/textchannelapprover.cpp
@@ -0,0 +1,114 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "textchannelapprover.h"
+#include <KNotification>
+#include <KStatusNotifierItem>
+#include <KLocale>
+#include <KGlobal>
+#include <TelepathyQt4/ReceivedMessage>
+#include <TelepathyQt4/AvatarData>
+
+TextChannelApprover::TextChannelApprover(const Tp::TextChannelPtr & channel, QObject *parent)
+    : ChannelApprover(parent), m_notifierItem(getNotifierItem())
+{
+    Q_FOREACH(const Tp::ReceivedMessage & msg, channel->messageQueue()) {
+        onMessageReceived(msg);
+    }
+
+    connect(channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)),
+            SLOT(onMessageReceived(Tp::ReceivedMessage)));
+    connect(m_notifierItem.data(), SIGNAL(activateRequested(bool,QPoint)),
+            SIGNAL(channelAccepted()));
+}
+
+TextChannelApprover::~TextChannelApprover()
+{
+    //destroy the notifications
+    Q_FOREACH(KNotification *notification, m_notifications) {
+        notification->close();
+    }
+    m_notifications.clear();
+}
+
+void TextChannelApprover::onMessageReceived(const Tp::ReceivedMessage & msg)
+{
+    KNotification *notification = new KNotification("new_text_message");
+    notification->setText(msg.text());
+
+    Tp::ContactPtr sender = msg.sender();
+    if (sender) {
+        notification->setTitle(i18n("Incoming message from %1", sender->alias()));
+
+        QPixmap pixmap;
+        if (pixmap.load(sender->avatarData().fileName)) {
+            notification->setPixmap(pixmap);
+        }
+    } else {
+        notification->setTitle(i18n("Incoming message"));
+    }
+
+    notification->setActions(QStringList() << i18n("Respond"));
+    connect(notification, SIGNAL(activated()), SIGNAL(channelAccepted()));
+
+    notification->sendEvent();
+
+    m_notifications.insert(notification);
+    connect(notification, SIGNAL(destroyed(QObject*)), SLOT(onNotificationDestroyed(QObject*)));
+
+    updateNotifierItemTooltip();
+}
+
+void TextChannelApprover::onNotificationDestroyed(QObject *notification)
+{
+    m_notifications.remove(reinterpret_cast<KNotification*>(notification));
+}
+
+
+K_GLOBAL_STATIC(QWeakPointer<KStatusNotifierItem>, s_notifierItem)
+
+//static
+QSharedPointer<KStatusNotifierItem> TextChannelApprover::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("mail-unread"));
+        notifierItem->setAttentionIconByName(QLatin1String("mail-unread-new"));
+        notifierItem->setStandardActionsEnabled(false);
+        notifierItem->setProperty("approver_new_messages_count", 0U);
+        *s_notifierItem = notifierItem;
+    }
+
+    return notifierItem;
+}
+
+void TextChannelApprover::updateNotifierItemTooltip()
+{
+    QVariant numMessages = m_notifierItem->property("approver_new_messages_count");
+    numMessages = QVariant(numMessages.toUInt() + 1);
+    m_notifierItem->setProperty("approver_new_messages_count", numMessages);
+
+    m_notifierItem->setToolTip(QLatin1String("mail-unread-new"),
+                               i18n("You have %1 new unread messages", numMessages.toUInt()),
+                               QString());
+}
+
+
+#include "textchannelapprover.moc"
diff --git a/src/textchannelapprover.h b/src/textchannelapprover.h
new file mode 100644
index 0000000..7f2e1db
--- /dev/null
+++ b/src/textchannelapprover.h
@@ -0,0 +1,48 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef TEXTCHANNELAPPROVER_H
+#define TEXTCHANNELAPPROVER_H
+
+#include "channelapprover.h"
+#include <QtCore/QSet>
+#include <QtCore/QSharedPointer>
+#include <TelepathyQt4/TextChannel>
+
+class KStatusNotifierItem;
+class KNotification;
+
+class TextChannelApprover : public ChannelApprover
+{
+    Q_OBJECT
+public:
+    TextChannelApprover(const Tp::TextChannelPtr & channel, QObject *parent);
+    virtual ~TextChannelApprover();
+
+private Q_SLOTS:
+    void onMessageReceived(const Tp::ReceivedMessage & msg);
+    void onNotificationDestroyed(QObject *notification);
+
+private:
+    static QSharedPointer<KStatusNotifierItem> getNotifierItem();
+    void updateNotifierItemTooltip();
+
+    QSet<KNotification*> m_notifications;
+    QSharedPointer<KStatusNotifierItem> m_notifierItem;
+};
+
+#endif //TEXTCHANNELAPPROVER_H
diff --git a/src/tpkdeapprovermodule.cpp b/src/tpkdeapprovermodule.cpp
new file mode 100644
index 0000000..7df6f5c
--- /dev/null
+++ b/src/tpkdeapprovermodule.cpp
@@ -0,0 +1,82 @@
+/*
+    Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+      @author George Kiagiadakis <george.kiagiadakis at collabora.co.uk>
+
+    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 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 Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "approverdaemon.h"
+
+#include <KAboutData>
+#include <KLocale>
+#include <KComponentData>
+#include <KDEDModule>
+#include <KPluginFactory>
+
+#include <TelepathyQt4/Types>
+#include <TelepathyQt4/Debug>
+#include <TelepathyQt4/ClientRegistrar>
+#include <TelepathyQt4/Channel>
+#include <TelepathyQt4/TextChannel>
+
+class TpKDEApproverModule : public KDEDModule
+{
+public:
+    TpKDEApproverModule(QObject *parent, const QVariantList & args)
+        : KDEDModule(parent)
+    {
+        Q_UNUSED(args);
+
+        Tp::registerTypes();
+        Tp::enableDebug(true);
+        Tp::enableWarnings(true);
+
+        Tp::AccountFactoryPtr accountFactory =
+            Tp::AccountFactory::create(QDBusConnection::sessionBus());
+        Tp::ConnectionFactoryPtr connectionFactory =
+            Tp::ConnectionFactory::create(QDBusConnection::sessionBus());
+
+        Tp::ChannelFactoryPtr channelFactory =
+            Tp::ChannelFactory::create(QDBusConnection::sessionBus());
+        channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
+        channelFactory->addFeaturesForTextChats(Tp::Features()
+                                                    << Tp::TextChannel::FeatureCore
+                                                    << Tp::TextChannel::FeatureMessageQueue);
+
+        Tp::ContactFactoryPtr contactFactory =
+            Tp::ContactFactory::create(Tp::Features()
+                                        << Tp::Contact::FeatureAlias
+                                        << Tp::Contact::FeatureAvatarData);
+
+        m_registrar = Tp::ClientRegistrar::create(accountFactory, connectionFactory,
+                                                  channelFactory, contactFactory);
+        m_registrar->registerClient(Tp::SharedPtr<ApproverDaemon>(new ApproverDaemon()),
+                                    "telepathy_kde_approver");
+    }
+
+    static inline KAboutData aboutData()
+    {
+        KAboutData aboutData("telepathy_kde_approver", 0, KLocalizedString(), "0.1",
+                             KLocalizedString(), KAboutData::License_LGPL,
+                             ki18n("(C) 2010, Collabora Ltd."));
+        aboutData.addAuthor(ki18nc("@info:credit", "George Kiagiadakis"),
+                            KLocalizedString(), "george.kiagiadakis at collabora.co.uk");
+        return aboutData;
+    }
+
+private:
+    Tp::ClientRegistrarPtr m_registrar;
+};
+
+K_PLUGIN_FACTORY(TpKDEApproverFactory, registerPlugin<TpKDEApproverModule>();)
+K_EXPORT_PLUGIN(TpKDEApproverFactory(TpKDEApproverModule::aboutData()))

-- 
ktp-approver packaging



More information about the pkg-kde-commits mailing list