2006-09-10 03:07:10 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
import os
|
2006-09-10 11:57:41 +02:00
|
|
|
|
|
|
|
import gtk
|
2006-09-10 13:10:46 +02:00
|
|
|
import gobject
|
2006-09-10 11:57:41 +02:00
|
|
|
|
2006-09-10 03:07:10 +02:00
|
|
|
from sugar.session.TestSession import TestSession
|
|
|
|
from sugar.presence import PresenceService
|
2006-09-10 11:57:41 +02:00
|
|
|
from sugar.canvas.IconColor import IconColor
|
|
|
|
from sugar.p2p import Stream
|
|
|
|
from sugar import util
|
|
|
|
|
|
|
|
PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
|
|
|
|
|
|
|
|
class SimulatedActivity:
|
|
|
|
def __init__(self):
|
|
|
|
self._id = util.unique_id()
|
|
|
|
|
|
|
|
def get_id(self):
|
|
|
|
return self._id
|
|
|
|
|
|
|
|
class ShellOwner(object):
|
|
|
|
def __init__(self):
|
|
|
|
self._pservice = PresenceService.get_instance()
|
|
|
|
self._color = IconColor()
|
|
|
|
self._nick = 'kiu'
|
|
|
|
|
|
|
|
def announce(self):
|
|
|
|
props = { 'color': self._color.to_string() }
|
|
|
|
self._service = self._pservice.register_service(self._nick,
|
|
|
|
PRESENCE_SERVICE_TYPE, properties=props)
|
|
|
|
self._stream = Stream.Stream.new_from_service(self._service)
|
|
|
|
self._stream.register_reader_handler(self._handle_buddy_icon_request, "get_buddy_icon")
|
|
|
|
self._stream.register_reader_handler(self._handle_invite, "invite")
|
|
|
|
|
|
|
|
def _handle_buddy_icon_request(self):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def _handle_invite(self, issuer, bundle_id, activity_id):
|
|
|
|
return ''
|
2006-09-10 03:07:10 +02:00
|
|
|
|
2006-09-10 13:10:46 +02:00
|
|
|
def start():
|
|
|
|
pservice = PresenceService.get_instance()
|
|
|
|
|
|
|
|
if not pservice.get_owner().get_color():
|
|
|
|
print 'Color not found'
|
|
|
|
return True
|
|
|
|
|
|
|
|
activity = SimulatedActivity()
|
|
|
|
properties = { 'title' : 'OLPC' }
|
|
|
|
activity_type = '_GroupChatActivity_Sugar_redhat_com._udp'
|
|
|
|
service = pservice.share_activity(activity, activity_type, properties)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
2006-09-10 03:07:10 +02:00
|
|
|
os.environ['SUGAR_NICK_NAME'] = 'kiu'
|
|
|
|
|
|
|
|
session = TestSession()
|
|
|
|
session.start()
|
|
|
|
|
|
|
|
PresenceService.start()
|
|
|
|
|
2006-09-10 11:57:41 +02:00
|
|
|
owner = ShellOwner()
|
|
|
|
owner.announce()
|
|
|
|
|
2006-09-10 13:10:46 +02:00
|
|
|
gobject.timeout_add(1000, start)
|
2006-09-10 11:57:41 +02:00
|
|
|
|
|
|
|
gtk.main()
|