[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:23:23 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=9cc5c69

The following commit has been merged in the master branch:
commit 9cc5c6996bc08c29dbc24dc0758f0badaf336855
Author: Lasath Fernando <kde at lasath.org>
Date:   Tue Feb 26 11:45:32 2013 -0500

    Create NotifyFilter
    
    Basically move the contents of
    ChatWidget::notifyAboutIncomingMessage() to a filter of it's own.
    
    Will have to make it possible to add view specific filters into
    KTp::MessageProcessor.
---
 lib/CMakeLists.txt    |  1 +
 lib/chat-widget.cpp   | 77 +++++------------------------------------------
 lib/chat-widget.h     |  4 ++-
 lib/notify-filter.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/notify-filter.h   | 19 ++++++++++++
 5 files changed, 112 insertions(+), 71 deletions(-)

diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 5c4741d..4e03671 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -14,6 +14,7 @@ set(ktpchat_SRCS
         chat-text-edit.cpp
         chat-search-bar.cpp
         logmanager.cpp
+        notify-filter.cpp
 )
 
 set(ktpchat_HDRS
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index e7adc5a..d2519b1 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -26,6 +26,7 @@
 #include "adium-theme-status-info.h"
 #include "channel-contact-model.h"
 #include "logmanager.h"
+#include "notify-filter.h"
 
 #include <QtGui/QKeyEvent>
 #include <QtGui/QAction>
@@ -81,6 +82,7 @@ public:
     QList< Tp::OutgoingFileTransferChannelPtr > tmpFileTransfers;
 
     KComponentData telepathyComponentData();
+    KTp::AbstractMessageFilter *notifyFilter;
 };
 
 
@@ -165,12 +167,16 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
     } else {
         m_previousConversationAvailable = false;
     }
+
+    d->notifyFilter = new NotifyFilter(this);
+    KTp::MessageProcessor::instance()->appendFilter(d->notifyFilter);
 }
 
 ChatWidget::~ChatWidget()
 {
     saveSpellCheckingOption();
     d->channel->requestClose(); // ensure closing; does nothing, if already closed
+    KTp::MessageProcessor::instance()->removeFilter(d->notifyFilter);
     delete d;
 }
 
@@ -430,8 +436,6 @@ void ChatWidget::setupChannelSignals()
 {
     connect(d->channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)),
             SLOT(handleIncomingMessage(Tp::ReceivedMessage)));
-    connect(d->channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)),
-            SLOT(notifyAboutIncomingMessage(Tp::ReceivedMessage)));
     connect(d->channel.data(), SIGNAL(pendingMessageRemoved(Tp::ReceivedMessage)),
             SIGNAL(unreadMessagesChanged()));
     connect(d->channel.data(), SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
@@ -646,74 +650,7 @@ void ChatWidget::handleIncomingMessage(const Tp::ReceivedMessage &message)
 
 void ChatWidget::notifyAboutIncomingMessage(const Tp::ReceivedMessage & message)
 {
-    //send the correct notification:
-    QString notificationType;
-    //choose the correct notification type:
-    //options are:
-    // kde_telepathy_contact_incoming
-    // kde_telepathy_contact_incoming_active_window
-    // don't notify of messages sent by self from another computer
-    if (message.sender() == d->channel->groupSelfContact()) {
-        return;
-    }
-
-    if (message.isDeliveryReport()) {
-        return;
-    }
-
-    // kde_telepathy_contact_highlight (contains your name)
-    // kde_telepathy_info_event
-
-    //if the message text contains sender name, it's a "highlighted message"
-    //TODO DrDanz suggested this could be a configurable list of words that make it highlighted.(seems like a good idea to me)
-    if(message.text().contains(d->channel->groupSelfContact()->alias())) {
-        notificationType = QLatin1String("kde_telepathy_contact_highlight");
-    } else if(message.messageType() == Tp::ChannelTextMessageTypeNotice) {
-        notificationType = QLatin1String("kde_telepathy_info_event");
-    } else {
-        if (isOnTop()) {
-            notificationType = QLatin1String("kde_telepathy_contact_incoming_active_window");
-        } else {
-            notificationType = QLatin1String("kde_telepathy_contact_incoming");
-        }
-    }
-
-    KNotification *notification = new KNotification(notificationType, this,
-                                                    KNotification::RaiseWidgetOnActivation
-                                                    | KNotification::CloseWhenWidgetActivated
-                                                    | KNotification::Persistent);
-    notification->setComponentData(d->telepathyComponentData());
-   
-    QString senderName;
-
-    if (message.sender().isNull()) {
-        senderName = message.senderNickname();
-    } else {
-        senderName = message.sender()->alias();
-        QPixmap notificationPixmap;
-        if (notificationPixmap.load(message.sender()->avatarData().fileName)) {
-            notification->setPixmap(notificationPixmap);
-        }
-        //allows per contact notifications
-        notification->addContext(QLatin1String("contact"), message.sender()->id());
-    }
-    notification->setTitle(i18n("%1 has sent you a message", senderName));
-
-    // Remove empty lines from message
-    QString notifyText = message.text().simplified();
-    if (notifyText.length() > 170) {
-        //search for the closest space in text
-        QString truncatedMsg = notifyText.left(notifyText.indexOf(QLatin1Char(' '), 150)).append(QLatin1String("..."));
-        notification->setText(truncatedMsg);
-    } else {
-        notification->setText(notifyText);
-    }
-
-
-    notification->setActions(QStringList(i18n("View")));
-    connect(notification, SIGNAL(activated(uint)), this, SIGNAL(notificationClicked()));
-
-    notification->sendEvent();
+    Q_ASSERT(false);
 }
 
 void ChatWidget::handleMessageSent(const Tp::Message &message, Tp::MessageSendingFlags, const QString&) /*Not sure what these other args are for*/
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index 2c85f3b..a88e599 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -99,6 +99,9 @@ public:
 
     void setZoomFactor(qreal zoomFactor);
 
+    /** Is this widget visible and in the active window */
+    virtual bool isOnTop() const;
+
 public Q_SLOTS:
     /** toggle the search bar visibility */
     void toggleSearchBar() const;
@@ -200,7 +203,6 @@ private:
     /** Loads theme into the the AdiumThemeView */
     void initChatArea();
 
-    virtual bool isOnTop() const;
     bool m_previousConversationAvailable;
 
     ChatWidgetPrivate * const d;
diff --git a/lib/notify-filter.cpp b/lib/notify-filter.cpp
new file mode 100644
index 0000000..d180aba
--- /dev/null
+++ b/lib/notify-filter.cpp
@@ -0,0 +1,82 @@
+#include "notify-filter.h"
+
+#include <KAboutData>
+#include <KComponentData>
+#include <KNotification>
+
+NotifyFilter::NotifyFilter(ChatWidget *widget) :
+    KTp::AbstractMessageFilter(widget),
+    m_widget(widget)
+{
+}
+
+// TODO: when d_ed makes this available in a libarary, like he
+// said in chat-widget.cpp, replace this
+static KComponentData telepathyComponentData() {
+    KAboutData telepathySharedAboutData("ktelepathy",0,KLocalizedString(),0);
+    return KComponentData(telepathySharedAboutData);
+}
+
+void NotifyFilter::filterMessage(KTp::Message &message, const KTp::MessageContext &context) {
+
+    // don't notify of past messages
+    if (message.isHistory()) {
+        return;
+    }
+    // don't notify of outgoing messages
+    if (message.direction() != KTp::Message::RemoteToLocal) {
+        return;
+    }
+    // don't notify of messages sent by self from another location
+    if (message.property("sender").toString() ==
+            context.channel()->groupSelfContact()->alias()) {
+        return;
+    }
+
+    // choose correct notification type
+    QString notificationType;
+    if(message.property("highlight").toBool()) {
+        notificationType = QLatin1String("kde_telepathy_contact_highlight");
+    } else if(message.type() == Tp::ChannelTextMessageTypeNotice) {
+        notificationType = QLatin1String("kde_telepathy_info_event");
+    } else {
+        if (m_widget->isOnTop()) {
+            notificationType = QLatin1String("kde_telepathy_contact_incoming_active_window");
+        } else {
+            notificationType = QLatin1String("kde_telepathy_contact_incoming");
+        }
+    }
+
+    KNotification *notification = new KNotification(
+                notificationType, m_widget,
+                KNotification::RaiseWidgetOnActivation
+                | KNotification::CloseWhenWidgetActivated
+                | KNotification::Persistent);
+
+    notification->setComponentData(telepathyComponentData());
+    notification->setTitle(i18n("%1 has sent you a message",
+                                message.property("sender").toString()));
+
+    QString senderAvatar = message.property("sender-avatar").toString();
+    if (!senderAvatar.isNull()) {
+        QPixmap notificationPixmap;
+        if (notificationPixmap.load(senderAvatar)) {
+            notification->setPixmap(notificationPixmap);
+        }
+    }
+
+    //truncate message if necessary
+    QString notifyText = message.mainMessagePart().simplified();
+    if (notifyText.length() > 170) {
+        //search for the closest space in text
+        notifyText.truncate(notifyText.indexOf(QLatin1Char(' '), 150));
+        notifyText.append(QLatin1String("..."));
+    }
+    notification->setText(notifyText);
+
+
+    notification->setActions(QStringList(i18n("View")));
+    connect(notification, SIGNAL(activated(uint)), m_widget, SIGNAL(notificationClicked()));
+
+    notification->sendEvent();
+}
diff --git a/lib/notify-filter.h b/lib/notify-filter.h
new file mode 100644
index 0000000..9a8b90f
--- /dev/null
+++ b/lib/notify-filter.h
@@ -0,0 +1,19 @@
+#ifndef NOTIFYFILTER_H
+#define NOTIFYFILTER_H
+
+#include "chat-widget.h"
+
+#include <KTp/abstract-message-filter.h>
+
+class NotifyFilter : public KTp::AbstractMessageFilter
+{
+    Q_OBJECT
+public:
+    explicit NotifyFilter(ChatWidget *widget);
+    void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
+
+private:
+    ChatWidget *m_widget;
+};
+
+#endif // NOTIFYFILTER_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list