eric6/WebBrowser/Bookmarks/BookmarksImporters/FirefoxImporter.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8143
2c730d5fd177
permissions
-rw-r--r--

Updated copyright for 2021.

1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an importer for Firefox bookmarks.
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
11 import sqlite3
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtCore import QCoreApplication, QDate, Qt, QUrl
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .BookmarksImporter import BookmarksImporter
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import Globals
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
21 def getImporterInfo(sourceId):
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Module function to get information for the given source id.
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
25 @param sourceId id of the browser ("chrome" or "chromium")
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @return tuple with an icon (QPixmap), readable name (string), name of
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 the default bookmarks file (string), an info text (string),
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
28 a prompt (string) and the default directory of the bookmarks file
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
29 (string)
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
30 @exception ValueError raised to indicate an invalid browser ID
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
32 if sourceId == "firefox":
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 if Globals.isWindowsPlatform():
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 standardDir = os.path.expandvars(
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 "%APPDATA%\\Mozilla\\Firefox\\Profiles")
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
36 elif Globals.isMacPlatform():
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
37 standardDir = os.path.expanduser(
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
38 "~/Library/Application Support/Firefox/Profiles")
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 else:
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 standardDir = os.path.expanduser("~/.mozilla/firefox")
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 return (
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
42 UI.PixmapCache.getPixmap("chrome"),
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 "Mozilla Firefox",
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 "places.sqlite",
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
45 QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
46 "FirefoxImporter",
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
47 """Mozilla Firefox stores its bookmarks in the"""
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
48 """ <b>places.sqlite</b> SQLite database. This file is"""
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
49 """ usually located in"""),
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
50 QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
51 "FirefoxImporter",
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """Please choose the file to begin importing bookmarks."""),
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 standardDir,
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 )
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 else:
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
56 raise ValueError(
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
57 "Unsupported browser ID given ({0}).".format(sourceId))
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 class FirefoxImporter(BookmarksImporter):
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Class implementing the Chrome bookmarks importer.
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
64 def __init__(self, sourceId="", parent=None):
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 Constructor
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
68 @param sourceId source ID (string)
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param parent reference to the parent object (QObject)
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
71 super(FirefoxImporter, self).__init__(sourceId, parent)
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__fileName = ""
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.__db = None
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 def setPath(self, path):
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 Public method to set the path of the bookmarks file or directory.
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @param path bookmarks file or directory (string)
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__fileName = path
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 def open(self):
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 Public method to open the bookmarks file.
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 @return flag indicating success (boolean)
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if not os.path.exists(self.__fileName):
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self._error = True
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
92 self._errorString = self.tr(
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
93 "File '{0}' does not exist."
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
94 ).format(self.__fileName)
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 return False
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
97 try:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
98 self.__db = sqlite3.connect(self.__fileName)
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
99 except sqlite3.DatabaseError as err:
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self._error = True
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
101 self._errorString = self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
102 "Unable to open database.\nReason: {0}").format(str(err))
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 return False
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 return True
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 def importedBookmarks(self):
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Public method to get the imported bookmarks.
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @return imported bookmarks (BookmarkNode)
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
113 from ..BookmarkNode import BookmarkNode
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
114 importRootNode = BookmarkNode(BookmarkNode.Root)
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 # step 1: build the hierarchy of bookmark folders
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 folders = {}
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
118
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
119 try:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
120 cursor = self.__db.cursor()
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
121 cursor.execute(
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
122 "SELECT id, parent, title FROM moz_bookmarks "
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
123 "WHERE type = 2 and title !=''")
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
124 for row in cursor:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
125 id_ = row[0]
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
126 parent = row[1]
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
127 title = row[2]
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
128 if parent in folders:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
129 folder = BookmarkNode(BookmarkNode.Folder, folders[parent])
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
130 else:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
131 folder = BookmarkNode(BookmarkNode.Folder, importRootNode)
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
132 folder.title = title.replace("&", "&&")
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
133 folders[id_] = folder
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
134 except sqlite3.DatabaseError as err:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
135 self._error = True
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
136 self._errorString = self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
137 "Unable to open database.\nReason: {0}").format(str(err))
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
138 return None
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
140 try:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
141 cursor = self.__db.cursor()
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
142 cursor.execute(
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
143 "SELECT parent, title, fk, position FROM moz_bookmarks"
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
144 " WHERE type = 1 and title != '' ORDER BY position")
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
145 for row in cursor:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
146 parent = row[0]
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
147 title = row[1]
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
148 placesId = row[2]
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
149
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
150 cursor2 = self.__db.cursor()
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
151 cursor2.execute(
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7533
diff changeset
152 "SELECT url FROM moz_places WHERE id = {0}" # secok
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
153 .format(placesId))
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
154 row2 = cursor2.fetchone()
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
155 if row2:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
156 url = QUrl(row2[0])
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
157 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
158 not title or
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
159 url.isEmpty() or
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
160 url.scheme() in ["place", "about"]
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
161 ):
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
162 continue
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
163
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
164 if parent in folders:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
165 bookmark = BookmarkNode(BookmarkNode.Bookmark,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
166 folders[parent])
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
167 else:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
168 bookmark = BookmarkNode(BookmarkNode.Bookmark,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
169 importRootNode)
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
170 bookmark.url = url.toString()
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
171 bookmark.title = title.replace("&", "&&")
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
172 except sqlite3.DatabaseError as err:
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
173 self._error = True
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
174 self._errorString = self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
175 "Unable to open database.\nReason: {0}").format(str(err))
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
176 return None
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
1725
d7a3430f7cbf Adapted the bookmarks importers to Mac OS X and changed the SQL stuff of the firefox importer to use sqlite3 because of issues of QSql on Mac OS X.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1719
diff changeset
178 importRootNode.setType(BookmarkNode.Folder)
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 if self._id == "firefox":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
180 importRootNode.title = self.tr("Mozilla Firefox Import")
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 else:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
182 importRootNode.title = self.tr(
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
183 "Imported {0}"
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
184 ).format(QDate.currentDate().toString(Qt.SystemLocaleShortDate))
1716
d634df56a664 Added a bookmarks importer for Firefox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 return importRootNode

eric ide

mercurial