phonebookengines/VirtualPhonebook/VPbkEng/src/CVPbkContactStoreProperties.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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:  A store property implementation class for the stores
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CVPbkContactStoreProperties.h"
       
    22 
       
    23 #include <MVPbkContactStoreProperties2.h>
       
    24 
       
    25 // LOCAL
       
    26 /// Unnamed namespace for local definitions
       
    27 namespace
       
    28     {
       
    29     #ifdef _DEBUG
       
    30     enum TPanicCode
       
    31         {
       
    32         EPanicSupportedFieldsPreCond = 1
       
    33         };
       
    34 
       
    35     void Panic( TPanicCode aPanic )
       
    36         {
       
    37         _LIT( KPanicTxt, "CVPbkContactStoreProperties" );
       
    38         User::Panic( KPanicTxt(), aPanic );
       
    39         }
       
    40     #endif // _DEBUG
       
    41     } // unnamed namespace
       
    42 
       
    43 
       
    44 /*
       
    45 * Small helper class which implements MVPbkContactStoreProperties2
       
    46 *
       
    47 */
       
    48 class TVPbkContactStoreProperties2 : public MVPbkContactStoreProperties2
       
    49     {
       
    50     public:
       
    51 
       
    52         TVPbkContactStoreProperties2( TUint32& aFlags )
       
    53         : iFlags( aFlags )
       
    54             {
       
    55             }
       
    56 
       
    57     public://from MVPbkContactStoreProperties2
       
    58 
       
    59         TBool SupportsOwnContact() const
       
    60             {
       
    61             return (iFlags & CVPbkContactStoreProperties::EPropertyOwnContactSupported) != 0;
       
    62             }
       
    63 
       
    64     private:
       
    65 
       
    66         ///Ref: Boolean flags
       
    67         TUint32& iFlags;
       
    68 
       
    69     };
       
    70 
       
    71 
       
    72 // ============================ MEMBER FUNCTIONS ===============================
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CVPbkContactStoreProperties::CVPbkContactStoreProperties
       
    76 // C++ default constructor can NOT contain any code, that
       
    77 // might leave.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CVPbkContactStoreProperties::CVPbkContactStoreProperties()
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CVPbkContactStoreProperties::NewL
       
    86 // Two-phased constructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CVPbkContactStoreProperties* CVPbkContactStoreProperties::NewL()
       
    90     {
       
    91     CVPbkContactStoreProperties* self = new( ELeave )CVPbkContactStoreProperties;
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop();//self
       
    95     return self;
       
    96     }
       
    97 
       
    98 // Destructor
       
    99 CVPbkContactStoreProperties::~CVPbkContactStoreProperties()
       
   100     {
       
   101     iServiceTable.Close();
       
   102 
       
   103     delete iExtension2;
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CVPbkContactStoreProperties::ConstructL
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CVPbkContactStoreProperties::ConstructL()
       
   112     {
       
   113     iExtension2 = new( ELeave ) TVPbkContactStoreProperties2( iFlags );
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CVPbkContactStoreProperties::SetName
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C void CVPbkContactStoreProperties::SetName(
       
   122         const TVPbkContactStoreUriPtr& aName)
       
   123     {
       
   124     iUriName.Set(aName);
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CVPbkContactStoreProperties::SetSupportedFields
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C void CVPbkContactStoreProperties::SetSupportedFields(
       
   132         const MVPbkFieldTypeList& aSupportedFields)
       
   133     {
       
   134     iSupportedFields = &aSupportedFields;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CVPbkContactStoreProperties::SetBooleanProperty
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C void CVPbkContactStoreProperties::SetBooleanProperty(
       
   142         TPropertyFlag aFlag,
       
   143         TBool aValue)
       
   144     {
       
   145     if (aValue)
       
   146         {
       
   147         iFlags |= static_cast<TUint32>(aFlag);
       
   148         }
       
   149     else
       
   150         {
       
   151         iFlags &= ~static_cast<TUint32>(aFlag);
       
   152         }
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CVPbkContactStoreProperties::SetServiceProperty
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C void CVPbkContactStoreProperties::SetServicePropertyL(
       
   160         TUid aServiceUid,
       
   161         TBool aValue)
       
   162     {
       
   163     TBool append = ETrue;
       
   164     // look if the service is already in the table,
       
   165     for (TInt i = 0; i < iServiceTable.Count(); ++i)
       
   166         {
       
   167         TServiceElement element = iServiceTable[i];
       
   168         if (element.iServiceUid == aServiceUid)
       
   169             {
       
   170             // service uid exists in service table, replace value in table
       
   171             iServiceTable[i].iValue = aValue;
       
   172             append = EFalse;
       
   173             break;
       
   174             }
       
   175         }
       
   176     // service UID not in service table, append it to the array
       
   177     if (append)
       
   178         {
       
   179         TServiceElement element;
       
   180         element.iServiceUid = aServiceUid;
       
   181         element.iValue = aValue;
       
   182         iServiceTable.AppendL(element);
       
   183         }
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CVPbkContactStoreProperties::Name
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 TVPbkContactStoreUriPtr CVPbkContactStoreProperties::Name() const
       
   191     {
       
   192     // parse actual name of the contact store
       
   193     return iUriName.Component(TVPbkContactStoreUriPtr::EContactStoreUriStoreLocation);
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CVPbkContactStoreProperties::Uri
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TVPbkContactStoreUriPtr CVPbkContactStoreProperties::Uri() const
       
   201     {
       
   202     return iUriName;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CVPbkContactStoreProperties::ReadOnly
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TBool CVPbkContactStoreProperties::ReadOnly() const
       
   210     {
       
   211     return (iFlags & EPropertyReadOnly) != 0;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CVPbkContactStoreProperties::Persistent
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TBool CVPbkContactStoreProperties::Persistent() const
       
   219     {
       
   220     return (iFlags & EPropertyPersistent) != 0;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CVPbkContactStoreProperties::Local
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TBool CVPbkContactStoreProperties::Local() const
       
   228     {
       
   229     return (iFlags & EPropertyLocal) != 0;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CVPbkContactStoreProperties::Removable
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 TBool CVPbkContactStoreProperties::Removable() const
       
   237     {
       
   238     return (iFlags & EPropertyRemovable) != 0;
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CVPbkContactStoreProperties::SupportsFieldLabels
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TBool CVPbkContactStoreProperties::SupportsFieldLabels() const
       
   246     {
       
   247     return (iFlags & EPropertyFieldLabelSupported) != 0;
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CVPbkContactStoreProperties::SupportsDefaults
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 TBool CVPbkContactStoreProperties::SupportsDefaults() const
       
   255     {
       
   256     return (iFlags & EPropertyDefaultsSupported) != 0;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CVPbkContactStoreProperties::SupportsVoiceTags
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TBool CVPbkContactStoreProperties::SupportsVoiceTags() const
       
   264     {
       
   265     return (iFlags & EPropertyVoiceTagsSupported) != 0;
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CVPbkContactStoreProperties::SupportsSpeedDials
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 TBool CVPbkContactStoreProperties::SupportsSpeedDials() const
       
   273     {
       
   274     return (iFlags & EPropertySpeedDialsSupported) != 0;
       
   275     }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CVPbkContactStoreProperties::SupportsContactGroups
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 TBool CVPbkContactStoreProperties::SupportsContactGroups() const
       
   282     {
       
   283     return (iFlags & EPropertyContactGroupsSupported) != 0;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CVPbkContactStoreProperties::SupportedFields
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 const MVPbkFieldTypeList& CVPbkContactStoreProperties::SupportedFields() const
       
   291     {
       
   292     // Make sure that iSupportedFields has been assigned
       
   293     __ASSERT_DEBUG( iSupportedFields, Panic( EPanicSupportedFieldsPreCond ) );
       
   294 
       
   295     return *iSupportedFields;
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CVPbkContactStoreProperties::SupportsService
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TBool CVPbkContactStoreProperties::SupportsService(TUid aServiceUid) const
       
   303     {
       
   304     // this function is able to map a service UID to a certain service
       
   305     // and return whether the store supports it.
       
   306     // this allows clients to query support for services, such as voice tag,
       
   307     // without the need to make changes to existing client interfaces
       
   308     TBool ret = EFalse;
       
   309     for (TInt i = 0; i < iServiceTable.Count(); ++i)
       
   310         {
       
   311         TServiceElement element = iServiceTable[i];
       
   312         if (element.iServiceUid == aServiceUid)
       
   313             {
       
   314             // service uid exists in service table,
       
   315             // return service table value
       
   316             ret = element.iValue;
       
   317             break;
       
   318             }
       
   319         }
       
   320     return ret;
       
   321     }
       
   322 
       
   323 
       
   324 TAny* CVPbkContactStoreProperties::ContactStorePropertiesExtension( TUid aExtensionUid )
       
   325     {
       
   326     if( aExtensionUid == KMVPbkContactStorePropertiesExtension2Uid )
       
   327         {
       
   328         return static_cast<MVPbkContactStoreProperties2*>( iExtension2 );
       
   329         }
       
   330 
       
   331     return NULL;
       
   332     }
       
   333 
       
   334 //  End of File