Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2008-06-12 20:12:05 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2008-06-12 20:12:05 (GMT)
commitfed5435ca8e69f6b476f31e6ec3a748fa0b02c15 (patch)
treec6547172e004633b7283427541fc7f554ee65700
parent2decba58009262ca6c3855575bc7508235ef269f (diff)
Implement the sqlite store.
-rw-r--r--globalhistory.py18
-rw-r--r--places.py82
-rwxr-xr-xwebactivity.py1
-rwxr-xr-xwebtoolbar.py1
4 files changed, 59 insertions, 43 deletions
diff --git a/globalhistory.py b/globalhistory.py
index 635deca..ae7b999 100644
--- a/globalhistory.py
+++ b/globalhistory.py
@@ -41,13 +41,13 @@ class GlobalHistory:
return place != None
def addURI(self, uri, redirect, toplevel, referrer):
- place = places.Place(uri.spec)
-
- place.redirect = redirect
- place.toplevel = toplevel
- place.referrer = referrer
-
- self._store.add_place(place)
+ place = self._store.lookup_place(uri.spec)
+ if place:
+ place.visits += 1
+ self._store.update_place(place)
+ else:
+ place = places.Place(uri.spec)
+ self._store.add_place(place)
def setPageTitle(self, uri, title):
place = self._store.lookup_place(uri.spec)
@@ -71,10 +71,6 @@ class GlobalHistory:
place.gecko_flags = flags
self._store.update_place(place)
-def init():
- global _global_history
- _global_history = GlobalHistory()
-
components.registrar.registerFactory(GlobalHistory.cid,
GlobalHistory.description,
'@mozilla.org/browser/global-history;2',
diff --git a/places.py b/places.py
index 481c16b..00c6be0 100644
--- a/places.py
+++ b/places.py
@@ -14,59 +14,81 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+import os
+import sqlite3
+
+from sugar.activity import activity
+
_store = None
class Place(object):
- def __init__(self, uri):
+ def __init__(self, uri=None):
self.uri = uri
- self.redirect = False
- self.toplevel = True
- self.referrer = None
self.title = None
self.gecko_flags = 0
self.visits = 0
-class MemoryStore(object):
+class SqliteStore(object):
def __init__(self):
- self._places = {}
+ db_path = os.path.join(activity.get_activity_root(),
+ 'data', 'places.db')
+
+ self._con = sqlite3.connect(db_path)
+ cur = self._con.cursor()
+
+ cur.execute('select * from sqlite_master where name == "places"')
+ if cur.fetchone() == None:
+ cur.execute("""create table places (
+ uri TEXT,
+ title TEXT,
+ gecko_flags INTEGER,
+ visits INTEGER
+ );
+ """)
def search(self, text):
- result = []
- for place in self._places.values():
- if text in place.uri or text in place.title:
- result.append(place)
- return result
+ cur = self._con.cursor()
+
+ text = '%' + text + '%'
+ cur.execute('select * from places where uri like ? or title like ? ' \
+ 'order by visits desc limit 0, 30', (text, text))
+
+ return [_place_from_row(row) for row in cur]
def add_place(self, place):
- self._places[place.uri] = place
+ cur = self._con.cursor()
+
+ cur.execute('insert into places values (?, ?, ?, ?)', \
+ (place.uri, place.title, place.gecko_flags, place.visits))
+
+ self._con.commit()
def lookup_place(self, uri):
- try:
- return self._places[uri]
- except KeyError:
+ cur = self._con.cursor()
+ cur.execute('select * from places where uri=?', (uri,))
+
+ row = cur.fetchone()
+ if row:
+ return _place_from_row(row)
+ else:
return None
def update_place(self, place):
- self._places[place.uri] = place
-
-class SQliteStore(object):
- def __init__(self):
- pass
-
- def search(self, text):
- pass
+ cur = self._con.cursor()
- def add_place(self, place):
- pass
+ cur.execute('update places set title=?, gecko_flags=?, visits=? ' \
+ 'where uri=?', (place.title, place.gecko_flags,
+ place.visits, place.uri))
- def lookup_place(self, uri):
- pass
+ self._con.commit()
- def update_place(self, place):
- pass
+def _place_from_row(row):
+ place = Place()
+ place.uri, place.title, place.gecko_flags, place.visits = row
+ return place
def get_store():
global _store
if _store == None:
- _store = MemoryStore()
+ _store = SqliteStore()
return _store
diff --git a/webactivity.py b/webactivity.py
index 4bf55bd..4b2a2d8 100755
--- a/webactivity.py
+++ b/webactivity.py
@@ -101,7 +101,6 @@ class WebActivity(activity.Activity):
sessionhistory.init(self._browser)
progresslistener.init(self._browser)
filepicker.init(self)
- globalhistory.init()
toolbox = activity.ActivityToolbox(self)
diff --git a/webtoolbar.py b/webtoolbar.py
index ecea25e..2d7a92f 100755
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -159,7 +159,6 @@ class WebEntry(AddressEntry):
def __key_press_event_cb(self, entry, event):
keyname = gtk.gdk.keyval_name(event.keyval)
- logging.info(keyname)
selection = self._search_view.get_selection()
model, selected = selection.get_selected()