landmarksui/engine/src/CLmkEncodeUnsavedLandmarksOp.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2002 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:   This class provides functionality of encoding landmarks
       
    15 *                both saved and unsaved landmarks (In Landmarks DB).
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "CLmkEncodeUnsavedLandmarksOp.h"
       
    27 #include "CLmkAOOperation.h"
       
    28 #include <EPos_CPosLmCategoryManager.h>
       
    29 #include <EPos_CPosLmOperation.h>
       
    30 #include "CLmkDbUtils.h"
       
    31 
       
    32 
       
    33 //CONSTANTS
       
    34 const TReal32 KOperationDone = 1;
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CLmkEncodeUnsavedLandmarksOp::CLmkEncodeUnsavedLandmarksOp
       
    39 // C++ constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CLmkEncodeUnsavedLandmarksOp::CLmkEncodeUnsavedLandmarksOp(
       
    44            CPosLandmarkEncoder&  aLandmarkEncoder,
       
    45            CPosLandmarkDatabase::TTransferOptions  aTransferOptions)
       
    46            :iEncoder(aLandmarkEncoder),
       
    47             iTransferOptions(aTransferOptions),
       
    48             iCurrentIsLm(ETrue),
       
    49             iStatusFlag(KPosLmOperationNotComplete)
       
    50 
       
    51     {
       
    52     iNrOfSubOperations = 1;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CLmkEncodeUnsavedLandmarksOp::ConstructL
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CLmkEncodeUnsavedLandmarksOp::ConstructL(const RPointerArray<CLmkLandmark>&  aLandmarks)
       
    61     {
       
    62     for (TInt i = 0; i < aLandmarks.Count(); i++)
       
    63         {
       
    64         CLmkLandmark* landmark = CLmkLandmark::NewL(*aLandmarks[i]);
       
    65         CleanupStack::PushL(landmark);
       
    66         User::LeaveIfError(iLandmarks.Append(landmark));
       
    67         CleanupStack::Pop();//landmark
       
    68         }
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CLmkEncodeUnsavedLandmarksOp::NewL
       
    74 // Two-phased constructor.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CLmkEncodeUnsavedLandmarksOp* CLmkEncodeUnsavedLandmarksOp::NewL(
       
    78                               CPosLandmarkEncoder&  aLandmarkEncoder,
       
    79                               const RPointerArray<CLmkLandmark>&  aLandmarks,
       
    80                               CPosLandmarkDatabase::TTransferOptions  aTransferOptions )
       
    81     {
       
    82     CLmkEncodeUnsavedLandmarksOp* self =
       
    83         new ( ELeave ) CLmkEncodeUnsavedLandmarksOp(aLandmarkEncoder,
       
    84                                                     aTransferOptions);
       
    85 
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL(aLandmarks );
       
    88     CleanupStack::Pop();
       
    89     return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CLmkEncodeUnsavedLandmarksOp::~CLmkEncodeUnsavedLandmarksOp
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CLmkEncodeUnsavedLandmarksOp::~CLmkEncodeUnsavedLandmarksOp()
       
    97     {
       
    98     iLandmarks.ResetAndDestroy();
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CLmkEncodeUnsavedLandmarksOp::NextStep
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CLmkEncodeUnsavedLandmarksOp::NextStep( TRequestStatus& aStatus,
       
   106                                     TReal32& aProgress )
       
   107     {
       
   108     aStatus = KRequestPending;
       
   109     iStatus = &aStatus;
       
   110     iProgress = &aProgress;
       
   111     TInt err(KErrNone);
       
   112     if (iCurrentIsLm)
       
   113         {
       
   114         CLmkLandmark* lmkLm  = iLandmarks[iCurrentLm++];
       
   115         CPosLandmark* lm = lmkLm->PosLandmark();
       
   116         TRAP(err,CLmkDbUtils::AddDefaultProtocolL(lm));
       
   117         if (iTransferOptions & CPosLandmarkDatabase::EIncludeCategories)
       
   118             {
       
   119             iCurrentCategory = 0;
       
   120             iCategories = lmkLm->Categories();
       
   121             if (iCategories.Count() != 0)
       
   122                 {
       
   123                 iCurrentIsLm = EFalse;
       
   124                 }
       
   125             }
       
   126 
       
   127         TRAP(err,iEncoder.AddLandmarkL(*lm));
       
   128         }
       
   129     else
       
   130         {
       
   131         for (TInt i = 0;
       
   132             i < iNrOfSubOperations &&
       
   133                 iCurrentCategory < iCategories.Count(); i++)
       
   134             {
       
   135             CPosLandmarkCategory* category =iCategories[iCurrentCategory++];
       
   136             if (iCurrentCategory == iCategories.Count())
       
   137                 {
       
   138                 iCurrentIsLm = ETrue;
       
   139                 }
       
   140             TRAP(err,iEncoder.AddCategoryForLatestLandmarkL(*category));
       
   141             }
       
   142         }
       
   143 
       
   144     if(!err)
       
   145         {
       
   146         if (iCurrentLm == iLandmarks.Count() &&
       
   147             iCurrentCategory == iCategories.Count())
       
   148             {
       
   149             iStatusFlag = KErrNone;
       
   150             aProgress = KOperationDone;
       
   151             }
       
   152         else if (iCurrentIsLm)
       
   153             {
       
   154             aProgress = TReal32(iCurrentLm) / iLandmarks.Count();
       
   155             }
       
   156         else
       
   157             {
       
   158             aProgress = TReal32(iCurrentLm - 1) / iLandmarks.Count() +
       
   159                         TReal32(iCurrentCategory + 1) /
       
   160                         (iCategories.Count() + 1) /
       
   161                         iLandmarks.Count();
       
   162             }
       
   163         }
       
   164     else
       
   165         {
       
   166         iStatusFlag = err;
       
   167         aProgress = KOperationDone;
       
   168         }
       
   169 
       
   170     User::RequestComplete( iStatus,iStatusFlag);
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CLmkEncodeUnsavedLandmarksOp::ExecuteL
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CLmkEncodeUnsavedLandmarksOp::ExecuteL()
       
   178     {
       
   179     // We never use asynchronous methods in synchronous way and therefore
       
   180     // don't need to support this method
       
   181     User::Leave( KErrNotSupported );
       
   182     }
       
   183 //  End of File