1 /* |
|
2 * Copyright (c) 2004-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Contains the CPrintJob class definition and the PJS enum. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <pathinfo.h> |
|
21 #include <driveinfo.h> |
|
22 |
|
23 #include "cprintjob.h" |
|
24 #include "printcapabilitycodes.h" |
|
25 #include "imageprint.h" |
|
26 #include "clog.h" |
|
27 #include "tbtmapper.h" |
|
28 #include "btprotocolconsts.h" |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 // Public functions |
|
34 //-------------------------------------------------------------------------------------------- |
|
35 // |
|
36 // CPrintJob::NewL |
|
37 // |
|
38 //-------------------------------------------------------------------------------------------- |
|
39 CPrintJob* CPrintJob::NewL(CRsBtDevice* aDevice, RArray<TFileName>& aImages, |
|
40 const TDesC8& aUserName) |
|
41 { |
|
42 CPrintJob* self = new (ELeave) CPrintJob(aDevice); |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(aImages, aUserName); |
|
45 CleanupStack::Pop(); // self |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 //-------------------------------------------------------------------------------------------- |
|
51 // |
|
52 // CPrintJob::~CPrintJob |
|
53 // |
|
54 //-------------------------------------------------------------------------------------------- |
|
55 CPrintJob::~CPrintJob() |
|
56 { |
|
57 iImages.Reset(); |
|
58 iImages.Close(); |
|
59 iDevice = NULL; |
|
60 } |
|
61 |
|
62 //-------------------------------------------------------------------------------------------- |
|
63 // |
|
64 // CPrintJob::SetJobId |
|
65 // |
|
66 //-------------------------------------------------------------------------------------------- |
|
67 void CPrintJob::SetJobId(const TInt aId) |
|
68 { |
|
69 iJobId = aId; |
|
70 } |
|
71 |
|
72 |
|
73 //-------------------------------------------------------------------------------------------- |
|
74 // |
|
75 // CPrintJob::GetJobId |
|
76 // |
|
77 //-------------------------------------------------------------------------------------------- |
|
78 TInt CPrintJob::JobId() |
|
79 { |
|
80 return iJobId; |
|
81 } |
|
82 |
|
83 //-------------------------------------------------------------------------------------------- |
|
84 // |
|
85 // CPrintJob::GetJobName |
|
86 // |
|
87 //-------------------------------------------------------------------------------------------- |
|
88 void CPrintJob::GetJobName(TDes8& aJobName) |
|
89 { |
|
90 // Return the name of first image |
|
91 if (iImages.Count() > 0) |
|
92 { |
|
93 iImages[0].GetFilePath(aJobName); |
|
94 } |
|
95 else |
|
96 { |
|
97 aJobName.Append(KNullDesC8()); |
|
98 } |
|
99 } |
|
100 |
|
101 //-------------------------------------------------------------------------------------------- |
|
102 // |
|
103 // CPrintJob::ImageCount |
|
104 // |
|
105 //-------------------------------------------------------------------------------------------- |
|
106 TInt CPrintJob::ImageCount() |
|
107 { |
|
108 return iImages.Count(); |
|
109 } |
|
110 |
|
111 //-------------------------------------------------------------------------------------------- |
|
112 // |
|
113 // CPrintJob::Images |
|
114 // |
|
115 //-------------------------------------------------------------------------------------------- |
|
116 void CPrintJob::Images(RArray<CImageInfo>& aImages) |
|
117 { |
|
118 for (TInt i=0; i < iImages.Count(); i++) |
|
119 { |
|
120 aImages.Append(iImages[i]); |
|
121 } |
|
122 } |
|
123 |
|
124 |
|
125 //-------------------------------------------------------------------------------------------- |
|
126 // |
|
127 // CPrintJob::PrinterId |
|
128 // |
|
129 //-------------------------------------------------------------------------------------------- |
|
130 TInt CPrintJob::PrinterId() |
|
131 { |
|
132 if(Device()) |
|
133 return Device()->DeviceId(); |
|
134 |
|
135 return KErrNotFound; |
|
136 } |
|
137 |
|
138 //-------------------------------------------------------------------------------------------- |
|
139 // |
|
140 // CPrintJob::GetUserName |
|
141 // |
|
142 //-------------------------------------------------------------------------------------------- |
|
143 void CPrintJob::GetUserName(TPtrC8& aUserName) |
|
144 { |
|
145 aUserName.Set(iUserName); |
|
146 } |
|
147 |
|
148 //-------------------------------------------------------------------------------------------- |
|
149 // |
|
150 // CPrintJob::GetUserName |
|
151 // |
|
152 //-------------------------------------------------------------------------------------------- |
|
153 CRsBtDevice* CPrintJob::Device() |
|
154 { |
|
155 if(iDevice) |
|
156 return iDevice; |
|
157 else |
|
158 return NULL; |
|
159 } |
|
160 |
|
161 //-------------------------------------------------------------------------------------------- |
|
162 // |
|
163 // CPrintJob::SetNumsOfCopies |
|
164 // |
|
165 //-------------------------------------------------------------------------------------------- |
|
166 TInt CPrintJob::SetNumsOfCopies( const RArray<TInt>& aNumsOfCopies) |
|
167 { |
|
168 TInt err = KErrNone; |
|
169 |
|
170 for(TInt arrayIx = 0, imgIx = 0; arrayIx < aNumsOfCopies.Count(); ++arrayIx) |
|
171 { |
|
172 if(iImages[imgIx].Index() < aNumsOfCopies.Count()) |
|
173 { |
|
174 TInt copies = aNumsOfCopies[iImages[imgIx].Index()]; |
|
175 if(0 < copies) |
|
176 iImages[imgIx].SetCopies(copies); |
|
177 ++imgIx; |
|
178 } |
|
179 else |
|
180 err = KErrCorrupt; |
|
181 } |
|
182 return err; |
|
183 } |
|
184 |
|
185 //-------------------------------------------------------------------------------------------- |
|
186 // |
|
187 // CPrintJob::GetPrintFileL |
|
188 // |
|
189 //-------------------------------------------------------------------------------------------- |
|
190 void CPrintJob::GetPrintFileL(TDes8& aPrintFile) |
|
191 { |
|
192 LOG("[CPrintJob::GetPrintFileL]\t begin"); |
|
193 |
|
194 TInt layout; |
|
195 TInt paper; |
|
196 TInt quality; |
|
197 |
|
198 GetPrintSetting(EPrintCapabLayout, layout); |
|
199 GetPrintSetting(EPrintCapabPaperSize, paper); |
|
200 GetPrintSetting(EPrintCapabQuality, quality); |
|
201 |
|
202 TFileName tmpFile; |
|
203 tmpFile.Copy(aPrintFile); |
|
204 |
|
205 CXhtmlFileComposer* fileComposer = CXhtmlFileComposer::NewLC(KNullDesC()); |
|
206 |
|
207 LOG("[CPrintJob::GetPrintFileL]\t create file"); |
|
208 fileComposer->CreateXhtmlFileL( iImages, layout, paper, quality, tmpFile, iSheets ); |
|
209 |
|
210 CleanupStack::PopAndDestroy(fileComposer); |
|
211 aPrintFile.Copy(tmpFile); |
|
212 |
|
213 LOG("[CPrintJob::GetPrintFileL]\t file created"); |
|
214 } |
|
215 |
|
216 |
|
217 //-------------------------------------------------------------------------------------------- |
|
218 // |
|
219 // CPrintJob::Sheets |
|
220 // |
|
221 //-------------------------------------------------------------------------------------------- |
|
222 TInt CPrintJob::Sheets() |
|
223 { |
|
224 if(0 == iSheets) |
|
225 { |
|
226 TInt layout; |
|
227 TInt layoutNbr = 1; |
|
228 TInt imageNbr = 0; |
|
229 |
|
230 // We don't care about return value here: if GetPrintSetting |
|
231 // fails, we can anyway tell there will be at least an image/page |
|
232 GetPrintSetting(EPrintCapabLayout, layout); |
|
233 |
|
234 switch( layout ) |
|
235 { |
|
236 case EPrintCapabLayout1Up: |
|
237 case EPrintCapabLayout1UpBorderless: |
|
238 case EPrintCapabLayout1UpBorder: |
|
239 layoutNbr = 1; |
|
240 break; |
|
241 case EPrintCapabLayout2Up: |
|
242 layoutNbr = 2; |
|
243 break; |
|
244 case EPrintCapabLayout4Up: |
|
245 layoutNbr = 4; |
|
246 break; |
|
247 case EPrintCapabLayout6Up: |
|
248 layoutNbr = 6; |
|
249 break; |
|
250 case EPrintCapabLayout9Up: |
|
251 layoutNbr = 9; |
|
252 break; |
|
253 case EPrintCapabLayout12Up: |
|
254 layoutNbr = 12; |
|
255 break; |
|
256 case EPrintCapabLayout16Up: |
|
257 layoutNbr = 16; |
|
258 break; |
|
259 default: |
|
260 break; |
|
261 } |
|
262 |
|
263 for (TInt i = 0; i<iImages.Count(); ++i) |
|
264 { |
|
265 imageNbr += iImages[i].Copies(); |
|
266 } |
|
267 |
|
268 iSheets = imageNbr / layoutNbr; |
|
269 if(0 < imageNbr % layoutNbr) |
|
270 { |
|
271 ++iSheets; |
|
272 } |
|
273 } |
|
274 LOG1("[CPrintJob::Sheets]\t iSheets = %d", iSheets); |
|
275 return iSheets; |
|
276 } |
|
277 |
|
278 // Protected functions |
|
279 //-------------------------------------------------------------------------------------------- |
|
280 // |
|
281 // CPrintJob::ConstructL |
|
282 // |
|
283 //-------------------------------------------------------------------------------------------- |
|
284 void CPrintJob::ConstructL(RArray<TFileName>& aImages, const TDesC8& aUserName) |
|
285 { |
|
286 if (aImages.Count() < 1) |
|
287 { |
|
288 User::Leave(KErrArgument); |
|
289 } |
|
290 |
|
291 _LIT(KObex, "obex:"); |
|
292 _LIT(KMmc, "\\mmc"); |
|
293 _LIT(KLocal, "\\media"); |
|
294 _LIT(KSlash, "/"); |
|
295 _LIT(KBackSlash, "\\"); |
|
296 |
|
297 // Initialize iImages array |
|
298 for (TInt i=0 ; i<aImages.Count(); i++) |
|
299 { |
|
300 // Skip empty strings |
|
301 if (aImages[i].Length() < 1) |
|
302 { |
|
303 continue; |
|
304 } |
|
305 |
|
306 aImages[i].LowerCase(); |
|
307 |
|
308 CImageInfo imageInfo; |
|
309 imageInfo.SetId(KErrNotFound); |
|
310 imageInfo.SetIndex(i); |
|
311 imageInfo.SetCopies(1); |
|
312 |
|
313 // Image file path |
|
314 imageInfo.SetFilePathL(aImages[i]); |
|
315 |
|
316 // Parse obex "uri" |
|
317 TFileName tmpUri; |
|
318 |
|
319 TParse parse; |
|
320 parse.Set(aImages[i], NULL, NULL); |
|
321 |
|
322 // Get drive id and root path when multiple drive is enabled. |
|
323 TInt driveId; |
|
324 TFileName localRoot; |
|
325 User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, driveId)); |
|
326 User::LeaveIfError(PathInfo::GetRootPath(localRoot, driveId)); |
|
327 |
|
328 localRoot.LowerCase(); |
|
329 |
|
330 tmpUri.Copy(KObex()); |
|
331 // Note here: the correct format would be uuid.LongForm(), |
|
332 // but in currently supported services it is not required. |
|
333 tmpUri.AppendNum(KBTSDPDPROService, EHex); |
|
334 |
|
335 TFileName drive = parse.Drive(); |
|
336 |
|
337 TInt pos = localRoot.Find(drive); |
|
338 if(KErrNotFound < pos) |
|
339 { |
|
340 tmpUri.Append(KLocal()); |
|
341 } |
|
342 else |
|
343 { |
|
344 tmpUri.Append(KMmc()); |
|
345 } |
|
346 tmpUri.Append(parse.Path()); |
|
347 tmpUri.Append(parse.NameAndExt()); |
|
348 |
|
349 pos = tmpUri.Find(KBackSlash()); |
|
350 while(KErrNotFound != pos) |
|
351 { |
|
352 tmpUri.Replace(pos, KBackSlash().Length(), KSlash()); |
|
353 pos = tmpUri.Find(KBackSlash()); |
|
354 } |
|
355 |
|
356 LOG1("[CPrintJob::ConstructL]\t tmpUri: \"%S\"", &tmpUri); |
|
357 imageInfo.SetUriL(tmpUri); |
|
358 // LOG82("[CPrintJob::ConstructL]\t iFilePath: \"%S\", iUri: \"%S\"", &imageInfo.iFilePath, &imageInfo.iUri); |
|
359 |
|
360 iImages.Append(imageInfo); |
|
361 } |
|
362 |
|
363 iUserName.Copy(aUserName); |
|
364 iSheets = 0; |
|
365 } |
|
366 |
|
367 |
|
368 // Private functions |
|
369 //-------------------------------------------------------------------------------------------- |
|
370 // |
|
371 // CPrintJob::CPrintJob |
|
372 // |
|
373 //-------------------------------------------------------------------------------------------- |
|
374 CPrintJob::CPrintJob(CRsBtDevice* aDevice) : |
|
375 iJobId(KErrNotFound), |
|
376 iDeviceId(KErrNotFound), |
|
377 iDevice(aDevice), |
|
378 iUserName(KNullDesC8()), |
|
379 iSheets(0), |
|
380 iJobState(CPrintJob::EStateNone) |
|
381 { |
|
382 } |
|
383 |
|
384 //-------------------------------------------------------------------------------------------- |
|
385 // |
|
386 // CPrintJob::UpdateJobState |
|
387 // |
|
388 //-------------------------------------------------------------------------------------------- |
|
389 void CPrintJob::UpdateJobState(const TJobState aState) |
|
390 { |
|
391 iJobState = aState; |
|
392 } |
|
393 |
|
394 //-------------------------------------------------------------------------------------------- |
|
395 // |
|
396 // CPrintJob::JobState |
|
397 // |
|
398 //-------------------------------------------------------------------------------------------- |
|
399 CPrintJob::TJobState CPrintJob::JobState() |
|
400 { |
|
401 return iJobState; |
|
402 } |
|
403 |
|
404 //-------------------------------------------------------------------------------------------- |
|
405 // CPrintJob::GetPrintSetting |
|
406 //-------------------------------------------------------------------------------------------- |
|
407 TInt CPrintJob::GetPrintSetting(TInt aCapabilityID, TInt& aValue) |
|
408 { |
|
409 if(Device()) |
|
410 { |
|
411 for(TInt i = 0; i < Device()->CapabilityCount(); ++i) |
|
412 { |
|
413 TPrintCapability c; |
|
414 if(KErrNone == Device()->GetCapability(aCapabilityID, c) ) |
|
415 { |
|
416 aValue = c.iDefaultValue; |
|
417 LOG2("[CPrintJob::GetPrintSetting]\t %d = %d", aCapabilityID, aValue); |
|
418 return KErrNone; |
|
419 } |
|
420 } |
|
421 } |
|
422 |
|
423 aValue = KErrNotFound; |
|
424 |
|
425 LOG("[CPrintJob::GetPrintSetting]\t out: KErrInvalidData"); |
|
426 return KErrInvalidData; |
|
427 } |
|
428 |
|
429 //-------------------------------------------------------------------------------------------- |
|
430 // CPrintJob::SetPrintSetting |
|
431 //-------------------------------------------------------------------------------------------- |
|
432 TInt CPrintJob::SetPrintSetting(TInt aCapabilityID, TInt aValue) |
|
433 { |
|
434 LOG2("[CPrintJob::SetPrintSetting]\t %d = %d", aCapabilityID, aValue); |
|
435 |
|
436 if(Device()) |
|
437 return Device()->SetDefaultCapability(aCapabilityID, aValue); |
|
438 |
|
439 LOG("[CPrintJob::GetPrintSetting]\t out: KErrInvalidData"); |
|
440 return KErrInvalidSequence; |
|
441 } |
|
442 |
|
443 // End of File |
|