1 /* |
|
2 * Copyright (c) 2004 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: Implementation of CBtListenActive |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "oppcontroller.h" |
|
21 #include "btengdevman.h" |
|
22 #include <obexutilsmessagehandler.h> |
|
23 #include "debug.h" |
|
24 #include <bautils.h> |
|
25 #include <btengdomaincrkeys.h> |
|
26 #include <sysutil.h> |
|
27 #include <btengdomaincrkeys.h> |
|
28 #include <msvids.h> |
|
29 #include <driveinfo.h> |
|
30 #include <es_sock.h> |
|
31 #include <bt_sock.h> |
|
32 #include <bluetoothdevicedialogs.h> |
|
33 #include <hbtextresolversymbian.h> |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 const TInt KBufferSize = 0x10000; // 64 kB |
|
38 const TInt KFileManagerUID3 = 0x101F84EB; /// File Manager application UID3 |
|
39 _LIT( KBTDevDialogId, "com.nokia.hb.btdevicedialog/1.0" ); |
|
40 _LIT(KLocFileName, "btdialogs_"); |
|
41 _LIT(KPath, "z:/resource/qt/translations/"); |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 |
|
46 COPPController* COPPController::NewL() |
|
47 { |
|
48 COPPController* self = new ( ELeave ) COPPController(); |
|
49 CleanupStack::PushL( self ); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 COPPController::COPPController() |
|
56 { |
|
57 TRACE_FUNC |
|
58 } |
|
59 |
|
60 void COPPController::ConstructL() |
|
61 { |
|
62 TRACE_FUNC |
|
63 iObexTransferState = ETransferIdle; |
|
64 iLowMemoryActiveCDrive = CObexUtilsPropertyNotifier::NewL(this, ECheckPhoneMemory); |
|
65 iLowMemoryActiveMMC = CObexUtilsPropertyNotifier::NewL(this, ECheckMMCMemory); |
|
66 iDevMan=CBTEngDevMan::NewL(this); |
|
67 iResultArray = new (ELeave) CBTDeviceArray(1); |
|
68 // Get default folder from CenRep |
|
69 TObexUtilsMessageHandler::GetCenRepKeyStringValueL(KCRUidBluetoothEngine, |
|
70 KLCReceiveFolder, |
|
71 iCenRepFolder); |
|
72 iDialog = CObexUtilsDialog::NewL(this); |
|
73 TBool ok = HbTextResolverSymbian::Init(KLocFileName, KPath); |
|
74 if (!ok) |
|
75 { |
|
76 User::Leave( KErrNotFound ); |
|
77 } |
|
78 } |
|
79 |
|
80 COPPController::~COPPController() |
|
81 { |
|
82 TRACE_FUNC |
|
83 delete iObexObject; |
|
84 delete iBuf; |
|
85 delete iLowMemoryActiveCDrive; |
|
86 delete iLowMemoryActiveMMC; |
|
87 delete iDevMan; |
|
88 if (iResultArray) |
|
89 { |
|
90 iResultArray->ResetAndDestroy(); |
|
91 delete iResultArray; |
|
92 } |
|
93 iFs.Close(); |
|
94 delete iDialog; |
|
95 delete iProgressDialog; |
|
96 delete iRecvDoneDialog; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // ErrorIndication() |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void COPPController::ErrorIndication( TInt TRACE_ONLY(aError) ) |
|
104 { |
|
105 TRACE_FUNC |
|
106 TRACE_ERROR((_L( "[oppreceiveservice] COPPController: ErrorIndication error:\t %d" ),aError)); |
|
107 HandleError(EFalse); // false because not explicit abort |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // AbortIndication() |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void COPPController::AbortIndication() |
|
115 { |
|
116 TRACE_FUNC |
|
117 HandleError(ETrue); // true because explicit abort |
|
118 } |
|
119 |
|
120 void COPPController::HandleError(TBool aAbort) |
|
121 { |
|
122 TRACE_ERROR((_L( "[oppreceiveservice] COPPController:HandleError" ))); |
|
123 iReceivingFailed = ETrue; |
|
124 iShowRecvCompleteDialog = EFalse; |
|
125 if( iObexTransferState == ETransferPut || iObexTransferState == ETransferPutDiskError ) |
|
126 { |
|
127 if(iObexObject) |
|
128 { |
|
129 iObexObject->Reset(); |
|
130 } |
|
131 CancelTransfer(); |
|
132 if(!aAbort) |
|
133 { |
|
134 if(iMediaType == ESrcsMediaBT) |
|
135 { |
|
136 TRAP_IGNORE( |
|
137 HBufC* note = HbTextResolverSymbian::LoadLC(_L("txt_bt_dpophead_receiving_failed")); |
|
138 iDialog->ShowErrorNoteL(note->Des()); |
|
139 CleanupStack::PopAndDestroy(note); |
|
140 ); |
|
141 } |
|
142 TRACE_ASSERT(iMediaType != ESrcsMediaIrDA, KErrNotSupported) |
|
143 } |
|
144 } |
|
145 delete iBuf; |
|
146 iBuf = NULL; |
|
147 iObexTransferState = ETransferIdle; |
|
148 TRAP_IGNORE(TObexUtilsMessageHandler::RemoveInboxEntriesL(iObexObject, iMsvIdParent)); |
|
149 TRAP_IGNORE(TObexUtilsMessageHandler::RemoveTemporaryRFileL (iFullPathFilename)); |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------- |
|
153 // TransportUpIndication() |
|
154 // --------------------------------------------------------- |
|
155 // |
|
156 void COPPController::TransportUpIndication() |
|
157 { |
|
158 TRACE_FUNC |
|
159 iReceivingFailed = EFalse; |
|
160 iObexTransferState = ETransferIdle; |
|
161 |
|
162 if ( !iFs.Handle() ) |
|
163 { |
|
164 TRACE_INFO( (_L( "[oppreceiveservice] TransportUpIndication iFs.Connect()" )) ); |
|
165 if ( iFs.Connect() ) // error value not preserved, iFs.Handle() checked one more time before first useage |
|
166 { |
|
167 TRACE_INFO( (_L( "[oppreceiveservice] TransportUpIndication iFs.Connect() failed" )) ); |
|
168 } |
|
169 } |
|
170 |
|
171 iFile = RFile(); |
|
172 iFullPathFilename.Zero(); |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------- |
|
176 // ObexConnectIndication() |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 TInt COPPController::ObexConnectIndication( const TObexConnectInfo& aRemoteInfo, |
|
180 const TDesC8& aInfo) |
|
181 { |
|
182 TRACE_FUNC |
|
183 (void) aRemoteInfo; |
|
184 (void) aInfo; |
|
185 |
|
186 if ( iMediaType == ESrcsMediaBT ) |
|
187 { |
|
188 TRACE_INFO( _L( "[oppreceiveservice] ObexConnectIndication: BT media \t" ) ); |
|
189 |
|
190 // Get remote device socket address and bluetooth name |
|
191 // Remote bluetooth name will be displayed in the new message in inbox. |
|
192 // |
|
193 TSockAddr addr; |
|
194 iObexServer->RemoteAddr(addr); |
|
195 TBTDevAddr tBTDevAddr = static_cast<TBTSockAddr>(addr).BTAddr(); |
|
196 |
|
197 TBTRegistrySearch nameSearch; |
|
198 nameSearch.FindAddress(tBTDevAddr); |
|
199 |
|
200 iResultArray->Reset(); |
|
201 // ignore any errors here, if we don't get the name, we don't get the name |
|
202 static_cast<void>(iDevMan->GetDevices(nameSearch, iResultArray)); |
|
203 } |
|
204 |
|
205 return KErrNone; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------- |
|
209 // ObexDisconnectIndication( |
|
210 // --------------------------------------------------------- |
|
211 // |
|
212 void COPPController::ObexDisconnectIndication(const TDesC8& aInfo) |
|
213 { |
|
214 TRACE_FUNC |
|
215 (void) aInfo; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // TransportDownIndication() |
|
220 // --------------------------------------------------------- |
|
221 // |
|
222 void COPPController::TransportDownIndication() |
|
223 { |
|
224 TRACE_FUNC |
|
225 if(!iReceivingFailed && iShowRecvCompleteDialog) |
|
226 { |
|
227 //Launch recevice completed dialog. |
|
228 iRecvDoneDialog = CHbDeviceDialogSymbian::NewL(); |
|
229 iRecvDoneDialog->SetObserver(this); |
|
230 |
|
231 CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL(); |
|
232 CleanupStack::PushL(variantMap); |
|
233 |
|
234 TInt dialogIdx = TBluetoothDialogParams::EReceiveDone; |
|
235 CHbSymbianVariant* dialogType = CHbSymbianVariant::NewL( (TAny*) &(dialogIdx), |
|
236 CHbSymbianVariant::EInt ); |
|
237 CleanupStack::PushL(dialogType); |
|
238 TBuf16<6> dialogTypeKey; |
|
239 dialogTypeKey.Num(TBluetoothDialogParams::EDialogType); |
|
240 User::LeaveIfError(variantMap->Add(dialogTypeKey, dialogType)); |
|
241 CleanupStack::Pop(dialogType); |
|
242 |
|
243 CHbSymbianVariant* deviceName = CHbSymbianVariant::NewL( (TAny*) (&iRemoteDeviceName), |
|
244 CHbSymbianVariant::EDes ); |
|
245 CleanupStack::PushL(deviceName); |
|
246 TBuf16<6> deviceNameKey; |
|
247 deviceNameKey.Num(TBluetoothDeviceDialog::EDeviceName); |
|
248 User::LeaveIfError(variantMap->Add(deviceNameKey, deviceName)); |
|
249 CleanupStack::Pop(deviceName); |
|
250 |
|
251 CHbSymbianVariant* fileName = CHbSymbianVariant::NewL( (TAny*) (&iReceivingFileName), |
|
252 CHbSymbianVariant::EDes ); |
|
253 CleanupStack::PushL(fileName); |
|
254 TBuf16<6> fileNameKey; |
|
255 fileNameKey.Num(TBluetoothDeviceDialog::EReceivingFileName); |
|
256 User::LeaveIfError(variantMap->Add(fileNameKey, fileName)); |
|
257 CleanupStack::Pop(fileName); |
|
258 |
|
259 CHbSymbianVariant* fileSz = CHbSymbianVariant::NewL( (TAny*) &iTotalSizeByte, |
|
260 CHbSymbianVariant::EInt ); |
|
261 CleanupStack::PushL(fileSz); |
|
262 TBuf16<6> fileSzKey; |
|
263 fileSzKey.Num(TBluetoothDeviceDialog::EReceivingFileSize); |
|
264 User::LeaveIfError(variantMap->Add(fileSzKey, fileSz)); |
|
265 CleanupStack::Pop(fileSz); |
|
266 |
|
267 CHbSymbianVariant* fileCnt = CHbSymbianVariant::NewL( (TAny*) &iFileCount, |
|
268 CHbSymbianVariant::EInt ); |
|
269 CleanupStack::PushL(fileCnt); |
|
270 TBuf16<6> fileCntKey; |
|
271 fileCntKey.Num(TBluetoothDeviceDialog::EReceivedFileCount); |
|
272 User::LeaveIfError(variantMap->Add(fileCntKey, fileCnt)); |
|
273 CleanupStack::Pop(fileCnt); |
|
274 |
|
275 iRecvDoneDialog->Show( KBTDevDialogId(), *variantMap, this ); |
|
276 CleanupStack::PopAndDestroy(variantMap); |
|
277 iShowRecvCompleteDialog = EFalse; |
|
278 } |
|
279 |
|
280 // Remove receiving buffer and files used during file receiving. |
|
281 // |
|
282 delete iObexObject; |
|
283 iObexObject = NULL; |
|
284 TRAP_IGNORE(TObexUtilsMessageHandler::RemoveTemporaryRFileL (iFullPathFilename)); |
|
285 iFs.Close(); |
|
286 iFileCount = 0; |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------- |
|
290 // PutRequestIndication() |
|
291 // --------------------------------------------------------- |
|
292 // |
|
293 CObexBufObject* COPPController::PutRequestIndication() |
|
294 { |
|
295 TRACE_FUNC |
|
296 iLengthHeaderReceived = EFalse; // New put request so clear header based state |
|
297 iObexTransferState = ETransferPut; |
|
298 |
|
299 // Checking if backup is running now - if backup process is active, then we |
|
300 // need to cancel transfer - otherwise phone will freeze during receiving |
|
301 // data |
|
302 if ( IsBackupRunning() ) |
|
303 { |
|
304 TRACE_INFO ( _L ("Backup in progress! Canceling incoming transfer.")); |
|
305 iObexTransferState = ETransferPutInitError; |
|
306 return NULL; |
|
307 } |
|
308 |
|
309 TRAPD(err, HandlePutRequestL()); |
|
310 if(err == KErrNone) |
|
311 { |
|
312 return iObexObject; |
|
313 } |
|
314 TRACE_INFO( _L( "[oppreceiveservice] COPPController: PutRequestIndication end\t" ) ); |
|
315 if (iObexTransferState != ETransferPutInitError) |
|
316 { |
|
317 iObexTransferState = ETransferPutDiskError; |
|
318 } |
|
319 return NULL; |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------- |
|
323 // PutPacketIndication() |
|
324 // --------------------------------------------------------- |
|
325 // |
|
326 TInt COPPController::PutPacketIndication() |
|
327 { |
|
328 TRACE_FUNC |
|
329 if(iObexTransferState == ETransferPutCancel) |
|
330 { |
|
331 // User cancelled the put request, so error the next packet to terminate the put request. |
|
332 // BIP considers the Unauthorized error response suitable for this... |
|
333 HandleError(ETrue); // reset state and clear up |
|
334 return KErrIrObexRespUnauthorized; |
|
335 } |
|
336 |
|
337 iTotalSizeByte = iObexObject->Length(); // get size of receiving file |
|
338 iReceivingFileName = iObexObject->Name(); // get name of receiving file |
|
339 |
|
340 // Check that capacity is suitable as soon as possible |
|
341 if(!iLengthHeaderReceived && iTotalSizeByte > 0) |
|
342 { |
|
343 iLengthHeaderReceived = ETrue; // total size value is from length header |
|
344 TBool capacity = ETrue; |
|
345 TRAPD(retTrap, capacity = CheckCapacityL()); |
|
346 if(retTrap != KErrNone) |
|
347 { |
|
348 return KErrGeneral; |
|
349 } |
|
350 if(!capacity) |
|
351 { |
|
352 //TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY)); |
|
353 //todo: Need to use Localized string. |
|
354 _LIT(KText, "Not enough memory to execute operation. Delete some documents and try again."); |
|
355 TRAP_IGNORE(iDialog->ShowErrorNoteL(KText)); |
|
356 |
|
357 return KErrDiskFull; |
|
358 } |
|
359 } |
|
360 if(iObexObject->Name().Length() > KMaxFileName) |
|
361 { |
|
362 return KErrAccessDenied; |
|
363 } |
|
364 if(iObexTransferState == ETransferPutDiskError) |
|
365 { |
|
366 return KErrDiskFull; |
|
367 } |
|
368 // successfully received put packet if we reached here |
|
369 iObexTransferState = ETransferPut; |
|
370 |
|
371 // Now we need to either create (in the first instance) or update the dialog on the UI. |
|
372 if(ReceivingIndicatorActive()) |
|
373 { |
|
374 TRAPD(err, UpdateReceivingIndicatorL()); |
|
375 if(err < KErrNone) |
|
376 { |
|
377 return err; |
|
378 } |
|
379 } |
|
380 else if(!iNoteDisplayed) |
|
381 { |
|
382 // No note launched yet, so try to launch |
|
383 TRAPD(err, LaunchReceivingIndicatorL()); |
|
384 iNoteDisplayed = (err == KErrNone); |
|
385 } |
|
386 |
|
387 return KErrNone; |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 // PutCompleteIndication() |
|
392 // --------------------------------------------------------- |
|
393 // |
|
394 TInt COPPController::PutCompleteIndication() |
|
395 { |
|
396 TRACE_FUNC |
|
397 TInt retVal = KErrNone; |
|
398 if(iObexTransferState == ETransferPutCancel) |
|
399 { |
|
400 retVal = KErrIrObexRespUnauthorized; |
|
401 HandleError(ETrue); |
|
402 } |
|
403 else |
|
404 { |
|
405 retVal = HandlePutCompleteIndication(); |
|
406 iObexTransferState = ETransferIdle; |
|
407 CloseReceivingIndicator(); |
|
408 iFileCount++; |
|
409 iShowRecvCompleteDialog = ETrue; |
|
410 } |
|
411 TRACE_FUNC_EXIT |
|
412 return retVal; |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------- |
|
416 // GetRequestIndication() |
|
417 // --------------------------------------------------------- |
|
418 // |
|
419 CObexBufObject* COPPController::GetRequestIndication( CObexBaseObject* aRequiredObject) |
|
420 { |
|
421 TRACE_FUNC |
|
422 (void) aRequiredObject; |
|
423 return NULL; |
|
424 } |
|
425 |
|
426 // --------------------------------------------------------- |
|
427 // GetPacketIndication() |
|
428 // --------------------------------------------------------- |
|
429 // |
|
430 TInt COPPController::GetPacketIndication() |
|
431 { |
|
432 TRACE_FUNC |
|
433 return KErrNone; |
|
434 } |
|
435 |
|
436 // --------------------------------------------------------- |
|
437 // GetCompleteIndication() |
|
438 // --------------------------------------------------------- |
|
439 // |
|
440 TInt COPPController::GetCompleteIndication() |
|
441 { |
|
442 TRACE_FUNC |
|
443 return KErrNone; |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------- |
|
447 // SetPathIndication() |
|
448 // --------------------------------------------------------- |
|
449 // |
|
450 TInt COPPController::SetPathIndication( const CObex::TSetPathInfo& aPathInfo, |
|
451 const TDesC8& aInfo) |
|
452 { |
|
453 TRACE_FUNC |
|
454 |
|
455 (void) aPathInfo; |
|
456 (void) aInfo; |
|
457 // SetPath is not implemented in OPP - so following IrOBEX guidance, return |
|
458 // the Forbidden response code. |
|
459 return KErrIrObexRespForbidden; |
|
460 } |
|
461 |
|
462 |
|
463 |
|
464 // --------------------------------------------------------- |
|
465 // HandleNotifyL() |
|
466 // --------------------------------------------------------- |
|
467 // |
|
468 void COPPController::HandleNotifyL( TMemoryPropertyCheckType aCheckType ) |
|
469 { |
|
470 TRACE_FUNC |
|
471 |
|
472 // Only interested on this notification if we are receiving something |
|
473 if ( iObexTransferState == ETransferPut ) |
|
474 { |
|
475 // Check the keys, what has been changed. |
|
476 TRACE_INFO( _L( "[oppreceiveservice] COPPController::HandleNotifyL\t" ) ); |
|
477 if ( aCheckType == ECheckPhoneMemory ) |
|
478 { |
|
479 if ( SysUtil::FFSSpaceBelowCriticalLevelL( NULL, 0 ) ) |
|
480 { |
|
481 TRACE_INFO( _L( "[oppreceiveservice] COPPController: Obex Server error diskfull\t" ) ); |
|
482 iObexTransferState = ETransferPutDiskError; |
|
483 } |
|
484 } |
|
485 else if ( aCheckType == ECheckMMCMemory ) |
|
486 { |
|
487 if ( SysUtil::MMCSpaceBelowCriticalLevelL( NULL, 0 ) ) |
|
488 { |
|
489 TRACE_INFO( _L( "[oppreceiveservice] COPPController: Obex Server error diskfull\t" ) ); |
|
490 iObexTransferState = ETransferPutDiskError; |
|
491 } |
|
492 } |
|
493 } |
|
494 } |
|
495 // --------------------------------------------------------- |
|
496 // HandlePutRequestL() |
|
497 // --------------------------------------------------------- |
|
498 // |
|
499 void COPPController::HandlePutRequestL() |
|
500 { |
|
501 TRACE_FUNC |
|
502 |
|
503 delete iObexObject; |
|
504 iObexObject = NULL; |
|
505 |
|
506 iFile = RFile(); |
|
507 |
|
508 if ( !iFs.Handle() ) |
|
509 { |
|
510 User::Leave(KErrGeneral); |
|
511 } |
|
512 |
|
513 // Assign an initial value to iDrive |
|
514 iDrive = GetDriveWithMaximumFreeSpaceL(); |
|
515 |
|
516 // If iDrive is at critical space level, we immediately show out_of_memory. |
|
517 // |
|
518 if (SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, 0, iDrive )) |
|
519 { |
|
520 //TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY)); |
|
521 //todo: Need to use Localized string. |
|
522 _LIT(KText, "Not enough memory to execute operation. Delete some documents and try again."); |
|
523 TRAP_IGNORE(iDialog->ShowErrorNoteL(KText)); |
|
524 |
|
525 User::Leave(KErrGeneral); |
|
526 } |
|
527 |
|
528 TRACE_INFO( (_L( "[oppreceiveservice] HandlePutRequestL %d\t" ),iDrive ) ); |
|
529 |
|
530 iObexObject = CObexBufObject::NewL( NULL ); |
|
531 |
|
532 delete iBuf; |
|
533 iBuf = NULL; |
|
534 |
|
535 TRACE_ASSERT(iMediaType != ESrcsMediaIrDA, KErrNotSupported); |
|
536 if ( iMediaType == ESrcsMediaBT ) |
|
537 { |
|
538 TChar driveLetter; |
|
539 iDefaultFolder.Zero(); |
|
540 iFs.DriveToChar(iDrive, driveLetter); |
|
541 iDefaultFolder.Append(driveLetter); |
|
542 if ( iDrive == EDriveC ) |
|
543 { |
|
544 iDefaultFolder.Append(_L(":\\data\\")); |
|
545 } |
|
546 else |
|
547 { |
|
548 iDefaultFolder.Append(_L(":\\")); |
|
549 } |
|
550 iDefaultFolder.Append(iCenRepFolder); |
|
551 |
|
552 iFile = RFile(); |
|
553 iFullPathFilename.Zero(); |
|
554 TRAPD(err, TObexUtilsMessageHandler::CreateReceiveBufferAndRFileL(iFile, |
|
555 iDefaultFolder, |
|
556 iFullPathFilename, |
|
557 iBuf, |
|
558 KBufferSize)); |
|
559 if(err != KErrNone) |
|
560 { |
|
561 iObexTransferState = ETransferPutInitError; |
|
562 User::Leave(KErrGeneral); |
|
563 } |
|
564 } |
|
565 else |
|
566 { |
|
567 iObexTransferState = ETransferPutInitError; |
|
568 User::Leave(KErrGeneral); |
|
569 } |
|
570 |
|
571 User::LeaveIfError(iFile.Open(iFs,iFullPathFilename,EFileWrite)); |
|
572 TObexRFileBackedBuffer bufferdetails(*iBuf,iFile,CObexBufObject::EDoubleBuffering); |
|
573 |
|
574 TRAPD(err, iObexObject->SetDataBufL( bufferdetails) ); |
|
575 if (err != KErrNone) |
|
576 { |
|
577 iObexTransferState = ETransferPutInitError; |
|
578 User::Leave(KErrGeneral); // set to != KErrNone |
|
579 } |
|
580 |
|
581 TRACE_INFO( _L( "[oppreceiveservice] COPPController: HandlePutRequestL completed\t" ) ); |
|
582 } |
|
583 |
|
584 |
|
585 // --------------------------------------------------------- |
|
586 // HandlePutCompleteIndication() |
|
587 // --------------------------------------------------------- |
|
588 // |
|
589 TInt COPPController::HandlePutCompleteIndication() |
|
590 { |
|
591 TRACE_FUNC |
|
592 TInt retVal = KErrNone; |
|
593 |
|
594 TChar driveLetter; |
|
595 iDefaultFolder.Zero(); |
|
596 iFs.DriveToChar(iDrive, driveLetter); |
|
597 iDefaultFolder.Append(driveLetter); |
|
598 if ( iDrive == EDriveC ) |
|
599 { |
|
600 iDefaultFolder.Append(_L(":\\data\\")); |
|
601 } |
|
602 else |
|
603 { |
|
604 iDefaultFolder.Append(_L(":\\")); |
|
605 } |
|
606 iDefaultFolder.Append(iCenRepFolder); |
|
607 iFullPathFilename.Zero(); |
|
608 iFullPathFilename.Append(iDefaultFolder); |
|
609 |
|
610 |
|
611 TRACE_INFO( (_L( "[oppreceiveservice] HandlePutCompleteIndication %d\t" ),iDrive ) ); |
|
612 |
|
613 if (iMediaType==ESrcsMediaBT) |
|
614 { |
|
615 TRAP ( retVal, TObexUtilsMessageHandler::SaveFileToFileSystemL(iObexObject, |
|
616 KUidMsgTypeBt, |
|
617 iMsvIdParent, |
|
618 iFullPathFilename, |
|
619 iFile, |
|
620 iRemoteDeviceName)); |
|
621 } |
|
622 TRACE_ASSERT( iMediaType!=ESrcsMediaIrDA, KErrNotSupported); |
|
623 if ( retVal == KErrNone) |
|
624 { |
|
625 TRAP (retVal, TObexUtilsMessageHandler::AddEntryToInboxL(iMsvIdParent, iFullPathFilename)); |
|
626 |
|
627 if( retVal != KErrNone ) |
|
628 { |
|
629 TRACE_INFO( (_L( "[oppreceiveservice] HandlePutCompleteIndication AddEntryToInboxL() failed %d \t" ),retVal ) ); |
|
630 TRAP_IGNORE(TObexUtilsMessageHandler::RemoveInboxEntriesL(iObexObject, iMsvIdParent)); |
|
631 } |
|
632 } |
|
633 else |
|
634 { |
|
635 TRACE_INFO( (_L( "[oppreceiveservice] HandlePutCompleteIndication failed %d \t" ),retVal ) ); |
|
636 } |
|
637 |
|
638 |
|
639 delete iObexObject; |
|
640 iObexObject = NULL; |
|
641 |
|
642 delete iBuf; |
|
643 iBuf = NULL; |
|
644 |
|
645 iPreviousDefaultFolder = iDefaultFolder; // save the last file path where file is successfully saved to file system. |
|
646 iMsvIdParent = KMsvNullIndexEntryId; |
|
647 TRACE_INFO( _L( "[oppreceiveservice] HandlePutCompleteIndication Done\t" ) ); |
|
648 return retVal; |
|
649 } |
|
650 |
|
651 |
|
652 // --------------------------------------------------------- |
|
653 // CheckCapacity() |
|
654 // --------------------------------------------------------- |
|
655 // |
|
656 TBool COPPController::CheckCapacityL() |
|
657 { |
|
658 TRACE_FUNC_ENTRY |
|
659 |
|
660 iDrive = EDriveZ; // Intialize iDrive to Z |
|
661 TInt filesize = iObexObject->Length(); |
|
662 |
|
663 RFs rfs ; |
|
664 User::LeaveIfError(rfs.Connect()); |
|
665 |
|
666 TInt mmcDrive = KDefaultDrive; // External memroy card |
|
667 TInt imsDrive = KDefaultDrive; // Internal mass storage |
|
668 |
|
669 User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, imsDrive)); |
|
670 User::LeaveIfError(DriveInfo::GetDefaultDrive(DriveInfo::EDefaultRemovableMassStorage, mmcDrive)); |
|
671 |
|
672 TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL imsDrive=%d; mmcDrive=%d\t" ),imsDrive, mmcDrive ) ); |
|
673 |
|
674 TVolumeInfo volumeInfo; |
|
675 TInt err = rfs.Volume(volumeInfo, imsDrive); |
|
676 |
|
677 // If err != KErrNone, Drive is not available. |
|
678 // |
|
679 if ( !err ) |
|
680 { |
|
681 // Check capacity on Internal mass storage |
|
682 TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL Internal mass storage\t" )) ); |
|
683 if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &rfs, filesize, imsDrive ) ) |
|
684 { |
|
685 iDrive = imsDrive; |
|
686 } |
|
687 } |
|
688 |
|
689 if ( iDrive == EDriveZ) |
|
690 { |
|
691 err = rfs.Volume(volumeInfo, mmcDrive); |
|
692 if ( !err ) |
|
693 { |
|
694 // Check capacity on Internal mass storage |
|
695 TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL Checking memory card\t" )) ); |
|
696 if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &rfs, filesize, mmcDrive ) ) |
|
697 { |
|
698 iDrive = mmcDrive; |
|
699 } |
|
700 } |
|
701 } |
|
702 if ( iDrive == EDriveZ ) |
|
703 { |
|
704 TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL Checking phone memory\t" )) ); |
|
705 // Phone memory |
|
706 if( !SysUtil::DiskSpaceBelowCriticalLevelL( &rfs, filesize, EDriveC )) |
|
707 { |
|
708 iDrive = EDriveC; |
|
709 } |
|
710 } |
|
711 rfs.Close(); |
|
712 TRACE_INFO( (_L( "[oppreceiveservice] CheckCapacityL iDrive = %d\t" ),iDrive ) ); |
|
713 TRACE_FUNC_EXIT |
|
714 if (iDrive == EDriveZ) |
|
715 { |
|
716 // If there is no free space for receiving file, we need to set iPreviousDefaultFolder back to iDefaultFolder. |
|
717 // In order to show the file receveing dialog correctly. |
|
718 iDefaultFolder = iPreviousDefaultFolder; |
|
719 return EFalse; |
|
720 } |
|
721 return ETrue; |
|
722 } |
|
723 |
|
724 // --------------------------------------------------------- |
|
725 // IsOBEXActive() |
|
726 // --------------------------------------------------------- |
|
727 // |
|
728 TBool COPPController::IsOBEXActive() |
|
729 { |
|
730 TRACE_FUNC |
|
731 return ETrue; |
|
732 } |
|
733 |
|
734 // --------------------------------------------------------- |
|
735 // SetMediaType() |
|
736 // --------------------------------------------------------- |
|
737 // |
|
738 void COPPController::SetMediaType( TSrcsMediaType aMediaType ) |
|
739 { |
|
740 TRACE_FUNC |
|
741 iMediaType=aMediaType; |
|
742 } |
|
743 |
|
744 // --------------------------------------------------------- |
|
745 // SetObexServer() |
|
746 // --------------------------------------------------------- |
|
747 // |
|
748 TInt COPPController::SetObexServer( CObexServer* aServer) |
|
749 { |
|
750 TInt retVal=KErrNone; |
|
751 |
|
752 if (aServer) |
|
753 { |
|
754 iObexServer = aServer; |
|
755 retVal=aServer->Start(this); |
|
756 } |
|
757 return retVal; |
|
758 } |
|
759 |
|
760 // --------------------------------------------------------- |
|
761 // CancelTransfer() |
|
762 // --------------------------------------------------------- |
|
763 // |
|
764 void COPPController::CancelTransfer() |
|
765 { |
|
766 TRACE_FUNC |
|
767 CloseReceivingIndicator(); |
|
768 if(iObexTransferState == ETransferPut) |
|
769 { |
|
770 iObexTransferState = ETransferPutCancel; |
|
771 } |
|
772 else // go to idle for all other states |
|
773 { |
|
774 iObexTransferState = ETransferIdle; |
|
775 } |
|
776 } |
|
777 |
|
778 void COPPController::LaunchReceivingIndicatorL() |
|
779 { |
|
780 if(ReceivingIndicatorActive()) |
|
781 { |
|
782 return; |
|
783 } |
|
784 |
|
785 if(iTotalSizeByte > 0) |
|
786 { |
|
787 if(iReceivingFileName.Length() > 0) |
|
788 { |
|
789 iProgressDialog = CHbDeviceDialogSymbian::NewL(); |
|
790 iProgressDialog->SetObserver(this); |
|
791 |
|
792 CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL(); |
|
793 CleanupStack::PushL(variantMap); |
|
794 |
|
795 TInt dialogIdx = TBluetoothDialogParams::EReceiveProgress; |
|
796 CHbSymbianVariant* dialogType = CHbSymbianVariant::NewL( (TAny*) &(dialogIdx), |
|
797 CHbSymbianVariant::EInt ); |
|
798 CleanupStack::PushL(dialogType); |
|
799 TBuf16<6> dialogTypeKey; |
|
800 dialogTypeKey.Num(TBluetoothDialogParams::EDialogType); |
|
801 User::LeaveIfError(variantMap->Add(dialogTypeKey, dialogType)); |
|
802 CleanupStack::Pop(dialogType); |
|
803 |
|
804 CHbSymbianVariant* deviceName = CHbSymbianVariant::NewL( (TAny*) (&iRemoteDeviceName), |
|
805 CHbSymbianVariant::EDes ); |
|
806 CleanupStack::PushL(deviceName); |
|
807 TBuf16<6> deviceNameKey; |
|
808 deviceNameKey.Num(TBluetoothDeviceDialog::EDeviceName); |
|
809 User::LeaveIfError(variantMap->Add(deviceNameKey, deviceName)); |
|
810 CleanupStack::Pop(deviceName); |
|
811 |
|
812 CHbSymbianVariant* fileName = CHbSymbianVariant::NewL( (TAny*) (&iReceivingFileName), |
|
813 CHbSymbianVariant::EDes ); |
|
814 CleanupStack::PushL(fileName); |
|
815 TBuf16<6> fileNameKey; |
|
816 fileNameKey.Num(TBluetoothDeviceDialog::EReceivingFileName); |
|
817 User::LeaveIfError(variantMap->Add(fileNameKey, fileName)); |
|
818 CleanupStack::Pop(fileName); |
|
819 |
|
820 CHbSymbianVariant* fileSz = CHbSymbianVariant::NewL( (TAny*) &iTotalSizeByte, |
|
821 CHbSymbianVariant::EInt ); |
|
822 CleanupStack::PushL(fileSz); |
|
823 TBuf16<6> fileSzKey; |
|
824 fileSzKey.Num(TBluetoothDeviceDialog::EReceivingFileSize); |
|
825 User::LeaveIfError(variantMap->Add(fileSzKey, fileSz)); |
|
826 CleanupStack::Pop(fileSz); |
|
827 |
|
828 CHbSymbianVariant* fileCnt = CHbSymbianVariant::NewL( (TAny*) &iFileCount, |
|
829 CHbSymbianVariant::EInt ); |
|
830 CleanupStack::PushL(fileCnt); |
|
831 TBuf16<6> fileCntKey; |
|
832 fileCntKey.Num(TBluetoothDeviceDialog::EReceivedFileCount); |
|
833 User::LeaveIfError(variantMap->Add(fileCntKey, fileCnt)); |
|
834 CleanupStack::Pop(fileCnt); |
|
835 |
|
836 iDialogActive = ETrue; |
|
837 iProgressDialog->Show( KBTDevDialogId(), *variantMap, this ); |
|
838 CleanupStack::PopAndDestroy(variantMap); |
|
839 } |
|
840 else |
|
841 { |
|
842 if(iMediaType == ESrcsMediaBT) |
|
843 { |
|
844 //TODO - Remove the usage of the resources. |
|
845 //iProgressDialog->ShowProgressDialogL(R_BT_RECEIVING_DATA); |
|
846 } |
|
847 TRACE_ASSERT(iMediaType != ESrcsMediaIrDA, KErrNotSupported); |
|
848 } |
|
849 } |
|
850 else |
|
851 { |
|
852 |
|
853 /* |
|
854 * TODO - The functionality provided by CGlobalDialog will be removed |
|
855 * TODO - and this will be provided by CGlobalProgressDialog. |
|
856 */ |
|
857 if(iMediaType == ESrcsMediaBT) |
|
858 { |
|
859 // TODO |
|
860 } |
|
861 TRACE_ASSERT(iMediaType != ESrcsMediaIrDA, KErrNotSupported); |
|
862 } |
|
863 } |
|
864 |
|
865 void COPPController::UpdateReceivingIndicatorL() |
|
866 { |
|
867 if(iProgressDialog) |
|
868 { |
|
869 CHbSymbianVariantMap* variantMap = CHbSymbianVariantMap::NewL(); |
|
870 CleanupStack::PushL(variantMap); |
|
871 |
|
872 TInt bytesReceived = iObexObject->BytesReceived(); |
|
873 CHbSymbianVariant* progress = CHbSymbianVariant::NewL( (TAny*) &bytesReceived, CHbSymbianVariant::EInt ); |
|
874 CleanupStack::PushL(progress); |
|
875 User::LeaveIfError(variantMap->Add(_L("progress"), progress)); |
|
876 CleanupStack::Pop(progress); |
|
877 |
|
878 iProgressDialog->Update(*variantMap); |
|
879 CleanupStack::PopAndDestroy(variantMap); |
|
880 } |
|
881 } |
|
882 |
|
883 void COPPController::CloseReceivingIndicator(TBool aResetDisplayedState) |
|
884 { |
|
885 TRACE_FUNC |
|
886 if(aResetDisplayedState) |
|
887 { |
|
888 iNoteDisplayed = EFalse; |
|
889 } |
|
890 |
|
891 if(iProgressDialog) |
|
892 { |
|
893 iProgressDialog->Cancel(); |
|
894 iDialogActive = EFalse; |
|
895 delete iProgressDialog; |
|
896 iProgressDialog = NULL; |
|
897 } |
|
898 } |
|
899 |
|
900 // --------------------------------------------------------- |
|
901 // GetDriveWithMaximumFreeSpace() |
|
902 // --------------------------------------------------------- |
|
903 // |
|
904 TInt COPPController::GetDriveWithMaximumFreeSpaceL() |
|
905 { |
|
906 // Get drive with maximum freespace among phone memory, MMC, internal mass storage. |
|
907 // |
|
908 TRACE_FUNC |
|
909 TVolumeInfo volumeInfoC; |
|
910 TVolumeInfo volumeInfoE; |
|
911 TVolumeInfo volumeInfoF; |
|
912 TInt64 max = 0; |
|
913 TInt drive = 0; |
|
914 |
|
915 TInt err = iFs.Volume(volumeInfoC, EDriveC); |
|
916 |
|
917 if ( !err ) |
|
918 { |
|
919 // set initial values to max and drive. |
|
920 max = volumeInfoC.iFree; |
|
921 drive = EDriveC; |
|
922 } |
|
923 |
|
924 err = iFs.Volume(volumeInfoE, EDriveE); |
|
925 if ( !err ) |
|
926 { |
|
927 if (volumeInfoE.iFree >= max) |
|
928 { |
|
929 max = volumeInfoE.iFree; |
|
930 drive = EDriveE; |
|
931 } |
|
932 |
|
933 } |
|
934 |
|
935 err = iFs.Volume(volumeInfoF, EDriveF); |
|
936 if ( !err ) |
|
937 { |
|
938 if (volumeInfoF.iFree >= max) |
|
939 { |
|
940 max = volumeInfoF.iFree; |
|
941 drive = EDriveF; |
|
942 } |
|
943 } |
|
944 |
|
945 max = 0; |
|
946 return drive; |
|
947 } |
|
948 |
|
949 |
|
950 // ---------------------------------------------------------- |
|
951 // COPPController::HandleGetDevicesComplete |
|
952 // Callback from devman |
|
953 // ---------------------------------------------------------- |
|
954 // |
|
955 void COPPController::HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* aDeviceArray) |
|
956 { |
|
957 TRACE_INFO( _L( "[oppreceiveservice] HandleGetDevicesComplete: enter \t" ) ); |
|
958 |
|
959 (void) aDeviceArray; |
|
960 |
|
961 if ( aErr == KErrNone ) |
|
962 { |
|
963 if ( iResultArray->Count()) |
|
964 { |
|
965 iRemoteDeviceName.Zero(); |
|
966 if ( iResultArray->At(0)->FriendlyName().Length() > 0 ) |
|
967 { |
|
968 TRACE_INFO( _L( "[oppreceiveservice] HandleGetDevicesComplete: got friendly name \t" ) ); |
|
969 iRemoteDeviceName.Copy(iResultArray->At(0)->FriendlyName()); |
|
970 } |
|
971 else |
|
972 { |
|
973 TRACE_INFO( _L( "[oppreceiveservice] HandleGetDevicesComplete: got devciename name \t" )); |
|
974 TRAP_IGNORE(iRemoteDeviceName.Copy( BTDeviceNameConverter::ToUnicodeL(iResultArray->At(0)->DeviceName()))); |
|
975 } |
|
976 } |
|
977 } |
|
978 } |
|
979 TBool COPPController::IsBackupRunning() |
|
980 { |
|
981 const TUint32 KFileManagerBkupStatus = 0x00000001; |
|
982 |
|
983 TInt status = EFileManagerBkupStatusUnset; |
|
984 TBool retValue = EFalse; |
|
985 TInt err = RProperty::Get( TUid::Uid(KFileManagerUID3), KFileManagerBkupStatus, |
|
986 status ); |
|
987 if ( err == KErrNone ) |
|
988 { |
|
989 if ( status == EFileManagerBkupStatusBackup || |
|
990 status == EFileManagerBkupStatusRestore ) |
|
991 { |
|
992 TSecureId fileManagerSecureId( KFileManagerUID3 ); |
|
993 //only returning ETrue if backup process is still active |
|
994 retValue = ProcessExists( fileManagerSecureId ); |
|
995 } |
|
996 } |
|
997 |
|
998 return retValue; |
|
999 } |
|
1000 |
|
1001 TBool COPPController::ProcessExists( const TSecureId& aSecureId ) |
|
1002 { |
|
1003 _LIT( KFindPattern, "*" ); |
|
1004 TFindProcess finder(KFindPattern); |
|
1005 TFullName processName; |
|
1006 while( finder.Next( processName ) == KErrNone ) |
|
1007 { |
|
1008 RProcess process; |
|
1009 if ( process.Open( processName ) == KErrNone ) |
|
1010 { |
|
1011 TSecureId processId( process.SecureId() ); |
|
1012 process.Close(); |
|
1013 if( processId == aSecureId ) |
|
1014 { |
|
1015 return ETrue; |
|
1016 } |
|
1017 } |
|
1018 } |
|
1019 return EFalse; |
|
1020 } |
|
1021 |
|
1022 void COPPController::DialogDismissed(TInt aButtonId) |
|
1023 { |
|
1024 (void) aButtonId; |
|
1025 } |
|
1026 |
|
1027 void COPPController::DataReceived(CHbSymbianVariantMap& aData) |
|
1028 { |
|
1029 if(aData.Keys().MdcaPoint(0).Compare(_L("actionResult")) == 0) |
|
1030 { |
|
1031 TInt val = *(static_cast<TInt*>(aData.Get(_L("actionResult"))->Data())); |
|
1032 switch(val) |
|
1033 { |
|
1034 case TBluetoothDialogParams::ECancelReceive: |
|
1035 { |
|
1036 //User choose to cancel receiving. |
|
1037 CancelTransfer(); |
|
1038 }break; |
|
1039 |
|
1040 case TBluetoothDialogParams::EHide: |
|
1041 { |
|
1042 //Use choose to hide the progress dialog. |
|
1043 CloseReceivingIndicator(EFalse); |
|
1044 }break; |
|
1045 |
|
1046 case TBluetoothDialogParams::EShow: |
|
1047 case TBluetoothDialogParams::ECancelShow: |
|
1048 { |
|
1049 //In case of Show, the device dialog will handle the opening of conversation view. |
|
1050 iRecvDoneDialog->Cancel(); |
|
1051 delete iRecvDoneDialog; |
|
1052 iRecvDoneDialog = NULL; |
|
1053 }break; |
|
1054 } |
|
1055 } |
|
1056 } |
|
1057 |
|
1058 void COPPController::DeviceDialogClosed(TInt aCompletionCode) |
|
1059 { |
|
1060 (void) aCompletionCode; |
|
1061 } |
|
1062 |
|
1063 //////////////////////////// Global part //////////////////////////// |
|
1064 |
|
1065 // End of File |
|