[Sugar-devel] [PATCH sugar 2/2] Escape all text passed to MenuItem.text_label
Sascha Silbe
silbe at activitycentral.com
Sun Jun 26 14:06:08 EDT 2011
sugar.graphics.menuitem.MenuItem passes text_label through to GTK without
escaping it, so we need to make sure it doesn't contain anything special in
user data or translations.
Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
extensions/deviceicon/network.py | 3 +-
src/jarabe/desktop/activitieslist.py | 4 ++-
src/jarabe/desktop/favoritesview.py | 12 ++++++----
src/jarabe/desktop/meshbox.py | 6 +++-
src/jarabe/desktop/networkviews.py | 15 ++++++++----
src/jarabe/frame/activitiestray.py | 31 +++++++++++++++++---------
src/jarabe/frame/clipboardmenu.py | 11 ++++++---
src/jarabe/journal/journaltoolbox.py | 11 ++++++---
src/jarabe/journal/palettes.py | 40 ++++++++++++++++++++-------------
src/jarabe/view/palettes.py | 2 +-
src/jarabe/view/viewsource.py | 3 +-
11 files changed, 87 insertions(+), 51 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index d6382c2..9a74237 100644
--- a/extensions/deviceicon/network.py
+++ b/extensions/deviceicon/network.py
@@ -101,7 +101,8 @@ class WirelessPalette(Palette):
self._info.pack_start(_padded(self._ip_address_label))
self._info.show_all()
- self._disconnect_item = MenuItem(_('Disconnect...'))
+ text = _('Disconnect...')
+ self._disconnect_item = MenuItem(glib.markup_escape_text(text))
icon = Icon(icon_size=gtk.ICON_SIZE_MENU, icon_name='media-eject')
self._disconnect_item.set_image(icon)
self._disconnect_item.connect('activate',
diff --git a/src/jarabe/desktop/activitieslist.py b/src/jarabe/desktop/activitieslist.py
index 05d760e..7f01ab0 100644
--- a/src/jarabe/desktop/activitieslist.py
+++ b/src/jarabe/desktop/activitieslist.py
@@ -22,6 +22,7 @@ from gettext import gettext as _
import gobject
import pango
import gconf
+import glib
import gtk
from sugar import util
@@ -414,7 +415,8 @@ class ActivityListPalette(ActivityPalette):
self.connect('destroy', self.__destroy_cb)
def _add_erase_option(self, registry, activity_info):
- menu_item = MenuItem(_('Erase'), 'list-remove')
+ text = _('Erase')
+ menu_item = MenuItem(glib.markup_escape_text(text), 'list-remove')
menu_item.connect('activate', self.__erase_activate_cb)
self.menu.append(menu_item)
menu_item.show()
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 4778ef9..636bf92 100644
--- a/src/jarabe/desktop/favoritesview.py
+++ b/src/jarabe/desktop/favoritesview.py
@@ -542,7 +542,8 @@ class FavoritePalette(ActivityPalette):
icon_file_name = misc.get_icon_name(entry)
color = misc.get_icon_color(entry)
- menu_item = MenuItem(text_label=entry['title'],
+ label = glib.markup_escape_text(entry['title'])
+ menu_item = MenuItem(text_label=label,
file_name=icon_file_name,
xo_color=color)
menu_item.connect('activate', self.__resume_entry_cb, entry)
@@ -628,11 +629,11 @@ class OwnerIcon(BuddyIcon):
backup_url = client.get_string('/desktop/sugar/backup_url')
if not backup_url:
- self._register_menu = MenuItem(_('Register'), 'media-record')
+ label = glib.markup_escape_text(_('Register'))
else:
- self._register_menu = MenuItem(_('Register again'),
- 'media-record')
+ label = glib.markup_escape_text(_('Register again'))
+ self._register_menu = MenuItem(label, 'media-record')
self._register_menu.connect('activate', self.__register_activate_cb)
palette.menu.append(self._register_menu)
self._register_menu.show()
@@ -647,7 +648,8 @@ class OwnerIcon(BuddyIcon):
def set_registered(self):
self.palette.menu.remove(self._register_menu)
- self._register_menu = MenuItem(_('Register again'), 'media-record')
+ label = glib.markup_escape_text(_('Register again'))
+ self._register_menu = MenuItem(label, 'media-record')
self._register_menu.connect('activate', self.__register_activate_cb)
self.palette.menu.append(self._register_menu)
self._register_menu.show()
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 3d1e52a..d3e2566 100644
--- a/src/jarabe/desktop/meshbox.py
+++ b/src/jarabe/desktop/meshbox.py
@@ -106,12 +106,14 @@ class ActivityView(hippo.CanvasBox):
joined = get_owner_instance() in self._model.props.buddies
if joined:
- item = MenuItem(_('Resume'), 'activity-start')
+ label = glib.markup_escape_text(_('Resume'))
+ item = MenuItem(label, 'activity-start')
item.connect('activate', self._clicked_cb)
item.show()
p.menu.append(item)
elif not private:
- item = MenuItem(_('Join'), 'activity-start')
+ label = glib.markup_escape_text(_('Join'))
+ item = MenuItem(label, 'activity-start')
item.connect('activate', self._clicked_cb)
item.show()
p.menu.append(item)
diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
index 99d46b6..a9fa4d3 100644
--- a/src/jarabe/desktop/networkviews.py
+++ b/src/jarabe/desktop/networkviews.py
@@ -131,11 +131,13 @@ class WirelessNetworkView(CanvasPulsingIcon):
p = palette.Palette(primary_text=glib.markup_escape_text(self._name),
icon=self._palette_icon)
- self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
+ label = glib.markup_escape_text(_('Connect'))
+ self._connect_item = MenuItem(label, 'dialog-ok')
self._connect_item.connect('activate', self.__connect_activate_cb)
p.menu.append(self._connect_item)
- self._disconnect_item = MenuItem(_('Disconnect'), 'media-eject')
+ label = glib.markup_escape_text(_('Disconnect'))
+ self._disconnect_item = MenuItem(label, 'media-eject')
self._disconnect_item.connect('activate',
self._disconnect_activate_cb)
p.menu.append(self._disconnect_item)
@@ -497,11 +499,13 @@ class SugarAdhocView(CanvasPulsingIcon):
palette_ = palette.Palette(_('Ad-hoc Network %d') % self._channel,
icon=self._palette_icon)
- self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
+ label = glib.markup_escape_text(_('Connect'))
+ self._connect_item = MenuItem(label, 'dialog-ok')
self._connect_item.connect('activate', self.__connect_activate_cb)
palette_.menu.append(self._connect_item)
- self._disconnect_item = MenuItem(_('Disconnect'), 'media-eject')
+ label = glib.markup_escape_text(_('Disconnect'))
+ self._disconnect_item = MenuItem(label, 'media-eject')
self._disconnect_item.connect('activate',
self.__disconnect_activate_cb)
palette_.menu.append(self._disconnect_item)
@@ -625,7 +629,8 @@ class OlpcMeshView(CanvasPulsingIcon):
def _create_palette(self):
_palette = palette.Palette(_('Mesh Network %d') % self._channel)
- self._connect_item = MenuItem(_('Connect'), 'dialog-ok')
+ label = glib.markup_escape_text(_('Connect'))
+ self._connect_item = MenuItem(label, 'dialog-ok')
self._connect_item.connect('activate', self.__connect_activate_cb)
_palette.menu.append(self._connect_item)
diff --git a/src/jarabe/frame/activitiestray.py b/src/jarabe/frame/activitiestray.py
index cb8e255..47b6cae 100644
--- a/src/jarabe/frame/activitiestray.py
+++ b/src/jarabe/frame/activitiestray.py
@@ -171,12 +171,14 @@ class InvitePalette(Palette):
self._invite = invite
- menu_item = MenuItem(_('Join'), icon_name='dialog-ok')
+ label = glib.markup_escape_text(_('Join'))
+ menu_item = MenuItem(label, icon_name='dialog-ok')
menu_item.connect('activate', self.__join_activate_cb)
self.menu.append(menu_item)
menu_item.show()
- menu_item = MenuItem(_('Decline'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Decline'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__decline_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -559,12 +561,14 @@ class IncomingTransferPalette(BaseTransferPalette):
def _update(self):
logging.debug('_update state: %r', self.file_transfer.props.state)
if self.file_transfer.props.state == filetransfer.FT_STATE_PENDING:
- menu_item = MenuItem(_('Accept'), icon_name='dialog-ok')
+ label = glib.markup_escape_text(_('Accept'))
+ menu_item = MenuItem(label, icon_name='dialog-ok')
menu_item.connect('activate', self.__accept_activate_cb)
self.menu.append(menu_item)
menu_item.show()
- menu_item = MenuItem(_('Decline'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Decline'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__decline_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -592,7 +596,8 @@ class IncomingTransferPalette(BaseTransferPalette):
for item in self.menu.get_children():
self.menu.remove(item)
- menu_item = MenuItem(_('Cancel'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Cancel'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__cancel_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -616,7 +621,8 @@ class IncomingTransferPalette(BaseTransferPalette):
for item in self.menu.get_children():
self.menu.remove(item)
- menu_item = MenuItem(_('Dismiss'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Dismiss'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__dismiss_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -627,7 +633,8 @@ class IncomingTransferPalette(BaseTransferPalette):
for item in self.menu.get_children():
self.menu.remove(item)
- menu_item = MenuItem(_('Resume'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Resume'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__resume_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -691,8 +698,8 @@ class OutgoingTransferPalette(BaseTransferPalette):
new_state = self.file_transfer.props.state
logging.debug('_update state: %r', new_state)
if new_state == filetransfer.FT_STATE_PENDING:
-
- menu_item = MenuItem(_('Cancel'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Cancel'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__cancel_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -720,7 +727,8 @@ class OutgoingTransferPalette(BaseTransferPalette):
for item in self.menu.get_children():
self.menu.remove(item)
- menu_item = MenuItem(_('Cancel'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Cancel'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__cancel_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -745,7 +753,8 @@ class OutgoingTransferPalette(BaseTransferPalette):
for item in self.menu.get_children():
self.menu.remove(item)
- menu_item = MenuItem(_('Dismiss'), icon_name='dialog-cancel')
+ label = glib.markup_escape_text(_('Dismiss'))
+ menu_item = MenuItem(label, icon_name='dialog-cancel')
menu_item.connect('activate', self.__dismiss_activate_cb)
self.menu.append(menu_item)
menu_item.show()
diff --git a/src/jarabe/frame/clipboardmenu.py b/src/jarabe/frame/clipboardmenu.py
index 695b66e..431add8 100644
--- a/src/jarabe/frame/clipboardmenu.py
+++ b/src/jarabe/frame/clipboardmenu.py
@@ -52,17 +52,19 @@ class ClipboardMenu(Palette):
self._progress_bar = None
- self._remove_item = MenuItem(_('Remove'), 'list-remove')
+ label = glib.markup_escape_text(_('Remove'))
+ self._remove_item = MenuItem(label, 'list-remove')
self._remove_item.connect('activate', self._remove_item_activate_cb)
self.menu.append(self._remove_item)
self._remove_item.show()
- self._open_item = MenuItem(_('Open'), 'zoom-activity')
+ label = glib.markup_escape_text(_('Open'))
+ self._open_item = MenuItem(label, 'zoom-activity')
self._open_item.connect('activate', self._open_item_activate_cb)
self.menu.append(self._open_item)
self._open_item.show()
- self._journal_item = MenuItem(_('Keep'))
+ self._journal_item = MenuItem(glib.markup_escape_text(_('Keep')))
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU,
@@ -102,7 +104,8 @@ class ClipboardMenu(Palette):
if not activity_info:
logging.warning('Activity %s is unknown.', service_name)
- item = gtk.MenuItem(activity_info.get_name())
+ activity_name = activity_info.get_name()
+ item = gtk.MenuItem(glib.markup_escape_text(activity_name))
item.connect('activate', self._open_submenu_item_activate_cb,
service_name)
submenu.append(item)
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index d825bc9..b53b058 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -24,6 +24,7 @@ import time
import gobject
import gio
+import glib
import gtk
from sugar.graphics.toolbox import Toolbox
@@ -453,7 +454,7 @@ class EntryToolbar(gtk.Toolbar):
menu_item.destroy()
if self._metadata['mountpoint'] != '/':
- journal_item = MenuItem(_('Journal'))
+ journal_item = MenuItem(glib.markup_escape_text(_('Journal')))
journal_item.set_image(Icon(
icon_name='activity-journal',
xo_color=profile.get_color(),
@@ -467,7 +468,7 @@ class EntryToolbar(gtk.Toolbar):
for mount in volume_monitor.get_mounts():
if self._metadata['mountpoint'] == mount.get_root().get_path():
continue
- menu_item = MenuItem(mount.get_name())
+ menu_item = MenuItem(glib.markup_escape_text(mount.get_name()))
icon_theme = gtk.icon_theme_get_default()
for name in mount.get_icon().props.names:
@@ -497,7 +498,8 @@ class EntryToolbar(gtk.Toolbar):
menu_item.destroy()
for activity_info in misc.get_activities(self._metadata):
- menu_item = MenuItem(activity_info.get_name())
+ activity_name = activity_info.get_name()
+ menu_item = MenuItem(glib.markup_escape_text(activity_name))
menu_item.set_image(Icon(file=activity_info.get_icon(),
icon_size=gtk.ICON_SIZE_MENU))
menu_item.connect('activate', self._resume_menu_item_activate_cb,
@@ -531,7 +533,8 @@ class SortingButton(ToolButton):
self.props.icon_name = 'view-lastedit'
for property_, icon, label in self._SORT_OPTIONS:
- button = MenuItem(icon_name=icon, text_label=label)
+ button = MenuItem(icon_name=icon,
+ text_label=glib.markup_escape_text(label))
button.connect('activate',
self.__sort_type_changed_cb,
property_,
diff --git a/src/jarabe/journal/palettes.py b/src/jarabe/journal/palettes.py
index c0d1e0c..be1f6fc 100644
--- a/src/jarabe/journal/palettes.py
+++ b/src/jarabe/journal/palettes.py
@@ -64,11 +64,11 @@ class ObjectPalette(Palette):
if misc.get_activities(metadata) or misc.is_bundle(metadata):
if metadata.get('activity_id', ''):
- resume_label = _('Resume')
- resume_with_label = _('Resume with')
+ resume_label = glib.markup_escape_text(_('Resume'))
+ resume_with_label = glib.markup_escape_text(_('Resume with'))
else:
- resume_label = _('Start')
- resume_with_label = _('Start with')
+ resume_label = glib.markup_escape_text(_('Start'))
+ resume_with_label = glib.markup_escape_text(_('Start with'))
menu_item = MenuItem(resume_label, 'activity-start')
menu_item.connect('activate', self.__start_activate_cb)
self.menu.append(menu_item)
@@ -81,14 +81,15 @@ class ObjectPalette(Palette):
menu_item.set_submenu(start_with_menu)
else:
- menu_item = MenuItem(_('No activity to start entry'))
+ label = glib.markup_escape_text(_('No activity to start entry'))
+ menu_item = MenuItem(label)
menu_item.set_sensitive(False)
self.menu.append(menu_item)
menu_item.show()
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
- menu_item = MenuItem(_('Copy'))
+ menu_item = MenuItem(glib.markup_escape_text(_('Copy')))
icon = Icon(icon_name='edit-copy', xo_color=color,
icon_size=gtk.ICON_SIZE_MENU)
menu_item.set_image(icon)
@@ -96,7 +97,8 @@ class ObjectPalette(Palette):
self.menu.append(menu_item)
menu_item.show()
- menu_item = MenuItem(_('Send to'), 'document-send')
+ label = glib.markup_escape_text(_('Send to'))
+ menu_item = MenuItem(label, 'document-send')
self.menu.append(menu_item)
menu_item.show()
@@ -105,12 +107,14 @@ class ObjectPalette(Palette):
menu_item.set_submenu(friends_menu)
if detail == True:
- menu_item = MenuItem(_('View Details'), 'go-right')
+ label = glib.markup_escape_text(_('View Details'))
+ menu_item = MenuItem(label, 'go-right')
menu_item.connect('activate', self.__detail_activate_cb)
self.menu.append(menu_item)
menu_item.show()
- menu_item = MenuItem(_('Erase'), 'list-remove')
+ label = glib.markup_escape_text(_('Erase'))
+ menu_item = MenuItem(label, 'list-remove')
menu_item.connect('activate', self.__erase_activate_cb)
self.menu.append(menu_item)
menu_item.show()
@@ -177,7 +181,8 @@ class FriendsMenu(gtk.Menu):
friends_model = friends.get_model()
for friend in friends_model:
if friend.is_present():
- menu_item = MenuItem(text_label=friend.get_nick(),
+ label = glib.markup_escape_text(friend.get_nick())
+ menu_item = MenuItem(text_label=label,
icon_name='computer-xo',
xo_color=friend.get_color())
menu_item.connect('activate', self.__item_activate_cb,
@@ -186,12 +191,14 @@ class FriendsMenu(gtk.Menu):
menu_item.show()
if not self.get_children():
- menu_item = MenuItem(_('No friends present'))
+ label = glib.markup_escape_text(_('No friends present'))
+ menu_item = MenuItem(label)
menu_item.set_sensitive(False)
self.append(menu_item)
menu_item.show()
else:
- menu_item = MenuItem(_('No valid connection found'))
+ label = glib.markup_escape_text(_('No valid connection found'))
+ menu_item = MenuItem(label)
menu_item.set_sensitive(False)
self.append(menu_item)
menu_item.show()
@@ -209,7 +216,8 @@ class StartWithMenu(gtk.Menu):
self._metadata = metadata
for activity_info in misc.get_activities(metadata):
- menu_item = MenuItem(activity_info.get_name())
+ activity_name = activity_info.get_name()
+ menu_item = MenuItem(glib.markup_escape_text(activity_name))
menu_item.set_image(Icon(file=activity_info.get_icon(),
icon_size=gtk.ICON_SIZE_MENU))
menu_item.connect('activate', self.__item_activate_cb,
@@ -219,10 +227,10 @@ class StartWithMenu(gtk.Menu):
if not self.get_children():
if metadata.get('activity_id', ''):
- resume_label = _('No activity to resume entry')
+ resume_text = _('No activity to resume entry')
else:
- resume_label = _('No activity to start entry')
- menu_item = MenuItem(resume_label)
+ resume_text = _('No activity to start entry')
+ menu_item = MenuItem(glib.markup_escape_text(resume_text))
menu_item.set_sensitive(False)
self.append(menu_item)
menu_item.show()
diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py
index 70e17a8..7e2a74b 100644
--- a/src/jarabe/view/palettes.py
+++ b/src/jarabe/view/palettes.py
@@ -134,7 +134,7 @@ class ActivityPalette(Palette):
xo_color = XoColor('%s,%s' % (style.COLOR_WHITE.get_svg(),
style.COLOR_TRANSPARENT.get_svg()))
- menu_item = MenuItem(text_label=_('Start new'),
+ menu_item = MenuItem(glib.markup_escape_text(_('Start new')),
file_name=activity_info.get_icon(),
xo_color=xo_color)
menu_item.connect('activate', self.__start_activate_cb)
diff --git a/src/jarabe/view/viewsource.py b/src/jarabe/view/viewsource.py
index a1c0be3..4f63ebb 100644
--- a/src/jarabe/view/viewsource.py
+++ b/src/jarabe/view/viewsource.py
@@ -25,6 +25,7 @@ import gtk
import gtksourceview2
import dbus
import gconf
+import glib
from sugar.graphics import style
from sugar.graphics.icon import Icon
@@ -218,7 +219,7 @@ class DocumentButton(RadioToolButton):
self.set_icon_widget(icon)
icon.show()
- menu_item = MenuItem(_('Keep'))
+ menu_item = MenuItem(glib.markup_escape_text(_('Keep')))
icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU,
xo_color=XoColor(self._color))
menu_item.set_image(icon)
--
1.7.2.5
More information about the Sugar-devel
mailing list