|
1 /* |
|
2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <eikenv.h> |
|
20 #include <f32file.h> |
|
21 #include <xmlengelement.h> |
|
22 #include <xmlengattr.h> |
|
23 #include <xmlengnodelist.h> |
|
24 |
|
25 #include "DirectPrintModel.h" |
|
26 #include "directprintprinterinforeader.h" |
|
27 |
|
28 CDirectPrintPrinterInfoReader::CDirectPrintPrinterInfoReader(CDirectPrintModel& aModel) |
|
29 : iModel(aModel) |
|
30 { |
|
31 } |
|
32 |
|
33 CDirectPrintPrinterInfoReader::~CDirectPrintPrinterInfoReader() |
|
34 { |
|
35 if (iXmlEngDoc.NotNull()) |
|
36 { |
|
37 iXmlEngDoc.Close(); |
|
38 iXmlParser.Close(); |
|
39 iXmlDomImpl.Close(); |
|
40 } |
|
41 } |
|
42 |
|
43 CDirectPrintPrinterInfoReader* CDirectPrintPrinterInfoReader::NewL(CDirectPrintModel& aModel) |
|
44 { |
|
45 CDirectPrintPrinterInfoReader* self = CDirectPrintPrinterInfoReader::NewLC(aModel); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 CDirectPrintPrinterInfoReader* CDirectPrintPrinterInfoReader::NewLC(CDirectPrintModel& aModel) |
|
51 { |
|
52 CDirectPrintPrinterInfoReader* self = new(ELeave) CDirectPrintPrinterInfoReader(aModel); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 void CDirectPrintPrinterInfoReader::ConstructL() |
|
59 { |
|
60 iXmlDomImpl.OpenL(); |
|
61 TInt err = iXmlParser.Open(iXmlDomImpl); |
|
62 User::LeaveIfError(err); |
|
63 } |
|
64 |
|
65 void CDirectPrintPrinterInfoReader::ReadPrinterInfoL() |
|
66 { |
|
67 TDirectPrintPrinterData printer; |
|
68 iModel.GetPrinterDataL(0, printer); |
|
69 |
|
70 _LIT( KFilePath, "c:\\printers\\*.xml"); |
|
71 _LIT( KFilePathFormat, "c:\\printers\\%S"); |
|
72 |
|
73 CDir* fileList; |
|
74 const TUint KMask = KEntryAttNormal|KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem; |
|
75 User::LeaveIfError(CEikonEnv::Static()->FsSession().GetDir(KFilePath, KMask, ESortByName, fileList)); |
|
76 CleanupStack::PushL(fileList); |
|
77 |
|
78 TInt count = fileList->Count(); |
|
79 for (TInt i=0; i<count; i++) |
|
80 { |
|
81 TFileName filename; |
|
82 filename.Format(KFilePathFormat, &(*fileList)[i].iName); |
|
83 ReadXmlDataL(filename); |
|
84 |
|
85 // Check XML file for current printer driver |
|
86 if (CheckManufactureL(printer.iDriverName)) |
|
87 { |
|
88 break; |
|
89 } |
|
90 else |
|
91 { |
|
92 iXmlEngDoc.Close(); |
|
93 } |
|
94 } |
|
95 |
|
96 CleanupStack::PopAndDestroy(); // fileList |
|
97 } |
|
98 |
|
99 void CDirectPrintPrinterInfoReader::GetManufactureL(TDes& aManufacture) |
|
100 { |
|
101 if (iXmlEngDoc.NotNull()) |
|
102 { |
|
103 _LIT8(KElementManufacture, "Manufacture"); |
|
104 |
|
105 TXmlEngElement element = iXmlEngDoc.DocumentElement().FirstChild().AsElement(); |
|
106 |
|
107 while (element.NotNull()) |
|
108 { |
|
109 TBuf<50> elementName; |
|
110 elementName.Copy(element.Name()); |
|
111 if (element.Name().CompareF(KElementManufacture()) == 0) |
|
112 { |
|
113 aManufacture.Copy(element.Value()); |
|
114 break; |
|
115 } |
|
116 |
|
117 element = element.NextSibling().AsElement(); |
|
118 } |
|
119 } |
|
120 } |
|
121 |
|
122 TUid CDirectPrintPrinterInfoReader::GetDriverL(TDesC& aId) |
|
123 { |
|
124 TUint uidValue = 0; |
|
125 |
|
126 if (iXmlEngDoc.NotNull()) |
|
127 { |
|
128 _LIT8(KElementPrinters, "Printers"); |
|
129 _LIT8(KElementPrinter, "Printer"); |
|
130 _LIT8(KElementDriver, "Driver"); |
|
131 _LIT8(KAttributeId, "id"); |
|
132 |
|
133 TXmlEngElement element = iXmlEngDoc.DocumentElement().FirstChild().AsElement(); |
|
134 |
|
135 while (element.NotNull()) |
|
136 { |
|
137 TBuf<50> elementName; |
|
138 elementName.Copy(element.Name()); |
|
139 if (element.Name().CompareF(KElementPrinters()) == 0) |
|
140 { |
|
141 element = element.FirstChild().AsElement(); |
|
142 } |
|
143 else if (element.Name().CompareF(KElementPrinter()) == 0) |
|
144 { |
|
145 TBool next = EFalse; |
|
146 TBuf<50> attrValue; |
|
147 TXmlEngAttr attr = element.AttributeNodeL(KAttributeId); |
|
148 attrValue.Copy(attr.Value()); |
|
149 if (aId.CompareF(attrValue) == 0) |
|
150 { |
|
151 element = element.FirstChild().AsElement(); |
|
152 next = ETrue; |
|
153 } |
|
154 |
|
155 if (!next) |
|
156 { |
|
157 element = element.NextSibling().AsElement(); |
|
158 } |
|
159 } |
|
160 else if (element.Name().CompareF(KElementDriver()) == 0) |
|
161 { |
|
162 TLex8 lex(element.Value()); |
|
163 lex.Val(uidValue, EHex); |
|
164 break; |
|
165 } |
|
166 else |
|
167 { |
|
168 element = element.NextSibling().AsElement(); |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 return TUid::Uid(uidValue); |
|
174 } |
|
175 |
|
176 TUid CDirectPrintPrinterInfoReader::GetSettingUIPluginL(TDesC& aId) |
|
177 { |
|
178 TUint uidValue = 0; |
|
179 |
|
180 if (iXmlEngDoc.NotNull()) |
|
181 { |
|
182 _LIT8(KElementPrinters, "Printers"); |
|
183 _LIT8(KElementPrinter, "Printer"); |
|
184 _LIT8(KElementSettingUIPlugin, "SettingUIPlugin"); |
|
185 _LIT8(KAttributeId, "id"); |
|
186 |
|
187 TXmlEngElement element = iXmlEngDoc.DocumentElement().FirstChild().AsElement(); |
|
188 |
|
189 while (element.NotNull()) |
|
190 { |
|
191 if (element.Name().CompareF(KElementPrinters()) == 0) |
|
192 { |
|
193 element = element.FirstChild().AsElement(); |
|
194 } |
|
195 else if (element.Name().CompareF(KElementPrinter()) == 0) |
|
196 { |
|
197 TBool next = EFalse; |
|
198 TBuf<50> attrValue; |
|
199 TXmlEngAttr attr = element.AttributeNodeL(KAttributeId); |
|
200 attrValue.Copy(attr.Value()); |
|
201 if (aId.CompareF(attrValue) == 0) |
|
202 { |
|
203 element = element.FirstChild().AsElement(); |
|
204 next = ETrue; |
|
205 } |
|
206 |
|
207 if (!next) |
|
208 { |
|
209 element = element.NextSibling().AsElement(); |
|
210 } |
|
211 } |
|
212 else if (element.Name().CompareF(KElementSettingUIPlugin()) == 0) |
|
213 { |
|
214 TLex8 lex(element.Value()); |
|
215 lex.Val(uidValue, EHex); |
|
216 break; |
|
217 } |
|
218 |
|
219 element = element.NextSibling().AsElement(); |
|
220 } |
|
221 } |
|
222 |
|
223 return TUid::Uid(uidValue); |
|
224 } |
|
225 |
|
226 void CDirectPrintPrinterInfoReader::ReadXmlDataL(const TDesC& aFilename) |
|
227 { |
|
228 if (iXmlEngDoc.NotNull()) |
|
229 { |
|
230 iXmlEngDoc.Close(); |
|
231 } |
|
232 iXmlEngDoc = iXmlParser.ParseFileL(aFilename); |
|
233 } |
|
234 |
|
235 TBool CDirectPrintPrinterInfoReader::CheckManufactureL(const TDesC& aParam) |
|
236 { |
|
237 TBool res = EFalse; |
|
238 TBuf<50> buf; |
|
239 GetManufactureL(buf); |
|
240 if (aParam.Compare(buf) == 0) |
|
241 { |
|
242 res = ETrue; |
|
243 } |
|
244 return res; |
|
245 } |
|
246 |