|
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 Phonebook Info view UI control. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkPhonebookInfoDlg.h" |
|
22 |
|
23 #include <PbkView.rsg> |
|
24 #include <CPbkContactEngine.h> |
|
25 #include <StringLoader.h> |
|
26 #include <aknPopup.h> |
|
27 #include <aknlists.h> |
|
28 #include <StringLoader.h> |
|
29 |
|
30 |
|
31 /// Unnamed namespace for local definitions |
|
32 namespace |
|
33 { |
|
34 // LOCAL CONSTANTS AND MACROS |
|
35 _LIT( KNumberFormat, "%d" ); |
|
36 _LIT( KSeparator, "\t" ); |
|
37 const TUint KItemCount = 4; |
|
38 const TInt KKByte = 1024; |
|
39 const TUint KMaxInfoPopupWidth = 16; |
|
40 const TUint KSeparatorSize = 1; |
|
41 } |
|
42 |
|
43 |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 // inline because only one call site |
|
47 inline CPbkPhonebookInfoDlg::CPbkPhonebookInfoDlg |
|
48 (CPbkContactEngine& aEngine) : |
|
49 iEngine(aEngine), iContactsViewReady(EFalse), |
|
50 iGroupsViewReady(EFalse) |
|
51 { |
|
52 } |
|
53 |
|
54 |
|
55 CPbkPhonebookInfoDlg::~CPbkPhonebookInfoDlg() |
|
56 { |
|
57 if(iDestroyed) |
|
58 { |
|
59 *iDestroyed = ETrue; |
|
60 } |
|
61 delete iListBox; |
|
62 |
|
63 if (iAllGroupsView) |
|
64 { |
|
65 iAllGroupsView->Close(*this); |
|
66 } |
|
67 if (iAllContactsView) |
|
68 { |
|
69 iAllContactsView->Close(*this); |
|
70 } |
|
71 } |
|
72 |
|
73 // inline because only one call site |
|
74 inline void CPbkPhonebookInfoDlg::ConstructL() |
|
75 { |
|
76 // Attach to contact views |
|
77 CContactViewBase& allContactsView = iEngine.AllContactsView(); |
|
78 allContactsView.OpenL(*this); |
|
79 iAllContactsView = &allContactsView; |
|
80 |
|
81 CContactViewBase& allGroupsView = iEngine.AllGroupsViewL(); |
|
82 allGroupsView.OpenL(*this); |
|
83 iAllGroupsView = &allGroupsView; |
|
84 |
|
85 iListBox = new(ELeave) CAknSingleHeadingPopupMenuStyleListBox; |
|
86 iPopupList = CAknPopupList::NewL(iListBox, |
|
87 R_AVKON_SOFTKEYS_OK_EMPTY, |
|
88 AknPopupLayouts::EMenuGraphicHeadingWindow); |
|
89 iListBox->ConstructL(iPopupList, EAknListBoxViewerFlags); |
|
90 |
|
91 // Set title |
|
92 HBufC* title = StringLoader::LoadLC(R_QTN_PHOB_QTL_PB_INFO); |
|
93 SetTitleL(*title); |
|
94 CleanupStack::PopAndDestroy(); // title |
|
95 |
|
96 UpdateDataL(); |
|
97 |
|
98 iListBox->CreateScrollBarFrameL(ETrue); |
|
99 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL |
|
100 (CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
101 } |
|
102 |
|
103 EXPORT_C CPbkPhonebookInfoDlg* CPbkPhonebookInfoDlg::NewL |
|
104 (CPbkContactEngine& aEngine) |
|
105 { |
|
106 CPbkPhonebookInfoDlg* self = new(ELeave) CPbkPhonebookInfoDlg(aEngine); |
|
107 CleanupStack::PushL(self); |
|
108 self->ConstructL(); |
|
109 CleanupStack::Pop(); |
|
110 return self; |
|
111 } |
|
112 |
|
113 EXPORT_C void CPbkPhonebookInfoDlg::ExecuteLD() |
|
114 { |
|
115 CleanupStack::PushL(this); |
|
116 TBool thisDestroyed(EFalse); |
|
117 iDestroyed = &thisDestroyed; |
|
118 |
|
119 TRAPD(err, iPopupList->ExecuteLD()); |
|
120 |
|
121 // Just in case |
|
122 if(!thisDestroyed) |
|
123 { |
|
124 iPopupList = NULL; |
|
125 } |
|
126 |
|
127 User::LeaveIfError(err); |
|
128 |
|
129 if(thisDestroyed) |
|
130 { |
|
131 CleanupStack::Pop(); // this |
|
132 } |
|
133 else |
|
134 { |
|
135 CleanupStack::PopAndDestroy(); // this |
|
136 } |
|
137 iDestroyed = NULL; |
|
138 } |
|
139 |
|
140 void CPbkPhonebookInfoDlg::HandleContactViewEvent |
|
141 (const CContactViewBase& aView, |
|
142 const TContactViewEvent& aEvent) |
|
143 { |
|
144 // It's safe to ignore errors |
|
145 TRAP_IGNORE(HandleContactViewEventL(aView,aEvent)); |
|
146 } |
|
147 |
|
148 void CPbkPhonebookInfoDlg::HandleContactViewEventL |
|
149 (const CContactViewBase& aView, |
|
150 const TContactViewEvent& aEvent) |
|
151 { |
|
152 switch (aEvent.iEventType) |
|
153 { |
|
154 case TContactViewEvent::EReady: // FALLTHROUGH |
|
155 case TContactViewEvent::ESortOrderChanged: // FALLTHROUGH |
|
156 case TContactViewEvent::EItemAdded: // FALLTHROUGH |
|
157 case TContactViewEvent::EItemRemoved: |
|
158 { |
|
159 if (&aView == iAllContactsView) |
|
160 { |
|
161 iContactsViewReady = ETrue; |
|
162 } |
|
163 else if (&aView == iAllGroupsView) |
|
164 { |
|
165 iGroupsViewReady = ETrue; |
|
166 } |
|
167 UpdateDataL(); |
|
168 break; |
|
169 } |
|
170 |
|
171 default: |
|
172 { |
|
173 if (&aView == iAllContactsView) |
|
174 { |
|
175 iContactsViewReady = EFalse; |
|
176 } |
|
177 else if (&aView == iAllGroupsView) |
|
178 { |
|
179 iGroupsViewReady = EFalse; |
|
180 } |
|
181 break; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 |
|
187 void CPbkPhonebookInfoDlg::SetTitleL(const TDesC &aTitle) |
|
188 { |
|
189 iPopupList->SetTitleL(aTitle); |
|
190 } |
|
191 |
|
192 MDesCArray* CPbkPhonebookInfoDlg::ConstructDataArrayL() |
|
193 { |
|
194 CDesCArray* array = new(ELeave) CDesCArrayFlat(KItemCount); |
|
195 CleanupStack::PushL(array); |
|
196 |
|
197 // Names |
|
198 HBufC* contacts = ContactsEntryLC(); |
|
199 array->AppendL(*contacts); |
|
200 CleanupStack::PopAndDestroy(contacts); |
|
201 |
|
202 // Groups |
|
203 HBufC* groups = GroupsEntryLC(); |
|
204 array->AppendL(*groups); |
|
205 CleanupStack::PopAndDestroy(groups); |
|
206 |
|
207 // Used memory |
|
208 HBufC* usedMem = UsedMemoryEntryLC(); |
|
209 array->AppendL(*usedMem); |
|
210 CleanupStack::PopAndDestroy(usedMem); |
|
211 |
|
212 // Free memory |
|
213 HBufC* freeMem = FreeMemoryEntryLC(); |
|
214 array->AppendL(*freeMem); |
|
215 CleanupStack::PopAndDestroy(freeMem); |
|
216 |
|
217 CleanupStack::Pop(array); |
|
218 return array; |
|
219 } |
|
220 |
|
221 HBufC* CPbkPhonebookInfoDlg::ContactsEntryLC() |
|
222 { |
|
223 HBufC* dataStr = NULL; |
|
224 |
|
225 if (iContactsViewReady) |
|
226 { |
|
227 // Get contact count |
|
228 const TInt contacsCount = iAllContactsView->CountL(); |
|
229 |
|
230 // Format contacts string |
|
231 HBufC* contactsText = NULL; |
|
232 if (contacsCount == 1) |
|
233 { |
|
234 contactsText = StringLoader::LoadLC(R_QTN_PHOB_PB_INFO_ONE_NAME); |
|
235 } |
|
236 else |
|
237 { |
|
238 contactsText = StringLoader::LoadLC(R_QTN_PHOB_PB_INFO_NAMES); |
|
239 } |
|
240 |
|
241 // Format value string |
|
242 TBuf<KMaxInfoPopupWidth> valueStr; |
|
243 valueStr.Format(KNumberFormat, contacsCount); |
|
244 |
|
245 // Format the string to be returned |
|
246 dataStr = HBufC::NewL(contactsText->Length() + |
|
247 KSeparatorSize + valueStr.Length()); |
|
248 TPtr dataPtr(dataStr->Des()); |
|
249 dataPtr.Append(valueStr); |
|
250 // Convert digits |
|
251 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(dataPtr); |
|
252 dataPtr.Append(KSeparator); |
|
253 dataPtr.Append(*contactsText); |
|
254 |
|
255 CleanupStack::PopAndDestroy(contactsText); |
|
256 } |
|
257 else |
|
258 { |
|
259 dataStr = HBufC::NewL(KNullDesC().Length()); |
|
260 TPtr dataPtr(dataStr->Des()); |
|
261 dataPtr = KNullDesC; |
|
262 } |
|
263 |
|
264 CleanupStack::PushL(dataStr); |
|
265 return dataStr; |
|
266 } |
|
267 |
|
268 HBufC* CPbkPhonebookInfoDlg::GroupsEntryLC() |
|
269 { |
|
270 HBufC* dataStr = NULL; |
|
271 |
|
272 if (iGroupsViewReady) |
|
273 { |
|
274 // Get group count |
|
275 const TInt groupCount = iAllGroupsView->CountL(); |
|
276 |
|
277 // Format group string |
|
278 HBufC* groupsText = NULL; |
|
279 if (groupCount == 1) |
|
280 { |
|
281 groupsText = StringLoader::LoadLC(R_QTN_PHOB_PB_INFO_ONE_GROUP); |
|
282 } |
|
283 else |
|
284 { |
|
285 groupsText = StringLoader::LoadLC(R_QTN_PHOB_PB_INFO_GROUPS); |
|
286 } |
|
287 |
|
288 // Format value string |
|
289 TBuf<KMaxInfoPopupWidth> valueStr; |
|
290 valueStr.Format(KNumberFormat, groupCount); |
|
291 |
|
292 // Format the string to be returned |
|
293 dataStr = HBufC::NewL(groupsText->Length() + |
|
294 KSeparatorSize + valueStr.Length()); |
|
295 TPtr dataPtr(dataStr->Des()); |
|
296 dataPtr.Append(valueStr); |
|
297 // Convert digits |
|
298 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(dataPtr); |
|
299 dataPtr.Append(KSeparator); |
|
300 dataPtr.Append(*groupsText); |
|
301 |
|
302 CleanupStack::PopAndDestroy(groupsText); |
|
303 } |
|
304 else |
|
305 { |
|
306 dataStr = HBufC::NewL(KNullDesC().Length()); |
|
307 TPtr dataPtr(dataStr->Des()); |
|
308 dataPtr = KNullDesC; |
|
309 } |
|
310 |
|
311 CleanupStack::PushL(dataStr); |
|
312 return dataStr; |
|
313 } |
|
314 |
|
315 HBufC* CPbkPhonebookInfoDlg::UsedMemoryEntryLC() |
|
316 { |
|
317 // Format used memory amount |
|
318 HBufC* usedMemoryAmount = StringLoader::LoadLC(R_QTN_SIZE_KB, |
|
319 (iEngine.Database().FileSize() + KKByte/2) / KKByte); |
|
320 |
|
321 // Format used memory string |
|
322 HBufC* usedMemoryText = StringLoader::LoadLC(R_QTN_PHOB_PB_INFO_RESERVED); |
|
323 |
|
324 // Format the string to be returned |
|
325 HBufC* dataStr = HBufC::NewL(usedMemoryText->Length() + |
|
326 KSeparatorSize + usedMemoryAmount->Length()); |
|
327 TPtr dataPtr(dataStr->Des()); |
|
328 dataPtr.Append(*usedMemoryAmount); |
|
329 // Convert digits |
|
330 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(dataPtr); |
|
331 dataPtr.Append(KSeparator); |
|
332 dataPtr.Append(*usedMemoryText); |
|
333 |
|
334 CleanupStack::PopAndDestroy(2); // usedMemoryText, usedMemoryAmount |
|
335 CleanupStack::PushL(dataStr); |
|
336 return dataStr; |
|
337 } |
|
338 |
|
339 HBufC* CPbkPhonebookInfoDlg::FreeMemoryEntryLC() |
|
340 { |
|
341 TVolumeInfo volInfo; |
|
342 User::LeaveIfError(CCoeEnv::Static()->FsSession().Volume(volInfo,EDriveC)); |
|
343 |
|
344 // Format free memory amount |
|
345 HBufC* freeMemoryAmount = StringLoader::LoadLC(R_QTN_SIZE_KB, |
|
346 (I64LOW(volInfo.iFree) / KKByte)); |
|
347 |
|
348 // Format used memory string |
|
349 HBufC* freeMemoryText = StringLoader::LoadLC(R_QTN_PHOB_PB_INFO_FREE); |
|
350 |
|
351 // Format the string to be returned |
|
352 HBufC* dataStr = HBufC::NewL(freeMemoryText->Length() + |
|
353 KSeparatorSize + freeMemoryAmount->Length()); |
|
354 TPtr dataPtr(dataStr->Des()); |
|
355 dataPtr.Append(*freeMemoryAmount); |
|
356 // Convert digits |
|
357 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(dataPtr); |
|
358 dataPtr.Append(KSeparator); |
|
359 dataPtr.Append(*freeMemoryText); |
|
360 |
|
361 CleanupStack::PopAndDestroy(2); // freeMemoryText, freeMemoryAmount |
|
362 CleanupStack::PushL(dataStr); |
|
363 return dataStr; |
|
364 } |
|
365 |
|
366 void CPbkPhonebookInfoDlg::UpdateDataL() |
|
367 { |
|
368 // Construct and set data |
|
369 MDesCArray* array = ConstructDataArrayL(); |
|
370 if (iListBox) |
|
371 { |
|
372 iListBox->Model()->SetItemTextArray(array); |
|
373 iListBox->DrawNow(); |
|
374 } |
|
375 } |
|
376 |
|
377 // End of File |