Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Schampijer <simon@schampijer.de>2007-09-01 10:10:03 (GMT)
committer Simon Schampijer <simon@schampijer.de>2007-09-01 10:10:03 (GMT)
commitcd10c5006fa37eda8cdbb6000b5edfa70d70a37f (patch)
tree1657c20bca6def0d43c27f0867123eaabc6e7d28
parent6ae5e4111a76f9cb8f59ae6dfc9123365df39467 (diff)
more refactoring for using json only
-rw-r--r--model.py12
-rw-r--r--sessionstore.py6
-rwxr-xr-xwebactivity.py41
3 files changed, 27 insertions, 32 deletions
diff --git a/model.py b/model.py
index fdb8ff9..4fdb708 100644
--- a/model.py
+++ b/model.py
@@ -37,14 +37,18 @@ class Model(gobject.GObject):
gobject.GObject.__init__(self)
self.data = {}
- self.links = []
- self.data['shared_links'] = self.links
+ self._links = []
+ self.data['shared_links'] = self._links
def add_link(self, url, title, thumb, owner, color):
self.links.append( {'hash':sha.new(url).hexdigest(), 'url':url, 'title':title, 'thumb':thumb,
'owner':owner, 'color':color, 'deleted':0} )
self.emit('add_link', len(self.links)-1)
-
+
+ def mark_link_deleted(self, index):
+ self._links[index]['deleted'] = 1
+ self._links[index]['thumb'] = ''
+
def serialize(self):
self.get_session()
return json.write(self.data)
@@ -55,7 +59,7 @@ class Model(gobject.GObject):
def get_links_ids(self):
ids = []
- for link in self.links:
+ for link in self._links:
ids.append(link['hash'])
ids.append('')
return ids
diff --git a/sessionstore.py b/sessionstore.py
index 0847976..2b96ea0 100644
--- a/sessionstore.py
+++ b/sessionstore.py
@@ -22,15 +22,11 @@ import logging
from xpcom import components
from xpcom.components import interfaces
-import json
-
-
def get_session(browser):
session_history = browser.web_navigation.sessionHistory
if session_history.count == 0:
- return ''
-
+ return ''
return _get_history(session_history)
def set_session(browser, data):
diff --git a/webactivity.py b/webactivity.py
index b0180db..85ce780 100755
--- a/webactivity.py
+++ b/webactivity.py
@@ -264,7 +264,7 @@ class WebActivity(activity.Activity):
if self.metadata['mime_type'] == 'text/plain':
self.model.deserialize(file_path)
i=0
- for link in self.model.links:
+ for link in self.model['shared_links']:
_logger.debug('read: url=%s title=%s d=%s' % (link['url'],
link['title'],
link['color']))
@@ -289,20 +289,17 @@ class WebActivity(activity.Activity):
if self._browser.props.title:
self.metadata['title'] = self._browser.props.title
- for link in self.model.links:
- _logger.debug('write: url=%s title=%s d=%s' % (link['url'],
- link['title'],
- link['color']))
-
self.model.data['history'] = self._browser.get_session()
# self.model.write(file_path)
def _share_link_button_cb(self, button):
+ _logger.debug('button: Add link: %s.' % self.current)
self._add_link()
def key_press_cb(self, widget, event):
if event.state & gtk.gdk.CONTROL_MASK:
- if gtk.gdk.keyval_name(event.keyval) == "l":
+ if gtk.gdk.keyval_name(event.keyval) == "l":
+ _logger.debug('keyboard: Add link: %s.' % self.current)
self._add_link()
return True
elif gtk.gdk.keyval_name(event.keyval) == "s":
@@ -312,16 +309,11 @@ class WebActivity(activity.Activity):
return False
def _add_link(self):
+ ''' take screenshot and add link info to the model '''
buffer = self._get_screenshot()
- _logger.debug('keyboard: Add link: %s.' % self.current)
- self.model.links.append( {'hash':sha.new(self.current).hexdigest(),
- 'url':self.current, 'title':self.webtitle,
- 'thumb':buffer, 'owner':self.owner.props.nick,
- 'color':self.owner.props.color, 'deleted':0} )
-
- self._add_link_totray(self.current, buffer, self.owner.props.color,
- self.webtitle, self.owner.props.nick,
- len(self.model.links)-1)
+ self.model.add_link( self.current, self.webtitle, buffer,
+ self.owner.props.nick, self.owner.props.color)
+
if self.messenger is not None:
import base64
self.messenger._add_link(self.current, self.webtitle,
@@ -330,25 +322,28 @@ class WebActivity(activity.Activity):
base64.b64encode(buffer))
def _add_link_model_cb(self, model, index):
- link = self.model.links[index]
+ ''' receive index of new link from the model '''
+ link = self.model._links[index]
self._add_link_totray(link['url'], link['thumb'],
link['color'], link['title'],
link['owner'], index)
- def _add_link_totray(self, url, buffer, color, title, owner, index):
+ def _add_link_totray(self, url, buffer, color, title, owner, index):
+ ''' add a link to the tray '''
item = LinkButton(url, buffer, color, title, owner, index)
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
item.show()
- def _link_clicked_cb(self, button, url):
- self._browser.load_uri(url)
-
def _link_removed_cb(self, button, index):
- self.model.links[index]['deleted'] = 1
- self.model.links[index]['thumb'] = ''
+ ''' remove a link from tray and mark deleted in the model '''
+ self.model.mark_link_deleted(index)
self._tray.remove_item(button)
+
+ def _link_clicked_cb(self, button, url):
+ ''' an item of the link tray has been clicked '''
+ self._browser.load_uri(url)
def _toggle_visibility_tray(self):
if self._tray.isvisible is True: