Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/view/clipboardicon.py
diff options
context:
space:
mode:
Diffstat (limited to 'shell/view/clipboardicon.py')
-rw-r--r--shell/view/clipboardicon.py49
1 files changed, 22 insertions, 27 deletions
diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py
index 42c5453..ad74c1b 100644
--- a/shell/view/clipboardicon.py
+++ b/shell/view/clipboardicon.py
@@ -2,6 +2,7 @@ import logging
from sugar.graphics.menuicon import MenuIcon
from view.clipboardmenu import ClipboardMenu
+from sugar.graphics.iconcolor import IconColor
from sugar.activity import ActivityFactory
from sugar.clipboard import clipboardservice
from sugar import util
@@ -14,32 +15,30 @@ class ClipboardIcon(MenuIcon):
self._name = name
self._percent = 0
self._preview = None
+ self._activity = None
self.connect('activated', self._icon_activated_cb)
self._menu = None
def create_menu(self):
- self._menu = ClipboardMenu(self._name, self._percent, self._preview)
+ self._menu = ClipboardMenu(self._name, self._percent, self._preview,
+ self._activity)
self._menu.connect('action', self._popup_action_cb)
return self._menu
- def set_state(self, name, percent, icon_name, preview):
+ def set_state(self, name, percent, icon_name, preview, activity):
self._name = name
self._percent = percent
self._preview = preview
- self.set_icon_name(icon_name)
+ self._activity = activity
+ self.set_property("icon_name", icon_name)
if self._menu:
- self._menu.set_state(name, percent, preview)
+ self._menu.set_state(name, percent, preview, activity)
- 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"
+ if activity and percent < 100:
+ self.set_property('color', IconColor("#000000,#424242"))
else:
- return None
-
+ self.set_property('color', IconColor("#000000,#FFFFFF"))
+
def _activity_create_success_cb(self, handler, activity):
activity.start(util.unique_id())
activity.execute("open_document", [self._object_id])
@@ -47,26 +46,20 @@ class ClipboardIcon(MenuIcon):
def _activity_create_error_cb(self, handler, err):
pass
- def _icon_activated_cb(self, icon):
- if self._percent < 100:
- return
-
- cb_service = clipboardservice.get_instance()
- (name, percent, icon, preview, format_types) = \
- cb_service.get_object(self._object_id)
- if not format_types:
+ def _open_file(self):
+ if self._percent < 100 or not self._activity:
return
logging.debug("_icon_activated_cb: " + self._object_id)
- activity_type = self._get_activity_for_mime_type(format_types[0])
- if not activity_type:
- return
# Launch the activity to handle this item
- handler = ActivityFactory.create(activity_type)
+ handler = ActivityFactory.create(self._activity)
handler.connect('success', self._activity_create_success_cb)
handler.connect('error', self._activity_create_error_cb)
-
+
+ def _icon_activated_cb(self, icon):
+ self._open_file()
+
def _popup_action_cb(self, popup, action):
self.popdown()
@@ -75,6 +68,8 @@ class ClipboardIcon(MenuIcon):
elif action == ClipboardMenu.ACTION_DELETE:
cb_service = clipboardservice.get_instance()
cb_service.delete_object(self._object_id)
-
+ elif action == ClipboardMenu.ACTION_OPEN:
+ self._open_file()
+
def get_object_id(self):
return self._object_id