Skip to content

Commit

Permalink
Merge remote-tracking branch 'karol/bugs/lp516426_firefox_title'
Browse files Browse the repository at this point in the history
* karol/bugs/lp516426_firefox_title:
  firefox: support tags as subcatalogs of firefox
  firefox: set uri as title when title is null
  obj.UrlLead: add url as leaf alias; use url for name when name is none
  • Loading branch information
bluss committed Jul 4, 2012
2 parents 4c7e177 + cdc3282 commit eb3c767
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
10 changes: 6 additions & 4 deletions kupfer/obj/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def __init__(self, name=None):
if not name:
name = _("Open URL")
super(OpenUrl, self).__init__(name)

def activate(self, leaf):
url = leaf.object
self.open_url(url)

def open_url(self, url):
utils.show_url(url)

Expand All @@ -304,7 +304,7 @@ def __init__(self, name=None, is_running=False, open_new=False):
Action.__init__(self, name)
self.is_running = is_running
self.open_new = open_new

def wants_context(self):
return True

Expand Down Expand Up @@ -352,7 +352,9 @@ def get_icon_name(self):

class UrlLeaf (Leaf, TextRepresentation):
def __init__(self, obj, name):
super(UrlLeaf, self).__init__(obj, name)
super(UrlLeaf, self).__init__(obj, name or obj)
if obj != name:
self.kupfer_add_alias(obj)

def get_actions(self):
return (OpenUrl(), )
Expand Down
33 changes: 30 additions & 3 deletions kupfer/plugin/firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from kupfer import plugin_support
from kupfer.objects import Source
from kupfer.objects import UrlLeaf
from kupfer.objects import UrlLeaf, Leaf
from kupfer.obj.apps import AppLeafContentMixin
from kupfer.obj.helplib import FilesystemWatchMixin
from kupfer.plugin import firefox_support
Expand All @@ -30,6 +30,31 @@
)


class Tag(Leaf):
def __init__(self, name, bookmarks):
Leaf.__init__(self, bookmarks, name)

def has_content(self):
return bool(self.object)

def content_source(self, alternate=False):
return TaggedBookmarksSource(self)

def get_description(self):
return _("Firefox tag")


class TaggedBookmarksSource(Source):
"""docstring for TaggedBookmarksSource"""
def __init__(self, tag):
Source.__init__(self, tag.name)
self.tag = tag

def get_items(self):
for book in self.tag.object:
yield UrlLeaf(book["uri"], book["title"] or book["uri"])


class BookmarksSource (AppLeafContentMixin, Source, FilesystemWatchMixin):
appleaf_content_id = ("firefox", "iceweasel")
def __init__(self):
Expand Down Expand Up @@ -68,9 +93,11 @@ def _get_ffx3_bookmarks(self, fpath):
"""Parse Firefox' .json bookmarks backups"""
from kupfer.plugin import firefox3_support
self.output_debug("Parsing", fpath)
bookmarks = firefox3_support.get_bookmarks(fpath)
bookmarks, tags = firefox3_support.get_bookmarks(fpath)
for book in bookmarks:
yield UrlLeaf(book["uri"], book["title"])
yield UrlLeaf(book["uri"], book["title"] or book["uri"])
for tag, items in tags.iteritems():
yield Tag(tag, items)

def _get_ffx2_bookmarks(self, fpath):
"""Parse Firefox' bookmarks.html"""
Expand Down
11 changes: 9 additions & 2 deletions kupfer/plugin/firefox3_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ def is_good(ch):
visited.add(next["id"])

# visit all tag folders
tags_catalogs = {}
for tag in tagcatalogs:
items = []
for bmark in tag["children"]:
if is_bookmark(bmark) and is_good(bmark):
bmap_add(bmark, bmap)
bmap_add_tag(bmark["id"], tag["title"], bmap)
items.append(bmark)
if items:
tags_catalogs[tag['title']] = items

return bmap.values()
return bmap.values(), tags_catalogs

if __name__ == '__main__':
import os
Expand All @@ -90,4 +95,6 @@ def is_good(ch):
fpath = os.path.join(dirloc, latest_file)

if fpath and os.path.splitext(fpath)[-1].lower() == ".json":
print "Parsed # bookmarks:", len(list(get_bookmarks(fpath)))
bookmarks, tags = get_bookmarks(fpath)
print "Parsed # bookmarks:", len(bookmarks)
print "Parsed # tags:", len(tags)

0 comments on commit eb3c767

Please sign in to comment.