diff -r ae9232bf4854 -r 1193fc2bf192 src/eric7/WebBrowser/Bookmarks/BookmarksImporters/ChromeImporter.py --- a/src/eric7/WebBrowser/Bookmarks/BookmarksImporters/ChromeImporter.py Wed Nov 09 15:18:07 2022 +0100 +++ b/src/eric7/WebBrowser/Bookmarks/BookmarksImporters/ChromeImporter.py Fri Nov 11 15:30:47 2022 +0100 @@ -22,20 +22,20 @@ """ Module function to get information for the given source id. - @param sourceId id of the browser ("chrome" or "chromium") - @return tuple with an icon (QPixmap), readable name (string), name of - the default bookmarks file (string), an info text (string), - a prompt (string) and the default directory of the bookmarks file - (string) + @param sourceId id of the browser ("chrome", "chromium" or "edge") + @type str + @return tuple with an icon, readable name, name of the default bookmarks file, + an info text, a prompt and the default directory of the bookmarks file + @rtype tuple of (QPixmap, str, str, str, str, str) @exception ValueError raised to indicate an invalid browser ID """ - if sourceId not in ("chrome", "chromium"): + if sourceId not in ("chrome", "chromium", "edge", "falkon", "opera", "vivaldi"): raise ValueError("Unsupported browser ID given ({0}).".format(sourceId)) if sourceId == "chrome": if Globals.isWindowsPlatform(): standardDir = os.path.expandvars( - "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\" "User Data\\Default" + "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\Default" ) elif Globals.isMacPlatform(): standardDir = os.path.expanduser( @@ -59,10 +59,11 @@ ), standardDir, ) - else: + + elif sourceId == "chromium": if Globals.isWindowsPlatform(): standardDir = os.path.expandvars( - "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\" "User Data\\Default" + "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\Default" ) else: standardDir = os.path.expanduser("~/.config/chromium/Default") @@ -82,6 +83,125 @@ standardDir, ) + elif sourceId == "edge": + if Globals.isWindowsPlatform(): + standardDir = os.path.expandvars( + "%USERPROFILE%\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default" + ) + else: + standardDir = os.path.expanduser("~/.config/microsoft-edge/Default") + return ( + EricPixmapCache.getPixmap("edge"), + "Microsoft Edge", + "Bookmarks", + QCoreApplication.translate( + "ChromeImporter", + """Microsoft Edge stores its bookmarks in the""" + """ <b>Bookmarks</b> text file. This file is usually""" + """ located in""", + ), + QCoreApplication.translate( + "ChromeImporter", + """Please choose the file to begin importing bookmarks.""", + ), + standardDir, + ) + + elif sourceId == "falkon": + if Globals.isWindowsPlatform(): + standardDir = os.path.expandvars( + "%USERPROFILE%\\AppData\\Local\\falkon\\profiles\\default" + ) + else: + standardDir = os.path.expanduser("~/.config/falkon/profiles/default") + return ( + EricPixmapCache.getPixmap("falkon"), + "Falkon", + "bookmarks.json", + QCoreApplication.translate( + "ChromeImporter", + """Falkon stores its bookmarks in the""" + """ <b>bookmarks.json</b> text file. This file is usually""" + """ located in""", + ), + QCoreApplication.translate( + "ChromeImporter", + """Please choose the file to begin importing bookmarks.""", + ), + standardDir, + ) + + elif sourceId == "opera": + if Globals.isWindowsPlatform(): + standardDir = os.path.expandvars( + "%USERPROFILE%\\AppData\\Roaming\\Opera Software\\Opera Stable" + ) + else: + standardDir = os.path.expanduser("~/.config/opera") + return ( + EricPixmapCache.getPixmap("opera"), + "Opera", + "Bookmarks", + QCoreApplication.translate( + "ChromeImporter", + """Opera stores its bookmarks in the""" + """ <b>Bookmarks</b> text file. This file is usually""" + """ located in""", + ), + QCoreApplication.translate( + "ChromeImporter", + """Please choose the file to begin importing bookmarks.""", + ), + standardDir, + ) + + elif sourceId == "vivaldi": + if Globals.isWindowsPlatform(): + standardDir = os.path.expandvars( + "%USERPROFILE%\\AppData\\Local\\Vivaldi\\User Data\\Default" + ) + else: + standardDir = os.path.expanduser("~/.config/vivaldi/Default") + return ( + EricPixmapCache.getPixmap("vivaldi"), + "Vivaldi", + "Bookmarks", + QCoreApplication.translate( + "ChromeImporter", + """Vivaldi stores its bookmarks in the""" + """ <b>Bookmarks</b> text file. This file is usually""" + """ located in""", + ), + QCoreApplication.translate( + "ChromeImporter", + """Please choose the file to begin importing bookmarks.""", + ), + standardDir, + ) + + # entry if an unknown source is given + standardDir = ( + os.path.expandvars("%USERPROFILE%\\AppData") + if Globals.isWindowsPlatform() + else os.path.expanduser("~/.config") + ) + return ( + EricPixmapCache.getPixmap("chrome_unknown"), + "Unknown Chrome", + "Bookmarks", + QCoreApplication.translate( + "ChromeImporter", + """This browser stores its bookmarks in the""" + """ <b>Bookmarks</b> text file. This file is usually""" + """ located somewhere below""", + ), + QCoreApplication.translate( + "ChromeImporter", + """Please choose the file to begin importing bookmarks.""", + ), + standardDir, + ) + class ChromeImporter(BookmarksImporter): """ @@ -151,7 +271,7 @@ importRootNode.title = self.tr("Chromium Import") else: importRootNode.title = self.tr("Imported {0}").format( - QDate.currentDate().toString(Qt.DateFormat.SystemLocaleShortDate) + QDate.currentDate().toString(Qt.DateFormat.ISODate) ) return importRootNode @@ -162,11 +282,20 @@ @param data dictionary with the bookmarks data (dict) @param rootNode node to add the bookmarks to (BookmarkNode) """ - for node in data.values(): - if node["type"] == "folder": - self.__generateFolderNode(node, rootNode) - elif node["type"] == "url": - self.__generateUrlNode(node, rootNode) + for key, node in data.items(): + if "type" in node: + if node["type"] == "folder": + self.__generateFolderNode(node, rootNode) + elif node["type"] == "url": + self.__generateUrlNode(node, rootNode) + else: + if key == "custom_root": + # Opera bookmarks contain this + data = { + "name": "Custom bookmarks", + "children": list(node.values()), + } + self.__generateFolderNode(data, rootNode) def __generateFolderNode(self, data, rootNode): """