Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/model.py
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2007-09-03 20:14:02 (GMT)
committer Simon Schampijer <simon@schampijer.de>2007-09-03 20:14:02 (GMT)
commitc28b01faa7d2cf454d23904e6cde253ee3455e97 (patch)
tree06e98e420e5fee130f4b4d82e199c67fe2a14e22 /model.py
parent11ac469846e1239f88012c451f355c82374258f9 (diff)
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
Diffstat (limited to 'model.py')
-rw-r--r--model.py34
1 files changed, 23 insertions, 11 deletions
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