Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-10-09 14:10:01 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-10-09 14:10:01 (GMT)
commit994b337709383dc7858ae4c8d67870858d4fd120 (patch)
tree6fc349357ed575122c88c3e94ade08aa4ba44a47 /sugar
parentcbd3a52a6852574e3f481dac0ff2fc51c8d5038d (diff)
Add a bot and ability to share chat
Diffstat (limited to 'sugar')
-rw-r--r--sugar/simulator.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/sugar/simulator.py b/sugar/simulator.py
index c7fccfa..38603fc 100644
--- a/sugar/simulator.py
+++ b/sugar/simulator.py
@@ -1,3 +1,7 @@
+import random
+
+import gobject
+
from sugar.presence import PresenceService
from sugar.graphics.iconcolor import IconColor
from sugar.p2p import Stream
@@ -5,7 +9,7 @@ from sugar import util
_PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
-class BotService(object):
+class _BotService(object):
def __init__(self, bot):
self._bot = bot
@@ -36,12 +40,47 @@ class BotService(object):
def set_current_activity(self, activity_id):
self._service.set_published_value('curact', dbus.String(activity_id))
+class _ShareChatAction(object):
+ def __init__(self, bot, title):
+ self._bot = bot
+ self._title = title
+ self._id = util.unique_id()
+
+ def execute(self):
+ name = "%s [%s]" % (self._bot.name, self._id)
+ stype = '_GroupChatActivity_Sugar_redhat_com._udp'
+ properties = { 'title' : self._title,
+ 'color' : self._bot.color.to_string() }
+ address = u"232.%d.%d.%d" % (random.randint(0, 254),
+ random.randint(1, 254),
+ random.randint(1, 254))
+
+ pservice = PresenceService.get_instance()
+ pservice.register_service(name, stype, properties, address)
+
class Bot(object):
def __init__(self):
self.name = util.unique_id()
self.color = IconColor()
self.icon = None
+ self._queue = []
+
+ def share_chat(self, title):
+ action = _ShareChatAction(self, title)
+ self._queue.append(action)
+
def start(self):
- self._service = BotService(self)
+ self._service = _BotService(self)
self._service.announce()
+
+ gobject.idle_add(self._idle_cb)
+
+ def _idle_cb(self):
+ self._next_action()
+ return True
+
+ def _next_action(self):
+ if len(self._queue) > 0:
+ action = self._queue.pop(0)
+ action.execute()