Helpviewer/Bookmarks/BookmarksImporters/XbelImporter.py

Sat, 24 Mar 2012 16:10:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 24 Mar 2012 16:10:48 +0100
changeset 1729
66b9dc45f2bd
parent 1713
56fdde8a2441
child 1965
96f5a76e1845
permissions
-rw-r--r--

Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).

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
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
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 ..BookmarksManager import BookmarksManager
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from ..BookmarkNode import BookmarkNode
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from ..XbelReader import XbelReader
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 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
19
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 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
21
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 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
26
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @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
28 the default bookmarks file (string), an info text (string),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 a prompt (string) and the default directory of the bookmarks file (string)
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 if id == "e5browser":
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),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 QCoreApplication.translate("XbelImporter",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """eric5 Web Browser stores its bookmarks in the <b>{0}</b> XML file. """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """This file is usually located in"""
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 ).format(os.path.basename(bookmarksFile)),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 QCoreApplication.translate("XbelImporter",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """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
43 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
44 )
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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 "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
55 "bookmarks.xml",
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 QCoreApplication.translate("XbelImporter",
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 """Konqueror stores its bookmarks in the <b>bookmarks.xml</b> XML """
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
58 """file. This file is usually located in"""),
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
59 QCoreApplication.translate("XbelImporter",
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
60 """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
61 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
62 )
1713
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 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
64 return (
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 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
66 "XBEL Bookmarks",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 QCoreApplication.translate("XbelImporter", "XBEL Bookmarks") + \
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 " (*.xbel *.xml)",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 QCoreApplication.translate("XbelImporter",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """You can import bookmarks from any browser that supports XBEL """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """exporting. This file has usually the extension .xbel or .xml.""" ),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 QCoreApplication.translate("XbelImporter",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """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
74 "",
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 )
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 else:
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 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
78
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 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
81 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 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
83 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 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
85 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 Constructor
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 @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
89 @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
90 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 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
92
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__fileName = ""
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 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
96 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 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
98
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 @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
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 = path
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 open(self):
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 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
106
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @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
108 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 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
110 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
111 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
112 .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
113 return False
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 return True
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 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
117 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 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
119
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @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
121 """
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 reader = XbelReader()
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 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
124
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 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
126 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
127 self._errorString = self.trUtf8(
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
128 """Error when importing bookmarks on line {0}, 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
129 .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
130 reader.columnNumber(),
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 reader.errorString())
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 return None
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 else:
56fdde8a2441 Added a bookmarks importer to get them directly from other browsers files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 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
143 .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
144 return importRootNode

eric ide

mercurial