15 |
15 |
16 class PluginRepositoryReader(XMLStreamReaderBase): |
16 class PluginRepositoryReader(XMLStreamReaderBase): |
17 """ |
17 """ |
18 Class to read the plug-in repository contents file. |
18 Class to read the plug-in repository contents file. |
19 """ |
19 """ |
|
20 |
20 supportedVersions = ["4.1", "4.2"] |
21 supportedVersions = ["4.1", "4.2"] |
21 |
22 |
22 def __init__(self, device, entryCallback): |
23 def __init__(self, device, entryCallback): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
26 @param device reference to the I/O device to read from (QIODevice) |
27 @param device reference to the I/O device to read from (QIODevice) |
27 @param entryCallback reference to a function to be called once the |
28 @param entryCallback reference to a function to be called once the |
28 data for a plug-in has been read (function) |
29 data for a plug-in has been read (function) |
29 """ |
30 """ |
30 XMLStreamReaderBase.__init__(self, device) |
31 XMLStreamReaderBase.__init__(self, device) |
31 |
32 |
32 self.__entryCallback = entryCallback |
33 self.__entryCallback = entryCallback |
33 |
34 |
34 self.version = "" |
35 self.version = "" |
35 |
36 |
36 def readXML(self): |
37 def readXML(self): |
37 """ |
38 """ |
38 Public method to read and parse the XML document. |
39 Public method to read and parse the XML document. |
39 """ |
40 """ |
40 while not self.atEnd(): |
41 while not self.atEnd(): |
41 self.readNext() |
42 self.readNext() |
42 if self.isStartElement(): |
43 if self.isStartElement(): |
43 if self.name() == "Plugins": |
44 if self.name() == "Plugins": |
44 self.version = self.attribute( |
45 self.version = self.attribute( |
45 "version", |
46 "version", pluginRepositoryFileFormatVersion |
46 pluginRepositoryFileFormatVersion) |
47 ) |
47 if self.version not in self.supportedVersions: |
48 if self.version not in self.supportedVersions: |
48 self.raiseUnsupportedFormatVersion(self.version) |
49 self.raiseUnsupportedFormatVersion(self.version) |
49 elif self.name() == "RepositoryUrl": |
50 elif self.name() == "RepositoryUrl": |
50 url = self.readElementText() |
51 url = self.readElementText() |
51 Preferences.setUI("PluginRepositoryUrl7", url) |
52 Preferences.setUI("PluginRepositoryUrl7", url) |
52 elif self.name() == "Plugin": |
53 elif self.name() == "Plugin": |
53 self.__readPlugin() |
54 self.__readPlugin() |
54 else: |
55 else: |
55 self._skipUnknownElement() |
56 self._skipUnknownElement() |
56 |
57 |
57 self.showErrorMessage() |
58 self.showErrorMessage() |
58 |
59 |
59 def __readPlugin(self): |
60 def __readPlugin(self): |
60 """ |
61 """ |
61 Private method to read the plug-in info. |
62 Private method to read the plug-in info. |
62 """ |
63 """ |
63 pluginInfo = {"name": "", |
64 pluginInfo = { |
64 "short": "", |
65 "name": "", |
65 "description": "", |
66 "short": "", |
66 "url": "", |
67 "description": "", |
67 "author": "", |
68 "url": "", |
68 "version": "", |
69 "author": "", |
69 "filename": "", |
70 "version": "", |
70 } |
71 "filename": "", |
|
72 } |
71 pluginInfo["status"] = self.attribute("status", "unknown") |
73 pluginInfo["status"] = self.attribute("status", "unknown") |
72 |
74 |
73 while not self.atEnd(): |
75 while not self.atEnd(): |
74 self.readNext() |
76 self.readNext() |
75 if self.isEndElement() and self.name() == "Plugin": |
77 if self.isEndElement() and self.name() == "Plugin": |
76 self.__entryCallback( |
78 self.__entryCallback( |
77 pluginInfo["name"], pluginInfo["short"], |
79 pluginInfo["name"], |
78 pluginInfo["description"], pluginInfo["url"], |
80 pluginInfo["short"], |
79 pluginInfo["author"], pluginInfo["version"], |
81 pluginInfo["description"], |
80 pluginInfo["filename"], pluginInfo["status"]) |
82 pluginInfo["url"], |
|
83 pluginInfo["author"], |
|
84 pluginInfo["version"], |
|
85 pluginInfo["filename"], |
|
86 pluginInfo["status"], |
|
87 ) |
81 break |
88 break |
82 |
89 |
83 if self.isStartElement(): |
90 if self.isStartElement(): |
84 if self.name() == "Name": |
91 if self.name() == "Name": |
85 pluginInfo["name"] = self.readElementText() |
92 pluginInfo["name"] = self.readElementText() |
86 elif self.name() == "Short": |
93 elif self.name() == "Short": |
87 pluginInfo["short"] = self.readElementText() |
94 pluginInfo["short"] = self.readElementText() |