From 688fb669798e9ddc91948ab8655a4ee0f7766848 Mon Sep 17 00:00:00 2001
From: Nikos Kouremenos <kourem@gmail.com>
Date: Thu, 21 Jul 2005 21:39:47 +0000
Subject: [PATCH] gtkgui_helpers have func to escape pango markup

---
 src/check_for_new_version.py |  2 +-
 src/common/logger.py         |  1 +
 src/dialogs.py               | 20 +++++++++-----------
 src/gtkgui.glade             |  4 ++--
 src/gtkgui_helpers.py        | 28 ++++++++++++++++++++++++++++
 src/tabbed_chat_window.py    |  3 +--
 6 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/src/check_for_new_version.py b/src/check_for_new_version.py
index 3128a75f9e..82710c976d 100644
--- a/src/check_for_new_version.py
+++ b/src/check_for_new_version.py
@@ -1,4 +1,4 @@
-##	common/check_for_new_version.py
+##	check_for_new_version.py
 ##
 ## Gajim Team:
 ## - Yann Le Boulanger <asterix@lagaule.org>
diff --git a/src/common/logger.py b/src/common/logger.py
index c56843c24a..a867fefb2a 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -62,6 +62,7 @@ def write(self, kind, msg, jid, show = None, tim = None):
 
 		if not msg:
 			msg = ''
+
 		msg = helpers.to_one_line(msg)
 		if len(jid.split('/')) > 1:
 			ji, nick = jid.split('/', 1)
diff --git a/src/dialogs.py b/src/dialogs.py
index 89488dac56..a8a2f7d018 100644
--- a/src/dialogs.py
+++ b/src/dialogs.py
@@ -22,6 +22,8 @@
 import gobject
 import os
 
+import gtkgui_helpers.py
+
 from vcard import VcardWindow
 from gajim_themes_window import GajimThemesWindow
 from advanced import AdvancedConfigurationWindow
@@ -592,12 +594,8 @@ def add_status(self, file_path, resource, priority, show, status):
 				str_status += ' - ' + status
 		status_label = gtk.Label(str_status)
 		status_label.set_alignment(00, 0)
-		self.table.attach(status_label, 3, 4, self.current_row, self.current_row + 1, 
-				gtk.EXPAND | gtk.FILL, 0, 0, 0)
-		
-	def escape_entities(self, text):
-		# escapes markup entities
-		return text.replace('&', '&amp;').replace('>','&gt;').replace('<','&lt;')
+		self.table.attach(status_label, 3, 4, self.current_row,
+			self.current_row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0)
 		
 	def populate(self, contacts):
 		if not contacts or len(contacts) == 0:
@@ -645,9 +643,9 @@ def populate(self, contacts):
 
 		info = '<span size="large" weight="bold">' + prim_contact.jid + '</span>'
 		info += '\n<span weight="bold">' + _('Name: ') + '</span>' + \
-			self.escape_entities(prim_contact.name)
+			gtkgui_helpers.escape_for_pango_markup(prim_contact.name)
 		info += '\n<span weight="bold">' + _('Subscription: ') + '</span>' + \
-			self.escape_entities(prim_contact.sub)
+			gtkgui_helpers.escape_for_pango_markup(prim_contact.sub)
 
 		if prim_contact.keyID:
 			keyID = None
@@ -657,7 +655,7 @@ def populate(self, contacts):
 				keyID = prim_contact.keyID[8:]
 			if keyID:
 				info += '\n<span weight="bold">' + _('OpenPGP: ') + \
-					'</span>' + self.escape_entities(keyID )
+					'</span>' + gtkgui_helpers.escape_for_pango_markup(keyID)
 
 		single_line, resource_str, multiple_resource= '', '', False
 		num_resources = 0
@@ -676,7 +674,7 @@ def populate(self, contacts):
 		else: # only one resource
 			if contact.resource:
 				info += '\n<span weight="bold">' + _('Resource: ') + \
-					'</span>' + self.escape_entities(contact.resource) + ' (' + str(contact.priority) + ')'
+					'</span>' + gtkgui_helpers.escape_for_pango_markup(contact.resource) + ' (' + str(contact.priority) + ')'
 			if contact.show:
 				info += '\n<span weight="bold">' + _('Status: ') + \
 					'</span>' + helpers.get_uf_show(contact.show) 
@@ -684,7 +682,7 @@ def populate(self, contacts):
 					status = contact.status.strip()
 					if status != '':
 						# escape markup entities. Is it posible to have markup in status?
-						info += ' - ' + self.escape_entities(status)
+						info += ' - ' + gtkgui_helpers.escape_for_pango_markup(status)
 		
 		self.account.set_markup(info)
 
diff --git a/src/gtkgui.glade b/src/gtkgui.glade
index 2cf848c15f..6050b88722 100644
--- a/src/gtkgui.glade
+++ b/src/gtkgui.glade
@@ -10008,8 +10008,8 @@ Custom</property>
 		      <child>
 			<widget class="GtkLabel" id="banner_name_label">
 			  <property name="visible">True</property>
-			  <property name="label">&lt;span weight=&quot;heavy&quot; size=&quot;large&quot;&gt;Contact: name&lt;/span&gt;
-JID: whatever@jabber.org</property>
+			  <property name="label">&lt;span weight=&quot;heavy&quot; size=&quot;large&quot;&gt;Contact name&lt;/span&gt;
+Status message</property>
 			  <property name="use_underline">False</property>
 			  <property name="use_markup">True</property>
 			  <property name="justify">GTK_JUSTIFY_LEFT</property>
diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py
index 24a45a8f99..751f6fc466 100644
--- a/src/gtkgui_helpers.py
+++ b/src/gtkgui_helpers.py
@@ -1,3 +1,27 @@
+##	gtkgui_helpers.py
+##
+## Gajim Team:
+##	- Yann Le Boulanger <asterix@lagaule.org>
+##	- Vincent Hanquez <tab@snarc.org>
+##	- Nikos Kouremenos <kourem@gmail.com>
+##	- Dimitur Kirov <dkirov@gmail.com>
+##
+## This file was initially written by Dimitur Kirov
+##
+##	Copyright (C) 2003-2005 Gajim Team
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation; version 2 only.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+
+import cgi
+
 from common import gajim
 
 def get_contact_instances_from_jid(account, jid):
@@ -12,3 +36,7 @@ def get_first_contact_instance_from_jid(account, jid):
 def get_contact_name_from_jid(account, jid):
 	contact_instances = get_contact_instances_from_jid(account, jid)
 	return contact_instances[0].name
+
+def escape_for_pango_markup(string):
+	# escapes chars for pango markup not to break
+	return cgi.escape(string)
diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py
index ca8bdf72ca..19509db018 100644
--- a/src/tabbed_chat_window.py
+++ b/src/tabbed_chat_window.py
@@ -113,8 +113,7 @@ def draw_name_banner(self, contact, chatstate = None):
 		houses the status icon, name, jid, and avatar'''
 		# this is the text for the big brown bar
 		# some chars need to be escaped..
-		name = contact.name.replace('&', '&amp;').replace('>','&gt;').replace(
-			'<','&lt;')
+		name = gtkgui_helpers.escape_for_pango_markup(contact.name)
 		
 		jid = contact.jid
 		status = contact.status
-- 
GitLab