camerauis/cameraapp/generic/common/src/CamCollectionManagerAo.cpp
branchRCL_3
changeset 54 bac7acad7cb3
parent 0 1ddebce53859
child 57 2c87b2808fd7
equal deleted inserted replaced
53:61bc0f252b2b 54:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of Collection Manager asynchronous operation
       
    15 *  
       
    16 
       
    17    Copyright (c) 2007 Nokia Corporation.
       
    18 *  This material, including documentation and any related 
       
    19 *  computer programs, is protected by copyright controlled by 
       
    20 *  Nokia Corporation. All rights are reserved. Copying, 
       
    21 *  including reproducing, storing, adapting or translating, any 
       
    22 *  or all of this material requires the prior written consent of 
       
    23 *  Nokia Corporation. This material also contains confidential 
       
    24 *  information which may not be disclosed to others without the 
       
    25 *  prior written consent of Nokia Corporation.
       
    26 * 
       
    27 *
       
    28 */
       
    29 
       
    30 
       
    31 #include "CamCollectionManagerAo.h"
       
    32 #include <glxcollectionmanager.h>
       
    33 #include <glxcollectioninfo.h>
       
    34 #include "MCamAddToAlbumObserver.h"
       
    35 #include "CamLogger.h"
       
    36 #include "Cam.hrh"
       
    37 #include "CamUtility.h"
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CCamCollectionManagerAO::CCamCollectionManagerAO()
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CCamCollectionManagerAO::CCamCollectionManagerAO( MCamAddToAlbumObserver& aObserver )
       
    45 :CActive(EPriorityStandard),iObserver(aObserver)
       
    46     {
       
    47     CActiveScheduler::Add(this);
       
    48     }
       
    49 
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CCamCollectionManagerAO::~CCamCollectionManagerAO()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CCamCollectionManagerAO::~CCamCollectionManagerAO()
       
    56     {
       
    57     Cancel();
       
    58     if ( iCollectionManager )
       
    59         {
       
    60         delete iCollectionManager;
       
    61         iCollectionManager = NULL;
       
    62         }
       
    63     if ( iCollectionInfo )
       
    64         {
       
    65         delete iCollectionInfo;
       
    66         iCollectionInfo = NULL;
       
    67         }
       
    68     iSelectedAlbumIds.Close();
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CCamCollectionManagerAO::StartAddtoAlbumOperationL
       
    73 //
       
    74 // Initiates Callback Mechanism for adding Images/Videos to albums
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 void CCamCollectionManagerAO::StartCallBackAddToAlbumL(
       
    78                               const RArray<TUint32>& aSelectedAlbumIds, 
       
    79                               const TDesC& aUri 
       
    80                               )
       
    81     {
       
    82     PRINT( _L("Camera => CCamCollectionManagerAO::StartCallBackAddToAlbumL") );
       
    83     PRINT( _L("Camera <> CCamCollectionManagerAO::StartCallBackAddToAlbumL ... Calling CGlxCollectionManager::NewL()") );
       
    84     if (!iCollectionManager)
       
    85         {
       
    86         iCollectionManager = CGlxCollectionManager::NewL();
       
    87         }
       
    88     PRINT( _L("Camera <> CCamCollectionManagerAO::StartCallBackAddToAlbumL ... CGlxCollectionManager::NewL() Success ") );
       
    89     iUri = aUri;
       
    90     iSelectedAlbumIds.Reset();
       
    91 
       
    92     for ( TInt i = 0; i < aSelectedAlbumIds.Count(); i++ )
       
    93         {
       
    94         iSelectedAlbumIds.AppendL( aSelectedAlbumIds[i] );
       
    95         }
       
    96     iCurrentAlbumIndex = 0;
       
    97     PRINT( _L("Camera <> CCamCollectionManagerAO::StartCallBackAddToAlbumL ... Calling iCollectionManager->AddToCollectionL()") );
       
    98     iCollectionManager->AddToCollectionL(
       
    99                         aUri, 
       
   100     			        aSelectedAlbumIds[iCurrentAlbumIndex], 
       
   101     			        iStatus );
       
   102     PRINT( _L("Camera <> CCamCollectionManagerAO::StartCallBackAddToAlbumL ... iCollectionManager->AddToCollectionL() : Success") );
       
   103     iCurrentAlbumIndex++;
       
   104     iAddToAlbum = ETrue;
       
   105     SetActive();
       
   106     PRINT( _L("Camera <= CCamCollectionManagerAO::StartCallBackAddToAlbumL") );
       
   107     }
       
   108 
       
   109 
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 //  CCamCollectionManagerAO::CheckForAlbumExistenceL
       
   113 //
       
   114 //  Initiates Callback Mechanism for checking if the album really exists
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CCamCollectionManagerAO::CheckForAlbumExistenceL( 
       
   118                                        const TUint32 aDefaultAlbumId )
       
   119     {
       
   120     PRINT( _L("Camera => CCamCollectionManagerAO::CheckForAlbumExistenceL") );
       
   121     if (!iCollectionManager)
       
   122         {
       
   123         iCollectionManager = CGlxCollectionManager::NewL();
       
   124         }
       
   125     if ( iCollectionInfo )
       
   126         {
       
   127         delete iCollectionInfo;
       
   128         iCollectionInfo = NULL;
       
   129         }
       
   130     iCollectionInfo = CGlxCollectionInfo::NewL( aDefaultAlbumId );
       
   131     iCollectionManager->CollectionInfoL( *iCollectionInfo, iStatus );
       
   132     iCheckForAlbum = ETrue;
       
   133     SetActive();
       
   134     PRINT( _L("Camera <= CCamCollectionManagerAO::CheckForAlbumExistenceL") );
       
   135     }
       
   136    
       
   137 // ---------------------------------------------------------------------------
       
   138 // CCamCollectionManagerAO::RunL()
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CCamCollectionManagerAO::RunL()
       
   142     {
       
   143     PRINT( _L("Camera => CCamCollectionManagerAO::RunL") );
       
   144     if ( iAddToAlbum )
       
   145         {
       
   146         iAddToAlbum = EFalse;
       
   147         if ( iStatus.Int() == KErrNone)
       
   148     	    {
       
   149     	    PRINT( _L("Camera <> CCamCollectionManagerAO::RunL() Finalizing") );
       
   150             DoAddToAlbumOperationL();
       
   151     	    }
       
   152     	else
       
   153     	    {
       
   154     	    // if there is any error, we pass and handle there
       
   155     	    PRINT( _L("Camera <> CCamCollectionManagerAO::RunL() add to album has problems") );
       
   156     	    RunError( iStatus.Int() );
       
   157     	    }
       
   158         }
       
   159      else if ( iCheckForAlbum )
       
   160         {
       
   161         iCheckForAlbum = EFalse;
       
   162         if ( iStatus.Int() == KErrNone)
       
   163     	    {
       
   164             DoCheckAlbumOperationCompleteL();
       
   165     	    }
       
   166     	else
       
   167     	    {
       
   168     	    // if there is any error, we pass and handle there
       
   169     	    RunError( iStatus.Int() );
       
   170     	    }
       
   171         }
       
   172      else
       
   173         {
       
   174         // Handling special cases if any
       
   175         }
       
   176     PRINT( _L("Camera <= CCamCollectionManagerAO::RunL") );
       
   177     }
       
   178  
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CCamCollectionManagerAO::DoAddToAlbumOperationL()
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CCamCollectionManagerAO::DoAddToAlbumOperationL()
       
   185     {
       
   186     PRINT( _L("Camera => CCamCollectionManagerAO::DoAddToAlbumOperationL") );
       
   187     PRINT1( _L("Camera <> CCamCollectionManagerAO::DoAddToAlbumOperationL ... iCurrentAlbumIndex (%d)"), iCurrentAlbumIndex )
       
   188     PRINT1( _L("Camera <> CCamCollectionManagerAO::DoAddToAlbumOperationL ... iSelectedAlbumIds.Count() (%d)"), iSelectedAlbumIds.Count() )
       
   189 	if ( iCurrentAlbumIndex < iSelectedAlbumIds.Count() )
       
   190         {
       
   191         PRINT( _L("Camera <> CCamCollectionManagerAO::DoAddToAlbumOperationL ... Enters If Loop") );
       
   192         iCollectionManager->AddToCollectionL(
       
   193                             iUri, 
       
   194     			            iSelectedAlbumIds[iCurrentAlbumIndex], 
       
   195     			            iStatus );
       
   196         iCurrentAlbumIndex++;
       
   197         iAddToAlbum = ETrue;
       
   198     	SetActive();
       
   199         }
       
   200     else
       
   201         {
       
   202         PRINT( _L("Camera <> CCamCollectionManagerAO::DoAddToAlbumOperationL ... Enters Else Loop") );
       
   203         iAddToAlbum = EFalse;
       
   204         iSelectedAlbumIds.Reset();
       
   205         iObserver.AddToAlbumIdOperationComplete();
       
   206         }
       
   207     PRINT1( _L("Camera <= CCamCollectionManagerAO::DoAddToAlbumOperationL ... Before leaving iCurrentAlbumIndex (%d)"), iCurrentAlbumIndex )
       
   208     }
       
   209 
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CCamCollectionManagerAO::CheckAlbumOperationComplete
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CCamCollectionManagerAO::DoCheckAlbumOperationCompleteL()
       
   217     {
       
   218     PRINT( _L("Camera => CCamCollectionManagerAO::DoCheckAlbumOperationCompleteL") );
       
   219     if ( iCollectionInfo )
       
   220         {
       
   221    	    iObserver.CheckAlbumIdOperationCompleteL( iCollectionInfo->Exists(),
       
   222     	                                          iCollectionInfo->Title() );
       
   223         }
       
   224     PRINT( _L("Camera <= CCamCollectionManagerAO::DoCheckAlbumOperationCompleteL") );
       
   225     }
       
   226 
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CCamCollectionManagerAO::DoCancel()
       
   230 //
       
   231 // Cancels the active object
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CCamCollectionManagerAO::DoCancel()
       
   235     {
       
   236     PRINT( _L("Camera => CCamCollectionManagerAO::DoCancel") );
       
   237     if ( iCollectionManager )
       
   238         {
       
   239         iCollectionManager->Cancel();
       
   240         }
       
   241     iSelectedAlbumIds.Reset();
       
   242     PRINT( _L("Camera <= CCamCollectionManagerAO::DoCancel") );
       
   243     }
       
   244 
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CCamCollectionManagerAO::RunError()
       
   248 //
       
   249 // Handles all leaves and its safe to handle them in this method
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 TInt CCamCollectionManagerAO::RunError( TInt /*aError*/ )
       
   253     {
       
   254     PRINT( _L("Camera => CCamCollectionManagerAO::RunError") );
       
   255     // We make sure that if any error occurs, we cancel,
       
   256     // the ongoing request and delete all the pointers
       
   257     // so that no memory leaks occurs
       
   258     if ( iCollectionManager )
       
   259         {
       
   260         delete iCollectionManager;
       
   261         iCollectionManager = NULL;
       
   262         }
       
   263     if ( iCollectionInfo )
       
   264         {
       
   265         delete iCollectionInfo;
       
   266         iCollectionManager = NULL;
       
   267         }
       
   268     iSelectedAlbumIds.Reset();
       
   269 
       
   270     PRINT( _L("Camera <= CCamCollectionManagerAO::RunError") );
       
   271     return KErrNone;
       
   272     }
       
   273 
       
   274 //End of file