12 |
12 |
13 class SpeedDialWriter(QXmlStreamWriter): |
13 class SpeedDialWriter(QXmlStreamWriter): |
14 """ |
14 """ |
15 Class implementing a writer object to generate speed dial data files. |
15 Class implementing a writer object to generate speed dial data files. |
16 """ |
16 """ |
|
17 |
17 def __init__(self): |
18 def __init__(self): |
18 """ |
19 """ |
19 Constructor |
20 Constructor |
20 """ |
21 """ |
21 super().__init__() |
22 super().__init__() |
22 |
23 |
23 self.setAutoFormatting(True) |
24 self.setAutoFormatting(True) |
24 |
25 |
25 def write(self, fileNameOrDevice, pages, pagesPerRow, speedDialSize): |
26 def write(self, fileNameOrDevice, pages, pagesPerRow, speedDialSize): |
26 """ |
27 """ |
27 Public method to write a speed dial data file. |
28 Public method to write a speed dial data file. |
28 |
29 |
29 @param fileNameOrDevice name of the file to write (string) |
30 @param fileNameOrDevice name of the file to write (string) |
30 or device to write to (QIODevice) |
31 or device to write to (QIODevice) |
31 @param pages list of speed dial pages (list of Page) |
32 @param pages list of speed dial pages (list of Page) |
32 @param pagesPerRow number of pages per row (integer) |
33 @param pagesPerRow number of pages per row (integer) |
33 @param speedDialSize size of the speed dial pages (integer) |
34 @param speedDialSize size of the speed dial pages (integer) |
37 f = fileNameOrDevice |
38 f = fileNameOrDevice |
38 else: |
39 else: |
39 f = QFile(fileNameOrDevice) |
40 f = QFile(fileNameOrDevice) |
40 if not f.open(QIODevice.OpenModeFlag.WriteOnly): |
41 if not f.open(QIODevice.OpenModeFlag.WriteOnly): |
41 return False |
42 return False |
42 |
43 |
43 self.setDevice(f) |
44 self.setDevice(f) |
44 return self.__write(pages, pagesPerRow, speedDialSize) |
45 return self.__write(pages, pagesPerRow, speedDialSize) |
45 |
46 |
46 def __write(self, pages, pagesPerRow, speedDialSize): |
47 def __write(self, pages, pagesPerRow, speedDialSize): |
47 """ |
48 """ |
48 Private method to write a speed dial file. |
49 Private method to write a speed dial file. |
49 |
50 |
50 @param pages list of speed dial pages (list of Page) |
51 @param pages list of speed dial pages (list of Page) |
51 @param pagesPerRow number of pages per row (integer) |
52 @param pagesPerRow number of pages per row (integer) |
52 @param speedDialSize size of the speed dial pages (integer) |
53 @param speedDialSize size of the speed dial pages (integer) |
53 @return flag indicating success (boolean) |
54 @return flag indicating success (boolean) |
54 """ |
55 """ |
55 self.writeStartDocument() |
56 self.writeStartDocument() |
56 self.writeDTD("<!DOCTYPE speeddial>") |
57 self.writeDTD("<!DOCTYPE speeddial>") |
57 self.writeStartElement("SpeedDial") |
58 self.writeStartElement("SpeedDial") |
58 self.writeAttribute("version", "1.0") |
59 self.writeAttribute("version", "1.0") |
59 |
60 |
60 self.writeStartElement("Pages") |
61 self.writeStartElement("Pages") |
61 self.writeAttribute("row", str(pagesPerRow)) |
62 self.writeAttribute("row", str(pagesPerRow)) |
62 self.writeAttribute("size", str(speedDialSize)) |
63 self.writeAttribute("size", str(speedDialSize)) |
63 |
64 |
64 for page in pages: |
65 for page in pages: |
65 self.writeEmptyElement("Page") |
66 self.writeEmptyElement("Page") |
66 self.writeAttribute("url", page.url) |
67 self.writeAttribute("url", page.url) |
67 self.writeAttribute("title", page.title) |
68 self.writeAttribute("title", page.title) |
68 |
69 |
69 self.writeEndDocument() |
70 self.writeEndDocument() |
70 return True |
71 return True |