|
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 phonebook memory entry app view methods. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkMemoryEntryAppView.h" |
|
22 #include "CPbkAppUi.h" |
|
23 #include "CPbkCommandFactory.h" |
|
24 #include "CPbkAppGlobals.h" |
|
25 |
|
26 #include <CPbkContactEngine.h> |
|
27 #include <CPbkContactChangeNotifier.h> |
|
28 #include <CPbkContactItem.h> |
|
29 #include <CPbkPhoneNumberSelect.h> |
|
30 #include <CPbkDeleteContactQuery.h> |
|
31 #include <CPbkViewState.h> |
|
32 #include <SharedDataClient.h> |
|
33 #include <CPbkFFSCheck.h> |
|
34 |
|
35 /// Unnamed namespace for local defintions |
|
36 namespace { |
|
37 |
|
38 // LOCAL CONSTANTS |
|
39 |
|
40 // Sufficient amount of memory for contact database modification |
|
41 const TInt KFreeSpaceForDbCompress = 128*1024; // 128kb |
|
42 |
|
43 /// Values for TDeletedContactData::iFlags |
|
44 enum TDeletedContactFlags |
|
45 { |
|
46 EFlagContactDeleted = 0x01, |
|
47 EFlagContactRemoved = 0x02, |
|
48 EFlagContactDeletedAndRemoved = EFlagContactDeleted|EFlagContactRemoved |
|
49 }; |
|
50 |
|
51 } // namespace |
|
52 |
|
53 |
|
54 // ================= MEMBER FUNCTIONS ======================= |
|
55 |
|
56 // CPbkMemoryEntryAppView::TDeletedContactData |
|
57 inline void CPbkMemoryEntryAppView::TDeletedContactData::SetDeleted() |
|
58 { |
|
59 iFlags |= EFlagContactDeleted; |
|
60 } |
|
61 |
|
62 inline void CPbkMemoryEntryAppView::TDeletedContactData::SetRemoved() |
|
63 { |
|
64 iFlags |= EFlagContactRemoved; |
|
65 } |
|
66 |
|
67 inline TBool CPbkMemoryEntryAppView::TDeletedContactData::IsDeletedAndRemoved() const |
|
68 { |
|
69 return ((iFlags & EFlagContactDeletedAndRemoved)==EFlagContactDeletedAndRemoved); |
|
70 } |
|
71 |
|
72 inline void CPbkMemoryEntryAppView::TDeletedContactData::SetIndex(TInt aIndex) |
|
73 { |
|
74 iIndex = aIndex; |
|
75 } |
|
76 |
|
77 inline TInt CPbkMemoryEntryAppView::TDeletedContactData::Index() const |
|
78 { |
|
79 return iIndex; |
|
80 } |
|
81 |
|
82 void CPbkMemoryEntryAppView::TDeletedContactData::Reset() |
|
83 { |
|
84 iFlags = 0; |
|
85 iIndex = -1; |
|
86 } |
|
87 |
|
88 |
|
89 // CPbkMemoryEntryAppView |
|
90 CPbkMemoryEntryAppView::~CPbkMemoryEntryAppView() |
|
91 { |
|
92 if (iAllContactsView) |
|
93 { |
|
94 iAllContactsView->Close(*this); |
|
95 } |
|
96 delete iContactChangeNotifier; |
|
97 delete iPbkFFSCheck; |
|
98 if (iSharedDataClient) |
|
99 { |
|
100 iSharedDataClient->Close(); |
|
101 delete iSharedDataClient; |
|
102 } |
|
103 } |
|
104 |
|
105 void CPbkMemoryEntryAppView::CmdBackL() |
|
106 { |
|
107 CPbkViewState* state = GetViewStateLC(); |
|
108 PbkAppUi()->ActivatePreviousViewL(state); |
|
109 CleanupStack::PopAndDestroy(state); |
|
110 } |
|
111 |
|
112 void CPbkMemoryEntryAppView::CmdDeleteMeL() |
|
113 { |
|
114 CPbkContactItem* ci = ContactItemL(); |
|
115 if (DoAskDeleteL(*ci)) |
|
116 { |
|
117 // Compress contact database in low disk space situation. |
|
118 // This compress guarantees that contact db size decreases |
|
119 // when phone user deletes single contact manually several times. |
|
120 // Compression is done before delete because compression may release |
|
121 // disk space. This extra space may be needed for successful delete |
|
122 // operation. |
|
123 TRAPD(err,FFSCheckL()); |
|
124 if (KErrDiskFull == err) |
|
125 { |
|
126 //Db comppression does not cancel delete operation. |
|
127 TRAP_IGNORE(DbCompactL()); |
|
128 err = KErrNone; |
|
129 } |
|
130 User::LeaveIfError(err); |
|
131 TRAP(err, Engine()->DeleteContactL(ci->Id(), ETrue)) |
|
132 if ( KErrNotFound == err ) |
|
133 { |
|
134 // Ignore KErrNotFound which means that somebody got |
|
135 // the contact first |
|
136 err = KErrNone; |
|
137 } |
|
138 User::LeaveIfError(err); |
|
139 } |
|
140 // Previous view is activated from DB event handlers |
|
141 } |
|
142 |
|
143 TBool CPbkMemoryEntryAppView::DoAskDeleteL(CPbkContactItem& aContact) |
|
144 { |
|
145 CPbkDeleteContactQuery* dlg = CPbkDeleteContactQuery::NewLC(); |
|
146 return (dlg->RunLD(aContact) != 0); |
|
147 } |
|
148 |
|
149 void CPbkMemoryEntryAppView::ContactChangedL() |
|
150 { |
|
151 } |
|
152 |
|
153 void CPbkMemoryEntryAppView::HandleCommandL |
|
154 (TInt aCommandId) |
|
155 { |
|
156 switch (aCommandId) |
|
157 { |
|
158 case EAknSoftkeyBack: |
|
159 { |
|
160 CmdBackL(); |
|
161 break; |
|
162 } |
|
163 |
|
164 case EPbkCmdDeleteMe: |
|
165 { |
|
166 CmdDeleteMeL(); |
|
167 break; |
|
168 } |
|
169 |
|
170 default: |
|
171 { |
|
172 // Forward unknown commands to base class |
|
173 CPbkAppView::HandleCommandL(aCommandId); |
|
174 break; |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 void CPbkMemoryEntryAppView::DoActivateL |
|
180 (const TVwsViewId& /*aPrevViewId*/, |
|
181 TUid /*aCustomMessageId*/, |
|
182 const TDesC8& /*aCustomMessage*/) |
|
183 { |
|
184 if (!iContactChangeNotifier) |
|
185 { |
|
186 iContactChangeNotifier = CPbkContactChangeNotifier::NewL(*Engine(),this); |
|
187 } |
|
188 if (!iAllContactsView) |
|
189 { |
|
190 CContactViewBase* allContactsView = &Engine()->AllContactsView(); |
|
191 allContactsView->OpenL(*this); |
|
192 iAllContactsView = allContactsView; |
|
193 } |
|
194 } |
|
195 |
|
196 void CPbkMemoryEntryAppView::DoDeactivate() |
|
197 { |
|
198 if (iAllContactsView) |
|
199 { |
|
200 iAllContactsView->Close(*this); |
|
201 iAllContactsView = NULL; |
|
202 } |
|
203 delete iContactChangeNotifier; |
|
204 iContactChangeNotifier = NULL; |
|
205 } |
|
206 |
|
207 TBool CPbkMemoryEntryAppView::HandleCommandKeyL |
|
208 (const TKeyEvent& aKeyEvent, TEventCode aType) |
|
209 { |
|
210 if (aType == EEventKey) |
|
211 { |
|
212 switch (aKeyEvent.iCode) |
|
213 { |
|
214 case EKeyBackspace: // Clear key |
|
215 { |
|
216 HandleCommandL(EPbkCmdDeleteMe); |
|
217 return ETrue; |
|
218 } |
|
219 case EKeyOK: |
|
220 { |
|
221 HandleCommandL(EPbkCmdContextMenu); |
|
222 return ETrue; |
|
223 } |
|
224 default: |
|
225 { |
|
226 break; |
|
227 } |
|
228 } |
|
229 } |
|
230 |
|
231 // Key was not handled here |
|
232 return EFalse; |
|
233 } |
|
234 |
|
235 void CPbkMemoryEntryAppView::HandleDatabaseEventL(TContactDbObserverEvent aEvent) |
|
236 { |
|
237 if (aEvent.iContactId==ContactItemId()) |
|
238 { |
|
239 switch (aEvent.iType) |
|
240 { |
|
241 case EContactDbObserverEventContactChanged: |
|
242 { |
|
243 ContactChangedL(); |
|
244 break; |
|
245 } |
|
246 |
|
247 case EContactDbObserverEventContactDeleted: |
|
248 { |
|
249 iDeletedContactData.SetDeleted(); |
|
250 HandleContactDeletedL(); |
|
251 break; |
|
252 } |
|
253 |
|
254 default: |
|
255 { |
|
256 break; |
|
257 } |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 void CPbkMemoryEntryAppView::HandleContactViewEvent |
|
263 (const CContactViewBase& aView,const TContactViewEvent& aEvent) |
|
264 { |
|
265 if (&aView==iAllContactsView && aEvent.iContactId==ContactItemId()) |
|
266 { |
|
267 switch (aEvent.iEventType) |
|
268 { |
|
269 case TContactViewEvent::EItemRemoved: |
|
270 { |
|
271 iDeletedContactData.SetRemoved(); |
|
272 iDeletedContactData.SetIndex(aEvent.iInt); |
|
273 TRAP_IGNORE(HandleContactDeletedL()); |
|
274 break; |
|
275 } |
|
276 |
|
277 default: |
|
278 { |
|
279 break; |
|
280 } |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 void CPbkMemoryEntryAppView::HandleContactDeletedL() |
|
286 { |
|
287 // Ensure that delete event has been received by both HandleDatabaseEventL |
|
288 // and HandleContactViewEvent. HandleContactViewEvent receives a |
|
289 // EItemRemoved and EItemAdded events when a contact is merely renamed. |
|
290 if (iDeletedContactData.IsDeletedAndRemoved()) |
|
291 { |
|
292 // Calculate the contact to focus |
|
293 TContactItemId focusId = KNullContactId; |
|
294 TInt index = iDeletedContactData.Index(); |
|
295 iDeletedContactData.Reset(); |
|
296 if (index >= 0) |
|
297 { |
|
298 const TInt lastIndex = iAllContactsView->CountL() - 1; |
|
299 if (index > lastIndex) |
|
300 { |
|
301 index = lastIndex; |
|
302 } |
|
303 if (index >= 0) |
|
304 { |
|
305 focusId = iAllContactsView->AtL(index); |
|
306 } |
|
307 } |
|
308 |
|
309 // Activate previous view |
|
310 if (focusId != KNullContactId) |
|
311 { |
|
312 CPbkViewState* viewState = CPbkViewState::NewLC(); |
|
313 viewState->SetFocusedContactId(focusId); |
|
314 PbkAppUi()->ActivatePreviousViewL(viewState); |
|
315 CleanupStack::PopAndDestroy(viewState); |
|
316 } |
|
317 else |
|
318 { |
|
319 PbkAppUi()->ActivatePreviousViewL(); |
|
320 } |
|
321 } |
|
322 } |
|
323 |
|
324 inline void CPbkMemoryEntryAppView::FFSCheckL() |
|
325 { |
|
326 if (!iPbkFFSCheck) |
|
327 { |
|
328 iPbkFFSCheck = CPbkFFSCheck::NewL(); |
|
329 } |
|
330 // Leaves with KErrDiskFull if free disk space is below critical level. |
|
331 iPbkFFSCheck->FFSClCheckL(); |
|
332 } |
|
333 |
|
334 inline void CPbkMemoryEntryAppView::RequestFreeDiskSpaceLC() |
|
335 { |
|
336 if (!iSharedDataClient) |
|
337 { |
|
338 iSharedDataClient = new (ELeave) RSharedDataClient(); |
|
339 User::LeaveIfError(iSharedDataClient->Connect()); |
|
340 } |
|
341 iSharedDataClient->RequestFreeDiskSpaceLC(KFreeSpaceForDbCompress); |
|
342 } |
|
343 |
|
344 inline void CPbkMemoryEntryAppView::DbCompactL() |
|
345 { |
|
346 RequestFreeDiskSpaceLC(); |
|
347 Engine()->Database().CompactL(); |
|
348 CleanupStack::PopAndDestroy();// RequestFreeDiskSpaceLC |
|
349 } |
|
350 |
|
351 // End of File |