pimappservices/calendar/server/src/agsentrymodel.cpp
changeset 45 b6db4fd4947b
parent 0 f979ecb2b13e
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
    83         iExtractor = new (ELeave) TAgnInstanceExtractor(*iSimpleEntryTable);
    83         iExtractor = new (ELeave) TAgnInstanceExtractor(*iSimpleEntryTable);
    84 		iCategoryIndex = CAgnCategoryIndex::NewL();
    84 		iCategoryIndex = CAgnCategoryIndex::NewL();
    85 		iAttachmentIndex = new (ELeave) CAgnAttachmentIndex;
    85 		iAttachmentIndex = new (ELeave) CAgnAttachmentIndex;
    86 		CreateAlarmForServerL();
    86 		CreateAlarmForServerL();
    87 		}
    87 		}
       
    88 	
       
    89 	User::LeaveIfError(iFs.Connect());
       
    90     User::LeaveIfError( iFs.ShareProtected() );
       
    91     
    88 	iIndexFileIsDirty = ETrue; 	// for safety assume that the index
    92 	iIndexFileIsDirty = ETrue; 	// for safety assume that the index
    89 					// file is out of date. We can correct this
    93 					// file is out of date. We can correct this
    90 					// when we read the file
    94 					// when we read the file
    91 
    95 
    92 	iIndexFileIsPresent = ETrue; // Assume the index file is present. 
    96 	iIndexFileIsPresent = ETrue; // Assume the index file is present. 
   111 	delete iSimpleEntryTable;
   115 	delete iSimpleEntryTable;
   112 	delete iAlarm;
   116 	delete iAlarm;
   113 	delete iModelStreamIdSet;
   117 	delete iModelStreamIdSet;
   114 	delete iEntryManager;
   118 	delete iEntryManager;
   115 	delete iCalConverter;
   119 	delete iCalConverter;
       
   120 	iFs.Close();
   116 	}
   121 	}
   117 
   122 
   118 const CAgnServFile& CAgnEntryModel::AgnServFile()
   123 const CAgnServFile& CAgnEntryModel::AgnServFile()
   119 	{
   124 	{
   120 	return *iAgnServerFile;
   125 	return *iAgnServerFile;
       
   126 	}
       
   127 
       
   128 /**
       
   129  * Resets delete rollback array before the callback
       
   130  */	
       
   131 void CAgnEntryModel::ResetDeleteRollbackArray()
       
   132 	{
       
   133 	iDeleteRollbackArray.ResetAndDestroy();
   121 	}
   134 	}
   122 
   135 
   123 /** Load up the stream network
   136 /** Load up the stream network
   124  */
   137  */
   125 void CAgnEntryModel::DoOpenL(const TStreamId& aModelStreamId)
   138 void CAgnEntryModel::DoOpenL(const TStreamId& aModelStreamId)
   501 			else 
   514 			else 
   502 				{
   515 				{
   503 				_DBGLOG_VERBOSE(AgmDebug::DebugLog("StoreL: Existing entry types is different to incoming entry's type");)
   516 				_DBGLOG_VERBOSE(AgmDebug::DebugLog("StoreL: Existing entry types is different to incoming entry's type");)
   504 				_DBGLOG_VERBOSE(AgmDebug::DebugLog("StoreL: Delete the existing entry and add the incoming entry as a new one");)
   517 				_DBGLOG_VERBOSE(AgmDebug::DebugLog("StoreL: Delete the existing entry and add the incoming entry as a new one");)
   505 				
   518 				
   506 				// if the entry is a different type, delete the old entry and add the new one 
   519 				// if the entry is a different type, add the new one first and delete only later
       
   520                 // This change is needed if the entry having attachments, it will be shared by two 
       
   521                 //entries, so that attachments will not be deleted, while deleting it later. 
       
   522 				returnId = AddEntryL(aEntry);
   507 				DeleteEntryL(*existingEntryToReplace, ETrue, iChangeFilter);
   523 				DeleteEntryL(*existingEntryToReplace, ETrue, iChangeFilter);
   508 				returnId = AddEntryL(aEntry);
       
   509 				}
   524 				}
   510 
   525 
   511 			CleanupStack::PopAndDestroy(existingEntryToReplace);
   526 			CleanupStack::PopAndDestroy(existingEntryToReplace);
   512 			}
   527 			}
   513 		else
   528 		else
  1396 // This method marks the index file as dirty (i.e. out of sync with the indices 
  1411 // This method marks the index file as dirty (i.e. out of sync with the indices 
  1397 // in RAM) by deleting it. A flag is kept internally to allow us to know that the
  1412 // in RAM) by deleting it. A flag is kept internally to allow us to know that the
  1398 // file needs to be rebuilt and to no try to delete the file more than once.
  1413 // file needs to be rebuilt and to no try to delete the file more than once.
  1399 void CAgnEntryModel::MarkIndexFileAsDirtyL()
  1414 void CAgnEntryModel::MarkIndexFileAsDirtyL()
  1400 	{
  1415 	{
  1401 	if (iIndexFileIsDirty)
  1416 
  1402 		{
  1417     if(IsIndexFileAvailableL())
  1403 		return; // the file is already marked as dirty
  1418         {		
  1404 		}
  1419             TFileName idxfilename;
  1405 		
  1420             if (!GenerateIndexFileName(idxfilename))
  1406 	TFileName idxfilename;
  1421                 {
  1407 	if (!GenerateIndexFileName(idxfilename))
  1422                 User::Leave(KErrBadName);
  1408 		{
  1423                 }           
  1409 		User::Leave(KErrBadName);
  1424             iFs.Delete(idxfilename); // ignore return as there is nothing we can do with it           
  1410 		}
  1425         }        
  1411 	
       
  1412 	TInt connectErr = iFs.Connect();
       
  1413 	User::LeaveIfError(connectErr);
       
  1414 	
       
  1415 	iFs.Delete(idxfilename); // ignore return as there is nothing we can do with it
       
  1416 	
       
  1417 	iIndexFileIsDirty = ETrue;
  1426 	iIndexFileIsDirty = ETrue;
  1418 	}
  1427 	}
  1419 	
  1428 	
  1420 // This method allows clients of the model to determine if the index file is
  1429 // This method allows clients of the model to determine if the index file is
  1421 // dirty and therefore in need of being rewritten with the current data.
  1430 // dirty and therefore in need of being rewritten with the current data.
  1445 	if (!GenerateIndexFileName(idxfilename))
  1454 	if (!GenerateIndexFileName(idxfilename))
  1446 		{
  1455 		{
  1447 		User::Leave(KErrBadName);
  1456 		User::Leave(KErrBadName);
  1448 		}
  1457 		}
  1449 	
  1458 	
  1450 	TInt connectErr = iFs.Connect();
       
  1451 	User::LeaveIfError(connectErr);
       
  1452 	
       
  1453 	RFile idxFile;
  1459 	RFile idxFile;
  1454 	TInt errReadIdx = idxFile.Open(iFs, idxfilename, EFileRead);
  1460 	TInt errReadIdx = idxFile.Open(iFs, idxfilename, EFileRead);
  1455 	CleanupClosePushL(idxFile);
  1461 	CleanupClosePushL(idxFile);
  1456 	
  1462 	
  1457 	if (errReadIdx == KErrNone)    // we have a file
  1463 	if (errReadIdx == KErrNone)    // we have a file
  1510 	MarkIndexFileAsDirtyL();
  1516 	MarkIndexFileAsDirtyL();
  1511 	iIndexFileIsPresent = EFalse;	
  1517 	iIndexFileIsPresent = EFalse;	
  1512 	return EFalse;
  1518 	return EFalse;
  1513 	}
  1519 	}
  1514 
  1520 
       
  1521 // This method check the index file is exist.
       
  1522 // It returns:
       
  1523 //      ETrue - File is already exist
       
  1524 //      EFalse - File is not available
       
  1525 TBool CAgnEntryModel::IsIndexFileAvailableL()
       
  1526     {
       
  1527     TFileName idxfilename;
       
  1528     if (!GenerateIndexFileName(idxfilename))
       
  1529         {
       
  1530         User::Leave(KErrBadName);
       
  1531         }
       
  1532    
       
  1533     RFile idxFile;
       
  1534     TInt errReadIdx = idxFile.Open(iFs, idxfilename, EFileRead);
       
  1535     CleanupClosePushL(idxFile);
       
  1536     if((errReadIdx == KErrNotFound))
       
  1537         {
       
  1538             CleanupStack::PopAndDestroy();
       
  1539             return EFalse;
       
  1540         }
       
  1541     CleanupStack::PopAndDestroy(&idxFile);
       
  1542     return ETrue;
       
  1543 }
  1515 
  1544 
  1516 // This method attempts to save all indices to the index file.
  1545 // This method attempts to save all indices to the index file.
  1517 // If any errors are encountered it will Leave.
  1546 // If any errors are encountered it will Leave.
  1518 // Clients of this method should TRAP the Leave and possibly
  1547 // Clients of this method should TRAP the Leave and possibly
  1519 // mark the file as dirty or try to delete it.
  1548 // mark the file as dirty or try to delete it.
  1522 	TFileName idxfilename;
  1551 	TFileName idxfilename;
  1523 	if (!GenerateIndexFileName(idxfilename))
  1552 	if (!GenerateIndexFileName(idxfilename))
  1524 		{
  1553 		{
  1525 		User::Leave(KErrBadName);
  1554 		User::Leave(KErrBadName);
  1526 		}
  1555 		}
  1527 	TInt connectErr = iFs.Connect();
  1556 	
  1528 	User::LeaveIfError(connectErr);
       
  1529 
       
  1530 	RFile idxFile;
  1557 	RFile idxFile;
  1531 	TInt errWriteIdx = idxFile.Replace(iFs, idxfilename, EFileWrite);
  1558 	TInt errWriteIdx = idxFile.Replace(iFs, idxfilename, EFileWrite);
  1532 	User::LeaveIfError(errWriteIdx);
  1559 	User::LeaveIfError(errWriteIdx);
  1533 	CleanupClosePushL(idxFile);
  1560 	CleanupClosePushL(idxFile);
  1534 	
  1561 	
  2675 		_DBGLOG_ENTRY(AgmDebug::DebugLog("UpdateEntryL: DoUpdateEntryL failed: Leaving with error - %d",ret);)
  2702 		_DBGLOG_ENTRY(AgmDebug::DebugLog("UpdateEntryL: DoUpdateEntryL failed: Leaving with error - %d",ret);)
  2676 		User::Leave(ret);
  2703 		User::Leave(ret);
  2677 		}
  2704 		}
  2678 
  2705 
  2679 	NotifyingL(MCalChangeCallBack2::EChangeModify, aEntry, instanceInfoBefore);
  2706 	NotifyingL(MCalChangeCallBack2::EChangeModify, aEntry, instanceInfoBefore);
       
  2707 	
       
  2708 	if(iChangeFilter && iTzRuleIndex)
       
  2709         {
       
  2710         //Remove the tz rule from tz rule index
       
  2711         //we have to do it after CAgnEntryModel::NotifyingL that is indirectly using the
       
  2712         //tz rule in oldEntry.
       
  2713         iTzRuleIndex->RemoveTzRuleL(*oldEntry);
       
  2714         }
       
  2715   
  2680 	
  2716 	
  2681 	CleanupStack::PopAndDestroy(instanceInfoBefore);
  2717 	CleanupStack::PopAndDestroy(instanceInfoBefore);
  2682 	CleanupStack::PopAndDestroy(oldEntry);
  2718 	CleanupStack::PopAndDestroy(oldEntry);
  2683 	
  2719 	
  2684 	// Delete the old alarm and if a new alarm exists it will be added by findAndQueue
  2720 	// Delete the old alarm and if a new alarm exists it will be added by findAndQueue