|
1 /* |
|
2 * Copyright (c) 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: Implementation of the class CPbkxRclSettingItem. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <pbk2rclengine.rsg> |
|
21 #include <ecom/ecom.h> |
|
22 #include "cpbkxremotecontactlookupprotocoladapter.h" |
|
23 #include <cpbkxremotecontactlookupprotocolaccount.h> |
|
24 #include <StringLoader.h> |
|
25 #include <bautils.h> |
|
26 #include <data_caging_path_literals.hrh> |
|
27 |
|
28 #include "cpbkxrclsettingitem.h" |
|
29 #include "pbkxrclutils.h" |
|
30 #include "cpbkxrclprotocolenvimpl.h" |
|
31 #include "pbkxrclengineconstants.h" |
|
32 #include "pbkxremotecontactlookuppanic.h" |
|
33 |
|
34 |
|
35 _LIT( KEmpty, "Empty" ); |
|
36 |
|
37 // ======== MEMBER FUNCTIONS ======== |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CPbkxRclSettingItem::NewL |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CPbkxRclSettingItem* CPbkxRclSettingItem::NewL() |
|
44 { |
|
45 FUNC_LOG; |
|
46 CPbkxRclSettingItem* item = CPbkxRclSettingItem::NewLC(); |
|
47 CleanupStack::Pop( item ); |
|
48 return item; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CPbkxRclSettingItem::NewLC |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CPbkxRclSettingItem* CPbkxRclSettingItem::NewLC() |
|
56 { |
|
57 FUNC_LOG; |
|
58 CPbkxRclSettingItem* item = new ( ELeave ) CPbkxRclSettingItem(); |
|
59 CleanupStack::PushL( item ); |
|
60 item->ConstructL(); |
|
61 return item; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // CPbkxRclSettingItem::CPbkxRclSettingItem |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 CPbkxRclSettingItem::CPbkxRclSettingItem() : |
|
69 CAknEnumeratedTextPopupSettingItem( KPbkxRclSettingItemId, iSelectedItem ) |
|
70 { |
|
71 FUNC_LOG; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CPbkxRclSettingItem::~CPbkxRclSettingItem |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CPbkxRclSettingItem::~CPbkxRclSettingItem() |
|
79 { |
|
80 FUNC_LOG; |
|
81 iProtocolAccounts.ResetAndDestroy(); |
|
82 CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset ); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CPbkxRclSettingItem::ConstructL |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CPbkxRclSettingItem::ConstructL() |
|
90 { |
|
91 FUNC_LOG; |
|
92 |
|
93 // first load resource file |
|
94 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
95 TFileName dllFileName; |
|
96 Dll::FileName( dllFileName ); |
|
97 |
|
98 TParse parse; |
|
99 parse.Set( KResourceFile, &KDC_APP_RESOURCE_DIR, &dllFileName ); |
|
100 TFileName resourceFile = parse.FullName(); |
|
101 BaflUtils::NearestLanguageFile( coeEnv->FsSession(), resourceFile ); |
|
102 |
|
103 TRAPD( status, |
|
104 iResourceFileOffset = coeEnv->AddResourceFileL( resourceFile ) ); |
|
105 |
|
106 if( status != KErrNone ) |
|
107 { |
|
108 PbkxRclPanic( EPbkxRclPanicGeneral ); |
|
109 } |
|
110 else |
|
111 { |
|
112 } |
|
113 |
|
114 // set empty item text although it should not be used ever |
|
115 SetEmptyItemTextL( KEmpty ); |
|
116 |
|
117 HBufC* settingName = StringLoader::LoadLC( R_QTN_PHOB_SET_SERVER_SEARCH); |
|
118 |
|
119 // call base class ConstructL, this will create stuff we need |
|
120 CAknSettingItem::ConstructL( |
|
121 EFalse, |
|
122 KPbkxRclSettingItemId, |
|
123 *settingName, |
|
124 NULL, |
|
125 R_RCL_SETTING_ITEM_PAGE, |
|
126 -1, |
|
127 0, |
|
128 R_RCL_POPUP_SETTING_TEXTS ); |
|
129 |
|
130 CleanupStack::PopAndDestroy( settingName ); |
|
131 |
|
132 // get text arrays |
|
133 iEnumTexts = EnumeratedTextArray(); |
|
134 iPoppedUpTexts = PoppedUpTextArray(); |
|
135 |
|
136 // get all accounts |
|
137 LoadProtocolAccountsL(); |
|
138 |
|
139 // Fills enumeration and popup text array |
|
140 FillTextArraysL(); |
|
141 |
|
142 // sets selected account |
|
143 SetSelectedAccountL(); |
|
144 |
|
145 // load the selection |
|
146 LoadL(); |
|
147 |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // CPbkxRclSettingItem::EditItemL |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CPbkxRclSettingItem::EditItemL( TBool aCalledFromMenu ) |
|
155 { |
|
156 FUNC_LOG; |
|
157 TInt oldSelection = iSelectedItem; |
|
158 CAknEnumeratedTextPopupSettingItem::EditItemL( aCalledFromMenu ); |
|
159 StoreL(); |
|
160 |
|
161 if ( oldSelection != iSelectedItem ) |
|
162 { |
|
163 StoreSettingL(); |
|
164 } |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CPbkxRclSettingItem::LoadProtocolAccountsL |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CPbkxRclSettingItem::LoadProtocolAccountsL() |
|
172 { |
|
173 FUNC_LOG; |
|
174 |
|
175 // create environment given to plugins |
|
176 CPbkxRclProtocolEnvImpl* env = CPbkxRclProtocolEnvImpl::NewLC(); |
|
177 |
|
178 // load all adapter information |
|
179 RImplInfoPtrArray implArray; |
|
180 TUid pluginIfUid = {KPbkxRemoteContactLookupAdapterIfUid }; |
|
181 REComSession::ListImplementationsL( pluginIfUid, implArray ); |
|
182 |
|
183 // create adapters |
|
184 CPbkxRemoteContactLookupProtocolAdapter* adapter = NULL; |
|
185 for ( TInt i = 0; i < implArray.Count(); i++ ) |
|
186 { |
|
187 TRAPD( err, |
|
188 { |
|
189 adapter = CPbkxRemoteContactLookupProtocolAdapter::NewL( |
|
190 implArray[i]->ImplementationUid(), |
|
191 *env ); |
|
192 CleanupStack::PushL( adapter ); |
|
193 adapter->GetAllProtocolAccountsL( iProtocolAccounts ); |
|
194 CleanupStack::PopAndDestroy( adapter ); |
|
195 } ); |
|
196 if ( err != KErrNone ) |
|
197 { |
|
198 // log error |
|
199 } |
|
200 } |
|
201 |
|
202 implArray.ResetAndDestroy(); |
|
203 CleanupStack::PopAndDestroy( env ); |
|
204 |
|
205 // if no protocol accounts found, leave |
|
206 if ( iProtocolAccounts.Count() == 0 ) |
|
207 { |
|
208 User::Leave( KErrNotReady ); |
|
209 } |
|
210 |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CPbkxRclSettingItem::FillTextArraysL |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CPbkxRclSettingItem::FillTextArraysL() |
|
218 { |
|
219 FUNC_LOG; |
|
220 |
|
221 // add "none" selection in first place |
|
222 HBufC* noneText = StringLoader::LoadLC( R_QTN_RCL_SETTING_RCL_NOT_DEFINED ); |
|
223 |
|
224 CAknEnumeratedText* enumItem = |
|
225 new ( ELeave ) CAknEnumeratedText( 0, noneText ); |
|
226 CleanupStack::PushL( enumItem ); |
|
227 iEnumTexts->AppendL( enumItem ); |
|
228 CleanupStack::Pop( enumItem ); |
|
229 CleanupStack::Pop( noneText ); |
|
230 |
|
231 HBufC* notDefinedText = |
|
232 StringLoader::LoadLC( R_QTN_RCL_SETTING_RCL_SERVER_NONE ); |
|
233 |
|
234 iPoppedUpTexts->AppendL( notDefinedText ); |
|
235 |
|
236 CleanupStack::Pop( notDefinedText ); |
|
237 |
|
238 for ( TInt i = 0; i < iProtocolAccounts.Count(); i++ ) |
|
239 { |
|
240 CPbkxRemoteContactLookupProtocolAccount* account = iProtocolAccounts[i]; |
|
241 TUint accountId = account->Id().iAccountId; |
|
242 const TDesC& accountName = account->Name(); |
|
243 enumItem = |
|
244 new ( ELeave ) CAknEnumeratedText( i + 1, accountName.AllocL() ); |
|
245 CleanupStack::PushL( enumItem ); |
|
246 iEnumTexts->AppendL( enumItem ); |
|
247 iPoppedUpTexts->AppendL( accountName.AllocL() ); |
|
248 CleanupStack::Pop( enumItem ); |
|
249 } |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CPbkxRclSettingItem::SetSelectedAccountL |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CPbkxRclSettingItem::SetSelectedAccountL() |
|
257 { |
|
258 FUNC_LOG; |
|
259 TPbkxRemoteContactLookupProtocolAccountId id = |
|
260 PbkxRclUtils::DefaultProtocolAccountIdL(); |
|
261 |
|
262 if ( id.iProtocolUid == KNullUid ) |
|
263 { |
|
264 // no default account selected |
|
265 iSelectedItem = 0; |
|
266 } |
|
267 else |
|
268 { |
|
269 for ( TInt i = 0; i < iProtocolAccounts.Count(); i++ ) |
|
270 { |
|
271 if ( iProtocolAccounts[i]->Id().iProtocolUid == id.iProtocolUid && |
|
272 iProtocolAccounts[i]->Id().iAccountId == id.iAccountId ) |
|
273 { |
|
274 iSelectedItem = i + 1; |
|
275 break; |
|
276 } |
|
277 } |
|
278 |
|
279 if ( iSelectedItem == 0 ) |
|
280 { |
|
281 // adapter stored in cenrep not found, store new value |
|
282 StoreSettingL(); |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CPbkxRclSettingItem::StoreSettingL |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 void CPbkxRclSettingItem::StoreSettingL() |
|
292 { |
|
293 FUNC_LOG; |
|
294 if ( iSelectedItem == 0 ) |
|
295 { |
|
296 // none selected |
|
297 TPbkxRemoteContactLookupProtocolAccountId emptyId( TUid::Uid( 0 ), 0 ); |
|
298 PbkxRclUtils::StoreDefaultProtocolAccountIdL( emptyId ); |
|
299 } |
|
300 else |
|
301 { |
|
302 // none selection is not in the array, so decrease by one |
|
303 CPbkxRemoteContactLookupProtocolAccount* account = |
|
304 iProtocolAccounts[iSelectedItem - 1]; |
|
305 PbkxRclUtils::StoreDefaultProtocolAccountIdL( account->Id() ); |
|
306 } |
|
307 } |
|
308 |