menucontentsrv/srvsrc/mcschildrenscanner.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:  The API supports attributes not present in MCS from SAT Api
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "mcschildrenscanner.h"
       
    20 #include "menueng.h"
       
    21 #include "menusrveng.h"
       
    22 #include "menuengobject.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS =============================
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // Creates an instance of CMcsChildrenScanner implementation
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CMcsChildrenScanner* CMcsChildrenScanner::NewL( 
       
    31 	MMcsChildrenScanner& aObserver, 
       
    32 	CMenuSrvEng& aSrvEng)
       
    33     {
       
    34     CMcsChildrenScanner* self = new (ELeave) CMcsChildrenScanner( 
       
    35         aObserver, aSrvEng );
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     
       
    40     return self;
       
    41     }
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // Destructor
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CMcsChildrenScanner::~CMcsChildrenScanner()
       
    49     {
       
    50     Cancel();
       
    51     iSrvEng.Engine().DequeueOperation( *this );
       
    52     iIdBuff.Close();
       
    53     }
       
    54     
       
    55 // -----------------------------------------------------------------------------
       
    56 // CMcsChildrenScanner::CMcsChildrenScanner
       
    57 // C++ default constructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CMcsChildrenScanner::CMcsChildrenScanner( 
       
    61 	MMcsChildrenScanner& aObserver, 
       
    62     CMenuSrvEng& aSrvEng ): 
       
    63     CActive( EPriorityNormal ), iObserver( aObserver ), 
       
    64     iSrvEng(aSrvEng)
       
    65     {    
       
    66     CActiveScheduler::Add( this );
       
    67     iOpStatus = EFalse;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CMcsChildrenScanner::ConstructL
       
    72 // S2nd phase constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CMcsChildrenScanner::ConstructL()
       
    76     {
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CMcsChildrenScanner::DoCancel
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CMcsChildrenScanner::DoCancel()
       
    84     {
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CMcsChildrenScanner::RunL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CMcsChildrenScanner::RunL()
       
    92     {
       
    93     User::LeaveIfError( iStatus.Int() ); // Handle errors in RunL.
       
    94     iSrvEng.Engine().QueueOperationL( *this );    
       
    95     }    
       
    96 
       
    97 // ---------------------------------------------------------
       
    98 // CMcsChildrenScanner::RunError()
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 TInt CMcsChildrenScanner::RunError( TInt /*aError*/ )
       
   102     {
       
   103     // Ignore the error (what else could we do?).
       
   104     return KErrNone;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CMenuSrvAppScanner::RunMenuEngOperationL
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 void CMcsChildrenScanner::RunMenuEngOperationL()
       
   112     {
       
   113     ScanFolderL();
       
   114     iOpStatus = EFalse;
       
   115     }  
       
   116     
       
   117 // ---------------------------------------------------------
       
   118 // CMenuSrvAppScanner::CompletedMenuEngOperation
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 void CMcsChildrenScanner::CompletedMenuEngOperation( TInt /*aErr*/ )
       
   122     {
       
   123     }          
       
   124 
       
   125     
       
   126 // ---------------------------------------------------------
       
   127 // CMcsChildrenScanner::ScanFolderL
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 void CMcsChildrenScanner::ScanFolderL()
       
   131     {    
       
   132     
       
   133     while ( iIdBuff.Count( ) != 0 ) 
       
   134     	{
       
   135     	TInt currentFolder = iIdBuff[0];
       
   136     	
       
   137 		// Get current children_count
       
   138 		TUint32 newCount =  iSrvEng.GetChildrenCountL(currentFolder);
       
   139 		
       
   140 		// Chceck if children_count has changed
       
   141 		// if children_count wasn't in cash it will be added
       
   142 		// when GetAttributeL is executed
       
   143 		TBool attrExists;
       
   144 		RBuf attrVal;
       
   145 		attrVal.CleanupClosePushL();
       
   146 		attrVal.CreateL(KMenuMaxAttrValueLen);
       
   147 		
       
   148 		iSrvEng.GetAttributeL(currentFolder, KChildrenCount, attrExists, attrVal);
       
   149 		
       
   150 		if (attrExists)
       
   151 			{
       
   152 			TLex lex(attrVal);
       
   153 			TUint oldCount;
       
   154 			TInt err = lex.Val(oldCount);
       
   155 			if (err == KErrNone)
       
   156 				{
       
   157 				iObserver.HandleChildrenEvent(currentFolder, oldCount, newCount);
       
   158 				}
       
   159 			}
       
   160 		
       
   161 		CleanupStack::PopAndDestroy( &attrVal );
       
   162 		RemoveId(currentFolder);
       
   163     	}
       
   164     iOpStatus = EFalse;
       
   165     }
       
   166 
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // 
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CMcsChildrenScanner::Scan(TInt aId)
       
   173     {
       
   174     AddId(aId);
       
   175     if ( !IsActive() && !iOpStatus )
       
   176         {
       
   177         iOpStatus = ETrue;
       
   178         TRequestStatus* ownStatus = &iStatus;
       
   179         *ownStatus = KRequestPending;
       
   180         SetActive();
       
   181         User::RequestComplete( ownStatus, KErrNone );
       
   182         } 
       
   183     }  
       
   184     
       
   185 
       
   186 void CMcsChildrenScanner::AddId(TInt aId)
       
   187 	{
       
   188 	if (iIdBuff.Find(aId) == KErrNotFound)
       
   189 		{
       
   190 		iIdBuff.Append(aId);
       
   191 		}
       
   192 	}
       
   193 
       
   194 void CMcsChildrenScanner::RemoveId(TInt aId)
       
   195 	{
       
   196 	TInt index = iIdBuff.Find(aId);
       
   197 	if (index != KErrNotFound)
       
   198 		{
       
   199 		iIdBuff.Remove(index);
       
   200 		}
       
   201 	}
       
   202 // End of File