From 8c9259947084d6e77a74d8eeb1504fe7cbd7626f Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Mon, 18 Nov 2024 13:22:20 +0900 Subject: [PATCH] Format url links in event descriptions making them clickable This allows to click through links in events in description fields wherever the description field is displayed from libkcal. This is useful since links to virtual meetings are often attached in the description field in recent years Signed-off-by: Calvin Morrison Signed-off-by: Michele Calgaro --- libkcal/incidenceformatter.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libkcal/incidenceformatter.cpp b/libkcal/incidenceformatter.cpp index 785a681b..887d000a 100644 --- a/libkcal/incidenceformatter.cpp +++ b/libkcal/incidenceformatter.cpp @@ -575,9 +575,22 @@ static TQString displayViewFormatEvent( Calendar *calendar, Event *event, } if ( !event->description().isEmpty() ) { + TQString description = event->description(); + + // Regular expression to match URLs + TQRegExp urlRegex("https?://[^\\s]+"); + + int pos = 0; + while ((pos = urlRegex.search(description, pos)) != -1) { + TQString url = urlRegex.cap(0); + TQString link = "" + url + ""; + description.replace(pos, url.length(), link); + pos += link.length(); + } + tmpStr += ""; tmpStr += "" + i18n( "Description:" ) + ""; - tmpStr += "" + event->description() + ""; + tmpStr += "" + description + ""; tmpStr += ""; }