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