|
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: Phonebook 2 group rename command. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPguRenameGroupCmd.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "CPguGroupNameQueryDlg.h" |
|
24 #include "Pbk2GroupConsts.h" |
|
25 #include <Pbk2GroupUIRes.rsg> |
|
26 #include <MPbk2CommandObserver.h> |
|
27 #include <MPbk2ContactUiControl.h> |
|
28 #include <CPbk2StoreConfiguration.h> |
|
29 #include <CPbk2StoreProperty.h> |
|
30 #include <CPbk2StorePropertyArray.h> |
|
31 #include <MPbk2AppUi.h> |
|
32 #include <MPbk2ApplicationServices.h> |
|
33 #include <MPbk2ContactViewSupplier.h> |
|
34 |
|
35 // Virtual Phonebook |
|
36 #include <CVPbkContactManager.h> |
|
37 #include <MVPbkContactLink.h> |
|
38 #include <MVPbkContactGroup.h> |
|
39 #include <MVPbkContactStore.h> |
|
40 #include <MVPbkContactStoreList.h> |
|
41 #include <MVPbkContactOperationBase.h> |
|
42 #include <TVPbkContactStoreUriPtr.h> |
|
43 #include <CVPbkContactStoreUriArray.h> |
|
44 #include <MVPbkContactStoreProperties.h> |
|
45 |
|
46 // System includes |
|
47 #include <StringLoader.h> |
|
48 #include <aknnotewrappers.h> |
|
49 |
|
50 // Debugging headers |
|
51 #include <Pbk2Debug.h> |
|
52 |
|
53 /// Unnamed namespace for local definitions |
|
54 namespace { |
|
55 |
|
56 #ifdef _DEBUG |
|
57 enum TPanicCode |
|
58 { |
|
59 EPanicPreCond_NewL = 1, |
|
60 EPanicPreCond_ExecuteLD, |
|
61 EPanicContactNotGroup, |
|
62 ERunL_InvalidState |
|
63 }; |
|
64 |
|
65 void Panic(TPanicCode aReason) |
|
66 { |
|
67 _LIT(KPanicText, "CPguRenameGroupCmd"); |
|
68 User::Panic(KPanicText,aReason); |
|
69 } |
|
70 #endif // _DEBUG |
|
71 |
|
72 } /// namespace |
|
73 |
|
74 // -------------------------------------------------------------------------- |
|
75 // CPguRenameGroupCmd::CPguRenameGroupCmd |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 CPguRenameGroupCmd::CPguRenameGroupCmd |
|
79 ( MPbk2ContactUiControl& aUiControl ) : |
|
80 CActive( CActive::EPriorityIdle ), |
|
81 iUiControl( &aUiControl ) |
|
82 { |
|
83 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
84 ("CPguRenameGroupCmd::CPguRenameGroupCmd(0x%x)"), this); |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPguRenameGroupCmd::ConstructL |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 inline void CPguRenameGroupCmd::ConstructL() |
|
92 { |
|
93 CActiveScheduler::Add( this ); |
|
94 iGroupLink = iUiControl->FocusedContactL()->CreateLinkLC(); |
|
95 CleanupStack::Pop(); |
|
96 |
|
97 CPbk2StoreConfiguration* storeConfig = CPbk2StoreConfiguration::NewL(); |
|
98 CleanupStack::PushL( storeConfig ); |
|
99 iTargetStore = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
100 ContactManager().ContactStoresL(). |
|
101 Find( TVPbkContactStoreUriPtr( storeConfig->DefaultSavingStoreL() ) ); |
|
102 CleanupStack::PopAndDestroy( storeConfig ); |
|
103 } |
|
104 |
|
105 // -------------------------------------------------------------------------- |
|
106 // CPguRenameGroupCmd::NewL |
|
107 // -------------------------------------------------------------------------- |
|
108 // |
|
109 CPguRenameGroupCmd* CPguRenameGroupCmd::NewL |
|
110 ( MPbk2ContactUiControl& aUiControl ) |
|
111 { |
|
112 CPguRenameGroupCmd* self = |
|
113 new(ELeave) CPguRenameGroupCmd( aUiControl ); |
|
114 CleanupStack::PushL( self ); |
|
115 self->ConstructL(); |
|
116 CleanupStack::Pop( self ); |
|
117 return self; |
|
118 } |
|
119 |
|
120 // -------------------------------------------------------------------------- |
|
121 // CPguRenameGroupCmd::~CPguRenameGroupCmd |
|
122 // -------------------------------------------------------------------------- |
|
123 // |
|
124 CPguRenameGroupCmd::~CPguRenameGroupCmd() |
|
125 { |
|
126 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
127 ("CPguRenameGroupCmd::~CPguRenameGroupCmd(0x%x)"), this); |
|
128 Cancel(); |
|
129 delete iGroupLink; |
|
130 delete iContactOperation; |
|
131 delete iContactGroup; |
|
132 } |
|
133 |
|
134 // -------------------------------------------------------------------------- |
|
135 // CPguRenameGroupCmd::ExecuteLD |
|
136 // -------------------------------------------------------------------------- |
|
137 // |
|
138 void CPguRenameGroupCmd::ExecuteLD() |
|
139 { |
|
140 __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_ExecuteLD)); |
|
141 |
|
142 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
143 ("CPguRenameGroupCmd::ExecuteLD(0x%x)"), this); |
|
144 |
|
145 CleanupStack::PushL( this ); |
|
146 iContactOperation = Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
147 ContactManager().RetrieveContactL( *iGroupLink, *this ); |
|
148 CleanupStack::Pop( this ); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // CPguRenameGroupCmd::AddObserver |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 void CPguRenameGroupCmd::AddObserver( MPbk2CommandObserver& aObserver ) |
|
156 { |
|
157 iCommandObserver = &aObserver; |
|
158 } |
|
159 |
|
160 // -------------------------------------------------------------------------- |
|
161 // CPguRenameGroupCmd::ResetUiControl |
|
162 // -------------------------------------------------------------------------- |
|
163 // |
|
164 void CPguRenameGroupCmd::ResetUiControl( |
|
165 MPbk2ContactUiControl& aUiControl) |
|
166 { |
|
167 if (iUiControl == &aUiControl) |
|
168 { |
|
169 iUiControl = NULL; |
|
170 } |
|
171 } |
|
172 |
|
173 // -------------------------------------------------------------------------- |
|
174 // CPguRenameGroupCmd::RunL |
|
175 // -------------------------------------------------------------------------- |
|
176 // |
|
177 void CPguRenameGroupCmd::RunL() |
|
178 { |
|
179 switch ( iState ) |
|
180 { |
|
181 case ELauchQuery: |
|
182 { |
|
183 QueryGroupNameL(); |
|
184 break; |
|
185 } |
|
186 case EFinishCommand: |
|
187 { |
|
188 if ( iCommandObserver ) |
|
189 { |
|
190 iCommandObserver->CommandFinished( *this ); |
|
191 } |
|
192 break; |
|
193 } |
|
194 default: |
|
195 { |
|
196 __ASSERT_DEBUG( EFalse, Panic(ERunL_InvalidState) ); |
|
197 break; |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // -------------------------------------------------------------------------- |
|
203 // CPguRenameGroupCmd::DoCancel |
|
204 // -------------------------------------------------------------------------- |
|
205 // |
|
206 void CPguRenameGroupCmd::DoCancel() |
|
207 { |
|
208 //Do nothing |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CPguRenameGroupCmd::RunError |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 TInt CPguRenameGroupCmd::RunError( TInt aError ) |
|
216 { |
|
217 CCoeEnv::Static()->HandleError( aError ); |
|
218 return KErrNone; |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CPguRenameGroupCmd::ContactOperationCompleted |
|
223 // -------------------------------------------------------------------------- |
|
224 // |
|
225 void CPguRenameGroupCmd::ContactOperationCompleted( TContactOpResult aResult ) |
|
226 { |
|
227 if ( aResult.iOpCode == MVPbkContactObserver::EContactLock ) |
|
228 { |
|
229 IssueRequest( ELauchQuery ); |
|
230 } |
|
231 else if ( aResult.iOpCode == MVPbkContactObserver::EContactCommit ) |
|
232 { |
|
233 CleanupCommand(); |
|
234 } |
|
235 } |
|
236 |
|
237 // -------------------------------------------------------------------------- |
|
238 // CPguRenameGroupCmd::ContactOperationFailed |
|
239 // -------------------------------------------------------------------------- |
|
240 // |
|
241 void CPguRenameGroupCmd::ContactOperationFailed( |
|
242 TContactOp /*aOpCode*/, |
|
243 TInt aErrorCode, |
|
244 TBool aErrorNotified ) |
|
245 { |
|
246 if ( !aErrorNotified ) |
|
247 { |
|
248 CCoeEnv::Static()->HandleError( aErrorCode ); |
|
249 } |
|
250 CleanupCommand(); |
|
251 } |
|
252 |
|
253 // -------------------------------------------------------------------------- |
|
254 // CPguRenameGroupCmd::VPbkSingleContactOperationComplete |
|
255 // -------------------------------------------------------------------------- |
|
256 // |
|
257 void CPguRenameGroupCmd::VPbkSingleContactOperationComplete( |
|
258 MVPbkContactOperationBase& /*aOperation*/, |
|
259 MVPbkStoreContact* aContact ) |
|
260 { |
|
261 __ASSERT_DEBUG(aContact->Group(), Panic(EPanicContactNotGroup)); |
|
262 |
|
263 iContactGroup = aContact->Group(); |
|
264 if ( iContactGroup ) |
|
265 { |
|
266 // Lock contact group for editing |
|
267 TRAPD( error, iContactGroup->LockL( *this ) ); |
|
268 |
|
269 if ( error != KErrNone ) |
|
270 { |
|
271 CCoeEnv::Static()->HandleError( error ); |
|
272 IssueRequest( EFinishCommand ); |
|
273 } |
|
274 } |
|
275 |
|
276 delete iContactOperation; |
|
277 iContactOperation = NULL; |
|
278 } |
|
279 |
|
280 // -------------------------------------------------------------------------- |
|
281 // CPguRenameGroupCmd::VPbkSingleContactOperationFailed |
|
282 // -------------------------------------------------------------------------- |
|
283 // |
|
284 void CPguRenameGroupCmd::VPbkSingleContactOperationFailed( |
|
285 MVPbkContactOperationBase& aOperation, |
|
286 TInt aError ) |
|
287 { |
|
288 if ( iContactOperation == &aOperation ) |
|
289 { |
|
290 CCoeEnv::Static()->HandleError( aError ); |
|
291 CleanupCommand(); |
|
292 delete iContactOperation; |
|
293 iContactOperation = NULL; |
|
294 } |
|
295 } |
|
296 |
|
297 // -------------------------------------------------------------------------- |
|
298 // CPguRenameGroupCmd::QueryGroupNameL |
|
299 // -------------------------------------------------------------------------- |
|
300 // |
|
301 void CPguRenameGroupCmd::QueryGroupNameL() |
|
302 { |
|
303 HBufC* textBuf = HBufC::NewLC( KGroupLabelLength ); |
|
304 TPtr text = textBuf->Des(); |
|
305 TInt lengthInUse = Min( KGroupLabelLength, iContactGroup->GroupLabel().Length() ); |
|
306 text.Append( iContactGroup->GroupLabel().Left( lengthInUse ) ); |
|
307 |
|
308 MVPbkContactViewBase* groupsView = |
|
309 Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
310 ViewSupplier().AllGroupsViewL(); |
|
311 |
|
312 CPguGroupNameQueryDlg* dlg = CPguGroupNameQueryDlg::NewL( text, |
|
313 *groupsView, Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
314 NameFormatter(), EFalse ); |
|
315 |
|
316 dlg->SetMaxLength( KGroupLabelLength ); |
|
317 |
|
318 if ( dlg->ExecuteLD( R_PHONEBOOK2_GROUPLIST_NEWGROUP_QUERY ) ) |
|
319 { |
|
320 iContactGroup->SetGroupLabelL( text ); |
|
321 iContactGroup->CommitL( *this ); |
|
322 } |
|
323 else |
|
324 { |
|
325 IssueRequest( EFinishCommand ); |
|
326 } |
|
327 CleanupStack::PopAndDestroy( textBuf ); |
|
328 } |
|
329 |
|
330 // -------------------------------------------------------------------------- |
|
331 // CPguRenameGroupCmd::CleanupCommand |
|
332 // -------------------------------------------------------------------------- |
|
333 // |
|
334 void CPguRenameGroupCmd::CleanupCommand() |
|
335 { |
|
336 if ( iCommandObserver ) |
|
337 { |
|
338 iCommandObserver->CommandFinished( *this ); |
|
339 } |
|
340 if (iUiControl) |
|
341 { |
|
342 iUiControl->UpdateAfterCommandExecution(); |
|
343 } |
|
344 } |
|
345 |
|
346 // -------------------------------------------------------------------------- |
|
347 // CPguRenameGroupCmd::IssueRequest |
|
348 // -------------------------------------------------------------------------- |
|
349 // |
|
350 void CPguRenameGroupCmd::IssueRequest( TProcessState aState ) |
|
351 { |
|
352 if ( !IsActive() ) |
|
353 { |
|
354 iState = aState; |
|
355 TRequestStatus* status = &iStatus; |
|
356 User::RequestComplete( status, KErrNone ); |
|
357 SetActive(); |
|
358 } |
|
359 } |
|
360 |
|
361 // End of File |