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 CDPOFPrintingDevice class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <barsc.h> |
|
21 #include <dpof.rsg> |
|
22 #include <bautils.h> |
|
23 |
|
24 #include "cdpofprintingdevice.h" |
|
25 #include "cconfirmationquery.h" |
|
26 #include "cprintercapabilities.h" |
|
27 #include "cprinterelement.h" |
|
28 #include "imgprintkonst.h" |
|
29 #include "tsetting.h" |
|
30 #include "rsutils.h" |
|
31 #include "printcapabilitycodes.h" |
|
32 #include "printmessagecodes.h" |
|
33 #include "imageprint.h" |
|
34 #include "clog.h" |
|
35 #include "cprintjob.h" |
|
36 |
|
37 // CONSTANTS |
|
38 namespace |
|
39 { |
|
40 /// DPOF Version Major. |
|
41 const TInt KDPOFVersionMajor = 0; |
|
42 /// DPOF Version Minor. |
|
43 const TInt KDPOFVersionMinor = 0; |
|
44 /// DPOF Version Build. |
|
45 const TInt KDPOFVersionBuild = 1; |
|
46 |
|
47 _LIT( KResourceFileName, "imageprintdata\\protocols\\dpof.rsc" ); |
|
48 |
|
49 const TInt KMmcPrinterId = 1; |
|
50 _LIT( KMmcPrinterName, "Memory Card" ); |
|
51 } |
|
52 |
|
53 |
|
54 MProtPrintingDevice* CDPOFPrintingDevice::NewL() |
|
55 { |
|
56 return new (ELeave) CDPOFPrintingDevice(); |
|
57 } |
|
58 |
|
59 |
|
60 CDPOFPrintingDevice::CDPOFPrintingDevice() : CActive( CActive::EPriorityStandard ), |
|
61 iPrintError( KErrNone ), |
|
62 iPrintErrorMsgCode( 0 ) |
|
63 { |
|
64 CActiveScheduler::Add(this); |
|
65 } |
|
66 |
|
67 void CDPOFPrintingDevice::ConstructL(const TDesC& /*aDLLPath*/) |
|
68 { |
|
69 LOG("CDPOFPrintingDevice::ConstructL begin"); |
|
70 |
|
71 iCancelledByUser = EFalse; |
|
72 |
|
73 iPrintJob = new (ELeave) CPrintJob(); |
|
74 |
|
75 iMappingArray.AppendL(TMapping(1,EPrintCapabLayout1UpMedium)); |
|
76 iMappingArray.AppendL(TMapping(2,EPrintCapabLayout2Up)); |
|
77 iMappingArray.AppendL(TMapping(4,EPrintCapabLayout4Up)); |
|
78 iMappingArray.AppendL(TMapping(6,EPrintCapabLayout6Up)); |
|
79 iMappingArray.AppendL(TMapping(9,EPrintCapabLayout9Up)); |
|
80 iMappingArray.AppendL(TMapping(12,EPrintCapabLayout12Up)); |
|
81 iMappingArray.AppendL(TMapping(16,EPrintCapabLayout16Up)); |
|
82 |
|
83 RFs fs; |
|
84 User::LeaveIfError( fs.Connect() ); |
|
85 CleanupClosePushL( fs ); |
|
86 // Loading nearest Loc File. |
|
87 |
|
88 TFileName resourceFileName; |
|
89 resourceFileName.Append( KDC_RESOURCE_FILES_DIR ); |
|
90 resourceFileName.Append( KResourceFileName ); |
|
91 BaflUtils::NearestLanguageFile( fs, resourceFileName ); |
|
92 RResourceFile resourceFile; |
|
93 resourceFile.OpenL( fs, resourceFileName ); |
|
94 |
|
95 CleanupClosePushL( resourceFile ); |
|
96 iCapabilities = LoadCapabilityL( resourceFile, DPOF_CAPABILITIES ); |
|
97 CleanupStack::PopAndDestroy( 2 ); // resourceFile, fs |
|
98 |
|
99 iDPOF = CRsDpofEngine::NewL( *this ); |
|
100 |
|
101 SetMMCPrinterL(); |
|
102 |
|
103 LOG("CDPOFPrintingDevice::ConstructL end"); |
|
104 } |
|
105 |
|
106 void CDPOFPrintingDevice::SetMMCPrinterL() |
|
107 { |
|
108 LOG("CDPOFPrintingDevice::SetMMCPrinterL begin"); |
|
109 |
|
110 // New implementation |
|
111 LOG("CDPOFPrintingDevice::SetMMCPrinterL calling iDPOF->SetMMCPathL ..."); |
|
112 iDPOF->SetMMCPathL(); |
|
113 |
|
114 if( iDPOF->HasMmc() ) |
|
115 { |
|
116 CPrinterElement* printElem = CPrinterElement::NewLC(); |
|
117 printElem->iPrinter.iDisplayName = KMmcPrinterName; |
|
118 printElem->iPrinter.iPrinterID = KMmcPrinterId; |
|
119 printElem->iPrinter.iProperties = TPrinter::SupportsPreview; |
|
120 printElem->iPrinter.iProtocol = KImagePrint_PrinterProtocol_DPOF; |
|
121 printElem->iTransport = DPOFTrans; |
|
122 printElem->iPrinterClass = EDefault; |
|
123 printElem->iPrinterCapabilities = CPrinterCapabilities::NewL( iCapabilities, printElem->iPrinterClass ); |
|
124 User::LeaveIfError( iDeviceList.Append( printElem ) ); |
|
125 CleanupStack::Pop( printElem ); |
|
126 printElem = NULL; |
|
127 } |
|
128 |
|
129 LOG("CDPOFPrintingDevice::SetMMCPrinterL end"); |
|
130 } |
|
131 |
|
132 |
|
133 CDPOFPrintingDevice::~CDPOFPrintingDevice() |
|
134 { |
|
135 LOG("CDPOFPrintingDevice::~CDPOFPrintingDevice begin"); |
|
136 Cancel(); |
|
137 delete iDPOF; |
|
138 delete iCapabilities; |
|
139 iDeviceList.ResetAndDestroy(); |
|
140 iDeviceList.Close(); |
|
141 iMappingArray.Close(); |
|
142 delete iPrintJob; |
|
143 iReadyRequests.Close(); |
|
144 REComSession::DestroyedImplementation( iDtor_ID_Key ); |
|
145 |
|
146 if (iConfirmationQuery) |
|
147 { |
|
148 delete iConfirmationQuery; |
|
149 iConfirmationQuery = NULL; |
|
150 } |
|
151 |
|
152 if (iPQ) |
|
153 { |
|
154 delete iPQ; |
|
155 iPQ = NULL; |
|
156 } |
|
157 |
|
158 if (iQuestion) |
|
159 { |
|
160 delete iQuestion; |
|
161 iQuestion = NULL; |
|
162 } |
|
163 |
|
164 LOG("CDPOFPrintingDevice::~CDPOFPrintingDevice end"); |
|
165 } |
|
166 |
|
167 |
|
168 TVersion CDPOFPrintingDevice::Version() |
|
169 { |
|
170 return TVersion(KDPOFVersionMajor, KDPOFVersionMinor, KDPOFVersionBuild); |
|
171 } |
|
172 |
|
173 TUint CDPOFPrintingDevice::SupportedProtocols() |
|
174 { |
|
175 return KImagePrint_PrinterProtocol_DPOF; |
|
176 } |
|
177 |
|
178 |
|
179 void CDPOFPrintingDevice::StartDiscoveryL(MProtDiscoveryObserver& aObserver, TUint aProtocol) |
|
180 { |
|
181 LOG1("CDPOFPrintingDevice::StartDiscoveryL aProtocol: %d", aProtocol); |
|
182 iDiscoveryObserver = &aObserver; |
|
183 Cancel(); |
|
184 if( aProtocol & KImagePrint_PrinterProtocol_DPOF ) |
|
185 { |
|
186 LOG("CDPOFPrintingDevice::StartDiscoveryL protocol match, starting discovery..."); |
|
187 iDPOF->StartDiscovery( iStatus ); |
|
188 if( !IsActive() ) SetActive(); |
|
189 } |
|
190 else |
|
191 { |
|
192 LOG("CDPOFPrintingDevice::StartDiscoveryL NO protocol match, ending discovery..."); |
|
193 AddReadyRequestAndSetActive( EDiscoveryDone ); |
|
194 } |
|
195 LOG("CDPOFPrintingDevice::StartDiscoveryL end"); |
|
196 } |
|
197 |
|
198 |
|
199 TInt CDPOFPrintingDevice::RemoveCachedDeviceL( TInt aDeviceID ) |
|
200 { |
|
201 LOG1("CDPOFPrintingDevice::RemoveCachedDeviceL aDeviceID: %d", aDeviceID); |
|
202 CPrinterElement* targetPrinter = FindDeviceL( aDeviceID ); |
|
203 LOG1("CDPOFPrintingDevice::RemoveCachedDeviceL targetPrinter address: %d", (TInt)targetPrinter); |
|
204 return ( targetPrinter ) ? KErrNone : KErrInvalidData; |
|
205 } |
|
206 |
|
207 void CDPOFPrintingDevice::CancelDiscovery( TBool aDoCallBack ) |
|
208 { |
|
209 LOG1("CDPOFPrintingDevice::CancelDiscovery aDoCallBack: %d", aDoCallBack); |
|
210 if( aDoCallBack ) |
|
211 { |
|
212 AddReadyRequestAndSetActive( ECancelDiscovery ); |
|
213 } |
|
214 LOG("CDPOFPrintingDevice::CancelDiscovery end"); |
|
215 } |
|
216 |
|
217 |
|
218 TInt CDPOFPrintingDevice::CreatePrintJobL(TInt aDeviceID, RPointerArray<TDesC>& aImages, MProtPrintEventObserver& aObserver) |
|
219 { |
|
220 LOG1("CDPOFPrintingDevice::CreatePrintJobL aDeviceID: %d", aDeviceID); |
|
221 LOG1("CDPOFPrintingDevice::CreatePrintJobL aImages.Count(): %d", aImages.Count()); |
|
222 |
|
223 iPrintEventObserver = &aObserver; |
|
224 iPrintJob->iState = PJSNone; // Reset value until Job is fully setup in case of a leave. |
|
225 CPrinterElement *TargetPrinter = FindDeviceL( aDeviceID ); |
|
226 if( TargetPrinter == NULL ) |
|
227 { |
|
228 LOG("CDPOFPrintingDevice::CreatePrintJobL no device found, returning error"); |
|
229 return KErrInvalidData; |
|
230 } |
|
231 |
|
232 iPrintJob->iTransport = DPOFTrans; |
|
233 iPrintJob->iPrinterID = aDeviceID; |
|
234 TInt NumImages = aImages.Count(); |
|
235 iPrintJob->iImages.ResetAndDestroy(); |
|
236 for (TInt i = 0 ; i < NumImages; i++) |
|
237 { |
|
238 HBufC* Image = aImages[i]->AllocLC(); |
|
239 User::LeaveIfError( iPrintJob->iImages.Append( Image ) ); |
|
240 CleanupStack::Pop(Image); |
|
241 } |
|
242 LOG("CDPOFPrintingDevice::CreatePrintJobL image names copied"); |
|
243 |
|
244 // Now we can access the capabilities and fill in the printer settings. |
|
245 RArray<TInt> CapabilityIDs; |
|
246 CleanupClosePushL( CapabilityIDs ); |
|
247 GetDeviceCapabilityIDsL( aDeviceID, CapabilityIDs ); |
|
248 LOG1("CDPOFPrintingDevice::CreatePrintJobL capability ids count: %d", CapabilityIDs.Count()); |
|
249 |
|
250 iPrintJob->iSettings.Reset(); |
|
251 for (TInt i = 0; i < CapabilityIDs.Count(); i++) |
|
252 { |
|
253 TPrintCapability capability; |
|
254 GetDeviceCapabilityL(aDeviceID, CapabilityIDs[i], capability); |
|
255 TInt nCurrentValue; |
|
256 TBool bHasValue = TargetPrinter->iPrinterCapabilities->GetCurrentValue(CapabilityIDs[i], nCurrentValue); |
|
257 TSetting Setting; |
|
258 Setting.iCapabilityID = capability.iCapabilityID; |
|
259 if (bHasValue) |
|
260 Setting.iValue = nCurrentValue; |
|
261 else |
|
262 Setting.iValue = capability.iDefaultValue; |
|
263 |
|
264 User::LeaveIfError(iPrintJob->iSettings.Append(Setting)); |
|
265 } |
|
266 LOG("CDPOFPrintingDevice::CreatePrintJobL capabilities copied"); |
|
267 |
|
268 CleanupStack::PopAndDestroy(); // CapabilityIDs |
|
269 |
|
270 iPrintJob->iState = PJSCreated; |
|
271 LOG("CDPOFPrintingDevice::CreatePrintJobL end"); |
|
272 return KErrNone; |
|
273 } |
|
274 |
|
275 |
|
276 void CDPOFPrintingDevice::SubmitPrintJobL() |
|
277 { |
|
278 LOG("CDPOFPrintingDevice::SubmitPrintJobL begin"); |
|
279 |
|
280 if( iDPOF->AutoPrintFileExists() ) |
|
281 { |
|
282 ShowConfirmationQueryL(); |
|
283 } |
|
284 else |
|
285 { |
|
286 OverwriteExistingJobL (); |
|
287 } |
|
288 |
|
289 LOG("CDPOFPrintingDevice::SubmitPrintJobL end"); |
|
290 } |
|
291 |
|
292 void CDPOFPrintingDevice::ShowConfirmationQueryL() |
|
293 { |
|
294 LOG("CDPOFPrintingDevice::ShowConfirmationQueryL begin"); |
|
295 |
|
296 RFs fs; |
|
297 User::LeaveIfError( fs.Connect() ); |
|
298 CleanupClosePushL( fs ); |
|
299 TFileName resourceFileName; |
|
300 resourceFileName.Append ( KDC_RESOURCE_FILES_DIR ); |
|
301 resourceFileName.Append ( KResourceFileName ); |
|
302 BaflUtils::NearestLanguageFile( fs, resourceFileName ); |
|
303 RResourceFile resFile; |
|
304 resFile.OpenL( fs, resourceFileName ); |
|
305 CleanupClosePushL( resFile ); |
|
306 HBufC8 *resBuffer = resFile.AllocReadLC( R_QTN_PRINT_DPOF_CONFIRMATION_DIALOG ); |
|
307 TResourceReader reader; |
|
308 reader.SetBuffer( resBuffer ); |
|
309 TPtrC ptrQuestion = reader.ReadTPtrC(); |
|
310 iQuestion = ptrQuestion.AllocL(); |
|
311 CleanupStack::PopAndDestroy( 3 ); // resBuffer, resFile, fs |
|
312 |
|
313 iPQ = CAknGlobalConfirmationQuery::NewL(); |
|
314 |
|
315 iConfirmationQuery = CConfirmationQuery::NewL( *this ); |
|
316 |
|
317 iConfirmationQuery->StartWaitingAnswer( ); |
|
318 |
|
319 iPQ->ShowConfirmationQueryL( iConfirmationQuery->iStatus, *iQuestion, R_AVKON_SOFTKEYS_YES_NO ); |
|
320 |
|
321 LOG("CDPOFPrintingDevice::ShowConfirmationQueryL end"); |
|
322 } |
|
323 |
|
324 |
|
325 TInt CDPOFPrintingDevice::CancelPrintJob() |
|
326 { |
|
327 LOG1("CDPOFPrintingDevice::CancelPrintJob begin with job state: %d", iPrintJob->iState); |
|
328 TInt retVal(KErrNone); |
|
329 |
|
330 if( iPrintJob->iState == PJSSubmitted ) |
|
331 { |
|
332 LOG("CDPOFPrintingDevice::CancelPrintJob calling iDPOF->Stop()"); |
|
333 iDPOF->Stop(); |
|
334 iPrintJob->iState = PJSCreated; |
|
335 AddReadyRequestAndSetActive( EPrintJobDone ); |
|
336 } |
|
337 else |
|
338 { |
|
339 retVal = KErrInvalidSequence; |
|
340 } |
|
341 |
|
342 LOG1("CDPOFPrintingDevice::CancelPrintJob end with code: %d", retVal); |
|
343 return retVal; |
|
344 } |
|
345 |
|
346 TInt CDPOFPrintingDevice::ContinuePrintJobL() |
|
347 { |
|
348 LOG1("CDPOFPrintingDevice::ContinuePrintJobL returns with: %d", KErrNotSupported); |
|
349 return KErrNotSupported; |
|
350 } |
|
351 |
|
352 TInt CDPOFPrintingDevice::GetNumPrintPages() |
|
353 { |
|
354 LOG1("CDPOFPrintingDevice::GetNumPrintPages begin with job state: %d", iPrintJob->iState); |
|
355 if( iPrintJob->iState == PJSNone ) |
|
356 { |
|
357 LOG("CDPOFPrintingDevice::GetNumPrintPages job state == PJSNone, ending with 0"); |
|
358 return 0; |
|
359 } |
|
360 |
|
361 |
|
362 TInt ImagesPerPage = 1; |
|
363 TInt NumPrintPages; |
|
364 TInt NumImages = iPrintJob->iImages.Count(); |
|
365 |
|
366 // Get Num images per page from the mapping table. |
|
367 TSetting Setting; |
|
368 FindSetting(EPrintCapabLayout, Setting); |
|
369 |
|
370 for (TInt j = 0; j < iMappingArray.Count(); j++) |
|
371 { |
|
372 if (iMappingArray[j].iCode == Setting.iValue) |
|
373 { |
|
374 ImagesPerPage = iMappingArray[j].iImagesPerPage; |
|
375 break; |
|
376 } |
|
377 } |
|
378 |
|
379 if( ImagesPerPage == 0 ) // Stickers, Uses only one image, and populates a single page |
|
380 NumPrintPages = 1; |
|
381 else |
|
382 NumPrintPages = (NumImages + ImagesPerPage - 1) / ImagesPerPage; |
|
383 |
|
384 LOG1("CDPOFPrintingDevice::GetNumPrintPages returns: %d", NumPrintPages); |
|
385 return NumPrintPages; |
|
386 } |
|
387 |
|
388 TInt CDPOFPrintingDevice::GetPrintJobStatus() |
|
389 { |
|
390 LOG1("CDPOFPrintingDevice::GetPrintJobStatus returns with: %d", KErrNotSupported); |
|
391 return KErrNotSupported; |
|
392 } |
|
393 |
|
394 TInt CDPOFPrintingDevice::GetPrinterStatus(TInt /*aDeviceID*/) |
|
395 { |
|
396 LOG1("CDPOFPrintingDevice::GetPrinterStatus returns with: %d", KErrNotSupported); |
|
397 return KErrNotSupported; |
|
398 } |
|
399 |
|
400 TInt CDPOFPrintingDevice::GetDeviceCapabilityIDsL(TInt aDeviceID, RArray<TInt>& aCapabilityIDs) |
|
401 { |
|
402 LOG1("CDPOFPrintingDevice::GetDeviceCapabilityIDsL begins with aDeviceID: %d", aDeviceID); |
|
403 TInt err(KErrNone); |
|
404 aCapabilityIDs.Reset(); |
|
405 CPrinterElement* TargetPrinter = FindDeviceL(aDeviceID); |
|
406 if( TargetPrinter ) |
|
407 { |
|
408 TargetPrinter->iPrinterCapabilities->GetIDs(aCapabilityIDs); |
|
409 } |
|
410 else |
|
411 { |
|
412 err = KErrInvalidData; |
|
413 } |
|
414 LOG1("CDPOFPrintingDevice::GetDeviceCapabilityIDsL ends with err: %d", err); |
|
415 return err; |
|
416 } |
|
417 |
|
418 TInt CDPOFPrintingDevice::GetDeviceCapabilityL(TInt aDeviceID, TInt aCapabilityID, TPrintCapability& aCapability) |
|
419 { |
|
420 LOG1("CDPOFPrintingDevice::GetDeviceCapabilityL begins with aDeviceID: %d", aDeviceID); |
|
421 LOG1("CDPOFPrintingDevice::GetDeviceCapabilityL begins with aCapabilityID: %d", aCapabilityID); |
|
422 TInt err(KErrNone); |
|
423 CPrinterElement* TargetPrinter = FindDeviceL(aDeviceID); |
|
424 if( TargetPrinter ) |
|
425 { |
|
426 TargetPrinter->iPrinterCapabilities->GetCapability(aCapabilityID, aCapability); |
|
427 } |
|
428 else |
|
429 { |
|
430 err = KErrInvalidData; |
|
431 } |
|
432 LOG1("CDPOFPrintingDevice::GetDeviceCapabilityL ends with err: %d", err); |
|
433 return err; |
|
434 } |
|
435 |
|
436 TInt CDPOFPrintingDevice::GetJobSetting(TInt aCapabilityID, TInt& aValue) |
|
437 { |
|
438 LOG1("CDPOFPrintingDevice::GetJobSetting begins with aCapabilityID: %d", aCapabilityID); |
|
439 TInt err(KErrNone); |
|
440 if( iPrintJob->iState == PJSNone ) |
|
441 { |
|
442 err = KErrInvalidSequence; |
|
443 } |
|
444 else |
|
445 { |
|
446 TSetting Setting; |
|
447 if( FindSetting(aCapabilityID, Setting) ) |
|
448 { |
|
449 aValue = Setting.iValue; |
|
450 } |
|
451 else |
|
452 { |
|
453 err = KErrInvalidData; |
|
454 } |
|
455 } |
|
456 LOG1("CDPOFPrintingDevice::GetJobSetting ends with err: %d", err); |
|
457 return err; |
|
458 } |
|
459 |
|
460 TInt CDPOFPrintingDevice::SetJobSettingL(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability) |
|
461 { |
|
462 LOG1("CDPOFPrintingDevice::SetJobSettingL begins with aCapabilityID: %d", aCapabilityID); |
|
463 LOG1("CDPOFPrintingDevice::SetJobSettingL begins with aValue: %d", aValue); |
|
464 LOG1("CDPOFPrintingDevice::SetJobSettingL begins with aAffectedCapability: %d", aAffectedCapability); |
|
465 |
|
466 if( iPrintJob->iState == PJSNone ) |
|
467 { |
|
468 LOG("CDPOFPrintingDevice::SetJobSettingL job state == PJSNone"); |
|
469 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with: %d", KErrInvalidSequence); |
|
470 return KErrInvalidSequence; |
|
471 } |
|
472 |
|
473 aAffectedCapability = 0; |
|
474 TSetting Setting; |
|
475 if( FindSetting(aCapabilityID, Setting) == EFalse ) |
|
476 { |
|
477 LOG("CDPOFPrintingDevice::SetJobSettingL FindSetting == EFalse"); |
|
478 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with: %d", KErrInvalidData); |
|
479 return KErrInvalidData; |
|
480 } |
|
481 |
|
482 // Get the Target printer and capability |
|
483 TPrintCapability TargetCapability; |
|
484 CPrinterElement* TargetPrinter = FindDeviceL( iPrintJob->iPrinterID ); |
|
485 if( TargetPrinter == NULL ) |
|
486 { |
|
487 LOG("CDPOFPrintingDevice::SetJobSettingL TargetPrinter == NULL"); |
|
488 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with: %d", KErrInvalidData); |
|
489 return KErrInvalidData; |
|
490 } |
|
491 |
|
492 TargetPrinter->iPrinterCapabilities->GetCapability(aCapabilityID, TargetCapability); |
|
493 |
|
494 // Check Validity against the target capability ranges |
|
495 if ((TargetCapability.iType == TPrintCapability::Int) || |
|
496 (TargetCapability.iType == TPrintCapability::Float)) |
|
497 { |
|
498 if (((aValue < TargetCapability.iLow) && (TargetCapability.iLow != -1)) || |
|
499 ((aValue > TargetCapability.iHigh) && (TargetCapability.iHigh != -1))) |
|
500 { |
|
501 LOG("CDPOFPrintingDevice::SetJobSettingL capability ranges error"); |
|
502 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with: %d", KErrInvalidData); |
|
503 return KErrInvalidData; |
|
504 } |
|
505 |
|
506 } |
|
507 else // enum |
|
508 { |
|
509 TBool Valid = EFalse; |
|
510 for (TInt i = 0; i < TargetCapability.iEnumCount; i++) |
|
511 { |
|
512 if (aValue == TargetCapability.iEnumCodes[i]) |
|
513 { |
|
514 Valid = ETrue; |
|
515 break; |
|
516 } |
|
517 } |
|
518 if (!Valid) |
|
519 { |
|
520 LOG("CDPOFPrintingDevice::SetJobSettingL !Valid"); |
|
521 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with: %d", KErrInvalidData); |
|
522 return KErrInvalidData; |
|
523 } |
|
524 } |
|
525 |
|
526 for (TInt i = 0; i < iPrintJob->iSettings.Count(); i++) |
|
527 { |
|
528 if (aCapabilityID == iPrintJob->iSettings[i].iCapabilityID) |
|
529 { |
|
530 iPrintJob->iSettings[i].iValue = aValue; |
|
531 break; |
|
532 } |
|
533 } |
|
534 |
|
535 aAffectedCapability = TargetPrinter->iPrinterCapabilities->SetCurrentValueL(aCapabilityID, aValue); |
|
536 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with aAffectedCapability: %d", aAffectedCapability); |
|
537 LOG1("CDPOFPrintingDevice::SetJobSettingL ends with code: %d", KErrNone); |
|
538 return KErrNone; |
|
539 } |
|
540 |
|
541 |
|
542 TInt CDPOFPrintingDevice::GetNumPreviewPages() |
|
543 { |
|
544 LOG1("CDPOFPrintingDevice::GetNumPreviewPages ends with: %d", 1); |
|
545 return 1; |
|
546 } |
|
547 |
|
548 TInt CDPOFPrintingDevice::GetJobTemplateIconL( TInt /*aTemplateID*/, TInt& /*aFsBitmapHandle*/ ) |
|
549 { |
|
550 return KErrNone; |
|
551 } |
|
552 |
|
553 |
|
554 TInt CDPOFPrintingDevice::CreatePreviewImage(TInt /*aPageNumber*/) |
|
555 { |
|
556 return KErrNone; |
|
557 } |
|
558 |
|
559 |
|
560 void CDPOFPrintingDevice::HandleDpofEngineEventL(const TInt aStatus, const TInt aRetCode) |
|
561 { |
|
562 LOG1("CDPOFPrintingDevice::HandleDpofEngineEventL begins with aStatus: %d", aStatus); |
|
563 LOG1("CDPOFPrintingDevice::HandleDpofEngineEventL begins with aRetCode: %d", aRetCode); |
|
564 |
|
565 iPrintError = aRetCode; |
|
566 iPrintErrorMsgCode = 0; |
|
567 |
|
568 if( (aRetCode != KErrNone) && !(aRetCode==KErrCancel && aStatus==EJobCancelled) ) |
|
569 { |
|
570 AddReadyRequestAndSetActive( EPrintError ); |
|
571 } |
|
572 else |
|
573 { |
|
574 switch(aStatus) |
|
575 { |
|
576 case EDeleteDirectory: |
|
577 case ECopyImageFiles: |
|
578 case EDPOFGenerate: |
|
579 AddReadyRequestAndSetActive( EPrintJobProgress ); |
|
580 break; |
|
581 case EJobError: |
|
582 AddReadyRequestAndSetActive( EPrintError ); |
|
583 break; |
|
584 case EJobCompleted: |
|
585 case EJobCancelled: |
|
586 AddReadyRequestAndSetActive( EPrintJobDone ); |
|
587 break; |
|
588 default: |
|
589 break; |
|
590 } |
|
591 } |
|
592 LOG("CDPOFPrintingDevice::HandleDpofEngineEventL end"); |
|
593 } |
|
594 |
|
595 void CDPOFPrintingDevice::DoCancel() |
|
596 { |
|
597 } |
|
598 |
|
599 void CDPOFPrintingDevice::RunL() |
|
600 { |
|
601 LOG1("CDPOFPrintingDevice::RunL begins with iStatus.Int: %d", iStatus.Int()); |
|
602 PrintSessionStatus PEStatus = (PrintSessionStatus)iStatus.Int(); |
|
603 |
|
604 switch ( PEStatus ) |
|
605 { |
|
606 case KErrNone: |
|
607 break; |
|
608 case EPrinterDiscovered: |
|
609 { |
|
610 TPrinter foundPrinter; |
|
611 foundPrinter.iDisplayName = KMmcPrinterName; |
|
612 foundPrinter.iPrinterID = KMmcPrinterId; |
|
613 foundPrinter.iProperties = TPrinter::SupportsPreview; |
|
614 foundPrinter.iProtocol = KImagePrint_PrinterProtocol_DPOF; |
|
615 foundPrinter.iVendor = TPrinter::EVendorNone; |
|
616 |
|
617 LOG("CDPOFPrintingDevice::RunL printer discovered, informing observer"); |
|
618 if( iDiscoveryObserver ) |
|
619 { |
|
620 iDiscoveryObserver->FoundDeviceL( foundPrinter ); |
|
621 } |
|
622 AddReadyRequestAndSetActive( EDiscoveryDone ); |
|
623 break; |
|
624 } |
|
625 case EDiscoveryDone: |
|
626 { |
|
627 LOG("CDPOFPrintingDevice::RunL discovery done, informing observer"); |
|
628 if( iDiscoveryObserver ) |
|
629 { |
|
630 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrNone, 0); |
|
631 } |
|
632 break; |
|
633 } |
|
634 case ECancelDiscovery: |
|
635 { |
|
636 LOG("CDPOFPrintingDevice::RunL discovery cancelled, informing observer"); |
|
637 if( iDiscoveryObserver ) |
|
638 { |
|
639 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrCancel, 0); |
|
640 } |
|
641 break; |
|
642 } |
|
643 case EPrintError: |
|
644 { |
|
645 LOG("CDPOFPrintingDevice::RunL print error, informing observer"); |
|
646 LOG1("CDPOFPrintingDevice::RunL print error iPrintError: %d", iPrintError); |
|
647 LOG1("CDPOFPrintingDevice::RunL print error iPrintErrorMsgCode: %d", iPrintErrorMsgCode); |
|
648 if( iPrintEventObserver ) |
|
649 { |
|
650 iPrintEventObserver->PrintJobErrorEvent( iPrintError, iPrintErrorMsgCode ); |
|
651 } |
|
652 iPrintJob->iState = PJSCreated; |
|
653 break; |
|
654 } |
|
655 case EPrintJobProgress: |
|
656 { |
|
657 LOG("CDPOFPrintingDevice::RunL job progress, informing observer"); |
|
658 if( iPrintEventObserver ) |
|
659 { |
|
660 iPrintEventObserver->PrintJobProgressEvent(EActive, iDPOF->GetPrintPercentage(), ECopying); |
|
661 } |
|
662 break; |
|
663 } |
|
664 case EPrintJobDone: |
|
665 { |
|
666 iPrintJob->iState = PJSCreated; // go back to created so it can be re-submitted |
|
667 if( iPrintEventObserver ) |
|
668 { |
|
669 LOG1("CDPOFPrintingDevice::RunL job done percentage: %d", iDPOF->GetPrintPercentage()); |
|
670 |
|
671 if (iDPOF->WasCancelled() ) |
|
672 { |
|
673 LOG("CDPOFPrintingDevice::RunL job cancelled"); |
|
674 iPrintEventObserver->PrintJobProgressEvent(EDone, iDPOF->GetPrintPercentage(), ECancelling); |
|
675 } |
|
676 else |
|
677 { |
|
678 LOG("CDPOFPrintingDevice::RunL job done"); |
|
679 iPrintEventObserver->PrintJobProgressEvent(EDone, 100, ENoMessage); |
|
680 } |
|
681 } |
|
682 break; |
|
683 } |
|
684 |
|
685 default: |
|
686 { |
|
687 LOG("CDPOFPrintingDevice::RunL default, informing observer"); |
|
688 if( iPrintEventObserver ) |
|
689 { |
|
690 iPrintEventObserver->PrintJobErrorEvent(KErrGeneral, 0); |
|
691 } |
|
692 iPrintJob->iState = PJSCreated; |
|
693 break; |
|
694 } |
|
695 } |
|
696 |
|
697 CheckReadyRequestAndSetActive(); |
|
698 LOG("CDPOFPrintingDevice::RunL end"); |
|
699 } |
|
700 |
|
701 |
|
702 CCapabilityArray* CDPOFPrintingDevice::LoadCapabilityL(RResourceFile& aResFile, TInt aCapID) |
|
703 { |
|
704 LOG1("CDPOFPrintingDevice::LoadCapabilityL begins with capID: %d", aCapID); |
|
705 HBufC8* res = aResFile.AllocReadLC(aCapID); |
|
706 TResourceReader theReader; |
|
707 theReader.SetBuffer( res ); |
|
708 CCapabilityArray *capabilities = CCapabilityArray::NewL( theReader ); |
|
709 CleanupStack::PopAndDestroy(); // res |
|
710 LOG("CDPOFPrintingDevice::LoadCapabilityL end"); |
|
711 return capabilities; |
|
712 } |
|
713 |
|
714 |
|
715 CPrinterElement* CDPOFPrintingDevice::FindDeviceL(TInt aDeviceID) |
|
716 { |
|
717 LOG1("CDPOFPrintingDevice::FindDeviceL begins with aDeviceID: %d", aDeviceID); |
|
718 // Add this here to fix problem |
|
719 // if application is started without MMC and then user insert MMC in the phone ->cannot find MMC |
|
720 if( iDeviceList.Count() == 0 ) |
|
721 { |
|
722 SetMMCPrinterL(); |
|
723 } |
|
724 for( TInt i = 0; i < iDeviceList.Count(); i++ ) |
|
725 { |
|
726 if(iDeviceList[i]->iPrinter.iPrinterID == aDeviceID ) |
|
727 { |
|
728 LOG("CDPOFPrintingDevice::FindDeviceL device found"); |
|
729 return iDeviceList[i]; |
|
730 } |
|
731 } |
|
732 LOG("CDPOFPrintingDevice::FindDeviceL device NOT found"); |
|
733 return NULL; |
|
734 } |
|
735 |
|
736 TBool CDPOFPrintingDevice::FindSetting(TInt aCapabilityID, TSetting& aSetting) |
|
737 { |
|
738 LOG1("CDPOFPrintingDevice::FindSetting begins with aCapabilityID: %d", aCapabilityID); |
|
739 for(TInt i = 0; i < iPrintJob->iSettings.Count(); i++) |
|
740 { |
|
741 if (aCapabilityID == iPrintJob->iSettings[i].iCapabilityID) |
|
742 { |
|
743 aSetting = iPrintJob->iSettings[i]; |
|
744 LOG("CDPOFPrintingDevice::FindSetting setting found"); |
|
745 return ETrue; |
|
746 } |
|
747 } |
|
748 LOG("CDPOFPrintingDevice::FindSetting setting NOT found"); |
|
749 return EFalse; |
|
750 } |
|
751 /* |
|
752 TInt CDPOFPrintingDevice::AddReadyRequestAndSetActive( TInt aRequest ) |
|
753 { |
|
754 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive aRequest: %d", aRequest); |
|
755 TInt err = iReadyRequests.Append( aRequest ); |
|
756 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive err: %d", err); |
|
757 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive iReadyRequests.Count(): %d", iReadyRequests.Count()); |
|
758 if( !err ) |
|
759 { |
|
760 TInt request = iReadyRequests[0]; |
|
761 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive request: %d", request); |
|
762 iReadyRequests.Remove( 0 ); |
|
763 iStatus = KRequestPending; |
|
764 TRequestStatus* TempTRS = &iStatus; |
|
765 if( !IsActive() ) SetActive(); |
|
766 User::RequestComplete( TempTRS, request ); |
|
767 } |
|
768 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive return: %d", err); |
|
769 return err; |
|
770 } |
|
771 |
|
772 TInt CDPOFPrintingDevice::CheckReadyRequestAndSetActive() |
|
773 { |
|
774 LOG("CDPOFPrintingDevice::CheckReadyRequestAndSetActive begin"); |
|
775 TInt count = iReadyRequests.Count(); |
|
776 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive count: %d", count); |
|
777 TInt err( KErrNotFound ); |
|
778 if( count ) |
|
779 { |
|
780 TInt request = iReadyRequests[0]; |
|
781 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive request: %d", request); |
|
782 iReadyRequests.Remove( 0 ); |
|
783 iStatus = KRequestPending; |
|
784 TRequestStatus* TempTRS = &iStatus; |
|
785 if( !IsActive() ) SetActive(); |
|
786 User::RequestComplete( TempTRS, request ); |
|
787 err = KErrNone; |
|
788 } |
|
789 LOG1("CDPOFPrintingDevice::CheckReadyRequestAndSetActive return: %d", err); |
|
790 return err; |
|
791 } |
|
792 */ |
|
793 |
|
794 TInt CDPOFPrintingDevice::AddReadyRequestAndSetActive( TInt aRequest ) |
|
795 { |
|
796 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive aRequest: %d", aRequest); |
|
797 TInt err = iReadyRequests.Append( aRequest ); |
|
798 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive err: %d", err); |
|
799 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive iReadyRequests.Count(): %d", iReadyRequests.Count()); |
|
800 if( !err ) |
|
801 { |
|
802 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive IsActive(): %d", IsActive()); |
|
803 if( !IsActive() ) |
|
804 { |
|
805 TInt request = iReadyRequests[0]; |
|
806 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive request: %d", request); |
|
807 iReadyRequests.Remove( 0 ); |
|
808 iStatus = KRequestPending; |
|
809 TRequestStatus* TempTRS = &iStatus; |
|
810 SetActive(); |
|
811 User::RequestComplete( TempTRS, request ); |
|
812 } |
|
813 } |
|
814 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive return: %d", err); |
|
815 return err; |
|
816 } |
|
817 |
|
818 TInt CDPOFPrintingDevice::CheckReadyRequestAndSetActive() |
|
819 { |
|
820 LOG("CDPOFPrintingDevice::CheckReadyRequestAndSetActive begin"); |
|
821 TInt count = iReadyRequests.Count(); |
|
822 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive count: %d", count); |
|
823 TInt err( KErrNotFound ); |
|
824 if( count ) |
|
825 { |
|
826 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive IsActive(): %d", IsActive()); |
|
827 if( !IsActive() ) |
|
828 { |
|
829 TInt request = iReadyRequests[0]; |
|
830 LOG1("CDPOFPrintingDevice::AddRequestAndSetActive request: %d", request); |
|
831 iReadyRequests.Remove( 0 ); |
|
832 iStatus = KRequestPending; |
|
833 TRequestStatus* TempTRS = &iStatus; |
|
834 SetActive(); |
|
835 User::RequestComplete( TempTRS, request ); |
|
836 err = KErrNone; |
|
837 } |
|
838 } |
|
839 LOG1("CDPOFPrintingDevice::CheckReadyRequestAndSetActive return: %d", err); |
|
840 return err; |
|
841 } |
|
842 |
|
843 void CDPOFPrintingDevice::ConfirmationQueryCompleteL ( TInt aError ) |
|
844 { |
|
845 TBool answer = ( aError == EAknSoftkeyYes ); |
|
846 if( answer ) |
|
847 { |
|
848 iCancelledByUser = EFalse; // user want to write file |
|
849 OverwriteExistingJobL (); |
|
850 } |
|
851 else |
|
852 { |
|
853 iCancelledByUser = ETrue; |
|
854 } |
|
855 |
|
856 if( iDPOF->AutoPrintFileExists() ) |
|
857 { |
|
858 if( iCancelledByUser ) |
|
859 { |
|
860 iPrintEventObserver->PrintJobProgressEvent( EDone, 100, ECancellingNoMessage ); |
|
861 LOG("CDPOFPrintingDevice::SubmitPrintJobL end"); |
|
862 return; |
|
863 } |
|
864 } |
|
865 } |
|
866 |
|
867 void CDPOFPrintingDevice::OverwriteExistingJobL () |
|
868 { |
|
869 iPrintError = KErrNone; |
|
870 iPrintErrorMsgCode = 0; |
|
871 |
|
872 CRsDpofEngine::TRsDpofImageLayout layout; |
|
873 iDPOF->SetImageFileNamesL(iPrintJob->iImages); |
|
874 TSetting layoutSetting; |
|
875 FindSetting(EPrintCapabLayout, layoutSetting); |
|
876 LOG1("CDPOFPrintingDevice::OverwriteExistingJobL layoutSetting.iValue: %d", layoutSetting.iValue); |
|
877 switch(layoutSetting.iValue) |
|
878 { |
|
879 case EPrintCapabLayout1UpSmall: |
|
880 layout = CRsDpofEngine::EOnePerPageSmall; |
|
881 break; |
|
882 case EPrintCapabLayout1UpMedium: |
|
883 case EPrintCapabLayout1UpLarge: |
|
884 layout = CRsDpofEngine::EOnePerPageLarge; |
|
885 break; |
|
886 case EPrintCapabLayout2Up: |
|
887 layout = CRsDpofEngine::ETwoPerPage; |
|
888 break; |
|
889 case EPrintCapabLayout4Up: |
|
890 layout = CRsDpofEngine::EFourPerPage; |
|
891 break; |
|
892 case EPrintCapabLayout6Up: |
|
893 layout = CRsDpofEngine::ESixPerPage; |
|
894 break; |
|
895 case EPrintCapabLayout9Up: |
|
896 layout = CRsDpofEngine::ENinePerPage; |
|
897 break; |
|
898 case EPrintCapabLayout12Up: |
|
899 layout = CRsDpofEngine::ETwelvePerPage; |
|
900 break; |
|
901 case EPrintCapabLayout16Up: |
|
902 layout = CRsDpofEngine::ESixteenPerPage; |
|
903 break; |
|
904 default: |
|
905 layout = CRsDpofEngine::EOnePerPageMedium; |
|
906 break; |
|
907 } |
|
908 |
|
909 iDPOF->SetImageLayout(layout); |
|
910 LOG1("CDPOFPrintingDevice::OverwriteExistingJobL 1 iStatus.Int(): %d", iStatus.Int()); |
|
911 TInt err = iDPOF->PrintL(); |
|
912 LOG1("CDPOFPrintingDevice::OverwriteExistingJobL iDPOF->PrintL() error: %d", err); |
|
913 LOG1("CDPOFPrintingDevice::OverwriteExistingJobL 2 iStatus.Int(): %d", iStatus.Int()); |
|
914 |
|
915 if( err ) |
|
916 { |
|
917 iPrintError = err; |
|
918 iPrintErrorMsgCode = ENoMessage; |
|
919 AddReadyRequestAndSetActive( EPrintError ); |
|
920 } |
|
921 else |
|
922 { |
|
923 LOG("CDPOFPrintingDevice::OverwriteExistingJobL job submitted"); |
|
924 iPrintJob->iState = PJSSubmitted; |
|
925 if(!IsActive()) SetActive(); |
|
926 } |
|
927 } |
|
928 |
|
929 |
|
930 void CDPOFPrintingDevice::SetNumsOfCopiesL( const RArray<TInt>& aNumsOfCopies, TInt& aErr ) |
|
931 { |
|
932 LOG("CDPOFPrintingDevice::SetNumsOfCopiesL begin"); |
|
933 LOG1("CDPOFPrintingDevice::SetNumsOfCopiesL iPrintJob->iState: %d", iPrintJob->iState); |
|
934 TInt err( KErrNone ); |
|
935 if( iPrintJob->iState != PJSCreated ) |
|
936 { |
|
937 err = KErrInvalidSequence; |
|
938 } |
|
939 if( !err ) |
|
940 { |
|
941 LOG1("CDPOFPrintingDevice::SetNumsOfCopiesL iPrintJob->iImages.Count(): %d", iPrintJob->iImages.Count()); |
|
942 LOG1("CDPOFPrintingDevice::SetNumsOfCopiesL aNumsOfCopies.Count(): %d", aNumsOfCopies.Count()); |
|
943 if( iPrintJob->iImages.Count() != aNumsOfCopies.Count() ) |
|
944 { |
|
945 err = KErrInvalidData; |
|
946 } |
|
947 } |
|
948 if( !err ) |
|
949 { |
|
950 TInt count = aNumsOfCopies.Count(); |
|
951 for( TInt i = 0; i < count && !err; i++ ) |
|
952 { |
|
953 LOG1("CDPOFPrintingDevice::SetNumsOfCopiesL i: %d", i); |
|
954 LOG1("CDPOFPrintingDevice::SetNumsOfCopiesL aNumsOfCopies[i]: %d", aNumsOfCopies[i]); |
|
955 if( aNumsOfCopies[i] <= 0 ) |
|
956 { |
|
957 err = KErrInvalidData; |
|
958 } |
|
959 } |
|
960 } |
|
961 if( !err ) |
|
962 { |
|
963 iDPOF->SetNumsOfCopiesL( aNumsOfCopies ); |
|
964 } |
|
965 aErr = err; |
|
966 LOG1("CDPOFPrintingDevice::SetNumsOfCopiesL aErr: %d", aErr); |
|
967 } |
|
968 |
|
969 // End of File |
|