Helpviewer/Bookmarks/BookmarksImporters/XbelImporter.py

Wed, 01 Jan 2014 14:38:45 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 01 Jan 2014 14:38:45 +0100
changeset 3160
209a07d7e401
parent 3022
57179e4cdadd
child 3178
f25fc1364c88
child 3190
a9a94491c4fd
permissions
-rw-r--r--

Updated copyright for 2014.

1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
3 # Copyright (c) 2012 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an importer for XBEL files.
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt4.QtCore import QCoreApplication, QXmlStreamReader, QDate, Qt
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .BookmarksImporter import BookmarksImporter
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import UI.PixmapCache
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 def getImporterInfo(id):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Module function to get information for the given XBEL source id.
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
23 @param id id of the browser ("chrome" or "chromium")
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @return tuple with an icon (QPixmap), readable name (string), name of
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 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
26 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
27 (string)
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
28 @exception ValueError raised to indicate an invalid browser ID
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 if id == "e5browser":
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
31 from ..BookmarksManager import BookmarksManager
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 bookmarksFile = BookmarksManager.getFileName()
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 return (
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 UI.PixmapCache.getPixmap("ericWeb48.png"),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 "eric5 Web Browser",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 os.path.basename(bookmarksFile),
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
37 QCoreApplication.translate(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
38 "XbelImporter",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
39 """eric5 Web Browser 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
40 """ <b>{0}</b> XML file. This file is usually located in"""
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 ).format(os.path.basename(bookmarksFile)),
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
42 QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
43 "XbelImporter",
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """Please choose the file to begin importing bookmarks."""),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 os.path.dirname(bookmarksFile),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 )
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
47 elif id == "konqueror":
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
48 if os.path.exists(os.path.expanduser("~/.kde4")):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
49 standardDir = os.path.expanduser("~/.kde4/share/apps/konqueror")
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
50 elif os.path.exists(os.path.expanduser("~/.kde")):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
51 standardDir = os.path.expanduser("~/.kde/share/apps/konqueror")
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
52 else:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
53 standardDir = ""
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
54 return (
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
55 UI.PixmapCache.getPixmap("konqueror.png"),
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
56 "Konqueror",
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
57 "bookmarks.xml",
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
58 QCoreApplication.translate(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
59 "XbelImporter",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
60 """Konqueror 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
61 """ <b>bookmarks.xml</b> XML file. This file is usually"""
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
62 """ located in"""),
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
63 QCoreApplication.translate(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
64 "XbelImporter",
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
65 """Please choose the file to begin importing bookmarks."""),
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
66 standardDir,
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
67 )
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 elif id == "xbel":
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 return (
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 UI.PixmapCache.getPixmap("xbel.png"),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 "XBEL Bookmarks",
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
72 QCoreApplication.translate(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
73 "XbelImporter", "XBEL Bookmarks") + " (*.xbel *.xml)",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
74 QCoreApplication.translate(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
75 "XbelImporter",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
76 """You can import bookmarks from any browser that supports"""
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
77 """ XBEL exporting. This file has usually the extension"""
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
78 """ .xbel or .xml."""),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
79 QCoreApplication.translate(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
80 "XbelImporter",
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """Please choose the file to begin importing bookmarks."""),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 "",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 )
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 else:
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 raise ValueError("Unsupported browser ID given ({0}).".format(id))
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 class XbelImporter(BookmarksImporter):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Class implementing the XBEL bookmarks importer.
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 def __init__(self, id="", parent=None):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 Constructor
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 @param id source ID (string)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 @param parent reference to the parent object (QObject)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 super().__init__(id, parent)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.__fileName = ""
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 def setPath(self, path):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 Public method to set the path of the bookmarks file or directory.
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @param path bookmarks file or directory (string)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.__fileName = path
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 def open(self):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 Public method to open the bookmarks file.
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @return flag indicating success (boolean)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 if not os.path.exists(self.__fileName):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self._error = True
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self._errorString = self.trUtf8("File '{0}' does not exist.")\
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 .format(self.__fileName)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 return False
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 return True
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 def importedBookmarks(self):
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 Public method to get the imported bookmarks.
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @return imported bookmarks (BookmarkNode)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
130 from ..XbelReader import XbelReader
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
131
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 reader = XbelReader()
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 importRootNode = reader.read(self.__fileName)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 if reader.error() != QXmlStreamReader.NoError:
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 self._error = True
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self._errorString = self.trUtf8(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
138 """Error when importing bookmarks on line {0},"""
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
139 """ column {1}:\n{2}""")\
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 .format(reader.lineNumber(),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 reader.columnNumber(),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 reader.errorString())
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 return None
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
145 from ..BookmarkNode import BookmarkNode
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 importRootNode.setType(BookmarkNode.Folder)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 if self._id == "e5browser":
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 importRootNode.title = self.trUtf8("eric5 Web Browser Import")
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
149 elif self._id == "konqueror":
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1713
diff changeset
150 importRootNode.title = self.trUtf8("Konqueror Import")
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 elif self._id == "xbel":
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 importRootNode.title = self.trUtf8("XBEL Import")
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 else:
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 importRootNode.title = self.trUtf8("Imported {0}")\
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 .format(QDate.currentDate().toString(Qt.SystemLocaleShortDate))
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 return importRootNode

eric ide

mercurial