phonebookengines/VirtualPhonebook/VPbkCntModel/src/NamedRemoteViewViewDefinitionStoreUtility.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Utility to help manage the remote view definitions.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "NamedRemoteViewViewDefinitionStoreUtility.h"
       
    21 #include <cntviewstore.h>
       
    22 
       
    23 
       
    24 namespace VPbkCntModel {
       
    25 
       
    26 TBool IsViewDefinitionContentSame(
       
    27         const CContactDefaultViewDefinition& aLhsViewDef, 
       
    28         const CContactDefaultViewDefinition& aRhsViewDef)
       
    29     {
       
    30     TBool ret = ETrue;
       
    31     // view exists in the view definition
       
    32     // check views configuration - compare sort orders
       
    33     if ( !( aLhsViewDef.SortOrder() == aRhsViewDef.SortOrder() ) )
       
    34         {
       
    35         return EFalse;
       
    36         }
       
    37     if ( aLhsViewDef.ViewPreferences() != 
       
    38             aRhsViewDef.ViewPreferences() )
       
    39         {
       
    40         return EFalse;
       
    41         }
       
    42     if ( aLhsViewDef.SortPluginNameL().CompareF( 
       
    43             aRhsViewDef.SortPluginNameL() ) )
       
    44         {
       
    45         return EFalse;
       
    46         }
       
    47     return ret;
       
    48     }
       
    49 
       
    50 /// Sort plugin name
       
    51 _LIT8(KSortPluginName, "/default");
       
    52 
       
    53 void CleanupContent(TAny* aArray)
       
    54     {
       
    55     RPointerArray<CContactDefaultViewDefinition>* array = 
       
    56         static_cast<RPointerArray<CContactDefaultViewDefinition>* >(aArray);
       
    57     for (TInt i = 0; i < array->Count(); ++i)
       
    58         {
       
    59         CContactDefaultViewDefinition* elem = (*array)[i];
       
    60         delete elem;
       
    61         }
       
    62     }
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 // NamedRemoteViewViewDefinitionStoreUtility::SetNamedRemoteViewViewDefinitionL
       
    66 // --------------------------------------------------------------------------
       
    67 //
       
    68 void NamedRemoteViewViewDefinitionStoreUtility::SetNamedRemoteViewViewDefinitionL(
       
    69         const TDesC& aViewName, 
       
    70         const RContactViewSortOrder& aSortOrder, 
       
    71         TContactViewPreferences aContactTypes)
       
    72     {
       
    73     DoSetNamedRemoteViewViewDefinitionL( aViewName, aSortOrder, 
       
    74             aContactTypes );
       
    75     }
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // NamedRemoteViewViewDefinitionStoreUtility::DoSetNamedRemoteViewViewDefinitionL
       
    79 // --------------------------------------------------------------------------
       
    80 //
       
    81 void NamedRemoteViewViewDefinitionStoreUtility::DoSetNamedRemoteViewViewDefinitionL(
       
    82         const TDesC& aViewName, 
       
    83         const RContactViewSortOrder& aSortOrder, 
       
    84         TContactViewPreferences aContactTypes)
       
    85     {
       
    86     // first get the already saved named remote view settings
       
    87     RPointerArray<CContactDefaultViewDefinition> defaultViews;
       
    88     CleanupClosePushL( defaultViews );
       
    89     TContactViewStore::GetDefaultViewsL(defaultViews);
       
    90     CleanupStack::PushL(TCleanupItem(CleanupContent, &defaultViews));
       
    91 
       
    92     CContactDefaultViewDefinition* newViewDef = CContactDefaultViewDefinition::NewLC(
       
    93         CContactDefaultViewDefinition::ENamedRemoteView, aViewName, 
       
    94         aSortOrder, aContactTypes, KSortPluginName );
       
    95 
       
    96     // Check whether the view exist in the settings
       
    97     TBool overwriteDefinition = EFalse;
       
    98     TInt index = -1;
       
    99     TBool addNewViewDef = ETrue;
       
   100     for ( TInt i = 0; i < defaultViews.Count(); ++i )
       
   101         {
       
   102         CContactDefaultViewDefinition* viewDef = defaultViews[i];
       
   103         if ( viewDef && !viewDef->ViewNameL().CompareF( aViewName ) )
       
   104             {
       
   105             addNewViewDef = EFalse;
       
   106             if ( !IsViewDefinitionContentSame(*viewDef, *newViewDef) )
       
   107                 {
       
   108                 overwriteDefinition = ETrue;
       
   109                 index = i;
       
   110                 break;
       
   111                 }
       
   112             }
       
   113         }
       
   114 
       
   115     // change default views according to modifications
       
   116     if (overwriteDefinition)
       
   117         {
       
   118         // remove and delete previous definition
       
   119         CContactDefaultViewDefinition* def = defaultViews[index];
       
   120         defaultViews.Remove(index);
       
   121         delete def;
       
   122         }
       
   123     if (overwriteDefinition || addNewViewDef)
       
   124         {
       
   125         defaultViews.AppendL(newViewDef);
       
   126         CleanupStack::Pop( newViewDef );
       
   127         }
       
   128     else
       
   129         {
       
   130         CleanupStack::PopAndDestroy( newViewDef );
       
   131         }
       
   132 
       
   133     // write modified view definition
       
   134     if (overwriteDefinition || addNewViewDef)
       
   135         {
       
   136         TContactViewStore::SetDefaultViewsL( defaultViews );
       
   137         }
       
   138 
       
   139     CleanupStack::PopAndDestroy(); // Clean array elements
       
   140     CleanupStack::PopAndDestroy(); // close pointer array
       
   141     }
       
   142 
       
   143 
       
   144 }  // namespace VPbkCntModel
       
   145 
       
   146 // End of file