|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkAssignToGroupCmd.h" |
|
22 #include <eikprogi.h> |
|
23 #include <StringLoader.h> |
|
24 #include <Phonebook.rsg> |
|
25 #include <CPbkAssignToGroup.h> |
|
26 #include <CPbkContactViewListControl.h> |
|
27 #include <MPbkCommandObserver.h> |
|
28 #include <pbkdebug.h> |
|
29 |
|
30 /// Unnamed namespace for local definitions |
|
31 namespace { |
|
32 |
|
33 // LOCAL DEBUG CODE |
|
34 #ifdef _DEBUG |
|
35 enum TPanicCode |
|
36 { |
|
37 EPanicPreCond_ResetWhenDestroyed = 1 |
|
38 }; |
|
39 |
|
40 void Panic(TPanicCode aReason) |
|
41 { |
|
42 _LIT(KPanicText, "CPbkAssignToGroupCmd"); |
|
43 User::Panic(KPanicText,aReason); |
|
44 } |
|
45 #endif |
|
46 |
|
47 } |
|
48 |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 inline CPbkAssignToGroupCmd::CPbkAssignToGroupCmd |
|
53 (CPbkContactEngine& aEngine, |
|
54 CPbkContactViewListControl& aUiControl) : |
|
55 CActive(EPriorityIdle), |
|
56 iEngine(aEngine), |
|
57 iUiControl(aUiControl), |
|
58 iFocusId(KNullContactId), |
|
59 iDialogDismissed(ETrue) // there is no dialog at this point |
|
60 { |
|
61 PBK_DEBUG_PRINT |
|
62 (PBK_DEBUG_STRING("CPbkAssignToGroupCmd::CPbkAssignToGroupCmd(0x%x)"), |
|
63 this); |
|
64 |
|
65 CActiveScheduler::Add(this); |
|
66 } |
|
67 |
|
68 inline void CPbkAssignToGroupCmd::ConstructL |
|
69 (const CContactIdArray& aContacts, |
|
70 TContactItemId aGroupId) |
|
71 { |
|
72 iAssignToGroupProcess = CPbkAssignToGroup::NewLC(iEngine, aContacts, aGroupId); |
|
73 CleanupStack::Pop(iAssignToGroupProcess); |
|
74 } |
|
75 |
|
76 CPbkAssignToGroupCmd* CPbkAssignToGroupCmd::NewL |
|
77 (CPbkContactEngine& aEngine, |
|
78 const CContactIdArray& aContacts, |
|
79 CPbkContactViewListControl& aUiControl, |
|
80 TContactItemId aGroupId) |
|
81 { |
|
82 CPbkAssignToGroupCmd* self = new(ELeave) CPbkAssignToGroupCmd(aEngine, aUiControl); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(aContacts, aGroupId); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 void CPbkAssignToGroupCmd::ResetWhenDestroyed |
|
90 (CPbkAssignToGroupCmd** aSelfPtr) |
|
91 { |
|
92 __ASSERT_DEBUG(!aSelfPtr || *aSelfPtr==this, |
|
93 Panic(EPanicPreCond_ResetWhenDestroyed)); |
|
94 |
|
95 iSelfPtr = aSelfPtr; |
|
96 } |
|
97 |
|
98 CPbkAssignToGroupCmd::~CPbkAssignToGroupCmd() |
|
99 { |
|
100 PBK_DEBUG_PRINT |
|
101 (PBK_DEBUG_STRING("CPbkAssignToGroupCmd::~CPbkAssignToGroupCmd(0x%x)"), |
|
102 this); |
|
103 |
|
104 Cancel(); |
|
105 |
|
106 if ( !iRedButtonPressed ) |
|
107 { |
|
108 // Unblank and redraw UI control |
|
109 iUiControl.SetBlank(EFalse); |
|
110 } |
|
111 |
|
112 DeleteProgressNote(); |
|
113 delete iAssignToGroupProcess; |
|
114 |
|
115 if (iSelfPtr) |
|
116 { |
|
117 *iSelfPtr = NULL; |
|
118 } |
|
119 iDestroyed = ETrue; |
|
120 } |
|
121 |
|
122 void CPbkAssignToGroupCmd::ExecuteLD() |
|
123 { |
|
124 PBK_DEBUG_PRINT |
|
125 (PBK_DEBUG_STRING("CPbkAssignToGroupCmd::ExecuteLD(0x%x)"), |
|
126 this); |
|
127 CleanupStack::PushL(this); |
|
128 |
|
129 // save focus |
|
130 iFocusId = iUiControl.FocusedContactIdL(); |
|
131 |
|
132 // Blank UI control to avoid flicker |
|
133 iUiControl.SetBlank(ETrue); |
|
134 |
|
135 // delete previous note |
|
136 DeleteProgressNote(); |
|
137 |
|
138 // Start assignation process. ProcessFinished() will be called when execution |
|
139 // is finished. |
|
140 CAknProgressDialog* progressDialog = new(ELeave) CAknProgressDialog( |
|
141 reinterpret_cast<CEikDialog**>(NULL), ETrue); |
|
142 progressDialog->PrepareLC(R_QTN_PHOB_WNOTE_ADD_TO_GROUP); |
|
143 iProgressDlgInfo = progressDialog->GetProgressInfoL(); |
|
144 iProgressDlgInfo->SetFinalValue(iAssignToGroupProcess->TotalNumberOfSteps()); |
|
145 progressDialog->SetCallback(this); |
|
146 iDialogDismissed = EFalse; |
|
147 progressDialog->RunLD(); |
|
148 |
|
149 iProgressDialog = progressDialog; |
|
150 |
|
151 // issue request for entry assignation |
|
152 IssueRequest(); |
|
153 |
|
154 CleanupStack::Pop(this); |
|
155 } |
|
156 |
|
157 void CPbkAssignToGroupCmd::AddObserver |
|
158 (MPbkCommandObserver& aObserver) |
|
159 { |
|
160 iCommandObserver = &aObserver; |
|
161 } |
|
162 |
|
163 void CPbkAssignToGroupCmd::DoCancel() |
|
164 { |
|
165 } |
|
166 |
|
167 void CPbkAssignToGroupCmd::RunL() |
|
168 { |
|
169 PBK_DEBUG_PRINT |
|
170 (PBK_DEBUG_STRING("CPbkAssignToGroupCmd::StepL()"), |
|
171 this); |
|
172 |
|
173 if (!iAssignToGroupProcess->IsProcessDone() && !iDialogDismissed) |
|
174 { |
|
175 // process one step |
|
176 iAssignToGroupProcess->StepL(); |
|
177 ++iAssignedCount; |
|
178 |
|
179 // Incrementing progress of the process |
|
180 iProgressDlgInfo->SetAndDraw(iAssignedCount); |
|
181 |
|
182 // issue request to delete next item |
|
183 IssueRequest(); |
|
184 } |
|
185 else |
|
186 { |
|
187 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkAssignToGroupCmd::RunL process completed start")); |
|
188 |
|
189 // process is completed, all entries have been assigned |
|
190 ProcessFinished(*iAssignToGroupProcess); |
|
191 |
|
192 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkAssignToGroupCmd::RunL process completed end")); |
|
193 } |
|
194 |
|
195 PBK_DEBUG_PRINT |
|
196 (PBK_DEBUG_STRING("CPbkAssignToGroupCmd::RunL end")); |
|
197 } |
|
198 |
|
199 TInt CPbkAssignToGroupCmd::RunError |
|
200 (TInt aError) |
|
201 { |
|
202 TInt result = iAssignToGroupProcess->HandleStepError(aError); |
|
203 Cancel(); |
|
204 ProcessFinished(*iAssignToGroupProcess); |
|
205 return result; |
|
206 } |
|
207 |
|
208 void CPbkAssignToGroupCmd::ProcessFinished |
|
209 (MPbkBackgroundProcess& /*aProcess*/) |
|
210 { |
|
211 PBK_DEBUG_PRINT |
|
212 (PBK_DEBUG_STRING("CPbkAssignToGroupCmd::ProcessFinished(0x%x)"), |
|
213 this); |
|
214 |
|
215 if ( !iRedButtonPressed ) |
|
216 { |
|
217 // Clear listbox selections |
|
218 iUiControl.HandleMarkableListUpdateAfterCommandExecution(); |
|
219 |
|
220 // restore focus |
|
221 if (iFocusId != KNullContactId) |
|
222 { |
|
223 TInt index = -1; |
|
224 TRAP_IGNORE(index = iUiControl.FindContactIdL(iFocusId)); |
|
225 if (index >= 0) |
|
226 { |
|
227 iUiControl.SetCurrentItemIndex(index); |
|
228 } |
|
229 } |
|
230 |
|
231 // Unblank and redraw UI control |
|
232 iUiControl.SetBlank(EFalse); |
|
233 iUiControl.DrawNow(); |
|
234 } |
|
235 |
|
236 DeleteProgressNote(); |
|
237 } |
|
238 |
|
239 void CPbkAssignToGroupCmd::DeleteProgressNote() |
|
240 { |
|
241 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkAssignToGroupCmd::DeleteProgressNote start")); |
|
242 |
|
243 if (iProgressDialog && !iDialogDismissed) |
|
244 { |
|
245 // deletes the dialog |
|
246 TRAPD(err, iProgressDialog->ProcessFinishedL()); |
|
247 if (err != KErrNone) |
|
248 { |
|
249 delete iProgressDialog; |
|
250 } |
|
251 iProgressDialog = NULL; |
|
252 } |
|
253 |
|
254 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkAssignToGroupCmd::DeleteProgressNote end")); |
|
255 } |
|
256 |
|
257 void CPbkAssignToGroupCmd::IssueRequest() |
|
258 { |
|
259 TRequestStatus* status = &iStatus; |
|
260 User::RequestComplete(status, KErrNone); |
|
261 SetActive(); |
|
262 } |
|
263 |
|
264 void CPbkAssignToGroupCmd::DialogDismissedL( TInt aButtonId ) |
|
265 { |
|
266 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("CPbkAssignToGroupCmd::DialogDismissedL")); |
|
267 iDialogDismissed = ETrue; |
|
268 if ( aButtonId == KErrNotFound ) |
|
269 { |
|
270 iRedButtonPressed = ETrue; |
|
271 } |
|
272 |
|
273 // notify command owner that the command has finished |
|
274 iCommandObserver->CommandFinished(*this); |
|
275 } |
|
276 |
|
277 // End of File |