diff options
author | zakary <zak@ary.dev> | 2024-08-26 10:34:27 +0200 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2024-09-08 10:45:14 +0200 |
commit | 3bceb4bfc1f89d76004a1be50d3d864bd42215e1 (patch) | |
tree | 5a30a528b86fe6b1a013a7fac93d3b836e2fa872 | |
parent | [Tests] Fix missing __qualname__ for mock callback (diff) | |
download | deluge-3bceb4bfc1f89d76004a1be50d3d864bd42215e1.tar.xz deluge-3bceb4bfc1f89d76004a1be50d3d864bd42215e1.zip |
[UI][Common] Wrap torrent comment and tracker status URLs in HTML (clickable)
Closes: https://github.com/deluge-torrent/deluge/pull/460
-rw-r--r-- | deluge/common.py | 10 | ||||
-rw-r--r-- | deluge/ui/gtk3/details_tab.py | 6 | ||||
-rw-r--r-- | deluge/ui/gtk3/trackers_tab.py | 7 |
3 files changed, 18 insertions, 5 deletions
diff --git a/deluge/common.py b/deluge/common.py index be655447f..256f1f783 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -720,6 +720,16 @@ def parse_human_size(size): raise InvalidSize(msg % (size, tokens)) +def anchorify_urls(text: str) -> str: + """ + Wrap all occurrences of text URLs with HTML + """ + url_pattern = r'((htt)|(ft)|(ud))ps?://\S+' + html_href_pattern = r'<a href="\g<0>">\g<0></a>' + + return re.sub(url_pattern, html_href_pattern, text) + + def is_url(url): """ A simple test to check if the URL is valid diff --git a/deluge/ui/gtk3/details_tab.py b/deluge/ui/gtk3/details_tab.py index 04a5eabfe..95b4ab8e3 100644 --- a/deluge/ui/gtk3/details_tab.py +++ b/deluge/ui/gtk3/details_tab.py @@ -10,7 +10,7 @@ import logging from xml.sax.saxutils import escape as xml_escape import deluge.component as component -from deluge.common import decode_bytes, fdate, fsize, is_url +from deluge.common import anchorify_urls, decode_bytes, fdate, fsize from .tab_data_funcs import fdate_or_dash, fpieces_num_size from .torrentdetails import Tab @@ -61,8 +61,8 @@ class DetailsTab(Tab): for widget in self.tab_widgets.values(): txt = xml_escape(self.widget_status_as_fstr(widget, status)) if decode_bytes(widget.obj.get_text()) != txt: - if 'comment' in widget.status_keys and is_url(txt): - widget.obj.set_markup(f'<a href="{txt}">{txt}</a>') + if 'comment' in widget.status_keys: + widget.obj.set_markup(anchorify_urls(txt)) else: widget.obj.set_markup(txt) diff --git a/deluge/ui/gtk3/trackers_tab.py b/deluge/ui/gtk3/trackers_tab.py index d671471b0..5fad631e4 100644 --- a/deluge/ui/gtk3/trackers_tab.py +++ b/deluge/ui/gtk3/trackers_tab.py @@ -9,7 +9,7 @@ import logging import deluge.component as component -from deluge.common import ftime +from deluge.common import anchorify_urls, ftime from .tab_data_funcs import fcount, ftranslate, fyes_no from .torrentdetails import Tab @@ -54,7 +54,10 @@ class TrackersTab(Tab): for widget in self.tab_widgets.values(): txt = self.widget_status_as_fstr(widget, status) if widget.obj.get_text() != txt: - widget.obj.set_text(txt) + if 'tracker_status' in widget.status_keys: + widget.obj.set_markup(anchorify_urls(txt)) + else: + widget.obj.set_text(txt) def clear(self): for widget in self.tab_widgets.values(): |