Make bundle_id and activity_id window properties to

avoid races.
This commit is contained in:
Marco Pesenti Gritti 2007-06-01 21:21:30 +02:00
parent 5cc9a8c424
commit 2b7ffe41d9
6 changed files with 38 additions and 46 deletions

View File

@ -40,7 +40,7 @@ class HomeActivity(gobject.GObject):
gobject.PARAM_READWRITE), gobject.PARAM_READWRITE),
} }
def __init__(self, bundle=None, activity_id=None): def __init__(self, bundle, activity_id):
"""Initialise the HomeActivity """Initialise the HomeActivity
bundle -- sugar.activity.bundle.Bundle instance, bundle -- sugar.activity.bundle.Bundle instance,
@ -72,8 +72,6 @@ class HomeActivity(gobject.GObject):
def set_service(self, service): def set_service(self, service):
self._service = service self._service = service
if not self._activity_id:
self._activity_id = service.get_id()
def get_service(self): def get_service(self):
"""Retrieve the application's sugar introspection service """Retrieve the application's sugar introspection service

View File

@ -20,6 +20,8 @@ import gobject
import wnck import wnck
import dbus import dbus
from sugar import wm
from model.homeactivity import HomeActivity from model.homeactivity import HomeActivity
from model import bundleregistry from model import bundleregistry
@ -94,23 +96,25 @@ class HomeModel(gobject.GObject):
if window.get_window_type() == wnck.WINDOW_NORMAL: if window.get_window_type() == wnck.WINDOW_NORMAL:
activity = None activity = None
service = self._get_activity_service(window.get_xid()) activity_id = wm.get_activity_id(window)
if service:
activity_id = service.get_id() bundle_id = wm.get_bundle_id(window)
if bundle_id:
bundle = self._bundle_registry.get_bundle(bundle_id)
else:
bundle = None
if activity_id:
activity = self._get_activity_by_id(activity_id) activity = self._get_activity_by_id(activity_id)
if activity: if not activity:
activity.set_service(service) activity = HomeActivity(bundle, activity_id)
else:
activity = self._get_activity_by_xid(window.get_xid())
if activity:
activity.set_window(window)
else:
activity = HomeActivity()
activity.set_window(window)
self._add_activity(activity) self._add_activity(activity)
service = self._get_activity_service(window.get_xid())
activity.set_service(service)
activity.set_window(window)
activity.props.launching = False activity.props.launching = False
self.emit('activity-started', activity) self.emit('activity-started', activity)
@ -127,10 +131,9 @@ class HomeModel(gobject.GObject):
try: try:
xid = int(name[len(_SERVICE_NAME):]) xid = int(name[len(_SERVICE_NAME):])
activity = self._get_activity_by_xid(xid) activity = self._get_activity_by_xid(xid)
if activity: if activity and not activity.get_service():
service = self._get_activity_service(xid) service = self._get_activity_service(xid)
if service: activity.set_service(service)
activity.set_service()
except ValueError: except ValueError:
logging.error('Invalid activity service name, ' logging.error('Invalid activity service name, '
'cannot extract the xid') 'cannot extract the xid')
@ -221,8 +224,8 @@ class HomeModel(gobject.GObject):
self._add_activity(activity) self._add_activity(activity)
def notify_activity_launch_failed(self, activity_id): def notify_activity_launch_failed(self, activity_id):
if self._activities.has_key(activity_id): activity = self._get_activity_by_id(activity_id)
activity = self._activities[activity_id] if activity:
logging.debug("Activity %s (%s) launch failed" % (activity_id, activity.get_type())) logging.debug("Activity %s (%s) launch failed" % (activity_id, activity.get_type()))
self._remove_activity(activity) self._remove_activity(activity)
else: else:

View File

@ -9,7 +9,7 @@ sugar_PYTHON = \
ltihooks.py \ ltihooks.py \
profile.py \ profile.py \
util.py \ util.py \
x11.py wm.py
INCLUDES = \ INCLUDES = \
$(LIB_CFLAGS) \ $(LIB_CFLAGS) \

View File

