|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of the CProfileNameImpl. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CProfileNameImpl.h" |
|
22 #include <s32strm.h> |
|
23 #include <MProfilesNamesArray.h> |
|
24 #include "ProfileEngineConstants.h" |
|
25 #include <centralrepository.h> |
|
26 #include "ProfileEnginePrivateCRKeys.h" |
|
27 #include "ProfileEngUtils.h" |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CProfileNameImpl::CProfileNameImpl |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CProfileNameImpl::CProfileNameImpl( |
|
38 TInt aProfileId ) |
|
39 : iId( aProfileId ) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CProfileNameImpl::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CProfileNameImpl::ConstructL( |
|
49 const TDesC& aProfileName ) |
|
50 { |
|
51 iProfileName = aProfileName.AllocL(); |
|
52 iShortName = NULL; |
|
53 iNaviName = NULL; |
|
54 iTitleName = NULL; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CProfileNameImpl::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CProfileNameImpl::ConstructL( |
|
63 const CProfileNameImpl& aProfileNameImpl ) |
|
64 { |
|
65 iId = aProfileNameImpl.iId; |
|
66 iProfileName = aProfileNameImpl.iProfileName->AllocL(); |
|
67 if( aProfileNameImpl.iShortName && |
|
68 aProfileNameImpl.iNaviName && |
|
69 aProfileNameImpl.iTitleName ) |
|
70 { |
|
71 iShortName = aProfileNameImpl.iShortName->AllocL(); |
|
72 iNaviName = aProfileNameImpl.iNaviName->AllocL(); |
|
73 iTitleName = aProfileNameImpl.iTitleName->AllocL(); |
|
74 } |
|
75 else |
|
76 { |
|
77 iShortName = NULL; |
|
78 iNaviName = NULL; |
|
79 iTitleName = NULL; |
|
80 iNameChanged = ETrue; |
|
81 } |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CProfileNameImpl::ConstructL |
|
86 // Symbian 2nd phase constructor can leave. |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CProfileNameImpl::ConstructL( |
|
90 const TDesC& aProfileName, |
|
91 const TDesC& aShortName, |
|
92 const TDesC& aNaviName, |
|
93 const TDesC& aTitleName ) |
|
94 { |
|
95 iProfileName = aProfileName.AllocL(); |
|
96 iShortName = aShortName.AllocL(); |
|
97 iNaviName = aNaviName.AllocL(); |
|
98 iTitleName = aTitleName.AllocL(); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CProfileNameImpl::NewL |
|
103 // Two-phased constructor. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 CProfileNameImpl* CProfileNameImpl::NewL() |
|
107 { |
|
108 CProfileNameImpl* self = NewLC( 0, KNullDesC ); |
|
109 |
|
110 CleanupStack::Pop(); |
|
111 |
|
112 return self; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CProfileNameImpl::NewLC |
|
117 // Two-phased constructor. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 CProfileNameImpl* CProfileNameImpl::NewLC( |
|
121 TInt aProfileId, |
|
122 const TDesC& aProfileName ) |
|
123 { |
|
124 CProfileNameImpl* self = new ( ELeave ) CProfileNameImpl( aProfileId ); |
|
125 CleanupStack::PushL( self ); |
|
126 self->ConstructL( aProfileName ); |
|
127 return self; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CProfileNameImpl::NewLC |
|
132 // Two-phased constructor. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 CProfileNameImpl* CProfileNameImpl::NewLC( |
|
136 TInt aProfileId, |
|
137 const TDesC& aProfileName, |
|
138 const TDesC& aShortName, |
|
139 const TDesC& aNaviName, |
|
140 const TDesC& aTitleName ) |
|
141 { |
|
142 CProfileNameImpl* self = new ( ELeave ) CProfileNameImpl( aProfileId ); |
|
143 CleanupStack::PushL( self ); |
|
144 self->ConstructL( aProfileName, aShortName, aNaviName, aTitleName ); |
|
145 return self; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CProfileNameImpl::NewLC |
|
150 // Two-phased constructor. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 CProfileNameImpl* CProfileNameImpl::NewLC( |
|
154 const CProfileNameImpl& aProfileNameImpl ) |
|
155 { |
|
156 CProfileNameImpl* self = |
|
157 new ( ELeave ) CProfileNameImpl( aProfileNameImpl.iId ); |
|
158 CleanupStack::PushL( self ); |
|
159 self->ConstructL( aProfileNameImpl ); |
|
160 return self; |
|
161 } |
|
162 |
|
163 // Destructor |
|
164 CProfileNameImpl::~CProfileNameImpl() |
|
165 { |
|
166 delete iTitleName; |
|
167 delete iNaviName; |
|
168 delete iShortName; |
|
169 delete iProfileName; |
|
170 } |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CProfileNameImpl::IsProfileNameChanged |
|
175 // |
|
176 // (other items were commented in a header). |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 TBool CProfileNameImpl::IsProfileNameChanged() const |
|
180 { |
|
181 return iNameChanged; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CProfileImpl::SetLocalizedProfileNameL |
|
186 // |
|
187 // (other items were commented in a header). |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CProfileNameImpl::SetLocalizedProfileNameL( |
|
191 const MProfilesNamesArray& aNameArray ) |
|
192 { |
|
193 SetNameInternalL( iProfileName, |
|
194 aNameArray.MdcaPoint( aNameArray.FindById( iId ) ) ); |
|
195 SetNameInternalL( iShortName, |
|
196 aNameArray.ProfileName( aNameArray.FindById( iId ) )->ShortName() ); |
|
197 SetNameInternalL( iNaviName, |
|
198 aNameArray.ProfileName( aNameArray.FindById( iId ) )->NaviName() ); |
|
199 SetNameInternalL( iTitleName, |
|
200 aNameArray.ProfileName( aNameArray.FindById( iId ) )->TitleName() ); |
|
201 iNameChanged = EFalse; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CProfileImpl::SetLocalizedProfileNameL |
|
206 // |
|
207 // (other items were commented in a header). |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CProfileNameImpl::SetLocalizedProfileNameL( |
|
211 const CProfileNameImpl& aNameImpl, const TDesC& aUniquePart ) |
|
212 { |
|
213 TBuf<KProfileMaxNameLength> nameBuf; |
|
214 |
|
215 nameBuf.Copy( aNameImpl.Name() ); |
|
216 nameBuf.Append( aUniquePart ); |
|
217 SetNameInternalL( iProfileName, nameBuf ); |
|
218 |
|
219 nameBuf.Copy( aNameImpl.ShortName() ); |
|
220 nameBuf.Append( aUniquePart ); |
|
221 SetNameInternalL( iShortName, nameBuf ); |
|
222 |
|
223 nameBuf.Copy( aNameImpl.NaviName() ); |
|
224 nameBuf.Append( aUniquePart ); |
|
225 SetNameInternalL( iNaviName, nameBuf ); |
|
226 |
|
227 nameBuf.Copy( aNameImpl.TitleName() ); |
|
228 nameBuf.Append( aUniquePart ); |
|
229 SetNameInternalL( iTitleName, nameBuf ); |
|
230 |
|
231 iNameChanged = EFalse; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CProfileNameImpl::InternalizeL |
|
236 // |
|
237 // (other items were commented in a header). |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CProfileNameImpl::InternalizeL( CRepository& aCenRep, TInt aProfileId ) |
|
241 { |
|
242 delete iShortName; |
|
243 iShortName = NULL; |
|
244 |
|
245 delete iNaviName; |
|
246 iNaviName = NULL; |
|
247 |
|
248 delete iTitleName; |
|
249 iTitleName = NULL; |
|
250 |
|
251 TInt tmp( 0 ); |
|
252 User::LeaveIfError( |
|
253 aCenRep.Get( ProfileEngUtils::ResolveKey( |
|
254 KProEngNameChanged, aProfileId ), tmp ) ); |
|
255 |
|
256 TBuf< KProfileMaxNameLength > nameBuf; |
|
257 User::LeaveIfError( |
|
258 aCenRep.Get( ProfileEngUtils::ResolveKey( |
|
259 KProEngProfileName, aProfileId ), nameBuf ) ); |
|
260 HBufC* tmpName = nameBuf.AllocL(); |
|
261 delete iProfileName; |
|
262 |
|
263 iId = aProfileId; |
|
264 iProfileName = tmpName; |
|
265 iNameChanged = tmp; |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CProfileNameImpl::ExternalizeL |
|
270 // |
|
271 // (other items were commented in a header). |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 void CProfileNameImpl::ExternalizeL( CRepository& aCenRep ) const |
|
275 { |
|
276 if( iNameChanged ) |
|
277 { |
|
278 User::LeaveIfError( |
|
279 aCenRep.Set( ProfileEngUtils::ResolveKey( |
|
280 KProEngNameChanged, iId ), |
|
281 iNameChanged ) ); |
|
282 User::LeaveIfError( |
|
283 aCenRep.Set( ProfileEngUtils::ResolveKey( |
|
284 KProEngProfileName, iId ), |
|
285 *iProfileName ) ); |
|
286 } |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CProfileNameImpl::SetNameL |
|
291 // |
|
292 // (other items were commented in a header). |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CProfileNameImpl::SetNameL( |
|
296 const TDesC& aName ) |
|
297 { |
|
298 SetNameInternalL( iProfileName, aName ); |
|
299 // User changed the name, iShortName,iNaviName,iTitleName are not needed |
|
300 // anymore: |
|
301 delete iShortName; |
|
302 iShortName = NULL; |
|
303 |
|
304 delete iNaviName; |
|
305 iNaviName = NULL; |
|
306 |
|
307 delete iTitleName; |
|
308 iTitleName = NULL; |
|
309 |
|
310 iNameChanged = ETrue; |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CProfileNameImpl::Name |
|
315 // |
|
316 // (other items were commented in a header). |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 const TDesC& CProfileNameImpl::Name() const |
|
320 { |
|
321 return *iProfileName; |
|
322 } |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CProfileNameImpl::Id |
|
326 // |
|
327 // (other items were commented in a header). |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 TInt CProfileNameImpl::Id() const |
|
331 { |
|
332 return iId; |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CProfileNameImpl::ShortName |
|
337 // |
|
338 // (other items were commented in a header). |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 const TDesC& CProfileNameImpl::ShortName() const |
|
342 { |
|
343 if( iShortName ) |
|
344 { |
|
345 return *iShortName; |
|
346 } |
|
347 return *iProfileName; |
|
348 } |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CProfileNameImpl::NaviName |
|
352 // |
|
353 // (other items were commented in a header). |
|
354 // ----------------------------------------------------------------------------- |
|
355 // |
|
356 const TDesC& CProfileNameImpl::NaviName() const |
|
357 { |
|
358 if( iNaviName ) |
|
359 { |
|
360 return *iNaviName; |
|
361 } |
|
362 return *iProfileName; |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CProfileNameImpl::TitleName |
|
367 // |
|
368 // (other items were commented in a header). |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 const TDesC& CProfileNameImpl::TitleName() const |
|
372 { |
|
373 if( iTitleName ) |
|
374 { |
|
375 return *iTitleName; |
|
376 } |
|
377 return *iProfileName; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CProfileNameImpl::SetNameInternalL |
|
382 // |
|
383 // (other items were commented in a header). |
|
384 // ----------------------------------------------------------------------------- |
|
385 // |
|
386 void CProfileNameImpl::SetNameInternalL( HBufC*& aNameFieldRef, |
|
387 const TDesC& aName ) |
|
388 { |
|
389 HBufC* tmp = aName.Left( KProfileMaxNameLength ).AllocL(); |
|
390 delete aNameFieldRef; |
|
391 aNameFieldRef = tmp; |
|
392 } |
|
393 |
|
394 // End of File |