applayerpluginsandutils/bookmarksupport/src/bkmrkattachment.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Internal class for manipulating bookmark extended properties.
       
    15 // @internalComponent
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "bkmrkattachment.h"
       
    20 
       
    21 CBkmrkAttachment* CBkmrkAttachment::NewL(CRepository& aRepository, const TDesC8& aData)
       
    22 	{
       
    23 	CBkmrkAttachment* self = new (ELeave) CBkmrkAttachment();
       
    24 	CleanupStack::PushL(self);
       
    25 	self->ConstructL(aRepository, aData);
       
    26 	CleanupStack::Pop(self);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CBkmrkAttachment::CBkmrkAttachment() 
       
    31 	: CRepositoryAccessor(), iId(Bookmark::KNullAttachmentID)
       
    32 	{
       
    33 	}
       
    34 
       
    35 CBkmrkAttachment::~CBkmrkAttachment()
       
    36 	{
       
    37 	delete iData;
       
    38 	}
       
    39 
       
    40 void CBkmrkAttachment::ConstructL(CRepository& aRepository, const TDesC8& aData)
       
    41 	{
       
    42 	SetRepository(aRepository);
       
    43 	SetDataL(aData);
       
    44 	}
       
    45 
       
    46 Bookmark::TAttachmentId CBkmrkAttachment::Id() const
       
    47 	{
       
    48 	return iId;
       
    49 	}
       
    50 	
       
    51 void CBkmrkAttachment::SetIdL()
       
    52 	{
       
    53 	iId = NextIndexL();
       
    54 	}
       
    55 
       
    56 TInt CBkmrkAttachment::Size() const
       
    57 	{
       
    58 	return iData->Size();
       
    59 	}
       
    60 	
       
    61 const TDesC8& CBkmrkAttachment::Data() const
       
    62 	{
       
    63 	return *iData;
       
    64 	}
       
    65 
       
    66 void CBkmrkAttachment::SetDataL(const TDesC8& aData)
       
    67 	{
       
    68 	// The aData must be smaller that the maximim data storage size
       
    69 	__ASSERT_ALWAYS(aData.Length() <= Bookmark::KMaxDataLength, User::Panic(Bookmark::KBookmarkErrTooLong, KErrArgument));
       
    70 	
       
    71 	delete iData;
       
    72 	iData = NULL;
       
    73 	iData = aData.AllocL();
       
    74 	SetDirty();
       
    75 	}
       
    76 
       
    77 TUint32 CBkmrkAttachment::IndexBase()
       
    78 	{
       
    79 	return (iId << KIconIndexShift);
       
    80 	}
       
    81 	
       
    82 void CBkmrkAttachment::SetIdFromIndexBase(TUint32 aIndexBase)
       
    83 	{
       
    84 	iId = aIndexBase >> KIconIndexShift;
       
    85 	}
       
    86 
       
    87 void CBkmrkAttachment::TransNewL()
       
    88 	{
       
    89 	// create entries in the repository
       
    90 	iRepository->Create(IndexBase() + KIconDataIndex, Data());
       
    91 	}
       
    92 	
       
    93 void CBkmrkAttachment::TransSaveL()
       
    94 	{
       
    95 	iRepository->Set(IndexBase() + KIconDataIndex, Data());
       
    96 	}
       
    97 
       
    98 void CBkmrkAttachment::TransLoadL()
       
    99 	{
       
   100 	HBufC8* dataBuffer = HBufC8::NewLC(Bookmark::KMaxUriLength);
       
   101 	TPtr8 dataPtr = dataBuffer->Des();
       
   102 	User::LeaveIfError(iRepository->Get(IndexBase() + KIconDataIndex, dataPtr));
       
   103 	SetDataL(dataPtr);
       
   104 	CleanupStack::PopAndDestroy(dataBuffer);
       
   105 	SetClean();
       
   106 	}
       
   107 
       
   108 void CBkmrkAttachment::TransRemoveL()
       
   109 	{
       
   110 	iRepository->Delete(IndexBase() + KIconDataIndex);
       
   111 	}
       
   112