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: The virtual phonebook asynchronous contact operation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDES
|
|
21 |
#include "CAsyncContactOperation.h"
|
|
22 |
#include <cntdb.h>
|
|
23 |
#include <cntitem.h>
|
|
24 |
#include "CContactStore.h"
|
|
25 |
#include "CContact.h"
|
|
26 |
#include <CVPbkDiskSpaceCheck.h>
|
|
27 |
#include <MVPbkContactStoreProperties.h>
|
|
28 |
|
|
29 |
|
|
30 |
namespace VPbkCntModel {
|
|
31 |
|
|
32 |
const TInt KDiskSpaceNeedUnknown = 0;
|
|
33 |
|
|
34 |
inline CAsyncContactOperation::CAsyncContactOperation
|
|
35 |
( CContactStore& aContactStore ) :
|
|
36 |
CAsyncOneShot( CActive::EPriorityIdle ),
|
|
37 |
iContactStore( aContactStore ),
|
|
38 |
iOpCode( MVPbkContactObserver::EContactOperationUnknown )
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
CAsyncContactOperation* CAsyncContactOperation::NewL
|
|
43 |
( CContactStore& aContactStore )
|
|
44 |
{
|
|
45 |
CAsyncContactOperation* self =
|
|
46 |
new(ELeave) CAsyncContactOperation( aContactStore );
|
|
47 |
CleanupStack::PushL( self );
|
|
48 |
self->ConstructL();
|
|
49 |
CleanupStack::Pop( self );
|
|
50 |
return self;
|
|
51 |
}
|
|
52 |
|
|
53 |
CAsyncContactOperation::~CAsyncContactOperation()
|
|
54 |
{
|
|
55 |
CActive::Cancel();
|
|
56 |
delete iDiskSpaceChecker;
|
|
57 |
iFs.Close();
|
|
58 |
delete iViewDef;
|
|
59 |
}
|
|
60 |
|
|
61 |
void CAsyncContactOperation::ConstructL()
|
|
62 |
{
|
|
63 |
User::LeaveIfError( iFs.Connect() );
|
|
64 |
// Get contact store location drive for disk space check
|
|
65 |
const TPtrC ptr( iContactStore.StoreProperties().Uri().Component
|
|
66 |
( TVPbkContactStoreUriPtr::EContactStoreUriStoreDrive ) );
|
|
67 |
TInt drive( EDriveA ); // c is usually the default location
|
|
68 |
User::LeaveIfError( iFs.CharToDrive
|
|
69 |
( ptr[0], drive) );
|
|
70 |
iDiskSpaceChecker = VPbkEngUtils::CVPbkDiskSpaceCheck::NewL( iFs, drive );
|
|
71 |
|
|
72 |
iViewDef = CContactItemViewDef::NewL(
|
|
73 |
CContactItemViewDef::EIncludeFields,
|
|
74 |
CContactItemViewDef::EMaskHiddenFields);
|
|
75 |
|
|
76 |
iViewDef->AddL( KUidContactFieldMatchAll );
|
|
77 |
|
|
78 |
}
|
|
79 |
|
|
80 |
void CAsyncContactOperation::PrepareL
|
|
81 |
( MVPbkContactObserver::TContactOp aOpCode,
|
|
82 |
TContactItemId aContactId,
|
|
83 |
MVPbkContactObserver& aObserver )
|
|
84 |
{
|
|
85 |
if ( IsActive() )
|
|
86 |
{
|
|
87 |
User::Leave( KErrInUse );
|
|
88 |
}
|
|
89 |
iTargetContactId = aContactId;
|
|
90 |
iOpCode = aOpCode;
|
|
91 |
iObserver = &aObserver;
|
|
92 |
iClientContact = NULL;
|
|
93 |
}
|
|
94 |
|
|
95 |
void CAsyncContactOperation::PrepareL
|
|
96 |
( MVPbkContactObserver::TContactOp aOpCode,
|
|
97 |
const CContact& aContact,
|
|
98 |
MVPbkContactObserver& aObserver )
|
|
99 |
{
|
|
100 |
if ( IsActive() )
|
|
101 |
{
|
|
102 |
User::Leave( KErrInUse );
|
|
103 |
}
|
|
104 |
iOpCode = aOpCode;
|
|
105 |
iObserver = &aObserver;
|
|
106 |
iClientContact = &aContact;
|
|
107 |
}
|
|
108 |
|
|
109 |
void CAsyncContactOperation::Cancel( CContactItem* aContact )
|
|
110 |
{
|
|
111 |
if ( iClientContact &&
|
|
112 |
aContact == iClientContact->NativeContact() )
|
|
113 |
{
|
|
114 |
// Do not call CActive::Cancel(), it is not desired since not all
|
|
115 |
// operations are affected. The client contact is just not
|
|
116 |
// valid anymore, so let's reset it.
|
|
117 |
iClientContact = NULL;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
void CAsyncContactOperation::DoCancel()
|
|
122 |
{
|
|
123 |
iOpCode = MVPbkContactObserver::EContactOperationUnknown;
|
|
124 |
}
|
|
125 |
|
|
126 |
void CAsyncContactOperation::RunL()
|
|
127 |
{
|
|
128 |
MVPbkContactObserver::TContactOpResult result;
|
|
129 |
result.iOpCode = iOpCode;
|
|
130 |
result.iStoreContact = NULL;
|
|
131 |
result.iExtension = NULL;
|
|
132 |
|
|
133 |
switch( iOpCode )
|
|
134 |
{
|
|
135 |
case MVPbkContactObserver::EContactRead:
|
|
136 |
{
|
|
137 |
CContactItem* ci =
|
|
138 |
iContactStore.NativeDatabase().ReadContactLC( iTargetContactId );
|
|
139 |
result.iStoreContact = CContact::NewL( iContactStore, ci );
|
|
140 |
CleanupStack::Pop( ci );
|
|
141 |
break;
|
|
142 |
}
|
|
143 |
|
|
144 |
case MVPbkContactObserver::EContactReadAndLock:
|
|
145 |
{
|
|
146 |
CContactItem* ci =
|
|
147 |
iContactStore.NativeDatabase().OpenContactLX( iTargetContactId, *iViewDef );
|
|
148 |
CleanupStack::PushL( ci );
|
|
149 |
|
|
150 |
CContact* contact = CContact::NewL( iContactStore, ci );
|
|
151 |
result.iStoreContact = contact;
|
|
152 |
contact->SetModified();
|
|
153 |
CleanupStack::Pop( 2 ); // ci, lock
|
|
154 |
break;
|
|
155 |
}
|
|
156 |
|
|
157 |
case MVPbkContactObserver::EContactDelete:
|
|
158 |
{
|
|
159 |
iContactStore.NativeDatabase().DeleteContactL( iTargetContactId );
|
|
160 |
break;
|
|
161 |
}
|
|
162 |
|
|
163 |
case MVPbkContactObserver::EContactLock:
|
|
164 |
{
|
|
165 |
if( iClientContact )
|
|
166 |
{
|
|
167 |
CContactItem* ci = iContactStore.NativeDatabase().OpenContactLX(
|
|
168 |
iClientContact->NativeContact()->Id(), *iViewDef );
|
|
169 |
CleanupStack::PushL( ci );
|
|
170 |
const_cast<CContact*>( iClientContact )->SetContact( ci );
|
|
171 |
const_cast<CContact*>( iClientContact )->SetModified();
|
|
172 |
CleanupStack::Pop( 2 ); // ci, lock
|
|
173 |
}
|
|
174 |
break;
|
|
175 |
}
|
|
176 |
|
|
177 |
case MVPbkContactObserver::EContactCommit:
|
|
178 |
{
|
|
179 |
if( iClientContact )
|
|
180 |
{
|
|
181 |
iDiskSpaceChecker->DiskSpaceCheckL( KDiskSpaceNeedUnknown );
|
|
182 |
if (iClientContact->IsNewContact())
|
|
183 |
{
|
|
184 |
iContactStore.NativeDatabase().AddNewContactL(
|
|
185 |
*iClientContact->NativeContact() );
|
|
186 |
}
|
|
187 |
else
|
|
188 |
{
|
|
189 |
iContactStore.NativeDatabase().CommitContactL(
|
|
190 |
*iClientContact->NativeContact() );
|
|
191 |
}
|
|
192 |
}
|
|
193 |
break;
|
|
194 |
}
|
|
195 |
case MVPbkContactObserver::EContactSetOwn:
|
|
196 |
{
|
|
197 |
iContactStore.NativeDatabase().SetOwnCardL( *iClientContact->NativeContact() );
|
|
198 |
break;
|
|
199 |
}
|
|
200 |
default:
|
|
201 |
{
|
|
202 |
// Operation was canceled
|
|
203 |
return;
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
iObserver->ContactOperationCompleted( result );
|
|
208 |
}
|
|
209 |
|
|
210 |
TInt CAsyncContactOperation::RunError( TInt aError )
|
|
211 |
{
|
|
212 |
iObserver->ContactOperationFailed( iOpCode, aError, EFalse );
|
|
213 |
return KErrNone;
|
|
214 |
}
|
|
215 |
|
|
216 |
} // namespace VPbkCntModel
|
|
217 |
|
|
218 |
//End of file
|