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


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

The following commit has been merged in the master branch:
commit 6cfbdd78356dcfa286760f39eab8242eca4c8ab8
Author: Lasath Fernando <kde at lasath.org>
Date:   Thu Feb 2 12:32:49 2012 +1100

    Move definition of UrlFilter::filterMessage() url-filter.cpp
---
 lib/filters.h                     | 75 ++-------------------------------------
 lib/{filters.h => url-filter.cpp} | 48 ++++++++++---------------
 2 files changed, 20 insertions(+), 103 deletions(-)

diff --git a/lib/filters.h b/lib/filters.h
index 8824e01..2fe9650 100644
--- a/lib/filters.h
+++ b/lib/filters.h
@@ -1,79 +1,8 @@
 
-#include <QImageReader>
-
-#include <KProtocolInfo>
-#include <KDebug>
-
 #include "message-processor.h"
 
 class UrlFilter : public AbstractMessageFilter
 {
-    virtual void filterMessage(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);
-    }
+    virtual void filterMessage(Message& message);
 };
+
diff --git a/lib/filters.h b/lib/url-filter.cpp
similarity index 51%
copy from lib/filters.h
copy to lib/url-filter.cpp
index 8824e01..6c9360d 100644
--- a/lib/filters.h
+++ b/lib/url-filter.cpp
@@ -1,26 +1,25 @@
+#include "filters.h"
 
 #include <QImageReader>
 
 #include <KProtocolInfo>
 #include <KDebug>
 
-#include "message-processor.h"
-
-class UrlFilter : public AbstractMessageFilter
-{
-    virtual void filterMessage(Message &info) {
+virtual void UrlFilter::filterMessage(Message &info) {
         QString message = info.mainMessagePart();
+        //FIXME: make "Urls" into a constant
+        QStringList urls = info.property("Urls");
 
         // link detection
-        QRegExp linkRegExp(QLatin1String("\b(?:(\w+)://|(www\.))([^\s]+)"));
-        int index = 0;
+        QRegExp link(QLatin1String("\b(?:(\w+)://|(www\.))([^\s]+)"));
+        int fromIndex = 0;
 
-        while ((index = linkRegExp.indexIn(message, index)) != -1) {
-            QString realUrl = linkRegExp.cap(0);
-            QString protocol = linkRegExp.cap(1);
+        while ((fromIndex = message.indexOf(link, fromIndex)) != -1) {
+            QString realUrl = link.cap(0);
+            QString protocol = link.cap(1);
 
             //if cap(1) is empty cap(2) was matched -> starts with www.
-            const bool startsWithWWW = linkRegExp.cap(1).isEmpty();
+            const bool startsWithWWW = link.cap(1).isEmpty();
 
             kDebug() << "Found URL " << realUrl << "with protocol : " << (startsWithWWW ? QLatin1String("http") : protocol);
 
@@ -50,30 +49,19 @@ class UrlFilter : public AbstractMessageFilter
                     // 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);
+                    message.replace(fromIndex, shownUrl.length(), link);
                     // advance position otherwise I end up parsing the same link
-                    index += link.length();
+                    fromIndex += link.length();
                 } else {
-                    index += realUrl.length();
+                    fromIndex += realUrl.length();
                 }
+
+                urls.append(realUrl);
             } else {
-                index += linkRegExp.matchedLength();
+                fromIndex += link.matchedLength();
             }
         }
 
+        info.setProperty("Urls", urls);
         info.setMainMessagePart(message);
-    }
-};
+    }
\ No newline at end of file

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list