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