Skip to content

Commit 803b23c

Browse files
committed
[UI][Common] Wrap torrent comment and tracker status URLs in HTML (clickable)
1 parent f101f0a commit 803b23c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

deluge/common.py

+10
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,16 @@ def parse_human_size(size):
720720
raise InvalidSize(msg % (size, tokens))
721721

722722

723+
def anchorify_urls(text: str) -> str:
724+
"""
725+
Wrap all occurrences of text URLs with HTML
726+
"""
727+
url_pattern = r'((htt)|(ft)|(ud))ps?://\S+'
728+
html_href_pattern = r'<a href="\g<0>">\g<0></a>'
729+
730+
return re.sub(url_pattern, html_href_pattern, text)
731+
732+
723733
def is_url(url):
724734
"""
725735
A simple test to check if the URL is valid

deluge/ui/gtk3/details_tab.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from xml.sax.saxutils import escape as xml_escape
1111

1212
import deluge.component as component
13-
from deluge.common import decode_bytes, fdate, fsize, is_url
13+
from deluge.common import decode_bytes, fdate, fsize, anchorify_urls
1414

1515
from .tab_data_funcs import fdate_or_dash, fpieces_num_size
1616
from .torrentdetails import Tab
@@ -61,8 +61,8 @@ def _on_get_torrent_status(self, status):
6161
for widget in self.tab_widgets.values():
6262
txt = xml_escape(self.widget_status_as_fstr(widget, status))
6363
if decode_bytes(widget.obj.get_text()) != txt:
64-
if 'comment' in widget.status_keys and is_url(txt):
65-
widget.obj.set_markup(f'<a href="{txt}">{txt}</a>')
64+
if 'comment' in widget.status_keys:
65+
widget.obj.set_markup(anchorify_urls(txt))
6666
else:
6767
widget.obj.set_markup(txt)
6868

deluge/ui/gtk3/trackers_tab.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging
1010

1111
import deluge.component as component
12-
from deluge.common import ftime
12+
from deluge.common import ftime, anchorify_urls
1313

1414
from .tab_data_funcs import fcount, ftranslate, fyes_no
1515
from .torrentdetails import Tab
@@ -54,7 +54,10 @@ def _on_get_torrent_status(self, status):
5454
for widget in self.tab_widgets.values():
5555
txt = self.widget_status_as_fstr(widget, status)
5656
if widget.obj.get_text() != txt:
57-
widget.obj.set_text(txt)
57+
if 'tracker_status' in widget.status_keys:
58+
widget.obj.set_markup(anchorify_urls(txt))
59+
else:
60+
widget.obj.set_text(txt)
5861

5962
def clear(self):
6063
for widget in self.tab_widgets.values():

0 commit comments

Comments
 (0)