[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktp-text-ui/otr-proxy] lib: Added notification about authentication events and changes in OTR sessi
From:       Marcin_Ziemiński <zieminn () gmail ! com>
Date:       2014-08-17 17:09:40
Message-ID: E1XJ3xc-0000Br-U5 () scm ! kde ! org
[Download RAW message or body]

Git commit 881009073c1728470c94c8cde08087bd2a521857 by Marcin Ziemiński.
Committed on 17/08/2014 at 16:49.
Pushed by mzieminski into branch 'otr-proxy'.

Added notification about authentication events and changes in OTR sessions.

M  +1    -0    lib/CMakeLists.txt
M  +27   -2    lib/chat-widget.cpp
A  +112  -0    lib/otr-notifications.cpp     [License: GPL (v2+)]
A  +42   -0    lib/otr-notifications.h     [License: GPL (v2+)]

http://commits.kde.org/telepathy-text-ui/881009073c1728470c94c8cde08087bd2a521857

diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index e368194..796ff1b 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -24,6 +24,7 @@ set(ktpchat_SRCS
         proxy-service.cpp
         otr-utils.cpp
         authenticationwizard.cpp
+        otr-notifications.cpp
         )
 
 set(ktpchat_UI
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index bcd10e7..deff57c 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -31,6 +31,7 @@
 #include "contact-delegate.h"
 #include "channel-adapter.h"
 #include "authenticationwizard.h"
+#include "otr-notifications.h"
 
 #include <QtGui/QKeyEvent>
 #include <QtGui/QAction>
@@ -741,6 +742,9 @@ void ChatWidget::onOTRTrustLevelChanged(Tp::OTRTrustLevel \
trustLevel, Tp::OTRTru  }
             else {
                 d->ui.chatArea->addStatusMessage(i18n("Unverified OTR session \
started")); +                if(!this->isActiveWindow()) {
+                    OTRNotifications::otrSessionStarted(this, \
d->channel.textChannel()->targetContact(), false); +                }
             }
             break;
         case Tp::OTRTrustLevelPrivate:
@@ -749,10 +753,16 @@ void ChatWidget::onOTRTrustLevelChanged(Tp::OTRTrustLevel \
trustLevel, Tp::OTRTru  }
             else {
                 d->ui.chatArea->addStatusMessage(i18n("Private OTR session \
started")); +                if(!this->isActiveWindow()) {
+                    OTRNotifications::otrSessionStarted(this, \
d->channel.textChannel()->targetContact(), true); +                }
             }
             break;
         case Tp::OTRTrustLevelFinished:
             d->ui.chatArea->addStatusMessage(i18n("%1 has ended the OTR session. You \
should do the same", d->contactName)); +            if(!this->isActiveWindow()) {
+                OTRNotifications::otrSessionFinished(this, \
d->channel.textChannel()->targetContact()); +            }
             break;
 
         default: break;
@@ -769,12 +779,18 @@ void ChatWidget::onOTRsessionRefreshed()
 
 void ChatWidget::onPeerAuthenticationRequestedQA(const QString &question)
 {
-    new AuthenticationWizard(&d->channel, d->contactName, this, false, question);
+    AuthenticationWizard *wizard = new AuthenticationWizard(&d->channel, \
d->contactName, this, false, question); +    if(!wizard->isActiveWindow()) {
+        OTRNotifications::authenticationRequested(wizard, \
d->channel.textChannel()->targetContact()); +    }
 }
 
 void ChatWidget::onPeerAuthenticationRequestedSS()
 {
-    new AuthenticationWizard(&d->channel, d->contactName, this, false);
+    AuthenticationWizard *wizard = new AuthenticationWizard(&d->channel, \
d->contactName, this, false); +    if(!wizard->isActiveWindow()) {
+        OTRNotifications::authenticationRequested(wizard, \
d->channel.textChannel()->targetContact()); +    }
 }
 
 void ChatWidget::onPeerAuthenticationConcluded(bool authenticated)
@@ -785,6 +801,9 @@ void ChatWidget::onPeerAuthenticationConcluded(bool \
authenticated)  wizard->showNormal();
         wizard->finished(authenticated);
     }
+    if(!wizard->isActiveWindow()) {
+        OTRNotifications::authenticationConcluded(wizard, \
d->channel.textChannel()->targetContact(), authenticated); +    }
 }
 
 void ChatWidget::onPeerAuthenticationInProgress()
@@ -805,6 +824,9 @@ void ChatWidget::onPeerAuthenticationAborted()
         wizard->showNormal();
         wizard->aborted();
     }
+    if(!wizard->isActiveWindow()) {
+        OTRNotifications::authenticationAborted(wizard, \
d->channel.textChannel()->targetContact()); +    }
 }
 
 void ChatWidget::onPeerAuthenticationFailed()
@@ -815,6 +837,9 @@ void ChatWidget::onPeerAuthenticationFailed()
         wizard->showNormal();
         wizard->finished(false);
     }
