|
1 /* |
|
2 * Copyright (c) 2002 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 * Provides methods for UI control for Phonebook's "Add to group". |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkGroupPopup.h" // This class |
|
22 #include <aknlists.h> // AknListBoxUtils |
|
23 #include <aknPopup.h> // CAknPopupList |
|
24 |
|
25 #include "CPbkInputAbsorber.h" |
|
26 #include "CPbkContactGroupListModel.h" |
|
27 |
|
28 #include <CPbkContactEngine.h> // Phonebook engine |
|
29 #include <CPbkContactItem.h> // CPbkContactItem |
|
30 |
|
31 /// Unnamed namespace for local defintions |
|
32 namespace { |
|
33 |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 #ifdef _DEBUG |
|
36 enum TPanicCode |
|
37 { |
|
38 EPanicPostCond_Constructor = 1, |
|
39 EPanicPreCond_ExecuteLD, |
|
40 EPanicPreCond_RunPopupL, |
|
41 EPanicLogic_RunPopupL, |
|
42 EPanicPostCond_ExecuteLD, |
|
43 EPanicPreCond_ResetWhenDestroyed |
|
44 }; |
|
45 |
|
46 void Panic(TPanicCode aReason) |
|
47 { |
|
48 _LIT(KPanicText, "CPbkGroupPopup"); |
|
49 User::Panic(KPanicText, aReason); |
|
50 } |
|
51 #endif // _DEBUG |
|
52 |
|
53 } // namespace |
|
54 |
|
55 // MODULE DATA STRUCTURES |
|
56 |
|
57 NONSHARABLE_CLASS(CPbkGroupPopup::CPopupList) : |
|
58 public CAknPopupList |
|
59 { |
|
60 public: |
|
61 /** |
|
62 * Static constructor. |
|
63 * @param aListbox the listbox to use in the list |
|
64 * @param aCbaResource softkey resource |
|
65 * @param aType popup layout type |
|
66 * @return a new instance of this class |
|
67 */ |
|
68 static CPopupList* NewL(CEikListBox* aListBox, TInt aCbaResource, |
|
69 AknPopupLayouts::TAknPopupLayouts aType=AknPopupLayouts::EMenuWindow); |
|
70 /** |
|
71 * Destructor. |
|
72 */ |
|
73 ~CPopupList(); |
|
74 /** |
|
75 * Resets the object pointer after destruction. |
|
76 */ |
|
77 void ResetWhenDestroyed(CPopupList** aSelf); |
|
78 |
|
79 protected: |
|
80 /** |
|
81 * Constructor. |
|
82 */ |
|
83 CPopupList(); |
|
84 |
|
85 private: // Data |
|
86 /// Ref: self pointer |
|
87 CPopupList** iSelfPtr; |
|
88 }; |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 // ================= MEMBER FUNCTIONS ======================= |
|
94 |
|
95 // CPbkGroupPopup::CPopupList |
|
96 inline CPbkGroupPopup::CPopupList::CPopupList() |
|
97 { |
|
98 } |
|
99 |
|
100 CPbkGroupPopup::CPopupList* CPbkGroupPopup::CPopupList::NewL |
|
101 (CEikListBox* aListBox, |
|
102 TInt aCbaResource, |
|
103 AknPopupLayouts::TAknPopupLayouts aType) |
|
104 { |
|
105 CPopupList* self = new(ELeave) CPopupList; |
|
106 CleanupStack::PushL(self); |
|
107 self->CAknPopupList::ConstructL(aListBox, aCbaResource, aType); |
|
108 CleanupStack::Pop(self); |
|
109 return self; |
|
110 } |
|
111 |
|
112 CPbkGroupPopup::CPopupList::~CPopupList() |
|
113 { |
|
114 if (iSelfPtr) |
|
115 { |
|
116 *iSelfPtr = NULL; |
|
117 } |
|
118 } |
|
119 |
|
120 void CPbkGroupPopup::CPopupList::ResetWhenDestroyed(CPopupList** aSelf) |
|
121 { |
|
122 __ASSERT_DEBUG(!aSelf || *aSelf==this, Panic(EPanicPreCond_ResetWhenDestroyed)); |
|
123 iSelfPtr = aSelf; |
|
124 } |
|
125 |
|
126 |
|
127 // CPbkGroupPopup::TParams |
|
128 CPbkGroupPopup::TParams::TParams |
|
129 (CContactViewBase& aGroupView, |
|
130 TInt aInitialSoftkeyResId, |
|
131 TInt aSoftKeyResId) : |
|
132 iGroupView(&aGroupView), |
|
133 iInitialSoftkeyResId(aInitialSoftkeyResId), |
|
134 iSoftkeyResId(aSoftKeyResId), |
|
135 iPrompt(NULL), |
|
136 iEmptyText(NULL), |
|
137 iListBoxFlags(0), |
|
138 iSelectedGroupId(KNullContactId) |
|
139 { |
|
140 } |
|
141 |
|
142 |
|
143 // CPbkGroupPopup |
|
144 inline CPbkGroupPopup::CPbkGroupPopup(TParams& aParams) : |
|
145 iParams(aParams) |
|
146 { |
|
147 __ASSERT_DEBUG |
|
148 (!iInputAbsorber && !iListBox && !iPopupList && !iDestroyedPtr, |
|
149 Panic(EPanicPostCond_Constructor)); |
|
150 } |
|
151 |
|
152 inline void CPbkGroupPopup::ConstructL() |
|
153 { |
|
154 } |
|
155 |
|
156 CPbkGroupPopup* CPbkGroupPopup::NewL(TParams& aParams) |
|
157 { |
|
158 CPbkGroupPopup* self = new(ELeave) CPbkGroupPopup(aParams); |
|
159 CleanupStack::PushL(self); |
|
160 self->ConstructL(); |
|
161 CleanupStack::Pop(self); |
|
162 return self; |
|
163 } |
|
164 |
|
165 CPbkGroupPopup::~CPbkGroupPopup() |
|
166 { |
|
167 if (iDestroyedPtr) |
|
168 { |
|
169 *iDestroyedPtr = ETrue; |
|
170 } |
|
171 if (iSelfPtr) |
|
172 { |
|
173 *iSelfPtr = NULL; |
|
174 } |
|
175 if (iPopupList) |
|
176 { |
|
177 iPopupList->CancelPopup(); |
|
178 } |
|
179 iParams.iGroupView->Close(*this); |
|
180 delete iListBox; |
|
181 delete iInputAbsorber; |
|
182 } |
|
183 |
|
184 TInt CPbkGroupPopup::ExecuteLD() |
|
185 { |
|
186 __ASSERT_DEBUG(!iListBox && !iPopupList, Panic(EPanicPreCond_ExecuteLD)); |
|
187 |
|
188 TBool thisDestroyed = EFalse; |
|
189 iDestroyedPtr = &thisDestroyed; |
|
190 CleanupStack::PushL(this); |
|
191 |
|
192 iInputAbsorber = CPbkInputAbsorber::NewL(iParams.iInitialSoftkeyResId); |
|
193 iInputAbsorber->SetCommandObserver(this); |
|
194 |
|
195 // Register to receive view events |
|
196 iParams.iGroupView->OpenL(*this); |
|
197 |
|
198 // Use CPbkInputAbsorber to provide modal behaviour until we get the popup list up |
|
199 iInputAbsorber->Wait(); |
|
200 |
|
201 TInt result = 0; |
|
202 if (thisDestroyed) |
|
203 { |
|
204 CleanupStack::Pop(this); |
|
205 } |
|
206 else |
|
207 { |
|
208 result = iResult; |
|
209 if (result) |
|
210 { |
|
211 const TInt index = iListBox->CurrentItemIndex(); |
|
212 iParams.iSelectedGroupId = iParams.iGroupView->AtL(index); |
|
213 } |
|
214 __ASSERT_DEBUG(!result || iParams.iSelectedGroupId!=KNullContactId, |
|
215 Panic(EPanicPostCond_ExecuteLD)); |
|
216 CleanupStack::PopAndDestroy(this); |
|
217 } |
|
218 return result; |
|
219 } |
|
220 |
|
221 void CPbkGroupPopup::ResetWhenDestroyed(CPbkGroupPopup** aSelfPtr) |
|
222 { |
|
223 __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr==this, |
|
224 Panic(EPanicPreCond_ResetWhenDestroyed)); |
|
225 iSelfPtr = aSelfPtr; |
|
226 } |
|
227 |
|
228 void CPbkGroupPopup::HandleContactViewEvent |
|
229 (const CContactViewBase& /*aView*/, |
|
230 const TContactViewEvent& aEvent) |
|
231 { |
|
232 TRAPD(err, DoHandleContactViewEventL(aEvent)); |
|
233 if (err != KErrNone) |
|
234 { |
|
235 CCoeEnv::Static()->HandleError(err); |
|
236 Close(); |
|
237 } |
|
238 } |
|
239 |
|
240 void CPbkGroupPopup::ProcessCommandL(TInt aCommandId) |
|
241 { |
|
242 switch (aCommandId) |
|
243 { |
|
244 case EAknSoftkeyCancel: // FALLTHROUGH |
|
245 case EAknSoftkeyBack: // FALLTHROUGH |
|
246 case EAknSoftkeyNo: // FALLTHROUGH |
|
247 case EAknSoftkeyClose: // FALLTHROUGH |
|
248 case EAknSoftkeyExit: |
|
249 { |
|
250 Close(); |
|
251 break; |
|
252 } |
|
253 |
|
254 default: |
|
255 break; |
|
256 } |
|
257 } |
|
258 |
|
259 void CPbkGroupPopup::RunPopupL() |
|
260 { |
|
261 __ASSERT_DEBUG(iInputAbsorber->IsWaiting(), Panic(EPanicPreCond_RunPopupL)); |
|
262 |
|
263 // Create a list box |
|
264 iListBox = static_cast<CEikColumnListBox*> |
|
265 (EikControlFactory::CreateByTypeL(EAknCtSinglePopupMenuListBox).iControl); |
|
266 |
|
267 // Create a popup list |
|
268 iPopupList = CPopupList::NewL(iListBox, iParams.iSoftkeyResId); |
|
269 iPopupList->ResetWhenDestroyed(&iPopupList); |
|
270 |
|
271 // Init list box |
|
272 iListBox->ConstructL(iPopupList, iParams.iListBoxFlags | CEikListBox::ELeftDownInViewRect); |
|
273 CPbkContactGroupListModel* listBoxModel = CPbkContactGroupListModel::NewL |
|
274 (*iParams.iGroupView); |
|
275 iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray); |
|
276 iListBox->Model()->SetItemTextArray(listBoxModel); |
|
277 iListBox->CreateScrollBarFrameL(ETrue); |
|
278 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL |
|
279 (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
280 |
|
281 // Set empty text for the listbox |
|
282 if (iParams.iEmptyText) |
|
283 { |
|
284 iListBox->View()->SetListEmptyTextL(*iParams.iEmptyText); |
|
285 } |
|
286 |
|
287 // set title of popuplist |
|
288 if (iParams.iPrompt && iParams.iPrompt->Length() > 0) |
|
289 { |
|
290 iPopupList->SetTitleL(*iParams.iPrompt); |
|
291 } |
|
292 |
|
293 iResult = iPopupList->ExecuteLD(); |
|
294 __ASSERT_DEBUG(!iPopupList, Panic(EPanicLogic_RunPopupL)); |
|
295 |
|
296 // Wait is started in ExecuteLD() |
|
297 iInputAbsorber->StopWait(); |
|
298 } |
|
299 |
|
300 void CPbkGroupPopup::Close() |
|
301 { |
|
302 // Wait is started in ExecuteLD() |
|
303 iInputAbsorber->StopWait(); |
|
304 delete this; |
|
305 } |
|
306 |
|
307 void CPbkGroupPopup::DoHandleContactViewEventL |
|
308 (const TContactViewEvent& aEvent) |
|
309 { |
|
310 switch (aEvent.iEventType) |
|
311 { |
|
312 case TContactViewEvent::EReady: |
|
313 { |
|
314 // Run the popup list query |
|
315 RunPopupL(); |
|
316 break; |
|
317 } |
|
318 |
|
319 case TContactViewEvent::ESortOrderChanged: |
|
320 { |
|
321 if (iListBox) |
|
322 { |
|
323 iListBox->Reset(); |
|
324 iListBox->DrawNow(); |
|
325 } |
|
326 break; |
|
327 } |
|
328 |
|
329 case TContactViewEvent::EItemAdded: |
|
330 { |
|
331 if (iListBox) |
|
332 { |
|
333 const TInt focusIndex = iListBox->CurrentItemIndex(); |
|
334 if (focusIndex >= aEvent.iInt) |
|
335 { |
|
336 iListBox->SetCurrentItemIndex(focusIndex + 1); |
|
337 } |
|
338 iListBox->HandleItemAdditionL(); |
|
339 } |
|
340 break; |
|
341 } |
|
342 |
|
343 case TContactViewEvent::EItemRemoved: |
|
344 { |
|
345 if (iListBox) |
|
346 { |
|
347 const TInt focusIndex = iListBox->CurrentItemIndex(); |
|
348 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL |
|
349 (iListBox, focusIndex, focusIndex==aEvent.iInt); |
|
350 } |
|
351 break; |
|
352 } |
|
353 |
|
354 case TContactViewEvent::EUnavailable: |
|
355 { |
|
356 Close(); |
|
357 break; |
|
358 } |
|
359 |
|
360 case TContactViewEvent::ESortError: // FALLTHROUGH |
|
361 case TContactViewEvent::EServerError: // FALLTHROUGH |
|
362 case TContactViewEvent::EIndexingError: |
|
363 { |
|
364 CCoeEnv::Static()->HandleError(aEvent.iInt); |
|
365 Close(); |
|
366 break; |
|
367 } |
|
368 |
|
369 default: |
|
370 { |
|
371 Close(); |
|
372 break; |
|
373 } |
|
374 } |
|
375 } |
|
376 |
|
377 |
|
378 // End of File |