|
1 /* |
|
2 * Copyright (c) 2010 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: Class for handling popup query. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <s32mem.h> |
|
21 #include <aknappui.h> |
|
22 #include <coemain.h> |
|
23 #include <phoneappcommands.hrh> |
|
24 |
|
25 #include "edcontactorserviceheaders.h" |
|
26 |
|
27 #include <edcontactor.rsg> |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 // |
|
31 |
|
32 // -------------------------------------------------------------------------- |
|
33 // CEDContactorPopupHandler::NewL |
|
34 // -------------------------------------------------------------------------- |
|
35 // |
|
36 CEDContactorPopupHandler* CEDContactorPopupHandler::NewL() |
|
37 { |
|
38 CEDContactorPopupHandler* self = new (ELeave) CEDContactorPopupHandler(); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // -------------------------------------------------------------------------- |
|
46 // CEDContactorPopupHandler::~CEDContactorPopupHandler |
|
47 // -------------------------------------------------------------------------- |
|
48 // |
|
49 CEDContactorPopupHandler::~CEDContactorPopupHandler() |
|
50 { |
|
51 LOGSTRING("CEDContactorPopupHandler::~CEDContactorPopupHandler"); |
|
52 delete iServiceHandler; |
|
53 delete iSchedulerWait; |
|
54 iCoeEnv.DeleteResourceFile (iResourceOffset); |
|
55 delete iQueryResults; |
|
56 } |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CEDContactorPopupHandler::LaunchPopupL |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 TDesC& CEDContactorPopupHandler::LaunchPopupL( |
|
63 const TDesC8& aContactLinkArray, |
|
64 TAiwCommAddressSelectType aCommAddressSelectType, |
|
65 TBool aUseDefaults ) |
|
66 { |
|
67 LOGSTRING("CEDContactorPopupHandler::LaunchPopupL"); |
|
68 |
|
69 __ASSERT_ALWAYS (NULL != &aContactLinkArray, User::Leave (KErrArgument)); |
|
70 __ASSERT_ALWAYS (0 < aContactLinkArray.Size(), User::Leave (KErrArgument)); |
|
71 |
|
72 TUint fetchFlags = 0; |
|
73 |
|
74 // Stop scheduler just in case this is called while operation is still ongoing. |
|
75 AsyncStop(); |
|
76 |
|
77 // Set service data |
|
78 TAiwSingleItemSelectionDataV3 data; |
|
79 |
|
80 if (!aUseDefaults) |
|
81 { |
|
82 fetchFlags |= ::EDoNotUseDefaultField; |
|
83 } |
|
84 |
|
85 data.SetFlags(fetchFlags); |
|
86 data.SetCommAddressSelectType(aCommAddressSelectType); |
|
87 CAiwGenericParamList& inParamList = iServiceHandler->InParamListL(); |
|
88 inParamList.AppendL(TAiwGenericParam(EGenericParamContactSelectionData, |
|
89 TAiwVariant(TAiwSingleItemSelectionDataV3Pckg(data)))); |
|
90 |
|
91 // Set contactlink |
|
92 inParamList.AppendL(TAiwGenericParam(EGenericParamContactLinkArray, |
|
93 TAiwVariant(aContactLinkArray))); |
|
94 |
|
95 iServiceHandler->ExecuteServiceCmdL(KAiwCmdSelect, inParamList, |
|
96 iServiceHandler->OutParamListL(), 0, this); |
|
97 |
|
98 // Waiting for popup selection. |
|
99 // Make this whole operation look synchronous |
|
100 CAknAppUi* appUi = static_cast<CAknAppUi*>( iCoeEnv.AppUi() ); |
|
101 appUi->HandleCommandL( EPhoneCmdBlockingDialogLaunched ); |
|
102 iSchedulerWait->Start(); |
|
103 appUi->HandleCommandL( EPhoneCmdBlockingDialogClosed ); |
|
104 |
|
105 User::LeaveIfError(iError); |
|
106 |
|
107 LOGSTRING("CEDContactorPopupHandler::LaunchPopupL: Done."); |
|
108 |
|
109 return *iQueryResults; |
|
110 } |
|
111 |
|
112 // -------------------------------------------------------------------------- |
|
113 // CEDContactorPopupHandler::ClosePopupL |
|
114 // -------------------------------------------------------------------------- |
|
115 // |
|
116 void CEDContactorPopupHandler::ClosePopupL() |
|
117 { |
|
118 if ( iSchedulerWait->IsStarted() ) |
|
119 { |
|
120 iServiceHandler->ExecuteServiceCmdL( KAiwCmdSelect, |
|
121 iServiceHandler->InParamListL(), |
|
122 iServiceHandler->OutParamListL(), |
|
123 KAiwOptCancel, |
|
124 this ); |
|
125 } |
|
126 } |
|
127 |
|
128 // -------------------------------------------------------------------------- |
|
129 // CEDContactorPopupHandler::HandleNotifyL |
|
130 // -------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CEDContactorPopupHandler::HandleNotifyL(TInt aCmdId, TInt aEventId, |
|
133 CAiwGenericParamList& aEventParamList, |
|
134 const CAiwGenericParamList& /*aInParamList*/) |
|
135 { |
|
136 LOGSTRING("CEDContactorPopupHandler::HandleNotifyL"); |
|
137 TInt returnValue = KErrNone; |
|
138 |
|
139 if (aCmdId == KAiwCmdSelect) |
|
140 { |
|
141 switch(aEventId) |
|
142 { |
|
143 case KAiwEventCompleted: |
|
144 { |
|
145 LOGSTRING("CEDContactorPopupHandler::HandleNotifyL: KAiwEventCompleted"); |
|
146 // Selection done. |
|
147 // Read and store results |
|
148 TRAP(iError, ReadFieldDataL(aEventParamList)); |
|
149 } |
|
150 break; |
|
151 |
|
152 case KAiwEventCanceled: |
|
153 LOGSTRING("CEDContactorPopupHandler::HandleNotifyL: KAiwEventCanceled"); |
|
154 // Selection canceled. |
|
155 iError = KErrCancel; |
|
156 break; |
|
157 |
|
158 case KAiwEventError: |
|
159 case KAiwEventStopped: |
|
160 LOGSTRING("CEDContactorPopupHandler::HandleNotifyL: KAiwEventError or KAiwEventStopped"); |
|
161 // Error occurred. |
|
162 iError = KErrGeneral; |
|
163 break; |
|
164 |
|
165 case KAiwEventQueryExit: |
|
166 iError = KErrAbort; |
|
167 returnValue = EFalse; // Telephony must not be allowed to be closed down |
|
168 break; |
|
169 |
|
170 default: |
|
171 LOGSTRING("CEDContactorPopupHandler::HandleNotifyL: Unknown"); |
|
172 iError = KErrGeneral; |
|
173 break; |
|
174 } |
|
175 // Stop scheduler if service execution has finished. |
|
176 if ( aEventId != KAiwEventQueryExit ) |
|
177 { |
|
178 AsyncStop(); |
|
179 } |
|
180 } |
|
181 |
|
182 LOGSTRING("CEDContactorPopupHandler::HandleNotifyL: Done."); |
|
183 return returnValue; |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CEDContactorPopupHandler::CEDContactorPopupHandler |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 CEDContactorPopupHandler::CEDContactorPopupHandler() : |
|
191 iCoeEnv(*CCoeEnv::Static()), |
|
192 iError(KErrNone) |
|
193 { |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CEDContactorPopupHandler::ConstructL |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 void CEDContactorPopupHandler::ConstructL() |
|
201 { |
|
202 LOGSTRING("CEDContactorPopupHandler::ConstructL"); |
|
203 |
|
204 PrepareResourcesL(); |
|
205 |
|
206 iServiceHandler = CAiwServiceHandler::NewL(); |
|
207 iServiceHandler->AttachL(R_EDCONTACTORSERVICE_CONTACT_SELECTION_INTEREST); |
|
208 |
|
209 iSchedulerWait = new (ELeave) CActiveSchedulerWait(); |
|
210 |
|
211 LOGSTRING("CEDContactorPopupHandler::ConstructL: Done."); |
|
212 } |
|
213 |
|
214 // -------------------------------------------------------------------------- |
|
215 // CEDContactorPopupHandler::PrepareResourcesL |
|
216 // -------------------------------------------------------------------------- |
|
217 // |
|
218 void CEDContactorPopupHandler::PrepareResourcesL() |
|
219 { |
|
220 LOGSTRING("CEDContactorPopupHandler::PrepareResourcesL"); |
|
221 |
|
222 // preparing resources for use |
|
223 TFileName fileName; |
|
224 fileName.Append (KEDContactorServiceResourceFileName); |
|
225 |
|
226 BaflUtils::NearestLanguageFile (iCoeEnv.FsSession (), fileName); |
|
227 if (ConeUtils::FileExists (fileName)) |
|
228 { |
|
229 iResourceOffset = iCoeEnv.AddResourceFileL (fileName); |
|
230 } |
|
231 else // not found from user drive, leave badly. |
|
232 { |
|
233 LOGSTRING("CEDContactorPopupHandler::PrepareResourcesL: Resource file not exists."); |
|
234 User::Leave (KErrGeneral); |
|
235 } |
|
236 |
|
237 LOGSTRING("CEDContactorPopupHandler::PrepareResourcesL: Done."); |
|
238 } |
|
239 |
|
240 // -------------------------------------------------------------------------- |
|
241 // CEDContactorPopupHandler::ReadFieldDataL |
|
242 // -------------------------------------------------------------------------- |
|
243 // |
|
244 void CEDContactorPopupHandler::ReadFieldDataL( |
|
245 CAiwGenericParamList& aEventParamList) |
|
246 { |
|
247 LOGSTRING("CEDContactorPopupHandler::ReadFieldDataL"); |
|
248 |
|
249 if (iQueryResults) |
|
250 { |
|
251 delete iQueryResults; |
|
252 iQueryResults = NULL; |
|
253 } |
|
254 |
|
255 TInt index = 1; // Get field data from index 1 |
|
256 const TAiwGenericParam* param = |
|
257 aEventParamList.FindFirst(index, EGenericParamContactFieldData); |
|
258 if (KErrNotFound != index) |
|
259 { |
|
260 TInt length = param->Value().AsDes().Length(); |
|
261 iQueryResults = HBufC::NewL(length); |
|
262 iQueryResults->Des().Append(param->Value().AsDes()); |
|
263 |
|
264 // Data must be found! |
|
265 if (0 >= iQueryResults->Length()) |
|
266 { |
|
267 LOGSTRING("CEDContactorPopupHandler::ReadFieldDataL: Failed to get field data!"); |
|
268 User::Leave(KErrGeneral); |
|
269 } |
|
270 } |
|
271 else |
|
272 { |
|
273 LOGSTRING("CEDContactorPopupHandler::ReadFieldDataL: Not found!"); |
|
274 User::Leave(KErrNotFound); |
|
275 } |
|
276 |
|
277 LOGSTRING("CEDContactorPopupHandler::ReadFieldDataL: Done."); |
|
278 } |
|
279 |
|
280 // -------------------------------------------------------------------------- |
|
281 // CEDContactorPopupHandler::AsyncStop |
|
282 // -------------------------------------------------------------------------- |
|
283 // |
|
284 void CEDContactorPopupHandler::AsyncStop() |
|
285 { |
|
286 LOGSTRING("CEDContactorPopupHandler::AsyncStop"); |
|
287 |
|
288 if(iSchedulerWait->IsStarted()) |
|
289 { |
|
290 iSchedulerWait->AsyncStop(); |
|
291 } |
|
292 |
|
293 LOGSTRING("CEDContactorPopupHandler::AsyncStop: Done."); |
|
294 } |
|
295 |
|
296 // End of file |