|
1 /* |
|
2 * Copyright (c) 2004-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: The virtual phonebook field info |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CFieldInfo.h" |
|
20 |
|
21 #include <barsread.h> |
|
22 #include <cntfield.h> |
|
23 |
|
24 namespace VPbkCntModel { |
|
25 |
|
26 const TInt KFieldInfoGranularity = 8; |
|
27 |
|
28 CFieldInfo::CFieldInfo() |
|
29 { |
|
30 } |
|
31 |
|
32 inline void CFieldInfo::ConstructL(TResourceReader& aReader) |
|
33 { |
|
34 iFieldStorageType = aReader.ReadInt32(); |
|
35 iContentType = CContentType::NewL(); |
|
36 const TUid contactFieldUid = TUid::Uid(aReader.ReadInt32()); |
|
37 iContentType->SetMapping(TUid::Uid(aReader.ReadInt32())); |
|
38 if (contactFieldUid != KUidContactFieldNone) |
|
39 { |
|
40 iContentType->AddFieldTypeL(contactFieldUid); |
|
41 } |
|
42 TInt count = aReader.ReadInt16(); |
|
43 while (--count >= 0) |
|
44 { |
|
45 iContentType->AddFieldTypeL(TUid::Uid(aReader.ReadInt32())); |
|
46 } |
|
47 iCategory = aReader.ReadInt32(); |
|
48 iFieldName = aReader.ReadHBufCL(); |
|
49 iFlags = aReader.ReadInt32(); |
|
50 } |
|
51 |
|
52 CFieldInfo* CFieldInfo::NewL(TResourceReader& aReader) |
|
53 { |
|
54 CFieldInfo* self = new(ELeave) CFieldInfo; |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(aReader); |
|
57 CleanupStack::Pop(self); |
|
58 return self; |
|
59 } |
|
60 |
|
61 CFieldInfo::~CFieldInfo() |
|
62 { |
|
63 delete iFieldName; |
|
64 delete iContentType; |
|
65 } |
|
66 |
|
67 inline TBool CFieldInfo::IsEqualFlags(const CContactItemField& aField) const |
|
68 { |
|
69 TUint flags = 0; |
|
70 if (aField.IsHidden()) |
|
71 { |
|
72 flags |= EContactFieldFlagHidden; |
|
73 } |
|
74 if (aField.IsReadOnly()) |
|
75 { |
|
76 flags |= EContactFieldFlagReadOnly; |
|
77 } |
|
78 // Do not check synchronize flag as ctnmodel modifies it |
|
79 if (aField.IsDisabled()) |
|
80 { |
|
81 flags |= EContactFieldFlagDisabled; |
|
82 } |
|
83 return ((flags & iFlags) == flags); |
|
84 } |
|
85 |
|
86 TBool CFieldInfo::IsEqualType(const CContactItemField& aField) const |
|
87 { |
|
88 return |
|
89 (iFieldStorageType == aField.StorageType() && |
|
90 iContentType->IsEqual( aField.ContentType() ) && |
|
91 TUint(iCategory) == aField.UserFlags() && |
|
92 IsEqualFlags(aField)); |
|
93 } |
|
94 |
|
95 TBool CFieldInfo::IsEqualLabel(const CContactItemField& aField) const |
|
96 { |
|
97 return |
|
98 ((!iFieldName && aField.Label().Length()==0) || |
|
99 (iFieldName && aField.Label()==*iFieldName)); |
|
100 } |
|
101 |
|
102 CContactItemField* CFieldInfo::CreateFieldL() const |
|
103 { |
|
104 CContactItemField* field = CContactItemField::NewLC(iFieldStorageType, |
|
105 *iContentType); |
|
106 |
|
107 field->SetUserFlags( iCategory ); |
|
108 if ( iFieldName ) |
|
109 { |
|
110 field->SetLabelL( *iFieldName ); |
|
111 } |
|
112 if ( iFlags & EContactFieldFlagHidden ) |
|
113 { |
|
114 field->SetHidden( ETrue ); |
|
115 } |
|
116 if ( iFlags & EContactFieldFlagReadOnly ) |
|
117 { |
|
118 field->SetReadOnly( ETrue ); |
|
119 } |
|
120 if ( iFlags & EContactFieldFlagSynchronize ) |
|
121 { |
|
122 field->SetSynchronize( ETrue ); |
|
123 } |
|
124 if ( iFlags & EContactFieldFlagDisabled ) |
|
125 { |
|
126 field->SetDisabled( ETrue ); |
|
127 } |
|
128 CleanupStack::Pop(field); |
|
129 return field; |
|
130 } |
|
131 |
|
132 CFieldsInfo::CFieldsInfo() : |
|
133 CArrayPtrFlat<CFieldInfo>(KFieldInfoGranularity) |
|
134 { |
|
135 } |
|
136 |
|
137 inline void CFieldsInfo::ConstructL(TResourceReader& aReader) |
|
138 { |
|
139 AppendFieldsL(aReader); |
|
140 } |
|
141 |
|
142 CFieldsInfo* CFieldsInfo::NewL(TResourceReader& aReader) |
|
143 { |
|
144 CFieldsInfo* self = new(ELeave) CFieldsInfo; |
|
145 CleanupStack::PushL(self); |
|
146 self->ConstructL(aReader); |
|
147 CleanupStack::Pop(self); |
|
148 return self; |
|
149 } |
|
150 |
|
151 void CFieldsInfo::AppendFieldsL(TResourceReader& aReader) |
|
152 { |
|
153 TInt count = aReader.ReadInt16(); |
|
154 while (--count >= 0) |
|
155 { |
|
156 CFieldInfo* fieldInfo = CFieldInfo::NewL(aReader); |
|
157 CleanupStack::PushL(fieldInfo); |
|
158 AppendL(fieldInfo); |
|
159 CleanupStack::Pop(fieldInfo); |
|
160 } |
|
161 } |
|
162 |
|
163 CFieldsInfo::~CFieldsInfo() |
|
164 { |
|
165 ResetAndDestroy(); |
|
166 } |
|
167 |
|
168 } // VPbkCntModel |