More style fixes. Get it to work with multiple buddies on the same box.
This commit is contained in:
parent
3c0b08c811
commit
37c5aaf139
@ -2,29 +2,43 @@ from sugar.p2p.Stream import Stream
|
|||||||
from sugar.presence import PresenceService
|
from sugar.presence import PresenceService
|
||||||
|
|
||||||
class _Marshaller(object):
|
class _Marshaller(object):
|
||||||
def marshal(self, title, address):
|
def __init__(self, title, address):
|
||||||
return title + '\n' + address
|
pservice = PresenceService.get_instance()
|
||||||
|
name = pservice.get_owner().get_name()
|
||||||
|
self._message = name + '\n' + title + '\n' + address
|
||||||
|
|
||||||
def demarshal(self, message):
|
def get_message(self):
|
||||||
return message.split('\n')
|
return self._message
|
||||||
|
|
||||||
|
class _Demarshaller(object):
|
||||||
|
def __init__(self, message):
|
||||||
|
self._pservice = PresenceService.get_instance()
|
||||||
|
self._split_msg = message.split('\n')
|
||||||
|
|
||||||
|
def get_buddy(self):
|
||||||
|
return self._pservice.get_buddy_by_name(self._split_msg[0])
|
||||||
|
|
||||||
|
def get_title(self):
|
||||||
|
return self._split_msg[1]
|
||||||
|
|
||||||
|
def get_address(self):
|
||||||
|
return self._split_msg[2]
|
||||||
|
|
||||||
class LinksController(object):
|
class LinksController(object):
|
||||||
def __init__(self, service, model):
|
def __init__(self, service, model):
|
||||||
self._model = model
|
self._model = model
|
||||||
|
|
||||||
self._pservice = PresenceService.get_instance()
|
|
||||||
self._marshaller = _Marshaller()
|
|
||||||
|
|
||||||
self._stream = Stream.new_from_service(service)
|
self._stream = Stream.new_from_service(service)
|
||||||
self._stream.set_data_listener(self._recv_message)
|
self._stream.set_data_listener(self._recv_message)
|
||||||
self._stream_writer = self._stream.new_writer()
|
self._stream_writer = self._stream.new_writer()
|
||||||
|
|
||||||
def post_link(self, title, address):
|
def post_link(self, title, address):
|
||||||
message = self._marshaller.marshal(title, address)
|
marshaller = _Marshaller(title, address)
|
||||||
self._stream_writer.write(message)
|
self._stream_writer.write(marshaller.get_message())
|
||||||
|
|
||||||
def _recv_message(self, address, msg):
|
def _recv_message(self, address, msg):
|
||||||
buddy = self._pservice.get_buddy_by_address(address)
|
demarshaller = _Demarshaller(msg)
|
||||||
|
buddy = demarshaller.get_buddy()
|
||||||
if buddy:
|
if buddy:
|
||||||
link = self._marshaller.demarshal(msg)
|
self._model.add_link(buddy, demarshaller.get_title(),
|
||||||
self._model.add_link(buddy, *link)
|
demarshaller.get_address())
|
||||||
|
@ -23,6 +23,9 @@ class LinksView(hippo.Canvas):
|
|||||||
model.connect('link_removed', self._link_removed_cb)
|
model.connect('link_removed', self._link_removed_cb)
|
||||||
|
|
||||||
def _add_link(self, link):
|
def _add_link(self, link):
|
||||||
|
if len(self._bubbles) == 0:
|
||||||
|
self.show()
|
||||||
|
|
||||||
color = IconColor(link.buddy.get_color())
|
color = IconColor(link.buddy.get_color())
|
||||||
|
|
||||||
bubble = Bubble(color=color)
|
bubble = Bubble(color=color)
|
||||||
@ -42,6 +45,9 @@ class LinksView(hippo.Canvas):
|
|||||||
|
|
||||||
del self._bubbles[link]
|
del self._bubbles[link]
|
||||||
|
|
||||||
|
if len(self._bubbles) == 0:
|
||||||
|
self.hide()
|
||||||
|
|
||||||
def _link_added_cb(self, model, link):
|
def _link_added_cb(self, model, link):
|
||||||
self._add_link(link)
|
self._add_link(link)
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@ class WebActivity(Activity):
|
|||||||
hbox = gtk.HBox()
|
hbox = gtk.HBox()
|
||||||
|
|
||||||
hbox.pack_start(links_view, False)
|
hbox.pack_start(links_view, False)
|
||||||
links_view.show()
|
|
||||||
|
|
||||||
hbox.pack_start(self._browser)
|
hbox.pack_start(self._browser)
|
||||||
self._browser.show()
|
self._browser.show()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user