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