menucontentsrv/srvsrc/menusrvoperation.cpp
changeset 0 79c6a41cd166
equal deleted inserted replaced
-1:000000000000 0:79c6a41cd166
       
     1 /*
       
     2 * Copyright (c) 2009 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 FILES
       
    19 
       
    20 #include <s32strm.h>
       
    21 #include "menusrvoperation.h"
       
    22 #include "menuitemattr.h"
       
    23 #include "menuutil.h"
       
    24 #include "menueng.h"
       
    25 #include "menuengobject.h"
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // CMenuSrvOperation::CMenuSrvOperation()
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 CMenuSrvOperation::CMenuSrvOperation( CMenuEng& aEng )
       
    34 : iEng( aEng )
       
    35     {
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------
       
    39 // CMenuSrvOperation::StartL()
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 void CMenuSrvOperation::StartL( const RMessage2& aMessage )
       
    43     {
       
    44     PanicIfPendingL( aMessage );
       
    45     iEng.QueueOperationL( *this );
       
    46     SetPending( aMessage ); // No leaving after this point!
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // CMenuSrvOperation::Cancel()
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 void CMenuSrvOperation::Cancel()
       
    54     {
       
    55     iEng.DequeueOperation( *this );
       
    56     Complete( KErrCancel );
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------
       
    60 // CMenuSrvOperation::CompletedMenuEngOperation()
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 void CMenuSrvOperation::CompletedMenuEngOperation( TInt aErr )
       
    64     {
       
    65     iEng.DequeueOperation( *this );
       
    66     Complete( aErr );
       
    67     }
       
    68 
       
    69 // ================= MEMBER FUNCTIONS =======================
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CMenuSrvRemoveOperation::CMenuSrvRemoveOperation
       
    73 // ---------------------------------------------------------
       
    74 //
       
    75 CMenuSrvRemoveOperation::CMenuSrvRemoveOperation( CMenuEng& aEng, TInt aId )
       
    76 : CMenuSrvOperation( aEng ), iId( aId )
       
    77     {
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CMenuSrvRemoveOperation::RunMenuEngOperationL
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 void CMenuSrvRemoveOperation::RunMenuEngOperationL()
       
    85     {
       
    86     iEng.RemoveL( iId );
       
    87     }
       
    88 
       
    89 // ================= MEMBER FUNCTIONS =======================
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CMenuSrvMoveToFolderOperation::~CMenuSrvMoveToFolderOperation
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 CMenuSrvMoveToFolderOperation::~CMenuSrvMoveToFolderOperation()
       
    96     {
       
    97     iItems.Close();
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CMenuSrvMoveToFolderOperation::NewL()
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 CMenuSrvMoveToFolderOperation* CMenuSrvMoveToFolderOperation::NewL(
       
   105         CMenuEng& aEng,
       
   106         RReadStream& aItems,
       
   107         TInt aFolder,
       
   108         TInt aMoveBefore )
       
   109     {
       
   110     CMenuSrvMoveToFolderOperation* op =
       
   111         new (ELeave) CMenuSrvMoveToFolderOperation
       
   112         ( aEng, aFolder, aMoveBefore );
       
   113     CleanupStack::PushL( op );
       
   114     op->ConstructL( aItems );
       
   115     CleanupStack::Pop( op );
       
   116     return op;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CMenuSrvMoveToFolderOperation::CMenuSrvMoveToFolderOperation
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 CMenuSrvMoveToFolderOperation::CMenuSrvMoveToFolderOperation
       
   124 ( CMenuEng& aEng, TInt aFolder, TInt aMoveBefore )
       
   125 : CMenuSrvOperation( aEng ), iFolder( aFolder ), iMoveBefore( aMoveBefore )
       
   126     {
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CMenuSrvMoveToFolderOperation::ConstructL()
       
   131 // ---------------------------------------------------------
       
   132 //
       
   133 void CMenuSrvMoveToFolderOperation::ConstructL( RReadStream& aItems )
       
   134     {
       
   135     MenuUtil::InternalizeL( iItems, aItems );
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CMenuSrvMoveToFolderOperation::RunMenuEngOperationL
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 void CMenuSrvMoveToFolderOperation::RunMenuEngOperationL()
       
   143     {
       
   144     iEng.MoveToFolderL( iItems, iFolder, iMoveBefore );
       
   145     }
       
   146 
       
   147 // ================= MEMBER FUNCTIONS =======================
       
   148 
       
   149 // ---------------------------------------------------------
       
   150 // CMenuSrvReorderOperation::CMenuSrvReorderOperation
       
   151 // ---------------------------------------------------------
       
   152 //
       
   153 CMenuSrvReorderOperation::CMenuSrvReorderOperation
       
   154 ( CMenuEng& aEng, TInt aId, TInt aMoveBefore )
       
   155 : CMenuSrvOperation( aEng ), iId( aId ), iMoveBefore( aMoveBefore )
       
   156     {
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------
       
   160 // CMenuSrvReorderOperation::RunMenuEngOperationL
       
   161 // ---------------------------------------------------------
       
   162 //
       
   163 void CMenuSrvReorderOperation::RunMenuEngOperationL()
       
   164     {
       
   165     iEng.ReorderL( iId, iMoveBefore );
       
   166     }
       
   167 
       
   168 // ================= MEMBER FUNCTIONS =======================
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CMenuSrvAddOperation::~CMenuSrvAddOperation
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 CMenuSrvAddOperation::~CMenuSrvAddOperation()
       
   175     {
       
   176     delete iObject;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------
       
   180 // CMenuSrvAddOperation::NewL()
       
   181 // ---------------------------------------------------------
       
   182 //
       
   183 CMenuSrvAddOperation* CMenuSrvAddOperation::NewL
       
   184 ( CMenuEng& aEng, const TDesC& aType, RReadStream& aChanges )
       
   185     {
       
   186     CMenuSrvAddOperation* op = new (ELeave) CMenuSrvAddOperation( aEng );
       
   187     CleanupStack::PushL( op );
       
   188     op->ConstructL( aType, aChanges );
       
   189     CleanupStack::Pop( op );
       
   190     return op;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // CMenuSrvAddOperation::CMenuSrvAddOperation
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 CMenuSrvAddOperation::CMenuSrvAddOperation( CMenuEng& aEng )
       
   198 : CMenuSrvOperation( aEng )
       
   199     {
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CMenuSrvAddOperation::ConstructL()
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 void CMenuSrvAddOperation::ConstructL( const TDesC& aType, RReadStream& aChanges )
       
   207     {
       
   208     iObject = iEng.NewObjectL( aType );
       
   209     // Flags.
       
   210     const TUint32 flags = aChanges.ReadUint32L();
       
   211     // Attributes.
       
   212     RMenuItemAttrArray attrChanges;
       
   213     CleanupResetAndDestroyPushL( attrChanges );
       
   214     attrChanges.InternalizeL( aChanges );
       
   215     // Parent folder and insertion point.
       
   216     iParent = aChanges.ReadInt32L();
       
   217     iInsertBefore = aChanges.ReadInt32L();
       
   218     // Flag and attribute data is stored inside the object.
       
   219     iObject->SetFlags( flags, ETrue );
       
   220     for ( TInt i = 0; i < attrChanges.Count(); i++ )
       
   221         {
       
   222         const CMenuItemAttr* attr = attrChanges[i];
       
   223         if ( attr->Value() )
       
   224             {
       
   225             iObject->SetAttributeL( attr->Name(), *attr->Value(), EFalse );
       
   226             }
       
   227         else
       
   228             {
       
   229             ; // No use trying to remove attribute: this is a new object.
       
   230             }
       
   231         }
       
   232     CleanupStack::PopAndDestroy( &attrChanges ); // Ownership NOT passed.        
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------
       
   236 // CMenuSrvAddOperation::ObjectId
       
   237 // ---------------------------------------------------------
       
   238 //
       
   239 TInt CMenuSrvAddOperation::ObjectId()
       
   240     {
       
   241     __ASSERT_DEBUG( iObject, User::Invariant() );
       
   242     return iObject->Id();
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CMenuSrvAddOperation::RunMenuEngOperationL
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 void CMenuSrvAddOperation::RunMenuEngOperationL()
       
   250     {
       
   251     __ASSERT_DEBUG( iObject, User::Invariant() );
       
   252     iEng.AddL( *iObject, iParent, iInsertBefore );
       
   253     iObject = NULL; // Ownership passed to engine.
       
   254     }
       
   255 
       
   256 // ================= MEMBER FUNCTIONS =======================
       
   257 
       
   258 // ---------------------------------------------------------
       
   259 // CMenuSrvUpdateOperation::~CMenuSrvUpdateOperation
       
   260 // ---------------------------------------------------------
       
   261 //
       
   262 CMenuSrvUpdateOperation::~CMenuSrvUpdateOperation()
       
   263     {
       
   264     iAttrChanges.ResetAndDestroy();
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // CMenuSrvUpdateOperation::NewL()
       
   269 // ---------------------------------------------------------
       
   270 //
       
   271 CMenuSrvUpdateOperation* CMenuSrvUpdateOperation::NewL
       
   272 ( CMenuEng& aEng, TInt aId, RReadStream& aChanges )
       
   273     {
       
   274     CMenuSrvUpdateOperation* op =
       
   275         new (ELeave) CMenuSrvUpdateOperation( aEng, aId );
       
   276     CleanupStack::PushL( op );
       
   277     op->ConstructL( aChanges );
       
   278     CleanupStack::Pop( op );
       
   279     return op;
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------
       
   283 // CMenuSrvUpdateOperation::CMenuSrvUpdateOperation
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 CMenuSrvUpdateOperation::CMenuSrvUpdateOperation( CMenuEng& aEng, TInt aId )
       
   287 : CMenuSrvOperation( aEng ), iId( aId )
       
   288     {
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------
       
   292 // CMenuSrvUpdateOperation::ConstructL()
       
   293 // ---------------------------------------------------------
       
   294 //
       
   295 void CMenuSrvUpdateOperation::ConstructL( RReadStream& aChanges )
       
   296     {
       
   297     iFlags = aChanges.ReadUint32L();
       
   298     iChangedFlags = aChanges.ReadUint32L();
       
   299     iAttrChanges.InternalizeL( aChanges );
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------
       
   303 // CMenuSrvUpdateOperation::RunMenuEngOperationL
       
   304 // ---------------------------------------------------------
       
   305 //
       
   306 void CMenuSrvUpdateOperation::RunMenuEngOperationL()
       
   307     {
       
   308     CMenuEngObject& object = iEng.ModifiableObjectL( iId );
       
   309     object.SetFlags( iFlags & iChangedFlags, ETrue );
       
   310     object.SetFlags( ~iFlags & iChangedFlags, EFalse );
       
   311     for ( TInt i = 0; i < iAttrChanges.Count(); i++ )
       
   312         {
       
   313         const CMenuItemAttr* attr = iAttrChanges[i];
       
   314         if ( attr->Value() )
       
   315             {
       
   316             object.SetAttributeL( attr->Name(), *attr->Value(), EFalse );
       
   317             }
       
   318         else
       
   319             {
       
   320             object.RemoveAttribute( attr->Name() );
       
   321             }
       
   322         }
       
   323     }
       
   324 
       
   325 //  End of File