Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar

This commit is contained in:
Marco Pesenti Gritti 2007-04-28 01:24:18 +02:00
commit 4ecb7e26f9
5 changed files with 87 additions and 20 deletions

View File

@ -132,8 +132,8 @@ class Network(gobject.GObject):
return
self._valid = True
logging.debug("Net(%s): ssid '%s', mode %d, strength %d" % (self._op,
self._ssid, self._mode, self._strength))
# logging.debug("Net(%s): ssid '%s', mode %d, strength %d" % (self._op,
# self._ssid, self._mode, self._strength))
self.emit('initialized', self._valid)

View File

@ -30,13 +30,13 @@ class ActivityModel:
self._bundle = bundle
def get_id(self):
return self._activity.get_id()
return self._activity.props.id
def get_icon_name(self):
return self._bundle.get_icon()
def get_color(self):
return XoColor(self._activity.get_color())
return XoColor(self._activity.props.color)
def get_service_name(self):
return self._bundle.get_service_name()
@ -163,8 +163,8 @@ class MeshModel(gobject.GObject):
def _buddy_activity_changed_cb(self, model, cur_activity):
if not self._buddies.has_key(model.get_key()):
return
if cur_activity and self._activities.has_key(cur_activity.get_id()):
activity_model = self._activities[cur_activity.get_id()]
if cur_activity and self._activities.has_key(cur_activity.props.id):
activity_model = self._activities[cur_activity.props.id]
self.emit('buddy-moved', model, activity_model)
else:
self.emit('buddy-moved', model, None)
@ -193,12 +193,10 @@ class MeshModel(gobject.GObject):
self._check_activity(activity)
def _check_activity(self, activity):
atype = activity.props.type
bundle = self._bundle_registry.get_bundle(atype)
bundle = self._bundle_registry.get_bundle(activity.props.type)
if not bundle:
return
activity_id = activity.get_id()
if self.has_activity(activity_id):
if self.has_activity(activity.props.id):
return
self.add_activity(bundle, activity)
@ -224,7 +222,7 @@ class MeshModel(gobject.GObject):
self.emit('buddy-moved', buddy_model, model)
def _activity_disappeared_cb(self, pservice, activity):
if self._activities.has_key(activity.get_id()):
activity_model = self._activities[activity.get_id()]
if self._activities.has_key(activity.props.id):
activity_model = self._activities[activity.props.id]
self.emit('activity-removed', activity_model)
del self._activities[activity.get_id()]
del self._activities[activity.props.id]

View File

@ -189,7 +189,7 @@ class ActivityView(SnowflakeBox):
del self._icons[key]
def _clicked_cb(self, item):
bundle_id = self._model.get_service().get_service_name()
bundle_id = self._model.get_service_name()
self._shell.join_activity(bundle_id, self._model.get_id())
class MeshBox(SpreadBox):

View File

