Added icon, title and preview for clipboard objects. Also allow for opening docs and rtfs from the web.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import logging
|
||||
|
||||
from sugar.graphics.menuicon import MenuIcon
|
||||
from view.clipboardmenu import ClipboardMenu
|
||||
from sugar.activity import ActivityFactory
|
||||
@@ -6,31 +8,54 @@ from sugar.clipboard import clipboardservice
|
||||
class ClipboardIcon(MenuIcon):
|
||||
|
||||
def __init__(self, menu_shell, object_id, name):
|
||||
MenuIcon.__init__(self, menu_shell, icon_name='activity-xbook')
|
||||
MenuIcon.__init__(self, menu_shell)
|
||||
self._object_id = object_id
|
||||
self._name = name
|
||||
self._percent = 0
|
||||
self._preview = None
|
||||
self.connect('activated', self._icon_activated_cb)
|
||||
self._menu = None
|
||||
|
||||
def create_menu(self):
|
||||
self._menu = ClipboardMenu(self._name, self._percent)
|
||||
self._menu = ClipboardMenu(self._name, self._percent, self._preview)
|
||||
self._menu.connect('action', self._popup_action_cb)
|
||||
return self._menu
|
||||
|
||||
def set_percent(self, percent):
|
||||
def set_state(self, name, percent, icon_name, preview):
|
||||
self._name = name
|
||||
self._percent = percent
|
||||
self._preview = preview
|
||||
self.set_icon_name(icon_name)
|
||||
if self._menu:
|
||||
self._menu.set_percent(percent)
|
||||
self._menu.set_state(name, percent, preview)
|
||||
|
||||
def _get_activity_for_mime_type(self, mime_type):
|
||||
# FIXME: We should use some kind of registry that could be extended by
|
||||
# newly installed activities.
|
||||
if mime_type == "application/pdf":
|
||||
return "org.laptop.sugar.Xbook"
|
||||
elif mime_type in ["application/msword", "text/rtf", "application/rtf"]:
|
||||
return "org.laptop.AbiWordActivity"
|
||||
else:
|
||||
return None
|
||||
|
||||
def _icon_activated_cb(self, icon):
|
||||
if self._percent == 100:
|
||||
cb_service = clipboardservice.get_instance()
|
||||
format_types = cb_service.get_object_format_types(self._object_id)
|
||||
if len(format_types) > 0 and format_types[0] == "application/pdf":
|
||||
activity = ActivityFactory.create("org.laptop.sugar.Xbook")
|
||||
activity.execute("open_document", [self._object_id])
|
||||
|
||||
(name, percent, icon, preview, format_types) = \
|
||||
cb_service.get_object(self._object_id)
|
||||
|
||||
if format_types:
|
||||
logging.debug("_icon_activated_cb: " + self._object_id)
|
||||
|
||||
activity_id = self._get_activity_for_mime_type(format_types[0])
|
||||
|
||||
if activity_id:
|
||||
activity = ActivityFactory.create(activity_id)
|
||||
activity.start()
|
||||
activity.execute("open_document", [self._object_id])
|
||||
|
||||
def _popup_action_cb(self, popup, action):
|
||||
self.popdown()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user