[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_Better_link_detect?=
From: Francesco Nwokeka <francesco.nwokeka () gmail ! com>
Date: 2011-04-27 9:18:56
Message-ID: 20110427091856.89112A60A4 () git ! kde ! org
[Download RAW message or body]
Git commit fb33764f3cb678be1364b97e2f3a00f646fa9d8e by Francesco Nwokeka.
Committed on 27/04/2011 at 11:17.
Pushed by nwokeka into branch 'master'.
Better link detection for bug 270345
REVIEW: david edmundson
M +28 -12 lib/adium-theme-view.cpp
http://commits.kde.org/telepathy-chat-handler/fb33764f3cb678be1364b97e2f3a00f646fa9d8e
diff --git a/lib/adium-theme-view.cpp b/lib/adium-theme-view.cpp
index 8a8818c..2211cfa 100644
--- a/lib/adium-theme-view.cpp
+++ b/lib/adium-theme-view.cpp
@@ -362,24 +362,40 @@ QString AdiumThemeView::replaceMessageKeywords(QString &htmlTemplate, const Adiu
htmlTemplate.replace("%message%", m_emoticons.theme().parseEmoticons(info.message()));
// link detection
- QRegExp linkRegExp("(smb://|s{0,1}ftp://|www.|https{0,1}://)[^ \t\n\r\f\v]+");
+ QRegExp linkRegExp("\\b(smb://|s{0,1}ftp://|www\\.|https{0,1}://)\\b[^ \t\n\r\f\v]+");
int index = 0;
- while((index = linkRegExp.indexIn(htmlTemplate, index)) != -1) {
+
+ while ((index = linkRegExp.indexIn(htmlTemplate, index)) != -1) {
QString realUrl = linkRegExp.cap(0);
- // remove line breaks
- realUrl.remove("<br/>");
+ // text not wanted in a link ( <,> )
+ QRegExp unwanted("(<|>)");
- if (realUrl.startsWith("www")) {
- realUrl.prepend("http://");
- }
+ if (!realUrl.contains(unwanted)) {
+ // string to show to user
+ QString shownUrl = realUrl;
+
+ // check for newline and cut link when found
+ if (realUrl.contains("<br/>")) {
+ int findIndex = realUrl.indexOf("<br/>");
+ realUrl.truncate(findIndex);
+ shownUrl.truncate(findIndex);
+ }
- // 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);
+ // check prefix
+ if (realUrl.startsWith("www")) {
+ realUrl.prepend("http://");
+ }
- // advance pos otherwise i end up parsing same link
- index += link.length();
+ // if the url is changed, show in chat what the user typed in
+ QString link = "<a href='" + realUrl + "'>" + shownUrl + "</a>";
+ htmlTemplate.replace(index, shownUrl.length(), link);
+
+ // advance position otherwise I end up parsing the same link
+ index += link.length();
+ } else {
+ index += realUrl.length();
+ }
}
//service
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic