phonebookengines/VirtualPhonebook/VPbkCntModel/src/CViewContact.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     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:  Contacts Model store view contact implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "CViewContact.h"
       
    21 #include <cntviewbase.h>
       
    22 #include <cntitem.h>
       
    23 
       
    24 #include <VPbkError.h>
       
    25 #include <MVPbkContactObserver.h>
       
    26 #include <MVPbkFieldType.h>
       
    27 
       
    28 #include "CContact.h"
       
    29 #include "CContactView.h"
       
    30 #include "CGroupMembersView.h"
       
    31 #include "CContactStore.h"
       
    32 #include "CContactLink.h"
       
    33 #include "CFieldTypeMap.h"
       
    34 
       
    35 namespace VPbkCntModel {
       
    36 
       
    37 // --------------------------------------------------------------------------
       
    38 // TViewContactTextFieldData::TViewContactTextFieldData
       
    39 // --------------------------------------------------------------------------
       
    40 //
       
    41 TViewContactTextFieldData::TViewContactTextFieldData(const TDesC& aTextData) :
       
    42     iTextData(aTextData)
       
    43     {
       
    44     }
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // TViewContactTextFieldData::SetTextData
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 inline void TViewContactTextFieldData::SetTextData(const TDesC& aTextData)
       
    51     {
       
    52     iTextData.Set(aTextData);
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // TViewContactTextFieldData::IsEmpty
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 TBool TViewContactTextFieldData::IsEmpty() const
       
    60     {
       
    61     return iTextData.Length() == 0;
       
    62     }
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 // TViewContactTextFieldData::CopyL
       
    66 // --------------------------------------------------------------------------
       
    67 //
       
    68 void TViewContactTextFieldData::CopyL(const MVPbkContactFieldData& /*aFieldData*/)
       
    69     {
       
    70     /// Do nothing
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // TViewContactTextFieldData::Text
       
    75 // --------------------------------------------------------------------------
       
    76 //
       
    77 TPtrC TViewContactTextFieldData::Text() const
       
    78     {
       
    79     return iTextData;
       
    80     }
       
    81 
       
    82 // --------------------------------------------------------------------------
       
    83 // TViewContactTextFieldData::SetTextL
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 void TViewContactTextFieldData::SetTextL(const TDesC& /* aText */)
       
    87     {
       
    88     /// Do nothing
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // TViewContactTextFieldData::MaxLength
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 TInt TViewContactTextFieldData::MaxLength() const
       
    96     {
       
    97     return KVPbkUnlimitedFieldLength;
       
    98     }
       
    99 
       
   100 // --------------------------------------------------------------------------
       
   101 // TViewContactField::TViewContactField
       
   102 // --------------------------------------------------------------------------
       
   103 //
       
   104 TViewContactField::TViewContactField( CViewContact& aParentContact, 
       
   105     const TDesC& aFieldData, const MVPbkFieldType& aFieldType, 
       
   106     TInt aFieldIndex ) 
       
   107     :   iParentContact(aParentContact),
       
   108         iFieldData(aFieldData),
       
   109         iFieldType(&aFieldType),
       
   110         iFieldIndex(aFieldIndex)
       
   111     {
       
   112     }
       
   113     
       
   114 // --------------------------------------------------------------------------
       
   115 // TViewContactField::TViewContactField
       
   116 // --------------------------------------------------------------------------
       
   117 //
       
   118 inline void TViewContactField::SetFieldData(const TDesC& aFieldData)
       
   119     {
       
   120     iFieldData.SetTextData(aFieldData);
       
   121     }
       
   122 
       
   123 // --------------------------------------------------------------------------
       
   124 // TViewContactField::ParentContact
       
   125 // --------------------------------------------------------------------------
       
   126 //
       
   127 MVPbkBaseContact& TViewContactField::ParentContact() const
       
   128     {
       
   129     return iParentContact;
       
   130     }
       
   131 
       
   132 // --------------------------------------------------------------------------
       
   133 // TViewContactField::MatchFieldType
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 const MVPbkFieldType* TViewContactField::MatchFieldType(TInt /* aMatchPriority */) const
       
   137     {
       
   138     return iFieldType;
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // TViewContactField::BestMatchingFieldType
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 const MVPbkFieldType* TViewContactField::BestMatchingFieldType() const
       
   146     {
       
   147     return iFieldType;
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // TViewContactField::FieldData
       
   152 // --------------------------------------------------------------------------
       
   153 //
       
   154 const MVPbkContactFieldData& TViewContactField::FieldData() const
       
   155     {
       
   156     return iFieldData;
       
   157     }
       
   158 
       
   159 // --------------------------------------------------------------------------
       
   160 // TViewContactField::IsSame
       
   161 // --------------------------------------------------------------------------
       
   162 //
       
   163 TBool TViewContactField::IsSame( const MVPbkBaseContactField& aOther ) const
       
   164     {
       
   165     // View contact fields don't have unique
       
   166     // id. Fields are same if the parent view contact is same instance
       
   167     // and field indexes are the same
       
   168     if (&aOther.ParentContact() == &iParentContact)
       
   169         {
       
   170         return iFieldIndex == 
       
   171             static_cast<const TViewContactField&>( aOther ).iFieldIndex;
       
   172         }
       
   173 
       
   174     return EFalse;
       
   175     }
       
   176 
       
   177 // --------------------------------------------------------------------------
       
   178 // CViewContactFieldCollection::CViewContactFieldCollection
       
   179 // --------------------------------------------------------------------------
       
   180 //
       
   181 CViewContactFieldCollection::CViewContactFieldCollection
       
   182         (CViewContact& aParentContact) :
       
   183     iParentContact(aParentContact)
       
   184     {
       
   185     }
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // CViewContactFieldCollection::CViewContactFieldCollection
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 CViewContactFieldCollection::~CViewContactFieldCollection()
       
   192     {
       
   193     iFields.Close();
       
   194     }
       
   195 
       
   196 // --------------------------------------------------------------------------
       
   197 // CViewContactFieldCollection::SetFieldsData
       
   198 // --------------------------------------------------------------------------
       
   199 //
       
   200 void CViewContactFieldCollection::SetFieldsData(
       
   201         const ::CViewContact& aViewContact )
       
   202     {
       
   203     const TInt count = aViewContact.FieldCount()<iFields.Count()?
       
   204         aViewContact.FieldCount():iFields.Count();
       
   205     for (TInt i = 0; i < count; ++i)
       
   206         {
       
   207         iFields[i].SetFieldData(aViewContact.Field(i));
       
   208         }
       
   209     }
       
   210 
       
   211 // --------------------------------------------------------------------------
       
   212 // CViewContactFieldCollection::SetTypeListL
       
   213 // --------------------------------------------------------------------------
       
   214 //
       
   215 void CViewContactFieldCollection::SetTypeListL(
       
   216         const MVPbkFieldTypeList& aFieldTypes )
       
   217     {
       
   218     iFields.Reset();
       
   219     const TInt count = aFieldTypes.FieldTypeCount();
       
   220     for (TInt i = 0; i < count; ++i)
       
   221         {
       
   222         User::LeaveIfError(iFields.Append(TViewContactField(iParentContact, 
       
   223                 KNullDesC, aFieldTypes.FieldTypeAt(i), iFields.Count() )));
       
   224         }
       
   225     }
       
   226 
       
   227 // --------------------------------------------------------------------------
       
   228 // CViewContactFieldCollection::ParentContact
       
   229 // --------------------------------------------------------------------------
       
   230 //
       
   231 MVPbkBaseContact& CViewContactFieldCollection::ParentContact() const
       
   232     {
       
   233     return iParentContact;
       
   234     }
       
   235 
       
   236 // --------------------------------------------------------------------------
       
   237 // CViewContactFieldCollection::FieldCount
       
   238 // --------------------------------------------------------------------------
       
   239 //
       
   240 TInt CViewContactFieldCollection::FieldCount() const
       
   241     {
       
   242     return iFields.Count();
       
   243     }
       
   244 
       
   245 // --------------------------------------------------------------------------
       
   246 // CViewContactFieldCollection::FieldAt
       
   247 // --------------------------------------------------------------------------
       
   248 //
       
   249 const MVPbkBaseContactField& CViewContactFieldCollection::FieldAt(TInt aIndex) const
       
   250     {
       
   251     return iFields[aIndex];
       
   252     }
       
   253 
       
   254 // --------------------------------------------------------------------------
       
   255 // CViewContact::CViewContact
       
   256 // --------------------------------------------------------------------------
       
   257 //
       
   258 #pragma warning(push)
       
   259 #pragma warning(disable : 4355) // this used in base member initializer list
       
   260 CViewContact::CViewContact(CViewBase& aParentView) :
       
   261     iParentView(aParentView),
       
   262     iViewContact(NULL),
       
   263     iFieldCollection(*this)
       
   264     {
       
   265     }
       
   266 #pragma warning(pop)
       
   267 
       
   268 // --------------------------------------------------------------------------
       
   269 // CViewContact::NewL
       
   270 // --------------------------------------------------------------------------
       
   271 //
       
   272 CViewContact* CViewContact::NewL
       
   273         (CViewBase& aParentView, const MVPbkFieldTypeList& aFieldTypes)
       
   274     {
       
   275     CViewContact* self = new(ELeave) CViewContact(aParentView);
       
   276     CleanupStack::PushL(self);
       
   277     self->SetTypeListL(aFieldTypes);
       
   278     CleanupStack::Pop(self);
       
   279     return self;
       
   280     }
       
   281 
       
   282 // --------------------------------------------------------------------------
       
   283 // CViewContact::SetTypeListL
       
   284 // --------------------------------------------------------------------------
       
   285 //
       
   286 void CViewContact::SetTypeListL(const MVPbkFieldTypeList& aFieldTypes)
       
   287     {
       
   288     iFieldCollection.SetTypeListL(aFieldTypes);
       
   289     }
       
   290 
       
   291 // --------------------------------------------------------------------------
       
   292 // CViewContact::SetViewContact
       
   293 // --------------------------------------------------------------------------
       
   294 //
       
   295 void CViewContact::SetViewContact(const ::CViewContact& aViewContact)
       
   296     {
       
   297     iViewContact = &aViewContact;
       
   298     iFieldCollection.SetFieldsData(aViewContact);
       
   299     }
       
   300 
       
   301 // --------------------------------------------------------------------------
       
   302 // CViewContact::View
       
   303 // --------------------------------------------------------------------------
       
   304 //
       
   305 CViewBase& CViewContact::View() const
       
   306     {
       
   307     return iParentView;
       
   308     }
       
   309 
       
   310 // --------------------------------------------------------------------------
       
   311 // CViewContact::Id
       
   312 // --------------------------------------------------------------------------
       
   313 //
       
   314 TContactItemId CViewContact::Id() const
       
   315     {
       
   316     return iViewContact->Id();
       
   317     }
       
   318 
       
   319 // --------------------------------------------------------------------------
       
   320 // CViewContact::NativeContact
       
   321 // --------------------------------------------------------------------------
       
   322 //
       
   323 const ::CViewContact* CViewContact::NativeContact() const
       
   324     {
       
   325     return iViewContact;
       
   326     }
       
   327 
       
   328 // --------------------------------------------------------------------------
       
   329 // CViewContact::Fields
       
   330 // --------------------------------------------------------------------------
       
   331 //
       
   332 const MVPbkBaseContactFieldCollection& CViewContact::Fields() const
       
   333     {
       
   334     return iFieldCollection;
       
   335     }
       
   336 
       
   337 // --------------------------------------------------------------------------
       
   338 // CViewContact::IsSame
       
   339 // --------------------------------------------------------------------------
       
   340 //
       
   341 TBool CViewContact::IsSame(const MVPbkStoreContact& aOtherContact) const
       
   342     {
       
   343     if (iViewContact && &iParentView.ContactStore()
       
   344             == &aOtherContact.ContactStore())
       
   345         {
       
   346         return (iViewContact->Id() == 
       
   347             static_cast<const CContact&>(aOtherContact).
       
   348                 NativeContact()->Id());
       
   349         }
       
   350     return EFalse;
       
   351     }
       
   352 
       
   353 // --------------------------------------------------------------------------
       
   354 // CViewContact::IsSame
       
   355 // --------------------------------------------------------------------------
       
   356 //
       
   357 TBool CViewContact::IsSame(const MVPbkViewContact& aOtherContact) const
       
   358     {
       
   359     return aOtherContact.IsSame(*this, &iParentView.ContactStore());
       
   360     }
       
   361 
       
   362 // --------------------------------------------------------------------------
       
   363 // CViewContact::CreateLinkLC
       
   364 // --------------------------------------------------------------------------
       
   365 //
       
   366 MVPbkContactLink* CViewContact::CreateLinkLC() const
       
   367     {
       
   368     return iParentView.Store().CreateLinkLC(iViewContact->Id());
       
   369     }
       
   370 
       
   371 // --------------------------------------------------------------------------
       
   372 // CViewContact::ReadL
       
   373 // --------------------------------------------------------------------------
       
   374 //
       
   375 void CViewContact::ReadL(MVPbkContactObserver& aObserver) const
       
   376     {
       
   377     iParentView.Store().ReadContactL(iViewContact->Id(), aObserver);
       
   378     }
       
   379 
       
   380 // --------------------------------------------------------------------------
       
   381 // CViewContact::ReadAndLockL
       
   382 // --------------------------------------------------------------------------
       
   383 //
       
   384 void CViewContact::ReadAndLockL(MVPbkContactObserver& aObserver) const
       
   385     {
       
   386     iParentView.Store().ReadAndLockContactL(iViewContact->Id(), aObserver);
       
   387     }
       
   388 
       
   389 // --------------------------------------------------------------------------
       
   390 // CViewContact::Expandable
       
   391 // --------------------------------------------------------------------------
       
   392 //
       
   393 MVPbkExpandable* CViewContact::Expandable() const
       
   394     {
       
   395     MVPbkExpandable* result = NULL;
       
   396     
       
   397     if (iViewContact->ContactType() == ::CViewContact::EGroup)
       
   398         {
       
   399         result = const_cast<CViewContact*>(this);
       
   400         }
       
   401         
       
   402     return result;
       
   403     }
       
   404 
       
   405 // --------------------------------------------------------------------------
       
   406 // CViewContact::DeleteL
       
   407 // --------------------------------------------------------------------------
       
   408 //
       
   409 void CViewContact::DeleteL(MVPbkContactObserver& aObserver) const
       
   410     {
       
   411     iParentView.Store().DeleteContactL(iViewContact->Id(), aObserver);
       
   412     }
       
   413 
       
   414 // --------------------------------------------------------------------------
       
   415 // CViewContact::MatchContactStore
       
   416 // --------------------------------------------------------------------------
       
   417 //
       
   418 TBool CViewContact::MatchContactStore(const TDesC& aContactStoreUri) const
       
   419     {
       
   420     return iParentView.MatchContactStore(aContactStoreUri);
       
   421     }
       
   422     
       
   423 // --------------------------------------------------------------------------
       
   424 // CViewContact::MatchContactStoreDomain
       
   425 // --------------------------------------------------------------------------
       
   426 //
       
   427 TBool CViewContact::MatchContactStoreDomain
       
   428         (const TDesC& aContactStoreDomain) const
       
   429     {
       
   430     return iParentView.MatchContactStoreDomain(aContactStoreDomain);
       
   431     }
       
   432 
       
   433 // --------------------------------------------------------------------------
       
   434 // CViewContact::CreateBookmarkLC
       
   435 // --------------------------------------------------------------------------
       
   436 //
       
   437 MVPbkContactBookmark* CViewContact::CreateBookmarkLC() const
       
   438     {
       
   439     return iParentView.Store().CreateBookmarkLC(iViewContact->Id());
       
   440     }
       
   441 
       
   442 // --------------------------------------------------------------------------
       
   443 // CViewContact::ParentView
       
   444 // --------------------------------------------------------------------------
       
   445 //
       
   446 MVPbkContactViewBase& CViewContact::ParentView() const
       
   447     {
       
   448     return iParentView;
       
   449     }
       
   450 
       
   451 // --------------------------------------------------------------------------
       
   452 // CViewContact::IsSame
       
   453 // --------------------------------------------------------------------------
       
   454 //
       
   455 TBool CViewContact::IsSame(
       
   456         const MVPbkViewContact& aOtherContact, 
       
   457         const MVPbkContactStore* aContactStore) const
       
   458     {
       
   459     if (iViewContact && &iParentView.ContactStore() == aContactStore)
       
   460         {
       
   461         return (iViewContact->Id() ==
       
   462             static_cast<const CViewContact&>(aOtherContact).Id());
       
   463         }
       
   464     return EFalse;
       
   465     }
       
   466 
       
   467 // --------------------------------------------------------------------------
       
   468 // CViewContact::IsSame
       
   469 // --------------------------------------------------------------------------
       
   470 //
       
   471 TBool CViewContact::IsSame(
       
   472         const MVPbkStoreContact& aOtherContact, 
       
   473         const MVPbkContactStore* aContactStore) const
       
   474     {
       
   475     if (iViewContact && &iParentView.ContactStore() == aContactStore)
       
   476         {
       
   477         return (iViewContact->Id() == 
       
   478             static_cast<const CContact&>(aOtherContact).
       
   479                 NativeContact()->Id());
       
   480         }
       
   481     return EFalse;
       
   482     }
       
   483 
       
   484 // --------------------------------------------------------------------------
       
   485 // CViewContact::ExpandLC
       
   486 // --------------------------------------------------------------------------
       
   487 //
       
   488 MVPbkContactViewBase* CViewContact::ExpandLC(
       
   489         MVPbkContactViewObserver& aObserver,
       
   490         const MVPbkFieldTypeList& aSortOrder) const
       
   491     {
       
   492     return CGroupMembersView::NewLC(iParentView.Store(),
       
   493         iViewContact->Id(), aObserver, aSortOrder);
       
   494     }
       
   495 
       
   496 // --------------------------------------------------------------------------
       
   497 // CViewContact::BaseContactExtension
       
   498 // --------------------------------------------------------------------------
       
   499 //
       
   500 TAny* CViewContact::BaseContactExtension( TUid aExtensionUid )
       
   501     {
       
   502     if( aExtensionUid == KVPbkBaseContactExtension2Uid )
       
   503         return static_cast<MVPbkBaseContact2*>( this );
       
   504     return NULL;
       
   505     }
       
   506 
       
   507 // --------------------------------------------------------------------------
       
   508 // CViewContact::IsOwnContact
       
   509 // --------------------------------------------------------------------------
       
   510 //
       
   511 TBool CViewContact::IsOwnContact( TInt& aError ) const
       
   512     {
       
   513     aError = KErrNone;
       
   514     return ( iViewContact->ContactTypeUid() == KUidContactOwnCard );
       
   515     }
       
   516 
       
   517 } // namespace VPbkCntModel
       
   518 
       
   519 // End of File