Commit 629f07c4 authored by Philipp Hörist's avatar Philipp Hörist

Refactor making href pango markup

parent 25828b1c
......@@ -68,6 +68,7 @@ from gajim.gtk.util import format_activity
from gajim.gtk.util import format_tune
from gajim.gtk.util import format_location
from gajim.gtk.util import get_activity_icon_name
from gajim.gtk.util import make_href_markup
from gajim.command_system.implementation.hosts import ChatCommands
from gajim.command_system.framework import CommandHost # pylint: disable=unused-import
......@@ -760,7 +761,7 @@ class ChatControl(ChatControlBase):
label_tooltip = '%s%s' % (name, acct_info)
if status_escaped:
status_text = self.urlfinder.sub(self.make_href, status_escaped)
status_text = make_href_markup(status_escaped)
status_text = '<span size="x-small" weight="light">%s</span>' % status_text
self.banner_status_label.set_tooltip_text(status)
self.banner_status_label.set_no_show_all(False)
......
......@@ -24,7 +24,6 @@
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import time
from tempfile import TemporaryDirectory
......@@ -42,7 +41,6 @@ from gajim.common.i18n import _
from gajim.common.helpers import AdditionalDataDict
from gajim.common.contacts import GC_Contact
from gajim.common.connection_handlers_events import MessageOutgoingEvent
from gajim.common.const import StyleAttr
from gajim.common.const import Chatstate
from gajim import gtkgui_helpers
......@@ -56,7 +54,6 @@ from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import NewConfirmationCheckDialog
from gajim.gtk import util
from gajim.gtk.util import convert_rgb_to_hex
from gajim.gtk.util import at_the_end
from gajim.gtk.util import get_show_in_roster
from gajim.gtk.util import get_show_in_systray
......@@ -93,15 +90,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# Multiple hardware keycodes can trigger a keyval like Gdk.KEY_c.
keycodes_c = get_hardware_key_codes(Gdk.KEY_c)
def make_href(self, match):
url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
color = convert_rgb_to_hex(url_color)
url = match.group()
if '://' not in url:
url = 'https://' + url
return '<a href="%s"><span foreground="%s">%s</span></a>' % (
url, color, match.group())
def get_nb_unread(self):
jid = self.contact.jid
if self.resource:
......@@ -234,9 +222,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self._on_banner_eventbox_button_press_event)
self.handlers[id_] = widget
self.urlfinder = re.compile(
r"(www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'\"]+[^!,\.\s<>\)'\"\]]")
self.banner_status_label = self.xml.get_object('banner_label')
if self.banner_status_label is not None:
id_ = self.banner_status_label.connect('populate_popup',
......
......@@ -85,6 +85,9 @@ log = logging.getLogger('gajim.c.helpers')
special_groups = (_('Transports'), _('Not in contact list'), _('Observers'), _('Group chats'))
URL_REGEX = re.compile(
r"(www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'\"]+[^!,\.\s<>\)'\"\]]")
class InvalidFormat(Exception):
pass
......
......@@ -88,6 +88,7 @@ from gajim.gtk.util import NickCompletionGenerator
from gajim.gtk.util import get_icon_name
from gajim.gtk.util import get_affiliation_surface
from gajim.gtk.util import get_builder
from gajim.gtk.util import make_href_markup
log = logging.getLogger('gajim.groupchat_control')
......@@ -1118,7 +1119,7 @@ class GroupchatControl(ChatControlBase):
if self.subject:
subject = GLib.markup_escape_text(self.subject)
subject_text = self.urlfinder.sub(self.make_href, subject)
subject_text = make_href_markup(subject)
self.subject_button.get_popover().set_text(subject_text)
def _nec_update_avatar(self, obj):
......
......@@ -45,10 +45,12 @@ from gajim.common import app
from gajim.common import configpaths
from gajim.common import i18n
from gajim.common.i18n import _
from gajim.common.helpers import URL_REGEX
from gajim.common.const import MOODS
from gajim.common.const import ACTIVITIES
from gajim.common.const import LOCATION_DATA
from gajim.common.const import Display
from gajim.common.const import StyleAttr
from gajim.gtk.const import GajimIconSet
......@@ -698,3 +700,17 @@ def load_pixbuf(path, size=None):
height,
GdkPixbuf.InterpType.BILINEAR)
return pixbuf
def make_href_markup(string):
url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
color = convert_rgb_to_hex(url_color)
def _to_href(match):
url = match.group()
if '://' not in url:
url = 'https://' + url
return '<a href="%s"><span foreground="%s">%s</span></a>' % (
url, color, match.group())
return URL_REGEX.sub(_to_href, string)
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