[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:24:40 UTC 2016


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

The following commit has been merged in the master branch:
commit 494d208a199be41fb3482c938fb4498deb90250c
Author: Marcin Ziemiński <zieminn at gmail.com>
Date:   Thu Jun 19 17:52:26 2014 +0200

    Added OTR support for gabble channels.
    Users can now initialize and stop OTR sessions and authenticate remote contacts.
---
 app/chat-window.cpp           | 113 +++++++++++++++++-
 app/chat-window.h             |  10 ++
 app/chatwindow.rc             |   3 +
 app/main.cpp                  |   2 +
 lib/CMakeLists.txt            |   3 +
 lib/chat-widget.cpp           |  94 ++++++++++++++-
 lib/chat-widget.h             |  20 ++++
 lib/otr-channel-interface.cpp |  43 +++++++
 lib/otr-channel-interface.h   | 262 ++++++++++++++++++++++++++++++++++++++++++
 lib/otr-constants.h           |  62 ++++++++++
 lib/otr-types.cpp             |  38 ++++++
 lib/otr-types.h               |  56 +++++++++
 lib/otr-utils.cpp             |  51 ++++++++
 lib/otr-utils.h               |  40 +++++++
 14 files changed, 795 insertions(+), 2 deletions(-)

diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index 1125496..485b09a 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -81,7 +81,8 @@ K_GLOBAL_STATIC_WITH_ARGS(KTp::ServiceAvailabilityChecker, s_krfbAvailableChecke
 ChatWindow::ChatWindow()
     : m_sendMessage(0),
       m_tabWidget(0),
-      m_keyboardLayoutInterface(0)
+      m_keyboardLayoutInterface(0),
+      otrActionMenu(0)
 {
     //This effectively constructs the s_krfbAvailableChecker object the first
     //time that this code is executed. This is to start the d-bus query early, so
@@ -135,6 +136,9 @@ ChatWindow::ChatWindow()
     // we must do it AFTER m_tabWidget is set up
     setupCustomActions();
 
+    // create otr actions for otr popup menu
+    setupOtrActions();
+
     setupGUI(QSize(460, 440), static_cast<StandardWindowOptions>(Default^StatusBar), QLatin1String("chatwindow.rc"));
 
     // Connects the toolbars iconSizeChanged to the custom toolbar item
@@ -392,6 +396,8 @@ void ChatWindow::onCurrentIndexChanged(int index)
         setShowInfoEnabled(false);
     }
 
+    onOtrStatusChanged(currentChatTab->otrStatus(), currentChatTab);
+
     // Allow "Leaving" rooms only in group chat, and when persistent rooms are enabled
     actionCollection()->action(QLatin1String("leave-chat"))->setEnabled(currentChatTab->isGroupChat() && TextChatConfig::instance()->dontLeaveGroupChats());
     // No point having "Close" action with only one tab, it behaves exactly like "Quit"
@@ -745,6 +751,8 @@ void ChatWindow::removeChatTabSignals(ChatTab *chatTab)
     disconnect(chatTab, SIGNAL(contactPresenceChanged(Tp::Presence)), this, SLOT(onTabStateChanged()));
     disconnect(chatTab->chatSearchBar(), SIGNAL(enableSearchButtonsSignal(bool)), this, SLOT(onEnableSearchActions(bool)));
     disconnect(chatTab, SIGNAL(contactBlockStatusChanged(bool)), this, SLOT(toggleBlockButton(bool)));
+    if(chatTab->otrStatus())
+        disconnect(chatTab, SIGNAL(otrStatusChanged(OtrStatus, ChatWidget*)), this, SLOT(onOtrStatusChanged(OtrStatus, ChatWidget*)));
 }
 
 void ChatWindow::sendNotificationToUser(ChatWindow::NotificationType type, const QString& errorMsg)
@@ -772,6 +780,8 @@ void ChatWindow::setupChatTabSignals(ChatTab *chatTab)
     connect(chatTab->chatSearchBar(), SIGNAL(enableSearchButtonsSignal(bool)), this, SLOT(onEnableSearchActions(bool)));
     connect(chatTab, SIGNAL(contactBlockStatusChanged(bool)), this, SLOT(toggleBlockButton(bool)));
     connect(chatTab, SIGNAL(zoomFactorChanged(qreal)), this, SLOT(onZoomFactorChanged(qreal)));
+    if(chatTab->otrStatus()) 
+        connect(chatTab, SIGNAL(otrStatusChanged(OtrStatus, ChatWidget*)), this, SLOT(onOtrStatusChanged(OtrStatus, ChatWidget*)));
 }
 
 void ChatWindow::setupCustomActions()
