11 |
11 |
12 from PyQt6.QtCore import QDateTime, QFile, QIODevice, QObject |
12 from PyQt6.QtCore import QDateTime, QFile, QIODevice, QObject |
13 |
13 |
14 from eric7 import Utilities |
14 from eric7 import Utilities |
15 |
15 |
16 from .BookmarkNode import BookmarkNode |
16 from .BookmarkNode import BookmarkNode, BookmarkNodeType |
17 |
17 |
18 |
18 |
19 class NsHtmlReader(QObject): |
19 class NsHtmlReader(QObject): |
20 """ |
20 """ |
21 Class implementing a reader object for Netscape HTML bookmark files. |
21 Class implementing a reader object for Netscape HTML bookmark files. |
53 if isinstance(fileNameOrDevice, QIODevice): |
53 if isinstance(fileNameOrDevice, QIODevice): |
54 dev = fileNameOrDevice |
54 dev = fileNameOrDevice |
55 else: |
55 else: |
56 f = QFile(fileNameOrDevice) |
56 f = QFile(fileNameOrDevice) |
57 if not f.exists(): |
57 if not f.exists(): |
58 return BookmarkNode(BookmarkNode.Root) |
58 return BookmarkNode(BookmarkNodeType.Root) |
59 f.open(QIODevice.OpenModeFlag.ReadOnly) |
59 f.open(QIODevice.OpenModeFlag.ReadOnly) |
60 dev = f |
60 dev = f |
61 |
61 |
62 folders = [] |
62 folders = [] |
63 lastNode = None |
63 lastNode = None |
64 |
64 |
65 root = BookmarkNode(BookmarkNode.Root) |
65 root = BookmarkNode(BookmarkNodeType.Root) |
66 folders.append(root) |
66 folders.append(root) |
67 |
67 |
68 while not dev.atEnd(): |
68 while not dev.atEnd(): |
69 line = str(dev.readLine(), encoding="utf-8").rstrip() |
69 line = str(dev.readLine(), encoding="utf-8").rstrip() |
70 match = ( |
70 match = ( |
79 |
79 |
80 if match.re is self.__folderRx: |
80 if match.re is self.__folderRx: |
81 # folder definition |
81 # folder definition |
82 arguments = match.group(1) |
82 arguments = match.group(1) |
83 name = match.group(2) |
83 name = match.group(2) |
84 node = BookmarkNode(BookmarkNode.Folder, folders[-1]) |
84 node = BookmarkNode(BookmarkNodeType.Folder, folders[-1]) |
85 node.title = Utilities.html_udecode(name) |
85 node.title = Utilities.html_udecode(name) |
86 node.expanded = self.__foldedRx.search(arguments) is None |
86 node.expanded = self.__foldedRx.search(arguments) is None |
87 addedMatch = self.__addedRx.search(arguments) |
87 addedMatch = self.__addedRx.search(arguments) |
88 if addedMatch is not None: |
88 if addedMatch is not None: |
89 node.added = QDateTime.fromSecsSinceEpoch(int(addedMatch.group(1))) |
89 node.added = QDateTime.fromSecsSinceEpoch(int(addedMatch.group(1))) |
96 |
96 |
97 elif match.re is self.__bookmarkRx: |
97 elif match.re is self.__bookmarkRx: |
98 # bookmark definition |
98 # bookmark definition |
99 arguments = match.group(1) |
99 arguments = match.group(1) |
100 name = match.group(2) |
100 name = match.group(2) |
101 node = BookmarkNode(BookmarkNode.Bookmark, folders[-1]) |
101 node = BookmarkNode(BookmarkNodeType.Bookmark, folders[-1]) |
102 node.title = Utilities.html_udecode(name) |
102 node.title = Utilities.html_udecode(name) |
103 match1 = self.__urlRx.search(arguments) |
103 match1 = self.__urlRx.search(arguments) |
104 if match1 is not None: |
104 if match1 is not None: |
105 node.url = match1.group(1) |
105 node.url = match1.group(1) |
106 match1 = self.__addedRx.search(arguments) |
106 match1 = self.__addedRx.search(arguments) |