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

View File

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

View File

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

View File

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

View File

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