|
1 /* |
|
2 * Copyright (c) 2005-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 field property selector base. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2SelectFieldPropertyBase.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "CPbk2ServerAppAppUi.h" |
|
23 #include <CPbk2FieldPropertyArray.h> |
|
24 #include <MPbk2FieldProperty.h> |
|
25 #include <MPbk2FieldProperty2.h> |
|
26 #include <CPbk2AddItemToContactDlg.h> |
|
27 #include <TPbk2AddItemWrapper.h> |
|
28 #include <MPbk2ApplicationServices.h> |
|
29 |
|
30 // Virtual Phonebook |
|
31 #include <CVPbkContactManager.h> |
|
32 #include <CVPbkFieldTypeSelector.h> |
|
33 #include <MVPbkContactStore.h> |
|
34 #include <MVPbkContactStoreList.h> |
|
35 #include <MVPbkContactStoreProperties.h> |
|
36 |
|
37 // System includes |
|
38 #include <barsread.h> |
|
39 #include <aknnotewrappers.h> |
|
40 |
|
41 |
|
42 // -------------------------------------------------------------------------- |
|
43 // CPbk2SelectFieldPropertyBase::CPbk2SelectFieldPropertyBase |
|
44 // -------------------------------------------------------------------------- |
|
45 // |
|
46 CPbk2SelectFieldPropertyBase::CPbk2SelectFieldPropertyBase |
|
47 ( HBufC8& aSelector, TInt aResourceId ) : |
|
48 iSelector( aSelector ), |
|
49 iDialogTitleResourceId( aResourceId ) |
|
50 { |
|
51 } |
|
52 |
|
53 // -------------------------------------------------------------------------- |
|
54 // CPbk2SelectFieldPropertyBase::~CPbk2SelectFieldPropertyBase |
|
55 // -------------------------------------------------------------------------- |
|
56 // |
|
57 CPbk2SelectFieldPropertyBase::~CPbk2SelectFieldPropertyBase() |
|
58 { |
|
59 iWrappers.Close(); |
|
60 |
|
61 if ( iAddItemDlgEliminator ) |
|
62 { |
|
63 iAddItemDlgEliminator->ForceExit(); |
|
64 } |
|
65 |
|
66 delete iFieldProperties; |
|
67 } |
|
68 |
|
69 // -------------------------------------------------------------------------- |
|
70 // CPbk2SelectFieldPropertyBase::BaseConstructL |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 void CPbk2SelectFieldPropertyBase::BaseConstructL() |
|
74 { |
|
75 } |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CPbk2SelectFieldPropertyBase::SelectedFieldType |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 const MVPbkFieldType* |
|
82 CPbk2SelectFieldPropertyBase::SelectedFieldType() const |
|
83 { |
|
84 return iSelectedFieldType; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2SelectFieldPropertyBase::Cancel |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 void CPbk2SelectFieldPropertyBase::Cancel( TInt aCommandId ) |
|
92 { |
|
93 if ( iAddItemDlgEliminator ) |
|
94 { |
|
95 TRAPD( err, iAddItemDlgEliminator->RequestExitL( aCommandId ) ); |
|
96 if ( err != KErrNone && iAddItemDlgEliminator ) |
|
97 { |
|
98 // Use force if necessary |
|
99 iAddItemDlgEliminator->ForceExit(); |
|
100 } |
|
101 } |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------------- |
|
105 // CPbk2SelectFieldPropertyBase::CreateFieldPropertiesArrayL |
|
106 // -------------------------------------------------------------------------- |
|
107 // |
|
108 void CPbk2SelectFieldPropertyBase::CreateFieldPropertiesArrayL |
|
109 ( MVPbkContactStore& aStore ) |
|
110 { |
|
111 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
112 ( *CEikonEnv::Static()->EikAppUi() ); |
|
113 |
|
114 CPbk2FieldPropertyArray* temp = CPbk2FieldPropertyArray::NewL |
|
115 ( aStore.StoreProperties().SupportedFields(), |
|
116 appUi.ApplicationServices().ContactManager().FsSession() ); |
|
117 |
|
118 delete iFieldProperties; |
|
119 iFieldProperties = temp; |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // CPbk2SelectFieldPropertyBase::CreateWrappersL |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 void CPbk2SelectFieldPropertyBase::CreateWrappersL |
|
127 ( TVPbkContactStoreUriPtr aStoreUri ) |
|
128 { |
|
129 TResourceReader reader; |
|
130 reader.SetBuffer( &iSelector ); |
|
131 |
|
132 // Default saving store |
|
133 CPbk2ServerAppAppUi& appUi = static_cast<CPbk2ServerAppAppUi&> |
|
134 ( *CEikonEnv::Static()->EikAppUi() ); |
|
135 MVPbkContactStore* store = |
|
136 appUi.ApplicationServices().ContactManager().ContactStoresL(). |
|
137 Find( aStoreUri ); |
|
138 |
|
139 CVPbkFieldTypeSelector* selector = |
|
140 CVPbkFieldTypeSelector::NewL( reader, |
|
141 store->StoreProperties().SupportedFields() ); |
|
142 CleanupStack::PushL( selector ); |
|
143 |
|
144 CreateFieldPropertiesArrayL( *store ); |
|
145 |
|
146 const TInt count( iFieldProperties->Count() ); |
|
147 for ( TInt i = 0; i < count; ++i ) |
|
148 { |
|
149 const MPbk2FieldProperty& property = |
|
150 iFieldProperties->At( i ); |
|
151 |
|
152 MPbk2FieldProperty2* fieldPropertyExtension = |
|
153 reinterpret_cast<MPbk2FieldProperty2*>( |
|
154 const_cast<MPbk2FieldProperty&>( property ). |
|
155 FieldPropertyExtension( |
|
156 KMPbk2FieldPropertyExtension2Uid ) ); |
|
157 |
|
158 if ( fieldPropertyExtension != NULL ) |
|
159 { |
|
160 if ( !fieldPropertyExtension->XSpName().Length() && |
|
161 selector->IsFieldTypeIncluded( property.FieldType() ) ) |
|
162 { |
|
163 TPbk2AddItemWrapper wrapper( property ); |
|
164 iWrappers.Append( wrapper ); |
|
165 } |
|
166 } |
|
167 } |
|
168 CleanupStack::PopAndDestroy( selector ); |
|
169 } |
|
170 |
|
171 // -------------------------------------------------------------------------- |
|
172 // CPbk2SelectFieldPropertyBase::ShowSelectFieldQueryL |
|
173 // -------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CPbk2SelectFieldPropertyBase::ShowSelectFieldQueryL() |
|
176 { |
|
177 TInt result( KErrNotSupported ); |
|
178 |
|
179 // Show select field query |
|
180 if ( iWrappers.Count() > 1 ) |
|
181 { |
|
182 HBufC* titleBuf = |
|
183 CCoeEnv::Static()->AllocReadResourceLC( iDialogTitleResourceId ); |
|
184 |
|
185 TPbk2AddItemDialogParams params |
|
186 ( titleBuf, R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT, |
|
187 KErrNotFound ); |
|
188 |
|
189 CPbk2AddItemToContactDlg* addItemDlg = |
|
190 CPbk2AddItemToContactDlg::NewL(); |
|
191 iAddItemDlgEliminator = addItemDlg; |
|
192 iAddItemDlgEliminator->ResetWhenDestroyed |
|
193 ( &iAddItemDlgEliminator ); |
|
194 result = addItemDlg->ExecuteLD( iWrappers, ¶ms ); |
|
195 CleanupStack::PopAndDestroy( titleBuf ); |
|
196 } |
|
197 else if ( iWrappers.Count() == 1 ) |
|
198 { |
|
199 result = KErrNone; |
|
200 } |
|
201 return result; |
|
202 } |
|
203 |
|
204 // End of File |