|
1 /* |
|
2 * Copyright (c) 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: Obex Server image receiver module implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <avkon.hrh> // AVKON components |
|
21 #include "BIPController.h" |
|
22 #include "BIPCapabilityHandler.h" |
|
23 #include "BIPImageHandler.h" |
|
24 |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <StringLoader.h> // Series 60 localisation stringloader |
|
28 #include <obexutilsmessagehandler.h> |
|
29 #include <obexutilsuilayer.h> |
|
30 #include <obexutilsdialog.h> |
|
31 #include <UiklafInternalCRKeys.h> |
|
32 #include <obexutils.rsg> |
|
33 #include <sysutil.h> |
|
34 #include <bautils.h> |
|
35 #include <pathinfo.h> // provides interface for quering system paths |
|
36 #include <AknWaitDialog.h> |
|
37 #include <btengdomaincrkeys.h> |
|
38 #include <e32math.h> |
|
39 #include <es_sock.h> |
|
40 #include <bt_sock.h> |
|
41 #include <msvids.h> |
|
42 #include "debug.h" |
|
43 |
|
44 // CONSTANTS |
|
45 _LIT8(KBipCapabilityType, "x-bt/img-capabilities\0"); |
|
46 |
|
47 |
|
48 const TInt KBufferSize = 0x4000; // 16kB |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 CBIPController* CBIPController::NewL() |
|
53 { |
|
54 CBIPController* self = new ( ELeave ) CBIPController(); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 CleanupStack::Pop(self); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CBIPController() |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 CBIPController::CBIPController() |
|
66 { |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // ConstructL() |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 void CBIPController::ConstructL() |
|
74 { |
|
75 TRACE_FUNC_ENTRY |
|
76 iBIPImageHandler = CBIPImageHandler::NewL(); |
|
77 iLowMemoryActiveCDrive = CObexUtilsPropertyNotifier::NewL(this, ECheckPhoneMemory); |
|
78 iLowMemoryActiveMMC = CObexUtilsPropertyNotifier::NewL(this, ECheckMMCMemory); |
|
79 iDevMan = CBTEngDevMan::NewL(this); |
|
80 iResultArray = new(ELeave) CBTDeviceArray(1); |
|
81 // Get default folder from CenRep |
|
82 TObexUtilsMessageHandler::GetCenRepKeyStringValueL(KCRUidBluetoothEngine, KLCReceiveFolder, iCenRepFolder); |
|
83 TRACE_FUNC_EXIT |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------- |
|
87 // ~CBIPController() |
|
88 // --------------------------------------------------------- |
|
89 // |
|
90 CBIPController::~CBIPController() |
|
91 { |
|
92 TRACE_FUNC_ENTRY |
|
93 delete iGetObject; |
|
94 delete iBIPCapabilityHandler; |
|
95 delete iBIPImageHandler; |
|
96 delete iLowMemoryActiveCDrive; |
|
97 delete iLowMemoryActiveMMC; |
|
98 delete iBuf; |
|
99 delete iProgressDialog; |
|
100 delete iWaitDialog; |
|
101 delete iBTObject; |
|
102 delete iDevMan; |
|
103 if (iResultArray) |
|
104 { |
|
105 iResultArray->ResetAndDestroy(); |
|
106 delete iResultArray; |
|
107 } |
|
108 iFs.Close(); |
|
109 TRACE_FUNC_EXIT |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // ErrorIndication() |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 void CBIPController::ErrorIndication(TInt TRACE_ONLY(aError)) |
|
117 { |
|
118 TRACE_FUNC_ENTRY |
|
119 TRACE_ERROR((_L("[obexreceiveservicebip] CBIPController: ErrorIndication error:\t %d"), aError)); |
|
120 HandleError(EFalse); // false because this is not an explicit abort |
|
121 TRACE_FUNC_EXIT |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // AbortIndication() |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 void CBIPController::AbortIndication() |
|
129 { |
|
130 TRACE_FUNC_ENTRY |
|
131 HandleError(ETrue); // true because this is an explicit abort |
|
132 TRACE_FUNC_EXIT |
|
133 } |
|
134 |
|
135 void CBIPController::HandleError(TBool aAbort) |
|
136 { |
|
137 TRACE_FUNC_ENTRY |
|
138 |
|
139 if( iBTTransferState == ETransferPut || (!aAbort && iBTTransferState == ETransferPutDiskError) ) |
|
140 { |
|
141 if(iBTObject) |
|
142 { |
|
143 iBTObject->Reset(); |
|
144 } |
|
145 CancelTransfer(); |
|
146 TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL( R_BT_FAILED_TO_RECEIVE)); |
|
147 } |
|
148 delete iBuf; |
|
149 iBuf = NULL; |
|
150 |
|
151 iBTTransferState = ETransferIdle; |
|
152 TRAP_IGNORE(TObexUtilsMessageHandler::RemoveInboxEntriesL(iBTObject,iMsvIdParent)); |
|
153 TRAP_IGNORE(TObexUtilsMessageHandler::RemoveTemporaryRFileL(iFullPathFilename)); |
|
154 |
|
155 TRACE_FUNC_EXIT |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------- |
|
159 // CancelTransfer() |
|
160 // --------------------------------------------------------- |
|
161 // |
|
162 void CBIPController::CancelTransfer() |
|
163 { |
|
164 TRACE_FUNC_ENTRY |
|
165 CloseReceivingIndicator(); |
|
166 if(iBTTransferState == ETransferPut) |
|
167 { |
|
168 iBTTransferState = ETransferPutCancel; |
|
169 } |
|
170 else // go to idle for all other states |
|
171 { |
|
172 iBTTransferState = ETransferIdle; |
|
173 } |
|
174 } |
|
175 // --------------------------------------------------------- |
|
176 // TransportUpIndication() |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 void CBIPController::TransportUpIndication() |
|
180 { |
|
181 TRACE_FUNC |
|
182 if (!iFs.Handle()) |
|
183 { |
|
184 TRACE_INFO( (_L( "[bipreceiveservice] TransportUpIndication iFs.Connect()" )) ); |
|
185 if (iFs.Connect()) // error value not checked, iFs.Handle() checked one more time before first useage |
|
186 { |
|
187 TRACE_INFO( (_L( "[bipreceiveservice] TransportUpIndication iFs.Connect() failed" )) ); |
|
188 } |
|
189 } |
|
190 |
|
191 iFile = RFile(); |
|
192 iFullPathFilename.Zero(); |
|
193 iCapabilityFileName.Zero(); |
|
194 iMsvIdArray.Reset(); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------- |
|
198 // ObexConnectIndication() |
|
199 // --------------------------------------------------------- |
|
200 // |
|
201 TInt CBIPController::ObexConnectIndication( const TObexConnectInfo& /*aRemoteInfo*/, const TDesC8& /*aInfo*/ ) |
|
202 { |
|
203 TRACE_FUNC |
|
204 |
|
205 // Get remote device socket address and bluetooth name |
|
206 // Remote bluetooth name will be displayed in the new message in inbox. |
|
207 // |
|
208 TSockAddr addr; |
|
209 iBTObexServer->RemoteAddr(addr); |
|
210 TBTDevAddr tBTDevAddr = static_cast<TBTSockAddr>(addr).BTAddr(); |
|
211 |
|
212 TBTRegistrySearch nameSearch; |
|
213 nameSearch.FindAddress(tBTDevAddr); |
|
214 |
|
215 iResultArray->Reset(); |
|
216 // Ignore any errors here, if we don't get the name, we don't get the name. |
|
217 // It is also possible that the name is received too late.... |
|
218 static_cast<void>(iDevMan->GetDevices(nameSearch, iResultArray)); |
|
219 |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // ObexDisconnectIndication() |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 void CBIPController::ObexDisconnectIndication(const TDesC8& /*aInfo*/) |
|
228 { |
|
229 TRACE_FUNC |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // TransportDownIndication() |
|
234 // --------------------------------------------------------- |
|
235 // |
|
236 void CBIPController::TransportDownIndication() |
|
237 { |
|
238 TRACE_FUNC |
|
239 TRAP_IGNORE(ShowFileReceivedQueryL()); |
|
240 iFs.Close(); |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------- |
|
244 // PutRequestIndication() |
|
245 // --------------------------------------------------------- |
|
246 // |
|
247 CObexBufObject* CBIPController::PutRequestIndication() |
|
248 { |
|
249 TRACE_FUNC_ENTRY |
|
250 iLengthHeaderReceived = EFalse; // New put request so clear header based state |
|
251 iBTTransferState = ETransferPut; |
|
252 TRAPD(err, HandlePutImageRequestL()); |
|
253 if (err == KErrNone) |
|
254 { |
|
255 return iBTObject; |
|
256 } |
|
257 if (iBTTransferState != ETransferPutInitError) |
|
258 { |
|
259 iBTTransferState = ETransferPutDiskError; |
|
260 } |
|
261 TRACE_FUNC_EXIT |
|
262 return NULL; |
|
263 } |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // PutPacketIndication() |
|
267 // --------------------------------------------------------- |
|
268 // |
|
269 TInt CBIPController::PutPacketIndication() |
|
270 { |
|
271 TRACE_FUNC_ENTRY |
|
272 if(iBTTransferState == ETransferPutCancel) |
|
273 { |
|
274 // User cancelled the put request, so error the next packet to terminate the put request. |
|
275 // BIP considers the Unauthorized error response suitable for this... |
|
276 HandleError(ETrue); // reset state and clear up |
|
277 return KErrIrObexRespUnauthorized; |
|
278 } |
|
279 |
|
280 if (iBTObject) |
|
281 { |
|
282 iTotalSizeByte = iBTObject->Length(); // get size of receiving file |
|
283 iReceivingFileName = iBTObject->Name(); // get name of receiving file |
|
284 |
|
285 // Check that capacity is suitable as soon as possible |
|
286 if(!iLengthHeaderReceived && iTotalSizeByte > 0) |
|
287 { |
|
288 iLengthHeaderReceived = ETrue; // total size value is from length header |
|
289 TBool capacity = ETrue; |
|
290 TRAPD(retTrap, capacity = CheckCapacityL()); |
|
291 if(retTrap != KErrNone) |
|
292 { |
|
293 return KErrGeneral; |
|
294 } |
|
295 if(!capacity) |
|
296 { |
|
297 TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY)); |
|
298 return KErrDiskFull; |
|
299 } |
|
300 } |
|
301 if(iBTObject->Name().Length() > KMaxFileName) |
|
302 { |
|
303 return KErrAccessDenied; |
|
304 } |
|
305 if(iBTTransferState == ETransferPutDiskError) |
|
306 { |
|
307 return KErrDiskFull; |
|
308 } |
|
309 // successfully received put packet if we reached here |
|
310 iBTTransferState = ETransferPut; |
|
311 |
|
312 // Now we need to either create (in the first instance) or update the dialog on the UI. |
|
313 if(ReceivingIndicatorActive()) |
|
314 { |
|
315 UpdateReceivingIndicator(); |
|
316 } |
|
317 else if(!iNoteDisplayed) |
|
318 { |
|
319 // No note launched yet, so try to launch |
|
320 TRAPD(err, LaunchReceivingIndicatorL()); |
|
321 iNoteDisplayed = (err == KErrNone); |
|
322 } |
|
323 } |
|
324 |
|
325 TRACE_FUNC_EXIT |
|
326 return KErrNone; |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------- |
|
330 // PutCompleteIndication() |
|
331 // --------------------------------------------------------- |
|
332 // |
|
333 TInt CBIPController::PutCompleteIndication() // Once receive has completed. |
|
334 { |
|
335 TRACE_FUNC_ENTRY |
|
336 TInt retVal = KErrNone; |
|
337 if(iBTTransferState == ETransferPutCancel) |
|
338 { |
|
339 retVal = KErrIrObexRespUnauthorized; |
|
340 HandleError(ETrue); |
|
341 } |
|
342 else |
|
343 { |
|
344 retVal = HandlePutCompleteIndication(); |
|
345 iBTTransferState = ETransferIdle; |
|
346 CloseReceivingIndicator(); |
|
347 } |
|
348 TRACE_FUNC_EXIT |
|
349 return retVal; |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------- |
|
353 // GetRequestIndication() |
|
354 // --------------------------------------------------------- |
|
355 // |
|
356 CObexBufObject* CBIPController::GetRequestIndication( CObexBaseObject* aRequiredObject ) |
|
357 { |
|
358 TRACE_FUNC_ENTRY |
|
359 iBTTransferState = ETransferGet; |
|
360 TInt err = RemoveCapabilityObject(); |
|
361 if (err == KErrNone) |
|
362 { |
|
363 if( aRequiredObject->Type() == KBipCapabilityType ) |
|
364 { |
|
365 TRAP( err, HandleGetCapabilityRequestL( ) ); |
|
366 if( err == KErrNone ) |
|
367 { |
|
368 return iGetObject; |
|
369 } |
|
370 } |
|
371 } |
|
372 TRACE_FUNC_EXIT |
|
373 return NULL; |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------- |
|
377 // GetPacketIndication() |
|
378 // --------------------------------------------------------- |
|
379 // |
|
380 TInt CBIPController::GetPacketIndication() |
|
381 { |
|
382 TRACE_FUNC_ENTRY |
|
383 return KErrNone; |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------- |
|
387 // GetCompleteIndication() |
|
388 // --------------------------------------------------------- |
|
389 // |
|
390 TInt CBIPController::GetCompleteIndication() |
|
391 { |
|
392 TRACE_FUNC_ENTRY |
|
393 delete iGetObject; |
|
394 iGetObject=NULL; |
|
395 TInt err = RemoveCapabilityObject(); |
|
396 if (err != KErrNone) |
|
397 { |
|
398 err = KErrGeneral; |
|
399 } |
|
400 iBTTransferState = ETransferIdle; |
|
401 TRACE_FUNC_EXIT |
|
402 return err; |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // SetPathIndication() |
|
407 // --------------------------------------------------------- |
|
408 // |
|
409 TInt CBIPController::SetPathIndication( const CObex::TSetPathInfo& /*aPathInfo*/, |
|
410 const TDesC8& /*aInfo*/) |
|
411 { |
|
412 TRACE_FUNC |
|
413 // SetPath is not implemented in BIP - so following IrOBEX guidance, return |
|
414 // the Forbidden response code. |
|
415 return KErrIrObexRespForbidden; |
|
416 } |
|
417 |
|
418 /** |
|
419 * This function is implementation for mixin-class for Obexutils. |
|
420 * It is called every time another instance modifies disk status, |
|
421 * for example when it cross warning/critical level. |
|
422 * Parameters: |
|
423 * @param aCheckType Disktype changes. |
|
424 */ |
|
425 void CBIPController::HandleNotifyL(TMemoryPropertyCheckType aCheckType) |
|
426 { |
|
427 TRACE_FUNC_ENTRY |
|
428 // Only interested on this notification if we are receiving something |
|
429 if ( iBTTransferState == ETransferPut ) |
|
430 { |
|
431 // Check the keys, what has been changed. |
|
432 if ( aCheckType == ECheckPhoneMemory ) |
|
433 { |
|
434 if ( SysUtil::FFSSpaceBelowCriticalLevelL( NULL, 0 ) ) |
|
435 { |
|
436 TRACE_INFO( _L( "[obexreceiveservicebip] CBIPController: Obex Server error diskfull:\t" ) ); |
|
437 iBTTransferState = ETransferPutDiskError; |
|
438 } |
|
439 } |
|
440 else if ( aCheckType == ECheckMMCMemory ) |
|
441 { |
|
442 if ( SysUtil::MMCSpaceBelowCriticalLevelL( NULL, 0 ) ) |
|
443 { |
|
444 TRACE_INFO( _L( "[obexreceiveservicebip] CBIPController: Obex Server error diskfull:\t" ) ); |
|
445 iBTTransferState = ETransferPutDiskError; |
|
446 } |
|
447 } |
|
448 } |
|
449 TRACE_FUNC_EXIT |
|
450 } |
|
451 |
|
452 // --------------------------------------------------------- |
|
453 // HandleGetCapabilityRequestL() |
|
454 // --------------------------------------------------------- |
|
455 // |
|
456 void CBIPController::HandleGetCapabilityRequestL() |
|
457 { |
|
458 TRACE_FUNC_ENTRY |
|
459 CBIPCapabilityHandler* capHandler = CBIPCapabilityHandler::NewL(); |
|
460 CleanupStack::PushL(capHandler); |
|
461 capHandler->CreateCapabilityObjectL(iCapabilityFileName); |
|
462 delete iGetObject; |
|
463 iGetObject = NULL; |
|
464 iGetObject = CObexBufObject::NewL(NULL); |
|
465 iGetObject->SetDataBufL(iCapabilityFileName); |
|
466 CleanupStack::PopAndDestroy(capHandler); |
|
467 TRACE_FUNC_EXIT |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------- |
|
471 // HandlePutImageRequest() |
|
472 // --------------------------------------------------------- |
|
473 // |
|
474 void CBIPController::HandlePutImageRequestL() |
|
475 { |
|
476 TRACE_FUNC_ENTRY |
|
477 |
|
478 delete iBTObject; |
|
479 iBTObject = NULL; |
|
480 |
|
481 if (!iFs.Handle()) |
|
482 { |
|
483 User::Leave(KErrGeneral); |
|
484 } |
|
485 |
|
486 // Assign an initial value to iDrive |
|
487 iDrive = GetDriveWithMaximumFreeSpaceL(); |
|
488 |
|
489 // If iDrive is at critical space level, we immediately show out_of_memory. |
|
490 // |
|
491 if (SysUtil::DiskSpaceBelowCriticalLevelL(&iFs, 0, iDrive)) |
|
492 { |
|
493 TRAP_IGNORE(TObexUtilsUiLayer::ShowGlobalConfirmationQueryL(R_OUT_OF_MEMORY)); |
|
494 User::Leave(KErrGeneral); |
|
495 } |
|
496 |
|
497 iBTObject = CObexBufObject::NewL(NULL); |
|
498 |
|
499 delete iBuf; |
|
500 iBuf = NULL; |
|
501 |
|
502 TChar driveLetter; |
|
503 iDefaultFolder.Zero(); |
|
504 iFs.DriveToChar(iDrive, driveLetter); |
|
505 iDefaultFolder.Append(driveLetter); |
|
506 if ( iDrive == EDriveC ) |
|
507 { |
|
508 iDefaultFolder.Append(_L(":\\data\\")); |
|
509 } |
|
510 else |
|
511 { |
|
512 iDefaultFolder.Append(_L(":\\")); |
|
513 } |
|
514 |
|
515 iDefaultFolder.Append(iCenRepFolder); |
|
516 |
|
517 iFile = RFile(); |
|
518 iFullPathFilename.Zero(); |
|
519 TObexUtilsMessageHandler::CreateReceiveBufferAndRFileL(iFile, iDefaultFolder, iFullPathFilename, iBuf, KBufferSize); |
|
520 User::LeaveIfError(iFile.Open(iFs, iFullPathFilename, EFileWrite)); |
|
521 TObexRFileBackedBuffer bufferdetails(*iBuf, iFile, CObexBufObject::EDoubleBuffering); |
|
522 TRAPD(err, iBTObject->SetDataBufL(bufferdetails)); |
|
523 if (err != KErrNone) |
|
524 { |
|
525 iBTTransferState = ETransferPutInitError; |
|
526 User::Leave(KErrGeneral); |
|
527 } |
|
528 |
|
529 TRACE_FUNC_EXIT |
|
530 } |
|
531 |
|
532 |
|
533 // --------------------------------------------------------- |
|
534 // HandlePutCompleteIndication() |
|
535 // --------------------------------------------------------- |
|
536 // |
|
537 TInt CBIPController::HandlePutCompleteIndication() |
|
538 { |
|
539 TRACE_FUNC_ENTRY |
|
540 TInt retVal = KErrNone; |
|
541 |
|
542 iDefaultFolder.Zero(); |
|
543 TChar driveLetter; |
|
544 if ( iDrive == EDriveC ) |
|
545 { |
|
546 iFs.DriveToChar(iDrive, driveLetter); |
|
547 iDefaultFolder.Append(driveLetter); |
|
548 iDefaultFolder.Append(_L(":\\data\\")); |
|
549 iDefaultFolder.Append(iCenRepFolder); |
|
550 } |
|
551 else |
|
552 { |
|
553 iFs.DriveToChar(iDrive, driveLetter); |
|
554 iDefaultFolder.Append(driveLetter); |
|
555 iDefaultFolder.Append(_L(":\\")); |
|
556 iDefaultFolder.Append(iCenRepFolder); |
|
557 } |
|
558 |
|
559 iFullPathFilename.Zero(); |
|
560 iFullPathFilename.Append(iDefaultFolder); |
|
561 TRAP ( retVal, TObexUtilsMessageHandler::SaveFileToFileSystemL(iBTObject, |
|
562 KUidMsgTypeBt, |
|
563 iMsvIdParent, |
|
564 iFullPathFilename, |
|
565 iFile, |
|
566 iRemoteDeviceName)); |
|
567 if ( retVal == KErrNone) |
|
568 { |
|
569 TRAP (retVal, TObexUtilsMessageHandler::AddEntryToInboxL(iMsvIdParent, iFullPathFilename, &iMsvIdArray)); |
|
570 } |
|
571 |
|
572 |
|
573 if( retVal != KErrNone ) |
|
574 { |
|
575 TRACE_ERROR((_L( "[obexreceiveservicebip] CBIPController: HandlePutCompleteIndication error:\t %d" ), retVal ) ); |
|
576 TRAP( retVal, TObexUtilsMessageHandler::RemoveInboxEntriesL(iBTObject, iMsvIdParent)); |
|
577 retVal = KErrDiskFull; |
|
578 } |
|
579 // Even if the object saving fails we must return image handle with error code |
|
580 TRAP_IGNORE( iBIPImageHandler->AddImageHandleHeaderL( iBTObexServer ) ); |
|
581 TRACE_INFO( _L( "[obexreceiveservicebip] HandlePutCompleteIndication Done\t" ) ); |
|
582 delete iBTObject; |
|
583 iBTObject = NULL; |
|
584 delete iBuf; |
|
585 iBuf = NULL; |
|
586 iPreviousDefaultFolder = iDefaultFolder; // save the last file path where file is successfully saved to file system. |
|
587 iMsvIdParent = KMsvNullIndexEntryId; |
|
588 TRACE_FUNC_EXIT |
|
589 return retVal; |
|
590 } |
|
591 // --------------------------------------------------------- |
|
592 // RemoveCapabilityObject() |
|
593 // --------------------------------------------------------- |
|
594 // |
|
595 TInt CBIPController::RemoveCapabilityObject() |
|
596 { |
|
597 TRACE_FUNC_ENTRY |
|
598 if ( (iCapabilityFileName.Compare(KNullDesC)) == 0 ) |
|
599 { |
|
600 return KErrNone; |
|
601 } |
|
602 if ( !iFs.Handle() ) |
|
603 { |
|
604 TRACE_INFO( (_L( "[bipreceiveservice] RemoveCapabilityObject return" )) ); |
|
605 return KErrGeneral; |
|
606 } |
|
607 iFs.Delete(iCapabilityFileName); |
|
608 iCapabilityFileName=KNullDesC; |
|
609 TRACE_FUNC_EXIT |
|
610 return KErrNone; |
|
611 } |
|
612 |
|
613 // --------------------------------------------------------- |
|
614 // CheckCapacity() |
|
615 // --------------------------------------------------------- |
|
616 // |
|
617 TBool CBIPController::CheckCapacityL() |
|
618 { |
|
619 TRACE_FUNC_ENTRY |
|
620 |
|
621 iDrive = EDriveZ; // Intialize iDrive to Z |
|
622 TInt filesize = iBTObject->Length(); |
|
623 |
|
624 TFileName mmcRoot = PathInfo::MemoryCardRootPath(); // e.g. "E:\\" |
|
625 |
|
626 TInt mmcDrive = KDefaultDrive; // External memory card |
|
627 TInt imsDrive = KDefaultDrive; // Internal mass storage |
|
628 |
|
629 if ( mmcRoot == _L("E:\\")) |
|
630 { |
|
631 mmcDrive = EDriveE; |
|
632 imsDrive = EDriveF; |
|
633 } |
|
634 else if ( mmcRoot == _L("F:\\") ) |
|
635 { |
|
636 mmcDrive = EDriveF; |
|
637 imsDrive = EDriveE; |
|
638 } |
|
639 TVolumeInfo volumeInfo; |
|
640 TInt err = iFs.Volume(volumeInfo, imsDrive); |
|
641 |
|
642 // If err != KErrNone, Drive is not available. |
|
643 // |
|
644 if ( !err ) |
|
645 { |
|
646 // Check capacity on Internal mass storage |
|
647 TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Internal mass storage \t" )) ); |
|
648 if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, imsDrive ) ) |
|
649 { |
|
650 iDrive = imsDrive; |
|
651 } |
|
652 } |
|
653 if ( iDrive == EDriveZ ) |
|
654 { |
|
655 err = iFs.Volume(volumeInfo, mmcDrive); |
|
656 if ( !err ) |
|
657 { |
|
658 // Check capacity on memory card |
|
659 TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Checking memory card\t" )) ); |
|
660 if ( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, mmcDrive ) ) |
|
661 { |
|
662 iDrive = mmcDrive; |
|
663 } |
|
664 } |
|
665 } |
|
666 if ( iDrive == EDriveZ ) |
|
667 { |
|
668 TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL Checking phone memory\t" )) ); |
|
669 // Phone memory |
|
670 if( !SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, filesize, EDriveC )) |
|
671 { |
|
672 iDrive = EDriveC; |
|
673 } |
|
674 } |
|
675 |
|
676 TRACE_INFO( (_L( "[obexreceiveservicebip] CheckCapacityL iDrive = %d\t" ),iDrive ) ); |
|
677 TRACE_FUNC_EXIT |
|
678 |
|
679 if (iDrive == EDriveZ) |
|
680 { |
|
681 // If there is no free space for receiving file, we need to set iPreviousDefaultFolder back to iDefaultFolder. |
|
682 // In order to show the file receveing dialog correctly. |
|
683 iDefaultFolder = iPreviousDefaultFolder; |
|
684 return EFalse; |
|
685 } |
|
686 return ETrue; |
|
687 } |
|
688 |
|
689 |
|
690 // --------------------------------------------------------- |
|
691 // IsOBEXActive() |
|
692 // --------------------------------------------------------- |
|
693 // |
|
694 TBool CBIPController::IsOBEXActive() |
|
695 { |
|
696 TRACE_FUNC |
|
697 return ETrue; |
|
698 } |
|
699 |
|
700 // --------------------------------------------------------- |
|
701 // SetMediaType() |
|
702 // --------------------------------------------------------- |
|
703 // |
|
704 void CBIPController::SetMediaType( TSrcsMediaType __DEBUG_ONLY(aMediaType) ) |
|
705 { |
|
706 TRACE_FUNC |
|
707 // BIP is only for Bluetooth, so that is all we expect |
|
708 __ASSERT_DEBUG(aMediaType == ESrcsMediaBT, User::Panic(KBipPanicCategory, EBipPanicNotBluetoothMediaType)); |
|
709 } |
|
710 |
|
711 // --------------------------------------------------------- |
|
712 // SetObexServer() |
|
713 // --------------------------------------------------------- |
|
714 // |
|
715 TInt CBIPController::SetObexServer( CObexServer* aServer) |
|
716 { |
|
717 TInt retVal=KErrNone; |
|
718 if (aServer) |
|
719 { |
|
720 iBTObexServer=aServer; |
|
721 retVal=aServer->Start(this); |
|
722 } |
|
723 return retVal; |
|
724 } |
|
725 |
|
726 void CBIPController::LaunchReceivingIndicatorL() |
|
727 { |
|
728 if(ReceivingIndicatorActive()) |
|
729 { |
|
730 return; |
|
731 } |
|
732 |
|
733 if(iTotalSizeByte > 0) |
|
734 { |
|
735 iProgressDialog = CGlobalProgressDialog::NewL(this); |
|
736 if(iReceivingFileName.Length() > 0) |
|
737 { |
|
738 iProgressDialog->ShowProgressDialogNameSizeL(iReceivingFileName, iTotalSizeByte); |
|
739 } |
|
740 else |
|
741 { |
|
742 iProgressDialog->ShowProgressDialogL(R_BT_RECEIVING_DATA); |
|
743 } |
|
744 } |
|
745 else |
|
746 { |
|
747 iWaitDialog = CGlobalDialog::NewL(this); |
|
748 iWaitDialog->ShowNoteDialogL(R_BT_RECEIVING_DATA, ETrue); |
|
749 } |
|
750 } |
|
751 |
|
752 void CBIPController::UpdateReceivingIndicator() |
|
753 { |
|
754 if(iProgressDialog) |
|
755 { |
|
756 iProgressDialog->UpdateProgressDialog(iBTObject->BytesReceived(), iTotalSizeByte); |
|
757 } |
|
758 // else we are using a wait note, so no "need" to update |
|
759 } |
|
760 |
|
761 void CBIPController::HandleGlobalProgressDialogL( TInt aSoftkey ) |
|
762 { |
|
763 TRACE_FUNC |
|
764 |
|
765 if(aSoftkey == EAknSoftkeyCancel) |
|
766 { |
|
767 CancelTransfer(); |
|
768 } |
|
769 else if(aSoftkey == EAknSoftkeyHide) |
|
770 { |
|
771 CloseReceivingIndicator(EFalse); // Don't reset state as only hiding |
|
772 } |
|
773 } |
|
774 |
|
775 void CBIPController::HandleGlobalNoteDialogL( TInt aSoftkey ) |
|
776 { |
|
777 TRACE_FUNC |
|
778 |
|
779 if( aSoftkey == EAknSoftkeyCancel ) |
|
780 { |
|
781 CancelTransfer(); |
|
782 } |
|
783 else if( aSoftkey == EAknSoftkeyHide) |
|
784 { |
|
785 CloseReceivingIndicator(EFalse); // Don't reset state as only hiding |
|
786 } |
|
787 } |
|
788 |
|
789 void CBIPController::CloseReceivingIndicator(TBool aResetDisplayedState) |
|
790 { |
|
791 TRACE_FUNC |
|
792 if(aResetDisplayedState) |
|
793 { |
|
794 iNoteDisplayed = EFalse; |
|
795 } |
|
796 if(iProgressDialog) |
|
797 { |
|
798 iProgressDialog->ProcessFinished(); |
|
799 delete iProgressDialog; |
|
800 iProgressDialog = NULL; |
|
801 } |
|
802 if(iWaitDialog) |
|
803 { |
|
804 iWaitDialog->ProcessFinished(); |
|
805 delete iWaitDialog; |
|
806 iWaitDialog = NULL; |
|
807 } |
|
808 } |
|
809 |
|
810 // --------------------------------------------------------- |
|
811 // ShowFileReceivedQuery() |
|
812 // --------------------------------------------------------- |
|
813 // |
|
814 void CBIPController::ShowFileReceivedQueryL() |
|
815 { |
|
816 // Remove receiving buffer and files used during file receiving. |
|
817 // |
|
818 delete iBTObject; |
|
819 iBTObject = NULL; |
|
820 TObexUtilsMessageHandler::RemoveTemporaryRFileL (iFullPathFilename); |
|
821 |
|
822 TInt fileCount = iMsvIdArray.Count(); |
|
823 if ( fileCount ) |
|
824 { |
|
825 TBool answer = EFalse; |
|
826 TInt resourceID = R_BT_SAVED_SINGLE; |
|
827 if( fileCount > 1) |
|
828 { |
|
829 resourceID = R_BT_SAVED_MULTIPLE; |
|
830 } |
|
831 answer = TObexUtilsUiLayer::ShowGlobalFileOpenConfirmationQueryL(resourceID, iDefaultFolder); |
|
832 |
|
833 TInt sortMethod = 2; // 0 = by name 1 = by type 2 = most recent file and 3 = largest file |
|
834 |
|
835 if ( answer && fileCount == 1 ) // User accepts the query |
|
836 { |
|
837 TRAPD( error, TObexUtilsUiLayer::LaunchEditorApplicationL(iMsvIdArray[0])); |
|
838 if ( error != KErrNone ) // file is unsupported |
|
839 { |
|
840 TObexUtilsUiLayer::LaunchFileManagerL(iFullPathFilename, |
|
841 sortMethod, |
|
842 EFalse); // EFalse -> start file manager in standalone mode |
|
843 } |
|
844 } |
|
845 |
|
846 if ( answer && fileCount > 1 ) |
|
847 { |
|
848 // we open the file manager at default folder |
|
849 // |
|
850 TObexUtilsUiLayer::LaunchFileManagerL(iFullPathFilename, |
|
851 sortMethod, |
|
852 EFalse); // EFalse -> start file manager in standalone mode |
|
853 } |
|
854 iMsvIdArray.Reset(); |
|
855 } |
|
856 } |
|
857 |
|
858 |
|
859 // --------------------------------------------------------- |
|
860 // GetDriveWithMaximumFreeSpace() |
|
861 // --------------------------------------------------------- |
|
862 // |
|
863 TInt CBIPController::GetDriveWithMaximumFreeSpaceL() |
|
864 { |
|
865 // Get drive with maximum freespace among phone memory, MMC, internal mass storage. |
|
866 // |
|
867 TRACE_FUNC |
|
868 |
|
869 TVolumeInfo volumeInfoC; |
|
870 TVolumeInfo volumeInfoE; |
|
871 TVolumeInfo volumeInfoF; |
|
872 TInt64 max = 0; |
|
873 TInt drive = 0; |
|
874 |
|
875 TInt err = iFs.Volume(volumeInfoC, EDriveC); |
|
876 |
|
877 if ( !err ) |
|
878 { |
|
879 // set initial values to max and drive. |
|
880 max = volumeInfoC.iFree; |
|
881 drive = EDriveC; |
|
882 } |
|
883 |
|
884 err = iFs.Volume(volumeInfoE, EDriveE); |
|
885 if ( !err ) |
|
886 { |
|
887 if (volumeInfoE.iFree >= max) |
|
888 { |
|
889 max = volumeInfoE.iFree; |
|
890 drive = EDriveE; |
|
891 } |
|
892 |
|
893 } |
|
894 |
|
895 err = iFs.Volume(volumeInfoF, EDriveF); |
|
896 if ( !err ) |
|
897 { |
|
898 if (volumeInfoF.iFree >= max) |
|
899 { |
|
900 max = volumeInfoF.iFree; |
|
901 drive = EDriveF; |
|
902 } |
|
903 } |
|
904 max = 0; |
|
905 return drive; |
|
906 } |
|
907 |
|
908 // ---------------------------------------------------------- |
|
909 // COPPController::HandleDevManComplete |
|
910 // Callback from devman |
|
911 // ---------------------------------------------------------- |
|
912 // |
|
913 // |
|
914 void CBIPController::HandleGetDevicesComplete(TInt aErr, CBTDeviceArray* /*aDeviceArray*/) |
|
915 { |
|
916 if ( aErr == KErrNone ) |
|
917 { |
|
918 if ( iResultArray->Count()) |
|
919 { |
|
920 iRemoteDeviceName.Zero(); |
|
921 if ( iResultArray->At(0)->FriendlyName().Length() > 0 ) |
|
922 { |
|
923 TRACE_INFO( _L( "[CBIPController] HandleGetDevicesComplete: got friendly name \t" ) ); |
|
924 iRemoteDeviceName.Copy(iResultArray->At(0)->FriendlyName()); |
|
925 } |
|
926 else |
|
927 { |
|
928 TRACE_INFO( _L( "[CBIPController] HandleGetDevicesComplete: got devciename name \t" ) ); |
|
929 TRAP_IGNORE(iRemoteDeviceName.Copy(BTDeviceNameConverter::ToUnicodeL(iResultArray->At(0)->DeviceName()))); |
|
930 } |
|
931 } |
|
932 } |
|
933 } |
|
934 |
|
935 //////////////////////////// Global part //////////////////////////// |
|
936 |
|
937 // End of File |