@@ -877,6 +887,107 @@ void ChatWindow::setupCustomActions()
     actionCollection()->addAction(QLatin1String("leave-chat"), leaveAction);
 }
 
+
+void ChatWindow::setupOtrActions() {
+
+    otrActionMenu = new KActionMenu(KIcon(QLatin1String("object-unlocked")), i18n("&OTR"), this);
+    otrActionMenu->setDelayed(false);
+    
+    KAction *startRestartOtrAction = new KAction(KIcon(QLatin1String("object-locked")), i18n("&Start session"), this);
+    startRestartOtrAction->setEnabled(false);
+    connect(startRestartOtrAction, SIGNAL(triggered()), this, SLOT(onStartRestartOtrTriggered()));
+
+    KAction *stopOtrAction = new KAction(KIcon(QLatin1String("object-unlocked")), i18n("&Stop session"), this);
+    stopOtrAction->setEnabled(false);
+    connect(stopOtrAction, SIGNAL(triggered()), this, SLOT(onStopOtrTriggered()));
+
+    KAction *authenticateBuddyAction = new KAction(KIcon(QLatin1String("application-pgp-signature")), i18n("&Authenticate contact"), this);
+    authenticateBuddyAction->setEnabled(false);
+    connect(authenticateBuddyAction, SIGNAL(triggered()), this, SLOT(onAuthenticateBuddyTriggered()));
+
+    otrActionMenu->addAction(startRestartOtrAction);
+    otrActionMenu->addAction(stopOtrAction);
+    otrActionMenu->addAction(authenticateBuddyAction);
+    otrActionMenu->setEnabled(false);
+
+    actionCollection()->addAction(QLatin1String("start-restart-otr"), startRestartOtrAction);
+    actionCollection()->addAction(QLatin1String("stop-otr"), stopOtrAction);
+    actionCollection()->addAction(QLatin1String("authenticate-otr"), authenticateBuddyAction);
+    actionCollection()->addAction(QLatin1String("otr-actions"), otrActionMenu);
+}
+
+void ChatWindow::onOtrStatusChanged(OtrStatus status, ChatWidget *chatTab) {
+
+    if(chatTab != getCurrentTab()) return;
+
+    if(!status) {
+        otrActionMenu->setEnabled(false);
+        otrActionMenu->menu()->setIcon(KIcon(QLatin1String("object-unlocked")));
+        return;
+    }
+
+    QAction* srAction = actionCollection()->action(QLatin1String("start-restart-otr"));
+    QAction* stopAction = actionCollection()->action(QLatin1String("stop-otr"));
+    QAction* authenticateBuddyAction = actionCollection()->action(QLatin1String("authenticate-otr"));
+
+    otrActionMenu->setEnabled(true);
+
+    switch(status.otrTrustLevel()) {
+
+        case Tp::OTRTrustLevelNotPrivate:
+            otrActionMenu->setIcon(KIcon(QLatin1String("object-unlocked")));
+            srAction->setEnabled(true);
+            srAction->setText(i18n("&Start session"));
+            stopAction->setEnabled(false);
+            authenticateBuddyAction->setEnabled(false);
+            return;
+
+        case Tp::OTRTrustLevelUnverified:
+            otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-unverified")));
+            srAction->setEnabled(true);
+            srAction->setText(i18n("&Restart session"));
+            stopAction->setEnabled(true);
+            authenticateBuddyAction->setEnabled(true);
+            return;
+
+        case Tp::OTRTrustLevelPrivate:
+            otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-verified")));
+            srAction->setEnabled(true);
+            srAction->setText(i18n("&Restart session"));
+            stopAction->setEnabled(true);
+            authenticateBuddyAction->setEnabled(true);
+            return;
+
+        case Tp::OTRTrustLevelFinished:
+            otrActionMenu->setIcon(KIcon(QLatin1String("object-locked-finished")));
+            srAction->setEnabled(true);
+            srAction->setText(i18n("&Restart session"));
+            stopAction->setEnabled(true);
+            authenticateBuddyAction->setEnabled(false);
+            return;
+
+        default: return;
+    }
+}
+
+void ChatWindow::onStartRestartOtrTriggered() {
+
+    ChatTab* chat = getCurrentTab();
+    chat->startOtrSession();
+}
+
+void ChatWindow::onStopOtrTriggered() {
+
+    ChatTab* chat = getCurrentTab();
+    chat->stopOtrSession();
+}
+
+void ChatWindow::onAuthenticateBuddyTriggered() {
+
+    ChatTab* chat = getCurrentTab();
+    chat->authenticateBuddy();
+}
+
 void ChatWindow::setCollaborateDocumentEnabled(bool enable)
 {
     QAction* action = actionCollection()->action(QLatin1String("collaborate-document"));
diff --git a/app/chat-window.h b/app/chat-window.h
index bfd6db5..39b447e 100644
--- a/app/chat-window.h
+++ b/app/chat-window.h
@@ -26,6 +26,7 @@
 #include <KXmlGuiWindow>
 #include <KTabWidget>
 #include <KAction>
+#include <KActionMenu>
 
 namespace Sonnet {
     class DictionaryComboBox;
@@ -117,6 +118,11 @@ private Q_SLOTS:
     void onReloadTheme();
     void onCollaborateDocumentTriggered();
     void onLeaveChannelTriggered();
+    /** otr related handlers */
+    void onOtrStatusChanged(OtrStatus status, ChatWidget *chatTab);
+    void onStartRestartOtrTriggered();
+    void onStopOtrTriggered();
+    void onAuthenticateBuddyTriggered();
 
 protected Q_SLOTS:
     void showSettingsDialog();
@@ -142,6 +148,9 @@ private:
     /** creates and adds custom actions for the chat window */
     void setupCustomActions();
 
+    /** sets up otr actions */
+    void setupOtrActions();
+
     /** setters for chat actions */
     void setAudioCallEnabled(bool enable);
     void setBlockEnabled(bool enable);
@@ -208,6 +217,7 @@ private:
     Sonnet::DictionaryComboBox *m_spellDictCombo;
     QLabel *m_accountIconLabel;
     qreal m_zoomFactor;
+    KActionMenu *otrActionMenu;
 };
 
 #endif // CHATWINDOW_H
diff --git a/app/chatwindow.rc b/app/chatwindow.rc
index 3ad0c8f..588ffbf 100644
--- a/app/chatwindow.rc
+++ b/app/chatwindow.rc
@@ -31,6 +31,7 @@
    <Separator />
    <Action name="block-contact"/>
    <Separator />
+   <Action name="otr-actions"/>
   </Menu>
   <Menu name="settings"/>
   <Menu name="help"/>
@@ -44,6 +45,8 @@
   <Action name="collaborate-document"/>
   <Separator />
   <Action name="edit_find"/>
+  <Separator />
+  <Action name="otr-actions"/>
  </ToolBar>
 
  <ToolBar hidden="true" newline="false" noEdit="true" noMerge="1" name="accountIconToolBar">
diff --git a/app/main.cpp b/app/main.cpp
index 7f50162..8da3bc5 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -17,6 +17,7 @@
 */
 
 #include "chat-window.h"
+#include "otr-types.h"
 #include "telepathy-chat-ui.h"
 
 #include "defines.h"
@@ -51,6 +52,7 @@ int main(int argc, char *argv[])
     KCmdLineArgs::init(argc, argv, &aboutData);
 
     Tp::registerTypes();
+    Tp::registerOtrTypes();
 
     Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
     channelFactory->addCommonFeatures(Tp::Channel::FeatureCore);
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 77b2a76..eee2b07 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -17,6 +17,9 @@ set(ktpchat_SRCS
         contact-delegate.cpp
         notify-filter.cpp
         text-chat-config.cpp
+        otr-types.cpp
+        otr-channel-interface.cpp
+        otr-utils.cpp
         )
 
 set(ktpchat_UI
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index a12cabf..75a970a 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -28,6 +28,7 @@
 #include "notify-filter.h"
 #include "text-chat-config.h"
 #include "contact-delegate.h"
+#include "otr-channel-interface.h"
 
 #include <QtGui/QKeyEvent>
 #include <QtGui/QAction>
@@ -45,6 +46,7 @@
 #include <KTemporaryFile>
 #include <KFileDialog>
 #include <KMessageWidget>
+#include <KMessageBox>
 
 #include <TelepathyQt/Account>
 #include <TelepathyQt/Message>
@@ -81,7 +83,8 @@ public:
         shareImageMenuAction(0),
         messageWidgetSwitchOnlineAction(0),
         logsLoaded(false),
-        exchangedMessagesCount(0)
+        exchangedMessagesCount(0),
+        otrChannel(0)
     {
     }
     /** Stores whether the channel is ready with all contacts upgraded*/
@@ -108,6 +111,8 @@ public:
     QTimer *pausedStateTimer;
     bool logsLoaded;
     uint exchangedMessagesCount;
+    OtrStatus otrStatus;
+    Tp::Client::ChannelInterfaceOTR1Interface* otrChannel;
 
     QList< Tp::OutgoingFileTransferChannelPtr > tmpFileTransfers;
 
@@ -183,6 +188,9 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
     // connect channel signals
     setupChannelSignals();
 
+    // setup new otr channel along with connecting to signals
+    setupOtrChannel();
+
     // create contactModel and start keeping track of contacts.
     d->contactModel = new ChannelContactModel(d->channel, this);
     setupContactModelSignals();
@@ -350,6 +358,9 @@ void ChatWidget::setTextChannel(const Tp::TextChannelPtr &newTextChannelPtr)
     // connect signals for the new textchannel
     setupChannelSignals();
 
+    // setup new otr channel along with connecting to signals
+    setupOtrChannel();
+
     //if the UI is ready process any messages in queue
     if (d->chatViewInitialized) {
         Q_FOREACH (const Tp::ReceivedMessage &message, d->channel->messageQueue()) {
@@ -635,6 +646,87 @@ bool ChatWidget::isOnTop() const
     return ( isActiveWindow() && isVisible() );
 }
 
+OtrStatus ChatWidget::otrStatus() const {
+    return d->otrStatus;
+}
+
+void ChatWidget::startOtrSession() {
+    if(!d->otrStatus) return;
+    d->otrChannel->Initialize();
+}
+
+void ChatWidget::stopOtrSession() {
+    if(!d->otrStatus) return;
+    d->otrChannel->Stop();
+}
+
+void ChatWidget::authenticateBuddy() {
+    if(!d->otrStatus) return;
+
+    QVariant fpReply = Tp::Utils::waitForOperation(d->otrChannel->requestPropertyRemoteFingerprint());
+    if(!fpReply.isValid()) {
+        kWarning() << "Could not get remote fingerprint for: " << d->channel->objectPath();
+        return;
+    } 
+    QDBusArgument dbusArg = fpReply.value<QDBusArgument>();
+    Tp::Fingerprint fingerprint;
+    dbusArg >> fingerprint;
+
+    QString question = QString::fromLatin1("Is the following fingerprint for the contact ") 
+        + d->contactName + QString::fromLatin1(" correct?
") + fingerprint.humanReadableFingerprint;
+
+    int askResult = KMessageBox::questionYesNoCancel(this, question);
+    switch(askResult) {
+        case KMessageBox::Yes:
+            d->otrChannel->TrustFingerprint(fingerprint.fingerprintRawData, true);
+            return;
+        case KMessageBox::No:
+            d->otrChannel->TrustFingerprint(fingerprint.fingerprintRawData, false);
+            return;
+        default:
+            return;
+    }
+}
+
+void ChatWidget::setupOtrChannel() {
+
+    QString busName = d->channel->connection()->objectPath();
+    busName = busName.replace(QChar::fromAscii('/'), QChar::fromAscii('.')).mid(1) + QString::fromLatin1(".OTR");
+
+    if(QDBusConnection::sessionBus().interface()->isServiceRegistered(busName)) {
+        d->otrChannel = new Tp::Client::ChannelInterfaceOTR1Interface(busName, d->channel->objectPath(), this);
+
+        d->otrChannel->setMonitorProperties(true);
+        connect(d->otrChannel, SIGNAL(propertiesChanged(QVariantMap, QStringList)), 
+                this, SLOT(onOtrChannelPropertiesChanged(QVariantMap, QStringList)));
+
+        QVariant reply = Tp::Utils::waitForOperation(d->otrChannel->requestPropertyTrustLevel());
+        if(reply.isValid()) {
+            Tp::OTRTrustLevel trustLevel = static_cast<Tp::OTRTrustLevel>(reply.value<int>());
+            d->otrStatus = OtrStatus(trustLevel);
+            kDebug() << "Channel: " << d->channel->objectPath() << " implements OTR";
+        } else {
+            d->otrStatus.otrImplemented = false;
+            kWarning() << "Could not get OTR status for channel: " << d->channel->objectPath();
+        }
+    } else {
+        d->otrStatus.otrImplemented = false;
+    }
+}
+
+void ChatWidget::onOtrChannelPropertiesChanged(QVariantMap props, QStringList /* ignored */) {
+
+    Q_FOREACH(const QString& key, props.keys()) {
+        if(key == QString::fromLatin1("TrustLevel")) {
+            d->otrStatus.trustLevel = static_cast<Tp::OTRTrustLevel>(props[key].toInt(0));
+            kDebug() << "Otr status changed for channel: " << d->channel->objectPath() 
+                << " to: " << (int) d->otrStatus.trustLevel;
+
+            Q_EMIT(otrStatusChanged(d->otrStatus, this));
+        }
+    }
+}
+
 void ChatWidget::handleIncomingMessage(const Tp::ReceivedMessage &message, bool alreadyNotified)
 {
     kDebug() << title() << message.text();
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index 14a35f6..6bb5868 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -22,6 +22,7 @@
 #define CHATWIDGET_H
 
 #include "ktpchat_export.h"
+#include "otr-utils.h"
 
 #include <QtCore/QString>
 #include <QtGui/QWidget>
@@ -108,6 +109,18 @@ public:
     /** Is this widget visible and in the active window */
     virtual bool isOnTop() const;
 
+    /** Starts otr session */
+    void startOtrSession();
+
+    /** Stops otr session */
+    void stopOtrSession();
+
+    /** Athenticates contact in the context of otr conversation */
+    void authenticateBuddy();
+
+    /** Returns OtrStatus linked to the channel represented by this tab */
+    OtrStatus otrStatus() const;
+
 public Q_SLOTS:
     /** toggle the search bar visibility */
     void toggleSearchBar() const;
@@ -190,6 +203,9 @@ Q_SIGNALS:
     /** Emitted when zoom level in chat view changes */
     void zoomFactorChanged(qreal zoomFactor);
 
+    /** Emitted when OTRTrustLevel changes in the channel */
+    void otrStatusChanged(OtrStatus otrStatus, ChatWidget *chatTab);
+
 private Q_SLOTS:
     /** received when user changes search criteria or when searching for text */
     void findTextInChat(const QString &text, QWebPage::FindFlags flags);
@@ -211,6 +227,7 @@ private Q_SLOTS:
     void onShareProviderFinishedSuccess(ShareProvider *provider, const QString &imageUrl);
     void onShareProviderFinishedFailure(ShareProvider *provider, const QString &errorMessage);
     void onSendFileClicked();
+    void onOtrChannelPropertiesChanged(QVariantMap props, QStringList ignored);
 
 private:
     /** connects necessary signals for the channel */
@@ -228,6 +245,9 @@ private:
     /** Loads theme into the the AdiumThemeView */
     void initChatArea();
 
+    /** connects necessary signals for the otr channel */
+    void setupOtrChannel();
+
     bool m_previousConversationAvailable;
 
     ChatWidgetPrivate * const d;
diff --git a/lib/otr-channel-interface.cpp b/lib/otr-channel-interface.cpp
new file mode 100644
index 0000000..3555b6f
--- /dev/null
+++ b/lib/otr-channel-interface.cpp
@@ -0,0 +1,43 @@
+#include <TelepathyQt/Channel>
+#include "otr-channel-interface.h"
+
+namespace Tp
+{
+namespace Client
+{
+
+ChannelInterfaceOTR1Interface::ChannelInterfaceOTR1Interface(const QString& busName, const QString& objectPath, QObject *parent)
+    : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), QDBusConnection::sessionBus(), parent)
+{
+}
+
+ChannelInterfaceOTR1Interface::ChannelInterfaceOTR1Interface(const QDBusConnection& connection, const QString& busName, const QString& objectPath, QObject *parent)
+    : Tp::AbstractInterface(busName, objectPath, staticInterfaceName(), connection, parent)
+{
+}
+
+ChannelInterfaceOTR1Interface::ChannelInterfaceOTR1Interface(Tp::DBusProxy *proxy)
+    : Tp::AbstractInterface(proxy, staticInterfaceName())
+{
+}
+
+ChannelInterfaceOTR1Interface::ChannelInterfaceOTR1Interface(const Tp::Client::ChannelInterface& mainInterface)
+    : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), mainInterface.parent())
+{
+}
+
+ChannelInterfaceOTR1Interface::ChannelInterfaceOTR1Interface(const Tp::Client::ChannelInterface& mainInterface, QObject *parent)
+    : Tp::AbstractInterface(mainInterface.service(), mainInterface.path(), staticInterfaceName(), mainInterface.connection(), parent)
+{
+}
+
+void ChannelInterfaceOTR1Interface::invalidate(Tp::DBusProxy *proxy,
+        const QString &error, const QString &message)
+{
+
+    Tp::AbstractInterface::invalidate(proxy, error, message);
+}
+
+} // namespace Client
+} // namespace Tp
+
diff --git a/lib/otr-channel-interface.h b/lib/otr-channel-interface.h
new file mode 100644
index 0000000..fff476e
--- /dev/null
+++ b/lib/otr-channel-interface.h
@@ -0,0 +1,262 @@
+#ifndef OTR_CHANNEL_INTERFACE_HEADER
+#define OTR_CHANNEL_INTERFACE_HEADER
+
+#include <TelepathyQt/Types>
+#include "otr-types.h"
+
+#include <QtGlobal>
+
+#include <QString>
+#include <QObject>
+#include <QVariant>
+
+#include <QDBusPendingReply>
+
+#include <TelepathyQt/AbstractInterface>
+#include <TelepathyQt/DBusProxy>
+#include <TelepathyQt/Global>
+
+namespace Tp
+{
+namespace Client
+{
+
+/**
+ * 
-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list