homescreensrv_plat/sapi_menucontent/mcsservice/src/mcsupdateitem.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2008 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include "mcsmenuitem.h"
       
    19 #include "mcsmenuoperation.h"
       
    20 
       
    21 #include "mcsupdateitem.h"
       
    22 #include "mcscallback.h"
       
    23 #include "mcsservice.h"
       
    24 #include "mcsmenuopwatcher.h"
       
    25 #include "mcsoperationmanager.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // two-phased constructor
       
    29 // ---------------------------------------------------------------------------
       
    30 CMCSUpdateItem* CMCSUpdateItem::NewL( CMenuItem& aMenu,
       
    31         MMCSCallback* aCallback, RMcsOperationManager& aOperationManager )
       
    32 	{
       
    33 	CMCSUpdateItem* self = new (ELeave) CMCSUpdateItem( aMenu, aCallback, 
       
    34 	                                                    aOperationManager );
       
    35 	CleanupStack::PushL( self );
       
    36 	self->ConstructL();
       
    37 	CleanupStack::Pop( self );
       
    38 	return self;
       
    39 	}
       
    40 	
       
    41 // ---------------------------------------------------------------------------
       
    42 // destructor
       
    43 // ---------------------------------------------------------------------------
       
    44 CMCSUpdateItem::~CMCSUpdateItem()
       
    45 	{
       
    46 	Cancel();
       
    47 	delete iMenu; 
       
    48 	}
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // default constructor
       
    52 // ---------------------------------------------------------------------------
       
    53 CMCSUpdateItem::CMCSUpdateItem( CMenuItem& aMenu, MMCSCallback* aCallback,
       
    54                                     RMcsOperationManager& aOperationManager) :
       
    55 						CActive( EPriorityStandard ),
       
    56 						iCallback( aCallback ),
       
    57 						iMenu( &aMenu ),
       
    58     					iOperationManager(aOperationManager)						
       
    59 	{
       
    60 	}
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // second phase constructor
       
    64 // ---------------------------------------------------------------------------
       
    65 void CMCSUpdateItem::ConstructL()
       
    66 	{
       
    67 	}
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // Async update (add/change) item
       
    71 // ---------------------------------------------------------------------------
       
    72 void CMCSUpdateItem::UpdateItemL()
       
    73     {
       
    74     if( !iCallback )
       
    75         {
       
    76         User::Leave( KErrArgument );
       
    77         }
       
    78         CActiveScheduler::Add ( this );
       
    79         ActivateRequest( KErrNone );
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Inherited from CActive class 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CMCSUpdateItem::DoCancel()
       
    87 	{
       
    88 	//TRequestStatus* temp = &iStatus;
       
    89 	//User::RequestComplete( temp, KErrCancel );
       
    90 	TRAP_IGNORE( iCallback->NotifyResultL( KErrCancel, NULL ));
       
    91 	//NotifyRequestResult( err );
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Inherited from CActive class 
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CMCSUpdateItem::RunL()
       
    99 	{
       
   100 	TInt err = iStatus.Int();
       
   101     if ( err == KErrNone )
       
   102         {
       
   103     	CMCSMenuOpWatcher* watcherAO =  CMCSMenuOpWatcher::NewL( *this, 
       
   104 	                                                    iOperationManager );
       
   105 	    CleanupStack::PushL( watcherAO );
       
   106 	    iOperationManager.AddL( watcherAO );
       
   107         CleanupStack::Pop( watcherAO );// we pop item from cleanupstack because
       
   108                                   //ownership was transfered to operation manager
       
   109 
       
   110         CMenuOperation* operation = iMenu->SaveL( watcherAO->iStatus );
       
   111 
       
   112 	    watcherAO->Watch( *operation );
       
   113         }
       
   114     else
       
   115         {
       
   116         NotifyRequestResult( err );
       
   117         }
       
   118 	}
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CMCSUpdateItem::RunError
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 TInt CMCSUpdateItem::RunError(TInt aError)
       
   125 	{
       
   126     NotifyRequestResult( aError );
       
   127     if ( (aError != KErrDiskFull) && (aError != KErrNoMemory))
       
   128     	{
       
   129     	aError = KErrNone;
       
   130     	}    
       
   131 	return aError; 
       
   132 	}
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // Activates the asynchronous request
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CMCSUpdateItem::ActivateRequest( TInt aReason )
       
   139 	{
       
   140 	iStatus = KRequestPending;
       
   141 	SetActive();
       
   142 	TRequestStatus* temp = &iStatus;
       
   143     User::RequestComplete( temp, aReason );
       
   144 	}
       
   145 
       
   146 // --------------------------------------------------------------------------------------------------------
       
   147 // Notifies callback the result for asynchronous request.
       
   148 // --------------------------------------------------------------------------------------------------------
       
   149 //
       
   150 void CMCSUpdateItem::NotifyRequestResult( TInt aReason )
       
   151     {
       
   152     iOperationManager.Remove( this );//remove it 
       
   153                                      //from operation manager   
       
   154     if ( iCallback )
       
   155         {
       
   156         TInt id = iMenu->Id(); 
       
   157         TRAP_IGNORE(iCallback->NotifyResultL( aReason, (TAny*)&id));
       
   158         }
       
   159     delete this;
       
   160     }
       
   161 
       
   162 // --------------------------------------------------------------------------------------------------------
       
   163 // Notifies callback the result for asynchronous request.
       
   164 // --------------------------------------------------------------------------------------------------------
       
   165 //
       
   166 void CMCSUpdateItem::MenuOpCompletedL(TInt aStatus )
       
   167     {
       
   168     NotifyRequestResult( aStatus );
       
   169     }
       
   170 
       
   171 // End of file