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 == "chrome": |
32 if id == "chrome": |
32 if Globals.isWindowsPlatform(): |
33 if Globals.isWindowsPlatform(): |
33 standardDir = os.path.expandvars( |
34 standardDir = os.path.expandvars( |
34 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\Default") |
35 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\" |
|
36 "User Data\\Default") |
35 elif Globals.isMacPlatform(): |
37 elif Globals.isMacPlatform(): |
36 standardDir = os.path.expanduser( |
38 standardDir = os.path.expanduser( |
37 "~/Library/Application Support/Google/Chrome/Default") |
39 "~/Library/Application Support/Google/Chrome/Default") |
38 else: |
40 else: |
39 standardDir = os.path.expanduser("~/.config/google-chrome/Default") |
41 standardDir = os.path.expanduser("~/.config/google-chrome/Default") |
40 return ( |
42 return ( |
41 UI.PixmapCache.getPixmap("chrome.png"), |
43 UI.PixmapCache.getPixmap("chrome.png"), |
42 "Google Chrome", |
44 "Google Chrome", |
43 "Bookmarks", |
45 "Bookmarks", |
44 QCoreApplication.translate("ChromeImporter", |
46 QCoreApplication.translate( |
45 """Google Chrome stores its bookmarks in the <b>Bookmarks</b> """ |
47 "ChromeImporter", |
46 """text file. This file is usually located in"""), |
48 """Google Chrome stores its bookmarks in the""" |
|
49 """ <b>Bookmarks</b> text file. This file is usually""" |
|
50 """ located in"""), |
47 QCoreApplication.translate("ChromeImporter", |
51 QCoreApplication.translate("ChromeImporter", |
48 """Please choose the file to begin importing bookmarks."""), |
52 """Please choose the file to begin importing bookmarks."""), |
49 standardDir, |
53 standardDir, |
50 ) |
54 ) |
51 elif id == "chromium": |
55 elif id == "chromium": |
52 if Globals.isWindowsPlatform(): |
56 if Globals.isWindowsPlatform(): |
53 standardDir = os.path.expandvars( |
57 standardDir = os.path.expandvars( |
54 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\Default") |
58 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\" |
|
59 "User Data\\Default") |
55 else: |
60 else: |
56 standardDir = os.path.expanduser("~/.config/chromium/Default") |
61 standardDir = os.path.expanduser("~/.config/chromium/Default") |
57 return ( |
62 return ( |
58 UI.PixmapCache.getPixmap("chromium.png"), |
63 UI.PixmapCache.getPixmap("chromium.png"), |
59 "Chromium", |
64 "Chromium", |
60 "Bookmarks", |
65 "Bookmarks", |
61 QCoreApplication.translate("ChromeImporter", |
66 QCoreApplication.translate( |
62 """Chromium stores its bookmarks in the <b>Bookmarks</b> text file. """ |
67 "ChromeImporter", |
63 """This file is usually located in"""), |
68 """Chromium stores its bookmarks in the <b>Bookmarks</b>""" |
|
69 """ text file. This file is usually located in"""), |
64 QCoreApplication.translate("ChromeImporter", |
70 QCoreApplication.translate("ChromeImporter", |
65 """Please choose the file to begin importing bookmarks."""), |
71 """Please choose the file to begin importing bookmarks."""), |
66 standardDir, |
72 standardDir, |
67 ) |
73 ) |
68 else: |
74 else: |
115 f = open(self.__fileName, "r", encoding="utf-8") |
121 f = open(self.__fileName, "r", encoding="utf-8") |
116 contents = json.load(f) |
122 contents = json.load(f) |
117 f.close() |
123 f.close() |
118 except IOError as err: |
124 except IOError as err: |
119 self._error = True |
125 self._error = True |
120 self._errorString = self.trUtf8("File '{0}' cannot be read.\nReason: {1}")\ |
126 self._errorString = self.trUtf8( |
|
127 "File '{0}' cannot be read.\nReason: {1}")\ |
121 .format(self.__fileName, str(err)) |
128 .format(self.__fileName, str(err)) |
122 return None |
129 return None |
123 |
130 |
124 from ..BookmarkNode import BookmarkNode |
131 from ..BookmarkNode import BookmarkNode |
125 importRootNode = BookmarkNode(BookmarkNode.Folder) |
132 importRootNode = BookmarkNode(BookmarkNode.Folder) |