33 Public method to write an Netscape HTML bookmark file. |
34 Public method to write an Netscape HTML bookmark file. |
34 |
35 |
35 @param fileNameOrDevice name of the file to write (string) |
36 @param fileNameOrDevice name of the file to write (string) |
36 or device to write to (QIODevice) |
37 or device to write to (QIODevice) |
37 @param root root node of the bookmark tree (BookmarkNode) |
38 @param root root node of the bookmark tree (BookmarkNode) |
|
39 @return flag indicating success (boolean) |
38 """ |
40 """ |
39 if isinstance(fileNameOrDevice, QIODevice): |
41 if isinstance(fileNameOrDevice, QIODevice): |
40 f = fileNameOrDevice |
42 f = fileNameOrDevice |
41 else: |
43 else: |
42 f = QFile(fileNameOrDevice) |
44 f = QFile(fileNameOrDevice) |
49 def __write(self, root): |
51 def __write(self, root): |
50 """ |
52 """ |
51 Private method to write an Netscape HTML bookmark file. |
53 Private method to write an Netscape HTML bookmark file. |
52 |
54 |
53 @param root root node of the bookmark tree (BookmarkNode) |
55 @param root root node of the bookmark tree (BookmarkNode) |
|
56 @return flag indicating success (boolean) |
54 """ |
57 """ |
55 self.__dev.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n" |
58 self.__dev.write("<!DOCTYPE NETSCAPE-Bookmark-file-1>\n" |
56 "<!-- This is an automatically generated file.\n" |
59 "<!-- This is an automatically generated file.\n" |
57 " It will be read and overwritten.\n" |
60 " It will be read and overwritten.\n" |
58 " DO NOT EDIT! -->\n" |
61 " DO NOT EDIT! -->\n" |
59 "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">\n" |
62 "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;" |
|
63 " charset=UTF-8\">\n" |
60 "<TITLE>Bookmarks</TITLE>\n" |
64 "<TITLE>Bookmarks</TITLE>\n" |
61 "<H1>Bookmarks</H1>\n" |
65 "<H1>Bookmarks</H1>\n" |
62 "\n" |
66 "\n" |
63 "<DL><p>\n") |
67 "<DL><p>\n") |
64 if root.type() == BookmarkNode.Root: |
68 if root.type() == BookmarkNode.Root: |
102 if node.added.isValid(): |
106 if node.added.isValid(): |
103 added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t()) |
107 added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t()) |
104 else: |
108 else: |
105 added = "" |
109 added = "" |
106 if node.modified.isValid(): |
110 if node.modified.isValid(): |
107 modified = " LAST_MODIFIED=\"{0}\"".format(node.modified.toTime_t()) |
111 modified = " LAST_MODIFIED=\"{0}\"".format( |
|
112 node.modified.toTime_t()) |
108 else: |
113 else: |
109 modified = "" |
114 modified = "" |
110 if node.visited.isValid(): |
115 if node.visited.isValid(): |
111 visited = " LAST_VISIT=\"{0}\"".format(node.visited.toTime_t()) |
116 visited = " LAST_VISIT=\"{0}\"".format(node.visited.toTime_t()) |
112 else: |
117 else: |
113 visited = "" |
118 visited = "" |
114 |
119 |
115 self.__dev.write(" " * indent) |
120 self.__dev.write(" " * indent) |
116 self.__dev.write("<DT><A HREF=\"{0}\"{1}{2}{3}>{4}</A>\n".format( |
121 self.__dev.write("<DT><A HREF=\"{0}\"{1}{2}{3}>{4}</A>\n".format( |
117 node.url, added, modified, visited, Utilities.html_uencode(node.title) |
122 node.url, added, modified, visited, |
|
123 Utilities.html_uencode(node.title) |
118 )) |
124 )) |
119 |
125 |
120 if node.desc: |
126 if node.desc: |
121 self.__dev.write(" " * indent) |
127 self.__dev.write(" " * indent) |
122 self.__dev.write("<DD>{0}\n".format( |
128 self.__dev.write("<DD>{0}\n".format( |
144 folded, added, Utilities.html_uencode(node.title) |
150 folded, added, Utilities.html_uencode(node.title) |
145 )) |
151 )) |
146 |
152 |
147 if node.desc: |
153 if node.desc: |
148 self.__dev.write(" " * indent) |
154 self.__dev.write(" " * indent) |
149 self.__dev.write("<DD>{0}\n".format("".join(node.desc.splitlines()))) |
155 self.__dev.write("<DD>{0}\n".format( |
|
156 "".join(node.desc.splitlines()))) |
150 |
157 |
151 self.__dev.write(" " * indent) |
158 self.__dev.write(" " * indent) |
152 self.__dev.write("<DL><p>\n") |
159 self.__dev.write("<DL><p>\n") |
153 |
160 |
154 for child in node.children(): |
161 for child in node.children(): |