1 /* |
|
2 * Copyright (c) 2006, 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: Handles Dps Request call with AO |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <dpsdefs.h> |
|
21 #include <s32file.h> |
|
22 #include <f32file.h> |
|
23 #include <coeutils.h> |
|
24 #include <imageprintui.rsg> |
|
25 |
|
26 #include "requestmanager.h" |
|
27 #include "imageprintuiappui.h" |
|
28 #include "pictbridge.h" |
|
29 #include "notes.h" |
|
30 #include "capabilitymanager.h" |
|
31 #include "imageprintuidebug.h" |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // constructor |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CRequestManager::CRequestManager(CDpsEngine* aDpsEngine, |
|
38 CCapabilityManager* aCapabilityManager, CImagePrintUiAppUi* aAppUi) |
|
39 : CActive(CActive::EPriorityStandard), iDpsEngine(aDpsEngine), |
|
40 iCapabilityManager(aCapabilityManager), iAppUi(aAppUi), iNumberOfImages(0) |
|
41 { |
|
42 CActiveScheduler::Add(this); |
|
43 } |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // 2nd phase construction |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 |
|
51 void CRequestManager::ConstructL() |
|
52 { |
|
53 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager ConstructL")); |
|
54 iFileExist = EFalse; |
|
55 iCongFileName = HBufC::NewL(iDpsEngine->DpsFolder().Length() + KConfigLength); |
|
56 iCongFileName->Des().Copy(iDpsEngine->DpsFolder()); |
|
57 iCongFileName->Des().Append(KConfigInfoFile); |
|
58 |
|
59 // always start with configure, this is part of the DPS protocol |
|
60 ChooseDpsRequestTypeL(EConfigurePrintService); |
|
61 |
|
62 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager ConstructL")); |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CRequestManager* CRequestManager::NewL( CDpsEngine* aDpsEngine, |
|
71 CCapabilityManager* aCapabilityManager,CImagePrintUiAppUi* aAppUi) |
|
72 { |
|
73 CRequestManager* self = CRequestManager::NewLC( aDpsEngine, aCapabilityManager, aAppUi); |
|
74 CleanupStack::Pop( self ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 CRequestManager* CRequestManager::NewLC(CDpsEngine* aDpsEngine, |
|
84 CCapabilityManager* aCapabilityManager, |
|
85 CImagePrintUiAppUi* aAppUi) |
|
86 { |
|
87 CRequestManager* self = new( ELeave ) CRequestManager(aDpsEngine, |
|
88 aCapabilityManager, aAppUi); |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL(); |
|
91 return self; |
|
92 } |
|
93 |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CRequestManager::~CRequestManager() |
|
100 { |
|
101 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager Destructor called")); |
|
102 delete iCongFileName; |
|
103 Cancel(); |
|
104 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager Destructor END")); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CRequestManager::ReIssueDoDpsRequestL() |
|
112 { |
|
113 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager ReIssueDoDpsRequestL")); |
|
114 FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CRequestManager::reissue request is %d"), iRequestType )); |
|
115 ChooseDpsRequestTypeL(iRequestType); |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CRequestManager::RunL() |
|
123 { |
|
124 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager RunL")); |
|
125 FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CRequestManager::RunL iStatus is %d"), iStatus.Int() )); |
|
126 if(iStatus.Int() == KErrNone) |
|
127 { |
|
128 switch ( iRequestType ) |
|
129 { |
|
130 case EConfigurePrintService: |
|
131 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, Handle configure")); |
|
132 HandleConfigureL(); |
|
133 break; |
|
134 |
|
135 case EGetJobStatus: |
|
136 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, HandleGetJobStatusL")); |
|
137 HandleGetJobStatusL(); |
|
138 break; |
|
139 |
|
140 case EGetDeviceStatus: |
|
141 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, Handle Device Status")); |
|
142 HandleDeviceStatusL(); |
|
143 break; |
|
144 |
|
145 case EStartJob: |
|
146 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, Handle Start Job")); |
|
147 HandleStartJobL(); |
|
148 break; |
|
149 |
|
150 case EAbortJob: |
|
151 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, HandleAbortL")); |
|
152 HandleAbortL(); |
|
153 break; |
|
154 |
|
155 case EContinueJob: |
|
156 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, EContinueJob")); |
|
157 break; |
|
158 |
|
159 default: |
|
160 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, default branch")); |
|
161 break; |
|
162 } |
|
163 } |
|
164 else |
|
165 { |
|
166 FLOG(_L("[IMAGEPRINTUIENGINE]\t CRequestManager: RunL, call leave, it call RunError")); |
|
167 User::LeaveIfError(iStatus.Int()); |
|
168 } |
|
169 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager RunL")); |
|
170 } |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CRequestManager::RunError |
|
175 // Standard active object error function. |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 |
|
179 TInt CRequestManager::RunError(TInt aError) |
|
180 { |
|
181 FTRACE(FPrint(_L("[IMAGEPRINTUI] CRequestManager::RunError: err %d from RunL"), aError)); |
|
182 if(aError == KErrNotFound) |
|
183 { |
|
184 FLOG(_L("[IMAGEPRINTUI] CRequestManager Pictures not found when printing")); |
|
185 TRAPD(err,iAppUi->NotifyRequestL(EPicturesNotFound)); |
|
186 if(err) |
|
187 { |
|
188 FLOG(_L("[IMAGEPRINTUI] CRequestManager err calling notify")); |
|
189 } |
|
190 } |
|
191 else if(aError == KErrTimedOut || aError == KErrInUse) |
|
192 { |
|
193 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager; RunError, timed out or in use")); |
|
194 iAppUi->HandleRequestTime(KRetryClose); |
|
195 } |
|
196 |
|
197 return KErrNone; |
|
198 } |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CRequestManager::DoCancel() |
|
204 { |
|
205 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager DoCancel")); |
|
206 iDpsEngine->CancelDpsRequest(); |
|
207 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager DoCancel complete")); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 void CRequestManager::ExecuteStartJobRequestL() |
|
215 { |
|
216 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ExecuteStartJobRequestL ")); |
|
217 iStart.iReqParam.Reset(); |
|
218 |
|
219 TUint layout = iCapabilityManager->Layout(); |
|
220 TUint quality = iCapabilityManager->Quality(); |
|
221 TUint paperSize = iCapabilityManager->PaperSize(); |
|
222 |
|
223 //fill request parameter by retrieved values |
|
224 TDpsArgsInt req_quality,req_papersize, req_layout; |
|
225 |
|
226 req_quality.iElement = EDpsArgQuality; |
|
227 req_quality.iContent = quality; |
|
228 iStart.iReqParam.iJobConfig.AppendL(req_quality); |
|
229 |
|
230 req_papersize.iElement = EDpsArgPaperSize; |
|
231 req_papersize.iContent = paperSize; |
|
232 iStart.iReqParam.iJobConfig.AppendL(req_papersize); |
|
233 |
|
234 req_layout.iElement = EDpsArgLayout; |
|
235 req_layout.iContent = layout; |
|
236 iStart.iReqParam.iJobConfig.AppendL(req_layout); |
|
237 |
|
238 |
|
239 // retrieve images |
|
240 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, Get Images")); |
|
241 iImageArrayFlat = iAppUi->ImagesToPrint(); // not taking ownership |
|
242 |
|
243 |
|
244 iNumberOfImages = iImageArrayFlat->Count(); |
|
245 TDpsPrintInfo* helpTDpsPrintInfo = new (ELeave) TDpsPrintInfo[iNumberOfImages]; |
|
246 CleanupStack::PushL(helpTDpsPrintInfo); |
|
247 // go through the list of images and add info for start job request |
|
248 |
|
249 for(int i=0; i<iNumberOfImages; i++) |
|
250 { |
|
251 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, Start job, append image")); |
|
252 // check if file really exist, use may have delete it after choose print |
|
253 // that will set printer unstable state |
|
254 iFileExist = ConeUtils::FileExists(iImageArrayFlat->operator[](i)); |
|
255 if(iFileExist) |
|
256 { |
|
257 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, Start job, file exist")); |
|
258 helpTDpsPrintInfo[i].iFile.Copy(iImageArrayFlat->operator[](i)); |
|
259 iStart.iReqParam.iPrintInfo.AppendL(helpTDpsPrintInfo[i]); |
|
260 } |
|
261 } |
|
262 |
|
263 FTRACE(FPrint(_L("[IMAGEPRINTUI]\t CRequestManager iNumberOfImages is %d"), iNumberOfImages)); |
|
264 iAppUi->NumberOfImages(iNumberOfImages); |
|
265 if(!iFileExist) |
|
266 { |
|
267 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager, ExecuteStartJobRequestL, file not exist ")); |
|
268 iAppUi->Notes()->ShowErrorMsgL(R_ERROR_FILE_NOT_FOUND); |
|
269 } |
|
270 else |
|
271 { |
|
272 iDpsEngine->DoDpsRequestL(&iStart, iStatus); |
|
273 } |
|
274 |
|
275 CleanupStack::PopAndDestroy(helpTDpsPrintInfo); |
|
276 |
|
277 |
|
278 FLOG(_L("[IMAGEPRINTUI]>>> CRequestManager, ExecuteStartJobRequestL ")); |
|
279 } |
|
280 // --------------------------------------------------------------------------- |
|
281 // Choose DoDpsRequest type |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 void CRequestManager::ChooseDpsRequestTypeL(const TRequestType aType) |
|
285 { |
|
286 iRequestType = aType; |
|
287 switch ( aType ) |
|
288 { |
|
289 |
|
290 case EConfigurePrintService: |
|
291 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType Configure")); |
|
292 iConfig.iReqParam.Reset(); |
|
293 // retrieve current phone settings from DpsEngine and fill req param |
|
294 iDpsEngine->GetDpsConfigL(iConfig.iReqParam); |
|
295 iDpsEngine->DoDpsRequestL(&iConfig, iStatus); |
|
296 break; |
|
297 |
|
298 |
|
299 case EGetJobStatus: |
|
300 // no need to fill parameter for this Dps request |
|
301 iJobFinished = EFalse; |
|
302 iDpsEngine->DoDpsRequestL(&iJob, iStatus); |
|
303 break; |
|
304 |
|
305 case EGetDeviceStatus: |
|
306 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType Get Device status")); |
|
307 // no need to fill parameter for this Dps request |
|
308 iDpsEngine->DoDpsRequestL(&iPrinter, iStatus); |
|
309 break; |
|
310 |
|
311 case EStartJob: |
|
312 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType Start Job")); |
|
313 ExecuteStartJobRequestL(); |
|
314 break; |
|
315 |
|
316 case EAbortJob: |
|
317 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType Abort Job")); |
|
318 // fill only abort style ref. PictBridge Spec. CIPA DC-001-2003 page 68. |
|
319 iAbort.iReqParam.iAbortStyle = EDpsAbortStyleImmediately; |
|
320 iDpsEngine->DoDpsRequestL(&iAbort, iStatus); |
|
321 break; |
|
322 |
|
323 case EContinueJob: |
|
324 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType Continue Job")); |
|
325 // no need to fill parameter for this Dps request |
|
326 iDpsEngine->DoDpsRequestL(&iContinue, iStatus); |
|
327 break; |
|
328 |
|
329 default: |
|
330 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType default branch")); |
|
331 break; |
|
332 } |
|
333 |
|
334 if(!IsActive()) // check if active, user might try to print twice which is causing collision |
|
335 { |
|
336 if(!iFileExist && iRequestType == EStartJob) |
|
337 { |
|
338 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager, ChooseDpsRequestType, file not exist")); |
|
339 } |
|
340 else |
|
341 { |
|
342 SetActive(); |
|
343 } |
|
344 |
|
345 } |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CRequestManager::HandleDeviceStatusL() |
|
353 { |
|
354 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleDeviceStatus Start")); |
|
355 |
|
356 if(!iPrinter.iRepParam.iNewJobOk) |
|
357 { |
|
358 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleDeviceStatus NOK ")); |
|
359 iAppUi->NotifyRequestL(EGetDeviceStatusNOK); |
|
360 } |
|
361 else |
|
362 { |
|
363 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleDeviceStatus OK ")); |
|
364 iAppUi->NotifyRequestL(EGetDeviceStatusOK); |
|
365 ChooseDpsRequestTypeL(EStartJob); |
|
366 } |
|
367 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleDeviceStatus End")); |
|
368 } |
|
369 // --------------------------------------------------------------------------- |
|
370 // |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void CRequestManager::HandleAbortL() |
|
374 { |
|
375 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleAbort Start")); |
|
376 if(iAbort.iResult.iMajorCode != EDpsResultOk) |
|
377 { |
|
378 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleAbort EAbortJobNOK")); |
|
379 iAppUi->NotifyRequestL(EAbortJobNOK); |
|
380 } |
|
381 else |
|
382 { |
|
383 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleAbort EAbortJobOK")); |
|
384 iAppUi->NotifyRequestL(EAbortJobOK); |
|
385 } |
|
386 |
|
387 } |
|
388 |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void CRequestManager::HandleStartJobL() |
|
395 { |
|
396 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleStartJob Start")); |
|
397 |
|
398 if(iStart.iResult.iMajorCode == EDpsResultOk) |
|
399 { |
|
400 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleStartJob OK ")); |
|
401 iAppUi->NotifyRequestL(EStartJobOK); |
|
402 } |
|
403 else |
|
404 { |
|
405 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleStartJob NOK ")); |
|
406 iAppUi->NotifyRequestL(EStartJobNOK); |
|
407 } |
|
408 |
|
409 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleStartJob End")); |
|
410 } |
|
411 |
|
412 // --------------------------------------------------------------------------- |
|
413 // |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 void CRequestManager::HandleGetJobStatusL() |
|
417 { |
|
418 if(iJob.iResult.iMajorCode == EDpsResultOk) |
|
419 { |
|
420 iAppUi->NotifyRequestL(EGetJobStatusOK); |
|
421 } |
|
422 else |
|
423 { |
|
424 iAppUi->NotifyRequestL(EGetJobStatusNOK); |
|
425 } |
|
426 } |
|
427 |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 void CRequestManager::HandleConfigureL() |
|
433 { |
|
434 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleConfigure Start")); |
|
435 if(iConfig.iRepParam.iPrintAvailable == EDpsPrintServiceAvailableTrue) |
|
436 { |
|
437 // save name for AppUi |
|
438 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleConfigure OK ")); |
|
439 iVendorName = iConfig.iRepParam.iVendorName; |
|
440 iProductName = iConfig.iRepParam.iProductName; |
|
441 SaveConfigInfoL(); |
|
442 iAppUi->NotifyRequestL(EConfigurePrintServiceOK); |
|
443 |
|
444 } |
|
445 |
|
446 else if(iConfig.iResult.iMajorCode == EDpsResultNotExecuted) |
|
447 { |
|
448 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleConfigure OK old session")); |
|
449 ReadConfigInfoL(); |
|
450 iAppUi->NotifyRequestL(EConfigurePrintServiceOK); |
|
451 } |
|
452 else if(iConfig.iRepParam.iPrintAvailable == EDpsPrintServiceAvailableFalse) |
|
453 { |
|
454 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager,HandleConfigure NOK ")); |
|
455 iAppUi->NotifyRequestL(EConfigurePrintServiceNOK); |
|
456 } |
|
457 |
|
458 iConfig.iRepParam.Reset(); |
|
459 FLOG(_L("[IMAGEPRINTUI]<<< CRequestManager HandleConfigure End")); |
|
460 } |
|
461 |
|
462 void CRequestManager::GetPrinterName(TDes8& aVendorName, TDes8& aProductName) |
|
463 { |
|
464 FLOG(_L("[IMAGEPRINTUI]\t CRequestManager::GetPrinterName BEGIN")); |
|
465 aVendorName = iVendorName.Ptr(); |
|
466 aProductName = iProductName.Ptr(); |
|
467 FLOG(_L("[IMAGEPRINTUI]\t CRequestManager::GetPrinterName END")); |
|
468 } |
|
469 |
|
470 |
|
471 // --------------------------------------------------------------------------- |
|
472 // |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 |
|
476 void CRequestManager::SaveConfigInfoL() |
|
477 { |
|
478 FLOG(_L("[IMAGEPRINTUI]<<< CEventManager;SaveConfigInfoL ")); |
|
479 RFileWriteStream stream; |
|
480 CleanupClosePushL(stream); |
|
481 if((stream.Replace(CCoeEnv::Static()->FsSession(),iCongFileName->Des() ,EFileWrite)) == KErrNone) |
|
482 { |
|
483 ExternalizeL(stream); |
|
484 } |
|
485 CleanupStack::PopAndDestroy(&stream); |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------------------------- |
|
489 // |
|
490 // --------------------------------------------------------------------------- |
|
491 // |
|
492 void CRequestManager::ExternalizeL(RWriteStream& aStream) const |
|
493 { |
|
494 FLOG(_L("[IMAGEPRINTUI]<<< CEventManager;ExternalizeL ")); |
|
495 aStream << iVendorName; |
|
496 aStream << iProductName; |
|
497 aStream.CommitL(); |
|
498 } |
|
499 |
|
500 // --------------------------------------------------------------------------- |
|
501 // |
|
502 // --------------------------------------------------------------------------- |
|
503 // |
|
504 void CRequestManager::ReadConfigInfoL() |
|
505 { |
|
506 FLOG(_L("[IMAGEPRINTUI]\t CRequestManager::ReadConfogInfoL Sstart")); |
|
507 RFileReadStream readStream; |
|
508 User::LeaveIfError( readStream.Open(CCoeEnv::Static()->FsSession(), |
|
509 iCongFileName->Des(), EFileRead) ); |
|
510 readStream.PushL(); |
|
511 readStream >> iVendorName; |
|
512 readStream >> iProductName; |
|
513 |
|
514 CleanupStack::PopAndDestroy(&readStream); |
|
515 |
|
516 FLOG(_L("[IMAGEPRINTUI]\t CRequestManager::ReadConfogInfoL end")); |
|
517 } |
|
518 |
|
519 // end of file |
|