|
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: Contains the CDirectPrintBody class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <bluetooth/hci/hcierrors.h> |
|
20 |
|
21 #include "directprintbody.h" |
|
22 #include "directprintrsimageparser.h" |
|
23 #include "clog.h" |
|
24 #include "directprintselectitem.h" |
|
25 #include "directprintmessage.h" |
|
26 |
|
27 CDirectPrintBody* CDirectPrintBody::NewL() |
|
28 { |
|
29 CDirectPrintBody* self = new (ELeave) CDirectPrintBody(); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 CDirectPrintBody::~CDirectPrintBody() |
|
37 { |
|
38 LOG("CDirectPrintBody::~CDirectPrintBody begin"); |
|
39 delete iClassLoader; |
|
40 iImageFileNames.ResetAndDestroy(); |
|
41 delete iIdleDiscovery; |
|
42 LOG("CDirectPrintBody::~CDirectPrintBody end"); |
|
43 } |
|
44 |
|
45 TInt CDirectPrintBody::StartDiscovery(MPrinterDiscoveryObserver& aObserver, TUint aProtocols) |
|
46 { |
|
47 LOG1("CDirectPrintBody::StartDiscovery aProtocols: %d", aProtocols); |
|
48 iPrinterDiscoveryObserver = &aObserver; |
|
49 |
|
50 if( iCurrentProtocol ) |
|
51 { |
|
52 iCurrentProtocol->CancelDiscovery( EFalse ); |
|
53 } |
|
54 |
|
55 iCurrentProtocol = NULL; |
|
56 iClassLoader->Reset(); |
|
57 iProtocolsRequested = aProtocols; |
|
58 iDiscoveryCancelled = EFalse; |
|
59 TryNextDiscovery(); |
|
60 |
|
61 LOG("CDirectPrintBody::StartDiscovery end"); |
|
62 return KErrNone; |
|
63 } |
|
64 |
|
65 void CDirectPrintBody::CancelDiscovery() |
|
66 { |
|
67 LOG("CDirectPrintBody::CancelDiscovery begin"); |
|
68 iDiscoveryCancelled = ETrue; |
|
69 if( iCurrentProtocol ) |
|
70 { |
|
71 iCurrentProtocol->CancelDiscovery(); |
|
72 } |
|
73 LOG("CDirectPrintBody::CancelDiscovery end"); |
|
74 } |
|
75 |
|
76 |
|
77 TInt CDirectPrintBody::CreatePrintJobL(TInt aPrinterID, RPointerArray<TDesC>& aImages, MPrintEventObserver& aObserver) |
|
78 { |
|
79 LOG("CDirectPrintBody::CreatePrintJobL begin"); |
|
80 iPrinterPrintEventObserver = &aObserver; |
|
81 iCurrentPrintJobProtocol = NULL; |
|
82 |
|
83 if( iCurrentProtocol ) |
|
84 { |
|
85 iCurrentProtocol->CancelDiscovery( EFalse ); |
|
86 } |
|
87 |
|
88 #ifdef __IMAGE_PRINT_BASE |
|
89 TInt DeviceID; |
|
90 TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, iCurrentPrintJobProtocol ); |
|
91 if( !err ) |
|
92 { |
|
93 TInt count = aImages.Count(); |
|
94 if( count ) |
|
95 { |
|
96 iImageFileNames.ResetAndDestroy(); |
|
97 for( TInt i = 0; i < count; ++i ) |
|
98 { |
|
99 HBufC* fileName = aImages[i]->AllocLC(); |
|
100 iImageFileNames.AppendL( fileName ); |
|
101 CleanupStack::Pop(); // fileName |
|
102 } |
|
103 |
|
104 ActiveScheduler().SetCurrentProtocol( iCurrentPrintJobProtocol->SupportedProtocols() ); |
|
105 err = iCurrentPrintJobProtocol->CreatePrintJobL( DeviceID, aImages, *this ); |
|
106 } |
|
107 else |
|
108 { |
|
109 err = KErrInvalidData; |
|
110 } |
|
111 } |
|
112 #endif // __IMAGE_PRINT_BASE |
|
113 |
|
114 TInt DeviceID; |
|
115 TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, iCurrentPrintJobProtocol ); |
|
116 if( !err ) |
|
117 { |
|
118 ActiveScheduler().SetCurrentProtocol( iCurrentPrintJobProtocol->SupportedProtocols() ); |
|
119 err = iCurrentPrintJobProtocol->CreatePrintJobL( DeviceID, aImages, *this ); |
|
120 } |
|
121 |
|
122 LOG1("CDirectPrintBody::CreatePrintJobL return: %d", err); |
|
123 return err; |
|
124 } |
|
125 |
|
126 |
|
127 void CDirectPrintBody::SubmitPrintJobL() |
|
128 { |
|
129 LOG1("CDirectPrintBody::SubmitPrintJobL iCurrentPrintJobProtocol: %d", iCurrentPrintJobProtocol); |
|
130 TInt err( KErrNone ); |
|
131 |
|
132 if( !iCurrentPrintJobProtocol ) |
|
133 { |
|
134 err = KErrInvalidSequence; |
|
135 } |
|
136 if( !err ) |
|
137 { |
|
138 TInt invalidImages; |
|
139 err = ValidateImagesL( iImageFileNames, invalidImages ); |
|
140 LOG1("CDirectPrintBody::SubmitPrintJobL ValidateImagesL returns: %d", err); |
|
141 } |
|
142 |
|
143 User::LeaveIfError( err ); |
|
144 |
|
145 iCurrentPrintJobProtocol->SubmitPrintJobL(); |
|
146 |
|
147 LOG("CDirectPrintBody::SubmitPrintJobL end"); |
|
148 } |
|
149 |
|
150 |
|
151 TInt CDirectPrintBody::CancelPrintJob() |
|
152 { |
|
153 LOG("CDirectPrintBody::CancelPrintJob begin"); |
|
154 TInt err( KErrNone ); |
|
155 if( !iCurrentPrintJobProtocol ) |
|
156 { |
|
157 err = KErrInvalidSequence; |
|
158 } |
|
159 if( !err ) |
|
160 { |
|
161 err = iCurrentPrintJobProtocol->CancelPrintJob(); |
|
162 } |
|
163 LOG1("CDirectPrintBody::CancelPrintJob return: %d", err); |
|
164 return err; |
|
165 } |
|
166 |
|
167 |
|
168 TInt CDirectPrintBody::ContinuePrintJobL() |
|
169 { |
|
170 LOG("CDirectPrintBody::ContinuePrintJobL begin"); |
|
171 TInt err( KErrInvalidSequence ); |
|
172 if( iCurrentPrintJobProtocol ) |
|
173 { |
|
174 err = iCurrentPrintJobProtocol->ContinuePrintJobL(); |
|
175 } |
|
176 LOG1("CDirectPrintBody::ContinuePrintJobL return: %d", err); |
|
177 return err; |
|
178 } |
|
179 |
|
180 |
|
181 TInt CDirectPrintBody::GetNumPrintPages() |
|
182 { |
|
183 LOG("CDirectPrintBody::GetNumPrintPages begin"); |
|
184 TInt err( KErrInvalidSequence ); |
|
185 if( iCurrentPrintJobProtocol ) |
|
186 { |
|
187 err = iCurrentPrintJobProtocol->GetNumPrintPages(); |
|
188 } |
|
189 LOG1("CDirectPrintBody::GetNumPrintPages return: %d", err); |
|
190 return err; |
|
191 } |
|
192 |
|
193 TInt CDirectPrintBody::GetJobStatus() |
|
194 { |
|
195 LOG("CDirectPrintBody::GetJobStatus begin"); |
|
196 TInt err( KErrInvalidSequence ); |
|
197 if( iCurrentPrintJobProtocol ) |
|
198 { |
|
199 err = iCurrentPrintJobProtocol->GetPrintJobStatus(); |
|
200 } |
|
201 LOG1("CDirectPrintBody::GetJobStatus return: %d", err); |
|
202 return err; |
|
203 } |
|
204 |
|
205 TInt CDirectPrintBody::GetPrinterStatus(TInt aPrinterID) |
|
206 { |
|
207 LOG1("CDirectPrintBody::GetPrinterStatus aPrinterID: %d", aPrinterID); |
|
208 TInt DeviceID; |
|
209 MProtPrintingDevice* theProtToQuery = NULL; |
|
210 TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery ); |
|
211 if( !err ) |
|
212 { |
|
213 err = theProtToQuery->GetPrinterStatus( DeviceID ); |
|
214 } |
|
215 LOG1("CDirectPrintBody::GetPrinterStatus return: %d", err); |
|
216 return err; |
|
217 } |
|
218 |
|
219 TInt CDirectPrintBody::GetPrinterCapabilityIDsL(TInt aPrinterID, RArray<TInt>& aCapabilityIDs) |
|
220 { |
|
221 LOG1("CDirectPrintBody::GetPrinterCapabilityIDsL aPrinterID: %d", aPrinterID); |
|
222 TInt DeviceID; |
|
223 MProtPrintingDevice* theProtToQuery = NULL; |
|
224 |
|
225 TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery ); |
|
226 if( !err ) |
|
227 { |
|
228 err = theProtToQuery->GetDeviceCapabilityIDsL( DeviceID, aCapabilityIDs ); |
|
229 } |
|
230 else if( err == KErrNotFound ) |
|
231 { |
|
232 err = KErrInvalidData; |
|
233 } |
|
234 |
|
235 LOG1("CDirectPrintBody::GetPrinterCapabilityIDsL return: %d", err); |
|
236 return err; |
|
237 } |
|
238 |
|
239 TInt CDirectPrintBody::GetPrinterCapabilityL(TInt aPrinterID, TInt aCapabilityID, TDirectPrintCapability& aCapability) |
|
240 { |
|
241 LOG1("CDirectPrintBody::GetPrinterCapabilityL aPrinterID: %d", aPrinterID); |
|
242 LOG1("CDirectPrintBody::GetPrinterCapabilityL aCapabilityID: %d", aCapabilityID); |
|
243 TInt DeviceID; |
|
244 MProtPrintingDevice* theProtToQuery = NULL; |
|
245 |
|
246 TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery ); |
|
247 if( !err ) |
|
248 { |
|
249 err = theProtToQuery->GetDeviceCapabilityL( DeviceID, aCapabilityID, aCapability ); |
|
250 } |
|
251 else if( err == KErrNotFound ) |
|
252 { |
|
253 err = KErrInvalidData; |
|
254 } |
|
255 |
|
256 LOG1("CDirectPrintBody::GetPrinterCapabilityL return: %d", err); |
|
257 return err; |
|
258 } |
|
259 |
|
260 TInt CDirectPrintBody::GetJobSetting(TInt aCapabilityID, TInt& aValue) |
|
261 { |
|
262 LOG1("CDirectPrintBody::GetJobSetting aCapabilityID: %d", aCapabilityID); |
|
263 TInt err( KErrInvalidSequence ); |
|
264 if( iCurrentPrintJobProtocol ) |
|
265 { |
|
266 err = iCurrentPrintJobProtocol->GetJobSetting( aCapabilityID, aValue ); |
|
267 } |
|
268 LOG1("CDirectPrintBody::GetJobSetting return: %d", err); |
|
269 return err; |
|
270 } |
|
271 |
|
272 TInt CDirectPrintBody::SetJobSettingL(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability) |
|
273 { |
|
274 LOG1("CDirectPrintBody::SetJobSettingL aCapabilityID: %d", aCapabilityID); |
|
275 LOG1("CDirectPrintBody::SetJobSettingL aValue: %d", aValue); |
|
276 TInt err( KErrInvalidSequence ); |
|
277 if( iCurrentPrintJobProtocol ) |
|
278 { |
|
279 err = iCurrentPrintJobProtocol->SetJobSettingL( aCapabilityID, aValue, aAffectedCapability ); |
|
280 } |
|
281 LOG1("CDirectPrintBody::SetJobSettingL return: %d", err); |
|
282 return err; |
|
283 } |
|
284 |
|
285 TInt CDirectPrintBody::GetNumPreviewPages() |
|
286 { |
|
287 LOG("CDirectPrintBody::GetNumPreviewPages"); |
|
288 TInt err( KErrInvalidSequence ); |
|
289 if( iCurrentPrintJobProtocol ) |
|
290 { |
|
291 err = iCurrentPrintJobProtocol->GetNumPreviewPages(); |
|
292 } |
|
293 LOG1("CDirectPrintBody::GetNumPreviewPages return: %d", err); |
|
294 return err; |
|
295 } |
|
296 |
|
297 TInt CDirectPrintBody::GetJobTemplateIconL( TInt aTemplateID, TInt& aFbsBitmapHandle ) |
|
298 { |
|
299 LOG1("CDirectPrintBody::GetJobTemplateIconL aTemplateID: %d", aTemplateID); |
|
300 TInt err( KErrInvalidSequence ); |
|
301 if( iCurrentPrintJobProtocol ) |
|
302 { |
|
303 err = iCurrentPrintJobProtocol->GetJobTemplateIconL( aTemplateID, aFbsBitmapHandle ); |
|
304 } |
|
305 LOG1("CDirectPrintBody::GetJobTemplateIconL return: %d", err); |
|
306 return err; |
|
307 } |
|
308 |
|
309 TInt CDirectPrintBody::CreatePreviewImage(TInt aPageNumber) |
|
310 { |
|
311 LOG1("CDirectPrintBody::CreatePreviewImage aPageNumber: %d", aPageNumber); |
|
312 TInt err( KErrInvalidSequence ); |
|
313 if( iCurrentPrintJobProtocol ) |
|
314 { |
|
315 err = iCurrentPrintJobProtocol->CreatePreviewImage(aPageNumber); |
|
316 } |
|
317 LOG1("CDirectPrintBody::CreatePreviewImage return: %d", err); |
|
318 return err; |
|
319 } |
|
320 |
|
321 TInt CDirectPrintBody::RemoveCachedPrinterL(TInt aPrinterID) |
|
322 { |
|
323 LOG1("CDirectPrintBody::RemoveCachedPrinterL aPrinterID: %d", aPrinterID); |
|
324 TInt DeviceID; |
|
325 MProtPrintingDevice* theProtToQuery = NULL; |
|
326 TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery ); |
|
327 if( !err ) |
|
328 { |
|
329 err = theProtToQuery->RemoveCachedDeviceL( DeviceID ); |
|
330 } |
|
331 LOG1("CDirectPrintBody::RemoveCachedPrinterL return: %d", err); |
|
332 return err; |
|
333 } |
|
334 |
|
335 TUint CDirectPrintBody::SupportedProtocols() |
|
336 { |
|
337 LOG("CDirectPrintBody::SupportedProtocols begin"); |
|
338 TUint prots = iClassLoader->SupportedProtocols(); |
|
339 LOG1("CDirectPrintBody::SupportedProtocols return: %d", prots); |
|
340 return prots; |
|
341 } |
|
342 |
|
343 void CDirectPrintBody::RegisterIdleObserver(MIdleObserver *aObserver) |
|
344 { |
|
345 LOG("CDirectPrintBody::RegisterIdleObserver begin"); |
|
346 iPrinterIdleObserver = aObserver; |
|
347 LOG("CDirectPrintBody::RegisterIdleObserver end"); |
|
348 } |
|
349 |
|
350 // From MProtDiscoveryObserver. |
|
351 void CDirectPrintBody::FoundDeviceL(TPrinter& aDeviceInfo) |
|
352 { |
|
353 LOG("CDirectPrintBody::FoundDeviceL begin"); |
|
354 if( iPrinterDiscoveryObserver ) |
|
355 { |
|
356 //Check that device id is valid, there can't be any bits in the protocol field (higher bits) |
|
357 if( !( PROTOCOL_ID_FIELD_MASK & aDeviceInfo.iPrinterID ) ) |
|
358 { |
|
359 // Get the protocol index number |
|
360 TInt protocolIndex = iClassLoader->GetProtocolIndex(); |
|
361 |
|
362 // Left shift this number so that it occupies the higher X bits (the PROTOCOL_ID_BIT_COUNT highest bits) |
|
363 protocolIndex <<= sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT; |
|
364 |
|
365 // Add the protocol index number to the device id |
|
366 aDeviceInfo.iPrinterID |= protocolIndex; |
|
367 |
|
368 // Forward the FoundPrinterL callback to the observer |
|
369 iPrinterDiscoveryObserver->FoundPrinterL( aDeviceInfo ); |
|
370 } |
|
371 } |
|
372 LOG("CDirectPrintBody::FoundDeviceL end"); |
|
373 } |
|
374 |
|
375 void CDirectPrintBody::DiscoveryStatusL( TInt aStatus, TInt aErrorCode, TInt aErrorStringCode ) |
|
376 { |
|
377 LOG1("CDirectPrintBody::DiscoveryStatusL aStatus: %d", aStatus); |
|
378 LOG1("CDirectPrintBody::DiscoveryStatusL aErrorCode: %d", aErrorCode); |
|
379 LOG1("CDirectPrintBody::DiscoveryStatusL aErrorStringCode: %d", aErrorStringCode); |
|
380 if( iPrinterDiscoveryObserver ) |
|
381 { |
|
382 switch( aStatus ) |
|
383 { |
|
384 case EDiscoveryFinished: // Done with 1 protocol. |
|
385 { |
|
386 // When Bluetooth discovery is finished, but Bluetooth is not enabled pass error code to UI. |
|
387 if ( aErrorCode == ENoConnection ) |
|
388 { |
|
389 iPrinterDiscoveryObserver->DiscoveryStatusL( aStatus, aErrorCode, aErrorStringCode ); |
|
390 } |
|
391 iCurrentProtocol = NULL; |
|
392 TUint doDiscovery = iProtocolsRequested & iClassLoader->SupportedProtocols(); |
|
393 LOG1("CDirectPrintBody::DiscoveryStatusL doDiscovery: %d", doDiscovery); |
|
394 LOG1("CDirectPrintBody::DiscoveryStatusL iDiscoveryCancelled: %d", iDiscoveryCancelled); |
|
395 if( ( !doDiscovery && aErrorCode == KErrCancel ) || iDiscoveryCancelled ) |
|
396 { |
|
397 iPrinterDiscoveryObserver->DiscoveryStatusL( aStatus, aErrorCode, aErrorStringCode ); |
|
398 } |
|
399 else |
|
400 { |
|
401 TryNextDiscovery(); |
|
402 } |
|
403 } |
|
404 break; |
|
405 default: // Discovering, Cancelling. |
|
406 iCurrentProtocol = NULL; |
|
407 iPrinterDiscoveryObserver->DiscoveryStatusL( aStatus, aErrorCode, aErrorStringCode ); |
|
408 break; |
|
409 } |
|
410 } |
|
411 LOG("CDirectPrintBody::DiscoveryStatusL end"); |
|
412 } |
|
413 |
|
414 |
|
415 void CDirectPrintBody::RemoveDeviceL(TPrinter& aDeviceInfo) |
|
416 { |
|
417 LOG("CDirectPrintBody::RemoveDeviceL begin"); |
|
418 if( iPrinterDiscoveryObserver ) |
|
419 { |
|
420 if (PROTOCOL_ID_FIELD_MASK & aDeviceInfo.iPrinterID) |
|
421 { //Invalid id, reject printer |
|
422 } |
|
423 else |
|
424 { // Get the protocol index number |
|
425 TInt protocolIndex = iClassLoader->GetProtocolIndex(); |
|
426 |
|
427 // Left shift this number so that it occupies the higher X bits (the PROTOCOL_ID_BIT_COUNT highest bits) |
|
428 protocolIndex <<= sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT; |
|
429 |
|
430 // Add the protocol index number to the device id |
|
431 aDeviceInfo.iPrinterID |= protocolIndex; |
|
432 |
|
433 // Forward the RemovePrinterL callback to the observer |
|
434 iPrinterDiscoveryObserver->RemovePrinterL( aDeviceInfo ); |
|
435 } |
|
436 } |
|
437 LOG("CDirectPrintBody::RemoveDeviceL end"); |
|
438 } |
|
439 |
|
440 // From MProtPrintEventObserver. |
|
441 void CDirectPrintBody::PrintJobProgressEvent(TInt aStatus, TInt aPercent, TInt aJobStateCode) |
|
442 { |
|
443 LOG1("CDirectPrintBody::PrintJobProgressEvent aStatus: %d", aStatus); |
|
444 LOG1("CDirectPrintBody::PrintJobProgressEvent aPercent: %d", aPercent); |
|
445 LOG1("CDirectPrintBody::PrintJobProgressEvent aJobStateCode: %d", aJobStateCode); |
|
446 if( iPrinterPrintEventObserver ) |
|
447 iPrinterPrintEventObserver->PrintJobProgressEvent(aStatus, aPercent, aJobStateCode); |
|
448 LOG("CDirectPrintBody::PrintJobProgressEvent end"); |
|
449 } |
|
450 |
|
451 void CDirectPrintBody::PrintJobErrorEvent(TInt aErrorCode, TInt aErrorStringCode) |
|
452 { |
|
453 LOG1("CDirectPrintBody::PrintJobErrorEvent aErrorCode: %d", aErrorCode); |
|
454 LOG1("CDirectPrintBody::PrintJobErrorEvent aErrorStringCode: %d", aErrorStringCode); |
|
455 if( iPrinterPrintEventObserver ) |
|
456 iPrinterPrintEventObserver->PrintJobErrorEvent(aErrorCode, aErrorStringCode); |
|
457 LOG("CDirectPrintBody::PrintJobErrorEvent end"); |
|
458 } |
|
459 |
|
460 void CDirectPrintBody::PrinterStatusEvent(TInt aErrorCode, TInt aErrorStringCode) |
|
461 { |
|
462 LOG1("CDirectPrintBody::PrinterStatusEvent aErrorCode: %d", aErrorCode); |
|
463 LOG1("CDirectPrintBody::PrinterStatusEvent aErrorStringCode: %d", aErrorStringCode); |
|
464 if( iPrinterPrintEventObserver ) |
|
465 iPrinterPrintEventObserver->PrinterStatusEvent(aErrorCode, aErrorStringCode); |
|
466 LOG("CDirectPrintBody::PrinterStatusEvent end"); |
|
467 } |
|
468 |
|
469 void CDirectPrintBody::PreviewImageEvent(TInt aFsBitmapHandle) |
|
470 { |
|
471 LOG1("CDirectPrintBody::PreviewImageEvent aFsBitmapHandle: %d", aFsBitmapHandle); |
|
472 if( iPrinterPrintEventObserver ) |
|
473 iPrinterPrintEventObserver->PreviewImageEvent(aFsBitmapHandle); |
|
474 LOG("CDirectPrintBody::PreviewImageEvent end"); |
|
475 } |
|
476 |
|
477 void CDirectPrintBody::ShowMessageL(TInt aMsgLine1Code, TInt aMsgLine2Code) |
|
478 { |
|
479 LOG1("CDirectPrintBody::ShowMessageL aMsgLine1Code: %d", aMsgLine1Code); |
|
480 LOG1("CDirectPrintBody::ShowMessageL aMsgLine2Code: %d", aMsgLine2Code); |
|
481 if( iPrinterPrintEventObserver ) |
|
482 iPrinterPrintEventObserver->ShowMessageL(aMsgLine1Code, aMsgLine2Code); |
|
483 LOG("CDirectPrintBody::ShowMessageL end"); |
|
484 } |
|
485 |
|
486 TBool CDirectPrintBody::AskYesNoQuestionL(TInt aMsgLine1Code, TInt aMsgLine2Code) |
|
487 { |
|
488 LOG1("CDirectPrintBody::AskYesNoQuestionL aMsgLine1Code: %d", aMsgLine1Code); |
|
489 LOG1("CDirectPrintBody::AskYesNoQuestionL aMsgLine2Code: %d", aMsgLine2Code); |
|
490 TBool res( EFalse ); |
|
491 if( iPrinterPrintEventObserver ) |
|
492 { |
|
493 res = iPrinterPrintEventObserver->AskYesNoQuestionL(aMsgLine1Code, aMsgLine2Code); |
|
494 } |
|
495 LOG1("CDirectPrintBody::AskYesNoQuestionL return: %d", res); |
|
496 return res; |
|
497 } |
|
498 |
|
499 const TDesC& CDirectPrintBody::AskForInputL(TInt aMsgLine1Code, TInt aMsgLine2Code) |
|
500 { |
|
501 LOG1("CDirectPrintBody::ShowMessageL aMsgLine1Code: %d", aMsgLine1Code); |
|
502 LOG1("CDirectPrintBody::ShowMessageL aMsgLine2Code: %d", aMsgLine2Code); |
|
503 if( iPrinterPrintEventObserver ) |
|
504 { |
|
505 return iPrinterPrintEventObserver->AskForInputL(aMsgLine1Code, aMsgLine2Code); |
|
506 } |
|
507 else |
|
508 { |
|
509 return KNullDesC; |
|
510 } |
|
511 } |
|
512 |
|
513 void CDirectPrintBody::StatusEvent(const TEvent& aEvent, TInt aError, TInt aMsgCode) |
|
514 { |
|
515 LOG1("CDirectPrintBody::StatusEvent aError: %d", aError); |
|
516 LOG1("CDirectPrintBody::StatusEvent aMsgCode: %d", aMsgCode); |
|
517 LOG1("CDirectPrintBody::StatusEvent aEvent.iProtocol: %d", aEvent.iProtocol); |
|
518 LOG1("CDirectPrintBody::StatusEvent aEvent.iSeverity: %d", aEvent.iSeverity); |
|
519 LOG1("CDirectPrintBody::StatusEvent aEvent.iEventType: %d", aEvent.iEventType); |
|
520 |
|
521 if( iPrinterIdleObserver ) |
|
522 { |
|
523 iPrinterIdleObserver->StatusEvent( aEvent, aError, aMsgCode ); |
|
524 } |
|
525 |
|
526 if( aEvent.iEventType == EAsynchronousLeave ) |
|
527 { |
|
528 // a protocol threw an async leave |
|
529 // we continue with other protocols |
|
530 TUint doDiscovery = iProtocolsRequested & iClassLoader->SupportedProtocols(); |
|
531 if( doDiscovery ) TryNextDiscovery(); |
|
532 } |
|
533 LOG("CDirectPrintBody::StatusEvent end"); |
|
534 } |
|
535 |
|
536 CDirectPrintBody::CDirectPrintBody() |
|
537 : iCurrentProtocol( NULL ) |
|
538 , iCurrentPrintJobProtocol( NULL ) |
|
539 { |
|
540 LOG("CDirectPrintBody::CDirectPrintBody begin"); |
|
541 LOG("CDirectPrintBody::CDirectPrintBody end"); |
|
542 } |
|
543 |
|
544 void CDirectPrintBody::ConstructL() |
|
545 { |
|
546 LOG("CDirectPrintBody::ConstructL begin"); |
|
547 iClassLoader = CDirectPrintProtocolsLoader::NewL(); |
|
548 iClassLoader->Reset(); |
|
549 for( TInt x=0; x < iClassLoader->GetNumberOfProtocolsAvailable(); ++x ) |
|
550 { |
|
551 iClassLoader->GetNextProtocol()->RegisterIdleObserver( this ); |
|
552 } |
|
553 |
|
554 iIdleDiscovery = CIdle::NewL( CActive::EPriorityIdle ); |
|
555 ActiveScheduler().SetIdleObserver( *this ); |
|
556 LOG("CDirectPrintBody::ConstructL end"); |
|
557 } |
|
558 |
|
559 CDirectPrintScheduler& CDirectPrintBody::ActiveScheduler() const |
|
560 { |
|
561 LOG("CDirectPrintBody::ActiveScheduler begin"); |
|
562 CDirectPrintScheduler* scheduler = static_cast<CDirectPrintScheduler*>( CActiveScheduler::Current() ); |
|
563 LOG("CDirectPrintBody::ActiveScheduler end"); |
|
564 return *scheduler; |
|
565 } |
|
566 |
|
567 TInt CDirectPrintBody::FindInternalDeviceReference(TInt aExternalDeviceID, TInt& aInternalDeviceID, MProtPrintingDevice*& aProtToUse) |
|
568 { |
|
569 LOG1("CDirectPrintBody::FindInternalDeviceReference aExternalDeviceID: %d", aExternalDeviceID); |
|
570 TInt err( KErrNotFound ); |
|
571 |
|
572 #ifdef __IMAGE_PRINT_BASE |
|
573 aProtToUse = NULL; |
|
574 |
|
575 // Separate the external id into the corresponding fields |
|
576 TInt protId = aExternalDeviceID & PROTOCOL_ID_FIELD_MASK; |
|
577 |
|
578 TInt deviceId = aExternalDeviceID & DEVICE_ID_FIELD_MASK; |
|
579 protId >>= (sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT); |
|
580 // If TInt is more than 4 bytes the mask should clear everything but the 6 least significant bits |
|
581 protId &= PROTOCOL_ID_CLEAR_MASK; //remove 1's if the original protId was negative |
|
582 |
|
583 // Check that the external ID does indeed belong to one of the currently |
|
584 // loaded protocols |
|
585 if( protId >= 0 && protId < iClassLoader->GetNumberOfProtocolsAvailable() ) |
|
586 { |
|
587 aInternalDeviceID = deviceId; |
|
588 aProtToUse = iClassLoader->GetProtocolAt(protId); |
|
589 if( aProtToUse ) err = KErrNone; |
|
590 } |
|
591 #endif // __IMAGE_PRINT_BASE |
|
592 #if 1 // ko |
|
593 TInt protId = aExternalDeviceID & PROTOCOL_ID_FIELD_MASK; |
|
594 protId >>= (sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT); |
|
595 protId &= PROTOCOL_ID_CLEAR_MASK; |
|
596 if( protId >= 0 && protId < iClassLoader->GetNumberOfProtocolsAvailable() ) |
|
597 { |
|
598 aInternalDeviceID = 128; |
|
599 aProtToUse = iClassLoader->GetProtocolAt(protId); |
|
600 if( aProtToUse ) err = KErrNone; |
|
601 } |
|
602 #else // ko |
|
603 aInternalDeviceID = 128; |
|
604 aProtToUse = iClassLoader->GetProtocolAt(0); |
|
605 if( aProtToUse ) err = KErrNone; |
|
606 #endif // ko |
|
607 LOG1("CDirectPrintBody::FindInternalDeviceReference return: %d", err); |
|
608 return err; |
|
609 } |
|
610 |
|
611 TInt CDirectPrintBody::ValidateImagesL(const RPointerArray<HBufC>& aImageList, TInt &aInvalidCount) |
|
612 { |
|
613 LOG1("CDirectPrintBody::ValidateImagesL aImageList.Count(): %d", aImageList.Count()); |
|
614 aInvalidCount = 0; |
|
615 TInt lastError = KErrNone; |
|
616 CDirectPrintRsImageParser *imageParser = CDirectPrintRsImageParser::NewLC(); |
|
617 |
|
618 for( TInt nCnt=0; nCnt < aImageList.Count(); ++nCnt ) |
|
619 { |
|
620 LOG1("CDirectPrintBody::ValidateImagesL nCnt: %d", nCnt); |
|
621 LOG1("CDirectPrintBody::ValidateImagesL image: %S", aImageList[nCnt]); |
|
622 TBool valid; |
|
623 imageParser->ValidateL(*(aImageList[nCnt]), valid, lastError); |
|
624 LOG1("CDirectPrintBody::ValidateImagesL valid: %d", valid); |
|
625 LOG1("CDirectPrintBody::ValidateImagesL lastError: %d", lastError); |
|
626 if( !valid ) |
|
627 { |
|
628 ++aInvalidCount; |
|
629 } |
|
630 } |
|
631 |
|
632 CleanupStack::PopAndDestroy(imageParser); |
|
633 LOG1("CDirectPrintBody::ValidateImagesL aInvalidCount: %d", aInvalidCount); |
|
634 LOG1("CDirectPrintBody::ValidateImagesL ends with: %d", lastError); |
|
635 return lastError; |
|
636 } |
|
637 |
|
638 void CDirectPrintBody::TryNextDiscovery() |
|
639 { |
|
640 LOG("CDirectPrintBody::TryNextDiscovery begin"); |
|
641 iIdleDiscovery->Cancel(); |
|
642 iIdleDiscovery->Start(TCallBack(TryNextDiscoveryL, this)); |
|
643 LOG("CDirectPrintBody::TryNextDiscovery end"); |
|
644 } |
|
645 |
|
646 void CDirectPrintBody::DoTryNextDiscoveryL() |
|
647 { |
|
648 LOG("CDirectPrintBody::DoTryNextDiscoveryL begin"); |
|
649 TUint doDiscovery = iProtocolsRequested & iClassLoader->SupportedProtocols(); |
|
650 LOG1("CDirectPrintBody::DoTryNextDiscoveryL doDiscovery: %d", doDiscovery); |
|
651 if( doDiscovery ) |
|
652 { |
|
653 TBool found( EFalse ); |
|
654 TInt protId( 0 ); |
|
655 TInt count = iClassLoader->GetNumberOfProtocolsAvailable(); |
|
656 LOG1("CDirectPrintBody::DoTryNextDiscoveryL count: %d", count); |
|
657 for( TInt i = 0; i < count && !found; i++ ) |
|
658 { |
|
659 iCurrentProtocol = iClassLoader->GetNextProtocol(); |
|
660 protId = iCurrentProtocol->SupportedProtocols(); |
|
661 if( iProtocolsRequested & protId ) found = ETrue; |
|
662 } |
|
663 LOG1("CDirectPrintBody::DoTryNextDiscoveryL found: %d", found); |
|
664 LOG1("CDirectPrintBody::DoTryNextDiscoveryL protId: %d", protId); |
|
665 if( found ) |
|
666 { |
|
667 TUint temp = KMaxTUint ^ protId; |
|
668 iProtocolsRequested &= temp; |
|
669 LOG1("CDirectPrintBody::DoTryNextDiscoveryL iProtocolsRequested: %d", iProtocolsRequested); |
|
670 ActiveScheduler().SetCurrentProtocol( protId ); |
|
671 iCurrentProtocol->StartDiscoveryL( *this, protId ); |
|
672 } |
|
673 } |
|
674 else |
|
675 { |
|
676 iPrinterDiscoveryObserver->DiscoveryStatusL( EDiscoveryFinished, 0, 0 ); |
|
677 } |
|
678 LOG("CDirectPrintBody::DoTryNextDiscoveryL end"); |
|
679 } |
|
680 |
|
681 TInt CDirectPrintBody::TryNextDiscoveryL(TAny* aObj) |
|
682 { |
|
683 LOG("CDirectPrintBody::TryNextDiscoveryL begin"); |
|
684 CDirectPrintBody* obj = static_cast<CDirectPrintBody*>(aObj); |
|
685 obj->DoTryNextDiscoveryL(); |
|
686 LOG("CDirectPrintBody::TryNextDiscoveryL end"); |
|
687 return EFalse; |
|
688 } |
|
689 |
|
690 void CDirectPrintBody::SetNumsOfCopiesL( const RArray<TInt>& aNumsOfCopies, TInt& aErr ) |
|
691 { |
|
692 LOG1("CDirectPrintBody::SetNumberOfCopiesL aNumsOfCopies.Count(): %d", aNumsOfCopies.Count()); |
|
693 |
|
694 if( iCurrentPrintJobProtocol ) |
|
695 { |
|
696 iCurrentPrintJobProtocol->SetNumsOfCopiesL( aNumsOfCopies, aErr ); |
|
697 LOG1("CDirectPrintBody::SetNumberOfCopiesL aErr: %d", aErr); |
|
698 } |
|
699 |
|
700 LOG("CDirectPrintBody::SetNumberOfCopiesL end"); |
|
701 } |
|
702 |
|
703 void CDirectPrintBody::HandleSessionDisconnect( const MIdleObserver* aIdleObserver, |
|
704 const MPrinterDiscoveryObserver* aDiscoveryObserver, |
|
705 const MPrintEventObserver* aEventObserver ) |
|
706 { |
|
707 LOG1("CDirectPrintBody::HandleSessionDisconnect aIdleObserver address: %d", aIdleObserver); |
|
708 LOG1("CDirectPrintBody::HandleSessionDisconnect iPrinterIdleObserver address: %d", iPrinterIdleObserver); |
|
709 LOG1("CDirectPrintBody::HandleSessionDisconnect aDiscoveryObserver address: %d", aDiscoveryObserver); |
|
710 LOG1("CDirectPrintBody::HandleSessionDisconnect iPrinterDiscoveryObserver address: %d", iPrinterDiscoveryObserver); |
|
711 LOG1("CDirectPrintBody::HandleSessionDisconnect aEventObserver address: %d", aEventObserver); |
|
712 LOG1("CDirectPrintBody::HandleSessionDisconnect iPrinterPrintEventObserver address: %d", iPrinterPrintEventObserver); |
|
713 if( aIdleObserver == iPrinterIdleObserver ) iPrinterIdleObserver = NULL; |
|
714 if( aEventObserver == iPrinterPrintEventObserver ) iPrinterPrintEventObserver = NULL; |
|
715 if( aDiscoveryObserver == iPrinterDiscoveryObserver ) iPrinterDiscoveryObserver = NULL; |
|
716 LOG("CDirectPrintBody::HandleSessionDisconnect end"); |
|
717 } |
|
718 |
|
719 TInt CDirectPrintBody::ProtocolCount() |
|
720 { |
|
721 return iClassLoader->GetNumberOfProtocolsAvailable(); |
|
722 } |
|
723 |
|
724 TInt CDirectPrintBody::GetProtocolNameL( TDpMessage& aMessage ) |
|
725 { |
|
726 TDirectPrintSelectItem item; |
|
727 TInt index = aMessage.Int0(); |
|
728 TInt err = iClassLoader->GetProtocolName(index, item.iName, item.iId); |
|
729 |
|
730 if (err == KErrNone) |
|
731 { |
|
732 TPtr8 ptr(reinterpret_cast<TUint8*>(&item), sizeof(item), sizeof(item)); |
|
733 aMessage.WriteL( 1, ptr ); |
|
734 } |
|
735 |
|
736 return err; |
|
737 } |
|
738 |
|
739 // End of File |