[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91

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


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

The following commit has been merged in the master branch:
commit 508333a0c81f78dcedeff1004c2df7608bb8cbaa
Author: Francesco Nwokeka <francesco.nwokeka at gmail.com>
Date:   Mon Sep 12 23:18:35 2011 +0200

    Add sub menu to contact context menu to navigate directly to links in the contact presence message
    
    This patch adds a context menu in the contact custom menu you get when right clicking a contact ONLY if the contact's
    presence message contains links, otherwise no submenu is added.
    
    REVIEW: 102568
    Reviewed by: Martin Klapetek
---
 main-widget.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 main-widget.h   |  8 +++---
 2 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/main-widget.cpp b/main-widget.cpp
index dd7e24b..51266ee 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -47,12 +47,14 @@
 #include <KUser>
 #include <KMenu>
 #include <KMessageBox>
+#include <KProtocolInfo>
 #include <KSettings/Dialog>
 #include <KSharedConfig>
 #include <KFileDialog>
 #include <KInputDialog>
 #include <KStandardShortcut>
 #include <KNotification>
+#include <KToolInvocation>
 
 #include "ui_main-widget.h"
 #include "account-button.h"
@@ -819,6 +821,22 @@ KMenu* MainWidget::contactContextMenu(const QModelIndex &index)
         action->setEnabled(true);
     }
 
+    // add "goto" submenu for navigating to links the contact has in presence message
+    // first check to see if there are any links in the contact's presence message
+    QStringList contactLinks = extractLinksFromIndex(index);
+
+    if (!contactLinks.empty()) {
+        KMenu *subMenu = new KMenu(i18np("Presence message link", "Presence message links", contactLinks.count()));
+
+        foreach(const QString &link, contactLinks) {
+            action = subMenu->addAction(link);
+            action->setData(link);
+        }
+        connect(subMenu, SIGNAL(triggered(QAction*)), this, SLOT(onOpenLinkTriggered(QAction*)));
+        menu->addMenu(subMenu);
+    }
+
+
     menu->addSeparator();
 
     // remove contact action
@@ -1059,6 +1077,11 @@ void MainWidget::onGenericOperationFinished(Tp::PendingOperation* operation)
     }
 }
 
+void MainWidget::onOpenLinkTriggered(QAction *action)
+{
+    KToolInvocation::invokeBrowser(action->data().toString());
+}
+
 void MainWidget::onShowInfoTriggered()
 {
     QModelIndex index = m_contactsListView->currentIndex();
@@ -1208,6 +1231,59 @@ void MainWidget::onPresencePublicationRequested(const Tp::Contacts& contacts)
     }
 }
 
+QStringList MainWidget::extractLinksFromIndex(const QModelIndex& index)
+{
+    QStringList links;
+    QString presenceMsg = index.data(AccountsModel::PresenceMessageRole).toString();
+
+    if (presenceMsg.isEmpty()) {
+        return links;
+    } else {
+        // link detection taken from chatHandler adium-theme-view.cpp
+        QRegExp linkRegExp("\b(?:(\w+)://|(www\.))([^\s]+)");
+        int index = 0;
+
+        while ((index = linkRegExp.indexIn(presenceMsg, index)) != -1) {
+            QString realUrl = linkRegExp.cap(0);
+            QString protocol = linkRegExp.cap(1);
+
+            //if cap(1) is empty cap(2) was matched -> starts with www.
+            const bool startsWithWWW = protocol.isEmpty();
+
+            kDebug() << "Found URL " << realUrl << "with protocol : " << (startsWithWWW ? QLatin1String("http") : protocol);
+
+            // if url has a supported protocol
+            if (startsWithWWW || KProtocolInfo::protocols().contains(protocol, Qt::CaseInsensitive)) {
+
+                // text not wanted in a link ( <,> )
+                QRegExp unwanted("(<|>)");
+
+                if (!realUrl.contains(unwanted)) {
+                    // check for newline and cut link when found
+                    if (realUrl.contains("<br/>")) {
+                        int findIndex = realUrl.indexOf("<br/>");
+                        realUrl.truncate(findIndex);
+                    }
+
+                    // check prefix
+                    if (startsWithWWW) {
+                        realUrl.prepend("http://");
+                    }
+
+                    // add to links list
+                    links.push_back(realUrl);
+
+                    // advance position otherwise I end up parsing the same link
+                    index += realUrl.length();
+                }
+            } else {
+                index += linkRegExp.matchedLength();
+            }
+        }
+    }
+    return links;
+}
+
 void MainWidget::handleConnectionError(const Tp::AccountPtr& account)
 {
     QString connectionError = account->connectionError();
diff --git a/main-widget.h b/main-widget.h
index 34a41d9..608e968 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -119,8 +119,8 @@ private Q_SLOTS:
     void onSwitchToFullView();
     void onSwitchToCompactView();
 
-    void onGenericOperationFinished(Tp::PendingOperation *operation); /** called when a Tp::PendingOperation finishes. Used to check for errors */
-
+    void onGenericOperationFinished(Tp::PendingOperation *operation);   /** called when a Tp::PendingOperation finishes. Used to check for errors */
+    void onOpenLinkTriggered(QAction *action);                          /** triggered from custom contact menu when user clicks contact link */
     void groupContacts(bool enabled);
     void monitorPresence(const Tp::ConnectionPtr &connection);
 
@@ -128,8 +128,8 @@ Q_SIGNALS:
     void enableOverlays(bool);
 
 private:
-    /** handle connection errors for given account. This method provides visual notification */
-    void handleConnectionError(const Tp::AccountPtr &account);
+    QStringList extractLinksFromIndex(const QModelIndex &index);    /** extract links from a QModelIndex pointing to a contact */
+    void handleConnectionError(const Tp::AccountPtr &account);      /** handle connection errors for given account. This method provides visual notification */
     void closeEvent(QCloseEvent *e);
 
     KMenu* contactContextMenu(const QModelIndex &index);

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list