]> git.phdru.name Git - bookmarks_db.git/blobdiff - Storage/bkmk_stjson.py
Comments are always strings.
[bookmarks_db.git] / Storage / bkmk_stjson.py
index cd6139faa36c66afdaf65c57deb479e13e46b99f..d44e1114a15a9705b794f6b78413e5800c1b08f9 100644 (file)
@@ -39,6 +39,8 @@ class storage_json(Walker):
         dict["lastModified"] = f.last_modified
         parent_idx = getattr(f, 'parent_idx')
         if parent_idx: dict["parent"] = parent_idx
+        root = getattr(f, 'root')
+        if root: dict["root"] = root
         dict["title"] = f.name.decode('utf-8')
         dict["type"] = "text/x-moz-place-container"
         self.folder_stack[-1].append(dict)
@@ -63,7 +65,17 @@ class storage_json(Walker):
         dict["parent"] = b.parent_idx
         dict["title"] = b.name.decode('utf-8')
         dict["type"] = "text/x-moz-place"
-        dict["uri"] = b.href
+        dict["uri"] = uri = b.href
+        if uri.startswith('place:'):
+            if uri.startswith('place:sort=8'):
+                value = 'MostVisited'
+            elif uri.startswith('place:folder=BOOKMARKS_MENU'):
+                value = 'RecentlyBookmarked'
+            elif uri.startswith('place:sort=14'):
+                value = 'RecentTags'
+            dict["annos"] = make_annos(value, name='Places/SmartBookmark')
+            del dict["dateAdded"]
+            del dict["lastModified"]
         self.folder_stack[-1].append(dict)
 
     def ruler(self, r, level):
@@ -118,6 +130,7 @@ class storage_json(Walker):
         folder.id = fdict["id"]
         folder.index = fdict.get("index")
         folder.parent_idx = fdict.get("parent")
+        folder.root = fdict.get("root")
         folder.name = encode(fdict["title"])
 
         for record in fdict["children"]:
@@ -170,20 +183,20 @@ def encode(title):
 
 def get_comment(annos):
     if not annos:
-        return None
+        return ''
 
     for a in annos:
         if a["name"] == "bookmarkProperties/description" and \
                 a["type"] == 3:
             return a["value"].encode('utf-8')
 
-    return None
+    return ''
 
-def make_annos(comment):
+def make_annos(value, name="bookmarkProperties/description"):
     return [{
         "expires": 4,
         "flags": 0,
         "mimeType": None,
-        "name": "bookmarkProperties/description",
+        "name": name,
         "type": 3,
-        "value": comment.decode('utf-8')}]
+        "value": value.decode('utf-8')}]