phonebookui/Phonebook2/CommonUI/src/CPbk2ViewState.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Phonebook 2 view state.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <CPbk2ViewState.h>
       
    21 
       
    22 // Phonebook 2
       
    23 #include <Pbk2UID.h>
       
    24 #include <MPbk2ApplicationServices.h>
       
    25 #include <MPbk2AppUi.h>
       
    26 
       
    27 // Virtual Phonebook
       
    28 #include <MVPbkContactLink.h>
       
    29 #include <CVPbkContactManager.h>
       
    30 
       
    31 // System includes
       
    32 #include <s32mem.h>
       
    33 
       
    34 
       
    35 const TUid CPbk2ViewState::KUid = { KPbk2ViewStateUid };
       
    36 
       
    37 /// Unnamed namespace for local definitions
       
    38 namespace {
       
    39 
       
    40 const TUint8 KPbk2ViewStateVersionNumber = 1;
       
    41 
       
    42 /**
       
    43  * Stream buffer which counts number of bytes written to it.
       
    44  */
       
    45 class TCalcLengthStreamBuf : public MStreamBuf
       
    46     {
       
    47     public: // Construction
       
    48 
       
    49         /**
       
    50          * Constructor.
       
    51          */
       
    52         inline TCalcLengthStreamBuf() :
       
    53                 iBytesWritten( 0 )
       
    54             {
       
    55             }
       
    56 
       
    57         /**
       
    58          * Returns the number of bytes written.
       
    59          *
       
    60          * @return  Number of bytes written.
       
    61          */
       
    62         inline TInt BytesWritten() const
       
    63             {
       
    64             return iBytesWritten;
       
    65             }
       
    66 
       
    67     private: // From MStreamBuf
       
    68 
       
    69         void DoWriteL( const TAny* /*aPtr*/, TInt aLength )
       
    70             {
       
    71             // Just count the bytes
       
    72             iBytesWritten += aLength;
       
    73             }
       
    74 
       
    75     private: // Data
       
    76         /// Ref: Count of bytes written to this streambuf
       
    77         TInt iBytesWritten;
       
    78     };
       
    79 
       
    80 enum TPanicCode
       
    81     {
       
    82     EPanicInvalidVersion = 1,
       
    83     EPanicInvalidDataType,
       
    84     EPanicInvalidMarkedContactCount
       
    85     };
       
    86 
       
    87 void Panic(TPanicCode aReason)
       
    88     {
       
    89     _LIT(KPanicText, "CPbk2ViewState");
       
    90     User::Panic(KPanicText, aReason);
       
    91     }
       
    92 
       
    93 } /// namespace
       
    94 
       
    95 
       
    96 // --------------------------------------------------------------------------
       
    97 // CPbk2ViewState::CPbk2ViewState
       
    98 // --------------------------------------------------------------------------
       
    99 //
       
   100 CPbk2ViewState::CPbk2ViewState() :
       
   101         iFocusedFieldIndex( KErrNotFound ),
       
   102         iTopFieldIndex( KErrNotFound ),
       
   103         iFocusedPropertiesIndex( KErrNotFound ),
       
   104         iTopPropertiesIndex( KErrNotFound )
       
   105     {
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CPbk2ViewState::~CPbk2ViewState
       
   110 // --------------------------------------------------------------------------
       
   111 //
       
   112 CPbk2ViewState::~CPbk2ViewState()
       
   113     {
       
   114     delete iFocusedContact;
       
   115     delete iTopContact;
       
   116     delete iParentContact;
       
   117     delete iArray;
       
   118     }
       
   119 
       
   120 // --------------------------------------------------------------------------
       
   121 // CPbk2ViewState::NewL
       
   122 // --------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C CPbk2ViewState* CPbk2ViewState::NewL()
       
   125     {
       
   126     CPbk2ViewState* self = new ( ELeave ) CPbk2ViewState;
       
   127     return self;
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CPbk2ViewState::NewLC
       
   132 // --------------------------------------------------------------------------
       
   133 //
       
   134 EXPORT_C CPbk2ViewState* CPbk2ViewState::NewLC()
       
   135     {
       
   136     CPbk2ViewState* self = new ( ELeave ) CPbk2ViewState;
       
   137     CleanupStack::PushL( self );
       
   138     return self;
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CPbk2ViewState::NewL
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C CPbk2ViewState* CPbk2ViewState::NewL( const TDesC8& aBuf )
       
   146     {
       
   147     CPbk2ViewState* self = CPbk2ViewState::NewLC( aBuf );
       
   148     CleanupStack::Pop( self );
       
   149     return self;
       
   150     }
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // CPbk2ViewState::NewLC
       
   154 // --------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C CPbk2ViewState* CPbk2ViewState::NewLC( const TDesC8& aBuf )
       
   157     {
       
   158     CPbk2ViewState* self = new ( ELeave ) CPbk2ViewState;
       
   159     CleanupStack::PushL( self );
       
   160     self->ConstructL( aBuf );
       
   161     return self;
       
   162     }
       
   163 
       
   164 // --------------------------------------------------------------------------
       
   165 // CPbk2ViewState::ConstructL
       
   166 // --------------------------------------------------------------------------
       
   167 //
       
   168 inline void CPbk2ViewState::ConstructL( const TDesC8& aBuf )
       
   169     {
       
   170     UnpackL( aBuf );
       
   171     }
       
   172 
       
   173 // --------------------------------------------------------------------------
       
   174 // CPbk2ViewState::Uid
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C TUid CPbk2ViewState::Uid()
       
   178     {
       
   179     return KUid;
       
   180     }
       
   181 
       
   182 // --------------------------------------------------------------------------
       
   183 // CPbk2ViewState::FocusedContact
       
   184 // --------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C const MVPbkContactLink* CPbk2ViewState::FocusedContact() const
       
   187     {
       
   188     return iFocusedContact;
       
   189     }
       
   190 
       
   191 // --------------------------------------------------------------------------
       
   192 // CPbk2ViewState::TakeFocusedContact
       
   193 // --------------------------------------------------------------------------
       
   194 //
       
   195 EXPORT_C MVPbkContactLink* CPbk2ViewState::TakeFocusedContact()
       
   196     {
       
   197     MVPbkContactLink* result = iFocusedContact;
       
   198     iFocusedContact = NULL;
       
   199     return result;
       
   200     }
       
   201 
       
   202 // --------------------------------------------------------------------------
       
   203 // CPbk2ViewState::TopContact
       
   204 // --------------------------------------------------------------------------
       
   205 //
       
   206 EXPORT_C const MVPbkContactLink* CPbk2ViewState::TopContact() const
       
   207     {
       
   208     return iTopContact;
       
   209     }
       
   210 
       
   211 // --------------------------------------------------------------------------
       
   212 // CPbk2ViewState::TakeTopContact
       
   213 // --------------------------------------------------------------------------
       
   214 //
       
   215 EXPORT_C MVPbkContactLink* CPbk2ViewState::TakeTopContact()
       
   216     {
       
   217     MVPbkContactLink* result = iTopContact;
       
   218     iTopContact = NULL;
       
   219     return result;
       
   220     }
       
   221 
       
   222 // --------------------------------------------------------------------------
       
   223 // CPbk2ViewState::ParentContact
       
   224 // --------------------------------------------------------------------------
       
   225 //
       
   226 EXPORT_C const MVPbkContactLink* CPbk2ViewState::ParentContact() const
       
   227     {
       
   228     return iParentContact;
       
   229     }
       
   230 
       
   231 // --------------------------------------------------------------------------
       
   232 // CPbk2ViewState::TakeParentContact
       
   233 // --------------------------------------------------------------------------
       
   234 //
       
   235 EXPORT_C MVPbkContactLink* CPbk2ViewState::TakeParentContact()
       
   236     {
       
   237     MVPbkContactLink* result = iParentContact;
       
   238     iParentContact = NULL;
       
   239     return result;
       
   240     }
       
   241 
       
   242 // --------------------------------------------------------------------------
       
   243 // CPbk2ViewState::MarkedContacts
       
   244 // --------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C const MVPbkContactLinkArray* CPbk2ViewState::MarkedContacts() const
       
   247     {
       
   248     return iArray;
       
   249     }
       
   250 
       
   251 // --------------------------------------------------------------------------
       
   252 // CPbk2ViewState::TakeMarkedContacts
       
   253 // --------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C MVPbkContactLinkArray* CPbk2ViewState::TakeMarkedContacts()
       
   256     {
       
   257     MVPbkContactLinkArray* result = iArray;
       
   258     iArray = NULL;
       
   259     return result;
       
   260     }
       
   261 
       
   262 // --------------------------------------------------------------------------
       
   263 // CPbk2ViewState::FocusedFieldIndex
       
   264 // --------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C TInt CPbk2ViewState::FocusedFieldIndex() const
       
   267     {
       
   268     return iFocusedFieldIndex;
       
   269     }
       
   270 
       
   271 // --------------------------------------------------------------------------
       
   272 // CPbk2ViewState::TopFieldIndex
       
   273 // --------------------------------------------------------------------------
       
   274 //
       
   275 EXPORT_C TInt CPbk2ViewState::TopFieldIndex() const
       
   276     {
       
   277     return iTopFieldIndex;
       
   278     }
       
   279 
       
   280 // --------------------------------------------------------------------------
       
   281 // CPbk2ViewState::FocusedPropertiesIndex
       
   282 // --------------------------------------------------------------------------
       
   283 //
       
   284 EXPORT_C TInt CPbk2ViewState::FocusedPropertiesIndex() const
       
   285     {
       
   286     return iFocusedPropertiesIndex;
       
   287     }
       
   288 
       
   289 // --------------------------------------------------------------------------
       
   290 // CPbk2ViewState::TopPropertiesIndex
       
   291 // --------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C TInt CPbk2ViewState::TopPropertiesIndex() const
       
   294     {
       
   295     return iTopPropertiesIndex;
       
   296     }
       
   297 
       
   298 // --------------------------------------------------------------------------
       
   299 // CPbk2ViewState::Flags
       
   300 // --------------------------------------------------------------------------
       
   301 //
       
   302 EXPORT_C TUint CPbk2ViewState::Flags() const
       
   303     {
       
   304     return iFlags;
       
   305     }
       
   306 
       
   307 // --------------------------------------------------------------------------
       
   308 // CPbk2ViewState::SetFocusedContact
       
   309 // --------------------------------------------------------------------------
       
   310 //
       
   311 EXPORT_C void CPbk2ViewState::SetFocusedContact
       
   312         ( MVPbkContactLink* aContact )
       
   313     {
       
   314     delete iFocusedContact;
       
   315     iFocusedContact = aContact;
       
   316     }
       
   317 
       
   318 // --------------------------------------------------------------------------
       
   319 // CPbk2ViewState::SetTopContact
       
   320 // --------------------------------------------------------------------------
       
   321 //
       
   322 EXPORT_C void CPbk2ViewState::SetTopContact( MVPbkContactLink* aTopContact )
       
   323     {
       
   324     delete iTopContact;
       
   325     iTopContact = aTopContact;
       
   326     }
       
   327 
       
   328 // --------------------------------------------------------------------------
       
   329 // CPbk2ViewState::SetParentContact
       
   330 // --------------------------------------------------------------------------
       
   331 //
       
   332 EXPORT_C void CPbk2ViewState::SetParentContact
       
   333         ( MVPbkContactLink* aParentContact )
       
   334     {
       
   335     delete iParentContact;
       
   336     iParentContact = aParentContact;
       
   337     }
       
   338 
       
   339 
       
   340 // --------------------------------------------------------------------------
       
   341 // CPbk2ViewState::SetMarkedContacts
       
   342 // --------------------------------------------------------------------------
       
   343 //
       
   344 EXPORT_C void CPbk2ViewState::SetMarkedContacts
       
   345         ( MVPbkContactLinkArray* aArray )
       
   346     {
       
   347     delete iArray;
       
   348     iArray = aArray;
       
   349     }
       
   350 
       
   351 // --------------------------------------------------------------------------
       
   352 // CPbk2ViewState::SetFocusedFieldIndex
       
   353 // --------------------------------------------------------------------------
       
   354 //
       
   355 EXPORT_C void CPbk2ViewState::SetFocusedFieldIndex( TInt aIndex )
       
   356     {
       
   357     iFocusedFieldIndex = aIndex;
       
   358     }
       
   359 
       
   360 // --------------------------------------------------------------------------
       
   361 // CPbk2ViewState::SetTopFieldIndex
       
   362 // --------------------------------------------------------------------------
       
   363 //
       
   364 EXPORT_C void CPbk2ViewState::SetTopFieldIndex( TInt aIndex )
       
   365     {
       
   366     iTopFieldIndex = aIndex;
       
   367     }
       
   368 
       
   369 // --------------------------------------------------------------------------
       
   370 // CPbk2ViewState::SetFocusedPropertiesIndex
       
   371 // --------------------------------------------------------------------------
       
   372 //
       
   373 EXPORT_C void CPbk2ViewState::SetFocusedPropertiesIndex( TInt aIndex )
       
   374     {
       
   375     iFocusedPropertiesIndex = aIndex;
       
   376     }
       
   377 
       
   378 // --------------------------------------------------------------------------
       
   379 // CPbk2ViewState::SetTopPropertiesIndex
       
   380 // --------------------------------------------------------------------------
       
   381 //
       
   382 EXPORT_C void CPbk2ViewState::SetTopPropertiesIndex( TInt aIndex )
       
   383     {
       
   384     iTopPropertiesIndex = aIndex;
       
   385     }
       
   386 
       
   387 // --------------------------------------------------------------------------
       
   388 // CPbk2ViewState::Reset
       
   389 // --------------------------------------------------------------------------
       
   390 //
       
   391 EXPORT_C void CPbk2ViewState::Reset()
       
   392     {
       
   393     iFocusedFieldIndex = KErrNotFound;
       
   394     iTopFieldIndex = KErrNotFound;
       
   395     iFocusedPropertiesIndex = KErrNotFound;
       
   396     iTopPropertiesIndex = KErrNotFound;
       
   397     delete iFocusedContact;
       
   398     iFocusedContact = NULL;
       
   399     delete iTopContact;
       
   400     iTopContact = NULL;
       
   401     delete iArray;
       
   402     iArray = NULL;
       
   403     iFlags = 0;
       
   404     }
       
   405 
       
   406 // --------------------------------------------------------------------------
       
   407 // CPbk2ViewState::SetFlags
       
   408 // --------------------------------------------------------------------------
       
   409 //
       
   410 EXPORT_C void CPbk2ViewState::SetFlags( TUint aFlags )
       
   411     {
       
   412     iFlags = aFlags;
       
   413     }
       
   414 
       
   415 // --------------------------------------------------------------------------
       
   416 // CPbk2ViewState::PackL
       
   417 // --------------------------------------------------------------------------
       
   418 //
       
   419 EXPORT_C HBufC8* CPbk2ViewState::PackL() const
       
   420     {
       
   421     HBufC8* buf = PackLC();
       
   422     CleanupStack::Pop(); // buf
       
   423     return buf;
       
   424     }
       
   425 
       
   426 // --------------------------------------------------------------------------
       
   427 // CPbk2ViewState::PackLC
       
   428 // --------------------------------------------------------------------------
       
   429 //
       
   430 EXPORT_C HBufC8* CPbk2ViewState::PackLC() const
       
   431     {
       
   432     // Calculate needed buffer size using TCalcLengthStreamBuf
       
   433     TCalcLengthStreamBuf countBuf;     
       
   434     RWriteStream countStream( &countBuf );
       
   435     // This can't leave because we are using TCalcLengthStreamBuf
       
   436     ExternalizeL( countStream );
       
   437 
       
   438     // Allocate a buffer and a stream
       
   439     HBufC8* buf = HBufC8::NewLC( countBuf.BytesWritten() );
       
   440     TPtr8 bufPtr = buf->Des();
       
   441     RDesWriteStream stream( bufPtr );
       
   442     stream.PushL();
       
   443 
       
   444     // Write this object to buf through stream
       
   445     ExternalizeL( stream );
       
   446 
       
   447     stream.CommitL();
       
   448     CleanupStack::PopAndDestroy(); // stream
       
   449     return buf;
       
   450     }
       
   451 
       
   452 // --------------------------------------------------------------------------
       
   453 // CPbk2ViewState::UnpackL
       
   454 // --------------------------------------------------------------------------
       
   455 //
       
   456 EXPORT_C void CPbk2ViewState::UnpackL( const TDesC8& aPack )
       
   457     {
       
   458     RDesReadStream stream( aPack );
       
   459     stream.PushL();
       
   460     InternalizeL( stream );
       
   461     CleanupStack::PopAndDestroy(); // stream
       
   462     }
       
   463 
       
   464 
       
   465 // --------------------------------------------------------------------------
       
   466 // CPbk2ViewState::operator==
       
   467 // --------------------------------------------------------------------------
       
   468 //
       
   469 EXPORT_C TBool CPbk2ViewState::operator==( const CPbk2ViewState& aRhs ) const
       
   470     {
       
   471     return iFocusedFieldIndex == aRhs.iFocusedFieldIndex &&
       
   472            iTopFieldIndex == aRhs.iTopFieldIndex &&
       
   473            iFocusedPropertiesIndex == aRhs.iFocusedPropertiesIndex &&
       
   474            iTopPropertiesIndex == aRhs.iTopPropertiesIndex;
       
   475     }
       
   476 
       
   477 // --------------------------------------------------------------------------
       
   478 // CPbk2ViewState::ExternalizeL
       
   479 // --------------------------------------------------------------------------
       
   480 //
       
   481 void CPbk2ViewState::ExternalizeL( RWriteStream& aStream ) const
       
   482     {
       
   483     aStream.WriteUint8L( KPbk2ViewStateVersionNumber );
       
   484 
       
   485     if (iFocusedContact)
       
   486         {
       
   487         aStream.WriteInt8L(EFocusedContact);
       
   488         HBufC8* buf = iFocusedContact->PackLC();
       
   489         aStream.WriteUint16L(buf->Length());
       
   490         aStream.WriteL(*buf);
       
   491         CleanupStack::PopAndDestroy(); // buf
       
   492         }
       
   493 
       
   494     if (iTopContact)
       
   495         {
       
   496         aStream.WriteInt8L(ETopContact);
       
   497         HBufC8* buf = iTopContact->PackLC();
       
   498         aStream.WriteUint16L(buf->Length());
       
   499         aStream.WriteL(*buf);
       
   500         CleanupStack::PopAndDestroy(); // buf
       
   501         }
       
   502 
       
   503     if (iParentContact)
       
   504         {
       
   505         aStream.WriteInt8L(EParentContact);
       
   506         HBufC8* buf = iParentContact->PackLC();
       
   507         aStream.WriteUint16L(buf->Length());
       
   508         aStream.WriteL(*buf);
       
   509         CleanupStack::PopAndDestroy(); // buf
       
   510         }
       
   511 
       
   512     if (iArray)
       
   513         {
       
   514         aStream.WriteInt8L(EMarkedContacts);
       
   515         HBufC8* buf = iArray->PackLC();
       
   516         aStream.WriteUint16L(buf->Length());
       
   517         aStream.WriteL(*buf);
       
   518         CleanupStack::PopAndDestroy(); // buf
       
   519         }
       
   520 
       
   521     if (iFocusedFieldIndex >= 0)
       
   522         {
       
   523         aStream.WriteInt8L(EFocusedFieldIndex);
       
   524         aStream.WriteInt32L(iFocusedFieldIndex);
       
   525         }
       
   526 
       
   527     if (iTopFieldIndex >= 0)
       
   528         {
       
   529         aStream.WriteInt8L(ETopFieldIndex);
       
   530         aStream.WriteInt32L(iTopFieldIndex);
       
   531         }
       
   532 
       
   533     if (iFocusedPropertiesIndex >= 0)
       
   534         {
       
   535         aStream.WriteInt8L(EFocusedPropertiesIndex);
       
   536         aStream.WriteInt32L(iFocusedPropertiesIndex);
       
   537         }
       
   538 
       
   539     if (iTopPropertiesIndex >= 0)
       
   540         {
       
   541         aStream.WriteInt8L(ETopPropertiesIndex);
       
   542         aStream.WriteInt32L(iTopPropertiesIndex);
       
   543         }
       
   544 
       
   545     if (iFlags != ENullFlags)
       
   546         {
       
   547         aStream.WriteInt8L(EFlags);
       
   548         aStream.WriteUint32L(iFlags);
       
   549         }
       
   550     }
       
   551 
       
   552 // --------------------------------------------------------------------------
       
   553 // CPbk2ViewState::InternalizeL
       
   554 // --------------------------------------------------------------------------
       
   555 //
       
   556 void CPbk2ViewState::InternalizeL( RReadStream& aStream )
       
   557     {
       
   558     Reset();
       
   559 
       
   560     const TUint versionNumber = aStream.ReadUint8L();
       
   561     __ASSERT_ALWAYS(versionNumber == KPbk2ViewStateVersionNumber,
       
   562                     Panic(EPanicInvalidVersion));
       
   563 
       
   564     CVPbkContactManager* contactManager =
       
   565         &Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager();
       
   566 
       
   567     TBool eof = EFalse;
       
   568     while (!eof)
       
   569         {
       
   570         TInt type = EEnd;
       
   571         TRAPD(err, type = aStream.ReadInt8L());
       
   572         switch (err)
       
   573             {
       
   574             case KErrEof:
       
   575                 {
       
   576                 // End of stream, exit loop like EEnd opcode was read
       
   577                 type = EEnd;
       
   578                 break;
       
   579                 }
       
   580             case KErrNone:
       
   581                 {
       
   582                 break;
       
   583                 }
       
   584             default:
       
   585                 {
       
   586                 // Some other error than EOF occured
       
   587                 User::Leave(err);
       
   588                 break;
       
   589                 }
       
   590             }
       
   591 
       
   592         switch (type)
       
   593             {
       
   594             case EFocusedContact:
       
   595                 {
       
   596                 TInt length = aStream.ReadUint16L();
       
   597                 HBufC8* buf = HBufC8::NewLC(length);
       
   598                 TPtr8 bufPtr = buf->Des();
       
   599                 aStream.ReadL(bufPtr, length);
       
   600                 MVPbkContactLinkArray* links =
       
   601                     contactManager->CreateLinksLC( *buf );
       
   602                 if ( links && links->Count() > 0 )
       
   603                     {
       
   604                     iFocusedContact = links->At(0).CloneLC();
       
   605                     CleanupStack::Pop();
       
   606                     }
       
   607                 CleanupStack::PopAndDestroy(2); // links, buf
       
   608                 break;
       
   609                 }
       
   610 
       
   611             case ETopContact:
       
   612                 {
       
   613                 TInt length = aStream.ReadUint16L();
       
   614                 HBufC8* buf = HBufC8::NewLC(length);
       
   615                 TPtr8 bufPtr = buf->Des();
       
   616                 aStream.ReadL(bufPtr, length);
       
   617                 MVPbkContactLinkArray* links =
       
   618                     contactManager->CreateLinksLC( *buf );
       
   619                 if ( links && links->Count() > 0 )
       
   620                     {
       
   621                     iTopContact = links->At(0).CloneLC();
       
   622                     CleanupStack::Pop();
       
   623                     }
       
   624                 CleanupStack::PopAndDestroy(2); // links, buf
       
   625                 break;
       
   626                 }
       
   627 
       
   628             case EParentContact:
       
   629                 {
       
   630                 TInt length = aStream.ReadUint16L();
       
   631                 HBufC8* buf = HBufC8::NewLC(length);
       
   632                 TPtr8 bufPtr = buf->Des();
       
   633                 aStream.ReadL(bufPtr, length);
       
   634                 MVPbkContactLinkArray* links =
       
   635                     contactManager->CreateLinksLC( *buf );
       
   636                 if ( links && links->Count() > 0 )
       
   637                     {
       
   638                     iParentContact = links->At(0).CloneLC();
       
   639                     CleanupStack::Pop();
       
   640                     }
       
   641                 CleanupStack::PopAndDestroy(2); // links, buf
       
   642                 break;
       
   643                 }
       
   644 
       
   645             case EMarkedContacts:
       
   646                 {
       
   647                 TInt length = aStream.ReadUint16L();
       
   648                 HBufC8* buf = HBufC8::NewLC(length);
       
   649                 TPtr8 bufPtr = buf->Des();
       
   650                 aStream.ReadL(bufPtr, length);
       
   651                 iArray = contactManager->CreateLinksLC( *buf );
       
   652                 CleanupStack::Pop();
       
   653                 CleanupStack::PopAndDestroy(); // buf
       
   654                 break;
       
   655                 }
       
   656 
       
   657             case EFocusedFieldIndex:
       
   658                 {
       
   659                 iFocusedFieldIndex = aStream.ReadInt32L();
       
   660                 break;
       
   661                 }
       
   662 
       
   663             case ETopFieldIndex:
       
   664                 {
       
   665                 iTopFieldIndex = aStream.ReadInt32L();
       
   666                 break;
       
   667                 }
       
   668             
       
   669             case EFocusedPropertiesIndex:
       
   670                 {
       
   671                 iFocusedPropertiesIndex = aStream.ReadInt32L();
       
   672                 break;
       
   673                 }
       
   674 
       
   675             case ETopPropertiesIndex:
       
   676                 {
       
   677                 iTopPropertiesIndex = aStream.ReadInt32L();
       
   678                 break;
       
   679                 }
       
   680 
       
   681             case EFlags:
       
   682                 {
       
   683                 iFlags = aStream.ReadUint32L();
       
   684                 break;
       
   685                 }
       
   686 
       
   687             case EEnd:
       
   688                 {
       
   689                 eof = ETrue;
       
   690                 break;
       
   691                 }
       
   692 
       
   693             default:
       
   694                 {
       
   695                 Panic(EPanicInvalidDataType);
       
   696                 break;
       
   697                 }
       
   698             }
       
   699         }
       
   700     }
       
   701 
       
   702 //  End of File