|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Handles monitored file creations, modifications and deletions.* |
|
15 */ |
|
16 |
|
17 #include <collate.h> |
|
18 #include <mdeobject.h> |
|
19 |
|
20 #include "fileeventhandlerao.h" |
|
21 #include "harvesterlog.h" |
|
22 #include "fsutil.h" |
|
23 #include "mdeconstants.h" |
|
24 #include "mdeharvestersession.h" |
|
25 #include "processoriginmapper.h" |
|
26 #include "mdenamespacedef.h" |
|
27 #include "mdeobjectdef.h" |
|
28 #include "FolderRenamer.h" |
|
29 #include "mdsutils.h" |
|
30 #include "harvesterpluginfactory.h" |
|
31 #include "mdsfspqueue.h" |
|
32 #include "harvestercommon.h" |
|
33 #include <centralrepository.h> |
|
34 |
|
35 using namespace MdeConstants; |
|
36 |
|
37 const TUid KRepositoryUid = { 0x20007182 }; |
|
38 const TUint32 KCacheSizeKey = 0x00000001; |
|
39 |
|
40 const TInt KMaxEventsAtTime = 20; |
|
41 const TInt KMaxEventsGranularity = 20; |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CFileEventHandlerAO::NewL() |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CFileEventHandlerAO* CFileEventHandlerAO::NewL( MMonitorPluginObserver& aObserver, |
|
48 CMdEHarvesterSession* aMdeSession, CHarvesterPluginFactory* aHarvesterPluginFactory ) |
|
49 { |
|
50 WRITELOG( "CFileEventHandlerAO::NewL" ); |
|
51 |
|
52 CFileEventHandlerAO* self = new (ELeave) CFileEventHandlerAO; |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL( aObserver, aMdeSession, aHarvesterPluginFactory ); |
|
55 CleanupStack::Pop( self ); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CFileEventHandlerAO::ConstructL() |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 void CFileEventHandlerAO::ConstructL( MMonitorPluginObserver& aObserver, |
|
64 CMdEHarvesterSession* aMdeSession, CHarvesterPluginFactory* aHarvesterPluginFactory ) |
|
65 { |
|
66 WRITELOG( "CFileEventHandlerAO::ConstructL" ); |
|
67 iObserver = &aObserver; |
|
68 iHarvesterPluginFactory = aHarvesterPluginFactory; |
|
69 iMdeSession = aMdeSession; |
|
70 iNextRequest = ERequestIdle; |
|
71 iCacheEvents = EFalse; |
|
72 |
|
73 CActiveScheduler::Add( this ); |
|
74 iMapper = CProcessOriginMapper::NewL(); |
|
75 iMoveTimer = CMoveTimer::NewL(this); |
|
76 iFolderRenamer = CFolderRenamer::NewL(*this); |
|
77 TRAPD( error, iMapper->ReadFileL() ); |
|
78 if ( error != KErrNone ) |
|
79 { |
|
80 WRITELOG1( "CFileEventHandlerAO::ConstructL - iMapper->ReadFileL() error %d", error ); |
|
81 } |
|
82 error = iFs.Connect(); |
|
83 User::LeaveIfError( error ); |
|
84 |
|
85 TRAP( error, ReadCacheSizeFromCenrepL() ); |
|
86 if ( error == KErrNone ) |
|
87 { |
|
88 iQueue.Reserve( iCacheSize ); |
|
89 } |
|
90 |
|
91 iEventArray = new (ELeave) CArrayFixSeg< TMdsFSPStatus >( KMaxEventsGranularity ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CFileEventHandlerAO::~CFileEventHandlerAO() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 CFileEventHandlerAO::~CFileEventHandlerAO() |
|
99 { |
|
100 WRITELOG( "CFileEventHandlerAO::~CFileEventHandlerAO" ); |
|
101 |
|
102 Cancel(); |
|
103 |
|
104 iIgnoreList.ResetAndDestroy(); |
|
105 iIgnoreList.Close(); |
|
106 |
|
107 iFs.Close(); |
|
108 |
|
109 delete iMapper; |
|
110 delete iMoveTimer; |
|
111 delete iFolderRenamer; |
|
112 |
|
113 delete iEventArray; |
|
114 iUriArray.Close(); |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // CFileEventHandlerAO::RunL() |
|
121 // From CActive |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CFileEventHandlerAO::RunL() |
|
125 { |
|
126 WRITELOG( "CFileEventHandlerAO::RunL" ); |
|
127 switch( iNextRequest ) |
|
128 { |
|
129 case ( ERequestIdle ): |
|
130 { |
|
131 break; |
|
132 } |
|
133 |
|
134 case ( ERequestProcessing ): |
|
135 { |
|
136 if( iQueue.Count() > 0 && !iCacheEvents ) |
|
137 { |
|
138 CMdsFSPQueueItem* item = iQueue[0]; |
|
139 iQueue.Remove( 0 ); |
|
140 |
|
141 ResetEvent(); |
|
142 item->GetAsFspStatus(iEvent); |
|
143 delete item; |
|
144 |
|
145 if( iEvent.iFileEventType == EMdsFileDeleted ) |
|
146 { |
|
147 iEventArray->AppendL( iEvent ); |
|
148 TInt limit( KMaxEventsAtTime ); |
|
149 const TInt count( iQueue.Count() ); |
|
150 if( count >= KMaxEventsAtTime ) |
|
151 { |
|
152 limit = KMaxEventsAtTime; |
|
153 } |
|
154 else |
|
155 { |
|
156 limit = count; |
|
157 } |
|
158 |
|
159 for( TInt i( 0 ); i < limit; i++ ) |
|
160 { |
|
161 CMdsFSPQueueItem* tempItem = iQueue[0]; |
|
162 TMdsFSPStatus status; |
|
163 tempItem->GetAsFspStatus( status ); |
|
164 if( status.iFileEventType == EMdsFileDeleted ) |
|
165 { |
|
166 iQueue.Remove( 0 ); |
|
167 delete tempItem; |
|
168 iEventArray->AppendL( status ); |
|
169 } |
|
170 else |
|
171 { |
|
172 break; |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 if( iEventArray->Count() > 1 ) |
|
178 { |
|
179 iFolderRenamer->HandleFileEventsL(iEventArray); |
|
180 } |
|
181 else |
|
182 { |
|
183 iFolderRenamer->HandleFileEventL(iEvent); |
|
184 } |
|
185 |
|
186 SetNextRequest( ERequestProcessing ); |
|
187 } |
|
188 else |
|
189 { |
|
190 SetNextRequest( ERequestIdle ); |
|
191 } |
|
192 break; |
|
193 } |
|
194 default: |
|
195 break; |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CFileEventHandlerAO::HandleNotificationL() |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CFileEventHandlerAO::HandleNotificationL(TMdsFSPStatus &aEvent) |
|
204 { |
|
205 WRITELOG( "CFileEventHandlerAO::HandleNotificationL" ); |
|
206 |
|
207 TMdsFSPStatus& status = aEvent; |
|
208 |
|
209 if ( !iObserver ) |
|
210 { |
|
211 WRITELOG( "-- ERROR -- CFileEventHandlerAO::HandleNotificationL - no observer" ); |
|
212 return; |
|
213 } |
|
214 |
|
215 TBool fastHarvest( EFalse ); |
|
216 |
|
217 TOrigin origin = MdeConstants::Object::EOther; |
|
218 if ( iMapper ) |
|
219 { |
|
220 TRAPD( originErr, origin = iMapper->OriginL( status.iProcessId ) ); |
|
221 if( originErr == KErrNone ) |
|
222 { |
|
223 if ( origin == KOriginIgnored ) |
|
224 { |
|
225 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - ignored origin for %S", &status.iFileName ); |
|
226 return; |
|
227 } |
|
228 else if( origin == KOriginFastHarvest ) |
|
229 { |
|
230 WRITELOG( "CFileEventHandlerAO::HandleNotificationL - potential fast harvest file detected" ); |
|
231 fastHarvest = ETrue; |
|
232 } |
|
233 |
|
234 _LIT(KCameraTemp,"camcordertmp"); |
|
235 if ( origin == MdeConstants::Object::ECamera && |
|
236 (aEvent.iFileEventType == EMdsFileCreated || |
|
237 aEvent.iFileName.FindF(KCameraTemp) != KErrNotFound) ) |
|
238 { |
|
239 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - ignored camera origin for %S", &status.iFileName ); |
|
240 return; |
|
241 } |
|
242 } |
|
243 else |
|
244 { |
|
245 origin = MdeConstants::Object::EOther; |
|
246 } |
|
247 } |
|
248 |
|
249 // ignore created file event if extension is not supported by any harverter plugin |
|
250 if( EMdsFileCreated == status.iFileEventType && |
|
251 status.iFileName.Length() > 0 ) |
|
252 { |
|
253 if( !iHarvesterPluginFactory->IsSupportedFileExtension( |
|
254 status.iFileName ) ) |
|
255 { |
|
256 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - file extension not supported: %S", &status.iFileName ); |
|
257 return; |
|
258 } |
|
259 } |
|
260 |
|
261 switch( status.iFileEventType ) |
|
262 { |
|
263 case EMdsFileCreated: |
|
264 { |
|
265 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - EmdsFileCreated: %S", &status.iFileName ); |
|
266 HBufC* fn = status.iFileName.AllocLC(); |
|
267 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
268 CleanupStack::Pop( fn ); |
|
269 hd->SetEventType( EHarvesterAdd ); |
|
270 hd->SetOrigin( origin ); |
|
271 CleanupStack::PushL( hd ); |
|
272 iMoveTimer->AddHarvesterDataL( hd ); |
|
273 CleanupStack::Pop( hd ); |
|
274 } |
|
275 break; |
|
276 |
|
277 case EMdsFileRenamed: |
|
278 { |
|
279 WRITELOG2( "CFileEventHandlerAO::HandleNotificationL - EMdsFileRenamed: %S to %S", &status.iFileName, &status.iNewFileName ); |
|
280 RenameToMDEL( status.iFileName, status.iNewFileName, origin ); |
|
281 } |
|
282 break; |
|
283 |
|
284 case EMdsFileModified: |
|
285 { |
|
286 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - EmdsFileModified: %S", &status.iFileName ); |
|
287 ModifyL( status.iFileName, origin, fastHarvest ); |
|
288 } |
|
289 break; |
|
290 |
|
291 case EMdsFileReplaced: |
|
292 { |
|
293 WRITELOG2( "CFileEventHandlerAO::HandleNotificationL - EMdsFileReplaced: %S to %S", &status.iFileName, &status.iNewFileName ); |
|
294 ReplaceL( status.iFileName, status.iNewFileName, origin, fastHarvest ); |
|
295 } |
|
296 break; |
|
297 |
|
298 case EMdsFileDeleted: |
|
299 { |
|
300 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - EmdsFileDeleted: %S", &status.iFileName ); |
|
301 CHarvesterData* hd = iMoveTimer->CheckUriL( status.iFileName ); |
|
302 if ( hd ) |
|
303 { |
|
304 // move event |
|
305 CleanupStack::PushL( hd ); |
|
306 RenameToMDEL( status.iFileName, hd->Uri(), hd->Origin() ); |
|
307 CleanupStack::PopAndDestroy( hd ); |
|
308 } |
|
309 |
|
310 DeleteFromMDEL( status.iFileName ); |
|
311 } |
|
312 break; |
|
313 |
|
314 case EMdsDriveFormatted: |
|
315 { |
|
316 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - EMdsDriveFormatted: %d", status.iDriveNumber ); |
|
317 // format drive |
|
318 FormatL( status.iDriveMediaId, status.iProcessId.iUid != 0 ); |
|
319 } |
|
320 break; |
|
321 |
|
322 default: |
|
323 WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - KErrNotSupported %d", status.iFileEventType ); |
|
324 User::Leave( KErrNotSupported ); |
|
325 break; |
|
326 } |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // CFileEventHandlerAO::HandleMultideletionL() |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CFileEventHandlerAO::HandleMultideletionL( CArrayFixSeg< TMdsFSPStatus >* aEvents ) |
|
334 { |
|
335 WRITELOG( "CFileEventHandlerAO::HandleMultideletionL" ); |
|
336 |
|
337 if ( !iObserver ) |
|
338 { |
|
339 WRITELOG( "-- ERROR -- CFileEventHandlerAO::HandleMultideletionL - no observer" ); |
|
340 return; |
|
341 } |
|
342 |
|
343 const TInt count( aEvents->Count() ); |
|
344 for( TInt i( 0 ); i < count; i++ ) |
|
345 { |
|
346 TMdsFSPStatus& status = (*aEvents)[i]; |
|
347 |
|
348 TOrigin origin = MdeConstants::Object::EOther; |
|
349 if ( iMapper ) |
|
350 { |
|
351 TRAPD( originErr, origin = iMapper->OriginL( status.iProcessId ) ); |
|
352 if( originErr == KErrNone ) |
|
353 { |
|
354 if ( origin == KOriginIgnored ) |
|
355 { |
|
356 WRITELOG1( "CFileEventHandlerAO::HandleMultideletionL - ignored origin for %S", &status.iFileName ); |
|
357 continue; |
|
358 } |
|
359 } |
|
360 } |
|
361 |
|
362 WRITELOG1( "CFileEventHandlerAO::HandleMultideletionL - EmdsFileDeleted: %S", &status.iFileName ); |
|
363 CHarvesterData* hd = iMoveTimer->CheckUriL( status.iFileName ); |
|
364 if ( hd ) |
|
365 { |
|
366 // move event |
|
367 CleanupStack::PushL( hd ); |
|
368 RenameToMDEL( status.iFileName, hd->Uri(), hd->Origin() ); |
|
369 CleanupStack::PopAndDestroy( hd ); |
|
370 } |
|
371 iUriArray.Append( &(status.iFileName) ); |
|
372 } |
|
373 MultiDeleteFromMDEL( iUriArray ); |
|
374 } |
|
375 |
|
376 // --------------------------------------------------------------------------- |
|
377 // CFileEventHandlerAO::ResetMdsFSPStatus() |
|
378 // --------------------------------------------------------------------------- |
|
379 // |
|
380 void CFileEventHandlerAO::ResetEvent() |
|
381 { |
|
382 WRITELOG( "CFileEventHandlerAO::ResetEvent" ); |
|
383 |
|
384 iEvent.iDriveNumber = 0; |
|
385 iEvent.iFileEventType = EMdsFileUnknown; |
|
386 iEvent.iFileName.Zero(); |
|
387 iEvent.iNewFileName.Zero(); |
|
388 iEvent.iProcessId = TUid::Null(); |
|
389 |
|
390 iEventArray->Reset(); |
|
391 iUriArray.Reset(); |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------------------------- |
|
395 // CFileEventHandlerAO::RenameToMDEL() |
|
396 // --------------------------------------------------------------------------- |
|
397 // |
|
398 void CFileEventHandlerAO::RenameToMDEL( const TDesC& aOldUrl, |
|
399 const TDesC& aNewUrl, TOrigin aOrigin ) |
|
400 { |
|
401 WRITELOG( "CFileEventHandlerAO::RenameToMDEL" ); |
|
402 |
|
403 CMdEObject* oldObject = iMdeSession->Session()->OpenObjectL( aOldUrl ); |
|
404 if ( oldObject ) |
|
405 { |
|
406 CleanupStack::PushL( oldObject ); |
|
407 } |
|
408 |
|
409 CMdEObject* newObject = iMdeSession->Session()->GetObjectL( aNewUrl ); |
|
410 if ( newObject ) |
|
411 { |
|
412 CleanupStack::PushL( newObject ); |
|
413 } |
|
414 |
|
415 // check if not in mde, harvest |
|
416 if ( !oldObject && !newObject && iObserver ) |
|
417 { |
|
418 HBufC* fn = aNewUrl.AllocLC(); |
|
419 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
420 CleanupStack::Pop( fn ); |
|
421 hd->SetEventType( EHarvesterAdd ); |
|
422 hd->SetOrigin( aOrigin ); |
|
423 iObserver->MonitorEvent( hd ); |
|
424 } |
|
425 |
|
426 // set old url to new url |
|
427 if ( oldObject && !newObject ) |
|
428 { |
|
429 SetTitleL( oldObject , aNewUrl ); |
|
430 oldObject->SetUriL( aNewUrl ); |
|
431 TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl ); |
|
432 oldObject->SetMediaId( mediaId ); |
|
433 } |
|
434 |
|
435 // if old and new then destroy new and change old |
|
436 if ( oldObject && newObject && ( oldObject->Id() != newObject->Id()) ) |
|
437 { |
|
438 const TItemId removedId = iMdeSession->Session()->RemoveObjectL( |
|
439 newObject->Id() ); |
|
440 if ( removedId != KNoId ) |
|
441 { |
|
442 oldObject->SetUriL( aNewUrl ); |
|
443 TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl ); |
|
444 oldObject->SetMediaId( mediaId ); |
|
445 } |
|
446 } |
|
447 |
|
448 if ( newObject ) |
|
449 { |
|
450 CleanupStack::PopAndDestroy( newObject ); |
|
451 } |
|
452 |
|
453 if ( oldObject ) |
|
454 { |
|
455 SetModifiedTimeL( oldObject, aNewUrl ); |
|
456 TOrigin origin = OriginFromMdEObjectL( *oldObject ); |
|
457 if( origin == MdeConstants::Object::EOther) |
|
458 { |
|
459 OriginToMdEObjectL( *oldObject, aOrigin ); |
|
460 } |
|
461 iMdeSession->Session()->CommitObjectL( *oldObject ); |
|
462 CleanupStack::PopAndDestroy( oldObject ); |
|
463 } |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // CFileEventHandlerAO::OriginFromMdEObject() |
|
468 // --------------------------------------------------------------------------- |
|
469 // |
|
470 TOrigin CFileEventHandlerAO::OriginFromMdEObjectL( CMdEObject& aObject ) |
|
471 { |
|
472 TOrigin retVal = MdeConstants::Object::EOther; |
|
473 |
|
474 if( !iOriginPropertyDef ) |
|
475 { |
|
476 CMdEObjectDef& objDef = aObject.Def(); |
|
477 iOriginPropertyDef = &objDef.GetPropertyDefL( Object::KOriginProperty ); |
|
478 } |
|
479 |
|
480 CMdEProperty* property = NULL; |
|
481 TInt err = aObject.Property( *iOriginPropertyDef, property ); |
|
482 if( err >= KErrNone && property ) |
|
483 { |
|
484 CMdEUint8Property* uint8Property = (CMdEUint8Property*)property; |
|
485 retVal = (TOrigin) uint8Property->Value(); |
|
486 } |
|
487 |
|
488 return retVal; |
|
489 } |
|
490 |
|
491 // --------------------------------------------------------------------------- |
|
492 // CFileEventHandlerAO::OriginFromMdEObject() |
|
493 // --------------------------------------------------------------------------- |
|
494 // |
|
495 void CFileEventHandlerAO::OriginToMdEObjectL( CMdEObject& aObject, |
|
496 TOrigin aOrigin ) |
|
497 { |
|
498 if( !iOriginPropertyDef ) |
|
499 { |
|
500 CMdEObjectDef& objDef = aObject.Def(); |
|
501 iOriginPropertyDef = &objDef.GetPropertyDefL( |
|
502 Object::KOriginProperty ); |
|
503 } |
|
504 |
|
505 CMdEProperty* property = NULL; |
|
506 TInt err = aObject.Property( *iOriginPropertyDef, property ); |
|
507 if(err < KErrNone) |
|
508 { |
|
509 return; |
|
510 } |
|
511 |
|
512 if( property ) |
|
513 { |
|
514 CMdEUint8Property* uint8Property = (CMdEUint8Property*)property; |
|
515 TRAP_IGNORE( uint8Property->SetValueL( aOrigin ) ); |
|
516 } |
|
517 else |
|
518 { |
|
519 TRAP_IGNORE( aObject.AddUint8PropertyL( *iOriginPropertyDef, |
|
520 (TUint8) aOrigin ) ); |
|
521 } |
|
522 } |
|
523 |
|
524 // --------------------------------------------------------------------------- |
|
525 // CFileEventHandlerAO::ReplaceL() |
|
526 // --------------------------------------------------------------------------- |
|
527 // |
|
528 void CFileEventHandlerAO::ReplaceL( const TDesC& aOldUrl, const TDesC& aNewUrl, |
|
529 TOrigin aOrigin, TBool aFastHarvest ) |
|
530 { |
|
531 WRITELOG( "CFileEventHandlerAO::ReplaceL" ); |
|
532 |
|
533 if ( !iObserver ) |
|
534 { |
|
535 User::Leave( KErrGeneral ); |
|
536 } |
|
537 |
|
538 CMdEObject* newObject = NULL; |
|
539 CMdEObject* oldObject = NULL; |
|
540 |
|
541 if ( aNewUrl.Length() > 0 ) |
|
542 { |
|
543 newObject = iMdeSession->Session()->GetObjectL( aNewUrl ); |
|
544 if ( newObject ) |
|
545 { |
|
546 CleanupStack::PushL( newObject ); |
|
547 } |
|
548 } |
|
549 |
|
550 if ( aOldUrl.Length() > 0 ) |
|
551 { |
|
552 oldObject = iMdeSession->Session()->GetObjectL( aOldUrl ); |
|
553 if ( oldObject ) |
|
554 { |
|
555 CleanupStack::PushL( oldObject ); |
|
556 } |
|
557 } |
|
558 |
|
559 // check if not in mde, harvest |
|
560 if ( !oldObject && !newObject ) |
|
561 { |
|
562 HBufC* fn = NULL; |
|
563 |
|
564 if (aNewUrl.Length() > 0) |
|
565 { |
|
566 fn = aNewUrl.AllocLC(); |
|
567 } |
|
568 else |
|
569 { |
|
570 fn = aOldUrl.AllocLC(); |
|
571 } |
|
572 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
573 CleanupStack::Pop( fn ); |
|
574 hd->SetEventType( EHarvesterAdd ); |
|
575 hd->SetOrigin( aOrigin ); |
|
576 if( aFastHarvest ) |
|
577 { |
|
578 hd->SetObjectType( EFastHarvest ); |
|
579 } |
|
580 iObserver->MonitorEvent( hd ); |
|
581 } |
|
582 |
|
583 if ( oldObject ) |
|
584 { |
|
585 // check if same then harvest modify |
|
586 if ( aNewUrl.Length() == 0 || MdsUtils::Compare( aNewUrl, aOldUrl ) == 0 ) |
|
587 { |
|
588 HBufC* fn = aOldUrl.AllocLC(); |
|
589 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
590 CleanupStack::Pop( fn ); |
|
591 hd->SetEventType(EHarvesterEdit); |
|
592 hd->SetOrigin( aOrigin ); |
|
593 if( aFastHarvest ) |
|
594 { |
|
595 hd->SetObjectType( EFastHarvest ); |
|
596 } |
|
597 iObserver->MonitorEvent( hd ); |
|
598 } |
|
599 else if ( newObject ) |
|
600 { |
|
601 // both are existing so delete new and change uri of old one |
|
602 const TItemId removedId = iMdeSession->Session()->RemoveObjectL( |
|
603 newObject->Id() ); |
|
604 if ( removedId != KNoId ) |
|
605 { |
|
606 const TItemId oldObjectId = oldObject->Id(); |
|
607 CleanupStack::PopAndDestroy( oldObject ); |
|
608 oldObject = iMdeSession->Session()->OpenObjectL( oldObjectId ); |
|
609 if ( oldObject ) |
|
610 { |
|
611 CleanupStack::PushL( oldObject ); |
|
612 SetTitleL( oldObject , aNewUrl ); |
|
613 oldObject->SetUriL( aNewUrl ); |
|
614 TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl ); |
|
615 oldObject->SetMediaId( mediaId ); |
|
616 TOrigin origin = OriginFromMdEObjectL( *oldObject ); |
|
617 if( origin == MdeConstants::Object::EOther) |
|
618 { |
|
619 OriginToMdEObjectL( *oldObject, aOrigin ); |
|
620 } |
|
621 iMdeSession->Session()->CommitObjectL( *oldObject ); |
|
622 } |
|
623 } |
|
624 } |
|
625 else |
|
626 { |
|
627 // case is actually rename |
|
628 const TItemId oldObjectId = oldObject->Id(); |
|
629 CleanupStack::PopAndDestroy( oldObject ); |
|
630 oldObject = iMdeSession->Session()->OpenObjectL( oldObjectId ); |
|
631 if ( oldObject ) |
|
632 { |
|
633 CleanupStack::PushL( oldObject ); |
|
634 SetTitleL( oldObject , aNewUrl ); |
|
635 oldObject->SetUriL( aNewUrl ); |
|
636 TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl ); |
|
637 oldObject->SetMediaId( mediaId ); |
|
638 SetModifiedTimeL( oldObject, aNewUrl ); |
|
639 TOrigin origin = OriginFromMdEObjectL( *oldObject ); |
|
640 if( origin == MdeConstants::Object::EOther) |
|
641 { |
|
642 OriginToMdEObjectL( *oldObject, aOrigin ); |
|
643 } |
|
644 iMdeSession->Session()->CommitObjectL( *oldObject ); |
|
645 } |
|
646 } |
|
647 } |
|
648 else if ( newObject ) |
|
649 { |
|
650 // if we replace file from not phone location (e.g. from PC) |
|
651 // where it create some temporary file and replace aNewUrl file |
|
652 WRITELOG( "CFileEventHandlerAO::ReplaceL - Different filenames... still try to harvest new one as modify" ); |
|
653 HBufC* fn = aNewUrl.AllocLC(); |
|
654 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
655 CleanupStack::Pop( fn ); |
|
656 hd->SetEventType( EHarvesterEdit ); |
|
657 hd->SetOrigin( aOrigin ); |
|
658 if( aFastHarvest ) |
|
659 { |
|
660 hd->SetObjectType( EFastHarvest ); |
|
661 } |
|
662 iObserver->MonitorEvent( hd ); |
|
663 } |
|
664 |
|
665 if ( oldObject ) |
|
666 { |
|
667 CleanupStack::PopAndDestroy( oldObject ); |
|
668 } |
|
669 |
|
670 if ( newObject ) |
|
671 { |
|
672 CleanupStack::PopAndDestroy( newObject ); |
|
673 } |
|
674 } |
|
675 |
|
676 // --------------------------------------------------------------------------- |
|
677 // CFileEventHandlerAO::ModifyL() |
|
678 // --------------------------------------------------------------------------- |
|
679 // |
|
680 void CFileEventHandlerAO::ModifyL( const TDesC& aUrl, TOrigin aOrigin, TBool aFastHarvest ) |
|
681 { |
|
682 WRITELOG( "CFileEventHandlerAO::ModifyL" ); |
|
683 |
|
684 CMdEObject* oldObject = iMdeSession->Session()->GetObjectL( aUrl ); |
|
685 |
|
686 // check if not in mde, harvest |
|
687 if ( !oldObject && iObserver ) |
|
688 { |
|
689 HBufC* fn = aUrl.AllocLC(); |
|
690 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
691 CleanupStack::Pop( fn ); |
|
692 hd->SetEventType( EHarvesterAdd ); |
|
693 hd->SetOrigin( aOrigin ); |
|
694 if( aFastHarvest ) |
|
695 { |
|
696 hd->SetObjectType( EFastHarvest ); |
|
697 } |
|
698 iObserver->MonitorEvent( hd ); |
|
699 } |
|
700 else if ( iObserver ) |
|
701 { |
|
702 HBufC* fn = aUrl.AllocLC(); |
|
703 CHarvesterData* hd = CHarvesterData::NewL( fn ); |
|
704 CleanupStack::Pop( fn ); |
|
705 hd->SetEventType( EHarvesterEdit ); |
|
706 hd->SetOrigin( aOrigin ); |
|
707 if( aFastHarvest ) |
|
708 { |
|
709 hd->SetObjectType( EFastHarvest ); |
|
710 } |
|
711 iObserver->MonitorEvent( hd ); |
|
712 } |
|
713 |
|
714 if ( oldObject ) |
|
715 { |
|
716 delete oldObject; |
|
717 oldObject = NULL; |
|
718 } |
|
719 } |
|
720 |
|
721 // --------------------------------------------------------------------------- |
|
722 // CFileEventHandlerAO::DeleteFromMDEL() |
|
723 // --------------------------------------------------------------------------- |
|
724 // |
|
725 void CFileEventHandlerAO::DeleteFromMDEL( const TDesC& aUrl ) |
|
726 { |
|
727 WRITELOG( "CFileEventHandlerAO::DeleteFromMDEL" ); |
|
728 |
|
729 iMdeSession->Session()->RemoveObjectL( aUrl ); |
|
730 } |
|
731 |
|
732 // --------------------------------------------------------------------------- |
|
733 // CFileEventHandlerAO::MultiDeleteFromMDEL() |
|
734 // --------------------------------------------------------------------------- |
|
735 // |
|
736 void CFileEventHandlerAO::MultiDeleteFromMDEL( const RPointerArray<TDesC>& aUrls ) |
|
737 { |
|
738 WRITELOG( "CFileEventHandlerAO::MultiDeleteFromMDEL" ); |
|
739 |
|
740 RArray<TItemId> results; |
|
741 CleanupClosePushL( results ); |
|
742 iMdeSession->Session()->RemoveObjectsL( aUrls, results ); |
|
743 CleanupStack::PopAndDestroy( &results ); |
|
744 } |
|
745 |
|
746 // --------------------------------------------------------------------------- |
|
747 // CFileEventHandlerAO::FormatL() |
|
748 // --------------------------------------------------------------------------- |
|
749 // |
|
750 void CFileEventHandlerAO::FormatL( TUint32 aOldMediaId, TBool aSubClose ) |
|
751 { |
|
752 WRITELOG2( "CFileEventHandlerAO::FormatL - old media ID %d subclose %d", |
|
753 aOldMediaId, aSubClose ); |
|
754 |
|
755 if ( aOldMediaId ) |
|
756 { |
|
757 iMdeSession->SetFilesToNotPresent( aOldMediaId ); |
|
758 if ( aSubClose ) |
|
759 { |
|
760 iMdeSession->RemoveFilesNotPresent( aOldMediaId ); |
|
761 } |
|
762 } |
|
763 } |
|
764 |
|
765 // --------------------------------------------------------------------------- |
|
766 // CFileEventHandlerAO::RunError() |
|
767 // From CActive |
|
768 // --------------------------------------------------------------------------- |
|
769 // |
|
770 #ifdef _DEBUG |
|
771 TInt CFileEventHandlerAO::RunError( TInt aError ) |
|
772 #else |
|
773 TInt CFileEventHandlerAO::RunError( TInt /*aError*/ ) |
|
774 #endif |
|
775 { |
|
776 WRITELOG1( "CFileEventHandlerAO::RunError %d", aError ); |
|
777 |
|
778 SetNextRequest( ERequestProcessing ); |
|
779 |
|
780 return KErrNone; |
|
781 } |
|
782 |
|
783 // --------------------------------------------------------------------------- |
|
784 // CFileEventHandlerAO::DoCancel() |
|
785 // From CActive |
|
786 // --------------------------------------------------------------------------- |
|
787 // |
|
788 void CFileEventHandlerAO::DoCancel() |
|
789 { |
|
790 WRITELOG( "CFileEventHandlerAO::DoCancel" ); |
|
791 |
|
792 } |
|
793 |
|
794 // --------------------------------------------------------------------------- |
|
795 // CFileEventHandlerAO::CFileEventHandlerAO() |
|
796 // Constructor |
|
797 // --------------------------------------------------------------------------- |
|
798 // |
|
799 CFileEventHandlerAO::CFileEventHandlerAO() : |
|
800 CActive( KHarvesterPriorityMonitorPlugin ) |
|
801 { |
|
802 } |
|
803 |
|
804 // --------------------------------------------------------------------------- |
|
805 // CFileEventHandlerAO::SetIgnoreListL() |
|
806 // --------------------------------------------------------------------------- |
|
807 // |
|
808 void CFileEventHandlerAO::SetIgnoreListL( RPointerArray<TDesC>& aList ) |
|
809 { |
|
810 WRITELOG( "CFileEventHandlerAO::SetIgnoreListL" ); |
|
811 |
|
812 iIgnoreList.ResetAndDestroy(); |
|
813 |
|
814 for ( TInt i = aList.Count(); --i >= 0; ) |
|
815 { |
|
816 TDesC* listPath = aList[i]; |
|
817 |
|
818 HBufC* name = listPath->AllocLC(); |
|
819 |
|
820 iIgnoreList.AppendL( name ); |
|
821 |
|
822 CleanupStack::Pop( name ); |
|
823 } |
|
824 } |
|
825 |
|
826 // --------------------------------------------------------------------------- |
|
827 // CFileEventHandlerAO::Mapper() |
|
828 // Returns a handle to CProcessOriginMapper. |
|
829 // --------------------------------------------------------------------------- |
|
830 // |
|
831 CProcessOriginMapper& CFileEventHandlerAO::Mapper() |
|
832 { |
|
833 return *iMapper; |
|
834 } |
|
835 |
|
836 |
|
837 // --------------------------------------------------------------------------- |
|
838 // CFileEventHandlerAO::NotMoveEvent() |
|
839 // Handles other than move events in move case (rename). If the case is not |
|
840 // move, then new file must be created. |
|
841 // --------------------------------------------------------------------------- |
|
842 // |
|
843 void CFileEventHandlerAO::NotMoveEvent(RPointerArray<CHarvesterData>& aHDArray) |
|
844 { |
|
845 TInt count = aHDArray.Count(); |
|
846 for (int i = 0; i < count; ++i) |
|
847 { |
|
848 CHarvesterData* hd = aHDArray[i]; |
|
849 iObserver->MonitorEvent( hd ); |
|
850 } |
|
851 } |
|
852 |
|
853 |
|
854 CMdEHarvesterSession * CFileEventHandlerAO::MdeHarvesterSession() |
|
855 { |
|
856 return iMdeSession; |
|
857 } |
|
858 |
|
859 |
|
860 void CFileEventHandlerAO::AddToQueueL( TMdsFSPStatus& aEvent ) |
|
861 { |
|
862 CMdsFSPQueueItem* item = CMdsFSPQueueItem::NewL(aEvent); |
|
863 iQueue.Append(item); |
|
864 if( iNextRequest == ERequestIdle && !iCacheEvents ) |
|
865 { |
|
866 SetNextRequest( ERequestProcessing ); |
|
867 } |
|
868 } |
|
869 |
|
870 void CFileEventHandlerAO::SetNextRequest( TRequest aRequest ) |
|
871 { |
|
872 WRITELOG( "CFileEventHandlerAO::SetNextRequest" ); |
|
873 iNextRequest = aRequest; |
|
874 |
|
875 if ( !IsActive() ) |
|
876 { |
|
877 iStatus = KRequestPending; |
|
878 SetActive(); |
|
879 TRequestStatus* ptrStatus = &iStatus; |
|
880 User::RequestComplete( ptrStatus, KErrNone ); |
|
881 } |
|
882 } |
|
883 |
|
884 |
|
885 void CFileEventHandlerAO::SetCachingStatus( TBool aCachingStatus ) |
|
886 { |
|
887 iCacheEvents = aCachingStatus; |
|
888 if ( iCacheEvents ) |
|
889 { |
|
890 SetNextRequest( ERequestIdle ); |
|
891 } |
|
892 else if ( iQueue.Count() > 0 ) |
|
893 { |
|
894 SetNextRequest( ERequestProcessing ); |
|
895 } |
|
896 } |
|
897 |
|
898 void CFileEventHandlerAO::ReadCacheSizeFromCenrepL() |
|
899 { |
|
900 CRepository* repo = CRepository::NewLC( KRepositoryUid ); |
|
901 User::LeaveIfError( repo->Get( KCacheSizeKey, iCacheSize ) ); |
|
902 CleanupStack::PopAndDestroy( repo ); |
|
903 } |
|
904 |
|
905 //--------------------------------------------------------------------------- |
|
906 // CFileEventHandlerAO::SetTitle() |
|
907 // Set MdE object's title with aNewUrl |
|
908 // --------------------------------------------------------------------------- |
|
909 // |
|
910 void CFileEventHandlerAO::SetTitleL( CMdEObject* aOldObject, const TDesC& aNewUrl ) |
|
911 { |
|
912 TPtrC newName; |
|
913 if( MdsUtils::GetName( aNewUrl, newName ) ) |
|
914 { |
|
915 if( !iTitlePropertyDef ) |
|
916 { |
|
917 iTitlePropertyDef = &aOldObject->Def().GetPropertyDefL( |
|
918 MdeConstants::Object::KTitleProperty ); |
|
919 } |
|
920 |
|
921 CMdEProperty* titleProp = NULL; |
|
922 aOldObject->Property( *iTitlePropertyDef, titleProp ); |
|
923 if ( titleProp ) |
|
924 { |
|
925 TPtrC oldName; |
|
926 if( MdsUtils::GetName( aOldObject->Uri(), oldName ) ) |
|
927 { |
|
928 // update title property only, |
|
929 // if title property is same as the old name and |
|
930 // the new name is not same as the old name |
|
931 if( MdsUtils::Compare( oldName, titleProp->TextValueL() ) == 0 && |
|
932 MdsUtils::Compare( newName, oldName ) != 0 ) |
|
933 { |
|
934 titleProp->SetTextValueL( newName ); |
|
935 } |
|
936 } |
|
937 } |
|
938 else |
|
939 { |
|
940 // add title property, if it doesn't exist |
|
941 aOldObject->AddTextPropertyL( *iTitlePropertyDef , newName ); |
|
942 } |
|
943 } |
|
944 } |
|
945 |
|
946 //--------------------------------------------------------------------------- |
|
947 // CFileEventHandlerAO::SetModifiedTimeL() |
|
948 // --------------------------------------------------------------------------- |
|
949 // |
|
950 void CFileEventHandlerAO::SetModifiedTimeL( CMdEObject* aOldObject, const TDesC& aNewUrl ) |
|
951 { |
|
952 TTime time; |
|
953 |
|
954 const TInt errorcode = iFs.Modified( aNewUrl, time ); |
|
955 if ( errorcode != KErrNone ) |
|
956 { |
|
957 return; |
|
958 } |
|
959 |
|
960 if( !iTimePropertyDef ) |
|
961 { |
|
962 iTimePropertyDef = &aOldObject->Def().GetPropertyDefL( |
|
963 MdeConstants::Object::KLastModifiedDateProperty ); |
|
964 } |
|
965 |
|
966 CMdEProperty* timeProp = NULL; |
|
967 aOldObject->Property( *iTimePropertyDef, timeProp ); |
|
968 if( timeProp ) |
|
969 { |
|
970 timeProp->SetTimeValueL( time ); |
|
971 } |
|
972 else |
|
973 { |
|
974 aOldObject->AddTimePropertyL( *iTimePropertyDef , time ); |
|
975 } |
|
976 } |
|
977 |