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

List:       kde-commits
Subject:    =?utf-8?q?=5Btelepathy-chat-handler=5D_lib=3A_Fix_bug_270345_=3A?=
From:       Francesco Nwokeka <francesco.nwokeka () gmail ! com>
Date:       2011-04-11 12:47:06
Message-ID: 20110411124706.3C80CA609B () git ! kde ! org
[Download RAW message or body]

Git commit a2ccf85e6cb3be91f8033c9f3b93235910c545f2 by Francesco Nwokeka.
Committed on 11/04/2011 at 14:51.
Pushed by nwokeka into branch 'master'.

Fix bug 270345 : URL parser recognizes addresses starting with http:// or https:// only

now smb, ftp links are detected as well

BUG: 270345
REVIEW: David Edmundson

M  +14   -2    lib/adium-theme-view.cpp     

http://commits.kde.org/telepathy-chat-handler/a2ccf85e6cb3be91f8033c9f3b93235910c545f2

diff --git a/lib/adium-theme-view.cpp b/lib/adium-theme-view.cpp
index 3cd889f..6c78889 100644
--- a/lib/adium-theme-view.cpp
+++ b/lib/adium-theme-view.cpp
@@ -361,11 +361,23 @@ QString AdiumThemeView::replaceMessageKeywords(QString &htmlTemplate, const Adiu
     //message
     htmlTemplate.replace("%message%", m_emoticons.theme().parseEmoticons(info.message()));
 
-    QRegExp linkRegExp("https{0,1}://[^ \t\n\r\f\v]+");
+    // link detection
+    QRegExp linkRegExp("(smb://|s{0,1}ftp://|www.|https{0,1}://)[^ \t\n\r\f\v]+");
     int index = 0;
     while((index = linkRegExp.indexIn(htmlTemplate, index)) != -1) {
-        QString link = "<a href='" + linkRegExp.cap(0) + "'>" + linkRegExp.cap(0) + "</a>";
+        QString realUrl = linkRegExp.cap(0);
+
+        // remove line breaks
+        realUrl.remove("<br/>");
+
+        if (realUrl.startsWith("www")) {
+            realUrl.prepend("http://");
+        }
+
+        // if the url is changed, show in chat what the user typed in
+        QString link = "<a href='" + realUrl + "'>" + linkRegExp.cap(0) + "</a>";
         htmlTemplate.replace(index, linkRegExp.cap(0).length(), link);
+
         // advance pos otherwise i end up parsing same link
         index += link.length();
     }

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

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