|
1 /* |
|
2 * Copyright (c) 2002-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: Phonebook 2 contact editor reading field visitor. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2ReadingFieldEditorVisitor.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include <MPbk2ContactEditorField.h> |
|
23 #include <CPbk2PresentationContactField.h> |
|
24 #include <Pbk2UIControls.rsg> |
|
25 |
|
26 // Virtual Phonebook |
|
27 #include <MVPbkFieldType.h> |
|
28 #include <MVPbkBaseContactField.h> |
|
29 #include <CVPbkContactManager.h> |
|
30 #include <CVPbkFieldTypeSelector.h> |
|
31 |
|
32 // System includes |
|
33 #include <AknReadingConverter.h> |
|
34 #include <barsread.h> |
|
35 |
|
36 // Debugging headers |
|
37 #include <Pbk2Debug.h> |
|
38 |
|
39 |
|
40 /// Unnamed namespace for local definitions |
|
41 namespace { |
|
42 |
|
43 /** |
|
44 * Matches field type. |
|
45 * |
|
46 * @param aFieldTypeList The field type list to use. |
|
47 * @param aField The field whose type to match. |
|
48 * @return Matched field type. |
|
49 */ |
|
50 const MVPbkFieldType* MatchFieldType |
|
51 ( const MVPbkFieldTypeList& aFieldTypeList, |
|
52 const MVPbkBaseContactField& aField ) |
|
53 { |
|
54 const MVPbkFieldType* result = NULL; |
|
55 |
|
56 for ( TInt matchPriority = 0; |
|
57 matchPriority <= aFieldTypeList.MaxMatchPriority() && !result; |
|
58 ++matchPriority ) |
|
59 { |
|
60 result = aField.MatchFieldType( matchPriority ); |
|
61 } |
|
62 |
|
63 return result; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Checks is the given field type included in |
|
68 * the given selection. |
|
69 * |
|
70 * @param aField The field whose type to check. |
|
71 * @param aManager Contact manager. |
|
72 * @param aResourceId Selector's resource id. |
|
73 * @return ETrue if field type is included. |
|
74 */ |
|
75 TBool IsFieldTypeIncludedL( |
|
76 const MVPbkBaseContactField& aField, |
|
77 const CVPbkContactManager& aManager, |
|
78 const TInt aResourceId ) |
|
79 { |
|
80 // Get the field type |
|
81 const MVPbkFieldType* fieldType = MatchFieldType |
|
82 ( aManager.FieldTypes(), aField ); |
|
83 |
|
84 TResourceReader resReader; |
|
85 CCoeEnv::Static()->CreateResourceReaderLC |
|
86 ( resReader, aResourceId ); |
|
87 |
|
88 CVPbkFieldTypeSelector* selector = |
|
89 CVPbkFieldTypeSelector::NewL( resReader, aManager.FieldTypes() ); |
|
90 CleanupStack::PopAndDestroy(); // resReader |
|
91 |
|
92 TBool ret = selector->IsFieldTypeIncluded( *fieldType ); |
|
93 delete selector; |
|
94 return ret; |
|
95 } |
|
96 |
|
97 } /// namespace |
|
98 |
|
99 |
|
100 // -------------------------------------------------------------------------- |
|
101 // CPbk2ReadingFieldEditorVisitor::CPbk2ReadingFieldEditorVisitor |
|
102 // -------------------------------------------------------------------------- |
|
103 // |
|
104 inline CPbk2ReadingFieldEditorVisitor::CPbk2ReadingFieldEditorVisitor |
|
105 ( const CVPbkContactManager& aContactManager ): |
|
106 iContactManager( aContactManager ) |
|
107 { |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CPbk2ReadingFieldEditorVisitor::~CPbk2ReadingFieldEditorVisitor |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 CPbk2ReadingFieldEditorVisitor::~CPbk2ReadingFieldEditorVisitor() |
|
115 { |
|
116 delete iFirstNameConverter; |
|
117 delete iLastNameConverter; |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CPbk2ReadingFieldEditorVisitor::NewL |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 CPbk2ReadingFieldEditorVisitor* CPbk2ReadingFieldEditorVisitor::NewL |
|
125 ( const CVPbkContactManager& aContactManager ) |
|
126 { |
|
127 return new ( ELeave ) |
|
128 CPbk2ReadingFieldEditorVisitor( aContactManager ); |
|
129 } |
|
130 |
|
131 // -------------------------------------------------------------------------- |
|
132 // CPbk2ReadingFieldEditorVisitor::VisitL |
|
133 // -------------------------------------------------------------------------- |
|
134 // |
|
135 void CPbk2ReadingFieldEditorVisitor::VisitL |
|
136 ( MPbk2ContactEditorField& /* aThis */ ) |
|
137 { |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPbk2ReadingFieldEditorVisitor::SetEditorsL |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 inline void CPbk2ReadingFieldEditorVisitor::SetEditorsL |
|
145 ( MPbk2ContactEditorField& aThis ) |
|
146 { |
|
147 const MVPbkStoreContactField& field = aThis.ContactField(); |
|
148 |
|
149 if ( IsFieldTypeIncludedL( field, iContactManager, |
|
150 R_PHONEBOOK2_LAST_NAME_SELECTOR ) ) |
|
151 { |
|
152 iLastNameConverter->SetMainEditor( *aThis.Control() ); |
|
153 } |
|
154 else if ( IsFieldTypeIncludedL( field, iContactManager, |
|
155 R_PHONEBOOK2_FIRST_NAME_SELECTOR ) ) |
|
156 { |
|
157 iFirstNameConverter->SetMainEditor( *aThis.Control() ); |
|
158 } |
|
159 else if ( IsFieldTypeIncludedL( field, iContactManager, |
|
160 R_PHONEBOOK2_LAST_NAME_PRONUNCIATION_SELECTOR ) ) |
|
161 { |
|
162 iLastNameConverter->SetReadingEditor( *aThis.Control() ); |
|
163 } |
|
164 else if ( IsFieldTypeIncludedL( field, iContactManager, |
|
165 R_PHONEBOOK2_FIRST_NAME_PRONUNCIATION_SELECTOR ) ) |
|
166 { |
|
167 iFirstNameConverter->SetReadingEditor( *aThis.Control() ); |
|
168 } |
|
169 } |
|
170 |
|
171 // End of File |