|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Updates Log events adding remote party |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <logfilterandeventconstants.hrh> |
|
23 #endif |
|
24 #include <logcli.h> |
|
25 #include <logview.h> |
|
26 #include <VPbkEng.rsg> |
|
27 #include <PbkFields.hrh> |
|
28 #include <CVPbkContactFieldIterator.h> |
|
29 #include <CVPbkContactManager.h> |
|
30 #include <MVPbkFieldType.h> |
|
31 #include <MVPbkStoreContact.h> |
|
32 #include <MVPbkContactFieldTextData.h> |
|
33 |
|
34 #include "CLogsEventUpdater.h" |
|
35 #include "MLogsObserver.h" |
|
36 #include "MLogsReaderConfig.h" |
|
37 |
|
38 // EXTERNAL DATA STRUCTURES |
|
39 |
|
40 // EXTERNAL FUNCTION PROTOTYPES |
|
41 |
|
42 // CONSTANTS |
|
43 const TInt KLogsPbkTypeIdLength = 11; |
|
44 // MACROS |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 |
|
48 // MODULE DATA STRUCTURES |
|
49 |
|
50 // LOCAL FUNCTION PROTOTYPES |
|
51 |
|
52 // ==================== LOCAL FUNCTIONS ==================== |
|
53 |
|
54 // ================= MEMBER FUNCTIONS ======================= |
|
55 |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CLogsEventUpdater::CLogsEventUpdater |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 CLogsEventUpdater::CLogsEventUpdater( |
|
62 RFs& aFsSession, |
|
63 MLogsObserver* aObserver ) : |
|
64 CLogsBaseUpdater( aFsSession, aObserver ), |
|
65 iNumberFieldType( EPbkFieldIdNone ) |
|
66 { |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CLogsEventUpdater::NewL |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 CLogsEventUpdater* CLogsEventUpdater::NewL( |
|
74 RFs& aFsSession, |
|
75 MLogsObserver* aObserver, |
|
76 CVPbkPhoneNumberMatchStrategy::TVPbkPhoneNumberMatchFlags aMatchFlags ) |
|
77 { |
|
78 CLogsEventUpdater* self = new ( ELeave ) CLogsEventUpdater( aFsSession, aObserver ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL( aMatchFlags ); |
|
81 CleanupStack::Pop(); |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CLogsEventUpdater::ConstructL |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 void CLogsEventUpdater::ConstructL( CVPbkPhoneNumberMatchStrategy::TVPbkPhoneNumberMatchFlags aMatchFlags ) |
|
90 { |
|
91 BaseConstructL( aMatchFlags ); |
|
92 iLogViewEvent = CLogViewEvent::NewL( *iLogClient ); |
|
93 iFilter->SetNullFields( ELogRemotePartyField ); |
|
94 CActiveScheduler::Add( this ); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CLogsEventUpdater::~CLogsEventUpdater |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 CLogsEventUpdater::~CLogsEventUpdater() |
|
102 { |
|
103 delete iNumber; |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CLogsEventUpdater::StartRunningL |
|
108 // |
|
109 // Called from base class |
|
110 // ---------------------------------------------------------------------------- |
|
111 // |
|
112 void CLogsEventUpdater::StartRunningL() |
|
113 { |
|
114 Cancel(); |
|
115 |
|
116 //Important that ConfigureL is called before we start here |
|
117 if( iNumber ) |
|
118 { |
|
119 //We first try to search corresponding contact for this phonenumber from Phonebook |
|
120 SearchRemotePartyL( *iNumber ); |
|
121 } |
|
122 } |
|
123 |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // CLogsEventUpdater::ContinueRunningL |
|
127 // ---------------------------------------------------------------------------- |
|
128 // |
|
129 void CLogsEventUpdater::ContinueRunningL( TInt aFieldId ) |
|
130 { |
|
131 TBool okToContinue( EFalse ); |
|
132 |
|
133 //1. Continue only if the contact was found from Phonebook as we prcess only one phone number at a time. |
|
134 if( aFieldId != KErrNotFound ) |
|
135 { |
|
136 |
|
137 // iFieldId.Num( aFieldId ); |
|
138 okToContinue = iLogViewEvent->SetFilterL( *iFilter, iStatus ); //ETrue, if at least one row in db available for filter, |
|
139 //current entry will be the first in view when asynch call |
|
140 //is finished. |
|
141 } |
|
142 |
|
143 //2. Continue only if found one or more database entries that need updating the remote party. |
|
144 if( okToContinue ) |
|
145 { |
|
146 iState = EStateActive; |
|
147 iPhase = ERead; |
|
148 SetActive(); //Continue |
|
149 } |
|
150 else if( iObserver ) //End this run |
|
151 { |
|
152 iState = EStateEventUpdaterFinished; |
|
153 iPhase = EDone; |
|
154 iObserver->StateChangedL( this ); |
|
155 } |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // CLogsEventUpdater::ConfigureL |
|
160 // |
|
161 // Sets the phone number that is used as search criteria this time (all events containing this |
|
162 // phone number are updated to log database) |
|
163 // ---------------------------------------------------------------------------- |
|
164 // |
|
165 void CLogsEventUpdater::ConfigureL( const MLogsReaderConfig* aConfig ) //Implemented from MLogsReader |
|
166 { |
|
167 if( iNumber ) |
|
168 { |
|
169 delete iNumber; |
|
170 iNumber = NULL; |
|
171 } |
|
172 iNumber = aConfig->Number().AllocL(); |
|
173 iFilter->SetNumber( *iNumber ); |
|
174 } |
|
175 |
|
176 |
|
177 // ---------------------------------------------------------------------------- |
|
178 // CLogsEventUpdater::RunL |
|
179 // |
|
180 // Update Log database entries corresponding to the filter |
|
181 // ---------------------------------------------------------------------------- |
|
182 // |
|
183 void CLogsEventUpdater::RunL() |
|
184 { |
|
185 if( iStatus != KErrNone && iObserver || |
|
186 *iName == KNullDesC ) // If the contact name is empty, dont update. Otherwise the code below the else |
|
187 // statement loops forewer between asynch calls to iLogClient->ChangeEvent and |
|
188 // iLogViewEvent->FirstL |
|
189 { |
|
190 iState = EStateEventUpdaterFinished; |
|
191 if ( iObserver ) |
|
192 { |
|
193 iObserver->StateChangedL( this ); |
|
194 } |
|
195 } |
|
196 else |
|
197 { |
|
198 switch( iPhase ) |
|
199 { |
|
200 case ERead: |
|
201 { |
|
202 TBuf<KLogsPbkTypeIdLength> subject; |
|
203 subject.Zero(); |
|
204 iEvent->CopyL( iLogViewEvent->Event() ); |
|
205 iEvent->SetRemoteParty( *iName ); |
|
206 subject.AppendNum( iNumberFieldType ); |
|
207 iEvent->SetSubject( subject ); |
|
208 iEvent->SetContact( KNullContactId ); //In Pbk2 links are used instead of TContactItemId |
|
209 iPhase = EUpdate; |
|
210 iLogClient->ChangeEvent( *iEvent, iStatus ); |
|
211 SetActive(); |
|
212 } |
|
213 break; |
|
214 |
|
215 case EUpdate: |
|
216 if( iLogViewEvent->FirstL( iStatus ) ) //If there's still at least one entry in view, let's continue |
|
217 //processing it (this assumes that the event updated above has |
|
218 //already disappeared from view and the "next" shows now as "first" |
|
219 //in view, otherwise not all events are updated correctly). |
|
220 { |
|
221 iPhase = ERead; |
|
222 SetActive(); |
|
223 } |
|
224 else if( iObserver ) |
|
225 { |
|
226 iState = EStateEventUpdaterFinished; |
|
227 iPhase = EDone; |
|
228 iObserver->StateChangedL( this ); |
|
229 } |
|
230 break; |
|
231 |
|
232 default: |
|
233 break; |
|
234 } |
|
235 } |
|
236 } |
|
237 |
|
238 // ---------------------------------------------------------------------------- |
|
239 // CLogsEventUpdater::ProcessVPbkSingleContactOperationCompleteImplL |
|
240 // |
|
241 // Detrived function by base class for get the number's pbk field type |
|
242 // ---------------------------------------------------------------------------- |
|
243 // |
|
244 void CLogsEventUpdater::ProcessVPbkSingleContactOperationCompleteImplL( |
|
245 MVPbkContactOperationBase& aOperation, |
|
246 MVPbkStoreContact* aContact ) |
|
247 { |
|
248 //invoke the base class function firstly to get the event's title(name) |
|
249 CLogsBaseUpdater::ProcessVPbkSingleContactOperationCompleteImplL( aOperation, aContact ); |
|
250 |
|
251 iNumberFieldType = EPbkFieldIdNone ; |
|
252 TBool found( EFalse ); |
|
253 |
|
254 TInt count = iContactManager->FieldTypes().FieldTypeCount(); |
|
255 |
|
256 for ( TInt i = 0; i < count && !found; i++ ) |
|
257 { |
|
258 const MVPbkFieldType& fieldType = iContactManager->FieldTypes().FieldTypeAt( i ); |
|
259 const TInt fieldTypeResId = fieldType.FieldTypeResId(); |
|
260 |
|
261 if ( fieldTypeResId == R_VPBK_FIELD_TYPE_MOBILEPHONEGEN |
|
262 || fieldTypeResId == R_VPBK_FIELD_TYPE_MOBILEPHONEWORK |
|
263 || fieldTypeResId == R_VPBK_FIELD_TYPE_MOBILEPHONEHOME |
|
264 || fieldTypeResId == R_VPBK_FIELD_TYPE_LANDPHONEHOME |
|
265 || fieldTypeResId == R_VPBK_FIELD_TYPE_LANDPHONEWORK |
|
266 || fieldTypeResId == R_VPBK_FIELD_TYPE_LANDPHONEGEN |
|
267 || fieldTypeResId == R_VPBK_FIELD_TYPE_CARPHONE |
|
268 || fieldTypeResId == R_VPBK_FIELD_TYPE_ASSTPHONE |
|
269 || fieldTypeResId == R_VPBK_FIELD_TYPE_PAGERNUMBER |
|
270 || fieldTypeResId == R_VPBK_FIELD_TYPE_FAXNUMBERGEN |
|
271 || fieldTypeResId == R_VPBK_FIELD_TYPE_FAXNUMBERHOME |
|
272 || fieldTypeResId == R_VPBK_FIELD_TYPE_FAXNUMBERWORK ) |
|
273 { |
|
274 CVPbkBaseContactFieldTypeIterator* itr = |
|
275 CVPbkBaseContactFieldTypeIterator::NewLC( fieldType, |
|
276 aContact->Fields() ); |
|
277 |
|
278 while ( !found && itr->HasNext() ) |
|
279 { |
|
280 const MVPbkBaseContactField* field = itr->Next(); |
|
281 // Check field type before casting. |
|
282 const MVPbkContactFieldData& contactFieldData = field->FieldData(); |
|
283 if ( EVPbkFieldStorageTypeText == contactFieldData.DataType() ) |
|
284 { |
|
285 // get field data |
|
286 const MVPbkContactFieldTextData& data = |
|
287 MVPbkContactFieldTextData::Cast( contactFieldData ); |
|
288 //Get the rightmost string pointer with the max length of match(iDigitsToMatch) |
|
289 TPtrC clipNumber = iNumber->Right( iDigitsToMatch ); |
|
290 TPtrC fieldNumber = data.Text().Right( iDigitsToMatch ); |
|
291 |
|
292 if ( 0 == fieldNumber.Compare( clipNumber ) ) |
|
293 { |
|
294 found = ETrue; |
|
295 iNumberFieldType = NumberPbkFieldFromVPbk( fieldTypeResId ); |
|
296 } |
|
297 } |
|
298 } |
|
299 CleanupStack::PopAndDestroy( itr ); |
|
300 } |
|
301 } |
|
302 } |
|
303 |
|
304 TInt CLogsEventUpdater::NumberPbkFieldFromVPbk( TInt aNumberFieldType ) const |
|
305 { |
|
306 TInt pbkFieldType = EPbkFieldIdNone; |
|
307 |
|
308 switch ( aNumberFieldType ) |
|
309 { |
|
310 case R_VPBK_FIELD_TYPE_MOBILEPHONEGEN: |
|
311 case R_VPBK_FIELD_TYPE_MOBILEPHONEWORK: |
|
312 case R_VPBK_FIELD_TYPE_MOBILEPHONEHOME: |
|
313 pbkFieldType = EPbkFieldIdPhoneNumberMobile; |
|
314 break; |
|
315 |
|
316 case R_VPBK_FIELD_TYPE_LANDPHONEHOME: |
|
317 case R_VPBK_FIELD_TYPE_LANDPHONEWORK: |
|
318 case R_VPBK_FIELD_TYPE_LANDPHONEGEN: |
|
319 pbkFieldType = EPbkFieldIdPhoneNumberGeneral; |
|
320 break; |
|
321 |
|
322 case R_VPBK_FIELD_TYPE_PAGERNUMBER: |
|
323 pbkFieldType = EPbkFieldIdPagerNumber; |
|
324 break; |
|
325 |
|
326 case R_VPBK_FIELD_TYPE_FAXNUMBERGEN: |
|
327 case R_VPBK_FIELD_TYPE_FAXNUMBERHOME: |
|
328 case R_VPBK_FIELD_TYPE_FAXNUMBERWORK: |
|
329 pbkFieldType = EPbkFieldIdFaxNumber; |
|
330 break; |
|
331 |
|
332 case R_VPBK_FIELD_TYPE_ASSTPHONE: |
|
333 pbkFieldType = EPbkFieldIdAssistantNumber; |
|
334 break; |
|
335 |
|
336 case R_VPBK_FIELD_TYPE_CARPHONE: |
|
337 pbkFieldType = EPbkFieldIdCarNumber; |
|
338 break; |
|
339 |
|
340 default: |
|
341 break; |
|
342 } |
|
343 |
|
344 return pbkFieldType; |
|
345 } |
|
346 |
|
347 // End of File |
|
348 |