conduit r1911 - in trunk: . conduit/modules/Firefox3Module po
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1911 - in trunk: . conduit/modules/Firefox3Module po
- Date: Tue, 24 Feb 2009 22:29:09 +0000 (UTC)
Author: jstowers
Date: Tue Feb 24 22:29:09 2009
New Revision: 1911
URL: http://svn.gnome.org/viewvc/conduit?rev=1911&view=rev
Log:
2009-02-25 John Stowers <john stowers gmail com>
* conduit/modules/Firefox3Module/Firefox3Module.py:
* conduit/modules/Firefox3Module/Makefile.am:
* conduit/modules/Firefox3Module/config.glade:
Port to new config system.
Removed:
trunk/conduit/modules/Firefox3Module/config.glade
Modified:
trunk/ChangeLog
trunk/conduit/modules/Firefox3Module/Firefox3Module.py
trunk/conduit/modules/Firefox3Module/Makefile.am
trunk/po/POTFILES.in
Modified: trunk/conduit/modules/Firefox3Module/Firefox3Module.py
==============================================================================
--- trunk/conduit/modules/Firefox3Module/Firefox3Module.py (original)
+++ trunk/conduit/modules/Firefox3Module/Firefox3Module.py Tue Feb 24 22:29:09 2009
@@ -1,139 +1,94 @@
# Copyright 2009 - Andrew Stormont <andyjstormont googlemail com>
-import os
-from ConfigParser import ConfigParser
+import os.path
+import ConfigParser
import sqlite3
import logging
+log = logging.getLogger("modules.Firefox3")
+
+from gettext import gettext as _
+
import conduit
import conduit.dataproviders.DataProvider as DataProvider
import conduit.utils as Utils
-from conduit.datatypes.Bookmark import Bookmark
+import conduit.datatypes.Bookmark as Bookmark
import conduit.Exceptions as Exceptions
-log = logging.getLogger("modules.Firefox3")
-
MODULES = {
"Firefox3DataProviderSource" : { "type" : "dataprovider" },
}
-class Firefox3DataProviderSource( DataProvider.DataSource ):
+class Firefox3DataProviderSource(DataProvider.DataSource):
"""
Firefox 3 Bookmarks datasource
"""
- _name_ = "Firefox 3 Bookmarks"
- _description_ = "Syncronize your Firefox 3 Bookmarks"
+ _name_ = _("Firefox 3 Bookmarks")
+ _description_ = _("Syncronize your Firefox 3 Bookmarks")
_category_ = conduit.dataproviders.CATEGORY_BOOKMARKS
_module_type_ = "source"
_out_type_ = "bookmark"
_icon_ = "applications-internet"
_configurable_ = True
- # nasty constants
- SYNCERROR = "Can't read Firefox 3 Bookmarks - please make sure Firefox is closed."
- ( BOOKMARKS_ROOT, BOOKMARKS_MENU, BOOKMARKS_TOOLBAR ) = range( 1,4 )
-
- def __init__( self ):
- self.Bookmarks = []
-
- self.FirefoxDir = os.path.expanduser( "~/.mozilla/firefox/" )
- self.Cf = ConfigParser()
- self.Cf.read( self.FirefoxDir + "profiles.ini" )
- self.ProfilePath = self.Cf.get( "Profile0", "Path" ) # default
- DataProvider.DataSource.__init__( self )
+ BOOKMARKS_ROOT, BOOKMARKS_MENU, BOOKMARKS_TOOLBAR = range(1,4)
- def refresh( self ):
- # sqlite3 is not thread safe, so we cannot preserve connections in this class
- Con = sqlite3.connect( self.FirefoxDir + self.ProfilePath + "/places.sqlite" )
- try:
- Cur = Con.execute( "select * from moz_bookmarks" )
- except:
- log.debug( self.SYNCERROR )
- raise Exceptions.SyncronizeError( self.SYNCERROR )
- for Line in Cur.fetchall():
- ( bid, btype, fk, parent, position, title, keywordid, folder_type, dateadded, lastmodified ) = Line
- if not fk:
- # this bookmark has no url, that means it's a folder or something firefox specific
- continue
- else:
- bookmark = Bookmark( title, self.get_bookmark_url_from_fk( fk ) )
- bookmark.set_UID( bookmark.get_hash() )
- self.Bookmarks.append( bookmark )
- Con.close()
- DataProvider.DataSource.refresh( self )
+ def __init__(self):
+ DataProvider.DataSource.__init__(self)
+
+ self._bookmarks = []
+ self._ffdir = os.path.expanduser(os.path.join("~",".mozilla","firefox"))
+ self._cf = ConfigParser.ConfigParser()
+ self._cf.read(os.path.join(self._ffdir,"profiles.ini"))
+
+ self.update_configuration(
+ profilepath = self._cf.get("Profile0", "Path") # default
+ )
- def get_all( self ):
- DataProvider.DataSource.get_all( self )
+ def _get_profiles(self):
retval = []
- for bookmark in self.Bookmarks:
- retval.append( bookmark.get_UID() )
+ for section in self._cf.sections():
+ if section != "General":
+ retval.append((self._cf.get(section, "Name"), self._cf.get(section, "Path")))
return retval
- def get( self, luid ):
- DataProvider.DataSource.get( self, luid )
- for bookmark in self.Bookmarks:
- if bookmark.get_UID() == luid:
- return bookmark
-
- def get_bookmark_url_from_fk( self, fk ):
- Con = sqlite3.connect( self.FirefoxDir + self.ProfilePath + "/places.sqlite" )
+ def refresh(self):
+ DataProvider.DataSource.refresh(self)
+ # sqlite3 is not thread safe, so we cannot preserve connections in this class
+ con = sqlite3.connect(os.path.join(self._ffdir,self.profilepath,"places.sqlite"))
try:
- Cur = Con.execute( "select * from moz_places" )
+ # table structure
+ # moz_bookmarks: id|type|fk|parent|position|title|keyword_id|folder_type|dateAdded|lastModified
+ # moz_places: id|url|title|rev_host|visit_count|hidden|typed|favicon_id|frecency
+ cur = con.execute("SELECT b.title,p.url FROM moz_bookmarks b, moz_places p WHERE b.fk=p.id;")
except:
- log.debug( self.SYNCERROR )
- raise Exceptions.SyncronizeError( self.SYNCERROR )
- retval = None
- for Line in Cur.fetchall():
- ( bid, url, title, host, visits, hidden, typed, faviconid, frecency ) = Line
- if bid == fk:
- retval = url
- break
- Con.close()
- return retval
-
- def configure( self, window ):
- # thanks to the evolution module for some of this
- import gtk
- tree = Utils.dataprovider_glade_get_widget(
- __file__,
- "config.glade",
- "Firefox3ConfigDialog"
- )
-
- sourceComboBox = tree.get_widget("profileComboBox")
- store = gtk.ListStore( str, str )
- sourceComboBox.set_model(store)
-
- cell = gtk.CellRendererText()
- sourceComboBox.pack_start(cell, True)
- sourceComboBox.add_attribute(cell, 'text', 0)
- sourceComboBox.set_active(0)
-
- for profilename, profilepath in self.get_profiles():
- rowref = store.append( ( profilename, profilepath ) )
- if profilepath == self.ProfilePath:
- sourceComboBox.set_active_iter(rowref)
-
- dlg = tree.get_widget("Firefox3ConfigDialog")
-
- response = Utils.run_dialog (dlg, window)
- if response == True:
- self.ProfilePath = store.get_value(sourceComboBox.get_active_iter(), 1)
- dlg.destroy()
+ con.close()
+ raise Exceptions.SyncronizeError("Can't read Firefox 3 Bookmarks - Make sure Firefox is closed.")
+ for (title, url) in cur.fetchall():
+ bookmark = Bookmark.Bookmark(title, url)
+ bookmark.set_UID(bookmark.get_hash())
+ self._bookmarks.append(bookmark)
+ con.close()
- def get_profiles( self ):
+ def get_all(self):
+ DataProvider.DataSource.get_all(self)
retval = []
- for section in self.Cf.sections():
- if section != "General":
- retval.append( ( self.Cf.get( section, "Name" ), self.Cf.get( section, "Path" ) ) )
+ for bookmark in self._bookmarks:
+ retval.append(bookmark.get_UID())
return retval
- def get_configuration(self):
- return { "ProfilePath" : self.ProfilePath }
+ def get(self, luid):
+ DataProvider.DataSource.get(self, luid)
+ for bookmark in self._bookmarks:
+ if bookmark.get_UID() == luid:
+ return bookmark
- def set_configuration(self, config):
- self.ProfilePath = config.get( "ProfilePath", self.ProfilePath )
+ def config_setup(self, config):
+ config.add_item(_("Firefox Profile"), "combo",
+ config_name = "profilepath",
+ choices = [(path, name) for name, path in self._get_profiles()]
+ )
- def get_UID( self ):
- return "Firefox3Module"
+ def get_UID(self):
+ return Utils.get_user_string()
Modified: trunk/conduit/modules/Firefox3Module/Makefile.am
==============================================================================
--- trunk/conduit/modules/Firefox3Module/Makefile.am (original)
+++ trunk/conduit/modules/Firefox3Module/Makefile.am Tue Feb 24 22:29:09 2009
@@ -1,8 +1,5 @@
conduit_handlersdir = $(libdir)/conduit/modules/Firefox3Module
-conduit_handlers_DATA = config.glade
conduit_handlers_PYTHON = Firefox3Module.py
-EXTRA_DIST = config.glade
-
clean-local:
rm -rf *.pyc *.pyo
Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in (original)
+++ trunk/po/POTFILES.in Tue Feb 24 22:29:09 2009
@@ -46,5 +46,4 @@
conduit/modules/SmugMugModule/config.glade
conduit/modules/ZotoModule/ZotoModule.py
conduit/modules/ZotoModule/zoto.glade
-conduit/modules/Firefox3Module/config.glade
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]