108 |
108 |
109 @return flag indicating success (boolean) |
109 @return flag indicating success (boolean) |
110 """ |
110 """ |
111 if not os.path.exists(self.__fileName): |
111 if not os.path.exists(self.__fileName): |
112 self._error = True |
112 self._error = True |
113 self._errorString = self.trUtf8( |
113 self._errorString = self.tr( |
114 "File '{0}' does not exist.").format(self.__fileName) |
114 "File '{0}' does not exist.").format(self.__fileName) |
115 return False |
115 return False |
116 return True |
116 return True |
117 |
117 |
118 def importedBookmarks(self): |
118 def importedBookmarks(self): |
125 f = open(self.__fileName, "r", encoding="utf-8") |
125 f = open(self.__fileName, "r", encoding="utf-8") |
126 contents = json.load(f) |
126 contents = json.load(f) |
127 f.close() |
127 f.close() |
128 except IOError as err: |
128 except IOError as err: |
129 self._error = True |
129 self._error = True |
130 self._errorString = self.trUtf8( |
130 self._errorString = self.tr( |
131 "File '{0}' cannot be read.\nReason: {1}")\ |
131 "File '{0}' cannot be read.\nReason: {1}")\ |
132 .format(self.__fileName, str(err)) |
132 .format(self.__fileName, str(err)) |
133 return None |
133 return None |
134 |
134 |
135 from ..BookmarkNode import BookmarkNode |
135 from ..BookmarkNode import BookmarkNode |
136 importRootNode = BookmarkNode(BookmarkNode.Folder) |
136 importRootNode = BookmarkNode(BookmarkNode.Folder) |
137 if contents["version"] == 1: |
137 if contents["version"] == 1: |
138 self.__processRoots(contents["roots"], importRootNode) |
138 self.__processRoots(contents["roots"], importRootNode) |
139 |
139 |
140 if self._id == "chrome": |
140 if self._id == "chrome": |
141 importRootNode.title = self.trUtf8("Google Chrome Import") |
141 importRootNode.title = self.tr("Google Chrome Import") |
142 elif self._id == "chromium": |
142 elif self._id == "chromium": |
143 importRootNode.title = self.trUtf8("Chromium Import") |
143 importRootNode.title = self.tr("Chromium Import") |
144 else: |
144 else: |
145 importRootNode.title = self.trUtf8("Imported {0}")\ |
145 importRootNode.title = self.tr("Imported {0}")\ |
146 .format(QDate.currentDate().toString(Qt.SystemLocaleShortDate)) |
146 .format(QDate.currentDate().toString(Qt.SystemLocaleShortDate)) |
147 return importRootNode |
147 return importRootNode |
148 |
148 |
149 def __processRoots(self, data, rootNode): |
149 def __processRoots(self, data, rootNode): |
150 """ |
150 """ |