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