From c28b01faa7d2cf454d23904e6cde253ee3455e97 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Mon, 03 Sep 2007 20:14:02 +0000 Subject: redesign when members leave and rejoin added timestamp to be able to bring the links in the right order, you can not add alink twice unless you deleted it already, links are added to the tray on the right side --- diff --git a/NEWS b/NEWS index 8c97ec9..9c4f0f4 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ -46 +* redesign when members leave and rejoin, added timestamp to be +able to bring the links in the right order, you can not add alink +twice unless you deleted it already, links are added to the tray +on the right side (erikos) +46 +* fix for gray page when resuming from journal (erikos) * #2327 Unescape the URI to display it in the address bar (marco) * fixed memory consuption when creating shared links by calling the garbage collector (erikos) diff --git a/linkbutton.py b/linkbutton.py index 8b2e478..aaa1d26 100644 --- a/linkbutton.py +++ b/linkbutton.py @@ -33,13 +33,13 @@ class LinkButton(TrayButton, gobject.GObject): __gtype_name__ = 'LinkButton' __gsignals__ = { 'remove_link': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([int])) + gobject.TYPE_NONE, ([str])) } - def __init__(self, url, buffer, color, title, owner, index): + def __init__(self, url, buffer, color, title, owner, index, hash): TrayButton.__init__(self) self.set_image(buffer, color.split(',')[1], color.split(',')[0]) - self.index = index + self.hash = hash info = title +'\n'+ owner self.setup_rollover_options(info) @@ -98,4 +98,4 @@ class LinkButton(TrayButton, gobject.GObject): menu_item.show() def item_remove_cb(self, widget): - self.emit('remove_link', self.index) + self.emit('remove_link', self.hash) diff --git a/messenger.py b/messenger.py index 35bbc21..1d6d93c 100644 --- a/messenger.py +++ b/messenger.py @@ -82,47 +82,47 @@ class Messenger(ExportedGObject): a_ids.pop() for link in self.model.data['shared_links']: if link['hash'] not in a_ids: - if link['deleted'] == 0: self.tube.get_object(sender, PATH).send_link( link['hash'], link['url'], link['title'], link['color'], - link['owner'], link['thumb']) + link['owner'], link['thumb'], link['timestamp']) def error_sync(self, e, when): _logger.error('Error %s: %s'%(when, e)) - @dbus.service.method(dbus_interface=IFACE, in_signature='as', out_signature='ass', sender_keyword='sender') + @dbus.service.method(dbus_interface=IFACE, in_signature='as', + out_signature='ass', sender_keyword='sender') def sync_with_members(self, b_ids, sender=None): '''Sync with members ''' b_ids.pop() # links the caller wants from me for link in self.model.data['shared_links']: if link['hash'] not in b_ids: - if link['deleted'] == 0: - self.tube.get_object(sender, PATH).send_link(link['hash'], link['url'], link['title'], link['color'], - link['owner'], link['thumb']) + self.tube.get_object(sender, PATH).send_link( + link['hash'], link['url'], link['title'], link['color'], + link['owner'], link['thumb'], link['timestamp']) a_ids = self.model.get_links_ids() a_ids.append('') # links I want from the caller return (a_ids, self.bus_name) - @dbus.service.method(dbus_interface=IFACE, in_signature='ssssss', out_signature='') - def send_link(self, id, url, title, color, owner, buffer): + @dbus.service.method(dbus_interface=IFACE, in_signature='ssssssd', out_signature='') + def send_link(self, id, url, title, color, owner, buffer, timestamp): '''Send link''' a_ids = self.model.get_links_ids() if id not in a_ids: thumb = base64.b64decode(buffer) - self.model.add_link(url, title, thumb, owner, color) + self.model.add_link(url, title, thumb, owner, color, timestamp) - @dbus.service.signal(IFACE, signature='sssss') - def _add_link(self, url, title, color, owner, thumb): + @dbus.service.signal(IFACE, signature='sssssd') + def _add_link(self, url, title, color, owner, thumb, timestamp): '''Signal to send the link information (add)''' _logger.debug('Add Link: %s '%url) - def _add_link_receiver(self, url, title, color, owner, buffer, sender=None): + def _add_link_receiver(self, url, title, color, owner, buffer, timestamp, sender=None): '''Member sent a link''' handle = self.tube.bus_name_to_handle[sender] if self.tube.self_handle != handle: thumb = base64.b64decode(buffer) - self.model.add_link(url, title, thumb, owner, color) + self.model.add_link(url, title, thumb, owner, color, timestamp) _logger.debug('Added link: %s to linkbar.'%(url)) diff --git a/model.py b/model.py index 4ffe5b7..987c5dd 100644 --- a/model.py +++ b/model.py @@ -35,18 +35,29 @@ class Model(gobject.GObject): gobject.GObject.__init__(self) self.data = {} self.data['shared_links'] = [] + self.data['deleted'] = [] + + def add_link(self, url, title, thumb, owner, color, timestamp): + index = len(self.data['shared_links']) + for item in self.data['shared_links']: + if timestamp <= item['timestamp']: + index = self.data['shared_links'].index(item) + break + + self.data['shared_links'].insert(index, + {'hash':sha.new(str(url)).hexdigest(), + 'url':str(url), 'title':str(title), + 'thumb':base64.b64encode(thumb), + 'owner':str(owner), 'color':str(color), + 'timestamp':float(timestamp)} ) + self.emit('add_link', index) - def add_link(self, url, title, thumb, owner, color): - self.data['shared_links'].append( {'hash':sha.new(str(url)).hexdigest(), - 'url':str(url), 'title':str(title), - 'thumb':base64.b64encode(thumb), - 'owner':str(owner), - 'color':str(color), 'deleted':0} ) - self.emit('add_link', len(self.data['shared_links'])-1) - - def mark_link_deleted(self, index): - self.data['shared_links'][index]['deleted'] = 1 - self.data['shared_links'][index]['thumb'] = '' + def remove_link(self, hash): + for link in self.data['shared_links']: + if link['hash'] == hash: + self.data['deleted'].append(link['hash']) + self.data['shared_links'].remove(link) + break def serialize(self): return json.write(self.data) @@ -58,6 +69,7 @@ class Model(gobject.GObject): ids = [] for link in self.data['shared_links']: ids.append(link['hash']) + ids.extend(self.data['deleted']) ids.append('') return ids diff --git a/webactivity.py b/webactivity.py index 8222a8a..1cdf90c 100755 --- a/webactivity.py +++ b/webactivity.py @@ -22,7 +22,8 @@ import gtk import dbus import sha import base64 - +import time + from sugar.activity import activity from sugar import env from sugar.graphics import style @@ -257,7 +258,7 @@ class WebActivity(activity.Activity): def _title_changed_cb(self, embed, pspec): if embed.props.title is not '': - #self.set_title(embed.props.title) + # self.set_title(embed.props.title) _logger.debug('Title changed=%s' % embed.props.title) self.webtitle = embed.props.title _sugarext.set_prgname("org.laptop.WebActivity") @@ -271,16 +272,13 @@ class WebActivity(activity.Activity): f.close() self.model.deserialize(data) - i=0 for link in self.model.data['shared_links']: _logger.debug('read: url=%s title=%s d=%s' % (link['url'], link['title'], link['color'])) - if link['deleted'] == 0: - self._add_link_totray(link['url'], base64.b64decode(link['thumb']), - link['color'], link['title'], - link['owner'], i) - i+=1 + self._add_link_totray(link['url'], base64.b64decode(link['thumb']), + link['color'], link['title'], + link['owner'], -1, link['hash']) self._browser.set_session(self.model.data['history']) else: self._browser.load_uri(file_path) @@ -321,35 +319,41 @@ class WebActivity(activity.Activity): def _add_link(self): ''' take screenshot and add link info to the model ''' + for link in self.model.data['shared_links']: + if link['hash'] == sha.new(self.current).hexdigest(): + _logger.debug('_add_link: link exist already') + return buffer = self._get_screenshot() - self.model.add_link( self.current, self.webtitle, buffer, - self.owner.props.nick, self.owner.props.color) + timestamp = time.time() + self.model.add_link(self.current, self.webtitle, buffer, + self.owner.props.nick, self.owner.props.color, + timestamp) if self.messenger is not None: self.messenger._add_link(self.current, self.webtitle, self.owner.props.color, self.owner.props.nick, - base64.b64encode(buffer)) + base64.b64encode(buffer), timestamp) - def _add_link_model_cb(self, model, index): + def _add_link_model_cb(self, model, index): ''' receive index of new link from the model ''' link = self.model.data['shared_links'][index] self._add_link_totray(link['url'], base64.b64decode(link['thumb']), link['color'], link['title'], - link['owner'], index) + link['owner'], index, link['hash']) - def _add_link_totray(self, url, buffer, color, title, owner, index): + def _add_link_totray(self, url, buffer, color, title, owner, index, hash): ''' add a link to the tray ''' - item = LinkButton(url, buffer, color, title, owner, index) + item = LinkButton(url, buffer, color, title, owner, index, hash) item.connect('clicked', self._link_clicked_cb, url) item.connect('remove_link', self._link_removed_cb) - self._tray.add_item(item, 0) # add to the beginning of the tray + self._tray.add_item(item, index) # use index to add to the tray item.show() self.tray_isvisible = True - def _link_removed_cb(self, button, index): - ''' remove a link from tray and mark deleted in the model ''' - self.model.mark_link_deleted(index) + def _link_removed_cb(self, button, hash): + ''' remove a link from tray and delete it in the model ''' + self.model.remove_link(hash) self._tray.remove_item(button) def _link_clicked_cb(self, button, url): -- cgit v0.9.1