204 // Create table. |
205 // Create table. |
205 iUtils.CreateTableL( KSortingTableName, *colSet ); |
206 iUtils.CreateTableL( KSortingTableName, *colSet ); |
206 |
207 |
207 CleanupStack::PopAndDestroy( colSet ); |
208 CleanupStack::PopAndDestroy( colSet ); |
208 |
209 |
209 // Create index for every column except for mailBoxId |
|
210 CreateIndexL( KSortingTableName, KSortingTableMessageIdIndex, KSortingTableMessageIdCol ); |
210 CreateIndexL( KSortingTableName, KSortingTableMessageIdIndex, KSortingTableMessageIdCol ); |
211 CreateIndexL( KSortingTableName, KSortingTableFolderIdIndex, KSortingTableFolderIdCol ); |
211 CreateIndexL( KSortingTableName, KSortingTableFolderIdIndex, KSortingTableFolderIdCol ); |
212 CreateIndexL( KSortingTableName, KSortingTableMailBoxIdIndex, KSortingTableMailBoxIdCol ); |
212 CreateIndexL( KSortingTableName, KSortingTableMailBoxIdIndex, KSortingTableMailBoxIdCol ); |
213 CreateIndexL( KSortingTableName, KSortingTableReceivedDateIndex, KSortingTableReceivedDateCol ); |
213 CreateIndexL( KSortingTableName, KSortingTableReceivedDateIndex, KSortingTableReceivedDateCol ); |
214 CreateIndexL( KSortingTableName, KSortingTableReadUnreadIndex, KSortingTableReadUnreadCol, KSortingTableReceivedDateCol ); |
214 CreateIndexL( KSortingTableName, KSortingTableReadUnreadIndex, KSortingTableReadUnreadCol, KSortingTableReceivedDateCol ); |
282 // FUNCTION: DeleteMessagesByFolderIdL |
282 // FUNCTION: DeleteMessagesByFolderIdL |
283 // ========================================================================== |
283 // ========================================================================== |
284 void CContainerStoreSortingTable::DeleteMessagesByFolderIdL( TContainerId aFolderId ) |
284 void CContainerStoreSortingTable::DeleteMessagesByFolderIdL( TContainerId aFolderId ) |
285 { |
285 { |
286 __LOG_ENTER_SUPPRESS( "DeleteMessagesByFolderIdL" ) |
286 __LOG_ENTER_SUPPRESS( "DeleteMessagesByFolderIdL" ) |
287 __LOG_WRITE8_FORMAT1_DEBUG3( "aFolderId=%x", aFolderId ) |
287 __LOG_WRITE8_FORMAT1_DEBUG3( "aFolderId=%x", aFolderId ) |
288 |
288 //Add the folder ID into the MarkedForDeleteTable to be processed in the background. |
289 TBuf<KQuerryBufSize> queryString; |
289 MarkIdForDeletionL(aFolderId); |
290 queryString.Copy( KDelete ); |
|
291 queryString.Append( KFrom ); |
|
292 queryString.Append( KSortingTableName ); |
|
293 queryString.Append( KWhere ); |
|
294 queryString.Append( KSortingTableFolderIdCol ); |
|
295 queryString.Append( KEquals ); |
|
296 queryString.AppendNum( aFolderId ); |
|
297 |
|
298 iUtils.Execute( queryString ); |
|
299 |
|
300 //Notify the observer |
|
301 iObserver.FolderDeleted( aFolderId ); |
|
302 } |
290 } |
303 |
291 |
304 // ========================================================================== |
292 // ========================================================================== |
305 // FUNCTION: DeleteMessagesByMailBoxIdL |
293 // FUNCTION: DeleteMessagesByMailBoxIdL |
306 // ========================================================================== |
294 // ========================================================================== |
307 void CContainerStoreSortingTable::DeleteMessagesByMailBoxIdL( TContainerId aMailBoxId ) |
295 void CContainerStoreSortingTable::DeleteMessagesByMailBoxIdL( TContainerId aMailBoxId ) |
308 { |
296 { |
309 __LOG_ENTER_SUPPRESS( "DeleteMessagesByMailBoxIdL" ) |
297 __LOG_ENTER_SUPPRESS( "DeleteMessagesByMailBoxIdL" ) |
310 __LOG_WRITE8_FORMAT1_DEBUG3( "aMailBoxId=%x", aMailBoxId ) |
298 __LOG_WRITE8_FORMAT1_DEBUG3( "aMailBoxId=%x", aMailBoxId ) |
311 |
299 //Add the mailbox ID into the MarkedForDeleteTable to be processed in the background. |
312 TBuf<KQuerryBufSize> queryString; |
300 MarkIdForDeletionL( aMailBoxId); |
313 queryString.Copy( KDelete ); |
|
314 queryString.Append( KFrom ); |
|
315 queryString.Append( KSortingTableName ); |
|
316 queryString.Append( KWhere ); |
|
317 queryString.Append( KSortingTableMailBoxIdCol ); |
|
318 queryString.Append( KEquals ); |
|
319 queryString.AppendNum( aMailBoxId ); |
|
320 |
|
321 iUtils.Execute( queryString ); |
|
322 |
|
323 //Notify the observer |
|
324 iObserver.MailBoxDeleted( aMailBoxId ); |
|
325 } |
301 } |
326 |
302 |
327 // ========================================================================== |
303 // ========================================================================== |
328 // FUNCTION: UpdateMessageL |
304 // FUNCTION: UpdateMessageL |
329 // ========================================================================== |
305 // ========================================================================== |
1243 void CContainerStoreSortingTable::SetEncryptedL( TBool aIsEncrypted ) |
1219 void CContainerStoreSortingTable::SetEncryptedL( TBool aIsEncrypted ) |
1244 { |
1220 { |
1245 iTable.SetColL( iIsEncryptedColNum, static_cast<TUint8>(aIsEncrypted) ); |
1221 iTable.SetColL( iIsEncryptedColNum, static_cast<TUint8>(aIsEncrypted) ); |
1246 } |
1222 } |
1247 |
1223 |
|
1224 // ========================================================================== |
|
1225 // FUNCTION: CreateMarkedForDeletionTableL |
|
1226 // ========================================================================== |
|
1227 void CContainerStoreSortingTable::CreateMarkedForDeletionTableL() |
|
1228 { |
|
1229 __LOG_ENTER( "CreateMarkedForDeletionTableL" ) |
|
1230 |
|
1231 // Create table columns |
|
1232 CDbColSet* colSet = CDbColSet::NewLC(); |
|
1233 TDbCol mailboxIdCol( KMarkedForDeleteTableIDCol, EDbColUint32 ); |
|
1234 colSet->AddL( mailboxIdCol ); |
|
1235 // Create table. |
|
1236 iUtils.CreateTableL( KMarkedForDeleteTableName, *colSet ); |
|
1237 CleanupStack::PopAndDestroy( colSet ); |
|
1238 __LOG_EXIT |
|
1239 } |
|
1240 |
|
1241 // ========================================================================== |
|
1242 // FUNCTION: CreateOrOpenMarkedForDeletionTableL |
|
1243 // try to open the Table - create if not found (IAD case) and then open |
|
1244 // ========================================================================== |
|
1245 void CContainerStoreSortingTable::CreateOrOpenMarkedForDeletionTableL() |
|
1246 { |
|
1247 __LOG_ENTER( "OpenMarkedForDeletionTableL" ) |
|
1248 |
|
1249 TRAPD(err, iUtils.OpenTableL( iMarkedForDeleteTable, KMarkedForDeleteTableName )); |
|
1250 if(err != KErrNone) |
|
1251 { |
|
1252 CreateMarkedForDeletionTableL(); |
|
1253 iUtils.OpenTableL( iMarkedForDeleteTable, KMarkedForDeleteTableName ); |
|
1254 } |
|
1255 CDbColSet* colSet = iMarkedForDeleteTable.ColSetL(); |
|
1256 CleanupStack::PushL( colSet ); |
|
1257 //Get the column number |
|
1258 iMarkedForDeleteIdColNum = colSet->ColNo( KMarkedForDeleteTableIDCol ); |
|
1259 CleanupStack::PopAndDestroy( colSet ); |
|
1260 __LOG_EXIT |
|
1261 } |
|
1262 |
|
1263 // ========================================================================== |
|
1264 // FUNCTION: MarkIdForDeletionL |
|
1265 // Add the ID into the marked for DeletionTable. |
|
1266 // ========================================================================== |
|
1267 void CContainerStoreSortingTable::MarkIdForDeletionL( TContainerId aId) |
|
1268 { |
|
1269 __LOG_ENTER( "MarkIdForDeletionL" ) |
|
1270 |
|
1271 __LOG_WRITE8_FORMAT1_DEBUG3( "Id=%x",aId ) |
|
1272 iMarkedForDeleteTable.LastL(); |
|
1273 iMarkedForDeleteTable.InsertL(); |
|
1274 iMarkedForDeleteTable.SetColL( iMarkedForDeleteIdColNum, aId ); |
|
1275 iMarkedForDeleteTable.PutL(); |
|
1276 __LOG_EXIT |
|
1277 } |
|
1278 |
|
1279 // ========================================================================== |
|
1280 // FUNCTION: DeleteNextContainerMarkedForDeletionL |
|
1281 // Use the ID in the MarkedForDeletionTable to delete items from the sorting table . |
|
1282 // ========================================================================== |
|
1283 TBool CContainerStoreSortingTable::DeleteNextContainerMarkedForDeletionL() |
|
1284 { |
|
1285 __LOG_ENTER( " DeleteNextContainerMarkedForDeletionL" ) |
|
1286 TBool more = EFalse; |
|
1287 //set the index to mailboxID to help with seek |
|
1288 // Set the table's index to the ID index. |
|
1289 if(!iMarkedForDeleteTable.IsEmptyL()) |
|
1290 { |
|
1291 iMarkedForDeleteTable.FirstL(); |
|
1292 iMarkedForDeleteTable.GetL(); |
|
1293 TInt deletionID = iMarkedForDeleteTable.ColUint32(iMarkedForDeleteIdColNum); |
|
1294 //check if the ID refers to a folder or is a mailbox and set the index for the table accordingly. |
|
1295 if ( ( deletionID & EMsgStoreContainerMask ) == EMsgStoreMailBoxBits) |
|
1296 { |
|
1297 iTable.SetIndex( KSortingTableMailBoxIdIndex ); |
|
1298 } |
|
1299 else if ( ( deletionID & EMsgStoreContainerMask ) == EMsgStoreFolderBits) |
|
1300 { |
|
1301 iTable.SetIndex( KSortingTableFolderIdIndex ); |
|
1302 } |
|
1303 //Delete next message from the mailbox/folder |
|
1304 TRAPD(err, more = DeleteNextMessageL(deletionID)); |
|
1305 if (err == KErrNone) |
|
1306 { |
|
1307 if (!more) |
|
1308 { |
|
1309 TRAP_IGNORE(more = DeleteFromMarkedForDeletionTableL()); |
|
1310 } |
|
1311 } |
|
1312 //reset to the original index |
|
1313 iTable.SetIndex( KSortingTableMessageIdIndex ); |
|
1314 } |
|
1315 __LOG_EXIT |
|
1316 return more; |
|
1317 } |
|
1318 |
|
1319 // ========================================================================== |
|
1320 // FUNCTION: DeleteNextContainerMarkedForDeletionL |
|
1321 // Use the ID in the MarkedForDeletionTable to delete items from the sorting table . |
|
1322 // ========================================================================== |
|
1323 TBool CContainerStoreSortingTable::DeleteFromMarkedForDeletionTableL() |
|
1324 { |
|
1325 __LOG_ENTER( " DeleteFromMarkedForDeletionTableL" ) |
|
1326 TBool more(EFalse); |
|
1327 // removed the row once all the messages for that ID have been deleted. |
|
1328 iMarkedForDeleteTable.DeleteL(); |
|
1329 //check if there is another entry |
|
1330 if(iMarkedForDeleteTable.NextL()) |
|
1331 { |
|
1332 more = ETrue; |
|
1333 } |
|
1334 __LOG_EXIT |
|
1335 return more; |
|
1336 } |
|
1337 |
|
1338 // ========================================================================== |
|
1339 // FUNCTION: DeleteNextMessageL |
|
1340 // Deletes one row where ID = aId. |
|
1341 // @ return Etrue if seek successful |
|
1342 // EFalse if seek failed which mean no more messages for the |
|
1343 // given container ID |
|
1344 // ========================================================================== |
|
1345 TBool CContainerStoreSortingTable::DeleteNextMessageL( TContainerId aId ) |
|
1346 { |
|
1347 __LOG_ENTER( "DeleteNextMessageL" ) |
|
1348 __LOG_WRITE8_FORMAT1_DEBUG3( "aId=%x", aId ) |
|
1349 |
|
1350 //Find first matching row |
|
1351 TRAPD(err, SeekL( aId )); |
|
1352 TBool more(EFalse); |
|
1353 if (err ==KErrNone) |
|
1354 { |
|
1355 iTable.GetL(); |
|
1356 iTable.DeleteL(); |
|
1357 more = ETrue; |
|
1358 } |
|
1359 __LOG_EXIT |
|
1360 return more; |
|
1361 } |
|
1362 |