@ -23,7 +23,7 @@ activity must do to participate in the Sugar desktop.
import logging
import os
import gtk
import gtk, gobject
from sugar.presence import presenceservice
from sugar.activity.activityservice import ActivityService
@ -32,30 +32,57 @@ from sugar.graphics.toolbox import Toolbox
from sugar.graphics.toolbutton import ToolButton
class ActivityToolbar(gtk.Toolbar):
__gsignals__ = {
'share-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
'close-clicked': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
}
def __init__(self, activity):
gtk.Toolbar.__init__(self)
self._activity = activity
activity.connect('shared', self._activity_shared_cb)
button = ToolButton('window-close')
button.connect('clicked', self._close_button_clicked_cb)
self.insert(button, -1)
button.show()
self._share_button = ToolButton('stock-share-mesh')
self._share_button.connect('clicked', self._share_button_clicked_cb)
self.insert(self._share_button, -1)
if activity.get_shared():
self._share_button.set_sensitive(False)
self._share_button.show()
def _close_button_clicked_cb(self, button):
self._activity.destroy()
self.emit('close-clicked')
def _share_button_clicked_cb(self, button):
self.emit('share-clicked')
def _activity_shared_cb(self, activity):
self._share_button.set_sensitive(False)
class ActivityToolbox(Toolbox):
def __init__(self, activity):
Toolbox.__init__(self)
activity_toolbar = ActivityToolbar(activity)
self.add_toolbar('Activity', activity_toolbar)
activity_toolbar.show()
self._activity_toolbar = ActivityToolbar(activity)
self.add_toolbar('Activity', self._activity_toolbar)
self._activity_toolbar.show()
def get_activity_toolbar(self):
return self._activity_toolbar
class Activity(Window, gtk.Container):
"""Base Activity class that all other Activities derive from."""
__gtype_name__ = 'SugarActivity'
__gsignals__ = {
'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
}
def __init__(self, handle):
"""Initialise the Activity
@ -111,6 +138,7 @@ class Activity(Window, gtk.Container):
self._shared = True
self._service.join()
self.present()
self.emit('shared')
def _share_cb(self, ps, success, service, err):
self._pservice.disconnect(self._share_sigid)
@ -119,6 +147,7 @@ class Activity(Window, gtk.Container):
logging.debug('Share of activity %s successful.' % self.get_id())
self._service = service
self._shared = True
self.emit('shared')
else:
logging.debug('Share of activity %s failed: %s.' % (self.get_id(), err))
@ -140,6 +169,18 @@ class Activity(Window, gtk.Container):
if self._service:
self._pservice.unregister_service(self._service)
def _handle_close_cb(self, toolbar):
self.destroy()
def _handle_share_cb(self, toolbar):
self.share()
def set_toolbox(self, toolbox):
Window.set_toolbox(self, toolbox)
act_toolbar = toolbox.get_activity_toolbar()
act_toolbar.connect('share-clicked', self._handle_share_cb)
act_toolbar.connect('close-clicked', self._handle_close_cb)
def get_bundle_path():
"""Return the bundle path for the current process' bundle
"""

View File

@ -671,7 +671,35 @@ class ActivityTests(GenericTestCase):
assert self._success == True, "Test unsuccessful"
assert len(self._activities) == 2, "Shared activities were not received"
# FIXME: check everything
assert self._got_first_curact == True, "Couldn't discover first activity"
assert self._got_other_curact == True, "Couldn't discover second activity"
assert self._start_monitor == True, "Couldn't discover both activities"
# check the buddy
assert self._buddy.props.key == BuddyTests._BA_PUBKEY, "Buddy key doesn't match expected"
assert self._buddy.props.nick == BuddyTests._BA_NICK, "Buddy nick doesn't match expected"
assert self._buddy.props.color == BuddyTests._BA_COLOR, "Buddy color doesn't match expected"
assert self._buddy.props.current_activity.props.id == self._other_actid, "Buddy current activity didn't match expected"
# check both activities
found = 0
for act in self._activities:
if act.props.id == self._AA_ID:
assert act.props.name == self._AA_NAME, "Name doesn't match expected"
assert act.props.color == self._AA_COLOR, "Color doesn't match expected"
buddies = act.get_joined_buddies()
assert len(buddies) == 1, "Unexpected number of buddies in first activity"
assert buddies[0] == self._buddy, "Unexpected buddy in first activity"
found += 1
elif act.props.id == self._other_actid:
assert act.props.name == self._other_actname, "Name doesn't match expected"
assert act.props.color == self._other_actcolor, "Color doesn't match expected"
buddies = act.get_joined_buddies()
assert len(buddies) == 1, "Unexpected number of buddies in first activity"
assert buddies[0] == self._buddy, "Unexpected buddy in first activity"
found += 1
assert found == 2, "Couldn't discover both activities"
def addToSuite(suite):
suite.addTest(ActivityTests("testActivityAppeared"))