mtpdataproviders/mtpimagedp/src/cmtpimagedprenameobject.cpp
changeset 0 d0791faffa3f
child 47 63cf70d3ecd8
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #include <f32file.h>
       
    22 
       
    23 #include <mtp/mmtpdataproviderframework.h>
       
    24 #include <mtp/mmtpobjectmgr.h>
       
    25 #include <mtp/cmtpobjectmetadata.h>
       
    26 #include <mtp/tmtptypeuint32.h>
       
    27 
       
    28 #include "cmtpimagedprenameobject.h"
       
    29 #include "cmtpimagedp.h"
       
    30 
       
    31 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDpRenameObject");)
       
    32 
       
    33 const TInt KMmMtpRArrayGranularity = 4;
       
    34 const TInt KUpdateThreshold = 30;
       
    35 const TInt KMaxFileNameLength = 260;
       
    36 
       
    37 CMTPImageDpRenameObject* CMTPImageDpRenameObject::NewL(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider)
       
    38     {
       
    39     CMTPImageDpRenameObject* self = new ( ELeave ) CMTPImageDpRenameObject(aFramework, aDataProvider);
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CMTPImageDpRenameObject::CMTPImageDpRenameObject
       
    48 // Standard C++ Constructor
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CMTPImageDpRenameObject::CMTPImageDpRenameObject(MMTPDataProviderFramework& aFramework, CMTPImageDataProvider& aDataProvider) :
       
    52     CActive(EPriorityStandard),
       
    53     iFramework(aFramework),
       
    54     iDataProvider(aDataProvider),
       
    55     iObjectHandles(KMmMtpRArrayGranularity)
       
    56     {
       
    57     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    58     __FLOG(_L8("CMTPImageDpRenameObject::CMTPImageDpRenameObject"));    
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CMTPImageDpRenameObject::~CMTPImageDpRenameObject
       
    63 // destructor
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CMTPImageDpRenameObject::~CMTPImageDpRenameObject()
       
    67     {
       
    68     __FLOG(_L8(">> ~CMTPImageDpRenameObject"));
       
    69     Cancel();
       
    70     iObjectHandles.Close();
       
    71     delete iObjectInfo;
       
    72     delete iParentObjectInfo;
       
    73     iNewFileName.Close();
       
    74     delete iRenameWaiter;
       
    75     __FLOG(_L8("<< ~CMTPImageDpRenameObject"));
       
    76     __FLOG_CLOSE;    
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CMTPImageDpRenameObject::StartL
       
    81 //
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CMTPImageDpRenameObject::StartL(const TUint32 aParentHandle, const TDesC& /*aOldFolderName*/)
       
    85     {
       
    86     __FLOG_VA((_L16(">> CMTPImageDpRenameObject::StartL aParentHandle(0x%x)"), aParentHandle));
       
    87 
       
    88     iObjectHandles.Reset();
       
    89 
       
    90     GenerateObjectHandleListL(aParentHandle);
       
    91     iCount = iObjectHandles.Count();
       
    92     __FLOG_VA((_L8(">> CMTPImageDpRenameObject::StartL handle count = %u"), iCount));
       
    93     if (iCount > 0)
       
    94         {
       
    95         iIndex = 0;
       
    96 
       
    97         TRequestStatus* status = &iStatus;
       
    98         User::RequestComplete( status, iStatus.Int() );
       
    99         SetActive();
       
   100 
       
   101         iRenameWaiter->Start();
       
   102         iObjectHandles.Reset();
       
   103         }
       
   104 
       
   105     __FLOG(_L8("<< CMTPImageDpRenameObject::StartL"));
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CMTPImageDpRenameObject::DoCancel()
       
   110 // Cancel the rename object process
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CMTPImageDpRenameObject::DoCancel()
       
   114     {
       
   115 
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CMTPImageDpRenameObject::RunL
       
   120 //
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CMTPImageDpRenameObject::RunL()
       
   124     {
       
   125     __FLOG_VA((_L8(">> CMTPImageDpRenameObject::RunL iIndex = %d"), iIndex));
       
   126     if (iIndex < iCount)
       
   127         {
       
   128         TInt threshold = KUpdateThreshold;
       
   129         for (;iIndex < iCount && threshold > 0; ++iIndex, --threshold)
       
   130             {
       
   131             if (iFramework.ObjectMgr().ObjectL(iObjectHandles[iIndex], *iObjectInfo))
       
   132                 {
       
   133                 //get parent object info
       
   134                 if (iFramework.ObjectMgr().ObjectL(iObjectInfo->Uint(CMTPObjectMetaData::EParentHandle), *iParentObjectInfo))
       
   135                     {                    
       
   136                     TParsePtrC objectUri = TParsePtrC(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
       
   137                     TParsePtrC parentUri = TParsePtrC(iParentObjectInfo->DesC(CMTPObjectMetaData::ESuid));
       
   138                     
       
   139                     iNewFileName.Zero();
       
   140                     iNewFileName.Append(parentUri.DriveAndPath());
       
   141                     iNewFileName.Append(objectUri.NameAndExt());
       
   142                     iNewFileName.Trim();
       
   143                     __FLOG_VA((_L16("New file name(%S)"), &iNewFileName));
       
   144                     
       
   145                     // update framework metadata DB
       
   146                     iObjectInfo->SetDesCL(CMTPObjectMetaData::ESuid, iNewFileName);
       
   147                     iObjectInfo->SetUint(CMTPObjectMetaData::EObjectMetaDataUpdate, 1);
       
   148                     iFramework.ObjectMgr().ModifyObjectL(*iObjectInfo);                  
       
   149                     }                
       
   150                 }         
       
   151             }
       
   152               
       
   153         TRequestStatus* status = &iStatus;
       
   154         User::RequestComplete(status, iStatus.Int());
       
   155         SetActive();
       
   156         }
       
   157     else
       
   158         {
       
   159         if(iRenameWaiter->IsStarted())
       
   160             iRenameWaiter->AsyncStop();
       
   161         }
       
   162 
       
   163     __FLOG(_L8("<< CMTPImageDpRenameObject::RunL"));
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CMTPImageDpRenameObject::RunError
       
   168 //
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CMTPImageDpRenameObject::RunError( TInt aError )
       
   172     {
       
   173     if (aError != KErrNone)
       
   174         __FLOG_VA((_L8(">> CMTPImageDpRenameObject::RunError with error %d"), aError));
       
   175 
       
   176     return KErrNone;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CMTPImageDpRenameObject::ConstructL
       
   181 //
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CMTPImageDpRenameObject::ConstructL()
       
   185     {
       
   186     __FLOG(_L8(">> CMTPImageDpRenameObject::ConstructL"));
       
   187     CActiveScheduler::Add( this );
       
   188 
       
   189     iObjectInfo = CMTPObjectMetaData::NewL();
       
   190     iParentObjectInfo = CMTPObjectMetaData::NewL();
       
   191     iNewFileName.CreateL(KMaxFileNameLength);
       
   192     iRenameWaiter = new( ELeave ) CActiveSchedulerWait;
       
   193     __FLOG(_L8("<< CMTPImageDpRenameObject::ConstructL"));
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CMTPImageDpRenameObject::GenerateObjectHandleListL
       
   198 //
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CMTPImageDpRenameObject::GenerateObjectHandleListL(TUint32 aParentHandle)
       
   202     {
       
   203     __FLOG_VA((_L8(">> CMTPImageDpRenameObject::GenerateObjectHandleListL aParentHandle(0x%x)"), aParentHandle));
       
   204     RMTPObjectMgrQueryContext context;
       
   205     RArray<TUint> handles;
       
   206     CleanupClosePushL(context); // + context
       
   207     CleanupClosePushL(handles); // + handles
       
   208 
       
   209     TMTPObjectMgrQueryParams params(KMTPStorageAll, KMTPFormatsAll, aParentHandle);
       
   210     do
       
   211         {
       
   212         iFramework.ObjectMgr().GetObjectHandlesL(params, context, handles);
       
   213 
       
   214         TInt numberOfObjects = handles.Count();
       
   215         for (TInt i = 0; i < numberOfObjects; i++)
       
   216             {
       
   217             if (iFramework.ObjectMgr().ObjectOwnerId(handles[i]) == iFramework.DataProviderId())
       
   218                 {
       
   219                 iObjectHandles.AppendL(handles[i]);
       
   220                 continue;
       
   221                 }
       
   222 
       
   223             // Folder
       
   224             // TODO: need to modify, should not know device dp id
       
   225             if (iFramework.ObjectMgr().ObjectOwnerId(handles[i]) == 0) // We know that the device dp id is always 0, otherwise the whole MTP won't work.
       
   226                 {
       
   227                 GenerateObjectHandleListL(handles[i]);
       
   228                 }
       
   229             }
       
   230         }
       
   231     while (!context.QueryComplete());
       
   232 
       
   233     CleanupStack::PopAndDestroy(&handles); // - handles
       
   234     CleanupStack::PopAndDestroy(&context); // - context
       
   235 
       
   236     __FLOG(_L8("<< CMTPImageDpRenameObject::GenerateObjectHandleListL"));
       
   237     }
       
   238 //end of file