Allow clicking of links in app descriptions

Prior to this patch, links found in KNewStuff content
descriptions were ignored and both unclickable and
unselectable. With this patch, clicking a link will
launch the default browser pointed at that link.
Currently this is limited to KNS content, but it would
be reasonably trivial to add to other content types as
well, but thought it would be best to discuss on one
type before doing them all at once.

This patch further fixes a minor oversight in the
BBCode neutraliser in the KNS backend (which would
previously eat chunks it was not supposed to, such
as parts of URLs).

BUG: 401176
Differential Revision: https://phabricator.kde.org/D17050
parent 990e8211
......@@ -157,6 +157,15 @@ DiscoverPage {
Layout.fillWidth: true
wrapMode: Text.WordWrap
text: appInfo.application.longDescription
onLinkActivated: Qt.openUrlExternally(link);
// Since Text (and Label) lack cursor-changing abilities of their own,
// as suggested by QTBUG-30804, use a MouseAra to do our dirty work.
// See comment https://bugreports.qt.io/browse/QTBUG-30804?#comment-206287
MouseArea {
anchors.fill: parent
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
acceptedButtons: Qt.NoButton // Not actually accepting clicks, just changing the cursor
}
}
Kirigami.Heading {
......
......@@ -79,7 +79,7 @@ QString KNSResource::comment()
if(newLine>0) {
ret=ret.left(newLine);
}
ret = ret.replace(QRegularExpression(QStringLiteral("\\[/?[a-z]*\\]")), QString());
ret = ret.replace(QRegularExpression(QStringLiteral("\\[\\/?[a-z]*\\]")), QString());
ret = ret.remove(QRegularExpression(QStringLiteral("<[^>]*>")));
}
return ret;
......@@ -97,7 +97,12 @@ QString KNSResource::longDescription()
}
ret = ret.replace(QLatin1Char('\r'), QString());
ret = ret.replace(QStringLiteral("[li]"), QStringLiteral("\n* "));
ret = ret.replace(QRegularExpression(QStringLiteral("\\[/?[a-z]*\\]")), QString());
// Get rid of all BBCode markup we don't handle above
ret = ret.replace(QRegularExpression(QStringLiteral("\\[\\/?[a-z]*\\]")), QString());
// Find anything that looks like a link (but which also is not some html
// tag value or another already) and make it a link
static const QRegularExpression urlRegExp(QStringLiteral("(^|\\s)([-a-zA-Z0-9@:%_\\+.~#?&//=]{2,256}\\.[a-z]{2,4}\\b(\\/[-a-zA-Z0-9@:;%_\\+.~#?&//=]*)?)"), QRegularExpression::CaseInsensitiveOption);
ret = ret.replace(urlRegExp, QStringLiteral("<a href=\"\\2\">\\2</a>"));
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment