/usr/share/pyshared/jarabe/journal/palettes.py is in python-jarabe-0.98 0.98.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | # Copyright (C) 2008 One Laptop Per Child
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gettext import gettext as _
import logging
import os
from gi.repository import GObject
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GConf
from gi.repository import Gio
from gi.repository import GLib
from sugar3.graphics import style
from sugar3.graphics.palette import Palette
from sugar3.graphics.menuitem import MenuItem
from sugar3.graphics.icon import Icon
from sugar3.graphics.xocolor import XoColor
from sugar3.graphics.alert import Alert
from sugar3 import mime
from jarabe.model import friends
from jarabe.model import filetransfer
from jarabe.model import mimeregistry
from jarabe.journal import misc
from jarabe.journal import model
from jarabe.journal import journalwindow
class ObjectPalette(Palette):
__gtype_name__ = 'ObjectPalette'
__gsignals__ = {
'detail-clicked': (GObject.SignalFlags.RUN_FIRST, None,
([str])),
'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, metadata, detail=False):
self._metadata = metadata
activity_icon = Icon(icon_size=Gtk.IconSize.LARGE_TOOLBAR)
activity_icon.props.file = misc.get_icon_name(metadata)
color = misc.get_icon_color(metadata)
activity_icon.props.xo_color = color
if 'title' in metadata:
title = GObject.markup_escape_text(metadata['title'])
else:
title = GLib.markup_escape_text(_('Untitled'))
Palette.__init__(self, primary_text=title,
icon=activity_icon)
if misc.get_activities(metadata) or misc.is_bundle(metadata):
if metadata.get('activity_id', ''):
resume_label = _('Resume')
resume_with_label = _('Resume with')
else:
resume_label = _('Start')
resume_with_label = _('Start with')
menu_item = MenuItem(resume_label, 'activity-start')
menu_item.connect('activate', self.__start_activate_cb)
self.menu.append(menu_item)
menu_item.show()
menu_item = MenuItem(resume_with_label, 'activity-start')
self.menu.append(menu_item)
menu_item.show()
start_with_menu = StartWithMenu(self._metadata)
menu_item.set_submenu(start_with_menu)
else:
menu_item = MenuItem(_('No activity to start entry'))
menu_item.set_sensitive(False)
self.menu.append(menu_item)
menu_item.show()
menu_item = MenuItem(_('Copy to'))
icon = Icon(icon_name='edit-copy', xo_color=color,
icon_size=Gtk.IconSize.MENU)
menu_item.set_image(icon)
self.menu.append(menu_item)
menu_item.show()
copy_menu = CopyMenu(metadata)
copy_menu.connect('volume-error', self.__volume_error_cb)
menu_item.set_submenu(copy_menu)
if self._metadata['mountpoint'] == '/':
menu_item = MenuItem(_('Duplicate'))
icon = Icon(icon_name='edit-duplicate', xo_color=color,
icon_size=Gtk.IconSize.MENU)
menu_item.set_image(icon)
menu_item.connect('activate', self.__duplicate_activate_cb)
self.menu.append(menu_item)
menu_item.show()
menu_item = MenuItem(_('Send to'), 'document-send')
self.menu.append(menu_item)
menu_item.show()
friends_menu = FriendsMenu()
friends_menu.connect('friend-selected', self.__friend_selected_cb)
menu_item.set_submenu(friends_menu)
if detail == True:
menu_item = MenuItem(_('View Details'), 'go-right')
menu_item.connect('activate', self.__detail_activate_cb)
self.menu.append(menu_item)
menu_item.show()
menu_item = MenuItem(_('Erase'), 'list-remove')
menu_item.connect('activate', self.__erase_activate_cb)
self.menu.append(menu_item)
menu_item.show()
def __start_activate_cb(self, menu_item):
misc.resume(self._metadata)
def __duplicate_activate_cb(self, menu_item):
file_path = model.get_file(self._metadata['uid'])
try:
model.copy(self._metadata, '/')
except IOError, e:
logging.exception('Error while copying the entry. %s', e.strerror)
self.emit('volume-error',
_('Error while copying the entry. %s') % e.strerror,
_('Error'))
def __erase_activate_cb(self, menu_item):
alert = Alert()
erase_string = _('Erase')
alert.props.title = erase_string
alert.props.msg = _('Do you want to permanently erase \"%s\"?') \
% self._metadata['title']
icon = Icon(icon_name='dialog-cancel')
alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon)
icon.show()
ok_icon = Icon(icon_name='dialog-ok')
alert.add_button(Gtk.ResponseType.OK, erase_string, ok_icon)
ok_icon.show()
alert.connect('response', self.__erase_alert_response_cb)
journalwindow.get_journal_window().add_alert(alert)
alert.show()
def __erase_alert_response_cb(self, alert, response_id):
journalwindow.get_journal_window().remove_alert(alert)
if response_id is Gtk.ResponseType.OK:
model.delete(self._metadata['uid'])
def __detail_activate_cb(self, menu_item):
self.emit('detail-clicked', self._metadata['uid'])
def __volume_error_cb(self, menu_item, message, severity):
self.emit('volume-error', message, severity)
def __friend_selected_cb(self, menu_item, buddy):
logging.debug('__friend_selected_cb')
file_name = model.get_file(self._metadata['uid'])
if not file_name or not os.path.exists(file_name):
logging.warn('Entries without a file cannot be sent.')
self.emit('volume-error',
_('Entries without a file cannot be sent.'),
_('Warning'))
return
title = str(self._metadata['title'])
description = str(self._metadata.get('description', ''))
mime_type = str(self._metadata['mime_type'])
if not mime_type:
mime_type = mime.get_for_file(file_name)
filetransfer.start_transfer(buddy, file_name, title, description,
mime_type)
class CopyMenu(Gtk.Menu):
__gtype_name__ = 'JournalCopyMenu'
__gsignals__ = {
'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, metadata):
Gtk.Menu.__init__(self)
self._metadata = metadata
clipboard_menu = ClipboardMenu(self._metadata)
clipboard_menu.set_image(Icon(icon_name='toolbar-edit',
icon_size=Gtk.IconSize.MENU))
clipboard_menu.connect('volume-error', self.__volume_error_cb)
self.append(clipboard_menu)
clipboard_menu.show()
if self._metadata['mountpoint'] != '/':
client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
journal_menu = VolumeMenu(self._metadata, _('Journal'), '/')
journal_menu.set_image(Icon(icon_name='activity-journal',
xo_color=color,
icon_size=Gtk.IconSize.MENU))
journal_menu.connect('volume-error', self.__volume_error_cb)
self.append(journal_menu)
journal_menu.show()
documents_path = model.get_documents_path()
if documents_path is not None and not \
self._metadata['uid'].startswith(documents_path):
documents_menu = VolumeMenu(self._metadata, _('Documents'),
documents_path)
documents_menu.set_image(Icon(icon_name='user-documents',
icon_size=Gtk.IconSize.MENU))
documents_menu.connect('volume-error', self.__volume_error_cb)
self.append(documents_menu)
documents_menu.show()
volume_monitor = Gio.VolumeMonitor.get()
icon_theme = Gtk.IconTheme.get_default()
for mount in volume_monitor.get_mounts():
if self._metadata['mountpoint'] == mount.get_root().get_path():
continue
volume_menu = VolumeMenu(self._metadata, mount.get_name(),
mount.get_root().get_path())
for name in mount.get_icon().props.names:
if icon_theme.has_icon(name):
volume_menu.set_image(Icon(icon_name=name,
icon_size=Gtk.IconSize.MENU))
break
volume_menu.connect('volume-error', self.__volume_error_cb)
self.append(volume_menu)
volume_menu.show()
def __volume_error_cb(self, menu_item, message, severity):
self.emit('volume-error', message, severity)
class VolumeMenu(MenuItem):
__gtype_name__ = 'JournalVolumeMenu'
__gsignals__ = {
'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, metadata, label, mount_point):
MenuItem.__init__(self, label)
self._metadata = metadata
self.connect('activate', self.__copy_to_volume_cb, mount_point)
def __copy_to_volume_cb(self, menu_item, mount_point):
file_path = model.get_file(self._metadata['uid'])
if not file_path or not os.path.exists(file_path):
logging.warn('Entries without a file cannot be copied.')
self.emit('volume-error',
_('Entries without a file cannot be copied.'),
_('Warning'))
return
try:
model.copy(self._metadata, mount_point)
except IOError, e:
logging.exception('Error while copying the entry. %s', e.strerror)
self.emit('volume-error',
_('Error while copying the entry. %s') % e.strerror,
_('Error'))
class ClipboardMenu(MenuItem):
__gtype_name__ = 'JournalClipboardMenu'
__gsignals__ = {
'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
([str, str])),
}
def __init__(self, metadata):
MenuItem.__init__(self, _('Clipboard'))
self._temp_file_path = None
self._metadata = metadata
self.connect('activate', self.__copy_to_clipboard_cb)
def __copy_to_clipboard_cb(self, menu_item):
file_path = model.get_file(self._metadata['uid'])
if not file_path or not os.path.exists(file_path):
logging.warn('Entries without a file cannot be copied.')
self.emit('volume-error',
_('Entries without a file cannot be copied.'),
_('Warning'))
return
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clipboard.set_with_data([Gtk.TargetEntry.new('text/uri-list', 0, 0)],
self.__clipboard_get_func_cb,
self.__clipboard_clear_func_cb, None)
def __clipboard_get_func_cb(self, clipboard, selection_data, info, data):
# Get hold of a reference so the temp file doesn't get deleted
self._temp_file_path = model.get_file(self._metadata['uid'])
logging.debug('__clipboard_get_func_cb %r', self._temp_file_path)
selection_data.set_uris(['file://' + self._temp_file_path])
def __clipboard_clear_func_cb(self, clipboard, data):
# Release and delete the temp file
self._temp_file_path = None
class FriendsMenu(Gtk.Menu):
__gtype_name__ = 'JournalFriendsMenu'
__gsignals__ = {
'friend-selected': (GObject.SignalFlags.RUN_FIRST, None,
([object])),
}
def __init__(self):
Gtk.Menu.__init__(self)
if filetransfer.file_transfer_available():
friends_model = friends.get_model()
for friend in friends_model:
if friend.is_present():
menu_item = MenuItem(text_label=friend.get_nick(),
icon_name='computer-xo',
xo_color=friend.get_color())
menu_item.connect('activate', self.__item_activate_cb,
friend)
self.append(menu_item)
menu_item.show()
if not self.get_children():
menu_item = MenuItem(_('No friends present'))
menu_item.set_sensitive(False)
self.append(menu_item)
menu_item.show()
else:
menu_item = MenuItem(_('No valid connection found'))
menu_item.set_sensitive(False)
self.append(menu_item)
menu_item.show()
def __item_activate_cb(self, menu_item, friend):
self.emit('friend-selected', friend)
class StartWithMenu(Gtk.Menu):
__gtype_name__ = 'JournalStartWithMenu'
def __init__(self, metadata):
Gtk.Menu.__init__(self)
self._metadata = metadata
for activity_info in misc.get_activities(metadata):
menu_item = MenuItem(activity_info.get_name())
menu_item.set_image(Icon(file=activity_info.get_icon(),
icon_size=Gtk.IconSize.MENU))
menu_item.connect('activate', self.__item_activate_cb,
activity_info.get_bundle_id())
self.append(menu_item)
menu_item.show()
if not self.get_children():
if metadata.get('activity_id', ''):
resume_label = _('No activity to resume entry')
else:
resume_label = _('No activity to start entry')
menu_item = MenuItem(resume_label)
menu_item.set_sensitive(False)
self.append(menu_item)
menu_item.show()
def __item_activate_cb(self, menu_item, service_name):
mime_type = self._metadata.get('mime_type', '')
if mime_type:
mime_registry = mimeregistry.get_registry()
mime_registry.set_default_activity(mime_type, service_name)
misc.resume(self._metadata, service_name)
class BuddyPalette(Palette):
def __init__(self, buddy):
self._buddy = buddy
nick, colors = buddy
buddy_icon = Icon(icon_name='computer-xo',
icon_size=style.STANDARD_ICON_SIZE,
xo_color=XoColor(colors))
Palette.__init__(self, primary_text=GLib.markup_escape_text(nick),
icon=buddy_icon)
# TODO: Support actions on buddies, like make friend, invite, etc.
|