|
5 | 5 | import locale |
6 | 6 | import gettext |
7 | 7 | import functools |
| 8 | +import html |
8 | 9 | import logging |
9 | 10 | import time |
10 | 11 | import math |
@@ -187,29 +188,30 @@ def refresh_status_widgets(self): |
187 | 188 | self.op_transfer_problem_label.set_text(_("Some files not found")) |
188 | 189 | elif self.op.status == OpStatus.FINISHED: |
189 | 190 | if isinstance(self.op, TextMessageOp): |
190 | | - label_length = 80 |
191 | | - lines_left = 4 |
| 191 | + label = "" |
192 | 192 | lines = self.op.message.split("\n") |
193 | | - msg = "" |
194 | | - for l in lines: |
195 | | - wrapped_lines = math.ceil(len(l) / label_length) |
196 | | - if wrapped_lines > lines_left: |
197 | | - msg += "\n" + l[:label_length*lines_left-3] + "..." |
| 193 | + for i in range(len(lines)): |
| 194 | + print(i, len(lines)) |
| 195 | + label += f"{lines[i]}" |
| 196 | + if i == 3 and len(lines) > 4: |
| 197 | + label += "..." |
198 | 198 | break |
199 | 199 | else: |
200 | | - msg += "\n" + l |
201 | | - lines_left -= wrapped_lines |
202 | | - if lines_left < 1: |
203 | | - last_line_len = len(l) % label_length |
204 | | - if last_line_len == 0 and len(l) > 0: |
205 | | - last_line_len = label_length |
206 | | - if len(lines) > 4: |
207 | | - if last_line_len > label_length-3: |
208 | | - msg = msg[:-last_line_len+label_length-3] |
209 | | - msg += "..." |
210 | | - break |
211 | | - msg = msg[1:] # skip first \n |
212 | | - self.op_transfer_text_message.set_text(msg) |
| 200 | + if i + 1 < len(lines): |
| 201 | + label += "\n" |
| 202 | + |
| 203 | + label = html.escape(label) |
| 204 | + url_pattern = r'(https?://[^\s<>"{}|\\^`\[\]]+|www\.[^\s<>"{}|\\^`\[\]]+)' |
| 205 | + def replace_url(match): |
| 206 | + url = match.group(0) |
| 207 | + # If URL doesn't start with http, add https:// |
| 208 | + href = url if url.startswith('http') else f'https://{url}' |
| 209 | + return f'<a href="{href}">{url}</a>' |
| 210 | + |
| 211 | + # Replace URLs with Pango markup |
| 212 | + markup = re.sub(url_pattern, replace_url, label) |
| 213 | + |
| 214 | + self.op_transfer_text_message.set_markup(markup) |
213 | 215 | else: |
214 | 216 | self.op_transfer_status_message.set_text(_("Completed")) |
215 | 217 | elif self.op.status == OpStatus.FINISHED_WARNING: |
|
0 commit comments