|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Organize(reorder) top contacts command |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2NlxMoveTopContactsCmd.h" |
|
21 #include "CPbk2NlxMoveTopContactsDlg.h" |
|
22 #include "CPbk2NlxReorderingModel.h" |
|
23 |
|
24 #include <Pbk2UIControls.rsg> |
|
25 #include <Pbk2ProcessDecoratorFactory.h> |
|
26 #include <MPbk2CommandObserver.h> |
|
27 #include <MPbk2ContactUiControl.h> |
|
28 #include <CPbk2AppUiBase.h> |
|
29 #include <MPbk2ApplicationServices.h> |
|
30 #include <MPbk2ContactViewSupplier.h> |
|
31 #include <MPbk2ContactViewSupplier2.h> |
|
32 #include <CVPbkContactManager.h> |
|
33 #include <MVPbkBaseContact.h> |
|
34 #include <MVPbkContactLink.h> |
|
35 #include <MVPbkContactOperationBase.h> |
|
36 #include <CVPbkContactLinkArray.h> |
|
37 #include <MVPbkContactViewBase.h> |
|
38 |
|
39 namespace |
|
40 { |
|
41 #ifdef _DEBUG |
|
42 enum TPanicCode |
|
43 { |
|
44 EPanicPreCond_IncorrestState = 1, |
|
45 EPanicPreCond_NoteActive |
|
46 }; |
|
47 |
|
48 void Panic(TPanicCode aReason) |
|
49 { |
|
50 _LIT(KPanicText, "CPbk2NlxMoveTopContactsCmd"); |
|
51 User::Panic(KPanicText, aReason); |
|
52 } |
|
53 #endif // _DEBUG |
|
54 } |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // CPbk2NlxMoveTopContactsCmd::CPbk2NlxMoveTopContactsCmd |
|
58 // -------------------------------------------------------------------------- |
|
59 // |
|
60 CPbk2NlxMoveTopContactsCmd::CPbk2NlxMoveTopContactsCmd( |
|
61 MPbk2ContactUiControl& aUiControl ) : |
|
62 CActive( EPriorityStandard ), |
|
63 iUiControl( &aUiControl ) |
|
64 { |
|
65 CActiveScheduler::Add( this ); |
|
66 if( iUiControl ) |
|
67 { |
|
68 iUiControl->RegisterCommand( this ); |
|
69 } |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // CPbk2NlxMoveTopContactsCmd::~CPbk2NlxMoveTopContactsCmd |
|
74 // -------------------------------------------------------------------------- |
|
75 // |
|
76 CPbk2NlxMoveTopContactsCmd::~CPbk2NlxMoveTopContactsCmd() |
|
77 { |
|
78 Cancel(); |
|
79 if (iUiControl) |
|
80 { |
|
81 iUiControl->RegisterCommand( NULL ); |
|
82 } |
|
83 |
|
84 delete iFocusedContact; |
|
85 delete iTopContactOperation; |
|
86 delete iReorderingModel; |
|
87 delete iVPbkTopContactManager; |
|
88 delete iDecorator; |
|
89 } |
|
90 |
|
91 // -------------------------------------------------------------------------- |
|
92 // CPbk2NlxMoveTopContactsCmd::NewL |
|
93 // -------------------------------------------------------------------------- |
|
94 // |
|
95 CPbk2NlxMoveTopContactsCmd* CPbk2NlxMoveTopContactsCmd::NewL( |
|
96 MPbk2ContactUiControl& aUiControl ) |
|
97 { |
|
98 CPbk2NlxMoveTopContactsCmd* self = |
|
99 new ( ELeave ) CPbk2NlxMoveTopContactsCmd( aUiControl ); |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL(); |
|
102 CleanupStack::Pop( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CPbk2NlxMoveTopContactsCmd::ConstructL |
|
108 // -------------------------------------------------------------------------- |
|
109 // |
|
110 void CPbk2NlxMoveTopContactsCmd::ConstructL() |
|
111 { |
|
112 if( iUiControl ) |
|
113 { |
|
114 iUiControl->RegisterCommand( this ); |
|
115 } |
|
116 |
|
117 iVPbkTopContactManager = CVPbkTopContactManager::NewL( |
|
118 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager() ); |
|
119 } |
|
120 |
|
121 // -------------------------------------------------------------------------- |
|
122 // CPbk2NlxMoveTopContactsCmd::ExecuteLD |
|
123 // -------------------------------------------------------------------------- |
|
124 // |
|
125 void CPbk2NlxMoveTopContactsCmd::ExecuteLD() |
|
126 { |
|
127 if ( iUiControl ) |
|
128 { |
|
129 iUiControl->SetBlank(ETrue); |
|
130 } |
|
131 IssueRequest(EShowMoveDlg); |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // CPbk2NlxMoveTopContactsCmd::ResetUiControl |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 void CPbk2NlxMoveTopContactsCmd::ResetUiControl( |
|
139 MPbk2ContactUiControl& aUiControl ) |
|
140 { |
|
141 if ( iUiControl == &aUiControl ) |
|
142 { |
|
143 iUiControl = NULL; |
|
144 } |
|
145 } |
|
146 |
|
147 // -------------------------------------------------------------------------- |
|
148 // CPbk2NlxMoveTopContactsCmd::AddObserver |
|
149 // -------------------------------------------------------------------------- |
|
150 // |
|
151 void CPbk2NlxMoveTopContactsCmd::AddObserver( |
|
152 MPbk2CommandObserver& aObserver ) |
|
153 { |
|
154 iCommandObserver = &aObserver; |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------- |
|
158 // CPbk2NlxMoveTopContactsCmd::RunL |
|
159 // -------------------------------------------------------------------------- |
|
160 // |
|
161 void CPbk2NlxMoveTopContactsCmd::RunL() |
|
162 { |
|
163 switch(iState) |
|
164 { |
|
165 case EShowMoveDlg: |
|
166 { |
|
167 ShowDlgL(); |
|
168 break; |
|
169 } |
|
170 case ESavingTopContacts: |
|
171 { |
|
172 ShowWaitNoteL(); |
|
173 |
|
174 iFocusedContact = iReorderingModel->FocusedContactLinkL(); |
|
175 MVPbkContactLinkArray* topContacts = |
|
176 iReorderingModel->ReorderedLinksLC(); |
|
177 //save top contacts |
|
178 iTopContactOperation = iVPbkTopContactManager->SetTopOrderL( |
|
179 *topContacts, |
|
180 *this, |
|
181 *this ); |
|
182 CleanupStack::PopAndDestroy(); //topContacts |
|
183 break; |
|
184 } |
|
185 case ECompleteCommand: |
|
186 { |
|
187 if ( iUiControl ) |
|
188 { |
|
189 // keep focused item |
|
190 if ( iFocusedContact ) |
|
191 { |
|
192 iUiControl->SetFocusedContactL( *iFocusedContact ); |
|
193 } |
|
194 iUiControl->SetBlank(EFalse); |
|
195 iUiControl->UpdateAfterCommandExecution(); |
|
196 } |
|
197 if ( iCommandObserver ) |
|
198 { |
|
199 iCommandObserver->CommandFinished( *this ); |
|
200 } |
|
201 break; |
|
202 } |
|
203 } |
|
204 } |
|
205 |
|
206 // -------------------------------------------------------------------------- |
|
207 // CPbk2NlxMoveTopContactsCmd::RunError |
|
208 // -------------------------------------------------------------------------- |
|
209 // |
|
210 TInt CPbk2NlxMoveTopContactsCmd::RunError( TInt aError ) |
|
211 { |
|
212 if ( aError != KErrNone ) |
|
213 { |
|
214 FinishCommand( aError ); |
|
215 } |
|
216 |
|
217 return KErrNone; |
|
218 } |
|
219 |
|
220 // -------------------------------------------------------------------------- |
|
221 // CPbk2NlxMoveTopContactsCmd::DoCancel |
|
222 // -------------------------------------------------------------------------- |
|
223 // |
|
224 void CPbk2NlxMoveTopContactsCmd::DoCancel() |
|
225 { |
|
226 } |
|
227 |
|
228 // -------------------------------------------------------------------------- |
|
229 // CPbk2NlxMoveTopContactsCmd::IssueRequest |
|
230 // Advances to the next state |
|
231 // -------------------------------------------------------------------------- |
|
232 // |
|
233 void CPbk2NlxMoveTopContactsCmd::IssueRequest(TState aNextState) |
|
234 { |
|
235 iState = aNextState; |
|
236 TRequestStatus* status = &iStatus; |
|
237 User::RequestComplete( status, KErrNone ); |
|
238 SetActive(); |
|
239 } |
|
240 |
|
241 // -------------------------------------------------------------------------- |
|
242 // CPbk2NlxMoveTopContactsCmd::FinishCommand |
|
243 // -------------------------------------------------------------------------- |
|
244 // |
|
245 void CPbk2NlxMoveTopContactsCmd::FinishCommand(TInt aResult) |
|
246 { |
|
247 if ( aResult != KErrNone && aResult != KErrCancel ) |
|
248 { |
|
249 CCoeEnv::Static()->HandleError( aResult ); |
|
250 } |
|
251 if ( iDecorator ) |
|
252 { |
|
253 // wait for callback from the wait note and finish then |
|
254 iDecorator->ProcessStopped(); |
|
255 } |
|
256 else |
|
257 { |
|
258 IssueRequest( ECompleteCommand ); |
|
259 } |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CPbk2NlxMoveTopContactsCmd::ShowDlgL |
|
264 // Displays Reordering dialog and creates listbox model for it |
|
265 // --------------------------------------------------------------------------- |
|
266 void CPbk2NlxMoveTopContactsCmd::ShowDlgL() |
|
267 { |
|
268 MPbk2ContactViewSupplier2* viewSupplierExtension = |
|
269 reinterpret_cast<MPbk2ContactViewSupplier2*>( |
|
270 Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier(). |
|
271 MPbk2ContactViewSupplierExtension( |
|
272 KMPbk2ContactViewSupplierExtension2Uid )); |
|
273 __ASSERT_DEBUG( viewSupplierExtension, Panic(EPanicPreCond_IncorrestState)); |
|
274 __ASSERT_DEBUG( viewSupplierExtension->TopContactsViewL(), |
|
275 Panic(EPanicPreCond_IncorrestState)); |
|
276 __ASSERT_DEBUG(!iReorderingModel, Panic(EPanicPreCond_IncorrestState)); |
|
277 |
|
278 iReorderingModel = CPbk2NlxReorderingModel::NewL( |
|
279 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(), |
|
280 *viewSupplierExtension->TopContactsViewL(), |
|
281 Phonebook2::Pbk2AppUi()->ApplicationServices().NameFormatter(), |
|
282 Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties() ); |
|
283 |
|
284 if ( iUiControl ) |
|
285 { |
|
286 //keep focus from the namelist view |
|
287 MVPbkContactLink* focusedContact = |
|
288 iUiControl->FocusedContactL()->CreateLinkLC(); |
|
289 iReorderingModel->SetFocusedContactL( *focusedContact ); |
|
290 CleanupStack::PopAndDestroy();//focusedContact |
|
291 } |
|
292 |
|
293 CPbk2NlxMoveTopContactsDlg* dlg = CPbk2NlxMoveTopContactsDlg::NewL( |
|
294 *iReorderingModel ); |
|
295 |
|
296 if ( dlg->ExecuteLD() ) |
|
297 { |
|
298 IssueRequest(ESavingTopContacts); |
|
299 } |
|
300 else |
|
301 { |
|
302 FinishCommand( KErrCancel ); |
|
303 } |
|
304 } |
|
305 |
|
306 void CPbk2NlxMoveTopContactsCmd::VPbkOperationCompleted( |
|
307 MVPbkContactOperationBase*) |
|
308 { |
|
309 FinishCommand( KErrNone ); |
|
310 } |
|
311 |
|
312 void CPbk2NlxMoveTopContactsCmd::VPbkOperationFailed( |
|
313 MVPbkContactOperationBase*, |
|
314 TInt aError ) |
|
315 { |
|
316 FinishCommand( aError ); |
|
317 } |
|
318 |
|
319 void CPbk2NlxMoveTopContactsCmd::ShowWaitNoteL() |
|
320 { |
|
321 __ASSERT_DEBUG(!iDecorator, Panic(EPanicPreCond_NoteActive)); |
|
322 |
|
323 iDecorator = Pbk2ProcessDecoratorFactory::CreateWaitNoteDecoratorL |
|
324 ( R_QTN_GEN_NOTE_SAVING_WAIT, ETrue ); |
|
325 iDecorator->SetObserver( *this ); |
|
326 iDecorator->ProcessStartedL( 0 ); // wait note doesn't care about amount |
|
327 } |
|
328 |
|
329 void CPbk2NlxMoveTopContactsCmd::ProcessDismissed( TInt /*aCancelCode*/ ) |
|
330 { |
|
331 // if it's cancel, just finish cmd execution, |
|
332 // the cmd will be deleted and canceled that way |
|
333 IssueRequest( ECompleteCommand ); |
|
334 } |
|
335 // End of File |