63
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-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: Remove speed dial command object.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "CPbk2RemoveSpeedDialCmd.h"
|
|
20 |
|
|
21 |
// From Phonebook 2
|
|
22 |
#include "MPbk2CommandObserver.h"
|
|
23 |
#include <CPbk2ApplicationServices.h>
|
|
24 |
#include <MPbk2AppUi.h>
|
|
25 |
#include <MPbk2ContactUiControl.h>
|
|
26 |
#include <CPbk2PresentationContact.h>
|
|
27 |
#include <CPbk2FieldPropertyArray.h>
|
|
28 |
#include <CPbk2PresentationContactFieldCollection.h>
|
|
29 |
#include <Pbk2CmdExtRes.rsg>
|
|
30 |
#include <CPbk2AppUiBase.h>
|
|
31 |
|
|
32 |
// From Virtual Phonebook
|
|
33 |
#include <CVPbkContactIdConverter.h>
|
|
34 |
#include <TVPbkContactStoreUriPtr.h>
|
|
35 |
#include <CVPbkContactManager.h>
|
|
36 |
#include <MVPbkContactStoreList.h>
|
|
37 |
#include <MVPbkBaseContact.h>
|
|
38 |
#include <MVPbkContactAttributeManager.h>
|
|
39 |
#include <CVPbkSpeedDialAttribute.h>
|
|
40 |
#include <MVPbkContactOperationBase.h>
|
|
41 |
#include <MVPbkStoreContact.h>
|
|
42 |
#include <MVPbkContactStore.h>
|
|
43 |
#include <MVPbkContactLink.h>
|
|
44 |
|
|
45 |
#include <coemain.h>
|
|
46 |
#include <AknQueryDialog.h>
|
|
47 |
|
|
48 |
/// Unnamed namespace for local definitons
|
|
49 |
namespace {
|
|
50 |
|
|
51 |
#ifdef _DEBUG
|
|
52 |
enum TPanicCode
|
|
53 |
{
|
|
54 |
EPanicPreCond_Null_Pointer
|
|
55 |
};
|
|
56 |
|
|
57 |
void Panic(TInt aReason)
|
|
58 |
{
|
|
59 |
_LIT(KPanicText, "CPbk2RemoveSpeedDialCmd");
|
|
60 |
User::Panic(KPanicText, aReason);
|
|
61 |
}
|
|
62 |
#endif // _DEBUG
|
|
63 |
|
|
64 |
} // namespace
|
|
65 |
|
|
66 |
// ============================== MEMBER FUNCTIONS ==========================
|
|
67 |
|
|
68 |
// --------------------------------------------------------------------------
|
|
69 |
// CPbk2RemoveSpeedDialCmd::CPbk2RemoveSpeedDialCmd
|
|
70 |
// --------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
CPbk2RemoveSpeedDialCmd::CPbk2RemoveSpeedDialCmd(
|
|
73 |
MPbk2ContactUiControl& aUiControl) :
|
|
74 |
iUiControl(&aUiControl)
|
|
75 |
{
|
|
76 |
}
|
|
77 |
|
|
78 |
// --------------------------------------------------------------------------
|
|
79 |
// CPbk2RemoveSpeedDialCmd::NewL
|
|
80 |
// --------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
CPbk2RemoveSpeedDialCmd* CPbk2RemoveSpeedDialCmd::NewL(
|
|
83 |
MPbk2ContactUiControl& aUiControl)
|
|
84 |
{
|
|
85 |
CPbk2RemoveSpeedDialCmd* self = new(ELeave) CPbk2RemoveSpeedDialCmd(
|
|
86 |
aUiControl);
|
|
87 |
CleanupStack::PushL( self );
|
|
88 |
self->ConstructL();
|
|
89 |
CleanupStack::Pop( self );
|
|
90 |
return self;
|
|
91 |
}
|
|
92 |
|
|
93 |
// --------------------------------------------------------------------------
|
|
94 |
// CPbk2RemoveSpeedDialCmd::~CPbk2RemoveSpeedDialCmd
|
|
95 |
// --------------------------------------------------------------------------
|
|
96 |
//
|
|
97 |
CPbk2RemoveSpeedDialCmd::~CPbk2RemoveSpeedDialCmd()
|
|
98 |
{
|
|
99 |
delete iStoreContact;
|
|
100 |
delete iOperation;
|
|
101 |
Release( iAppServices );
|
|
102 |
|
|
103 |
delete iContactLink;
|
|
104 |
}
|
|
105 |
|
|
106 |
// --------------------------------------------------------------------------
|
|
107 |
// CPbk2RemoveSpeedDialCmd::ConstructL
|
|
108 |
// --------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
inline void CPbk2RemoveSpeedDialCmd::ConstructL()
|
|
111 |
{
|
|
112 |
iAppServices = CPbk2ApplicationServices::InstanceL();
|
|
113 |
}
|
|
114 |
|
|
115 |
// --------------------------------------------------------------------------
|
|
116 |
// CPbk2RemoveSpeedDialCmd::ExecuteLD
|
|
117 |
// --------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
void CPbk2RemoveSpeedDialCmd::ExecuteLD()
|
|
120 |
{
|
|
121 |
CleanupStack::PushL(this);
|
|
122 |
|
|
123 |
iContactLink = iUiControl->FocusedContactL()->CreateLinkLC();
|
|
124 |
CleanupStack::Pop(); // iContactLink
|
|
125 |
iContactLink->ContactStore().OpenL( *this );
|
|
126 |
|
|
127 |
iContactLink->ContactStore().Close( *this );
|
|
128 |
|
|
129 |
if ( iUiControl )
|
|
130 |
{
|
|
131 |
iOperation = iAppServices->ContactManager().RetrieveContactL(
|
|
132 |
*iContactLink, *this);
|
|
133 |
}
|
|
134 |
else
|
|
135 |
{
|
|
136 |
FinishCommand( KErrNotFound );
|
|
137 |
}
|
|
138 |
|
|
139 |
delete iContactLink;
|
|
140 |
iContactLink = NULL;
|
|
141 |
|
|
142 |
CleanupStack::Pop(this);
|
|
143 |
}
|
|
144 |
|
|
145 |
// --------------------------------------------------------------------------
|
|
146 |
// CPbk2RemoveSpeedDialCmd::AddObserver
|
|
147 |
// --------------------------------------------------------------------------
|
|
148 |
//
|
|
149 |
void CPbk2RemoveSpeedDialCmd::AddObserver(MPbk2CommandObserver& aObserver)
|
|
150 |
{
|
|
151 |
iCommandObserver = &aObserver;
|
|
152 |
}
|
|
153 |
|
|
154 |
// --------------------------------------------------------------------------
|
|
155 |
// CPbk2RemoveSpeedDialCmd::ResetUiControl
|
|
156 |
// --------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
void CPbk2RemoveSpeedDialCmd::ResetUiControl(
|
|
159 |
MPbk2ContactUiControl& aUiControl)
|
|
160 |
{
|
|
161 |
if (iUiControl == &aUiControl)
|
|
162 |
{
|
|
163 |
iUiControl = NULL;
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
// --------------------------------------------------------------------------
|
|
168 |
// CPbk2RemoveSpeedDialCmd::StoreReady
|
|
169 |
// --------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
void CPbk2RemoveSpeedDialCmd::StoreReady(
|
|
172 |
MVPbkContactStore& /*aContactStore*/ )
|
|
173 |
{
|
|
174 |
}
|
|
175 |
|
|
176 |
// --------------------------------------------------------------------------
|
|
177 |
// CPbk2RemoveSpeedDialCmd::StoreUnavailable
|
|
178 |
// --------------------------------------------------------------------------
|
|
179 |
//
|
|
180 |
void CPbk2RemoveSpeedDialCmd::StoreUnavailable(
|
|
181 |
MVPbkContactStore& /*aContactStore*/,
|
|
182 |
TInt /*aReason*/ )
|
|
183 |
{
|
|
184 |
}
|
|
185 |
|
|
186 |
// --------------------------------------------------------------------------
|
|
187 |
// CPbk2RemoveSpeedDialCmd::HandleStoreEventL
|
|
188 |
// --------------------------------------------------------------------------
|
|
189 |
//
|
|
190 |
void CPbk2RemoveSpeedDialCmd::HandleStoreEventL(
|
|
191 |
MVPbkContactStore& /*aContactStore*/,
|
|
192 |
TVPbkContactStoreEvent aStoreEvent )
|
|
193 |
{
|
|
194 |
if ( iContactLink &&
|
|
195 |
aStoreEvent.iContactLink->IsSame( *iContactLink ) )
|
|
196 |
{
|
|
197 |
switch( aStoreEvent.iEventType )
|
|
198 |
{
|
|
199 |
case TVPbkContactStoreEvent::EContactDeleted: // FALLTHROUGH
|
|
200 |
case TVPbkContactStoreEvent::EContactChanged: // FALLTHROUGH
|
|
201 |
|
|
202 |
default:
|
|
203 |
break;
|
|
204 |
}
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
// --------------------------------------------------------------------------
|
|
209 |
// CPbk2RemoveSpeedDialCmd::VPbkSingleContactOperationComplete
|
|
210 |
// --------------------------------------------------------------------------
|
|
211 |
//
|
|
212 |
void CPbk2RemoveSpeedDialCmd::VPbkSingleContactOperationComplete(
|
|
213 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
214 |
MVPbkStoreContact* aContact)
|
|
215 |
{
|
|
216 |
delete iOperation;
|
|
217 |
iOperation = NULL;
|
|
218 |
|
|
219 |
delete iStoreContact;
|
|
220 |
iStoreContact = aContact;
|
|
221 |
|
|
222 |
TRAPD(error, iStoreContact->LockL(*this));
|
|
223 |
if (error != KErrNone)
|
|
224 |
{
|
|
225 |
FinishCommand(error);
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
// --------------------------------------------------------------------------
|
|
230 |
// CPbk2RemoveSpeedDialCmd::VPbkSingleContactOperationFailed
|
|
231 |
// --------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
void CPbk2RemoveSpeedDialCmd::VPbkSingleContactOperationFailed(
|
|
234 |
MVPbkContactOperationBase& /*aOperation*/,
|
|
235 |
TInt aError)
|
|
236 |
{
|
|
237 |
delete iOperation;
|
|
238 |
iOperation = NULL;
|
|
239 |
|
|
240 |
FinishCommand(aError);
|
|
241 |
}
|
|
242 |
|
|
243 |
// --------------------------------------------------------------------------
|
|
244 |
// CPbk2RemoveSpeedDialCmd::ContactOperationCompleted
|
|
245 |
// --------------------------------------------------------------------------
|
|
246 |
//
|
|
247 |
void CPbk2RemoveSpeedDialCmd::ContactOperationCompleted
|
|
248 |
(TContactOpResult aResult)
|
|
249 |
{
|
|
250 |
if (aResult.iOpCode == EContactCommit)
|
|
251 |
{
|
|
252 |
FinishCommand(KErrNone);
|
|
253 |
}
|
|
254 |
else if (aResult.iOpCode == EContactLock)
|
|
255 |
{
|
|
256 |
TInt index = KErrNotFound;
|
|
257 |
TInt err = KErrNone;
|
|
258 |
|
|
259 |
if (iUiControl)
|
|
260 |
{
|
|
261 |
index = iUiControl->FocusedFieldIndex();
|
|
262 |
}
|
|
263 |
|
|
264 |
if ( index != KErrNotFound )
|
|
265 |
{
|
|
266 |
MVPbkStoreContactField& field =
|
|
267 |
iStoreContact->Fields().FieldAt( index );
|
|
268 |
|
|
269 |
TBool hasAttribute = EFalse;
|
|
270 |
TRAP(err, hasAttribute =
|
|
271 |
iAppServices->ContactManager().
|
|
272 |
ContactAttributeManagerL().
|
|
273 |
HasFieldAttributeL(CVPbkSpeedDialAttribute::Uid(), field));
|
|
274 |
|
|
275 |
if (hasAttribute)
|
|
276 |
{
|
|
277 |
TRAP(err, iOperation = iAppServices->ContactManager().
|
|
278 |
ContactAttributeManagerL().RemoveFieldAttributeL(
|
|
279 |
field, CVPbkSpeedDialAttribute::Uid(), *this) );
|
|
280 |
}
|
|
281 |
else
|
|
282 |
{
|
|
283 |
FinishCommand( err );
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
if (err != KErrNone)
|
|
288 |
{
|
|
289 |
FinishCommand( err );
|
|
290 |
}
|
|
291 |
}
|
|
292 |
}
|
|
293 |
|
|
294 |
// --------------------------------------------------------------------------
|
|
295 |
// CPbk2RemoveSpeedDialCmd::ContactOperationFailed
|
|
296 |
// --------------------------------------------------------------------------
|
|
297 |
//
|
|
298 |
void CPbk2RemoveSpeedDialCmd::ContactOperationFailed
|
|
299 |
(TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/)
|
|
300 |
{
|
|
301 |
delete iOperation;
|
|
302 |
iOperation = NULL;
|
|
303 |
|
|
304 |
FinishCommand(aErrorCode);
|
|
305 |
}
|
|
306 |
|
|
307 |
// --------------------------------------------------------------------------
|
|
308 |
// CPbk2RemoveSpeedDialCmd::AttributeOperationComplete
|
|
309 |
// --------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
void CPbk2RemoveSpeedDialCmd::AttributeOperationComplete(
|
|
312 |
MVPbkContactOperationBase& /*aOperation*/)
|
|
313 |
{
|
|
314 |
delete iOperation;
|
|
315 |
iOperation = NULL;
|
|
316 |
|
|
317 |
TRAP_IGNORE(iStoreContact->CommitL(*this));
|
|
318 |
}
|
|
319 |
|
|
320 |
// --------------------------------------------------------------------------
|
|
321 |
// CPbk2RemoveSpeedDialCmd::AttributeOperationFailed
|
|
322 |
// --------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
void CPbk2RemoveSpeedDialCmd::AttributeOperationFailed(
|
|
325 |
MVPbkContactOperationBase& /*aOperation*/, TInt aError)
|
|
326 |
{
|
|
327 |
delete iOperation;
|
|
328 |
iOperation = NULL;
|
|
329 |
|
|
330 |
FinishCommand(aError);
|
|
331 |
}
|
|
332 |
|
|
333 |
// --------------------------------------------------------------------------
|
|
334 |
// CPbk2RemoveSpeedDialCmd::FinishCommand
|
|
335 |
// --------------------------------------------------------------------------
|
|
336 |
//
|
|
337 |
void CPbk2RemoveSpeedDialCmd::FinishCommand(TInt aError)
|
|
338 |
{
|
|
339 |
__ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer));
|
|
340 |
|
|
341 |
TInt error( aError );
|
|
342 |
if (iUiControl && error == KErrNone)
|
|
343 |
{
|
|
344 |
CPbk2AppUiBase<CAknViewAppUi>& appUi = static_cast<CPbk2AppUiBase<CAknViewAppUi>&>
|
|
345 |
( *CEikonEnv::Static()->EikAppUi() );
|
|
346 |
// If appUi is not in foreground, It means phonebook2 has hidden itself in background,
|
|
347 |
// no need to reload its contact, only phonebook2 in foreground case, need to reload
|
|
348 |
// call SetFocusedContactL
|
|
349 |
if ( appUi.IsForeground() )
|
|
350 |
{
|
|
351 |
TRAP( error,
|
|
352 |
iUiControl->SetFocusedContactL(
|
|
353 |
*iUiControl->FocusedStoreContact() ) );
|
|
354 |
|
|
355 |
iUiControl->SetFocusedFieldIndex( iUiControl->FocusedFieldIndex() );
|
|
356 |
iUiControl->UpdateAfterCommandExecution();
|
|
357 |
}
|
|
358 |
}
|
|
359 |
|
|
360 |
iCommandObserver->CommandFinished(*this);
|
|
361 |
|
|
362 |
if (error != KErrNone)
|
|
363 |
{
|
|
364 |
CCoeEnv::Static()->HandleError(error);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
// --------------------------------------------------------------------------
|
|
369 |
// CPbk2RemoveSpeedDialCmd::ToStoreFieldIndexL
|
|
370 |
// --------------------------------------------------------------------------
|
|
371 |
//
|
|
372 |
TInt CPbk2RemoveSpeedDialCmd::ToStoreFieldIndexL(
|
|
373 |
TInt aPresIndex,
|
|
374 |
const MVPbkStoreContact* aStoreContact )
|
|
375 |
{
|
|
376 |
// It is ok to remove const, we don't make any changes
|
|
377 |
MVPbkStoreContact* storeContact =
|
|
378 |
const_cast<MVPbkStoreContact*>( aStoreContact );
|
|
379 |
|
|
380 |
TInt index( KErrNotFound );
|
|
381 |
CPbk2PresentationContact* presentationContact =
|
|
382 |
CPbk2PresentationContact::NewL(
|
|
383 |
*storeContact,
|
|
384 |
iAppServices->FieldProperties() );
|
|
385 |
CleanupStack::PushL( presentationContact );
|
|
386 |
|
|
387 |
index = presentationContact->PresentationFields().StoreIndexOfField
|
|
388 |
( aPresIndex );
|
|
389 |
|
|
390 |
CleanupStack::PopAndDestroy( presentationContact );
|
|
391 |
|
|
392 |
return index;
|
|
393 |
}
|
|
394 |
|
|
395 |
// --------------------------------------------------------------------------
|
|
396 |
// CPbk2CommandHandler::HasSpeedDialL
|
|
397 |
// --------------------------------------------------------------------------
|
|
398 |
//
|
|
399 |
TBool CPbk2RemoveSpeedDialCmd::HasSpeedDialL()
|
|
400 |
{
|
|
401 |
TBool hasAttribute(EFalse);
|
|
402 |
|
|
403 |
const MVPbkStoreContact* storeContact =
|
|
404 |
iUiControl->FocusedStoreContact();
|
|
405 |
|
|
406 |
|
|
407 |
TInt index = iUiControl->FocusedFieldIndex();
|
|
408 |
|
|
409 |
|
|
410 |
if ( index != KErrNotFound )
|
|
411 |
{
|
|
412 |
const MVPbkStoreContactField& field =
|
|
413 |
storeContact->Fields().FieldAt( index );
|
|
414 |
|
|
415 |
hasAttribute =
|
|
416 |
iAppServices->ContactManager().ContactAttributeManagerL().
|
|
417 |
HasFieldAttributeL(
|
|
418 |
CVPbkSpeedDialAttribute::Uid(),
|
|
419 |
field );
|
|
420 |
}
|
|
421 |
return hasAttribute;
|
|
422 |
}
|
|
423 |
|
|
424 |
// End of File
|