89 |
89 |
90 const TInt KDriveLetterLength = 1; |
90 const TInt KDriveLetterLength = 1; |
91 _LIT(KColonBackslash, ":\\"); |
91 _LIT(KColonBackslash, ":\\"); |
92 _LIT(KFileNameFormatString, "(%+02u)"); |
92 _LIT(KFileNameFormatString, "(%+02u)"); |
93 |
93 |
|
94 // Items to be deleted from File server at a time before calling scheduler wait |
|
95 const TInt KDeletedItemCount = 50; |
|
96 const TInt KDeleteOperationInterval = 200000; |
|
97 |
94 // ---------------------------------------------------------------------------- |
98 // ---------------------------------------------------------------------------- |
95 // Destructor |
99 // Destructor |
96 // ---------------------------------------------------------------------------- |
100 // ---------------------------------------------------------------------------- |
97 // |
101 // |
98 CGlxDataSourceTaskMdeCommand::~CGlxDataSourceTaskMdeCommand() |
102 CGlxDataSourceTaskMdeCommand::~CGlxDataSourceTaskMdeCommand() |
129 iResponse = CMPXCommand::NewL(static_cast<CGlxCommandRequest*>(iRequest)->Command()); |
139 iResponse = CMPXCommand::NewL(static_cast<CGlxCommandRequest*>(iRequest)->Command()); |
130 #ifdef USE_S60_TNM |
140 #ifdef USE_S60_TNM |
131 DataSource()->CancelFetchThumbnail(); |
141 DataSource()->CancelFetchThumbnail(); |
132 #else |
142 #else |
133 DataSource()->ThumbnailCreator().CancelRequest( TGlxMediaId(0) ); |
143 DataSource()->ThumbnailCreator().CancelRequest( TGlxMediaId(0) ); |
134 #endif |
144 #endif |
|
145 |
|
146 iTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
147 iSchedulerWait = new (ELeave) CActiveSchedulerWait(); |
135 } |
148 } |
136 |
149 |
137 /// @todo minor: Rowland Cook 12/06/2007 Add method decription. |
150 /// @todo minor: Rowland Cook 12/06/2007 Add method decription. |
138 // ---------------------------------------------------------------------------- |
151 // ---------------------------------------------------------------------------- |
139 // CGlxDataSourceTaskMdeCommand::ExecuteRequestL |
152 // CGlxDataSourceTaskMdeCommand::ExecuteRequestL |
990 // |
1003 // |
991 void CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL |
1004 void CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL |
992 (CMdEQuery& aQuery) |
1005 (CMdEQuery& aQuery) |
993 { |
1006 { |
994 TRACER("CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL()"); |
1007 TRACER("CGlxDataSourceTaskMdeCommand::DoHandleDeleteItemsQueryCompletedL()"); |
|
1008 TInt deleteItemCounter = 0; |
995 ContentAccess::CManager *manager = ContentAccess::CManager::NewL(); |
1009 ContentAccess::CManager *manager = ContentAccess::CManager::NewL(); |
996 CleanupStack::PushL(manager); |
1010 CleanupStack::PushL(manager); |
997 TInt queryCount = aQuery.Count(); |
1011 TInt queryCount = aQuery.Count(); |
998 RArray<TItemId> objectsForRemoval; |
1012 RArray<TItemId> objectsForRemoval; |
999 CleanupClosePushL(objectsForRemoval); |
1013 CleanupClosePushL(objectsForRemoval); |
1008 CleanupClosePushL( fs ); |
1022 CleanupClosePushL( fs ); |
1009 //Connects a client to the file server |
1023 //Connects a client to the file server |
1010 User::LeaveIfError( fs.Connect() ); |
1024 User::LeaveIfError( fs.Connect() ); |
1011 |
1025 |
1012 TInt lastErr = KErrNone; |
1026 TInt lastErr = KErrNone; |
1013 for(TInt queryPos = queryCount - 1; queryPos >= 0; queryPos--) |
1027 |
|
1028 // If Delete operation is cancelled before completion, |
|
1029 // iCancelled because ETrue, break out of for loop. |
|
1030 for(TInt queryPos = queryCount - 1; (queryPos >= 0 && !iCancelled); queryPos--) |
1014 { |
1031 { |
1015 CMdEObject& object = static_cast<CMdEObject&>(aQuery.ResultItem(queryPos)); |
1032 CMdEObject& object = static_cast<CMdEObject&>(aQuery.ResultItem(queryPos)); |
1016 //Removes the Read Only attributes of the file |
1033 //Removes the Read Only attributes of the file |
1017 fs.SetAtt(object.Uri(), 0, KEntryAttReadOnly); |
1034 fs.SetAtt(object.Uri(), 0, KEntryAttReadOnly); |
1018 TInt err = manager->DeleteFile(object.Uri()); |
1035 TInt err = manager->DeleteFile(object.Uri()); |
1019 if (err != KErrNone) |
1036 if (err != KErrNone) |
1020 { |
1037 { |
1021 lastErr = err; |
1038 lastErr = err; |
1022 } |
1039 } |
1023 objectsForRemoval.AppendL(object.Id()); |
1040 else |
|
1041 { |
|
1042 // On successful deletion, delete the same from database |
|
1043 objectsForRemoval.AppendL(object.Id()); |
|
1044 } |
|
1045 |
|
1046 // After every 50 items are deleted, break from the for loop |
|
1047 // and process other pending requests if any |
|
1048 if(deleteItemCounter == KDeletedItemCount) |
|
1049 { |
|
1050 iTimer->Start( KDeleteOperationInterval, KDeleteOperationInterval, |
|
1051 TCallBack( &SchedulerStopCallback, (TAny *)this ) ); |
|
1052 iSchedulerWait->Start(); |
|
1053 deleteItemCounter = 0; |
|
1054 } |
|
1055 deleteItemCounter++; |
1024 } |
1056 } |
1025 // Calling Close() on file server session |
1057 // Calling Close() on file server session |
1026 CleanupStack::PopAndDestroy( &fs ); |
1058 CleanupStack::PopAndDestroy( &fs ); |
1027 |
1059 |
1028 User::LeaveIfError(lastErr); |
1060 User::LeaveIfError(lastErr); |
1210 CleanupStack::PopAndDestroy(string); |
1242 CleanupStack::PopAndDestroy(string); |
1211 |
1243 |
1212 return result; |
1244 return result; |
1213 |
1245 |
1214 } |
1246 } |
|
1247 |
|
1248 // ---------------------------------------------------------------------------- |
|
1249 // CGlxDataSourceTaskMdeCommand::SchedulerStopCallback |
|
1250 // ---------------------------------------------------------------------------- |
|
1251 // |
|
1252 TInt CGlxDataSourceTaskMdeCommand::SchedulerStopCallback(TAny* aPtr) |
|
1253 { |
|
1254 TRACER("CGlxDataSourceTaskMdeCommand::SchedulerStopCallback"); |
|
1255 |
|
1256 CGlxDataSourceTaskMdeCommand* self = (CGlxDataSourceTaskMdeCommand*) aPtr; |
|
1257 if ( self ) |
|
1258 { |
|
1259 self->SchedulerStopComplete(); |
|
1260 } |
|
1261 |
|
1262 return KErrNone; |
|
1263 } |
|
1264 |
|
1265 // ----------------------------------------------------------------------------- |
|
1266 // SchedulerStopComplete |
|
1267 // ----------------------------------------------------------------------------- |
|
1268 // |
|
1269 void CGlxDataSourceTaskMdeCommand::SchedulerStopComplete() |
|
1270 { |
|
1271 TRACER("CGlxDataSourceTaskMdeCommand::SchedulerStopComplete"); |
|
1272 |
|
1273 if(iTimer && iTimer->IsActive()) |
|
1274 { |
|
1275 iTimer->Cancel(); |
|
1276 } |
|
1277 |
|
1278 if(iSchedulerWait) |
|
1279 { |
|
1280 iSchedulerWait->AsyncStop(); |
|
1281 } |
|
1282 } |