[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:21:03 UTC 2016


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

The following commit has been merged in the master branch:
commit b5e2922c1436b6dc214d024d31ed36ed01b3b824
Author: Lasath Fernando <kde at lasath.org>
Date:   Thu Feb 2 09:58:23 2012 +1100

    Add missing file: filters.h
    
    filters.h currently contains UrlFilter, which just contains all the
    code that was previously in AdiumThemeView::replaceMessageKeywords().
---
 lib/filters.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/lib/filters.h b/lib/filters.h
new file mode 100644
index 0000000..b3976ee
--- /dev/null
+++ b/lib/filters.h
@@ -0,0 +1,79 @@
+
+#include <QImageReader>
+
+#include <KProtocolInfo>
+#include <KDebug>
+
+#include "message-processor.h"
+
+class UrlFilter : public AbstractMessageFilter
+{
+    virtual void filterMessage(KTp::Message &info) {
+        QString message = info.mainMessagePart();
+
+        // link detection
+        QRegExp linkRegExp(QLatin1String("\b(?:(\w+)://|(www\.))([^\s]+)"));
+        int index = 0;
+
+        while ((index = linkRegExp.indexIn(message, 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 = linkRegExp.cap(1).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(QLatin1String("(<|>)"));
+
+                if (!realUrl.contains(unwanted)) {
+                    // string to show to user
+                    QString shownUrl = realUrl;
+
+                    // check for newline and cut link when found
+                    if (realUrl.contains(QLatin1String(("<br/>")))) {
+                        int findIndex = realUrl.indexOf(QLatin1String("<br/>"));
+                        realUrl.truncate(findIndex);
+                        shownUrl.truncate(findIndex);
+                    }
+
+                    // check prefix
+                    if (startsWithWWW) {
+                        realUrl.prepend(QLatin1String("http://"));
+                    }
+
+                    // if the url is changed, show in chat what the user typed in
+                    QString link = QLatin1String("<a href='") + realUrl + QLatin1String("'>") + shownUrl + QLatin1String("</a>");
+
+                    //if the link is of a supported image type, embedd it in the chat
+                    QRegExp fileExtension(QLatin1String("\.(\w+)$"), Qt::CaseInsensitive);
+                    if(fileExtension.indexIn(realUrl) != -1) {
+                        QString extension = fileExtension.cap(1);
+                        bool supported = false;
+                        Q_FOREACH(QByteArray format, QImageReader::supportedImageFormats()) {
+                            supported |= !(QString::compare(extension, QString::fromAscii(format), Qt::CaseInsensitive));
+                        }
+                        kDebug() << "link is supported image type ?:" << supported;
+                        if(supported) {
+                            link.append(QLatin1String("<br/><img src='") + realUrl + QLatin1String("' style='width:100%;' alt='(link is of an image)'/>"));
+                        }
+                    }
+                    message.replace(index, shownUrl.length(), link);
+                    // advance position otherwise I end up parsing the same link
+                    index += link.length();
+                } else {
+                    index += realUrl.length();
+                }
+            } else {
+                index += linkRegExp.matchedLength();
+            }
+        }
+
+        info.setMainMessagePart(message);
+    }
+};
\ No newline at end of file

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list