Skip to content
Permalink
Browse files
Open with a activity if possible
This patch use the feature "Start activity from another" [1]
implemented in Sugar 0.106 if available.

Based in a patch from Sam Parkinson <sam.parkinson3@gmail.com>

[1] http://wiki.sugarlabs.org/go/Features/Start_activity_from_another_activity
  • Loading branch information
godiard committed May 12, 2015
1 parent 65c0bc8 commit 7315fe7
Showing 1 changed file with 36 additions and 14 deletions.
@@ -36,6 +36,14 @@
from sugar3.graphics.icon import Icon
from sugar3.activity import activity

try:
from jarabe.journal.bundlelauncher import get_bundle
from sugar3.activity.activity import launch_bundle
_HAS_BUNDLE_LAUNCHER = True
except ImportError:
_HAS_BUNDLE_LAUNCHER = False


DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore'
DS_DBUS_INTERFACE = 'org.laptop.sugar.DataStore'
DS_DBUS_PATH = '/org/laptop/sugar/DataStore'
@@ -187,16 +195,6 @@ def __state_change_cb(self, download, gparamspec):
self._stop_alert.props.title = _('Download completed')
self._stop_alert.props.msg = \
_('%s' % self._download.get_suggested_filename())
open_icon = Icon(icon_name='zoom-activity')
self._stop_alert.add_button(Gtk.ResponseType.APPLY,
_('Show in Journal'), open_icon)
open_icon.show()
ok_icon = Icon(icon_name='dialog-ok')
self._stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
ok_icon.show()
self._activity.add_alert(self._stop_alert)
self._stop_alert.connect('response', self.__stop_response_cb)
self._stop_alert.show()

if self._progress_sid is not None:
GObject.source_remove(self._progress_sid)
@@ -225,6 +223,28 @@ def __state_change_cb(self, download, gparamspec):
error_handler=self.__internal_error_cb,
timeout=360)

bundle = None
if _HAS_BUNDLE_LAUNCHER:
bundle = get_bundle(object_id=self._object_id)

if bundle is not None:
icon = Icon(file=bundle.get_icon())
label = _('Open with %s') % bundle.get_name()

This comment has been minimized.

Copy link
@tchx84

tchx84 Jul 2, 2015

Member

So basically the bundle is required to: (a) determine if there an activity that can open it and (b) to get the activity name (if exists)?

This comment has been minimized.

Copy link
@tchx84

tchx84 Jul 2, 2015

Member

Just to double check there isn't another way to resolve that information already.

This comment has been minimized.

Copy link
@godiard

godiard Jul 2, 2015

Author Contributor

Yes. Is possible you have a version of Sugar that allows "Open with activity", but you don't have the activity needed installed.

else:
icon = Icon(icon_name='zoom-activity')
label = _('Show in Journal')

self._stop_alert.add_button(Gtk.ResponseType.APPLY, label, icon)
icon.show()

ok_icon = Icon(icon_name='dialog-ok')
self._stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon)
ok_icon.show()

self._activity.add_alert(self._stop_alert)
self._stop_alert.connect('response', self.__stop_response_cb)
self._stop_alert.show()

elif state == WebKit.DownloadStatus.CANCELLED:
self.cleanup()

@@ -257,10 +277,12 @@ def __start_response_cb(self, alert, response_id):
self._activity.remove_alert(alert)

def __stop_response_cb(self, alert, response_id):
global _active_downloads
if response_id is Gtk.ResponseType.APPLY:
logging.debug('Start application with downloaded object')
activity.show_object_in_journal(self._object_id)
if response_id == Gtk.ResponseType.APPLY:
if _HAS_BUNDLE_LAUNCHER:

This comment has been minimized.

Copy link
@samdroid-apps

samdroid-apps May 12, 2015

Contributor

What if we are bundle launcher compatiable but we could not find a bundle: then we should open in journal.

This comment has been minimized.

Copy link
@godiard

godiard May 12, 2015

Author Contributor

True, need keep that state too (from bundle in line 230)

This comment has been minimized.

Copy link
@samdroid-apps

samdroid-apps May 12, 2015

Contributor

Or use different responce types :)

This comment has been minimized.

Copy link
@godiard

godiard May 13, 2015

Author Contributor

Yes :)
(Maybe use some of the other constants defined in Gtk.ResponseType, like ACCEPT)

logging.debug('Start application with downloaded object')
launch_bundle(object_id=self._object_id)
else:
activity.show_object_in_journal(self._object_id)
self._activity.remove_alert(alert)

def cleanup(self):

1 comment on commit 7315fe7

@godiard
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a fix in 157.1

Please sign in to comment.