19
|
1 |
/*
|
|
2 |
* Copyright (c) 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 the License "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: Implementation of the organise groups observer functionality.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
//User includes
|
|
20 |
#include "organisegroupsobserver.h"
|
|
21 |
#include "contactcallback.h"
|
|
22 |
|
|
23 |
//System include
|
|
24 |
#include <cvpbkcontactmanager.h>// for iContactManager
|
|
25 |
#include <mvpbkcontactstore.h>// for iContactStore
|
|
26 |
#include <mvpbkstorecontact.h>// used in many function to get the store contact
|
|
27 |
#include <mvpbkcontactoperationbase.h>//for observer
|
|
28 |
#include <mvpbkcontactlink.h>//for param in ContactsSaved()
|
|
29 |
#include <MVPbkContactGroup.h>
|
|
30 |
#include <CVPbkContactLinkArray.h>
|
|
31 |
|
|
32 |
|
|
33 |
//-------------------------------------------------------------------------------------
|
|
34 |
// Static method to create instance of organise groups observer.
|
|
35 |
//-------------------------------------------------------------------------------------
|
|
36 |
|
|
37 |
COrganiseGroupsObserver* COrganiseGroupsObserver::NewL( CContactService* aContactService,
|
|
38 |
const TDesC8& aGroupId,
|
|
39 |
RPointerArray<TDesC8>& aContactIdArray,
|
|
40 |
TBool aAssociateFlag,
|
|
41 |
TInt aTransId,
|
|
42 |
MContactCallback* aCallback,
|
|
43 |
MVPbkContactStore* aContactStore )
|
|
44 |
{
|
|
45 |
|
|
46 |
COrganiseGroupsObserver* self = new( ELeave ) COrganiseGroupsObserver( );
|
|
47 |
CleanupStack::PushL(self);
|
|
48 |
self->ConstructL(aContactService, aGroupId,
|
|
49 |
aContactIdArray, aAssociateFlag, aTransId, aCallback, aContactStore );
|
|
50 |
CleanupStack::Pop(self);
|
|
51 |
return self;
|
|
52 |
|
|
53 |
}
|
|
54 |
|
|
55 |
//Constructor.
|
|
56 |
COrganiseGroupsObserver::COrganiseGroupsObserver()
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
//second-phase constructor
|
|
61 |
void COrganiseGroupsObserver::ConstructL( CContactService* aContactService,
|
|
62 |
const TDesC8& aGroupId ,
|
|
63 |
RPointerArray<TDesC8>& aContactIdArray,
|
|
64 |
TBool aAssociateFlag,
|
|
65 |
TInt aTransId,
|
|
66 |
MContactCallback* aCallback,
|
|
67 |
MVPbkContactStore* aContactStore )
|
|
68 |
{
|
|
69 |
iContactService = aContactService;
|
|
70 |
iGroupId = HBufC8 :: NewL(aGroupId.Length());
|
|
71 |
*iGroupId = aGroupId;
|
|
72 |
iAssociateFlag = aAssociateFlag;
|
|
73 |
iTransId = aTransId;
|
|
74 |
iCallback = aCallback;
|
|
75 |
iContactStore = aContactStore;
|
|
76 |
iContactLinkArray = CVPbkContactLinkArray::NewL();
|
|
77 |
iContactManager = &(iContactService->GetContactManager());
|
|
78 |
ConvertContactIdsToLinkArrayL( aContactIdArray );
|
|
79 |
iOp =NULL;
|
|
80 |
}
|
|
81 |
|
|
82 |
/*
|
|
83 |
-------------------------------------------------------------------------------------
|
|
84 |
COrganiseGroupsObserver::Cancel()
|
|
85 |
Description : Cancel implementation relevant to OrganiseObserver
|
|
86 |
Return values : KErrorNone on Success and KErrGeneral on Failure
|
|
87 |
-------------------------------------------------------------------------------------
|
|
88 |
*/
|
|
89 |
|
|
90 |
void COrganiseGroupsObserver::Cancel()
|
|
91 |
{
|
|
92 |
iCallback->HandleReturnValue(EOpCancel, KErrNone, iTransId);
|
|
93 |
delete this;
|
|
94 |
}
|
|
95 |
|
|
96 |
//Get MVPbkContactLinkArray from the dynamic array, which is having contact ids.
|
|
97 |
|
|
98 |
void COrganiseGroupsObserver::ConvertContactIdsToLinkArrayL( RPointerArray<TDesC8>& aContactIdArray )
|
|
99 |
{
|
|
100 |
TInt contactIdCount = aContactIdArray.Count();
|
|
101 |
|
|
102 |
for(TInt index = 0; index < contactIdCount; index++)
|
|
103 |
{
|
|
104 |
//get the id from the contact id array
|
|
105 |
TPtrC8 contactId = *aContactIdArray[index];
|
|
106 |
|
|
107 |
//construct link using contact mngr's CreateLinksLC
|
|
108 |
MVPbkContactLinkArray* tmpLinkArray = iContactManager->CreateLinksLC(contactId);
|
|
109 |
|
|
110 |
iLinkArrayToDelete.AppendL(tmpLinkArray);
|
|
111 |
|
|
112 |
iContactLinkArray->AppendL(const_cast<MVPbkContactLink*> (&(tmpLinkArray->At(0))) );
|
|
113 |
|
|
114 |
CleanupStack::Pop(); //tmpLinkArray
|
|
115 |
}
|
|
116 |
|
|
117 |
}
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
//Destructor.
|
|
122 |
COrganiseGroupsObserver::~COrganiseGroupsObserver()
|
|
123 |
{
|
|
124 |
|
|
125 |
TInt count = iLinkArrayToDelete.Count();
|
|
126 |
if( count )
|
|
127 |
{
|
|
128 |
for(TInt index = 0; index < count; index++)
|
|
129 |
{
|
|
130 |
delete iLinkArrayToDelete[index];
|
|
131 |
}
|
|
132 |
}
|
|
133 |
iLinkArrayToDelete.Reset();
|
|
134 |
if(iContactLinkArray)
|
|
135 |
{
|
|
136 |
iContactLinkArray->Reset();
|
|
137 |
delete iContactLinkArray;
|
|
138 |
iContactLinkArray = NULL;
|
|
139 |
}
|
|
140 |
delete iLinkArray;
|
|
141 |
if(iOp)
|
|
142 |
{
|
|
143 |
delete iOp;
|
|
144 |
}
|
|
145 |
if(iContactStore)
|
|
146 |
{
|
|
147 |
iContactStore->Close(*this);
|
|
148 |
}
|
|
149 |
delete iGroupId;
|
|
150 |
}
|
|
151 |
|
|
152 |
//DoGetGroupL : gets the group from the contact manager.
|
|
153 |
void COrganiseGroupsObserver::DoGetGroupL()
|
|
154 |
{
|
|
155 |
iLinkArray = iContactManager->CreateLinksLC( *iGroupId );
|
|
156 |
|
|
157 |
iOp = iContactManager->RetrieveContactL( iLinkArray->At(0), *this );
|
|
158 |
|
|
159 |
CleanupStack::Pop();
|
|
160 |
}
|
|
161 |
|
|
162 |
//Enteres when OpenL() is successfull
|
|
163 |
void COrganiseGroupsObserver::StoreReady( MVPbkContactStore& /*aContactStore*/ )
|
|
164 |
{
|
|
165 |
TRAPD(error,DoGetGroupL());
|
|
166 |
|
|
167 |
if(error != KErrNone)
|
|
168 |
{
|
|
169 |
iContactService->RequestComplete(iTransId);
|
|
170 |
iCallback->HandleReturnValue(EOpComplete, error, iTransId);
|
|
171 |
delete this;
|
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
//Eneters when OpenL() fails.
|
|
176 |
void COrganiseGroupsObserver::StoreUnavailable( MVPbkContactStore& /*aContactStore*/, TInt aReason )
|
|
177 |
{
|
|
178 |
iContactService->RequestComplete(iTransId);
|
|
179 |
iCallback->HandleReturnValue(EOpError, aReason, iTransId);
|
|
180 |
|
|
181 |
delete this;
|
|
182 |
}
|
|
183 |
|
|
184 |
void COrganiseGroupsObserver::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/, TVPbkContactStoreEvent /*aStoreEvent*/ )
|
|
185 |
{
|
|
186 |
//do nothing here
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
//Associtates/Disassociates list of contacts to/from the group.
|
|
191 |
void COrganiseGroupsObserver::DoOrganiseGroupsL(MVPbkStoreContact* aContact)
|
|
192 |
{
|
|
193 |
MVPbkContactGroup* groupPtr = aContact->Group();
|
|
194 |
if( !groupPtr )
|
|
195 |
{
|
|
196 |
User::Leave(KErrNotFound);
|
|
197 |
}
|
|
198 |
|
|
199 |
TInt linkCount = iContactLinkArray->Count();
|
|
200 |
if(iAssociateFlag)
|
|
201 |
{
|
|
202 |
for(TInt index = 0; index < linkCount; index++)
|
|
203 |
{
|
|
204 |
groupPtr->AddContactL(iContactLinkArray->At(index));
|
|
205 |
}
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
for(TInt index = 0; index < linkCount; index++)
|
|
210 |
{
|
|
211 |
groupPtr->RemoveContactL(iContactLinkArray->At(index));
|
|
212 |
}
|
|
213 |
}
|
|
214 |
delete groupPtr;
|
|
215 |
}
|
|
216 |
|
|
217 |
//Single contact operation observer methods
|
|
218 |
void COrganiseGroupsObserver::VPbkSingleContactOperationComplete( MVPbkContactOperationBase& aOperation,
|
|
219 |
MVPbkStoreContact* aContact)
|
|
220 |
{
|
|
221 |
delete &aOperation;
|
|
222 |
iOp = NULL;
|
|
223 |
iContactService->RequestComplete(iTransId);
|
|
224 |
|
|
225 |
TRAPD(error, DoOrganiseGroupsL(aContact));
|
|
226 |
|
|
227 |
iCallback->HandleReturnValue(EOpComplete, error, iTransId);
|
|
228 |
|
|
229 |
delete this;
|
|
230 |
}
|
|
231 |
|
|
232 |
|
|
233 |
void COrganiseGroupsObserver::VPbkSingleContactOperationFailed( MVPbkContactOperationBase& aOperation,
|
|
234 |
TInt aError)
|
|
235 |
{
|
|
236 |
delete &aOperation;
|
|
237 |
iOp = NULL;
|
|
238 |
iContactService->RequestComplete(iTransId);
|
|
239 |
|
|
240 |
iCallback->HandleReturnValue(EOpError, aError, iTransId);
|
|
241 |
delete this;
|
|
242 |
}
|
|
243 |
|