+    if(!wizard->isActiveWindow()) {
+        OTRNotifications::authenticationFailed(wizard, \
d->channel.textChannel()->targetContact()); +    }
 }
 
 void ChatWidget::handleIncomingMessage(const Tp::ReceivedMessage &message, bool \
                alreadyNotified)
diff --git a/lib/otr-notifications.cpp b/lib/otr-notifications.cpp
new file mode 100644
index 0000000..883ac41
--- /dev/null
+++ b/lib/otr-notifications.cpp
@@ -0,0 +1,112 @@
+/***************************************************************************
+ *   Copyright (C) 2014 by Marcin Ziemiński <zieminn@gmail.com>            *
+ *                                                                         *
+ *   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; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+
+#include "otr-notifications.h"
+
+#include <TelepathyQt/AvatarData>
+
+#include <QWidget>
+
+#include <KAboutData>
+#include <KComponentData>
+#include <KNotification>
+
+namespace OTRNotifications
+{
+
+    static KNotification* prepareNotification(QWidget *widget, const Tp::ContactPtr \
&contact) +    {
+        const QString notificationType = QLatin1String("kde_telepathy_info_event");
+
+        KNotification *notification = new KNotification(
+                notificationType, widget,
+                KNotification::RaiseWidgetOnActivation
+                | KNotification::CloseWhenWidgetActivated
+                | KNotification::CloseOnTimeout);
+
+        KAboutData telepathySharedAboutData("ktelepathy", 0, KLocalizedString(), 0);
+        notification->setComponentData(KComponentData(telepathySharedAboutData));
+
+        QPixmap notificationPixmap;
+        if(notificationPixmap.load(contact->avatarData().fileName)) {
+            notification->setPixmap(notificationPixmap);
+        }
+
+        notification->setActions(QStringList(i18n("View")));
+
+        return notification;
+    }
+
+    void otrSessionStarted(QWidget *widget, const Tp::ContactPtr &targetContact, \
bool verified) +    {
+        KNotification *notification = prepareNotification(widget, targetContact);
+        if(verified) {
+            notification->setText(i18n("Private OTR session started with %1", \
targetContact->id())); +        } else {
+            notification->setText(i18n("Unverified OTR session started with %1", \
targetContact->id())); +        }
+
+        notification->sendEvent();
+    }
+
+    void otrSessionFinished(QWidget *widget, const Tp::ContactPtr &targetContact)
+    {
+        KNotification *notification = prepareNotification(widget, targetContact);
+        notification->setText(i18n("Finished OTR session with %1", \
targetContact->id())); +
+        notification->sendEvent();
+    }
+
+    void authenticationRequested(QWidget *widget, const Tp::ContactPtr \
&targetContact) +    {
+        KNotification *notification = prepareNotification(widget, targetContact);
+        notification->setText(i18n("%1 has requested your authentication", \
targetContact->id())); +
+        notification->sendEvent();
+    }
+
+    void authenticationConcluded(QWidget *widget, const Tp::ContactPtr \
&targetContact, bool success) +    {
+        KNotification *notification = prepareNotification(widget, targetContact);
+        if(success) {
+            notification->setText(i18n("Authentication with %1 completed \
successfully", targetContact->id())); +        } else {
+            notification->setText(i18n("Authentication with %1 failed", \
targetContact->id())); +        }
+
+        notification->sendEvent();
+    }
+
+    void authenticationAborted(QWidget *widget, const Tp::ContactPtr &targetContact)
+    {
+        KNotification *notification = prepareNotification(widget, targetContact);
+        notification->setText(i18n("Authentication with %1 was aborted", \
targetContact->id())); +
+        notification->sendEvent();
+    }
+
+    void authenticationFailed(QWidget *widget, const Tp::ContactPtr &targetContact)
+    {
+        KNotification *notification = prepareNotification(widget, targetContact);
+        notification->setText(i18n("Authentication with %1 failed", \
targetContact->id())); +
+        notification->sendEvent();
+    }
+}
diff --git a/lib/otr-notifications.h b/lib/otr-notifications.h
new file mode 100644
index 0000000..fdbc28a
--- /dev/null
+++ b/lib/otr-notifications.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ *   Copyright (C) 2014 by Marcin Ziemiński <zieminn@gmail.com>            *
+ *                                                                         *
+ *   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; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef OTR_NOTIFICATIONS_HEADER
+#define OTR_NOTIFICATIONS_HEADER
+
+#include <TelepathyQt/Contact>
+
+class QWidget;
+
+namespace OTRNotifications
+{
+    void otrSessionStarted(QWidget *widget, const Tp::ContactPtr &targetContact, \
bool verified); +
+    void otrSessionFinished(QWidget *widget, const Tp::ContactPtr &targetContact);
+
+    void authenticationRequested(QWidget *widget, const Tp::ContactPtr \
&targetContact); +
+    void authenticationConcluded(QWidget *widget, const Tp::ContactPtr \
&targetContact, bool success); +
+    void authenticationAborted(QWidget *widget, const Tp::ContactPtr \
&targetContact); +
+    void authenticationFailed(QWidget *widget, const Tp::ContactPtr &targetContact);
+}
+
+#endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic