|
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 the common bookmark properties. |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include "bkmrkproperties.h" |
|
20 #include "bkmrkbase.h" |
|
21 |
|
22 CBkmrkProperties* CBkmrkProperties::NewL(CBookmarkBase& aParent, CBookmarkDb& aDb, CRepository& aRepository) |
|
23 { |
|
24 CBkmrkProperties* self = new (ELeave) CBkmrkProperties(aParent, aDb, aRepository); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(); |
|
27 CleanupStack::Pop(self); |
|
28 return self; |
|
29 } |
|
30 |
|
31 CBkmrkProperties::CBkmrkProperties(CBookmarkBase& aParent, CBookmarkDb& aDb, CRepository& aRepository) |
|
32 : CRepositoryAccessor(), iParent(aParent), iDatabase(aDb), iIconId(Bookmark::KNullAttachmentID), iUpdateModifiedOnCommit ( ETrue ) |
|
33 { |
|
34 SetRepository(aRepository); |
|
35 } |
|
36 |
|
37 CBkmrkProperties::~CBkmrkProperties() |
|
38 { |
|
39 delete iDescription; |
|
40 delete iCustomProperties; |
|
41 } |
|
42 |
|
43 void CBkmrkProperties::ConstructL() |
|
44 { |
|
45 CPropertyReg::TPropertyGroup type = CPropertyReg::EGroupBookmark; |
|
46 if (iParent.Type() == Bookmark::ETypeFolder) |
|
47 { |
|
48 type = CPropertyReg::EGroupFolder; |
|
49 } |
|
50 iCustomProperties = CPropertyList::NewL(*iRepository, iDatabase.PropertyRegister(), type, IndexBase() + KBkmrkCusPropertyStart); |
|
51 } |
|
52 |
|
53 const TDesC& CBkmrkProperties::Description() const |
|
54 { |
|
55 if (!iDescription) |
|
56 { |
|
57 return KNullDesC; |
|
58 } |
|
59 return *iDescription; |
|
60 } |
|
61 |
|
62 void CBkmrkProperties::SetDescriptionL(const TDesC& aDescription) |
|
63 { |
|
64 // The aDescription must be smaller that the maximim descriptor storage size |
|
65 __ASSERT_ALWAYS(aDescription.Length() <= Bookmark::KMaxDescriptorLength, User::Panic(Bookmark::KBookmarkErrTooLong, KErrArgument)); |
|
66 |
|
67 iParent.LeaveIfNotWritableL(); |
|
68 |
|
69 if (iDescription) |
|
70 { |
|
71 delete iDescription; |
|
72 iDescription = NULL; |
|
73 } |
|
74 iDescription = aDescription.AllocL(); |
|
75 SetDirty(); |
|
76 } |
|
77 |
|
78 Bookmark::TAttachmentId CBkmrkProperties::IconId() const |
|
79 { |
|
80 return iIconId; |
|
81 } |
|
82 |
|
83 void CBkmrkProperties::SetIconIdL(Bookmark::TAttachmentId aIconId) |
|
84 { |
|
85 iParent.LeaveIfNotWritableL(); |
|
86 // ensure the icon exists |
|
87 iDatabase.IconL(aIconId); |
|
88 iIconId = aIconId; |
|
89 SetDirty(); |
|
90 } |
|
91 |
|
92 TUint32 CBkmrkProperties::IndexBase() |
|
93 { |
|
94 return iParent.IndexBase(); |
|
95 } |
|
96 |
|
97 void CBkmrkProperties::SetIdFromIndexBase(TUint32 aIndexBase) |
|
98 { |
|
99 return iParent.SetIdFromIndexBase(aIndexBase); |
|
100 } |
|
101 |
|
102 void CBkmrkProperties::CommitL() |
|
103 { |
|
104 CRepositoryAccessor::CommitL(); |
|
105 iCustomProperties->CommitL(); |
|
106 } |
|
107 |
|
108 void CBkmrkProperties::SetDirty() |
|
109 { |
|
110 CRepositoryAccessor::SetDirty(); |
|
111 iParent.SetDirty(); |
|
112 } |
|
113 |
|
114 void CBkmrkProperties::TransNewL() |
|
115 { |
|
116 SetModified (); |
|
117 |
|
118 TUint32 indexBase = IndexBase(); |
|
119 // create entries in the repository |
|
120 TUint32 timeLo = I64LOW(iLastModified.Int64()); |
|
121 TUint32 timeHi = I64HIGH(iLastModified.Int64()); |
|
122 iRepository->Create(indexBase + KBkmrkLastModifiedLoIndex, static_cast<TInt>(timeLo)); |
|
123 iRepository->Create(indexBase + KBkmrkLastModifiedHiIndex, static_cast<TInt>(timeHi)); |
|
124 iRepository->Create(indexBase + KCmnDescriptionIndex, Description()); |
|
125 iRepository->Create(indexBase + KCmnIconIndex, static_cast<TInt>(iIconId)); |
|
126 iCustomProperties->TransNewL(); |
|
127 } |
|
128 |
|
129 void CBkmrkProperties::TransSaveL() |
|
130 { |
|
131 SetModified (); |
|
132 |
|
133 TUint32 indexBase = IndexBase(); |
|
134 TUint32 timeLo = I64LOW(iLastModified.Int64()); |
|
135 TUint32 timeHi = I64HIGH(iLastModified.Int64()); |
|
136 iRepository->Set(indexBase + KBkmrkLastModifiedLoIndex, static_cast<TInt>(timeLo)); |
|
137 iRepository->Set(indexBase + KBkmrkLastModifiedHiIndex, static_cast<TInt>(timeHi)); |
|
138 iRepository->Set(indexBase + KCmnDescriptionIndex, Description()); |
|
139 iRepository->Set(indexBase + KCmnIconIndex, static_cast<TInt>(iIconId)); |
|
140 iCustomProperties->TransSaveL(); |
|
141 } |
|
142 |
|
143 void CBkmrkProperties::TransLoadL() |
|
144 { |
|
145 TUint32 indexBase = IndexBase(); |
|
146 TInt low = 0; |
|
147 TInt high = 0; |
|
148 TInt err = iRepository->Get( indexBase + KBkmrkLastModifiedLoIndex, low ); |
|
149 if ( err == KErrNone ) |
|
150 { |
|
151 User::LeaveIfError(iRepository->Get(indexBase + KBkmrkLastModifiedHiIndex, high)); |
|
152 TUint32 timeLo = static_cast<TUint32>(low); |
|
153 TUint32 timeHi = static_cast<TUint32>(high); |
|
154 TInt64 time = MAKE_TINT64(timeHi, timeLo); |
|
155 iLastModified = time; |
|
156 } |
|
157 else |
|
158 { |
|
159 // Set the time as 1st January 1970 midnight. |
|
160 TDateTime dt ( 1970, EJanuary, 1, 0, 0, 0, 0 ); |
|
161 iLastModified = TTime ( dt ); |
|
162 } |
|
163 |
|
164 HBufC* descBuffer = HBufC::NewLC(Bookmark::KMaxDescriptorLength); |
|
165 TPtr descPtr = descBuffer->Des(); |
|
166 User::LeaveIfError(iRepository->Get(indexBase + KCmnDescriptionIndex, descPtr)); |
|
167 delete iDescription; |
|
168 iDescription = NULL; |
|
169 iDescription = descPtr.AllocL(); |
|
170 CleanupStack::PopAndDestroy(descBuffer); |
|
171 |
|
172 TInt retVal; |
|
173 User::LeaveIfError(iRepository->Get(indexBase + KCmnIconIndex, retVal)); |
|
174 iIconId = static_cast<Bookmark::TAttachmentId>(retVal); |
|
175 |
|
176 iCustomProperties->TransLoadL(); |
|
177 SetClean(); |
|
178 } |
|
179 |
|
180 void CBkmrkProperties::TransRemoveL() |
|
181 { |
|
182 TUint32 indexBase = IndexBase(); |
|
183 iRepository->Delete(indexBase + KCmnDescriptionIndex); |
|
184 iRepository->Delete(indexBase + KCmnIconIndex); |
|
185 TInt low = 0; |
|
186 TInt err = iRepository->Get( indexBase + KBkmrkLastModifiedLoIndex, low ); |
|
187 if ( err == KErrNone ) |
|
188 { |
|
189 iRepository->Delete(indexBase + KBkmrkLastModifiedLoIndex); |
|
190 iRepository->Delete(indexBase + KBkmrkLastModifiedHiIndex); |
|
191 } |
|
192 iCustomProperties->TransRemoveL(); |
|
193 } |
|
194 |
|
195 CPropertyList& CBkmrkProperties::CustomProperties() |
|
196 { |
|
197 return *iCustomProperties; |
|
198 } |
|
199 |
|
200 TTime CBkmrkProperties::LastModified () const |
|
201 { |
|
202 return iLastModified; |
|
203 } |
|
204 |
|
205 void CBkmrkProperties::SetLastModified ( const TTime& aTime ) |
|
206 { |
|
207 iLastModified = aTime.Int64(); |
|
208 iUpdateModifiedOnCommit = EFalse; |
|
209 } |
|
210 |
|
211 void CBkmrkProperties::SetModified () |
|
212 { |
|
213 if ( iUpdateModifiedOnCommit ) |
|
214 { |
|
215 TTime currentTime; |
|
216 currentTime.HomeTime (); |
|
217 |
|
218 SetLastModified ( currentTime ); |
|
219 } |
|
220 // Reset the value. |
|
221 iUpdateModifiedOnCommit = ETrue; |
|
222 } |