17 |
17 |
18 import UI.PixmapCache |
18 import UI.PixmapCache |
19 import Globals |
19 import Globals |
20 |
20 |
21 |
21 |
22 def getImporterInfo(id): |
22 def getImporterInfo(sourceId): |
23 """ |
23 """ |
24 Module function to get information for the given source id. |
24 Module function to get information for the given source id. |
25 |
25 |
26 @param id id of the browser ("chrome" or "chromium") |
26 @param sourceId id of the browser ("chrome" or "chromium") |
27 @return tuple with an icon (QPixmap), readable name (string), name of |
27 @return tuple with an icon (QPixmap), readable name (string), name of |
28 the default bookmarks file (string), an info text (string), |
28 the default bookmarks file (string), an info text (string), |
29 a prompt (string) and the default directory of the bookmarks file |
29 a prompt (string) and the default directory of the bookmarks file |
30 (string) |
30 (string) |
31 @exception ValueError raised to indicate an invalid browser ID |
31 @exception ValueError raised to indicate an invalid browser ID |
32 """ |
32 """ |
33 if id == "ie": |
33 if sourceId == "ie": |
34 if Globals.isWindowsPlatform(): |
34 if Globals.isWindowsPlatform(): |
35 standardDir = os.path.expandvars( |
35 standardDir = os.path.expandvars( |
36 "%USERPROFILE%\\Favorites") |
36 "%USERPROFILE%\\Favorites") |
37 else: |
37 else: |
38 standardDir = "" |
38 standardDir = "" |
49 "IExplorerImporter", |
49 "IExplorerImporter", |
50 """Please choose the folder to begin importing bookmarks."""), |
50 """Please choose the folder to begin importing bookmarks."""), |
51 standardDir, |
51 standardDir, |
52 ) |
52 ) |
53 else: |
53 else: |
54 raise ValueError("Unsupported browser ID given ({0}).".format(id)) |
54 raise ValueError( |
|
55 "Unsupported browser ID given ({0}).".format(sourceId)) |
55 |
56 |
56 |
57 |
57 class IExplorerImporter(BookmarksImporter): |
58 class IExplorerImporter(BookmarksImporter): |
58 """ |
59 """ |
59 Class implementing the Chrome bookmarks importer. |
60 Class implementing the Chrome bookmarks importer. |
60 """ |
61 """ |
61 def __init__(self, id="", parent=None): |
62 def __init__(self, sourceId="", parent=None): |
62 """ |
63 """ |
63 Constructor |
64 Constructor |
64 |
65 |
65 @param id source ID (string) |
66 @param sourceId source ID (string) |
66 @param parent reference to the parent object (QObject) |
67 @param parent reference to the parent object (QObject) |
67 """ |
68 """ |
68 super(IExplorerImporter, self).__init__(id, parent) |
69 super(IExplorerImporter, self).__init__(sourceId, parent) |
69 |
70 |
70 self.__fileName = "" |
71 self.__fileName = "" |
71 |
72 |
72 def setPath(self, path): |
73 def setPath(self, path): |
73 """ |
74 """ |
105 folders = {} |
106 folders = {} |
106 |
107 |
107 importRootNode = BookmarkNode(BookmarkNode.Folder) |
108 importRootNode = BookmarkNode(BookmarkNode.Folder) |
108 folders[self.__fileName] = importRootNode |
109 folders[self.__fileName] = importRootNode |
109 |
110 |
110 for dir, subdirs, files in os.walk(self.__fileName): |
111 for directory, subdirs, files in os.walk(self.__fileName): |
111 for subdir in subdirs: |
112 for subdir in subdirs: |
112 path = os.path.join(dir, subdir) |
113 path = os.path.join(directory, subdir) |
113 if dir in folders: |
114 if directory in folders: |
114 folder = BookmarkNode(BookmarkNode.Folder, folders[dir]) |
115 folder = BookmarkNode(BookmarkNode.Folder, |
|
116 folders[directory]) |
115 else: |
117 else: |
116 folder = BookmarkNode(BookmarkNode.Folder, importRootNode) |
118 folder = BookmarkNode(BookmarkNode.Folder, importRootNode) |
117 folder.title = subdir.replace("&", "&&") |
119 folder.title = subdir.replace("&", "&&") |
118 folders[path] = folder |
120 folders[path] = folder |
119 |
121 |
120 for file in files: |
122 for file in files: |
121 name, ext = os.path.splitext(file) |
123 name, ext = os.path.splitext(file) |
122 if ext.lower() == ".url": |
124 if ext.lower() == ".url": |
123 path = os.path.join(dir, file) |
125 path = os.path.join(directory, file) |
124 try: |
126 try: |
125 f = open(path, "r") |
127 f = open(path, "r") |
126 contents = f.read() |
128 contents = f.read() |
127 f.close() |
129 f.close() |
128 except IOError: |
130 except IOError: |
131 for line in contents.splitlines(): |
133 for line in contents.splitlines(): |
132 if line.startswith("URL="): |
134 if line.startswith("URL="): |
133 url = line.replace("URL=", "") |
135 url = line.replace("URL=", "") |
134 break |
136 break |
135 if url: |
137 if url: |
136 if dir in folders: |
138 if directory in folders: |
137 bookmark = BookmarkNode(BookmarkNode.Bookmark, |
139 bookmark = BookmarkNode(BookmarkNode.Bookmark, |
138 folders[dir]) |
140 folders[directory]) |
139 else: |
141 else: |
140 bookmark = BookmarkNode(BookmarkNode.Bookmark, |
142 bookmark = BookmarkNode(BookmarkNode.Bookmark, |
141 importRootNode) |
143 importRootNode) |
142 bookmark.url = url |
144 bookmark.url = url |
143 bookmark.title = name.replace("&", "&&") |
145 bookmark.title = name.replace("&", "&&") |