23 Module function to get information for the given source id. |
23 Module function to get information for the given source id. |
24 |
24 |
25 @param id id of the browser ("chrome" or "chromium") |
25 @param id id of the browser ("chrome" or "chromium") |
26 @return tuple with an icon (QPixmap), readable name (string), name of |
26 @return tuple with an icon (QPixmap), readable name (string), name of |
27 the default bookmarks file (string), an info text (string), |
27 the default bookmarks file (string), an info text (string), |
28 a prompt (string) and the default directory of the bookmarks file (string) |
28 a prompt (string) and the default directory of the bookmarks file |
|
29 (string) |
29 @exception ValueError raised to indicate an invalid browser ID |
30 @exception ValueError raised to indicate an invalid browser ID |
30 """ |
31 """ |
31 if id == "firefox": |
32 if id == "firefox": |
32 if Globals.isWindowsPlatform(): |
33 if Globals.isWindowsPlatform(): |
33 standardDir = os.path.expandvars( |
34 standardDir = os.path.expandvars( |
40 return ( |
41 return ( |
41 UI.PixmapCache.getPixmap("chrome.png"), |
42 UI.PixmapCache.getPixmap("chrome.png"), |
42 "Mozilla Firefox", |
43 "Mozilla Firefox", |
43 "places.sqlite", |
44 "places.sqlite", |
44 QCoreApplication.translate("FirefoxImporter", |
45 QCoreApplication.translate("FirefoxImporter", |
45 """Mozilla Firefox stores its bookmarks in the <b>places.sqlite</b> """ |
46 """Mozilla Firefox stores its bookmarks in the""" |
46 """SQLite database. This file is usually located in"""), |
47 """ <b>places.sqlite</b> SQLite database. This file is""" |
|
48 """ usually located in"""), |
47 QCoreApplication.translate("FirefoxImporter", |
49 QCoreApplication.translate("FirefoxImporter", |
48 """Please choose the file to begin importing bookmarks."""), |
50 """Please choose the file to begin importing bookmarks."""), |
49 standardDir, |
51 standardDir, |
50 ) |
52 ) |
51 else: |
53 else: |
90 |
92 |
91 try: |
93 try: |
92 self.__db = sqlite3.connect(self.__fileName) |
94 self.__db = sqlite3.connect(self.__fileName) |
93 except sqlite3.DatabaseError as err: |
95 except sqlite3.DatabaseError as err: |
94 self._error = True |
96 self._error = True |
95 self._errorString = self.trUtf8("Unable to open database.\nReason: {0}")\ |
97 self._errorString = self.trUtf8( |
96 .format(str(err)) |
98 "Unable to open database.\nReason: {0}").format(str(err)) |
97 return False |
99 return False |
98 |
100 |
99 return True |
101 return True |
100 |
102 |
101 def importedBookmarks(self): |
103 def importedBookmarks(self): |
125 folder = BookmarkNode(BookmarkNode.Folder, importRootNode) |
127 folder = BookmarkNode(BookmarkNode.Folder, importRootNode) |
126 folder.title = title.replace("&", "&&") |
128 folder.title = title.replace("&", "&&") |
127 folders[id_] = folder |
129 folders[id_] = folder |
128 except sqlite3.DatabaseError as err: |
130 except sqlite3.DatabaseError as err: |
129 self._error = True |
131 self._error = True |
130 self._errorString = self.trUtf8("Unable to open database.\nReason: {0}")\ |
132 self._errorString = self.trUtf8( |
131 .format(str(err)) |
133 "Unable to open database.\nReason: {0}").format(str(err)) |
132 return None |
134 return None |
133 |
135 |
134 try: |
136 try: |
135 cursor = self.__db.cursor() |
137 cursor = self.__db.cursor() |
136 cursor.execute( |
138 cursor.execute( |
141 title = row[1] |
143 title = row[1] |
142 placesId = row[2] |
144 placesId = row[2] |
143 |
145 |
144 cursor2 = self.__db.cursor() |
146 cursor2 = self.__db.cursor() |
145 cursor2.execute( |
147 cursor2.execute( |
146 "SELECT url FROM moz_places WHERE id = {0}".format(placesId)) |
148 "SELECT url FROM moz_places WHERE id = {0}" |
|
149 .format(placesId)) |
147 row2 = cursor2.fetchone() |
150 row2 = cursor2.fetchone() |
148 if row2: |
151 if row2: |
149 url = QUrl(row2[0]) |
152 url = QUrl(row2[0]) |
150 if not title or url.isEmpty() or url.scheme() in ["place", "about"]: |
153 if not title or url.isEmpty() or \ |
|
154 url.scheme() in ["place", "about"]: |
151 continue |
155 continue |
152 |
156 |
153 if parent in folders: |
157 if parent in folders: |
154 bookmark = BookmarkNode(BookmarkNode.Bookmark, folders[parent]) |
158 bookmark = BookmarkNode(BookmarkNode.Bookmark, |
|
159 folders[parent]) |
155 else: |
160 else: |
156 bookmark = BookmarkNode(BookmarkNode.Bookmark, importRootNode) |
161 bookmark = BookmarkNode(BookmarkNode.Bookmark, |
|
162 importRootNode) |
157 bookmark.url = url.toString() |
163 bookmark.url = url.toString() |
158 bookmark.title = title.replace("&", "&&") |
164 bookmark.title = title.replace("&", "&&") |
159 except sqlite3.DatabaseError as err: |
165 except sqlite3.DatabaseError as err: |
160 self._error = True |
166 self._error = True |
161 self._errorString = self.trUtf8("Unable to open database.\nReason: {0}")\ |
167 self._errorString = self.trUtf8( |
162 .format(str(err)) |
168 "Unable to open database.\nReason: {0}").format(str(err)) |
163 return None |
169 return None |
164 |
170 |
165 importRootNode.setType(BookmarkNode.Folder) |
171 importRootNode.setType(BookmarkNode.Folder) |
166 if self._id == "firefox": |
172 if self._id == "firefox": |
167 importRootNode.title = self.trUtf8("Mozilla Firefox Import") |
173 importRootNode.title = self.trUtf8("Mozilla Firefox Import") |