author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 68 | 9da50d567e3c |
parent 63 | f4a778e096c2 |
child 85 | 38bb213f60ba |
permissions | -rw-r--r-- |
63 | 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" |
|
68
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
25 |
#include <pbk2groupuires.rsg> |
63 | 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 |
IssueRequest(EFinishCommand); |
|
218 |
||
219 |
return aError; |
|
220 |
} |
|
221 |
||
222 |
// -------------------------------------------------------------------------- |
|
223 |
// CPguRenameGroupCmd::ContactOperationCompleted |
|
224 |
// -------------------------------------------------------------------------- |
|
225 |
// |
|
226 |
void CPguRenameGroupCmd::ContactOperationCompleted( TContactOpResult aResult ) |
|
227 |
{ |
|
228 |
if ( aResult.iOpCode == MVPbkContactObserver::EContactLock ) |
|
229 |
{ |
|
230 |
IssueRequest( ELauchQuery ); |
|
231 |
} |
|
232 |
else if ( aResult.iOpCode == MVPbkContactObserver::EContactCommit ) |
|
233 |
{ |
|
234 |
CleanupCommand(); |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
// -------------------------------------------------------------------------- |
|
239 |
// CPguRenameGroupCmd::ContactOperationFailed |
|
240 |
// -------------------------------------------------------------------------- |
|
241 |
// |
|
242 |
void CPguRenameGroupCmd::ContactOperationFailed( |
|
243 |
TContactOp /*aOpCode*/, |
|
244 |
TInt aErrorCode, |
|
245 |
TBool aErrorNotified ) |
|
246 |
{ |
|
247 |
if ( !aErrorNotified ) |
|
248 |
{ |
|
249 |
CCoeEnv::Static()->HandleError( aErrorCode ); |
|
250 |
} |
|
251 |
CleanupCommand(); |
|
252 |
} |
|
253 |
||
254 |
// -------------------------------------------------------------------------- |
|
255 |
// CPguRenameGroupCmd::VPbkSingleContactOperationComplete |
|
256 |
// -------------------------------------------------------------------------- |
|
257 |
// |
|
258 |
void CPguRenameGroupCmd::VPbkSingleContactOperationComplete( |
|
259 |
MVPbkContactOperationBase& /*aOperation*/, |
|
260 |
MVPbkStoreContact* aContact ) |
|
261 |
{ |
|
262 |
__ASSERT_DEBUG(aContact->Group(), Panic(EPanicContactNotGroup)); |
|
263 |
||
264 |
iContactGroup = aContact->Group(); |
|
265 |
if ( iContactGroup ) |
|
266 |
{ |
|
267 |
// Lock contact group for editing |
|
268 |
TRAPD( error, iContactGroup->LockL( *this ) ); |
|
269 |
||
270 |
if ( error != KErrNone ) |
|
271 |
{ |
|
272 |
CCoeEnv::Static()->HandleError( error ); |
|
273 |
IssueRequest( EFinishCommand ); |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
delete iContactOperation; |
|
278 |
iContactOperation = NULL; |
|
279 |
} |
|
280 |
||
281 |
// -------------------------------------------------------------------------- |
|
282 |
// CPguRenameGroupCmd::VPbkSingleContactOperationFailed |
|
283 |
// -------------------------------------------------------------------------- |
|
284 |
// |
|
285 |
void CPguRenameGroupCmd::VPbkSingleContactOperationFailed( |
|
286 |
MVPbkContactOperationBase& aOperation, |
|
287 |
TInt aError ) |
|
288 |
{ |
|
289 |
if ( iContactOperation == &aOperation ) |
|
290 |
{ |
|
291 |
CCoeEnv::Static()->HandleError( aError ); |
|
292 |
CleanupCommand(); |
|
293 |
delete iContactOperation; |
|
294 |
iContactOperation = NULL; |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
// -------------------------------------------------------------------------- |
|
299 |
// CPguRenameGroupCmd::QueryGroupNameL |
|
300 |
// -------------------------------------------------------------------------- |
|
301 |
// |
|
302 |
void CPguRenameGroupCmd::QueryGroupNameL() |
|
303 |
{ |
|
304 |
HBufC* textBuf = HBufC::NewLC( KGroupLabelLength ); |
|
305 |
TPtr text = textBuf->Des(); |
|
306 |
TInt lengthInUse = Min( KGroupLabelLength, iContactGroup->GroupLabel().Length() ); |
|
307 |
text.Append( iContactGroup->GroupLabel().Left( lengthInUse ) ); |
|
308 |
||
309 |
MVPbkContactViewBase* groupsView = |
|
310 |
Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
311 |
ViewSupplier().AllGroupsViewL(); |
|
312 |
||
313 |
CPguGroupNameQueryDlg* dlg = CPguGroupNameQueryDlg::NewL( text, |
|
314 |
*groupsView, Phonebook2::Pbk2AppUi()->ApplicationServices(). |
|
315 |
NameFormatter(), EFalse ); |
|
316 |
||
317 |
dlg->SetMaxLength( KGroupLabelLength ); |
|
318 |
||
319 |
if ( dlg->ExecuteLD( R_PHONEBOOK2_GROUPLIST_NEWGROUP_QUERY ) ) |
|
320 |
{ |
|
321 |
iContactGroup->SetGroupLabelL( text ); |
|
322 |
iContactGroup->CommitL( *this ); |
|
323 |
} |
|
324 |
else |
|
325 |
{ |
|
326 |
IssueRequest( EFinishCommand ); |
|
327 |
} |
|
328 |
CleanupStack::PopAndDestroy( textBuf ); |
|
329 |
} |
|
330 |
||
331 |
// -------------------------------------------------------------------------- |
|
332 |
// CPguRenameGroupCmd::CleanupCommand |
|
333 |
// -------------------------------------------------------------------------- |
|
334 |
// |
|
335 |
void CPguRenameGroupCmd::CleanupCommand() |
|
336 |
{ |
|
337 |
if ( iCommandObserver ) |
|
338 |
{ |
|
339 |
iCommandObserver->CommandFinished( *this ); |
|
340 |
} |
|
341 |
if (iUiControl) |
|
342 |
{ |
|
343 |
iUiControl->UpdateAfterCommandExecution(); |
|
344 |
} |
|
345 |
} |
|
346 |
||
347 |
// -------------------------------------------------------------------------- |
|
348 |
// CPguRenameGroupCmd::IssueRequest |
|
349 |
// -------------------------------------------------------------------------- |
|
350 |
// |
|
351 |
void CPguRenameGroupCmd::IssueRequest( TProcessState aState ) |
|
352 |
{ |
|
353 |
if ( !IsActive() ) |
|
354 |
{ |
|
355 |
iState = aState; |
|
356 |
TRequestStatus* status = &iStatus; |
|
357 |
User::RequestComplete( status, KErrNone ); |
|
358 |
SetActive(); |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
// End of File |