17 |
17 |
18 |
18 |
19 def getImporterInfo(sourceId): |
19 def getImporterInfo(sourceId): |
20 """ |
20 """ |
21 Module function to get information for the given HTML source id. |
21 Module function to get information for the given HTML source id. |
22 |
22 |
23 @param sourceId id of the browser ("chrome" or "chromium") |
23 @param sourceId id of the browser ("chrome" or "chromium") |
24 @return tuple with an icon (QPixmap), readable name (string), name of |
24 @return tuple with an icon (QPixmap), readable name (string), name of |
25 the default bookmarks file (string), an info text (string), |
25 the default bookmarks file (string), an info text (string), |
26 a prompt (string) and the default directory of the bookmarks file |
26 a prompt (string) and the default directory of the bookmarks file |
27 (string) |
27 (string) |
28 @exception ValueError raised to indicate an invalid browser ID |
28 @exception ValueError raised to indicate an invalid browser ID |
29 """ |
29 """ |
30 if sourceId != "html": |
30 if sourceId != "html": |
31 raise ValueError( |
31 raise ValueError("Unsupported browser ID given ({0}).".format(sourceId)) |
32 "Unsupported browser ID given ({0}).".format(sourceId)) |
32 |
33 |
|
34 return ( |
33 return ( |
35 UI.PixmapCache.getPixmap("html"), |
34 UI.PixmapCache.getPixmap("html"), |
36 "HTML Netscape Bookmarks", |
35 "HTML Netscape Bookmarks", |
37 QCoreApplication.translate( |
36 QCoreApplication.translate("HtmlImporter", "HTML Netscape Bookmarks") |
38 "HtmlImporter", |
37 + " (*.htm *.html)", |
39 "HTML Netscape Bookmarks") + " (*.htm *.html)", |
|
40 QCoreApplication.translate( |
38 QCoreApplication.translate( |
41 "HtmlImporter", |
39 "HtmlImporter", |
42 """You can import bookmarks from any browser that supports""" |
40 """You can import bookmarks from any browser that supports""" |
43 """ HTML exporting. This file has usually the extension""" |
41 """ HTML exporting. This file has usually the extension""" |
44 """ .htm or .html."""), |
42 """ .htm or .html.""", |
|
43 ), |
45 QCoreApplication.translate( |
44 QCoreApplication.translate( |
46 "HtmlImporter", |
45 "HtmlImporter", """Please choose the file to begin importing bookmarks.""" |
47 """Please choose the file to begin importing bookmarks."""), |
46 ), |
48 "", |
47 "", |
49 ) |
48 ) |
50 |
49 |
51 |
50 |
52 class HtmlImporter(BookmarksImporter): |
51 class HtmlImporter(BookmarksImporter): |
53 """ |
52 """ |
54 Class implementing the HTML bookmarks importer. |
53 Class implementing the HTML bookmarks importer. |
55 """ |
54 """ |
|
55 |
56 def __init__(self, sourceId="", parent=None): |
56 def __init__(self, sourceId="", parent=None): |
57 """ |
57 """ |
58 Constructor |
58 Constructor |
59 |
59 |
60 @param sourceId source ID (string) |
60 @param sourceId source ID (string) |
61 @param parent reference to the parent object (QObject) |
61 @param parent reference to the parent object (QObject) |
62 """ |
62 """ |
63 super().__init__(sourceId, parent) |
63 super().__init__(sourceId, parent) |
64 |
64 |
65 self.__fileName = "" |
65 self.__fileName = "" |
66 self.__inFile = None |
66 self.__inFile = None |
67 |
67 |
68 def setPath(self, path): |
68 def setPath(self, path): |
69 """ |
69 """ |
70 Public method to set the path of the bookmarks file or directory. |
70 Public method to set the path of the bookmarks file or directory. |
71 |
71 |
72 @param path bookmarks file or directory (string) |
72 @param path bookmarks file or directory (string) |
73 """ |
73 """ |
74 self.__fileName = path |
74 self.__fileName = path |
75 |
75 |
76 def open(self): |
76 def open(self): |
77 """ |
77 """ |
78 Public method to open the bookmarks file. |
78 Public method to open the bookmarks file. |
79 |
79 |
80 @return flag indicating success (boolean) |
80 @return flag indicating success (boolean) |
81 """ |
81 """ |
82 if not os.path.exists(self.__fileName): |
82 if not os.path.exists(self.__fileName): |
83 self._error = True |
83 self._error = True |
84 self._errorString = self.tr( |
84 self._errorString = self.tr("File '{0}' does not exist.").format( |
85 "File '{0}' does not exist." |
85 self.__fileName |
86 ).format(self.__fileName) |
86 ) |
87 return False |
87 return False |
88 return True |
88 return True |
89 |
89 |
90 def importedBookmarks(self): |
90 def importedBookmarks(self): |
91 """ |
91 """ |
92 Public method to get the imported bookmarks. |
92 Public method to get the imported bookmarks. |
93 |
93 |
94 @return imported bookmarks (BookmarkNode) |
94 @return imported bookmarks (BookmarkNode) |
95 """ |
95 """ |
96 from ..BookmarkNode import BookmarkNode |
96 from ..BookmarkNode import BookmarkNode |
97 from ..NsHtmlReader import NsHtmlReader |
97 from ..NsHtmlReader import NsHtmlReader |
98 |
98 |
99 reader = NsHtmlReader() |
99 reader = NsHtmlReader() |
100 importRootNode = reader.read(self.__fileName) |
100 importRootNode = reader.read(self.__fileName) |
101 |
101 |
102 importRootNode.setType(BookmarkNode.Folder) |
102 importRootNode.setType(BookmarkNode.Folder) |
103 if self._id == "html": |
103 if self._id == "html": |
104 importRootNode.title = self.tr("HTML Import") |
104 importRootNode.title = self.tr("HTML Import") |
105 else: |
105 else: |
106 importRootNode.title = self.tr( |
106 importRootNode.title = self.tr("Imported {0}").format( |
107 "Imported {0}" |
107 QDate.currentDate().toString(Qt.DateFormat.SystemLocaleShortDate) |
108 ).format(QDate.currentDate().toString( |
108 ) |
109 Qt.DateFormat.SystemLocaleShortDate)) |
|
110 return importRootNode |
109 return importRootNode |