photosgallery/collectionframework/datasource/plugins/glxdatasourcemde2.5/src/glxdatasourcetaskmdscommand.cpp
branchRCL_3
changeset 9 6b87b143d312
parent 0 4e91876724a2
child 13 71da52165949
--- a/photosgallery/collectionframework/datasource/plugins/glxdatasourcemde2.5/src/glxdatasourcetaskmdscommand.cpp	Tue Feb 02 10:12:14 2010 +0200
+++ b/photosgallery/collectionframework/datasource/plugins/glxdatasourcemde2.5/src/glxdatasourcetaskmdscommand.cpp	Fri Feb 19 22:51:01 2010 +0200
@@ -91,6 +91,10 @@
 _LIT(KColonBackslash, ":\\");
 _LIT(KFileNameFormatString, "(%+02u)");
 
+// Items to be deleted from File server at a time before calling scheduler wait
+const TInt KDeletedItemCount = 50;
+const TInt KDeleteOperationInterval = 200000;
+
 // ----------------------------------------------------------------------------
 // Destructor
 // ----------------------------------------------------------------------------
@@ -103,6 +107,12 @@
     delete iTitle;
     delete iObjectToRename;
     delete iStringCache;
+    if(iTimer && iTimer->IsActive())
+		{
+		iTimer->Cancel();
+		}
+	delete iTimer;
+    delete iSchedulerWait;    
     }
 
 
@@ -131,7 +141,10 @@
     DataSource()->CancelFetchThumbnail();
 #else    
     DataSource()->ThumbnailCreator().CancelRequest( TGlxMediaId(0) );
-#endif
+#endif    
+    
+    iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
+    iSchedulerWait = new (ELeave) CActiveSchedulerWait();
 	}
 
 /// @todo minor: Rowland Cook 12/06/2007 Add method decription.
@@ -992,6 +1005,7 @@
 															(CMdEQuery& aQuery)
 	{
     TRACER("CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL()");
+    TInt deleteItemCounter = 0;
     ContentAccess::CManager *manager = ContentAccess::CManager::NewL();
     CleanupStack::PushL(manager);
     TInt queryCount = aQuery.Count();
@@ -1010,7 +1024,10 @@
     User::LeaveIfError( fs.Connect() );
     
     TInt lastErr = KErrNone;
-    for(TInt queryPos = queryCount - 1; queryPos >= 0; queryPos--)
+    
+    // If Delete operation is cancelled before completion, 
+    // iCancelled because ETrue, break out of for loop.
+    for(TInt queryPos = queryCount - 1; (queryPos >= 0 && !iCancelled); queryPos--)
         {
         CMdEObject& object = static_cast<CMdEObject&>(aQuery.ResultItem(queryPos));
         //Removes the Read Only attributes of the file 
@@ -1020,7 +1037,22 @@
         	{
         	lastErr = err;
         	}    
-        objectsForRemoval.AppendL(object.Id());
+        else
+            {    
+            // On successful deletion, delete the same from database
+            objectsForRemoval.AppendL(object.Id());
+            }
+			 
+        // After every 50 items are deleted, break from the for loop 
+        // and process other pending requests if any
+        if(deleteItemCounter == KDeletedItemCount)
+			{	
+			iTimer->Start( KDeleteOperationInterval, KDeleteOperationInterval,
+							TCallBack( &SchedulerStopCallback, (TAny *)this ) );	
+			iSchedulerWait->Start();  
+			deleteItemCounter = 0;
+			}     
+        deleteItemCounter++;     
         }
     // Calling Close() on file server session 
     CleanupStack::PopAndDestroy( &fs );
@@ -1212,3 +1244,39 @@
     return result;    
         	
 	}
+
+// ----------------------------------------------------------------------------
+//  CGlxDataSourceTaskMdeCommand::SchedulerStopCallback
+// ----------------------------------------------------------------------------
+//
+TInt CGlxDataSourceTaskMdeCommand::SchedulerStopCallback(TAny* aPtr)
+    {
+    TRACER("CGlxDataSourceTaskMdeCommand::SchedulerStopCallback");
+    
+    CGlxDataSourceTaskMdeCommand* self = (CGlxDataSourceTaskMdeCommand*) aPtr;
+    if ( self )
+        {
+        self->SchedulerStopComplete();
+        }
+
+    return KErrNone;
+    }
+
+// -----------------------------------------------------------------------------
+// SchedulerStopComplete
+// -----------------------------------------------------------------------------
+//
+void CGlxDataSourceTaskMdeCommand::SchedulerStopComplete()
+    {
+    TRACER("CGlxDataSourceTaskMdeCommand::SchedulerStopComplete");  
+    
+    if(iTimer && iTimer->IsActive())
+    	{
+    	iTimer->Cancel();
+    	}
+    
+    if(iSchedulerWait)
+		{		
+		iSchedulerWait->AsyncStop();    
+		}  
+    }