|
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: |
|
15 * Name formatter factory. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "Pbk2ContactNameFormatterFactory.h" |
|
21 |
|
22 // From Phonebook2 |
|
23 #include "Pbk2DataCaging.hrh" |
|
24 #include "CPbk2ContactNameFormatter.h" |
|
25 #include "CPbk2JapaneseContactNameFormatter.h" |
|
26 #include "CPbk2ChineseContactNameFormatter.h" |
|
27 #include "Pbk2PresentationUtils.h" |
|
28 #include <RPbk2LocalizedResourceFile.h> |
|
29 #include <Pbk2Presentation.rsg> |
|
30 |
|
31 // From Virtual Phonebook |
|
32 #include <CVPbkFieldTypeSelector.h> |
|
33 |
|
34 // System includes |
|
35 #include <barsread.h> |
|
36 #include <featmgr.h> |
|
37 |
|
38 namespace { |
|
39 |
|
40 MPbk2ContactNameFormatter* CreateFormatterL( |
|
41 const MVPbkFieldTypeList& aMasterFieldTypeList, |
|
42 const CPbk2SortOrderManager& aSortOrderManager, |
|
43 CVPbkFieldTypeSelector* aTitleFieldSelector, |
|
44 const TDesC& aUnnamedText ) |
|
45 { |
|
46 MPbk2ContactNameFormatter* result = NULL; |
|
47 |
|
48 FeatureManager::InitializeLibL(); |
|
49 TBool chinese = FeatureManager::FeatureSupported( KFeatureIdChinese ); |
|
50 FeatureManager::UnInitializeLib(); |
|
51 |
|
52 if ( chinese ) |
|
53 { |
|
54 result = CPbk2ChineseContactNameFormatter::NewL( aUnnamedText, |
|
55 aMasterFieldTypeList, aSortOrderManager, aTitleFieldSelector ); |
|
56 } |
|
57 else |
|
58 { |
|
59 result = CPbk2ContactNameFormatter::NewL( aUnnamedText, |
|
60 aMasterFieldTypeList, aSortOrderManager, aTitleFieldSelector ); |
|
61 } |
|
62 |
|
63 |
|
64 return result; |
|
65 } |
|
66 |
|
67 MPbk2ContactNameFormatter* CreateFormatterL( |
|
68 const MVPbkFieldTypeList& aMasterFieldTypeList, |
|
69 const CPbk2SortOrderManager& aSortOrderManager, |
|
70 TResourceReader* aTitleFieldSelectorReader, |
|
71 const TDesC* aUnnamedText, |
|
72 RFs* aRFs ) |
|
73 { |
|
74 RFs ownFs; |
|
75 RFs fs; |
|
76 |
|
77 if ( !aRFs ) |
|
78 { |
|
79 User::LeaveIfError( ownFs.Connect() ); |
|
80 CleanupClosePushL( ownFs ); |
|
81 fs = ownFs; |
|
82 } |
|
83 else |
|
84 { |
|
85 fs = *aRFs; |
|
86 } |
|
87 |
|
88 RPbk2LocalizedResourceFile resFile( &fs ); |
|
89 resFile.OpenLC( KPbk2RomFileDrive, |
|
90 KDC_RESOURCE_FILES_DIR, |
|
91 Pbk2PresentationUtils::PresentationResourceFile() ); |
|
92 |
|
93 CVPbkFieldTypeSelector* titleFieldSelector = NULL; |
|
94 |
|
95 HBufC* unnamed = NULL; |
|
96 if ( !aUnnamedText ) |
|
97 { |
|
98 TResourceReader reader; |
|
99 reader.SetBuffer( resFile.AllocReadLC( R_QTN_PHOB_UNNAMED ) ); |
|
100 unnamed = reader.ReadHBufCL(); |
|
101 CleanupStack::PopAndDestroy(); // reader |
|
102 CleanupStack::PushL( unnamed ); |
|
103 } |
|
104 else |
|
105 { |
|
106 unnamed = aUnnamedText->AllocLC(); |
|
107 } |
|
108 |
|
109 if ( !aTitleFieldSelectorReader ) |
|
110 { |
|
111 // Use default title fields |
|
112 TResourceReader reader; |
|
113 reader.SetBuffer( resFile.AllocReadLC( R_TITLE_FIELD_SELECTOR ) ); |
|
114 titleFieldSelector = |
|
115 CVPbkFieldTypeSelector::NewL( reader, aMasterFieldTypeList ); |
|
116 CleanupStack::PopAndDestroy(); // reader |
|
117 } |
|
118 else |
|
119 { |
|
120 titleFieldSelector = CVPbkFieldTypeSelector::NewL( |
|
121 *aTitleFieldSelectorReader, aMasterFieldTypeList ); |
|
122 } |
|
123 CleanupStack::PushL( titleFieldSelector ); |
|
124 |
|
125 // Ownership of titleFieldSelector changes |
|
126 MPbk2ContactNameFormatter* result = CreateFormatterL( aMasterFieldTypeList, |
|
127 aSortOrderManager, titleFieldSelector, *unnamed ); |
|
128 |
|
129 CleanupStack::Pop( titleFieldSelector ); |
|
130 CleanupStack::PopAndDestroy(2); // resFile, unnamed |
|
131 if ( ownFs.Handle() ) |
|
132 { |
|
133 CleanupStack::PopAndDestroy(); // ownFs |
|
134 } |
|
135 |
|
136 return result; |
|
137 } |
|
138 } |
|
139 |
|
140 |
|
141 EXPORT_C MPbk2ContactNameFormatter* Pbk2ContactNameFormatterFactory::CreateL |
|
142 ( const MVPbkFieldTypeList& aMasterFieldTypeList, |
|
143 const CPbk2SortOrderManager& aSortOrderManager, |
|
144 RFs* aRFs ) |
|
145 { |
|
146 return CreateFormatterL( aMasterFieldTypeList, aSortOrderManager, |
|
147 NULL, NULL, aRFs ); |
|
148 } |
|
149 |
|
150 EXPORT_C MPbk2ContactNameFormatter* Pbk2ContactNameFormatterFactory::CreateL |
|
151 ( const TDesC& aUnnamedText, |
|
152 const MVPbkFieldTypeList& aMasterFieldTypeList, |
|
153 const CPbk2SortOrderManager& aSortOrderManager, |
|
154 RFs* aRFs ) |
|
155 { |
|
156 return CreateFormatterL( aMasterFieldTypeList, aSortOrderManager, |
|
157 NULL, &aUnnamedText, aRFs ); |
|
158 } |
|
159 |
|
160 EXPORT_C MPbk2ContactNameFormatter* Pbk2ContactNameFormatterFactory::CreateL |
|
161 ( const MVPbkFieldTypeList& aMasterFieldTypeList, |
|
162 const CPbk2SortOrderManager& aSortOrderManager, |
|
163 TResourceReader& aTitleFieldSelectorReader, |
|
164 const TDesC* aUnnamedText, |
|
165 RFs* aRFs ) |
|
166 { |
|
167 return CreateFormatterL( aMasterFieldTypeList, aSortOrderManager, |
|
168 &aTitleFieldSelectorReader, aUnnamedText, aRFs ); |
|
169 } |