|
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 bookmarks. |
|
15 // @internalComponent |
|
16 // |
|
17 // |
|
18 |
|
19 #include "bkmrk.h" |
|
20 #include "bkmrkfolder.h" |
|
21 #include "bkmrkdb.h" |
|
22 #include "repository.h" |
|
23 |
|
24 CBookmark* CBookmark::NewL(CBookmarkFolder& aParent, CBookmarkDb& aDb) |
|
25 { |
|
26 CBookmark* self = new (ELeave) CBookmark(aDb); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(aParent); |
|
29 CleanupStack::Pop(self); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CBookmark::CBookmark(CBookmarkDb& aDb) |
|
34 : CBookmarkBase(aDb, aDb.BookmarkRepository()) |
|
35 { |
|
36 } |
|
37 |
|
38 CBookmark::~CBookmark() |
|
39 { |
|
40 delete iTitle; |
|
41 delete iUri; |
|
42 delete iProperties; |
|
43 } |
|
44 |
|
45 |
|
46 void CBookmark::DeleteL() |
|
47 { |
|
48 iDatabase.RemoveBookmarkL(this); |
|
49 iParent->Remove(*this); |
|
50 iParent = NULL; |
|
51 iStatus = EStatusDeleted; |
|
52 } |
|
53 |
|
54 void CBookmark::ConstructL(CBookmarkFolder& aParent) |
|
55 { |
|
56 aParent.AppendL(*this); |
|
57 iUri = CUri8::NewL(); |
|
58 } |
|
59 |
|
60 Bookmark::TType CBookmark::Type() const |
|
61 { |
|
62 return Bookmark::ETypeBookmark; |
|
63 } |
|
64 |
|
65 RBkBookmark CBookmark::OpenBookmark() |
|
66 { |
|
67 RBkBookmark bookmark; |
|
68 bookmark.SetItem(*this); |
|
69 return bookmark; |
|
70 } |
|
71 |
|
72 TBool CBookmark::IsHomePage() |
|
73 { |
|
74 TBool isHome = EFalse; |
|
75 CBookmark* home = iDatabase.Home(); |
|
76 if (home) |
|
77 { |
|
78 isHome = (home->Id() == Id()); |
|
79 } |
|
80 return isHome; |
|
81 } |
|
82 |
|
83 const TTime& CBookmark::LastVisited() const |
|
84 { |
|
85 return iLastVisited; |
|
86 } |
|
87 |
|
88 void CBookmark::SetLastVisited(const TTime& aTime) |
|
89 { |
|
90 iLastVisited = aTime; |
|
91 SetDirty(); |
|
92 } |
|
93 |
|
94 void CBookmark::UpdateVisited() |
|
95 { |
|
96 iLastVisited.HomeTime(); |
|
97 SetDirty(); |
|
98 } |
|
99 |
|
100 const TDesC8& CBookmark::Uri() const |
|
101 { |
|
102 return iUri->Uri().UriDes(); |
|
103 } |
|
104 |
|
105 void CBookmark::SetUriL(const TDesC8& aUri) |
|
106 { |
|
107 // The aUri must be smaller that the maximim uri storage size |
|
108 __ASSERT_ALWAYS(aUri.Length() <= Bookmark::KMaxUriLength, User::Panic(Bookmark::KBookmarkErrTooLong, KErrArgument)); |
|
109 LeaveIfNotWritableL(); |
|
110 |
|
111 delete iUri; |
|
112 iUri = NULL; |
|
113 |
|
114 TUriParser8 parser; |
|
115 User::LeaveIfError(parser.Parse(aUri)); |
|
116 if (parser.Extract(EUriUserinfo).Length() != 0) |
|
117 { |
|
118 CAuthentication* auth = CAuthentication::NewL(parser); |
|
119 CleanupStack::PushL(auth); |
|
120 CBkmrkExtendedProperties& properties = BkmrkExtendedPropertiesL(); |
|
121 properties.SetAuthenticationL(*auth); |
|
122 CleanupStack::PopAndDestroy(auth); |
|
123 |
|
124 // construct the uri without the userinfo |
|
125 iUri = CUri8::NewL(); |
|
126 iUri->SetComponentL(parser.Extract(EUriScheme), EUriScheme); |
|
127 iUri->SetComponentL(parser.Extract(EUriHost), EUriHost); |
|
128 iUri->SetComponentL(parser.Extract(EUriPort), EUriPort); |
|
129 iUri->SetComponentL(parser.Extract(EUriPath), EUriPath); |
|
130 iUri->SetComponentL(parser.Extract(EUriQuery), EUriQuery); |
|
131 iUri->SetComponentL(parser.Extract(EUriFragment), EUriFragment); |
|
132 } |
|
133 else |
|
134 { |
|
135 iUri = CUri8::NewL(parser); |
|
136 } |
|
137 |
|
138 SetDirty(); |
|
139 } |
|
140 |
|
141 CBkmrkExtendedProperties& CBookmark::BkmrkExtendedPropertiesL() |
|
142 { |
|
143 if (!iProperties) |
|
144 { |
|
145 iProperties = CBkmrkExtendedProperties::NewL(*this, iDatabase, *iRepository); |
|
146 if (iStatus != EStatusCreating) |
|
147 { |
|
148 iProperties->TransactionL(ETransLoad); |
|
149 } |
|
150 } |
|
151 |
|
152 return *iProperties; |
|
153 } |
|
154 |
|
155 |
|
156 // From CRepositoryAccessor |
|
157 TUint32 CBookmark::IndexBase() |
|
158 { |
|
159 return (iId << KBookmarkIndexShift); |
|
160 } |
|
161 |
|
162 void CBookmark::SetIdFromIndexBase(TUint32 aIndexBase) |
|
163 { |
|
164 iId = aIndexBase >> KBookmarkIndexShift; |
|
165 } |
|
166 |
|
167 void CBookmark::TransNewL() |
|
168 { |
|
169 CBookmarkBase::TransNewL(); |
|
170 TUint32 indexBase = IndexBase(); |
|
171 TUint32 timeLo = I64LOW(iLastVisited.Int64()); |
|
172 TUint32 timeHi = I64HIGH(iLastVisited.Int64()); |
|
173 iRepository->Create(indexBase + KBkmrkLastVisitedLoIndex, static_cast<TInt>(timeLo)); |
|
174 iRepository->Create(indexBase + KBkmrkLastVisitedHiIndex, static_cast<TInt>(timeHi)); |
|
175 iRepository->Create(indexBase + KBkmrkURIIndex, Uri()); |
|
176 BkmrkExtendedPropertiesL().TransNewL(); |
|
177 } |
|
178 |
|
179 void CBookmark::TransSaveL() |
|
180 { |
|
181 TUint32 indexBase = IndexBase(); |
|
182 CBookmarkBase::TransSaveL(); |
|
183 TUint32 timeLo = I64LOW(iLastVisited.Int64()); |
|
184 TUint32 timeHi = I64HIGH(iLastVisited.Int64()); |
|
185 iRepository->Set(indexBase + KBkmrkLastVisitedLoIndex, static_cast<TInt>(timeLo)); |
|
186 iRepository->Set(indexBase + KBkmrkLastVisitedHiIndex, static_cast<TInt>(timeHi)); |
|
187 iRepository->Set(indexBase + KBkmrkURIIndex, Uri()); |
|
188 if (iProperties) |
|
189 { |
|
190 BkmrkExtendedPropertiesL().TransSaveL(); |
|
191 } |
|
192 } |
|
193 |
|
194 void CBookmark::TransLoadL() |
|
195 { |
|
196 CBookmarkBase::TransLoadL(); |
|
197 |
|
198 TUint32 indexBase = IndexBase(); |
|
199 TInt low = 0; |
|
200 TInt high = 0; |
|
201 User::LeaveIfError(iRepository->Get(indexBase + KBkmrkLastVisitedLoIndex, low)); |
|
202 User::LeaveIfError(iRepository->Get(indexBase + KBkmrkLastVisitedHiIndex, high)); |
|
203 TUint32 timeLo = static_cast<TUint32>(low); |
|
204 TUint32 timeHi = static_cast<TUint32>(high); |
|
205 TInt64 time = MAKE_TINT64(timeHi, timeLo); |
|
206 iLastVisited = time; |
|
207 HBufC8* uriBuffer = HBufC8::NewLC(Bookmark::KMaxUriLength); |
|
208 TPtr8 uriPtr = uriBuffer->Des(); |
|
209 User::LeaveIfError(iRepository->Get(indexBase + KBkmrkURIIndex, uriPtr)); |
|
210 SetUriL(uriPtr); |
|
211 CleanupStack::PopAndDestroy(uriBuffer); |
|
212 |
|
213 if (iProperties) |
|
214 { |
|
215 BkmrkExtendedPropertiesL().TransLoadL(); |
|
216 } |
|
217 |
|
218 SetClean(); |
|
219 } |
|
220 |
|
221 void CBookmark::TransRemoveL() |
|
222 { |
|
223 CBookmarkBase::TransRemoveL(); |
|
224 |
|
225 TUint32 indexBase = IndexBase(); |
|
226 iRepository->Delete(indexBase + KBkmrkLastVisitedLoIndex); |
|
227 iRepository->Delete(indexBase + KBkmrkLastVisitedHiIndex); |
|
228 iRepository->Delete(indexBase + KBkmrkURIIndex); |
|
229 |
|
230 // ensure extended properties are loaded |
|
231 BkmrkExtendedPropertiesL(); |
|
232 iProperties->TransRemoveL(); |
|
233 } |
|
234 |