@ -32,6 +32,7 @@ from sugar.graphics.window import Window
from sugar.graphics.toolbox import Toolbox from sugar.graphics.toolbox import Toolbox
from sugar.graphics.toolbutton import ToolButton from sugar.graphics.toolbutton import ToolButton
from sugar.datastore import datastore from sugar.datastore import datastore
from sugar import wm
from sugar import profile from sugar import profile
class ActivityToolbar(gtk.Toolbar): class ActivityToolbar(gtk.Toolbar):
@ -178,6 +179,7 @@ class Activity(Window, gtk.Container):
Window.__init__(self) Window.__init__(self)
self.connect('destroy', self._destroy_cb) self.connect('destroy', self._destroy_cb)
self.connect('realize', self._realize_cb)
self._active = False self._active = False
self._activity_id = handle.activity_id self._activity_id = handle.activity_id
@ -207,7 +209,7 @@ class Activity(Window, gtk.Container):
logging.debug('Creating a jobject.') logging.debug('Creating a jobject.')
self._jobject = datastore.create() self._jobject = datastore.create()
self._jobject.metadata['title'] = '%s %s' % (get_bundle_name(), 'Activity') self._jobject.metadata['title'] = '%s %s' % (get_bundle_name(), 'Activity')
self._jobject.metadata['activity'] = self.get_service_name() self._jobject.metadata['activity'] = self._get_service_name()
self._jobject.metadata['keep'] = '0' self._jobject.metadata['keep'] = '0'
self._jobject.metadata['buddies'] = '' self._jobject.metadata['buddies'] = ''
self._jobject.metadata['preview'] = '' self._jobject.metadata['preview'] = ''
@ -286,20 +288,12 @@ class Activity(Window, gtk.Container):
self.present() self.present()
self.emit('joined') self.emit('joined')
def get_service_name(self):
"""Gets the activity service name."""
return os.environ['SUGAR_BUNDLE_SERVICE_NAME']
def get_shared(self): def get_shared(self):
"""Returns TRUE if the activity is shared on the mesh.""" """Returns TRUE if the activity is shared on the mesh."""
if not self._shared_activity: if not self._shared_activity:
return False return False
return self._shared_activity.props.joined return self._shared_activity.props.joined
def get_id(self):
"""Get the unique activity identifier."""
return self._activity_id
def _internal_share_cb(self, ps, success, activity, err): def _internal_share_cb(self, ps, success, activity, err):
self._pservice.disconnect(self._share_id) self._pservice.disconnect(self._share_id)
self._share_id = None self._share_id = None
@ -322,6 +316,13 @@ class Activity(Window, gtk.Container):
"""Execute the given command with args""" """Execute the given command with args"""
return False return False
def _get_service_name(self):
return os.environ['SUGAR_BUNDLE_SERVICE_NAME']
def _realize_cb(self, window):
wm.set_bundle_id(window.window, self._get_service_name())
wm.set_activity_id(window.window, self._activity_id)
def _destroy_cb(self, window): def _destroy_cb(self, window):
"""Destroys our ActivityService and sharing service""" """Destroys our ActivityService and sharing service"""
if self._bus: if self._bus:

View File

@ -63,16 +63,6 @@ class ActivityService(dbus.service.Object):
"""Called by the shell to request the activity to share itself on the network.""" """Called by the shell to request the activity to share itself on the network."""
self._activity.share() self._activity.share()
@dbus.service.method(_ACTIVITY_INTERFACE)
def get_id(self):
"""Get the activity identifier"""
return self._activity.get_id()
@dbus.service.method(_ACTIVITY_INTERFACE)
def get_service_name(self):
"""Get the activity service name"""
return self._activity.get_service_name()
@dbus.service.method(_ACTIVITY_INTERFACE) @dbus.service.method(_ACTIVITY_INTERFACE)
def get_shared(self): def get_shared(self):
"""Returns True if the activity is shared on the mesh.""" """Returns True if the activity is shared on the mesh."""

View File

@ -19,13 +19,13 @@ import gtk
import _sugarext import _sugarext
def get_activity_id(wnck_window) def get_activity_id(wnck_window):
window = gtk.gdk.window_foreign_new(window.get_xid()) window = gtk.gdk.window_foreign_new(wnck_window.get_xid())
return _sugarext.x11_get_string_property( return _sugarext.x11_get_string_property(
window, '_SUGAR_ACTIVITY_ID') window, '_SUGAR_ACTIVITY_ID')
def get_bundle_id(wnck_window, prop): def get_bundle_id(wnck_window):
window = gtk.gdk.window_foreign_new(window.get_xid()) window = gtk.gdk.window_foreign_new(wnck_window.get_xid())
return _sugarext.x11_get_string_property( return _sugarext.x11_get_string_property(
window, '_SUGAR_BUNDLE_ID') window, '_SUGAR_BUNDLE_ID')
@ -35,4 +35,4 @@ def set_activity_id(window, activity_id):
def set_bundle_id(window, bundle_id): def set_bundle_id(window, bundle_id):
_sugarext.x11_set_string_property( _sugarext.x11_set_string_property(
window, '_SUGAR_BUNDLE_ID', activity_id) window, '_SUGAR_BUNDLE_ID', bundle_id)